Skip to content

Commit 534c97b

Browse files
committed
Merge branch 'timers-nohz-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull 'full dynticks' support from Ingo Molnar: "This tree from Frederic Weisbecker adds a new, (exciting! :-) core kernel feature to the timer and scheduler subsystems: 'full dynticks', or CONFIG_NO_HZ_FULL=y. This feature extends the nohz variable-size timer tick feature from idle to busy CPUs (running at most one task) as well, potentially reducing the number of timer interrupts significantly. This feature got motivated by real-time folks and the -rt tree, but the general utility and motivation of full-dynticks runs wider than that: - HPC workloads get faster: CPUs running a single task should be able to utilize a maximum amount of CPU power. A periodic timer tick at HZ=1000 can cause a constant overhead of up to 1.0%. This feature removes that overhead - and speeds up the system by 0.5%-1.0% on typical distro configs even on modern systems. - Real-time workload latency reduction: CPUs running critical tasks should experience as little jitter as possible. The last remaining source of kernel-related jitter was the periodic timer tick. - A single task executing on a CPU is a pretty common situation, especially with an increasing number of cores/CPUs, so this feature helps desktop and mobile workloads as well. The cost of the feature is mainly related to increased timer reprogramming overhead when a CPU switches its tick period, and thus slightly longer to-idle and from-idle latency. Configuration-wise a third mode of operation is added to the existing two NOHZ kconfig modes: - CONFIG_HZ_PERIODIC: [formerly !CONFIG_NO_HZ], now explicitly named as a config option. This is the traditional Linux periodic tick design: there's a HZ tick going on all the time, regardless of whether a CPU is idle or not. - CONFIG_NO_HZ_IDLE: [formerly CONFIG_NO_HZ=y], this turns off the periodic tick when a CPU enters idle mode. - CONFIG_NO_HZ_FULL: this new mode, in addition to turning off the tick when a CPU is idle, also slows the tick down to 1 Hz (one timer interrupt per second) when only a single task is running on a CPU. The .config behavior is compatible: existing !CONFIG_NO_HZ and CONFIG_NO_HZ=y settings get translated to the new values, without the user having to configure anything. CONFIG_NO_HZ_FULL is turned off by default. This feature is based on a lot of infrastructure work that has been steadily going upstream in the last 2-3 cycles: related RCU support and non-periodic cputime support in particular is upstream already. This tree adds the final pieces and activates the feature. The pull request is marked RFC because: - it's marked 64-bit only at the moment - the 32-bit support patch is small but did not get ready in time. - it has a number of fresh commits that came in after the merge window. The overwhelming majority of commits are from before the merge window, but still some aspects of the tree are fresh and so I marked it RFC. - it's a pretty wide-reaching feature with lots of effects - and while the components have been in testing for some time, the full combination is still not very widely used. That it's default-off should reduce its regression abilities and obviously there are no known regressions with CONFIG_NO_HZ_FULL=y enabled either. - the feature is not completely idempotent: there is no 100% equivalent replacement for a periodic scheduler/timer tick. In particular there's ongoing work to map out and reduce its effects on scheduler load-balancing and statistics. This should not impact correctness though, there are no known regressions related to this feature at this point. - it's a pretty ambitious feature that with time will likely be enabled by most Linux distros, and we'd like you to make input on its design/implementation, if you dislike some aspect we missed. Without flaming us to crisp! :-) Future plans: - there's ongoing work to reduce 1Hz to 0Hz, to essentially shut off the periodic tick altogether when there's a single busy task on a CPU. We'd first like 1 Hz to be exposed more widely before we go for the 0 Hz target though. - once we reach 0 Hz we can remove the periodic tick assumption from nr_running>=2 as well, by essentially interrupting busy tasks only as frequently as the sched_latency constraints require us to do - once every 4-40 msecs, depending on nr_running. I am personally leaning towards biting the bullet and doing this in v3.10, like the -rt tree this effort has been going on for too long - but the final word is up to you as usual. More technical details can be found in Documentation/timers/NO_HZ.txt" * 'timers-nohz-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (39 commits) sched: Keep at least 1 tick per second for active dynticks tasks rcu: Fix full dynticks' dependency on wide RCU nocb mode nohz: Protect smp_processor_id() in tick_nohz_task_switch() nohz_full: Add documentation. cputime_nsecs: use math64.h for nsec resolution conversion helpers nohz: Select VIRT_CPU_ACCOUNTING_GEN from full dynticks config nohz: Reduce overhead under high-freq idling patterns nohz: Remove full dynticks' superfluous dependency on RCU tree nohz: Fix unavailable tick_stop tracepoint in dynticks idle nohz: Add basic tracing nohz: Select wide RCU nocb for full dynticks nohz: Disable the tick when irq resume in full dynticks CPU nohz: Re-evaluate the tick for the new task after a context switch nohz: Prepare to stop the tick on irq exit nohz: Implement full dynticks kick nohz: Re-evaluate the tick from the scheduler IPI sched: New helper to prevent from stopping the tick in full dynticks sched: Kick full dynticks CPU that have more than one task enqueued. perf: New helper to prevent full dynticks CPUs from stopping tick perf: Kick full dynticks CPU if events rotation is needed ...
2 parents 64049d1 + 265f22a commit 534c97b

