all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Juanma Barranquero" <lekktu@gmail.com>
To: "Eli Zaretskii" <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Optimized gcc 4.3.0 build on Windows returns 0 secs for all time values of system-process-attributes
Date: Thu, 1 Jan 2009 05:38:36 +0100	[thread overview]
Message-ID: <f7ccd24b0812312038x1fbb314exc159f563124c0495@mail.gmail.com> (raw)
In-Reply-To: <ur63onop4.fsf@gnu.org>

On Wed, Dec 31, 2008 at 20:12, Eli Zaretskii <eliz@gnu.org> wrote:

> It works for me with GCC 3.4.2 and MinGW 3.14:

Optimized or unoptimized build?

> Could you please step into process_times and ltime (or add printf's if
> stepping doesn't work), and see what is going wrong and where?

Stepping isn't much helpful because most variables are optimized away.

As for printf, I'm not sure what's wrong, but

    long double x = 3.5;
    printf ("f = %Lf\n", x);
    printf ("g = %Lg\n", x);

  =>

f = -26815615859885194000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000.000000
g = -2.68156e+154

(Not just with gcc 4.3.0, I get the same result with 3.4.5.)

Am I missing something obvious?

I tried rewriting w32.c:process_time to do time computations by using
ULARGE_INTEGER (see attached patch), as the Platform SDK recommends,
and it works fine. Why it is implemented with long doubles?

    Juanma


Index: src/w32.c
===================================================================
RCS file: /sources/emacs/emacs/src/w32.c,v
retrieving revision 1.157
diff -u -2 -r1.157 w32.c
--- src/w32.c	19 Dec 2008 19:50:39 -0000	1.157
+++ src/w32.c	31 Dec 2008 17:04:23 -0000
@@ -3778,7 +3778,7 @@
 {
   FILETIME ft_creation, ft_exit, ft_kernel, ft_user, ft_current;
-  long ctime_sec, ctime_usec, stime_sec, stime_usec, utime_sec, utime_usec;
-  long etime_sec, etime_usec;
-  long double tem1, tem2, tem;
+  DWORD ctime_sec, ctime_usec, stime_sec, stime_usec, utime_sec, utime_usec;
+  DWORD etime_sec, etime_usec;
+  ULARGE_INTEGER tem1, tem2, tem, utc;

   if (!h_proc
@@ -3788,31 +3788,43 @@
     return 0;

+  utc.LowPart = utc_base_ft.dwLowDateTime;
+  utc.HighPart = utc_base_ft.dwHighDateTime;
+
   GetSystemTimeAsFileTime (&ft_current);

-  tem1 = convert_time_raw (ft_kernel) * 0.1L;
-  stime_usec = fmodl (tem1, 1000000.0L);
-  stime_sec = tem1 * 0.000001L;
+  tem1.LowPart = ft_kernel.dwLowDateTime;
+  tem1.HighPart = ft_kernel.dwHighDateTime;
+  tem1.QuadPart /= 10L;
+  stime_usec = tem1.QuadPart % 1000000L;
+  stime_sec = tem1.QuadPart / 1000000L;
   *stime = ltime (stime_sec, stime_usec);
-  tem2 = convert_time_raw (ft_user) * 0.1L;
-  utime_usec = fmodl (tem2, 1000000.0L);
-  utime_sec = tem2 * 0.000001L;
+  tem2.LowPart = ft_user.dwLowDateTime;
+  tem2.HighPart = ft_user.dwHighDateTime;
+  tem2.QuadPart /= 10L;
+  utime_usec = tem2.QuadPart % 1000000L;
+  utime_sec = tem2.QuadPart / 1000000L;
   *utime = ltime (utime_sec, utime_usec);
-  tem = convert_time_raw (ft_creation);
+  tem.LowPart = ft_creation.dwLowDateTime;
+  tem.HighPart = ft_creation.dwHighDateTime;
   /* Process no 4 (System) returns zero creation time.  */
-  if (tem)
-    tem = (tem - utc_base) * 0.1;
-  ctime_usec = fmodl (tem, 1000000.0L);
-  ctime_sec = tem * 0.000001L;
+  if (tem.QuadPart)
+    tem.QuadPart = (tem.QuadPart - utc.QuadPart) / 10L;
+  ctime_usec = tem.QuadPart % 1000000L;
+  ctime_sec = tem.QuadPart / 1000000L;
   *ctime = ltime (ctime_sec, ctime_usec);
-  if (tem)
-    tem = (convert_time_raw (ft_current) - utc_base) * 0.1L - tem;
-  etime_usec = fmodl (tem, 1000000.0L);
-  etime_sec = tem * 0.000001L;
+  if (tem.QuadPart)
+    {
+      ULARGE_INTEGER current;
+      current.LowPart = ft_current.dwLowDateTime;
+      current.HighPart = ft_current.dwHighDateTime;
+      tem.QuadPart = (current.QuadPart - utc.QuadPart) / 10L - tem.QuadPart;
+    }
+  etime_usec = tem.QuadPart % 1000000L;
+  etime_sec = tem.QuadPart / 1000000L;
   *etime = ltime (etime_sec, etime_usec);
-
-  if (tem)
+  if (tem.QuadPart)
     {
-      *pcpu = 100.0 * (tem1 + tem2) / tem;
-      if (*pcpu > 100)
+      *pcpu = (100.0 * (tem1.QuadPart + tem2.QuadPart)) / tem.QuadPart;
+      if (*pcpu > 100.0)
 	*pcpu = 100.0;
     }




  reply	other threads:[~2009-01-01  4:38 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-31 13:00 Optimized gcc 4.3.0 build on Windows returns 0 secs for all time values of system-process-attributes Juanma Barranquero
2008-12-31 17:29 ` dhruva
2008-12-31 19:12 ` Eli Zaretskii
2009-01-01  4:38   ` Juanma Barranquero [this message]
2009-01-01 12:57     ` dhruva
2009-01-01 13:08       ` dhruva
2009-01-01 13:16       ` Jason Rumney
2009-01-01 13:43         ` dhruva
2009-01-01 19:00           ` Eli Zaretskii
2009-01-02  4:59             ` dhruva
2009-01-02 14:33               ` Eli Zaretskii
2009-01-02 17:44                 ` Chetan Pandya
2009-01-01 18:03       ` Juanma Barranquero
2009-01-01 18:54     ` Eli Zaretskii
2009-01-03  2:27       ` Juanma Barranquero
2009-01-03 12:29         ` Eli Zaretskii
2009-01-03 13:28           ` Juanma Barranquero
2009-01-03 13:53             ` Juanma Barranquero
2009-01-03 15:33               ` Eli Zaretskii
2009-01-03 16:00                 ` Juanma Barranquero
2009-01-03 16:40                   ` Eli Zaretskii
2009-01-03 16:56                   ` Eli Zaretskii
2009-01-03 17:14                     ` Juanma Barranquero
2009-01-03 19:02                       ` Eli Zaretskii
2009-01-04  2:24                       ` Jason Rumney
2009-01-04  2:30                         ` Juanma Barranquero
2009-01-04  2:33                           ` Jason Rumney
2009-01-04  2:35                             ` Juanma Barranquero

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f7ccd24b0812312038x1fbb314exc159f563124c0495@mail.gmail.com \
    --to=lekktu@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.