[Prev][Next][Index][Thread]

Re: sleep function



> From: Andrew Lipnitsky <ert@cit.org.by>
> Subject: Re: sleep function
> Date: Wed, 25 Apr 2001 17:30:33 +0300
> 
> > Well, thats odd. What happens when you try to make the timer or timer_com
> > example in examples/x86 directory? Do they run okay?
> 
> Timer, timer_com and timer_com2 examples work as expected.

Sorry for the delay. I was out of the office for a few days.

So, the problem is rather embarassing. The minimal C library impl of sleep
does a clock spin, which means it is based on the oskit clock interface,
which implements spin in terms of the oskit timer interface (which is the
actual interface to the raw hardware). I know, sounds contorted.

The problem is that the timer spin function is limited to 2^32 nanoseconds,
so the longest sleep you get is kinda short! You can either switch to the
FreeBSD C library (typically my choice for any oskit work), or you can
apply this incredibly simple (and in this case, incredibly stupid) patch to
libc/gen/sleep.c.

Hope this works for ya.
Lbs

Index: sleep.c
===================================================================
RCS file: /usr/lsrc/flux/CVS/oskit/libc/gen/sleep.c,v
retrieving revision 1.1
diff -c -r1.1 sleep.c
*** sleep.c	1999/04/22 18:56:28	1.1
--- sleep.c	2001/04/27 16:39:41
***************
*** 27,37 ****
  	if (!sys_clock && !posixlib_clock_init())
  		return seconds;
  
! 	time.tv_nsec = 0;
! 	time.tv_sec = seconds;
  
! 	oskit_clock_spin(sys_clock, &time);
  
  	return 0;
  }
  
--- 27,44 ----
  	if (!sys_clock && !posixlib_clock_init())
  		return seconds;
  
! 	/*
! 	 * oskit_clock_spin based on osenv_timer_spin, which is limited
! 	 * to 2^32 nanoseconds.
! 	 */
! 	while (seconds) {
! 		time.tv_nsec = 0;
! 		time.tv_sec  = 1;
  
! 		oskit_clock_spin(sys_clock, &time);
  
+ 		seconds--;
+ 	}
  	return 0;
  }
  

Follow-Ups: References: