DragonFly BSD
DragonFly bugs List (threaded) for 2004-01
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: My newyear's resolution is...


From: Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 6 Jan 2004 22:31:02 -0800 (PST)

:>     API, but there is still an issue with the last bit of your kern_time.c
:>     patch:
:>
:>     +		if (tv.tv_sec == 0 && tv.tv_usec < tick)
:>     +			return (0);
:>
:>     The problem is that this may break the guarentee that it sleeps at least
:>     as long as requested.
:
:That's what the (sleepticks < 1)? contitional in nanosleep()
:checked for.  I moved the guarantee out of tvtohz() up to
:nanosleep() where it "should be".
:
:-Paul.

    That just prevents the tick value from being zero, because otherwise
    tsleep() will not sleep at all.  It doesn't fix the guarentee problem
    due to the possibility of a clock interrupt occuring just a few
    microseconds after tsleep(.... 1) is called, causing tsleep to sleep
    far less then 1 tick (or up to almost one tick less then N ticks if N
    is passed to tsleep()).  The comparison above would then cause the 
    loop to terminate too early.

    e.g. if you tsleep for 5 ticks the earliest tsleep can return is going
    to be just over 4 ticks later.

    clock interrupt:	*-------*------*-------*------*------*
    tsleep:                   ^                              RETURN
			    BEGIN

	actual sleep time for tsleep(....5) == 4.1 ticks.

    This is probably why the original tvtohz() routine returned N+1, but I
    agree that that is not the correct place to put it.  tvtohz() should
    return the correct calculation.

					-Matt
					Matthew Dillon 
					<dillon@xxxxxxxxxxxxx>



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