delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/01/24/15:04:54

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
From: "Ralf Habacker" <Ralf DOT Habacker AT freenet DOT de>
To: "Cygwin" <cygwin AT sources DOT redhat DOT com>
Subject: RE: gettimeofday() does not returns usec resolution
Date: Thu, 24 Jan 2002 21:01:35 +0100
Message-ID: <002d01c1a511$ed628b50$0fa807d5@BRAMSCHE>
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0
Importance: Normal
In-reply-to: <3C4F01DF.70AA4F00@lapo.it>
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400

> 
> > >> Has anyone address this problem already. I have looked int the
> > >> cygwin and list and found the only topic
> > >http://sources.redhat.com/ml/cygwin/2001-12/msg00201.html
> 
> In the attached file there is a "patch" for gettmieofday:
> 
> -------
> int gettimeofday(struct timeval *tv, struct timezone *tz)
> {
>  LARGE_INTEGER   t;
>  FILETIME   f;
>  double     microseconds;
>  static LARGE_INTEGER offset;
>  static double   frequencyToMicroseconds;
>  static int    initialized = 0;
>  static BOOL    usePerformanceCounter = 0;
> 
>  if (!initialized) {
>   LARGE_INTEGER performanceFrequency;
>   initialized = 1;
>   usePerformanceCounter = QueryPerformanceFrequency(&performanceFrequency);
>   if (usePerformanceCounter) {
>    QueryPerformanceCounter(&offset);
>    frequencyToMicroseconds = (double)performanceFrequency.QuadPart /
> 1000000.;
>   } else {
>    offset = getFILETIMEoffset();
>    frequencyToMicroseconds = 10.;
>   }
>  }
>  if (usePerformanceCounter) QueryPerformanceCounter(&t);
>  else {
>   GetSystemTimeAsFileTime(&f);
>   t.QuadPart = f.dwHighDateTime;
>   t.QuadPart <<= 32;
>   t.QuadPart |= f.dwLowDateTime;
>  }
> 
>  t.QuadPart -= offset.QuadPart;
>  microseconds = (double)t.QuadPart / frequencyToMicroseconds;
>  t.QuadPart = microseconds;
>  tv->tv_sec = t.QuadPart / 1000000;
>  tv->tv_usec = t.QuadPart % 1000000;
>  return (0);
> }
> ------------
> 
> The following Microsoft page (
> http://www.vbapi.com/ref/q/queryperformancecounter.html ) says it supported
> on all version (startig from NT3.51 and Windows95) an, at least, it calls
> GetTickCount()*1000.
> 
> > >> In http://www-106.ibm.com/developerworks/library/l-rt1/ there is a
> > >> detailed instruction how to use the hugh resolution counter. .
> > >>
> > >> $ cat timeofday.c #include <sys/time.h>
> > >>
> > >> int main() { struct timeval tp; long a,b;
> > >>
> > >> gettimeofday(&tp,0); a =
> > >> ((unsigned)tp.tv_sec)*1000000+((unsigned)tp.tv_usec);
> > >>
> > >> printf("timestamp (us): %d\n",a); usleep(1000); gettimeofday(&tp,0); b
> > >>  = ((unsigned)tp.tv_sec)*1000000+((unsigned)tp.tv_usec);
> > >printf("timestamp
> > >>  (us): %d (diff) %d\n",b,b-a); }
> 
> I adapted the code to find exactly the minimum time slice, and not "how well
> 1ms of retard is seen" (it was a 0ns or 15000ns, this is always 15000ns;
> moreover printf is out of the "timing" section):

isn't the time slice about 10ms. ? 


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019