Mail Archives: djgpp/2007/01/04/19:22:00

X-Authentication-Warning: mail set sender to djgpp-bounces using -f
Subject: Performance enhancement for gettimeofday()?
To: djgpp AT delorie DOT com
X-Mailer: Lotus Notes Release 6.5.4 CCH5 September 12, 2005
Message-ID: <>
From: Gordon DOT Schumacher AT seagate DOT com
Date: Thu, 4 Jan 2007 17:16:32 -0700
X-MIMETrack: Serialize by Router on SV-GW1/Seagate Internet(Release 7.0.1 HF29|March 07, 2006) at
01/04/2007 04:16:36 PM
MIME-Version: 1.0
X-Proofpoint-FWRule: outbound2
X-Proofpoint-Virus-Version: vendor=fsecure engine=4.65.5446:2.3.11,1.2.37,4.0.164 definitions=2007-01-04_05:2007-01-03,2006-12-29,2007-01-04 signatures=0

This might seem like a strange place to be focusing on for performance...
but it turns out that the GNU Pth library uses gettimeofday() from inside
the "put a thread to sleep for x time" functions and that is something
which can get called from performance-critical code (and profiling tells
me is being done in the application I'm working on).

It was spending much of its time in the __dpmi_int function (no surprise),
and I figured out that better than 90% of those calls were coming from
gettimeofday().  So I started pondering whether there was a way to fix
the library routine to not have to make a real-mode transition.

Most of the data returned by the DOS int 21/2C and 21/2A functions can be
obtained directly from the CMOS, with nothing more than port I/O: that
will give us everything except the "hundredths" of a second field.  For
that field, what about installing a interrupt handler to simply increment
a counter every timer tick, and reset it to zero when the counter reaches
91 (signifying five seconds have elapsed)?

I can, indeed, also fix this inside of the Pth library (or for that
matter inside my application so as not to call pth_nap at all) but it
seemed like the ideal solution would be to fix the library so that
everyone wins with the performance boost.

Also did anyone have any thoughts on my ideas for improvements to pipe()?

- Raw text -

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