31 files changed

+990
-119
lines changed

Documentation/RCU/stallwarn.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ o A CPU-bound real-time task in a CONFIG_PREEMPT_RT kernel that
191191
o A hardware or software issue shuts off the scheduler-clock
192192
interrupt on a CPU that is not in dyntick-idle mode. This
193193
problem really has happened, and seems to be most likely to
194-
result in RCU CPU stall warnings for CONFIG_NO_HZ=n kernels.
194+
result in RCU CPU stall warnings for CONFIG_NO_HZ_COMMON=n kernels.
195195

196196
o A bug in the RCU implementation.
197197

Documentation/cpu-freq/governors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ sampling_rate_min:
131131
The sampling rate is limited by the HW transition latency:
132132
transition_latency * 100
133133
Or by kernel restrictions:
134-
If CONFIG_NO_HZ is set, the limit is 10ms fixed.
135-
If CONFIG_NO_HZ is not set or nohz=off boot parameter is used, the
134+
If CONFIG_NO_HZ_COMMON is set, the limit is 10ms fixed.
135+
If CONFIG_NO_HZ_COMMON is not set or nohz=off boot parameter is used, the
136136
limits depend on the CONFIG_HZ option:
137137
HZ=1000: min=20000us (20ms)
138138
HZ=250: min=80000us (80ms)

Documentation/kernel-parameters.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,6 +1964,14 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
19641964
Valid arguments: on, off
19651965
Default: on
19661966

1967+
nohz_full= [KNL,BOOT]
1968+
In kernels built with CONFIG_NO_HZ_FULL=y, set
1969+
the specified list of CPUs whose tick will be stopped
1970+
whenever possible. The boot CPU will be forced outside
1971+
the range to maintain the timekeeping.
1972+
The CPUs in this range must also be included in the
1973+
rcu_nocbs= set.
1974+
19671975
noiotrap [SH] Disables trapped I/O port accesses.
19681976

19691977
noirqdebug [X86-32] Disables the code which attempts to detect and

