History

Merge tag 'timers-core-2025-11-30' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull timer core updates from Thomas Gleixner: - Prevent a thundering herd problem when the timekeeper CPU is delayed and a large number of CPUs compete to acquire jiffies_lock to do the update. Limit it to one CPU with a separate "uncontended" atomic variable. - A set of improvements for the timer migration mechanism: - Support imbalanced NUMA trees correctly - Support dynamic exclusion of CPUs from the migrator duty to allow the cpuset/isolation mechanism to exclude them from handling timers of remote idle CPUs - The usual small updates, cleanups and enhancements * tag 'timers-core-2025-11-30' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: timers/migration: Exclude isolated cpus from hierarchy cpumask: Add initialiser to use cleanup helpers sched/isolation: Force housekeeping if isolcpus and nohz_full don't leave any cgroup/cpuset: Rename update_unbound_workqueue_cpumask() to update_isolation_cpumasks() timers/migration: Use scoped_guard on available flag set/clear timers/migration: Add mask for CPUs available in the hierarchy timers/migration: Rename 'online' bit to 'available' selftests/timers/nanosleep: Add tests for return of remaining time selftests/timers: Clean up kernel version check in posix_timers time: Fix a few typos in time[r] related code comments time: tick-oneshot: Add missing Return and parameter descriptions to kernel-doc hrtimer: Store time as ktime_t in restart block timers/migration: Remove dead code handling idle CPU checking for remote timers timers/migration: Remove unused "cpu" parameter from tmigr_get_group() timers/migration: Assert that hotplug preparing CPU is part of stable active hierarchy timers/migration: Fix imbalanced NUMA trees timers/migration: Remove locking on group connection timers/migration: Convert "while" loops to use "for" tick/sched: Limit non-timekeeper CPUs calling jiffies update

Linus Torvalds committed 11 months ago

Commit d42e5042 parents 5028f42 7dec06216 files · +503 −196Browse files

Unified · Split

16 files
  1. include/linux/cpumask.h +2 −0
  2. include/linux/delay.h +4 −4
  3. include/linux/restart_block.h +1 −1
  4. include/linux/timer.h +9 −0
  5. include/trace/events/timer_migration.h +2 −2
  6. kernel/cgroup/cpuset.c +9 −6
  7. kernel/sched/isolation.c +23 −0
  8. kernel/time/hrtimer.c +2 −2
  9. kernel/time/posix-cpu-timers.c +2 −2
  10. kernel/time/posix-timers.c +1 −1
  11. kernel/time/tick-oneshot.c +19 −1
  12. kernel/time/tick-sched.c +26 −4
  13. kernel/time/timer_migration.c +325 −162
  14. kernel/time/timer_migration.h +1 −1
  15. tools/testing/selftests/timers/nanosleep.c +55 −0
  16. tools/testing/selftests/timers/posix_timers.c +22 −10
