[Vm-dev] microsecond timing for GC work

John M McIntosh johnmci at smalltalkconsulting.com
Tue Jan 19 18:54:35 UTC 2010


Ok, we maybe Ian can comment since the the code for the millisecond clock has been start at zero. 

Also if we return a value starting at epoch then we'll always end up with a large integer object which is costly and on base squeak systems could trigger a GC event, right
now we just end up with a small integer at least for a few day(s)... 

Perhaps we could look at having  two primitives one to return the microsecond clock from image startup, the other to return it from epoch start? 

Also the ioSecond primitive has been based on localTime versus  time() as per the Unix VM code below. 




time_t convertToSqueakTime(time_t unixTime)
{
#ifdef HAVE_TM_GMTOFF
  unixTime+= localtime(&unixTime)->tm_gmtoff;
#else
# ifdef HAVE_TIMEZONE
  unixTime+= ((daylight) * 60*60) - timezone;
# else
#  error: cannot determine timezone correction
# endif
#endif
  /* Squeak epoch is Jan 1, 1901.  Unix epoch is Jan 1, 1970: 17 leap years
     and 52 non-leap years later than Squeak. */
  return unixTime + ((52*365UL + 17*366UL) * 24*60*60UL);
}

/* returns the local wall clock time */
sqInt ioSeconds(void)
{
  return convertToSqueakTime(time(0));
}

--------------------------------------

On OS-X I do 

sqInt ioSeconds(void) {
	//API Documented
	time_t unixTime;
	sqInt	theSecondsAre; 
	
	unixTime = time(0);
	unixTime += localtime(&unixTime)->tm_gmtoff;
	/* Squeak epoch is Jan 1, 1901.  Unix epoch is Jan 1, 1970: 17 leap years
	 and 52 non-leap years later than Squeak. */
	theSecondsAre = unixTime + ((52*365UL + 17*366UL) * 24*60*60UL);
	return theSecondsAre;
}


The original C code written by John Maloney did the following and has a most fascinating issue, anyone care to guess? 
I even opened an official bug with Apple on it and 20 months later got a curt reply from an Apple/NeXt unix engineer.

int ioSeconds(void) {
	/* return the time in seconds since midnight of Jan 1, 1901.  */
	/* optional: could simply return 0.  */

	struct tm timeRec;
	time_t time1904, timeNow;

	/* start of ANSI epoch is midnight of Jan 1, 1904 */
	timeRec.tm_sec   = 0;
	timeRec.tm_min   = 0;
	timeRec.tm_hour  = 0;
	timeRec.tm_mday  = 1;
	timeRec.tm_mon   = 0;
	timeRec.tm_year  = 4;
	timeRec.tm_wday  = 0;
	timeRec.tm_yday  = 0;
	timeRec.tm_isdst = 0;
	time1904 = mktime(&timeRec);

	timeNow = time(NULL);

	/* Squeak epoch is Jan 1, 1901, 3 non-leap years earlier than ANSI one */
	return (timeNow - time1904) + (3 * 365 * 24 * 60 * 60);
}




On 2010-01-19, at 9:26 AM, Eliot Miranda wrote:

> Please keep to the Smalltalk epoch (start of the 20th century, 12am January 1 1901).  Then deriving the second clock from the microsecond clock requires only division, not division and subtraction.  Small point, but keep it as simple as possible.  i.e. the Smalltalk code for the second clock could read ^self microsecondClock // 1000000, with the VM losing the secondClock primitive.
> 
> 
> Dave
> 

--
===========================================================================
John M. McIntosh <johnmci at smalltalkconsulting.com>   Twitter:  squeaker68882
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20100119/0c9c4b45/attachment-0001.htm


More information about the Vm-dev mailing list