mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Mauricio Lin" <mauriciolin@gmail.com>
To: balbir@in.ibm.com
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: Jiffies wraparound is not treated in the schedstats
Date: Thu, 9 Nov 2006 10:35:53 -0400	[thread overview]
Message-ID: <3f250c710611090635j530e7f02q7a84d367fa2ab41c@mail.gmail.com> (raw)
In-Reply-To: <4552CAD9.1080603@in.ibm.com>

Hi Balbir,

I did not know about arithmetic properties of the unsigned types, so
the misundertanding about jiffies calculation. It was my mistake.

On 11/9/06, Balbir Singh <balbir@in.ibm.com> wrote:
> Mauricio Lin wrote:
> > Hi Balbir,
> >
> > Do you know why in the sched_info_arrive() and sched_info_depart()
> > functions the calculation of delta_jiffies does not use the time_after
> > or time_before macro to prevent  the miscalculation when jiffies
> > overflow?
> >
> > For instance the delta_jiffies variable is simply calculated as:
> >
> > delta_jiffies = now - t->sched_info.last_queued;
> >
> > Do not you think the more logical way should be
> >
> > if (time_after(now, t->sched_info.last_queued))
> >    delta_jiffies = now - t->sched_info.last_queued;
> > else
> >    delta_jiffies = (MAX_JIFFIES - t->sched_info.last_queued) + now
> >
>
> What's MAX_JIFFIES? Is it MAX_ULONG? jiffies is unsigned long
> so you'll have to be careful with unsigned long arithmetic.

It is ULONG_MAX. :)

>
> Consider that now is 5 and t->sched_info.last_queued is 10.
>
> On my system
>
> perl -e '{printf("%lu\n", -5 + (1<<32) - 1);}'
> 4294967291
>
> perl -e '{printf("%lu\n", -5 );}'
> 4294967291
>
>
> > I have included more variables to measure some issues of schedule in
> > the kernel (following schedstat idea) and I noticed that jiffies
> > wraparound has led to wrong values, since the user space tool when
> > collecting the values is producing negative values.
> >
>
> hmm.. jiffies wrapped around in sched_info_depart()? I've never seen
> that happen. Could you post the additions and user space tool to look at?
> What additional features are you planning to measure in the scheduler?

Well, one of the behaviour we would like to check its the time that
the system remains idle. As the schedstat already provide the
sched_goidle (number of time the system gets idle), during the
measurements we would like to know also the time spent in the idle
state.

Checking the results, perhaps such new info is not necessary to be
included if we want the percentage of use in our measurements. For
instance if we want the cpu_load calculated as:

cpu_load = (cpu_time2 - cpu_time1)/sample_period

where "cpu_time" corresponds to the rq->rq_sched_info.cpu_time in the
kernel and "sample period" is the time spent running the use case.

So the "cpu_idle_load" can be calculated as (1-cpu_load).

If we include in the __sched_info_switch() (kernel) something like:

...
	if (prev != rq->idle)
		sched_info_depart(prev);
	else
		rq->rq_sched_info.idle_time +=
			jiffies - prev->sched_info.last_arrival;

	if (next != rq->idle)
		sched_info_arrive(next);
	else
		next->sched_info.last_arrival = jiffies;
...

We can calculated the cpu_idle_load at user space as:

cpu_idle_load = (cpu_idle_time2 - cpu_idle_time1)/sample_period

where cpu_idle_time corresponds to rq->rq_sched_info.idle_time

This info leads to the same result if we just base the calculation on
the (1-cpu_load) as mentioned previously.

BR,

Mauricio Lin.

  parent reply	other threads:[~2006-11-09 14:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-08 18:05 Mauricio Lin
2006-11-09  6:29 ` Balbir Singh
2006-11-09  6:45   ` Balbir Singh
2006-11-09 14:35   ` Mauricio Lin [this message]
2007-05-30  4:03   ` Oleg Verych
2006-11-08 19:01 Kaz Kylheku

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=3f250c710611090635j530e7f02q7a84d367fa2ab41c@mail.gmail.com \
    --to=mauriciolin@gmail.com \
    --cc=balbir@in.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®