Skip to content

Commit a831881

Browse files
committed
nohz: Basic full dynticks interface
For extreme usecases such as Real Time or HPC, having the ability to shutdown the tick when a single task runs on a CPU is a desired feature: * Reducing the amount of interrupts improves throughput for CPU-bound tasks. The CPU is less distracted from its real job, from an execution time and from the cache point of views. * This also improve latency response as we have less critical sections. Start with introducing a very simple interface to define full dynticks CPU: use a boot time option defined cpumask through the "nohz_extended=" kernel parameter. CPUs that are part of this range will have their tick shutdown whenever possible: provided they run a single task and they don't do kernel activity that require the periodic tick. These details will be later documented in Documentation/* An online CPU must be kept outside this range to handle the timekeeping. Suggested-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Chris Metcalf <cmetcalf@tilera.com> Cc: Christoph Lameter <cl@linux.com> Cc: Geoff Levand <geoff@infradead.org> Cc: Gilad Ben Yossef <gilad@benyossef.com> Cc: Hakan Akkan <hakanakkan@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Kevin Hilman <khilman@linaro.org> Cc: Li Zhong <zhong@linux.vnet.ibm.com> Cc: Namhyung Kim <namhyung.kim@lge.com> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Paul Gortmaker <paul.gortmaker@windriver.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de>
1 parent a8d7ad5 commit a831881

4 files changed

Lines changed: 94 additions & 0 deletions

File tree

‎Documentation/kernel-parameters.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,6 +1913,12 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
19131913
Valid arguments: on, off
19141914
Default: on
19151915

1916+
nohz_extended= [KNL,BOOT]
1917+
In kernels built with CONFIG_NO_HZ_EXTENDED=y, set
1918+
the specified list of CPUs whose tick will be stopped
1919+
whenever possible. You need to keep at least one online
1920+
CPU outside the range to maintain the timekeeping.
1921+
19161922
noiotrap [SH] Disables trapped I/O port accesses.
19171923

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

‎include/linux/tick.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
157157
static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
158158
# endif /* !NO_HZ */
159159

160+
#ifdef CONFIG_NO_HZ_EXTENDED
161+
extern int tick_nohz_extended_cpu(int cpu);
162+
#else
163+
static inline int tick_nohz_extended_cpu(int cpu) { return 0; }
164+
#endif
165+
166+
160167
# ifdef CONFIG_CPU_IDLE_GOV_MENU
161168
extern void menu_hrtimer_cancel(void);
162169
# else

‎kernel/time/Kconfig‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,25 @@ config NO_HZ
7979
only trigger on an as-needed basis both when the system is
8080
busy and when the system is idle.
8181

82+
config NO_HZ_EXTENDED
83+
bool "Full dynticks system"
84+
depends on NO_HZ && RCU_USER_QS && VIRT_CPU_ACCOUNTING_GEN && RCU_NOCB_CPU && SMP
85+
select CONTEXT_TRACKING_FORCE
86+
help
87+
Adaptively try to shutdown the tick whenever possible, even when
88+
the CPU is running tasks. Typically this requires running a single
89+
task on the CPU. Chances for running tickless are maximized when
90+
the task mostly runs in userspace and has few kernel activity.
91+
92+
You need to fill up the nohz_extended boot parameter with the
93+
desired range of dynticks CPUs.
94+
95+
This is implemented at the expense of some overhead in user <-> kernel
96+
transitions: syscalls, exceptions and interrupts. Even when it's
97+
dynamically off.
98+
99+
Say N.
100+
82101
config HIGH_RES_TIMERS
83102
bool "High Resolution Timer Support"
84103
depends on !ARCH_USES_GETTIMEOFFSET && GENERIC_CLOCKEVENTS

‎kernel/time/tick-sched.c‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,68 @@ static void tick_sched_handle(struct tick_sched *ts, struct pt_regs *regs)
142142
profile_tick(CPU_PROFILING);
143143
}
144144

145+
#ifdef CONFIG_NO_HZ_EXTENDED
146+
static cpumask_var_t nohz_extended_mask;
147+
bool have_nohz_extended_mask;
148+
149+
int tick_nohz_extended_cpu(int cpu)
150+
{
151+
if (!have_nohz_extended_mask)
152+
return 0;
153+
154+
return cpumask_test_cpu(cpu, nohz_extended_mask);
155+
}
156+
157+
/* Parse the boot-time nohz CPU list from the kernel parameters. */
158+
static int __init tick_nohz_extended_setup(char *str)
159+
{
160+
alloc_bootmem_cpumask_var(&nohz_extended_mask);
161+
if (cpulist_parse(str, nohz_extended_mask) < 0)
162+
pr_warning("NOHZ: Incorrect nohz_extended cpumask\n");
163+
else
164+
have_nohz_extended_mask = true;
165+
return 1;
166+
}
167+
__setup("nohz_extended=", tick_nohz_extended_setup);
168+
169+
static int __init init_tick_nohz_extended(void)
170+
{
171+
cpumask_var_t online_nohz;
172+
int cpu;
173+
174+
if (!have_nohz_extended_mask)
175+
return 0;
176+
177+
if (!zalloc_cpumask_var(&online_nohz, GFP_KERNEL)) {
178+
pr_warning("NO_HZ: Not enough memory to check extended nohz mask\n");
179+
return -ENOMEM;
180+
}
181+
182+
/*
183+
* CPUs can probably not be concurrently offlined on initcall time.
184+
* But we are paranoid, aren't we?
185+
*/
186+
get_online_cpus();
187+
188+
/* Ensure we keep a CPU outside the dynticks range for timekeeping */
189+
cpumask_and(online_nohz, cpu_online_mask, nohz_extended_mask);
190+
if (cpumask_equal(online_nohz, cpu_online_mask)) {
191+
cpu = cpumask_any(cpu_online_mask);
192+
pr_warning("NO_HZ: Must keep at least one online CPU "
193+
"out of nohz_extended range\n");
194+
pr_warning("NO_HZ: Clearing %d from nohz_extended range\n", cpu);
195+
cpumask_clear_cpu(cpu, nohz_extended_mask);
196+
}
197+
put_online_cpus();
198+
free_cpumask_var(online_nohz);
199+
200+
return 0;
201+
}
202+
core_initcall(init_tick_nohz_extended);
203+
#else
204+
#define have_nohz_extended_mask (0)
205+
#endif
206+
145207
/*
146208
* NOHZ - aka dynamic tick functionality
147209
*/

0 commit comments

Comments
 (0)