9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: cinap_lenrek@gmx.de
To: 9fans@9fans.net
Subject: Re: [9fans] fossil periodic thread does zero sleep()
Date: Mon, 23 Mar 2009 01:52:45 +0100	[thread overview]
Message-ID: <a5ec93342b820ee31072481987411c2f@gmx.de> (raw)
In-Reply-To: <fb31fd1a5a64c0bf6f85af88838face3@quanstro.net>

[-- Attachment #1: Type: text/plain, Size: 609 bytes --]

I have no idea what HZ is used on my kernel, but i think
i understand the problem now.

I still can reproduce it with this:

	double t, ct, ts;

	ct = nsec()*1e-6;
	t = ct + msec;

	for(;;){
		ts = t - ct;
		sleep(ts);
		ct = nsec()*1e-6;
		if(t <= ct){
			t += msec;
		}
	}

The problem is that when sleep is a little bit too fast on every round,
t will never catch up with ct. so it sleeps shorter and shorter until
t - ct < 1.

It all works when changing t += msec to t = ct + msec. It may still
do a zero sleep, but the error will not add up.

making new kernel...

--
cinap

[-- Attachment #2: Type: message/rfc822, Size: 2133 bytes --]

From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@9fans.net
Subject: Re: [9fans] fossil periodic thread does zero sleep()
Date: Sun, 22 Mar 2009 20:24:17 -0400
Message-ID: <fb31fd1a5a64c0bf6f85af88838face3@quanstro.net>

what is your HZ set at?  after chasing a few bugs like this,
i've set HZ=1000.  actually i first saw the idea in sam hopins'
work  there's no performance drag and 1 ms
sleeps do actually sleep.

- erik

  reply	other threads:[~2009-03-23  0:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-22 23:13 cinap_lenrek
2009-03-22 23:41 ` erik quanstrom
2009-03-23  0:16   ` cinap_lenrek
2009-03-23  0:24     ` erik quanstrom
2009-03-23  0:52       ` cinap_lenrek [this message]
2009-03-23  0:54         ` erik quanstrom
2009-03-23  4:04     ` ron minnich
2009-03-23 13:27       ` ron minnich
2009-03-23  0:24   ` cinap_lenrek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a5ec93342b820ee31072481987411c2f@gmx.de \
    --to=cinap_lenrek@gmx.de \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).