From: Peter Zijlstra <peterz@infradead.org>
To: Linus Walleij <linus.walleij@stericsson.com>
Cc: linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Nicolas Pitre <nico@fluxnic.net>, Colin Cross <ccross@google.com>,
John Stultz <johnstul@us.ibm.com>, Ingo Molnar <mingo@redhat.com>,
Rabin Vincent <rabin.vincent@stericsson.com>
Subject: Re: [PATCH] clocksource: document some basic concepts
Date: Mon, 15 Nov 2010 11:48:14 +0100 [thread overview]
Message-ID: <1289818094.2109.487.camel@laptop> (raw)
In-Reply-To: <1289817228-14838-1-git-send-email-linus.walleij@stericsson.com>
On Mon, 2010-11-15 at 11:33 +0100, Linus Walleij wrote:
> +sched_clock()
> +-------------
> +
> +In addition to the clock sources and clock events there is a special weak
> +function in the kernel called sched_clock(). This function shall return the
> +number of nanoseconds since the system was started. An architecture may or
> +may not provide an implementation of sched_clock() on its own.
> +
> +As the name suggests, sched_clock() is used for scheduling the system,
> +determining the absolute timeslice for a certain process in the CFS scheduler
> +for example. It is also used for printk timestamps when you have selected to
> +include time information in printk for things like bootcharts.
> +
> +Compared to clock sources, sched_clock() has to be very fast: it is called
> +much more often, especially by the scheduler. If you have to do trade-offs
> +between accuracy compared to the clock source, you may sacrifice accuracy
> +for speed in sched_clock(). It however require the same basic characteristics
> +as the clock source, i.e. it has to be monotonic.
Not so, we prefer it be synchronized and monotonic, but we don't require
so, see below.
> +The sched_clock() function may wrap only on unsigned long long boundaries,
> +i.e. after 64 bits. Since this is a nanosecond value this will mean it wraps
> +after circa 585 years. (For most practical systems this means "never".)
Currently true, John Stultz was going to look into ammending this by
teaching the kernel/sched_clock.c bits about early wraps (and a way for
architectures to specify this)
#define SCHED_CLOCK_WRAP_BITS 48
...
#ifdef SCHED_CLOCK_WRAP_BITS
/* handle short wraps */
#endif
foo for wrap_min/wrap_max and "delta = now - scd->tick_raw" like things
might work.
> +If an architecture does not provide its own implementation of this function,
> +it will fall back to using jiffies, making its maximum resolution 1/HZ of the
> +jiffy frequency for the architecture. This will affect scheduling accuracy
> +and will likely show up in system benchmarks.
sched_clock() need not be synchronized between CPUs, nor even be
monotonic, we prefer a fast high res clock over a slow one,
CONFIG_HAVE_UNSTABLE_SCHED_CLOCK provides infrastructure to sanitize the
output of sched_clock().
[ of course we prefer a fast and synchronized clock, but we take fast
over synchronized ]
sched_clock() requires local IRQs to be disabled.
Therefore, sched_clock() shall not be used, see kernel/sched_clock.c for
detail and alternative interfaces.
next prev parent reply other threads:[~2010-11-15 10:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-15 10:33 [PATCH] clocksource: document some basic concepts Linus Walleij
2010-11-15 10:48 ` Peter Zijlstra [this message]
2010-11-15 10:50 ` Peter Zijlstra
2010-11-15 19:48 ` john stultz
2010-11-15 20:06 ` Nicolas Pitre
2010-11-15 21:13 ` Peter Zijlstra
2010-11-15 16:34 ` Randy Dunlap
2010-11-15 19:45 ` john stultz
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=1289818094.2109.487.camel@laptop \
--to=peterz@infradead.org \
--cc=ccross@google.com \
--cc=johnstul@us.ibm.com \
--cc=linus.walleij@stericsson.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=nico@fluxnic.net \
--cc=rabin.vincent@stericsson.com \
--cc=tglx@linutronix.de \
/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.