From: Martin Schwidefsky <schwidefsky@de.ibm.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
Michael Abbott <michael@araneidae.co.uk>,
Jan Engelhardt <jengelh@medozas.de>
Subject: Re: [GIT PULL] cputime patch for 2.6.30-rc6
Date: Mon, 25 May 2009 13:35:04 +0200 [thread overview]
Message-ID: <20090525133504.62c3a6d7@skybase> (raw)
In-Reply-To: <1243249766.26820.665.camel@twins>
On Mon, 25 May 2009 13:09:26 +0200
Peter Zijlstra <peterz@infradead.org> wrote:
> On Mon, 2009-05-25 at 12:50 +0200, Martin Schwidefsky wrote:
> > On Tue, 19 May 2009 11:00:35 +0200
> > Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > > So, I'm really not objecting too much to the patch at hand, but I'd love
> > > to find a solution to this problem.
> >
> > It is not hard so solve the problem for /proc/uptime, e.g. like this:
> >
> > static u64 uptime_jiffies = INITIAL_JIFFIES;
> > static struct timespec ts_uptime;
> > static struct timespec ts_idle;
> >
> > static int uptime_proc_show(struct seq_file *m, void *v)
> > {
> > cputime_t idletime;
> > u64 now;
> > int i;
> >
> > now = get_jiffies_64();
> > if (uptime_jiffies != now) {
> > uptime_jiffies = now;
> > idletime = cputime_zero;
> > for_each_possible_cpu(i)
> > idletime = cputime64_add(idletime,
> > kstat_cpu(i).cpustat.idle);
> > do_posix_clock_monotonic_gettime(&ts_uptime);
> > monotonic_to_bootbased(&ts_uptime);
> > cputime_to_timespec(idletime, &ts_idle);
> > }
> >
> > seq_printf(m, "%lu.%02lu %lu.%02lu\n",
> > (unsigned long) ts_uptime.tv_sec,
> > (ts_uptime.tv_nsec / (NSEC_PER_SEC / 100)),
> > (unsigned long) ts_idle.tv_sec,
> > (ts_idle.tv_nsec / (NSEC_PER_SEC / 100)));
> > return 0;
> > }
> >
> > For /proc/stat it is less clear. Just storing the values in static
> > variables is not such a good idea as there are lots of values.
> > 10*NR_CPUS + NR_IRQS values to be exact. With NR_CPUS in the thousands
> > this will waste quite a bit of memory.
>
> Right, I know of for_each_possible_cpu() loops that took longer than a
> jiffy and caused general melt-down -- not saying the loop for idle time
> will be one such a loop, but then it seems silly anyway, who's
> incrementing the idle time when we're idle?
Psst, I do ;-) Look at the arch_idle_time macro in fs/proc/stat.c..
> I really prefer using things like percpu_counter/vmstat that have error
> bounds that scale with the number of cpus in the system.
>
> We simply have to start educating people that numbers on the global
> state of the machine are inaccurate (they were anyway, because by the
> time the userspace bits that read the /proc file get scheduled again the
> numbers will have changed again).
That is one problem, the other is that the values you'll get are not
atomic in any way. Not even the totals in /proc/stat match the sum over
the cpus.
> There's a variant of Heisenberg's uncertainty principle applicable to
> (parallel) computers in that one either gets concurrency or accuracy on
> global state, you cannot have both.
If the time you need to generate a value is longer than the maximum
error you do have a problem.
--
blue skies,
Martin.
"Reality continues to ruin my life." - Calvin.
next prev parent reply other threads:[~2009-05-25 11:36 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-18 14:09 [GIT PULL] cputime patch for 2.6.30-rc6 Martin Schwidefsky
2009-05-18 15:24 ` Peter Zijlstra
2009-05-18 16:28 ` Michael Abbott
2009-05-19 9:00 ` Martin Schwidefsky
2009-05-19 9:31 ` Peter Zijlstra
2009-05-20 8:09 ` Martin Schwidefsky
2009-05-20 8:19 ` Peter Zijlstra
2009-05-20 8:44 ` Michael Abbott
2009-05-25 11:06 ` Martin Schwidefsky
2009-05-19 8:49 ` Martin Schwidefsky
2009-05-19 9:00 ` Peter Zijlstra
2009-05-25 10:50 ` Martin Schwidefsky
2009-05-25 11:09 ` Peter Zijlstra
2009-05-25 11:24 ` Jan Engelhardt
2009-05-25 11:35 ` Martin Schwidefsky [this message]
2009-05-19 13:32 ` Jan Engelhardt
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=20090525133504.62c3a6d7@skybase \
--to=schwidefsky@de.ibm.com \
--cc=jengelh@medozas.de \
--cc=linux-kernel@vger.kernel.org \
--cc=michael@araneidae.co.uk \
--cc=peterz@infradead.org \
--cc=torvalds@linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.