This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] CPU-time clocks


On May 16 18:10, Yaakov (Cygwin/X) wrote:
> On Mon, 2011-05-16 at 12:43 +0200, Corinna Vinschen wrote:
> > Thanks for this patch.  It looks good to me with two exceptions:
> > [...]
> Revised patch attached.

Thank you.  You can apply it, but while I was looking into it,
this occured to me:

> +      FILETIME creation_time, exit_time, kernel_time, user_time;
> +      long long x;
> +      [...]
> +      GetProcessTimes (hProcess, &creation_time, &exit_time, &kernel_time,
> +                       &user_time);
> +
> +      x = ((long long) kernel_time.dwHighDateTime << 32)
> +          + ((unsigned) kernel_time.dwLowDateTime)
> +          + ((long long) user_time.dwHighDateTime << 32)
> +          + ((unsigned) user_time.dwLowDateTime);
> +      tp->tv_sec = x / (long long) NSPERSEC;
> +      tp->tv_nsec = (x % (long long) NSPERSEC) * 100LL;

This conversion arithmetic from FILETIME to long long happens a lot
in times.cc, even though it's absolutely not necessary.

The FILETIME struct is actually a LARGE_INTEGER in which just the
QuadPart member is missing, unfortunately.  What we can do is to
replace the bit shifting stuff with a simple cast:

  x = ((PLARGE_INTEGER) &kernel_time)->QuadPart
      + ((PLARGE_INTEGER) &user_time)->QuadPart;

Alternatively we can define kernel_time etc as LARGE_INTEGER and cast in
the call to GetProcessTimes or just call NtQueryInformationProcess.

What do you think?  If you don't care, just apply your patch as is.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]