LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Simon Arlott <simon@fire.lp0.eu>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: Pavel Machek <pavel@ucw.cz>,
	akpm@linux-foundation.org, arjan@linux.intel.com
Subject: Re: [PATCH (update 4)] timer: Run calc_load halfway through each round_jiffies second
Date: Tue, 06 Mar 2007 18:42:39 +0000	[thread overview]
Message-ID: <45EDB61F.9050301@simon.arlott.org.uk> (raw)
In-Reply-To: <45EC9B15.6090908@simon.arlott.org.uk>

On 05/03/07 22:35, Simon Arlott wrote:
> On 01/01/02 03:05, Pavel Machek wrote:
>>> This changes calc_load so that it updates load half a second after 
>>> any tasks scheduled using round_jiffies.
>>
>> Hmm, otoh this makes calc_load more expensive, power-wise, because it
>> needs to wake the cpu once more?

I suddenly realised that since calc_load was already being called at 
second + 1 tick, moving it back 1 tick should mean it gets called and 
allowed to finish before the other tasks:

[ 1392.745730] cxacru_poll_status jiffies=1064000 [start]
[ 1392.765628] cxacru_poll_status jiffies=1064020 [finish]
[ 1393.745284] calc_load(1) jiffies=1065000 count=5000 count=5000
[ 1393.745320] cxacru_poll_status jiffies=1065000 [start]
[ 1393.754412] cxacru_poll_status jiffies=1065009 [finish]

How will this work in the presence of multiple CPUs? Will the scheduled 
task be run on another CPU while calc_load is run? I don't have anything 
I can test it on.

However since 5*HZ is unlikely to be a factor of 2^32, as soon as jiffies 
wraps a second time it will no longer be in sync:

HZ=100 0 (time after jiffies wrap that calc_load will be run)
HZ=100 4
HZ=100 8
HZ=100 12
HZ=100 16
...

It takes 3.2 *years* (increasing 40ms each time) at HZ=100 before it's 
back in sync. This would be ok for my task which is unlikely to ever take 
40ms or more to complete, but could still hit other tasks.

HZ=1000 0
HZ=1000 704
HZ=1000 408
HZ=1000 112
HZ=1000 816
...

It takes 16.9 years (jumping around, only <=40ms 4 times) at HZ=1000 
before it's back in sync.

Since calc_load is now running on the second already and this is 
preferable to different times during a second than other tasks, it can 
be rounded more easily than before:

 kernel/timer.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/timer.c b/kernel/timer.c
index 6663a87..4abead0 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -1226,17 +1226,19 @@ EXPORT_SYMBOL(avenrun);
 static inline void calc_load(unsigned long ticks)
 {
 	unsigned long active_tasks; /* fixed-point */
 	static int count = LOAD_FREQ;
 
 	count -= ticks;
-	if (unlikely(count < 0)) {
+	if (unlikely(count <= 0)) {
 		active_tasks = count_active_tasks();
 		do {
 			CALC_LOAD(avenrun[0], EXP_1, active_tasks);
 			CALC_LOAD(avenrun[1], EXP_5, active_tasks);
 			CALC_LOAD(avenrun[2], EXP_15, active_tasks);
 			count += LOAD_FREQ;
-		} while (count < 0);
+		} while (count <= 0);
+
+		count = round_jiffies_relative(count);
 	}
 }
 

-- 
Simon Arlott

  reply	other threads:[~2007-03-06 18:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-24 15:19 round_jiffies and load average Simon Arlott
2007-03-01  9:11 ` Simon Arlott
2007-03-01 18:52   ` [PATCH] timer: Add an initial 0.5s delay to calc_load Simon Arlott
2007-03-01 22:52     ` [PATCH (updated)] timer: Run calc_load halfway through each round_jiffies second Simon Arlott
2002-01-01  3:05       ` Pavel Machek
2007-03-05 22:35         ` Simon Arlott
2007-03-06 18:42           ` Simon Arlott [this message]
2007-03-06 22:20         ` Chuck Ebbert
2007-03-01 23:10       ` Bill Irwin
2007-03-02 10:15         ` [PATCH (update 2)] " Simon Arlott
2007-03-02 15:15           ` [PATCH (update 3)] " Simon Arlott
2007-03-02 16:35             ` Eric Dumazet
2007-03-02 17:32               ` Simon Arlott
2007-03-02 18:03                 ` Eric Dumazet
2007-03-02 20:14                   ` Simon Arlott
2007-03-02 22:32                     ` Eric Dumazet
2007-03-02 23:54                       ` Simon Arlott

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=45EDB61F.9050301@simon.arlott.org.uk \
    --to=simon@fire.lp0.eu \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --subject='Re: [PATCH (update 4)] timer: Run calc_load halfway through each round_jiffies second' \
    /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

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).