Documentation/timers/NO_HZ.txt

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
NO_HZ: Reducing Scheduling-Clock Ticks
2+
3+
4+
This document describes Kconfig options and boot parameters that can
5+
reduce the number of scheduling-clock interrupts, thereby improving energy
6+
efficiency and reducing OS jitter. Reducing OS jitter is important for
7+
some types of computationally intensive high-performance computing (HPC)
8+
applications and for real-time applications.
9+
10+
There are two main contexts in which the number of scheduling-clock
11+
interrupts can be reduced compared to the old-school approach of sending
12+
a scheduling-clock interrupt to all CPUs every jiffy whether they need
13+
it or not (CONFIG_HZ_PERIODIC=y or CONFIG_NO_HZ=n for older kernels):
14+
15+
1. Idle CPUs (CONFIG_NO_HZ_IDLE=y or CONFIG_NO_HZ=y for older kernels).
16+
17+
2. CPUs having only one runnable task (CONFIG_NO_HZ_FULL=y).
18+
19+
These two cases are described in the following two sections, followed
20+
by a third section on RCU-specific considerations and a fourth and final
21+
section listing known issues.
22+
23+
24+
IDLE CPUs
25+
26+
If a CPU is idle, there is little point in sending it a scheduling-clock
27+
interrupt. After all, the primary purpose of a scheduling-clock interrupt
28+
is to force a busy CPU to shift its attention among multiple duties,
29+
and an idle CPU has no duties to shift its attention among.
30+
31+
The CONFIG_NO_HZ_IDLE=y Kconfig option causes the kernel to avoid sending
32+
scheduling-clock interrupts to idle CPUs, which is critically important
33+
both to battery-powered devices and to highly virtualized mainframes.
34+
A battery-powered device running a CONFIG_HZ_PERIODIC=y kernel would
35+
drain its battery very quickly, easily 2-3 times as fast as would the
36+
same device running a CONFIG_NO_HZ_IDLE=y kernel. A mainframe running
37+
1,500 OS instances might find that half of its CPU time was consumed by
38+
unnecessary scheduling-clock interrupts. In these situations, there
39+
is strong motivation to avoid sending scheduling-clock interrupts to
40+
idle CPUs. That said, dyntick-idle mode is not free:
41+
42+
1. It increases the number of instructions executed on the path
43+
to and from the idle loop.
44+
45+
2. On many architectures, dyntick-idle mode also increases the
46+
number of expensive clock-reprogramming operations.
47+
48+
Therefore, systems with aggressive real-time response constraints often
49+
run CONFIG_HZ_PERIODIC=y kernels (or CONFIG_NO_HZ=n for older kernels)
50+
in order to avoid degrading from-idle transition latencies.
51+
52+
An idle CPU that is not receiving scheduling-clock interrupts is said to
53+
be "dyntick-idle", "in dyntick-idle mode", "in nohz mode", or "running
54+
tickless". The remainder of this document will use "dyntick-idle mode".
55+
56+
There is also a boot parameter "nohz=" that can be used to disable
57+
dyntick-idle mode in CONFIG_NO_HZ_IDLE=y kernels by specifying "nohz=off".
58+
By default, CONFIG_NO_HZ_IDLE=y kernels boot with "nohz=on", enabling
59+
dyntick-idle mode.
60+
61+
62+
CPUs WITH ONLY ONE RUNNABLE TASK
63+
64+
If a CPU has only one runnable task, there is little point in sending it
65+
a scheduling-clock interrupt because there is no other task to switch to.
66+
67+
The CONFIG_NO_HZ_FULL=y Kconfig option causes the kernel to avoid
68+
sending scheduling-clock interrupts to CPUs with a single runnable task,
69+
and such CPUs are said to be "adaptive-ticks CPUs". This is important
70+
for applications with aggressive real-time response constraints because
71+
it allows them to improve their worst-case response times by the maximum
72+
duration of a scheduling-clock interrupt. It is also important for
73+
computationally intensive short-iteration workloads: If any CPU is
74+
delayed during a given iteration, all the other CPUs will be forced to
75+
wait idle while the delayed CPU finishes. Thus, the delay is multiplied
76+
by one less than the number of CPUs. In these situations, there is
77+
again strong motivation to avoid sending scheduling-clock interrupts.
78+
79+
By default, no CPU will be an adaptive-ticks CPU. The "nohz_full="
80+
boot parameter specifies the adaptive-ticks CPUs. For example,
81+
"nohz_full=1,6-8" says that CPUs 1, 6, 7, and 8 are to be adaptive-ticks
82+
CPUs. Note that you are prohibited from marking all of the CPUs as
83+
adaptive-tick CPUs: At least one non-adaptive-tick CPU must remain
84+
online to handle timekeeping tasks in order to ensure that system calls
85+
like gettimeofday() returns accurate values on adaptive-tick CPUs.
86+
(This is not an issue for CONFIG_NO_HZ_IDLE=y because there are no
87+
running user processes to observe slight drifts in clock rate.)
88+
Therefore, the boot CPU is prohibited from entering adaptive-ticks
89+
mode. Specifying a "nohz_full=" mask that includes the boot CPU will
90+
result in a boot-time error message, and the boot CPU will be removed
91+
from the mask.
92+
93+
Alternatively, the CONFIG_NO_HZ_FULL_ALL=y Kconfig parameter specifies
94+
that all CPUs other than the boot CPU are adaptive-ticks CPUs. This
95+
Kconfig parameter will be overridden by the "nohz_full=" boot parameter,
96+
so that if both the CONFIG_NO_HZ_FULL_ALL=y Kconfig parameter and
97+
the "nohz_full=1" boot parameter is specified, the boot parameter will
98+
prevail so that only CPU 1 will be an adaptive-ticks CPU.
99+
100+
Finally, adaptive-ticks CPUs must have their RCU callbacks offloaded.
101+
This is covered in the "RCU IMPLICATIONS" section below.
102+
103+
Normally, a CPU remains in adaptive-ticks mode as long as possible.
104+
In particular, transitioning to kernel mode does not automatically change
105+
the mode. Instead, the CPU will exit adaptive-ticks mode only if needed,
106+
for example, if that CPU enqueues an RCU callback.
107+
108+
Just as with dyntick-idle mode, the benefits of adaptive-tick mode do
109+
not come for free:
110+
111+
1. CONFIG_NO_HZ_FULL selects CONFIG_NO_HZ_COMMON, so you cannot run
112+
adaptive ticks without also running dyntick idle. This dependency
113+
extends down into the implementation, so that all of the costs
114+
of CONFIG_NO_HZ_IDLE are also incurred by CONFIG_NO_HZ_FULL.
115+
116+
2. The user/kernel transitions are slightly more expensive due
117+
to the need to inform kernel subsystems (such as RCU) about
118+
the change in mode.
119+
120+
3. POSIX CPU timers on adaptive-tick CPUs may miss their deadlines
121+
(perhaps indefinitely) because they currently rely on
122+
scheduling-tick interrupts. This will likely be fixed in
123+
one of two ways: (1) Prevent CPUs with POSIX CPU timers from
124+
entering adaptive-tick mode, or (2) Use hrtimers or other
125+
adaptive-ticks-immune mechanism to cause the POSIX CPU timer to
126+
fire properly.
127+
128+
4. If there are more perf events pending than the hardware can
129+
accommodate, they are normally round-robined so as to collect
130+
all of them over time. Adaptive-tick mode may prevent this
131+
round-robining from happening. This will likely be fixed by
132+
preventing CPUs with large numbers of perf events pending from
133+
entering adaptive-tick mode.
134+
135+
5. Scheduler statistics for adaptive-tick CPUs may be computed
136+
slightly differently than those for non-adaptive-tick CPUs.
137+
This might in turn perturb load-balancing of real-time tasks.
138+
139+
6. The LB_BIAS scheduler feature is disabled by adaptive ticks.
140+
141+
Although improvements are expected over time, adaptive ticks is quite
142+
useful for many types of real-time and compute-intensive applications.
143+
However, the drawbacks listed above mean that adaptive ticks should not
144+
(yet) be enabled by default.
145+
146+
147+
RCU IMPLICATIONS
148+
149+
There are situations in which idle CPUs cannot be permitted to
150+
enter either dyntick-idle mode or adaptive-tick mode, the most
151+
common being when that CPU has RCU callbacks pending.
152+
153+
The CONFIG_RCU_FAST_NO_HZ=y Kconfig option may be used to cause such CPUs
154+
to enter dyntick-idle mode or adaptive-tick mode anyway. In this case,
155+
a timer will awaken these CPUs every four jiffies in order to ensure
156+
that the RCU callbacks are processed in a timely fashion.
157+
158+
Another approach is to offload RCU callback processing to "rcuo" kthreads
159+
using the CONFIG_RCU_NOCB_CPU=y Kconfig option. The specific CPUs to
160+
offload may be selected via several methods:
161+
162+
1. One of three mutually exclusive Kconfig options specify a
163+
build-time default for the CPUs to offload:
164+
165+
a. The CONFIG_RCU_NOCB_CPU_NONE=y Kconfig option results in
166+
no CPUs being offloaded.
167+
168+
b. The CONFIG_RCU_NOCB_CPU_ZERO=y Kconfig option causes
169+
CPU 0 to be offloaded.
170+
171+
c. The CONFIG_RCU_NOCB_CPU_ALL=y Kconfig option causes all
172+
CPUs to be offloaded. Note that the callbacks will be
173+
offloaded to "rcuo" kthreads, and that those kthreads
174+
will in fact run on some CPU. However, this approach
175+
gives fine-grained control on exactly which CPUs the
176+
callbacks run on, along with their scheduling priority
177+
(including the default of SCHED_OTHER), and it further
178+
allows this control to be varied dynamically at runtime.
179+
180+
2. The "rcu_nocbs=" kernel boot parameter, which takes a comma-separated
181+
list of CPUs and CPU ranges, for example, "1,3-5" selects CPUs 1,
182+
3, 4, and 5. The specified CPUs will be offloaded in addition to
183+
any CPUs specified as offloaded by CONFIG_RCU_NOCB_CPU_ZERO=y or
184+
CONFIG_RCU_NOCB_CPU_ALL=y. This means that the "rcu_nocbs=" boot
185+
parameter has no effect for kernels built with RCU_NOCB_CPU_ALL=y.
186+
187+
The offloaded CPUs will never queue RCU callbacks, and therefore RCU
188+
never prevents offloaded CPUs from entering either dyntick-idle mode
189+
or adaptive-tick mode. That said, note that it is up to userspace to
190+
pin the "rcuo" kthreads to specific CPUs if desired. Otherwise, the
191+
scheduler will decide where to run them, which might or might not be
192+
where you want them to run.
193+
194+
195+
KNOWN ISSUES
196+
197+
o Dyntick-idle slows transitions to and from idle slightly.
198+
In practice, this has not been a problem except for the most
199+
aggressive real-time workloads, which have the option of disabling
200+
dyntick-idle mode, an option that most of them take. However,
201+
some workloads will no doubt want to use adaptive ticks to
202+
eliminate scheduling-clock interrupt latencies. Here are some
203+
options for these workloads:
204+
205+
a. Use PMQOS from userspace to inform the kernel of your
206+
latency requirements (preferred).
207+
208+
b. On x86 systems, use the "idle=mwait" boot parameter.
209+
210+
c. On x86 systems, use the "intel_idle.max_cstate=" to limit
211+
` the maximum C-state depth.
212+
213+
d. On x86 systems, use the "idle=poll" boot parameter.
214+
However, please note that use of this parameter can cause
215+
your CPU to overheat, which may cause thermal throttling
216+
to degrade your latencies -- and that this degradation can
217+
be even worse than that of dyntick-idle. Furthermore,
218+
this parameter effectively disables Turbo Mode on Intel
219+
CPUs, which can significantly reduce maximum performance.
220+
221+
o Adaptive-ticks slows user/kernel transitions slightly.
222+
This is not expected to be a problem for computationally intensive
223+
workloads, which have few such transitions. Careful benchmarking
224+
will be required to determine whether or not other workloads
225+
are significantly affected by this effect.
226+
227+
o Adaptive-ticks does not do anything unless there is only one
228+
runnable task for a given CPU, even though there are a number
229+
of other situations where the scheduling-clock tick is not
230+
needed. To give but one example, consider a CPU that has one
231+
runnable high-priority SCHED_FIFO task and an arbitrary number
232+
of low-priority SCHED_OTHER tasks. In this case, the CPU is
233+
required to run the SCHED_FIFO task until it either blocks or
234+
some other higher-priority task awakens on (or is assigned to)
235+
this CPU, so there is no point in sending a scheduling-clock
236+
interrupt to this CPU. However, the current implementation
237+
nevertheless sends scheduling-clock interrupts to CPUs having a
238+
single runnable SCHED_FIFO task and multiple runnable SCHED_OTHER
239+
tasks, even though these interrupts are unnecessary.
240+
241+
Better handling of these sorts of situations is future work.
242+
243+
o A reboot is required to reconfigure both adaptive idle and RCU
244+
callback offloading. Runtime reconfiguration could be provided
245+
if needed, however, due to the complexity of reconfiguring RCU at
246+
runtime, there would need to be an earthshakingly good reason.
247+
Especially given that you have the straightforward option of
248+
simply offloading RCU callbacks from all CPUs and pinning them
249+
where you want them whenever you want them pinned.
250+
251+
o Additional configuration is required to deal with other sources
252+
of OS jitter, including interrupts and system-utility tasks
253+
and processes. This configuration normally involves binding
254+
interrupts and tasks to particular CPUs.
255+
256+
o Some sources of OS jitter can currently be eliminated only by
257+
constraining the workload. For example, the only way to eliminate
258+
OS jitter due to global TLB shootdowns is to avoid the unmapping
259+
operations (such as kernel module unload operations) that
260+
result in these shootdowns. For another example, page faults
261+
and TLB misses can be reduced (and in some cases eliminated) by
262+
using huge pages and by constraining the amount of memory used
263+
by the application. Pre-faulting the working set can also be
264+
helpful, especially when combined with the mlock() and mlockall()
265+
system calls.
266+
267+
o Unless all CPUs are idle, at least one CPU must keep the
268+
scheduling-clock interrupt going in order to support accurate
269+
timekeeping.
270+
271+
o If there are adaptive-ticks CPUs, there will be at least one
272+
CPU keeping the scheduling-clock interrupt going, even if all
273+
CPUs are otherwise idle.

arch/um/include/shared/common-offsets.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ DEFINE(UM_NSEC_PER_USEC, NSEC_PER_USEC);
3030
#ifdef CONFIG_PRINTK
3131
DEFINE(UML_CONFIG_PRINTK, CONFIG_PRINTK);
3232
#endif
33-
#ifdef CONFIG_NO_HZ
34-
DEFINE(UML_CONFIG_NO_HZ, CONFIG_NO_HZ);
33+
#ifdef CONFIG_NO_HZ_COMMON
34+
DEFINE(UML_CONFIG_NO_HZ_COMMON, CONFIG_NO_HZ_COMMON);
3535
#endif
3636
#ifdef CONFIG_UML_X86
3737
DEFINE(UML_CONFIG_UML_X86, CONFIG_UML_X86);

arch/um/os-Linux/time.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ long long os_nsecs(void)
7979
return timeval_to_ns(&tv);
8080
}
8181

82-
#ifdef UML_CONFIG_NO_HZ
82+
#ifdef UML_CONFIG_NO_HZ_COMMON
8383
static int after_sleep_interval(struct timespec *ts)
8484
{
8585
return 0;

0 commit comments

Comments
 (0)