include/linux/cpumask.h+2−0
@@ -1022,6 +1022,7 @@ static __always_inline unsigned int cpumask_size(void) · 1021 unmodified lines
10221022
10231023 #define this_cpu_cpumask_var_ptr(x) this_cpu_read(x)
10241024 #define __cpumask_var_read_mostly __read_mostly
1025+#define CPUMASK_VAR_NULL NULL
10251026
10261027 bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node);
10271028
@@ -1068,6 +1069,7 @@ static __always_inline bool cpumask_available(cpumask_var_t mask) · 40 unmodified lines
10681069
10691070 #define this_cpu_cpumask_var_ptr(x) this_cpu_ptr(x)
10701071 #define __cpumask_var_read_mostly
1072+#define CPUMASK_VAR_NULL {}
10711073
10721074 static __always_inline bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
10731075 {
include/linux/delay.h+4−4
@@ -68,7 +68,7 @@ void usleep_range_state(unsigned long min, unsigned long max, · 67 unmodified lines
6868 * @min: Minimum time in microseconds to sleep
6969 * @max: Maximum time in microseconds to sleep
7070 *
71− * For basic information please refere to usleep_range_state().
71+ * For basic information please refer to usleep_range_state().
7272 *
7373 * The task will be in the state TASK_UNINTERRUPTIBLE during the sleep.
7474 */
@@ -82,10 +82,10 @@ static inline void usleep_range(unsigned long min, unsigned long max) · 7 unmodified lines
8282 * @min: Minimum time in microseconds to sleep
8383 * @max: Maximum time in microseconds to sleep
8484 *
85− * For basic information please refere to usleep_range_state().
85+ * For basic information please refer to usleep_range_state().
8686 *
8787 * The sleeping task has the state TASK_IDLE during the sleep to prevent
88− * contribution to the load avarage.
88+ * contribution to the load average.
8989 */
9090 static inline void usleep_range_idle(unsigned long min, unsigned long max)
9191 {
@@ -96,7 +96,7 @@ static inline void usleep_range_idle(unsigned long min, unsigned long max) · 4 unmodified lines
9696 * ssleep - wrapper for seconds around msleep
9797 * @seconds: Requested sleep duration in seconds
9898 *
99− * Please refere to msleep() for detailed information.
99+ * Please refer to msleep() for detailed information.
100100 */
101101 static inline void ssleep(unsigned int seconds)
102102 {
include/linux/restart_block.h+1−1
@@ -43,7 +43,7 @@ struct restart_block { · 42 unmodified lines
4343 struct __kernel_timespec __user *rmtp;
4444 struct old_timespec32 __user *compat_rmtp;
4545 };
46− u64 expires;
46+ ktime_t expires;
4747 } nanosleep;
4848 /* For poll */
4949 struct {
include/linux/timer.h+9−0
@@ -188,4 +188,13 @@ int timers_dead_cpu(unsigned int cpu); · 187 unmodified lines
188188 #define timers_dead_cpu NULL
189189 #endif
190190
191+#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
192+extern int tmigr_isolated_exclude_cpumask(struct cpumask *exclude_cpumask);
193+#else
194+static inline int tmigr_isolated_exclude_cpumask(struct cpumask *exclude_cpumask)
195+{
196+ return 0;
197+}
198+#endif
199+
191200 #endif
include/trace/events/timer_migration.h+2−2
@@ -173,14 +173,14 @@ DEFINE_EVENT(tmigr_cpugroup, tmigr_cpu_active, · 172 unmodified lines
173173 TP_ARGS(tmc)
174174 );
175175
176−DEFINE_EVENT(tmigr_cpugroup, tmigr_cpu_online,
176+DEFINE_EVENT(tmigr_cpugroup, tmigr_cpu_available,
177177
178178 TP_PROTO(struct tmigr_cpu *tmc),
179179
180180 TP_ARGS(tmc)
181181 );
182182
183−DEFINE_EVENT(tmigr_cpugroup, tmigr_cpu_offline,
183+DEFINE_EVENT(tmigr_cpugroup, tmigr_cpu_unavailable,
184184
185185 TP_PROTO(struct tmigr_cpu *tmc),
186186
kernel/cgroup/cpuset.c+9−6
@@ -1391,7 +1391,7 @@ static bool partition_xcpus_del(int old_prs, struct cpuset *parent, · 1390 unmodified lines
13911391 return isolcpus_updated;
13921392 }
13931393
1394−static void update_unbound_workqueue_cpumask(bool isolcpus_updated)
1394+static void update_isolation_cpumasks(bool isolcpus_updated)
13951395 {
13961396 int ret;
13971397
@@ -1402,6 +1402,9 @@ static void update_unbound_workqueue_cpumask(bool isolcpus_updated) · 4 unmodified lines
14021402
14031403 ret = workqueue_unbound_exclude_cpumask(isolated_cpus);
14041404 WARN_ON_ONCE(ret < 0);
1405+
1406+ ret = tmigr_isolated_exclude_cpumask(isolated_cpus);
1407+ WARN_ON_ONCE(ret < 0);
14051408 }
14061409
14071410 /**
@@ -1555,7 +1558,7 @@ static int remote_partition_enable(struct cpuset *cs, int new_prs, · 147 unmodified lines
15551558 list_add(&cs->remote_sibling, &remote_children);
15561559 cpumask_copy(cs->effective_xcpus, tmp->new_cpus);
15571560 spin_unlock_irq(&callback_lock);
1558− update_unbound_workqueue_cpumask(isolcpus_updated);
1561+ update_isolation_cpumasks(isolcpus_updated);
15591562 cpuset_force_rebuild();
15601563 cs->prs_err = 0;
15611564
@@ -1596,7 +1599,7 @@ static void remote_partition_disable(struct cpuset *cs, struct tmpmasks *tmp) · 34 unmodified lines
15961599 compute_excpus(cs, cs->effective_xcpus);
15971600 reset_partition_data(cs);
15981601 spin_unlock_irq(&callback_lock);
1599− update_unbound_workqueue_cpumask(isolcpus_updated);
1602+ update_isolation_cpumasks(isolcpus_updated);
16001603 cpuset_force_rebuild();
16011604
16021605 /*
@@ -1665,7 +1668,7 @@ static void remote_cpus_update(struct cpuset *cs, struct cpumask *xcpus, · 62 unmodified lines
16651668 if (xcpus)
16661669 cpumask_copy(cs->exclusive_cpus, xcpus);
16671670 spin_unlock_irq(&callback_lock);
1668− update_unbound_workqueue_cpumask(isolcpus_updated);
1671+ update_isolation_cpumasks(isolcpus_updated);
16691672 if (adding || deleting)
16701673 cpuset_force_rebuild();
16711674
@@ -2023,7 +2026,7 @@ write_error: · 351 unmodified lines
20232026 WARN_ON_ONCE(parent->nr_subparts < 0);
20242027 }
20252028 spin_unlock_irq(&callback_lock);
2026− update_unbound_workqueue_cpumask(isolcpus_updated);
2029+ update_isolation_cpumasks(isolcpus_updated);
20272030
20282031 if ((old_prs != new_prs) && (cmd == partcmd_update))
20292032 update_partition_exclusive_flag(cs, new_prs);
@@ -3043,7 +3046,7 @@ out: · 1013 unmodified lines
30433046 else if (isolcpus_updated)
30443047 isolated_cpus_update(old_prs, new_prs, cs->effective_xcpus);
30453048 spin_unlock_irq(&callback_lock);
3046− update_unbound_workqueue_cpumask(isolcpus_updated);
3049+ update_isolation_cpumasks(isolcpus_updated);
30473050
30483051 /* Force update if switching back to member & update effective_xcpus */
30493052 update_cpumasks_hier(cs, &tmpmask, !new_prs);
kernel/sched/isolation.c+23−0
@@ -167,6 +167,29 @@ static int __init housekeeping_setup(char *str, unsigned long flags) · 166 unmodified lines
167167 }
168168 }
169169
170+ /*
171+ * Check the combination of nohz_full and isolcpus=domain,
172+ * necessary to avoid problems with the timer migration
173+ * hierarchy. managed_irq is ignored by this check since it
174+ * isn't considered in the timer migration logic.
175+ */
176+ iter_flags = housekeeping.flags & (HK_FLAG_KERNEL_NOISE | HK_FLAG_DOMAIN);
177+ type = find_first_bit(&iter_flags, HK_TYPE_MAX);
178+ /*
179+ * Pass the check if none of these flags were previously set or
180+ * are not in the current selection.
181+ */
182+ iter_flags = flags & (HK_FLAG_KERNEL_NOISE | HK_FLAG_DOMAIN);
183+ first_cpu = (type == HK_TYPE_MAX || !iter_flags) ? 0 :
184+ cpumask_first_and_and(cpu_present_mask,
185+ housekeeping_staging, housekeeping.cpumasks[type]);
186+ if (first_cpu >= min(nr_cpu_ids, setup_max_cpus)) {
187+ pr_warn("Housekeeping: must include one present CPU "
188+ "neither in nohz_full= nor in isolcpus=domain, "
189+ "ignoring setting %s\n", str);
190+ goto free_housekeeping_staging;
191+ }
192+
170193 iter_flags = flags & ~housekeeping.flags;
171194
172195 for_each_set_bit(type, &iter_flags, HK_TYPE_MAX)
kernel/time/hrtimer.c+2−2
@@ -2145,7 +2145,7 @@ static long __sched hrtimer_nanosleep_restart(struct restart_block *restart) · 2144 unmodified lines
21452145 int ret;
21462146
21472147 hrtimer_setup_sleeper_on_stack(&t, restart->nanosleep.clockid, HRTIMER_MODE_ABS);
2148− hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires);
2148+ hrtimer_set_expires(&t.timer, restart->nanosleep.expires);
21492149 ret = do_nanosleep(&t, HRTIMER_MODE_ABS);
21502150 destroy_hrtimer_on_stack(&t.timer);
21512151 return ret;
@@ -2172,7 +2172,7 @@ long hrtimer_nanosleep(ktime_t rqtp, const enum hrtimer_mode mode, · 20 unmodified lines
21722172
21732173 restart = &current->restart_block;
21742174 restart->nanosleep.clockid = t.timer.base->clockid;
2175− restart->nanosleep.expires = hrtimer_get_expires_tv64(&t.timer);
2175+ restart->nanosleep.expires = hrtimer_get_expires(&t.timer);
21762176 set_restart_fn(restart, hrtimer_nanosleep_restart);
21772177 out:
21782178 destroy_hrtimer_on_stack(&t.timer);
kernel/time/posix-cpu-timers.c+2−2
@@ -1557,7 +1557,7 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags, · 1556 unmodified lines
15571557 * Report back to the user the time still remaining.
15581558 */
15591559 restart = &current->restart_block;
1560− restart->nanosleep.expires = expires;
1560+ restart->nanosleep.expires = ns_to_ktime(expires);
15611561 if (restart->nanosleep.type != TT_NONE)
15621562 error = nanosleep_copyout(restart, &it.it_value);
15631563 }
@@ -1599,7 +1599,7 @@ static long posix_cpu_nsleep_restart(struct restart_block *restart_block) · 35 unmodified lines
15991599 clockid_t which_clock = restart_block->nanosleep.clockid;
16001600 struct timespec64 t;
16011601
1602− t = ns_to_timespec64(restart_block->nanosleep.expires);
1602+ t = ktime_to_timespec64(restart_block->nanosleep.expires);
16031603
16041604 return do_cpu_nanosleep(which_clock, TIMER_ABSTIME, &t);
16051605 }
kernel/time/posix-timers.c+1−1
@@ -1242,7 +1242,7 @@ SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock, · 1241 unmodified lines
12421242 * sys_clock_settime(). The kernel internal timekeeping is always using
12431243 * nanoseconds precision independent of the clocksource device which is
12441244 * used to read the time from. The resolution of that device only
1245− * affects the presicion of the time returned by sys_clock_gettime().
1245+ * affects the precision of the time returned by sys_clock_gettime().
12461246 *
12471247 * Returns:
12481248 * 0 Success. @tp contains the resolution
kernel/time/tick-oneshot.c+19−1
@@ -19,6 +19,10 @@ · 18 unmodified lines
1919
2020 /**
2121 * tick_program_event - program the CPU local timer device for the next event
22+ * @expires: the time at which the next timer event should occur
23+ * @force: flag to force reprograming even if the event time hasn't changed
24+ *
25+ * Return: 0 on success, negative error code on failure
2226 */
2327 int tick_program_event(ktime_t expires, int force)
2428 {
@@ -57,6 +61,13 @@ void tick_resume_oneshot(void) · 32 unmodified lines
5761
5862 /**
5963 * tick_setup_oneshot - setup the event device for oneshot mode (hres or nohz)
64+ * @newdev: Pointer to the clock event device to configure
65+ * @handler: Function to be called when the event device triggers an interrupt
66+ * @next_event: Initial expiry time for the next event (in ktime)
67+ *
68+ * Configures the specified clock event device for onshot mode,
69+ * assigns the given handler as its event callback, and programs
70+ * the device to trigger at the specified next event time.
6071 */
6172 void tick_setup_oneshot(struct clock_event_device *newdev,
6273 void (*handler)(struct clock_event_device *),
@@ -69,6 +80,10 @@ void tick_setup_oneshot(struct clock_event_device *newdev, · 6 unmodified lines
6980
7081 /**
7182 * tick_switch_to_oneshot - switch to oneshot mode
83+ * @handler: function to call when an event occurs on the tick device
84+ *
85+ * Return: 0 on success, -EINVAL if the tick device is not present,
86+ * not functional, or does not support oneshot mode.
7287 */
7388 int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *))
7489 {
@@ -101,7 +116,7 @@ int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *)) · 26 unmodified lines
101116 /**
102117 * tick_oneshot_mode_active - check whether the system is in oneshot mode
103118 *
104− * returns 1 when either nohz or highres are enabled. otherwise 0.
119+ * Return: 1 when either nohz or highres are enabled, otherwise 0.
105120 */
106121 int tick_oneshot_mode_active(void)
107122 {
@@ -120,6 +135,9 @@ int tick_oneshot_mode_active(void) · 12 unmodified lines
120135 * tick_init_highres - switch to high resolution mode
121136 *
122137 * Called with interrupts disabled.
138+ *
139+ * Return: 0 on success, -EINVAL if the tick device cannot switch
140+ * to oneshot/high-resolution mode.
123141 */
124142 int tick_init_highres(void)
125143 {
kernel/time/tick-sched.c+26−4
@@ -201,6 +201,27 @@ static inline void tick_sched_flag_clear(struct tick_sched *ts, · 200 unmodified lines
201201 ts->flags &= ~flag;
202202 }
203203
204+/*
205+ * Allow only one non-timekeeper CPU at a time update jiffies from
206+ * the timer tick.
207+ *
208+ * Returns true if update was run.
209+ */
210+static bool tick_limited_update_jiffies64(struct tick_sched *ts, ktime_t now)
211+{
212+ static atomic_t in_progress;
213+ int inp;
214+
215+ inp = atomic_read(&in_progress);
216+ if (inp || !atomic_try_cmpxchg(&in_progress, &inp, 1))
217+ return false;
218+
219+ if (ts->last_tick_jiffies == jiffies)
220+ tick_do_update_jiffies64(now);
221+ atomic_set(&in_progress, 0);
222+ return true;
223+}
224+
204225 #define MAX_STALLED_JIFFIES 5
205226
206227 static void tick_sched_do_timer(struct tick_sched *ts, ktime_t now)
@@ -239,10 +260,11 @@ static void tick_sched_do_timer(struct tick_sched *ts, ktime_t now) · 32 unmodified lines
239260 ts->stalled_jiffies = 0;
240261 ts->last_tick_jiffies = READ_ONCE(jiffies);
241262 } else {
242− if (++ts->stalled_jiffies == MAX_STALLED_JIFFIES) {
243− tick_do_update_jiffies64(now);
244− ts->stalled_jiffies = 0;
245− ts->last_tick_jiffies = READ_ONCE(jiffies);
263+ if (++ts->stalled_jiffies >= MAX_STALLED_JIFFIES) {
264+ if (tick_limited_update_jiffies64(ts, now)) {
265+ ts->stalled_jiffies = 0;
266+ ts->last_tick_jiffies = READ_ONCE(jiffies);
267+ }
246268 }
247269 }
248270
kernel/time/timer_migration.c+325−162
@@ -10,6 +10,7 @@ · 9 unmodified lines
1010 #include <linux/spinlock.h>
1111 #include <linux/timerqueue.h>
1212 #include <trace/events/ipi.h>
13+#include <linux/sched/isolation.h>
1314
1415 #include "timer_migration.h"
1516 #include "tick-internal.h"
@@ -420,14 +421,54 @@ static struct list_head *tmigr_level_list __read_mostly; · 404 unmodified lines
420421 static unsigned int tmigr_hierarchy_levels __read_mostly;
421422 static unsigned int tmigr_crossnode_level __read_mostly;
422423
424+static struct tmigr_group *tmigr_root;
425+
423426 static DEFINE_PER_CPU(struct tmigr_cpu, tmigr_cpu);
424427
428+/*
429+ * CPUs available for timer migration.
430+ * Protected by cpuset_mutex (with cpus_read_lock held) or cpus_write_lock.
431+ * Additionally tmigr_available_mutex serializes set/clear operations with each other.
432+ */
433+static cpumask_var_t tmigr_available_cpumask;
434+static DEFINE_MUTEX(tmigr_available_mutex);
435+
436+/* Enabled during late initcall */
437+static DEFINE_STATIC_KEY_FALSE(tmigr_exclude_isolated);
438+
425439 #define TMIGR_NONE 0xFF
426440 #define BIT_CNT 8
427441
428442 static inline bool tmigr_is_not_available(struct tmigr_cpu *tmc)
429443 {
430− return !(tmc->tmgroup && tmc->online);
444+ return !(tmc->tmgroup && tmc->available);
445+}
446+
447+/*
448+ * Returns true if @cpu should be excluded from the hierarchy as isolated.
449+ * Domain isolated CPUs don't participate in timer migration, nohz_full CPUs
450+ * are still part of the hierarchy but become idle (from a tick and timer
451+ * migration perspective) when they stop their tick. This lets the timekeeping
452+ * CPU handle their global timers. Marking also isolated CPUs as idle would be
453+ * too costly, hence they are completely excluded from the hierarchy.
454+ * This check is necessary, for instance, to prevent offline isolated CPUs from
455+ * being incorrectly marked as available once getting back online.
456+ *
457+ * This function returns false during early boot and the isolation logic is
458+ * enabled only after isolated CPUs are marked as unavailable at late boot.
459+ * The tick CPU can be isolated at boot, however we cannot mark it as
460+ * unavailable to avoid having no global migrator for the nohz_full CPUs. This
461+ * should be ensured by the callers of this function: implicitly from hotplug
462+ * callbacks and explicitly in tmigr_init_isolation() and
463+ * tmigr_isolated_exclude_cpumask().
464+ */
465+static inline bool tmigr_is_isolated(int cpu)
466+{
467+ if (!static_branch_unlikely(&tmigr_exclude_isolated))
468+ return false;
469+ return (!housekeeping_cpu(cpu, HK_TYPE_DOMAIN) ||
470+ cpuset_cpu_is_isolated(cpu)) &&
471+ housekeeping_cpu(cpu, HK_TYPE_KERNEL_NOISE);
431472 }
432473
433474 /*
@@ -502,11 +543,6 @@ static bool tmigr_check_lonely(struct tmigr_group *group) · 68 unmodified lines
502543 * @now: timer base monotonic
503544 * @check: is set if there is the need to handle remote timers;
504545 * required in tmigr_requires_handle_remote() only
505− * @tmc_active: this flag indicates, whether the CPU which triggers
506− * the hierarchy walk is !idle in the timer migration
507− * hierarchy. When the CPU is idle and the whole hierarchy is
508− * idle, only the first event of the top level has to be
509− * considered.
510546 */
511547 struct tmigr_walk {
512548 u64 nextexp;
@@ -517,16 +553,13 @@ struct tmigr_walk { · 4 unmodified lines
517553 unsigned long basej;
518554 u64 now;
519555 bool check;
520− bool tmc_active;
521556 };
522557
523558 typedef bool (*up_f)(struct tmigr_group *, struct tmigr_group *, struct tmigr_walk *);
524559
525−static void __walk_groups(up_f up, struct tmigr_walk *data,
526− struct tmigr_cpu *tmc)
560+static void __walk_groups_from(up_f up, struct tmigr_walk *data,
561+ struct tmigr_group *child, struct tmigr_group *group)
527562 {
528− struct tmigr_group *child = NULL, *group = tmc->tmgroup;
529−
530563 do {
531564 WARN_ON_ONCE(group->level >= tmigr_hierarchy_levels);
532565
@@ -544,6 +577,12 @@ static void __walk_groups(up_f up, struct tmigr_walk *data, · 11 unmodified lines
544577 } while (group);
545578 }
546579
580+static void __walk_groups(up_f up, struct tmigr_walk *data,
581+ struct tmigr_cpu *tmc)
582+{
583+ __walk_groups_from(up, data, NULL, tmc->tmgroup);
584+}
585+
547586 static void walk_groups(up_f up, struct tmigr_walk *data, struct tmigr_cpu *tmc)
548587 {
549588 lockdep_assert_held(&tmc->lock);
@@ -708,7 +747,7 @@ void tmigr_cpu_activate(void) · 158 unmodified lines
708747 /*
709748 * Returns true, if there is nothing to be propagated to the next level
710749 *
711− * @data->firstexp is set to expiry of first gobal event of the (top level of
750+ * @data->firstexp is set to expiry of first global event of the (top level of
712751 * the) hierarchy, but only when hierarchy is completely idle.
713752 *
714753 * The child and group states need to be read under the lock, to prevent a race
@@ -926,7 +965,7 @@ static void tmigr_handle_remote_cpu(unsigned int cpu, u64 now, · 211 unmodified lines
926965 * updated the event takes care when hierarchy is completely
927966 * idle. Otherwise the migrator does it as the event is enqueued.
928967 */
929− if (!tmc->online || tmc->remote || tmc->cpuevt.ignore ||
968+ if (!tmc->available || tmc->remote || tmc->cpuevt.ignore ||
930969 now < tmc->cpuevt.nextevt.expires) {
931970 raw_spin_unlock_irq(&tmc->lock);
932971 return;
@@ -973,7 +1012,7 @@ static void tmigr_handle_remote_cpu(unsigned int cpu, u64 now, · 40 unmodified lines
9731012 * (See also section "Required event and timerqueue update after a
9741013 * remote expiry" in the documentation at the top)
9751014 */
976− if (!tmc->online || !tmc->idle) {
1015+ if (!tmc->available || !tmc->idle) {
9771016 timer_unlock_remote_bases(cpu);
9781017 goto unlock;
9791018 }
@@ -1113,15 +1152,6 @@ static bool tmigr_requires_handle_remote_up(struct tmigr_group *group, · 133 unmodified lines
11131152 */
11141153 if (!tmigr_check_migrator(group, childmask))
11151154 return true;
1116−
1117− /*
1118− * When there is a parent group and the CPU which triggered the
1119− * hierarchy walk is not active, proceed the walk to reach the top level
1120− * group before reading the next_expiry value.
1121− */
1122− if (group->parent && !data->tmc_active)
1123− return false;
1124−
11251155 /*
11261156 * The lock is required on 32bit architectures to read the variable
11271157 * consistently with a concurrent writer. On 64bit the lock is not
@@ -1166,7 +1196,6 @@ bool tmigr_requires_handle_remote(void) · 38 unmodified lines
11661196 data.now = get_jiffies_update(&jif);
11671197 data.childmask = tmc->groupmask;
11681198 data.firstexp = KTIME_MAX;
1169− data.tmc_active = !tmc->idle;
11701199 data.check = false;
11711200
11721201 /*
@@ -1432,38 +1461,43 @@ static long tmigr_trigger_active(void *unused) · 259 unmodified lines
14321461 {
14331462 struct tmigr_cpu *tmc = this_cpu_ptr(&tmigr_cpu);
14341463
1435− WARN_ON_ONCE(!tmc->online || tmc->idle);
1464+ WARN_ON_ONCE(!tmc->available || tmc->idle);
14361465
14371466 return 0;
14381467 }
14391468
1440−static int tmigr_cpu_offline(unsigned int cpu)
1469+static int tmigr_clear_cpu_available(unsigned int cpu)
14411470 {
14421471 struct tmigr_cpu *tmc = this_cpu_ptr(&tmigr_cpu);
14431472 int migrator;
14441473 u64 firstexp;
14451474
1446− raw_spin_lock_irq(&tmc->lock);
1447− tmc->online = false;
1448− WRITE_ONCE(tmc->wakeup, KTIME_MAX);
1475+ guard(mutex)(&tmigr_available_mutex);
14491476
1450− /*
1451− * CPU has to handle the local events on his own, when on the way to
1452− * offline; Therefore nextevt value is set to KTIME_MAX
1453− */
1454− firstexp = __tmigr_cpu_deactivate(tmc, KTIME_MAX);
1455− trace_tmigr_cpu_offline(tmc);
1456− raw_spin_unlock_irq(&tmc->lock);
1477+ cpumask_clear_cpu(cpu, tmigr_available_cpumask);
1478+ scoped_guard(raw_spinlock_irq, &tmc->lock) {
1479+ if (!tmc->available)
1480+ return 0;
1481+ tmc->available = false;
1482+ WRITE_ONCE(tmc->wakeup, KTIME_MAX);
1483+
1484+ /*
1485+ * CPU has to handle the local events on his own, when on the way to
1486+ * offline; Therefore nextevt value is set to KTIME_MAX
1487+ */
1488+ firstexp = __tmigr_cpu_deactivate(tmc, KTIME_MAX);
1489+ trace_tmigr_cpu_unavailable(tmc);
1490+ }
14571491
14581492 if (firstexp != KTIME_MAX) {
1459− migrator = cpumask_any_but(cpu_online_mask, cpu);
1493+ migrator = cpumask_any(tmigr_available_cpumask);
14601494 work_on_cpu(migrator, tmigr_trigger_active, NULL);
14611495 }
14621496
14631497 return 0;
14641498 }
14651499
1466−static int tmigr_cpu_online(unsigned int cpu)
1500+static int tmigr_set_cpu_available(unsigned int cpu)
14671501 {
14681502 struct tmigr_cpu *tmc = this_cpu_ptr(&tmigr_cpu);
14691503
@@ -1471,16 +1505,123 @@ static int tmigr_cpu_online(unsigned int cpu) · 1 unmodified line
14711505 if (WARN_ON_ONCE(!tmc->tmgroup))
14721506 return -EINVAL;
14731507
1474− raw_spin_lock_irq(&tmc->lock);
1475− trace_tmigr_cpu_online(tmc);
1476− tmc->idle = timer_base_is_idle();
1477− if (!tmc->idle)
1478− __tmigr_cpu_activate(tmc);
1479− tmc->online = true;
1480− raw_spin_unlock_irq(&tmc->lock);
1508+ if (tmigr_is_isolated(cpu))
1509+ return 0;
1510+
1511+ guard(mutex)(&tmigr_available_mutex);
1512+
1513+ cpumask_set_cpu(cpu, tmigr_available_cpumask);
1514+ scoped_guard(raw_spinlock_irq, &tmc->lock) {
1515+ if (tmc->available)
1516+ return 0;
1517+ trace_tmigr_cpu_available(tmc);
1518+ tmc->idle = timer_base_is_idle();
1519+ if (!tmc->idle)
1520+ __tmigr_cpu_activate(tmc);
1521+ tmc->available = true;
1522+ }
14811523 return 0;
14821524 }
14831525
1526+static void tmigr_cpu_isolate(struct work_struct *ignored)
1527+{
1528+ tmigr_clear_cpu_available(smp_processor_id());
1529+}
1530+
1531+static void tmigr_cpu_unisolate(struct work_struct *ignored)
1532+{
1533+ tmigr_set_cpu_available(smp_processor_id());
1534+}
1535+
1536+/**
1537+ * tmigr_isolated_exclude_cpumask - Exclude given CPUs from hierarchy
1538+ * @exclude_cpumask: the cpumask to be excluded from timer migration hierarchy
1539+ *
1540+ * This function can be called from cpuset code to provide the new set of
1541+ * isolated CPUs that should be excluded from the hierarchy.
1542+ * Online CPUs not present in exclude_cpumask but already excluded are brought
1543+ * back to the hierarchy.
1544+ * Functions to isolate/unisolate need to be called locally and can sleep.
1545+ */
1546+int tmigr_isolated_exclude_cpumask(struct cpumask *exclude_cpumask)
1547+{
1548+ struct work_struct __percpu *works __free(free_percpu) =
1549+ alloc_percpu(struct work_struct);
1550+ cpumask_var_t cpumask __free(free_cpumask_var) = CPUMASK_VAR_NULL;
1551+ int cpu;
1552+
1553+ lockdep_assert_cpus_held();
1554+
1555+ if (!works)
1556+ return -ENOMEM;
1557+ if (!alloc_cpumask_var(&cpumask, GFP_KERNEL))
1558+ return -ENOMEM;
1559+
1560+ /*
1561+ * First set previously isolated CPUs as available (unisolate).
1562+ * This cpumask contains only CPUs that switched to available now.
1563+ */
1564+ cpumask_andnot(cpumask, cpu_online_mask, exclude_cpumask);
1565+ cpumask_andnot(cpumask, cpumask, tmigr_available_cpumask);
1566+
1567+ for_each_cpu(cpu, cpumask) {
1568+ struct work_struct *work = per_cpu_ptr(works, cpu);
1569+
1570+ INIT_WORK(work, tmigr_cpu_unisolate);
1571+ schedule_work_on(cpu, work);
1572+ }
1573+ for_each_cpu(cpu, cpumask)
1574+ flush_work(per_cpu_ptr(works, cpu));
1575+
1576+ /*
1577+ * Then clear previously available CPUs (isolate).
1578+ * This cpumask contains only CPUs that switched to not available now.
1579+ * There cannot be overlap with the newly available ones.
1580+ */
1581+ cpumask_and(cpumask, exclude_cpumask, tmigr_available_cpumask);
1582+ cpumask_and(cpumask, cpumask, housekeeping_cpumask(HK_TYPE_KERNEL_NOISE));
1583+ /*
1584+ * Handle this here and not in the cpuset code because exclude_cpumask
1585+ * might include also the tick CPU if included in isolcpus.
1586+ */
1587+ for_each_cpu(cpu, cpumask) {
1588+ if (!tick_nohz_cpu_hotpluggable(cpu)) {
1589+ cpumask_clear_cpu(cpu, cpumask);
1590+ break;
1591+ }
1592+ }
1593+
1594+ for_each_cpu(cpu, cpumask) {
1595+ struct work_struct *work = per_cpu_ptr(works, cpu);
1596+
1597+ INIT_WORK(work, tmigr_cpu_isolate);
1598+ schedule_work_on(cpu, work);
1599+ }
1600+ for_each_cpu(cpu, cpumask)
1601+ flush_work(per_cpu_ptr(works, cpu));
1602+
1603+ return 0;
1604+}
1605+
1606+static int __init tmigr_init_isolation(void)
1607+{
1608+ cpumask_var_t cpumask __free(free_cpumask_var) = CPUMASK_VAR_NULL;
1609+
1610+ static_branch_enable(&tmigr_exclude_isolated);
1611+
1612+ if (!housekeeping_enabled(HK_TYPE_DOMAIN))
1613+ return 0;
1614+ if (!alloc_cpumask_var(&cpumask, GFP_KERNEL))
1615+ return -ENOMEM;
1616+
1617+ cpumask_andnot(cpumask, cpu_possible_mask, housekeeping_cpumask(HK_TYPE_DOMAIN));
1618+
1619+ /* Protect against RCU torture hotplug testing */
1620+ guard(cpus_read_lock)();
1621+ return tmigr_isolated_exclude_cpumask(cpumask);
1622+}
1623+late_initcall(tmigr_init_isolation);
1624+
14841625 static void tmigr_init_group(struct tmigr_group *group, unsigned int lvl,
14851626 int node)
14861627 {
@@ -1498,21 +1639,6 @@ static void tmigr_init_group(struct tmigr_group *group, unsigned int lvl, · 11 unmodified lines
14981639 s.seq = 0;
14991640 atomic_set(&group->migr_state, s.state);
15001641
1501− /*
1502− * If this is a new top-level, prepare its groupmask in advance.
1503− * This avoids accidents where yet another new top-level is
1504− * created in the future and made visible before the current groupmask.
1505− */
1506− if (list_empty(&tmigr_level_list[lvl])) {
1507− group->groupmask = BIT(0);
1508− /*
1509− * The previous top level has prepared its groupmask already,
1510− * simply account it as the first child.
1511− */
1512− if (lvl > 0)
1513− group->num_children = 1;
1514− }
1515−
15161642 timerqueue_init_head(&group->events);
15171643 timerqueue_init(&group->groupevt.nextevt);
15181644 group->groupevt.nextevt.expires = KTIME_MAX;
@@ -1520,8 +1646,7 @@ static void tmigr_init_group(struct tmigr_group *group, unsigned int lvl, · 1 unmodified line
15201646 group->groupevt.ignore = true;
15211647 }
15221648
1523−static struct tmigr_group *tmigr_get_group(unsigned int cpu, int node,
1524− unsigned int lvl)
1649+static struct tmigr_group *tmigr_get_group(int node, unsigned int lvl)
15251650 {
15261651 struct tmigr_group *tmp, *group = NULL;
15271652
@@ -1567,25 +1692,51 @@ static struct tmigr_group *tmigr_get_group(unsigned int cpu, int node, · 39 unmodified lines
15671692 return group;
15681693 }
15691694
1695+static bool tmigr_init_root(struct tmigr_group *group, bool activate)
1696+{
1697+ if (!group->parent && group != tmigr_root) {
1698+ /*
1699+ * This is the new top-level, prepare its groupmask in advance
1700+ * to avoid accidents where yet another new top-level is
1701+ * created in the future and made visible before this groupmask.
1702+ */
1703+ group->groupmask = BIT(0);
1704+ WARN_ON_ONCE(activate);
1705+
1706+ return true;
1707+ }
1708+
1709+ return false;
1710+
1711+}
1712+
15701713 static void tmigr_connect_child_parent(struct tmigr_group *child,
15711714 struct tmigr_group *parent,
15721715 bool activate)
15731716 {
1574− struct tmigr_walk data;
1575−
1576− raw_spin_lock_irq(&child->lock);
1577− raw_spin_lock_nested(&parent->lock, SINGLE_DEPTH_NESTING);
1717+ if (tmigr_init_root(parent, activate)) {
1718+ /*
1719+ * The previous top level had prepared its groupmask already,
1720+ * simply account it in advance as the first child. If some groups
1721+ * have been created between the old and new root due to node
1722+ * mismatch, the new root's child will be intialized accordingly.
1723+ */
1724+ parent->num_children = 1;
1725+ }
15781726
1579− if (activate) {
1727+ /* Connecting old root to new root ? */
1728+ if (!parent->parent && activate) {
15801729 /*
1581− * @child is the old top and @parent the new one. In this
1582− * case groupmask is pre-initialized and @child already
1583− * accounted, along with its new sibling corresponding to the
1584− * CPU going up.
1730+ * @child is the old top, or in case of node mismatch, some
1731+ * intermediate group between the old top and the new one in
1732+ * @parent. In this case the @child must be pre-accounted above
1733+ * as the first child. Its new inactive sibling corresponding
1734+ * to the CPU going up has been accounted as the second child.
15851735 */
1586− WARN_ON_ONCE(child->groupmask != BIT(0) || parent->num_children != 2);
1736+ WARN_ON_ONCE(parent->num_children != 2);
1737+ child->groupmask = BIT(0);
15871738 } else {
1588− /* Adding @child for the CPU going up to @parent. */
1739+ /* Common case adding @child for the CPU going up to @parent. */
15891740 child->groupmask = BIT(parent->num_children++);
15901741 }
15911742
@@ -1596,87 +1747,61 @@ static void tmigr_connect_child_parent(struct tmigr_group *child, · 4 unmodified lines
15961747 */
15971748 smp_store_release(&child->parent, parent);
15981749
1599− raw_spin_unlock(&parent->lock);
1600− raw_spin_unlock_irq(&child->lock);
1601−
16021750 trace_tmigr_connect_child_parent(child);
1603−
1604− if (!activate)
1605− return;
1606−
1607− /*
1608− * To prevent inconsistent states, active children need to be active in
1609− * the new parent as well. Inactive children are already marked inactive
1610− * in the parent group:
1611− *
1612− * * When new groups were created by tmigr_setup_groups() starting from
1613− * the lowest level (and not higher then one level below the current
1614− * top level), then they are not active. They will be set active when
1615− * the new online CPU comes active.
1616− *
1617− * * But if a new group above the current top level is required, it is
1618− * mandatory to propagate the active state of the already existing
1619− * child to the new parent. So tmigr_connect_child_parent() is
1620− * executed with the formerly top level group (child) and the newly
1621− * created group (parent).
1622− *
1623− * * It is ensured that the child is active, as this setup path is
1624− * executed in hotplug prepare callback. This is exectued by an
1625− * already connected and !idle CPU. Even if all other CPUs go idle,
1626− * the CPU executing the setup will be responsible up to current top
1627− * level group. And the next time it goes inactive, it will release
1628− * the new childmask and parent to subsequent walkers through this
1629− * @child. Therefore propagate active state unconditionally.
1630− */
1631− data.childmask = child->groupmask;
1632−
1633− /*
1634− * There is only one new level per time (which is protected by
1635− * tmigr_mutex). When connecting the child and the parent and set the
1636− * child active when the parent is inactive, the parent needs to be the
1637− * uppermost level. Otherwise there went something wrong!
1638− */
1639− WARN_ON(!tmigr_active_up(parent, child, &data) && parent->parent);
16401751 }
16411752
1642−static int tmigr_setup_groups(unsigned int cpu, unsigned int node)
1753+static int tmigr_setup_groups(unsigned int cpu, unsigned int node,
1754+ struct tmigr_group *start, bool activate)
16431755 {
16441756 struct tmigr_group *group, *child, **stack;
1645− int top = 0, err = 0, i = 0;
1646− struct list_head *lvllist;
1757+ int i, top = 0, err = 0, start_lvl = 0;
1758+ bool root_mismatch = false;
16471759
16481760 stack = kcalloc(tmigr_hierarchy_levels, sizeof(*stack), GFP_KERNEL);
16491761 if (!stack)
16501762 return -ENOMEM;
16511763
1652− do {
1653− group = tmigr_get_group(cpu, node, i);
1764+ if (start) {
1765+ stack[start->level] = start;
1766+ start_lvl = start->level + 1;
1767+ }
1768+
1769+ if (tmigr_root)
1770+ root_mismatch = tmigr_root->numa_node != node;
1771+
1772+ for (i = start_lvl; i < tmigr_hierarchy_levels; i++) {
1773+ group = tmigr_get_group(node, i);
16541774 if (IS_ERR(group)) {
16551775 err = PTR_ERR(group);
1776+ i--;
16561777 break;
16571778 }
16581779
16591780 top = i;
1660− stack[i++] = group;
1781+ stack[i] = group;
16611782
16621783 /*
16631784 * When booting only less CPUs of a system than CPUs are
1664− * available, not all calculated hierarchy levels are required.
1785+ * available, not all calculated hierarchy levels are required,
1786+ * unless a node mismatch is detected.
16651787 *
16661788 * The loop is aborted as soon as the highest level, which might
16671789 * be different from tmigr_hierarchy_levels, contains only a
1668− * single group.
1790+ * single group, unless the nodes mismatch below tmigr_crossnode_level
16691791 */
1670− if (group->parent || list_is_singular(&tmigr_level_list[i - 1]))
1792+ if (group->parent)
16711793 break;
1794+ if ((!root_mismatch || i >= tmigr_crossnode_level) &&
1795+ list_is_singular(&tmigr_level_list[i]))
1796+ break;
1797+ }
16721798
1673− } while (i < tmigr_hierarchy_levels);
1674−
1675− /* Assert single root */
1676− WARN_ON_ONCE(!err && !group->parent && !list_is_singular(&tmigr_level_list[top]));
1799+ /* Assert single root without parent */
1800+ if (WARN_ON_ONCE(i >= tmigr_hierarchy_levels))
1801+ return -EINVAL;
16771802
1678− while (i > 0) {
1679− group = stack[--i];
1803+ for (; i >= start_lvl; i--) {
1804+ group = stack[i];
16801805
16811806 if (err < 0) {
16821807 list_del(&group->list);
@@ -1692,12 +1817,10 @@ static int tmigr_setup_groups(unsigned int cpu, unsigned int node) · 9 unmodified lines
16921817 if (i == 0) {
16931818 struct tmigr_cpu *tmc = per_cpu_ptr(&tmigr_cpu, cpu);
16941819
1695− raw_spin_lock_irq(&group->lock);
1696−
16971820 tmc->tmgroup = group;
16981821 tmc->groupmask = BIT(group->num_children++);
16991822
1700− raw_spin_unlock_irq(&group->lock);
1823+ tmigr_init_root(group, activate);
17011824
17021825 trace_tmigr_connect_cpu_parent(tmc);
17031826
@@ -1705,42 +1828,58 @@ static int tmigr_setup_groups(unsigned int cpu, unsigned int node) · 1 unmodified line
17051828 continue;
17061829 } else {
17071830 child = stack[i - 1];
1708− /* Will be activated at online time */
1709− tmigr_connect_child_parent(child, group, false);
1831+ tmigr_connect_child_parent(child, group, activate);
17101832 }
1833+ }
17111834
1712− /* check if uppermost level was newly created */
1713− if (top != i)
1714− continue;
1715−
1716− WARN_ON_ONCE(top == 0);
1835+ if (err < 0)
1836+ goto out;
17171837
1718− lvllist = &tmigr_level_list[top];
1838+ if (activate) {
1839+ struct tmigr_walk data;
1840+ union tmigr_state state;
17191841
17201842 /*
1721− * Newly created root level should have accounted the upcoming
1722− * CPU's child group and pre-accounted the old root.
1843+ * To prevent inconsistent states, active children need to be active in
1844+ * the new parent as well. Inactive children are already marked inactive
1845+ * in the parent group:
1846+ *
1847+ * * When new groups were created by tmigr_setup_groups() starting from
1848+ * the lowest level, then they are not active. They will be set active
1849+ * when the new online CPU comes active.
1850+ *
1851+ * * But if new groups above the current top level are required, it is
1852+ * mandatory to propagate the active state of the already existing
1853+ * child to the new parents. So tmigr_active_up() activates the
1854+ * new parents while walking up from the old root to the new.
1855+ *
1856+ * * It is ensured that @start is active, as this setup path is
1857+ * executed in hotplug prepare callback. This is executed by an
1858+ * already connected and !idle CPU. Even if all other CPUs go idle,
1859+ * the CPU executing the setup will be responsible up to current top
1860+ * level group. And the next time it goes inactive, it will release
1861+ * the new childmask and parent to subsequent walkers through this
1862+ * @child. Therefore propagate active state unconditionally.
17231863 */
1724− if (group->num_children == 2 && list_is_singular(lvllist)) {
1725− /*
1726− * The target CPU must never do the prepare work, except
1727− * on early boot when the boot CPU is the target. Otherwise
1728− * it may spuriously activate the old top level group inside
1729− * the new one (nevertheless whether old top level group is
1730− * active or not) and/or release an uninitialized childmask.
1731− */
1732− WARN_ON_ONCE(cpu == raw_smp_processor_id());
1733−
1734− lvllist = &tmigr_level_list[top - 1];
1735− list_for_each_entry(child, lvllist, list) {
1736− if (child->parent)
1737− continue;
1864+ state.state = atomic_read(&start->migr_state);
1865+ WARN_ON_ONCE(!state.active);
1866+ WARN_ON_ONCE(!start->parent);
1867+ data.childmask = start->groupmask;
1868+ __walk_groups_from(tmigr_active_up, &data, start, start->parent);
1869+ }
17381870
1739− tmigr_connect_child_parent(child, group, true);
1740− }
1871+ /* Root update */
1872+ if (list_is_singular(&tmigr_level_list[top])) {
1873+ group = list_first_entry(&tmigr_level_list[top],
1874+ typeof(*group), list);
1875+ WARN_ON_ONCE(group->parent);
1876+ if (tmigr_root) {
1877+ /* Old root should be the same or below */
1878+ WARN_ON_ONCE(tmigr_root->level > top);
17411879 }
1880+ tmigr_root = group;
17421881 }
1743−
1882+out:
17441883 kfree(stack);
17451884
17461885 return err;
@@ -1748,12 +1887,31 @@ static int tmigr_setup_groups(unsigned int cpu, unsigned int node) · 1 unmodified line
17481887
17491888 static int tmigr_add_cpu(unsigned int cpu)
17501889 {
1890+ struct tmigr_group *old_root = tmigr_root;
17511891 int node = cpu_to_node(cpu);
17521892 int ret;
17531893
1754− mutex_lock(&tmigr_mutex);
1755− ret = tmigr_setup_groups(cpu, node);
1756− mutex_unlock(&tmigr_mutex);
1894+ guard(mutex)(&tmigr_mutex);
1895+
1896+ ret = tmigr_setup_groups(cpu, node, NULL, false);
1897+
1898+ /* Root has changed? Connect the old one to the new */
1899+ if (ret >= 0 && old_root && old_root != tmigr_root) {
1900+ /*
1901+ * The target CPU must never do the prepare work, except
1902+ * on early boot when the boot CPU is the target. Otherwise
1903+ * it may spuriously activate the old top level group inside
1904+ * the new one (nevertheless whether old top level group is
1905+ * active or not) and/or release an uninitialized childmask.
1906+ */
1907+ WARN_ON_ONCE(cpu == raw_smp_processor_id());
1908+ /*
1909+ * The (likely) current CPU is expected to be online in the hierarchy,
1910+ * otherwise the old root may not be active as expected.
1911+ */
1912+ WARN_ON_ONCE(!per_cpu_ptr(&tmigr_cpu, raw_smp_processor_id())->available);
1913+ ret = tmigr_setup_groups(-1, old_root->numa_node, old_root, true);
1914+ }
17571915
17581916 return ret;
17591917 }
@@ -1798,6 +1956,11 @@ static int __init tmigr_init(void) · 38 unmodified lines
17981956 if (ncpus == 1)
17991957 return 0;
18001958
1959+ if (!zalloc_cpumask_var(&tmigr_available_cpumask, GFP_KERNEL)) {
1960+ ret = -ENOMEM;
1961+ goto err;
1962+ }
1963+
18011964 /*
18021965 * Calculate the required hierarchy levels. Unfortunately there is no
18031966 * reliable information available, unless all possible CPUs have been
@@ -1847,7 +2010,7 @@ static int __init tmigr_init(void) · 43 unmodified lines
18472010 goto err;
18482011
18492012 ret = cpuhp_setup_state(CPUHP_AP_TMIGR_ONLINE, "tmigr:online",
1850− tmigr_cpu_online, tmigr_cpu_offline);
2013+ tmigr_set_cpu_available, tmigr_clear_cpu_available);
18512014 if (ret)
18522015 goto err;
18532016
kernel/time/timer_migration.h+1−1
@@ -97,7 +97,7 @@ struct tmigr_group { · 96 unmodified lines
9797 */
9898 struct tmigr_cpu {
9999 raw_spinlock_t lock;
100− bool online;
100+ bool available;
101101 bool idle;
102102 bool remote;
103103 struct tmigr_group *tmgroup;
tools/testing/selftests/timers/nanosleep.c+55−0
@@ -116,6 +116,56 @@ int nanosleep_test(int clockid, long long ns) · 115 unmodified lines
116116 return 0;
117117 }
118118
119+static void dummy_event_handler(int val)
120+{
121+ /* No action needed */
122+}
123+
124+static int nanosleep_test_remaining(int clockid)
125+{
126+ struct timespec rqtp = {}, rmtp = {};
127+ struct itimerspec itimer = {};
128+ struct sigaction sa = {};
129+ timer_t timer;
130+ int ret;
131+
132+ sa.sa_handler = dummy_event_handler;
133+ ret = sigaction(SIGALRM, &sa, NULL);
134+ if (ret)
135+ return -1;
136+
137+ ret = timer_create(clockid, NULL, &timer);
138+ if (ret)
139+ return -1;
140+
141+ itimer.it_value.tv_nsec = NSEC_PER_SEC / 4;
142+ ret = timer_settime(timer, 0, &itimer, NULL);
143+ if (ret)
144+ return -1;
145+
146+ rqtp.tv_nsec = NSEC_PER_SEC / 2;
147+ ret = clock_nanosleep(clockid, 0, &rqtp, &rmtp);
148+ if (ret != EINTR)
149+ return -1;
150+
151+ ret = timer_delete(timer);
152+ if (ret)
153+ return -1;
154+
155+ sa.sa_handler = SIG_DFL;
156+ ret = sigaction(SIGALRM, &sa, NULL);
157+ if (ret)
158+ return -1;
159+
160+ if (!in_order((struct timespec) {}, rmtp))
161+ return -1;
162+
163+ if (!in_order(rmtp, rqtp))
164+ return -1;
165+
166+ return 0;
167+}
168+
119169 int main(int argc, char **argv)
120170 {
121171 long long length;
@@ -150,6 +200,11 @@ int main(int argc, char **argv) · 28 unmodified lines
150200 }
151201 length *= 100;
152202 }
203+ ret = nanosleep_test_remaining(clockid);
204+ if (ret < 0) {
205+ ksft_test_result_fail("%-31s\n", clockstring(clockid));
206+ ksft_exit_fail();
207+ }
153208 ksft_test_result_pass("%-31s\n", clockstring(clockid));
154209 next:
155210 ret = 0;
tools/testing/selftests/timers/posix_timers.c+22−10
@@ -18,6 +18,7 @@ · 17 unmodified lines
1818 #include <time.h>
1919 #include <include/vdso/time64.h>
2020 #include <pthread.h>
21+#include <stdbool.h>
2122
2223 #include "../kselftest.h"
2324
@@ -670,8 +671,14 @@ static void check_timer_create_exact(void) · 646 unmodified lines
670671
671672 int main(int argc, char **argv)
672673 {
674+ bool run_sig_ign_tests = ksft_min_kernel_version(6, 13);
675+
673676 ksft_print_header();
674− ksft_set_plan(19);
677+ if (run_sig_ign_tests) {
678+ ksft_set_plan(19);
679+ } else {
680+ ksft_set_plan(10);
681+ }
675682
676683 ksft_print_msg("Testing posix timers. False negative may happen on CPU execution \n");
677684 ksft_print_msg("based timers if other threads run on the CPU...\n");
@@ -695,15 +702,20 @@ int main(int argc, char **argv) · 17 unmodified lines
695702 check_timer_create(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
696703 check_timer_distribution();
697704
698− check_sig_ign(0);
699− check_sig_ign(1);
700− check_rearm();
701− check_delete();
702− check_sigev_none(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
703− check_sigev_none(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
704− check_gettime(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
705− check_gettime(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
706− check_gettime(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID");
705+ if (run_sig_ign_tests) {
706+ check_sig_ign(0);
707+ check_sig_ign(1);
708+ check_rearm();
709+ check_delete();
710+ check_sigev_none(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
711+ check_sigev_none(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
712+ check_gettime(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
713+ check_gettime(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
714+ check_gettime(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID");
715+ } else {
716+ ksft_print_msg("Skipping SIG_IGN tests on kernel < 6.13\n");
717+ }
718+
707719 check_overrun(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
708720 check_overrun(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
709721 check_overrun(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t