sched/isolation: Make the housekeeping cpumask private
[linux-2.6-block.git] / kernel / sched / isolation.c
1 /*
2  *  Housekeeping management. Manage the targets for routine code that can run on
3  *  any CPU: unbound workqueues, timers, kthreads and any offloadable work.
4  *
5  * Copyright (C) 2017 Red Hat, Inc., Frederic Weisbecker
6  *
7  */
8
9 #include <linux/sched/isolation.h>
10 #include <linux/tick.h>
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13
14 static cpumask_var_t housekeeping_mask;
15
16 int housekeeping_any_cpu(void)
17 {
18         if (tick_nohz_full_enabled())
19                 return cpumask_any_and(housekeeping_mask, cpu_online_mask);
20
21         return smp_processor_id();
22 }
23 EXPORT_SYMBOL_GPL(housekeeping_any_cpu);
24
25 const struct cpumask *housekeeping_cpumask(void)
26 {
27         if (tick_nohz_full_enabled())
28                 return housekeeping_mask;
29
30         return cpu_possible_mask;
31 }
32 EXPORT_SYMBOL_GPL(housekeeping_cpumask);
33
34 void housekeeping_affine(struct task_struct *t)
35 {
36         if (tick_nohz_full_enabled())
37                 set_cpus_allowed_ptr(t, housekeeping_mask);
38 }
39 EXPORT_SYMBOL_GPL(housekeeping_affine);
40
41 bool housekeeping_test_cpu(int cpu)
42 {
43         if (tick_nohz_full_enabled())
44                 return cpumask_test_cpu(cpu, housekeeping_mask);
45
46         return true;
47 }
48 EXPORT_SYMBOL_GPL(housekeeping_test_cpu);
49
50 void __init housekeeping_init(void)
51 {
52         if (!tick_nohz_full_enabled())
53                 return;
54
55         if (!alloc_cpumask_var(&housekeeping_mask, GFP_KERNEL)) {
56                 WARN(1, "NO_HZ: Can't allocate not-full dynticks cpumask\n");
57                 cpumask_clear(tick_nohz_full_mask);
58                 tick_nohz_full_running = false;
59                 return;
60         }
61
62         cpumask_andnot(housekeeping_mask,
63                        cpu_possible_mask, tick_nohz_full_mask);
64
65         /* We need at least one CPU to handle housekeeping work */
66         WARN_ON_ONCE(cpumask_empty(housekeeping_mask));
67 }