www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2007/01/08/13:05:41

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
In-Reply-To: <200701070505.l07551em014636@delorie.com>
Subject: Re: Performance enhancement for gettimeofday()?
To: djgpp AT delorie DOT com
X-Mailer: Lotus Notes Release 6.5.4 CCH5 September 12, 2005
Message-ID: <OF1B107D53.1922E890-ON8725725D.005F267B-8725725D.00633021@seagate.com>
From: Gordon DOT Schumacher AT seagate DOT com
Date: Mon, 8 Jan 2007 11:03:25 -0700
X-MIMETrack: Serialize by Router on SV-GW1/Seagate Internet(Release 7.0.1 HF29|March 07, 2006) at
01/08/2007 10:03:42 AM
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-08_05:2007-01-06,2007-01-08,2007-01-08 signatures=0
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

Rod Pemberton wrote on Sat, 6 Jan 2007 at 01:32:07 -0500:

# Why so many calls?  Isn't it a design problem with Pth to consume lots of
# CPU to set an alarm?

Well, gettimeofday() is usually not a CPU-intensive function on most
platforms, so I don't think that this counts as a Pth problem per se.

# DOS or Windows?  IIRC, PM port I/O is priviledged.  Does anyone know if
this
# would affect Windows?

For my latest version I dropped the direct-from-CMOS version as
unnecessary, so no longer relevant... my latest is using only
DOS interrupt calls and clock().

# For "hundredths" of a second, wouldn't you want a timer of 100Hz or
greater?
# Basically, if you used 18.0265Hz, you'd get "eighteenths" of a second or
# almost "twentieths" of a second.  So, the "hundredths" timer would
update,
# be stale for the next 4 reads, update, be stale for the next 4 reads,
# update, etc.

I was indeed talking about the 18.2 per second timer - which appears to be
the one that DOS is using internally.  So that staleness of the hundredths
field is already an issue just using the CMOS.  Here's a snippet of
documentation on this: http://www.merlyn.demon.co.uk/prog2000.htm#MSF
I've also dug through the FreeDOS source code and confirmed that this is
how FD behaves.
Use the following for proof:

#include <stdio.h>
#include <time.h>

int main()
{
  int i;
  for (i = 0; i < 400; i++) {
    uclock_t start;
    struct timeval tp;

    gettimeofday(&tp, NULL);
    printf("%ld\t", tp.tv_usec);
// Uncomment if your machine is too fast...
//    start = uclock();
//    while (uclock() < start + UCLOCKS_PER_SEC / 500);
  }
  printf("\n");
  return 0;
}

# clock() gets its ticks from 40:6ch which are saved from IRQ 0 (int 08h or
# 18.0265Hz).  clock has the define CLOCK_PER_SEC which is 91.  I'm not
sure
# why that value is used or the period it generates is used, but it does
# produce a period of about 5 seconds using the 18.0265Hz clock.

Looking at the libc source code, the value from the interrupt is multiplied
by five before being handed off to the user, so that the user does not have
to use floating-point math.

The clock frequency should be (1.193*10^6) / 65536 Hz, which works out to
18.203 or so.  I'm modifying my code to use the more accurate calculation
starting with the crystal frequency instead of CLOCKS_PER_SEC (it means
doing floating-point math but it's still so much faster than the original
that it's still worth it).

# I may not be the person to respond on this issue.  I've seen a number of
# posts on the intracacies of getting DJGPP to work on XP (and you didn't
say
# what OS).  I use DOS mostly (and Win98).  So, anything which affects DOS
# affects me.  I think alot of others are using XP.  I suspect whatever you
# create needs to work with MS-DOS,DR-DOS,FreeDOS, the various versions of
# Windows, etc...

I've tested my code under XP and FreeDOS.  I don't have DR-DOS anywhere
handy, though I could install it in a VM if that should be a sufficient
test?

# I had hoped someone much more familiar with the issues you bring up would
# respond to you first...

No worries.  I've also posted some actual code over on DJGPP-Workers,
since this didn't seem like the appropriate place for it... I'll link
to it though:
http://www.delorie.com/djgpp/mail-archives/browse.cgi?p=djgpp-workers/2007/01/05/17:36:42

- Raw text -


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