timers: Exclude isolated cpus from timer migation
Subsystems (5)
PATCH 1/1 timers: Exclude isolated cpus from timer migation
The timer migration mechanism allows timers to move from idle CPUs to active ones to improve the overall idle time. This is however undesired when CPU intensive workloads run on isolated cores, as the algorithm would move the timers from housekeeping to isolated cores, negatively affecting the isolation.
Exclude isolated cores from the timer migration algorithm, extend the concept of unavailable cores, currently used for offline ones, to isolated ones:
* A core is unavailable if isolated or offline;
* A core is available if isolated and offline;
Keep a cpumap to easily track unavailable cores and change the concept of online/offline tmigr to available/unavailable in code and tracepoints.
A core is considered unavailable as idle if:
* is in the isolcpus list
* is in the nohz_full list
* is in an isolated cpuset
--- include/linux/timer.h | 6 +++ include/trace/events/timer_migration.h | 4 +- kernel/cgroup/cpuset.c | 15 +++--- kernel/time/timer_migration.c | 72 +++++++++++++++++++++----- kernel/time/timer_migration.h | 2 +- 5 files changed, 76 insertions(+), 23 deletions(-)
include/linux/timer.h +6 -0
@@ -190,4 +190,10 @@ int timers_dead_cpu(unsigned int cpu);#define timers_dead_cpu NULL#endif +#if defined(CONFIG_SMP ) && defined(CONFIG_NO_HZ_COMMON ) +extern int tmigr_isolated_exclude_cpumask (cpumask_var_t exclude_cpumask); +#else +static inline int tmigr_isolated_exclude_cpumask (cpumask_var_t exclude_cpumask) { } +#endif +#endif
include/trace/events/timer_migration.h +2 -2
@@ -173,14 +173,14 @@ DEFINE_EVENT(tmigr_cpugroup, tmigr_cpu_active,TP_ARGS (tmc) ); -DEFINE_EVENT (tmigr_cpugroup, tmigr_cpu_online, +DEFINE_EVENT (tmigr_cpugroup, tmigr_cpu_available, TP_PROTO(struct tmigr_cpu *tmc),TP_ARGS (tmc) ); -DEFINE_EVENT(tmigr_cpugroup, tmigr_cpu_offline, +DEFINE_EVENT(tmigr_cpugroup, tmigr_cpu_unavailable, TP_PROTO(struct tmigr_cpu *tmc),
kernel/cgroup/cpuset.c +9 -6
@@ -1323,7 +1323,7 @@ static bool partition_xcpus_del(int old_prs, struct cpuset *parent,return isolcpus_updated; } -static void update_unbound_workqueue_cpumask (bool isolcpus_updated) +static void update_unbound_interference_cpumask (bool isolcpus_updated) {int ret;
@@ -1334,6 +1334,9 @@ static void update_unbound_workqueue_cpumask(bool isolcpus_updated) ret =workqueue_unbound_exclude_cpumask (isolated_cpus);WARN_ON_ONCE (ret <0 ); + + ret =tmigr_isolated_exclude_cpumask (isolated_cpus); +WARN_ON_ONCE (ret <0 ); }/**
@@ -1454,7 +1457,7 @@ static int remote_partition_enable(struct cpuset *cs, int new_prs,list_add (&cs->remote_sibling, &remote_children);cpumask_copy (cs->effective_xcpus, tmp->new_cpus);spin_unlock_irq (&callback_lock); -update_unbound_workqueue_cpumask (isolcpus_updated); +update_unbound_interference_cpumask (isolcpus_updated);cpuset_force_rebuild (); cs->prs_err =0 ;
@@ -1495,7 +1498,7 @@ static void remote_partition_disable(struct cpuset *cs, struct tmpmasks *tmp)compute_effective_exclusive_cpumask (cs,NULL ,NULL );reset_partition_data (cs);spin_unlock_irq (&callback_lock); -update_unbound_workqueue_cpumask (isolcpus_updated); +update_unbound_interference_cpumask (isolcpus_updated);cpuset_force_rebuild ();/*
@@ -1563,7 +1566,7 @@ static void remote_cpus_update(struct cpuset *cs, struct cpumask *xcpus,if (xcpus)cpumask_copy (cs->exclusive_cpus, xcpus);spin_unlock_irq (&callback_lock); -update_unbound_workqueue_cpumask (isolcpus_updated); +update_unbound_interference_cpumask (isolcpus_updated);if (adding || deleting)cpuset_force_rebuild ();
@@ -1906,7 +1909,7 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,WARN_ON_ONCE (parent->nr_subparts <0 ); }spin_unlock_irq (&callback_lock); -update_unbound_workqueue_cpumask (isolcpus_updated); +update_unbound_interference_cpumask (isolcpus_updated);if ((old_prs != new_prs) && (cmd == partcmd_update))update_partition_exclusive_flag (cs, new_prs);
@@ -2931,7 +2934,7 @@ static int update_prstate(struct cpuset *cs, int new_prs)else if (isolcpus_updated)isolated_cpus_update (old_prs, new_prs, cs->effective_xcpus);spin_unlock_irq (&callback_lock); -update_unbound_workqueue_cpumask (isolcpus_updated); +update_unbound_interference_cpumask (isolcpus_updated);/* Force update if switching back to member & update effective_xcpus */ update_cpumasks_hier (cs, &tmpmask, !new_prs);
kernel/time/timer_migration.c +58 -14
158 lines not on this page · raw message
kernel/time/timer_migration.h +1 -1
@@ -97,7 +97,7 @@ struct tmigr_group {*/ struct tmigr_cpu {raw_spinlock_t lock; -bool online; +bool available;bool idle;bool remote;struct tmigr_group *tmgroup;
base-commit: 3b07108ada81a8ebcebf1fe61367b4e436c895bd
Signature · 1 line
2.49.0
kernel/time/timer_migration.c static unsigned int tmigr_crossnode_level __read_mostly; · line 427
Quoted 3 lines · Gabriele Monaco
kernel/time/timer_migration.c +2
-0+/* cpumask excluded from migration */ +static cpumask_var_t tmigr_unavailable_cpumask;
Why is this a negated mask instead of being the obvious and intuitive available mask?
kernel/time/timer_migration.c static long tmigr_trigger_active(void *unused) · line 1468
Quoted 4 lines
kernel/time/timer_migration.c +2
-1if (firstexp !=KTIME_MAX ) { - migrator =cpumask_any_but (cpu_online_mask, cpu); + migrator =cpumask_nth_andnot (0 , cpu_possible_mask, + tmigr_unavailable_cpumask);
That's exactly what this negated mask causes: incomprehensible code.
cpumask_clear_cpu(cpu, available_mask);
...
migrator = cpumask_first(available_mask);is too simple and obvious, right?
kernel/time/timer_migration.c static long tmigr_trigger_active(void *unused) · line 1469
Quoted 1 line
kernel/time/timer_migration.c +1
-0+/* Fall back to any online in case all are isolated. */
How can that happen? There is always at least _ONE_ housekeeping, non-isolated, CPU online, no?
Quoted 9 lines
kernel/time/timer_migration.c +2
-1+if (migrator >= nr_cpu_ids) + migrator =cpumask_any_but (cpu_online_mask, cpu);work_on_cpu (migrator, tmigr_trigger_active,NULL ); }return 0 ; } -static int tmigr_cpu_online (unsigned int cpu)
kernel/time/timer_migration.c static long tmigr_trigger_active(void *unused) · line 1486
Quoted 10 lines
kernel/time/timer_migration.c +3
-1+static int tmigr_cpu_available (unsigned int cpu) { -struct tmigr_cpu *tmc =this_cpu_ptr (&tmigr_cpu); +struct tmigr_cpu *tmc =per_cpu_ptr (&tmigr_cpu, cpu);/* Check whether CPU data was successfully initialized */ if (WARN_ON_ONCE (!tmc->tmgroup))return -EINVAL ; +/* Silently ignore online requests if isolated */
This comment makes no sense.
/* Isolated CPUs are not participating in timer migration */
makes it entirely clear what this is about, no?
That brings me to the general design decision here. Your changelog explains at great length WHAT the change is doing, but completely fails to explain the consequences and the rationale why this is the right thing to do.
By excluding the isolated CPUs from migration completely, any 'global' timer, which is armed on such a CPU, has to be expired on that isolated CPU. That's fundamentaly different from e.g. RCU isolation.
It might be the right thing to do and harmless, but without a proper explanation it's a silent side effect of your changes, which leaves people scratching their heads.
kernel/time/timer_migration.c static long tmigr_trigger_active(void *unused) · line 1495
Quoted 11 lines
kernel/time/timer_migration.c +5
-2+if (cpu_is_isolated (cpu)) +return 0 ;raw_spin_lock_irq (&tmc->lock); -trace_tmigr_cpu_online (tmc); +trace_tmigr_cpu_available (tmc); tmc->idle =timer_base_is_idle ();if (!tmc->idle)__tmigr_cpu_activate (tmc); - tmc->online = true; + tmc->available = true; + tmc->idle = true;
How so?
kernel/time/timer_migration.c static long tmigr_trigger_active(void *unused) · line 1501
Quoted 6 lines
kernel/time/timer_migration.c +2
-0+cpumask_clear_cpu (cpu, tmigr_unavailable_cpumask);raw_spin_unlock_irq (&tmc->lock);return 0 ; } +int tmigr_isolated_exclude_cpumask (cpumask_var_t exclude_cpumask)
cpumask_var_t is wrong here. 'const struct cpumask *' is what you want.
kernel/time/timer_migration.c static long tmigr_trigger_active(void *unused) · line 1504
Quoted 3 lines
kernel/time/timer_migration.c +3
-0+{ +int cpu; +cpumask_var_t cpumask;
https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#coding-style-notes
kernel/time/timer_migration.c static long tmigr_trigger_active(void *unused) · line 1509
Quoted 4 lines
kernel/time/timer_migration.c +4
-0+if (!zalloc_cpumask_var (&cpumask,GFP_KERNEL )) +return -ENOMEM ; + +cpumask_copy (cpumask, tmigr_unavailable_cpumask);
What serializes this against concurrent CPU hotplug? I assume it's done by the caller, but then this code should have a lockdep assert to validate it. If it's not, then this is broken.
As it is serialized it does not need a copy either, right?
kernel/time/timer_migration.c static long tmigr_trigger_active(void *unused) · line 1518
Quoted 8 lines
kernel/time/timer_migration.c +8
-0+/* Was not excluded but should be excluded now. */ +for_each_cpu_andnot (cpu, exclude_cpumask, cpumask) +tmigr_cpu_unavailable (cpu); + +/* Was excluded but should be included now */ +for_each_cpu_andnot (cpu, cpumask, exclude_cpumask) +if (cpu_online (cpu)) +tmigr_cpu_available (cpu);
My brain hurts by now.
for_each_cpu_and(cpu, available_mask, exclude_mask)
tmigr_cpu_unavailable(cpu);
for_each_cpu_andnot(cpu, cpu_online_mask, exclude_mask) {
if (!cpumask_test_cpu(cpu, available_mask))
tmigr_cpu_available(cpu);
}No?
Also this patch is doing too many things at once. It want's to be split into:
Patch 1: Rename 'online' to 'available' (bit and function names) Patch 2: Add the available mask logic
Patch 3: Add the isolation functionality
Thanks,
tglx
Quoted 7 lines · Thomas Gleixner
kernel/time/timer_migration.c static unsigned int tmigr_crossnode_level __read_mostly; · line 427
Quoted 3 lines · Gabriele Monaco
kernel/time/timer_migration.c +2
-0+/* cpumask excluded from migration */ +static cpumask_var_t tmigr_unavailable_cpumask;Why is this a negated mask instead of being the obvious and intuitive available mask?
Well, the way I started writing the patch I found it easier to do the double andnot in tmigr_isolated_exclude_cpumask to see what changed. I see the way it evolved is just messier..
I'll apply your solution which seems much neater!
Quoted 12 lines
Quoted 5 lines
if (firstexp !=
KTIME_MAX) {
- migrator =cpumask_any_but(cpu_online_mask, cpu);
+ migrator = cpumask_nth_andnot(0,cpu_possible_mask,
+tmigr_unavailable_cpumask);That's exactly what this negated mask causes: incomprehensible code.
cpumask_clear_cpu(cpu, available_mask);
...
migrator =cpumask_first(available_mask);
Quoted 7 lines
is too simple and obvious, right?
Quoted 1 line
+ /* Fall back to any online in case all are isolated. */
How can that happen? There is always at least _ONE_ housekeeping, non-isolated, CPU online, no?
In my understanding it shouldn't, but I'm not sure there's anything preventing the user from isolating everything via cpuset. Anyway that's something no one in their mind should do, so I guess I'd just opt for the cpumask_first (or actually cpumask_any, like before the change).
Quoted 38 lines
Quoted 11 lines
+ if (migrator >=
nr_cpu_ids)
+ migrator =cpumask_any_but(cpu_online_mask, cpu);work_on_cpu(migrator, tmigr_trigger_active, NULL); }
return 0;
}kernel/time/timer_migration.c +1
-1-static int tmigr_cpu_online (unsigned int cpu) +static int tmigr_cpu_available (unsigned int cpu){
Quoted 8 lines
- struct
tmigr_cpu*tmc =this_cpu_ptr(&tmigr_cpu);
+ structtmigr_cpu*tmc =per_cpu_ptr(&tmigr_cpu, cpu);
/* Check whether CPU data was successfully initialized */ if (WARN_ON_ONCE(!tmc->tmgroup))
return-EINVAL;
+ /* Silently ignore online requests if isolated */This comment makes no sense.
/* Isolated CPUs are not participating in timer migration */
makes it entirely clear what this is about, no?
That brings me to the general design decision here. Your changelog explains at great length WHAT the change is doing, but completely fails
to explain the consequences and the rationale why this is the right thing to do.By excluding the isolated CPUs from migration completely, any 'global'
timer, which is armed on such a CPU, has to be expired on that isolated
CPU. That's fundamentaly different from e.g. RCU isolation.
Quoted 3 lines
It might be the right thing to do and harmless, but without a proper explanation it's a silent side effect of your changes, which leaves people scratching their heads.
Mmh, essentially the idea is that global timer should not migrate from housekeeping to isolated cores. I assumed the opposite never occurs (as global timers /should/ not even start on isolated cores on a properly isolated system), but you're right, that's not quite true.
Thinking about it now, since global timers /can/ start on isolated cores, that makes them quite different from offline ones and probably considering them the same is just not the right thing to do..
I'm going to have a deeper thought about this whole approach, perhaps something simpler just preventing migration in that one direction would suffice.
Quoted 22 lines
Quoted 12 lines
+ if (
cpu_is_isolated(cpu))
+ return 0;
raw_spin_lock_irq(&tmc->lock);
-trace_tmigr_cpu_online(tmc);
+trace_tmigr_cpu_available(tmc);
tmc->idle=timer_base_is_idle();
if (!tmc->idle)
__tmigr_cpu_activate(tmc);
-tmc->online= true;
+tmc->available= true;
+tmc->idle= true;How so?
Quoted 6 lines
+
cpumask_clear_cpu(cpu, tmigr_unavailable_cpumask);raw_spin_unlock_irq(&tmc->lock);
return 0;
}
+inttmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask)
Quoted 2 lines
cpumask_var_tis wrong here. 'const struct cpumask *' is what you want.
You mean in the function argument? That's exactly how it is handled in workqueue_unbound_exclude_cpumask. I get cpumask_var_t is not necessarily a pointer, perhaps it's worth changing it there too.. Or am I missing your point?
Quoted 40 lines
Quoted 4 lines
+{
+ int cpu;
+cpumask_var_tcpumask;https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#coding-style-notes
Quoted 4 lines
+ if (!zalloc_cpumask_var(&cpumask,
GFP_KERNEL))
+ return-ENOMEM;
+
+cpumask_copy(cpumask, tmigr_unavailable_cpumask);What serializes this against concurrent CPU hotplug? I assume it's done
by the caller, but then this code should have a lockdep assert to validate it. If it's not, then this is broken.As it is serialized it does not need a copy either, right?
Quoted 8 lines
+ /* Was not excluded but should be excluded now. */
+for_each_cpu_andnot(cpu, exclude_cpumask, cpumask)
+tmigr_cpu_unavailable(cpu);
+
+ /* Was excluded but should be included now */
+for_each_cpu_andnot(cpu, cpumask, exclude_cpumask)
+ if (cpu_online(cpu))
+tmigr_cpu_available(cpu);My brain hurts by now.
for_each_cpu_and(cpu, available_mask, exclude_mask)tmigr_cpu_unavailable(cpu);
for_each_cpu_andnot(cpu, cpu_online_mask, exclude_mask){ if (!cpumask_test_cpu(cpu,available_mask))tmigr_cpu_available(cpu);
}No?
Quoted 8 lines
Also this patch is doing too many things at once. It want's to be split
into:Patch 1: Rename 'online' to 'available' (bit and function names) Patch 2: Add the available mask logic
Patch 3: Add the isolation functionality
Good point, I'll keep it in mind if the patch keeps this shape.
Thanks for the feedback,
Gabriele
Frederic Weisbecker
maintainerQuoted 10 lines · Gabriele Monaco
Quoted 3 lines · Thomas Gleixner
How can that happen? There is always at least _ONE_ housekeeping, non-isolated, CPU online, no?
In my understanding it shouldn't, but I'm not sure there's anything preventing the user from isolating everything via cpuset. Anyway that's something no one in their mind should do, so I guess I'd just opt for the
cpumask_first(or actuallycpumask_any, like before the change).
With "nohz_full=..." or "isolcpus=nohz,..." there is always at least one housekeeping CPU. But with isolcpus=[domain] or cpusets equivalents (v1 cpuset.sched_load_balance, v2 isolated partion) there is nothing that prevents all CPUs from being isolated.
Speaking of, those are two different issues here:
* nohz_full CPUs are handled just like idle CPUs. Once the tick is stopped, the global timers are handled by other CPUs (housekeeping). There is always one housekeeping CPU that never goes idle.
One subtle thing though: if the nohz_full CPU fires a tick, because there is a local timer to be handled for example, it will also possibly handle some global timers along the way. If it happens to be a problem, it should be easy to resolve.
* Domain isolated CPUs are treated just like other CPUs. But there is not always a housekeeping CPU around. And no guarantee that there is always a non-idle CPU to take care of global timers.
Quoted 12 lines
Quoted 12 lines
That brings me to the general design decision here. Your changelog explains at great length WHAT the change is doing, but completely fails
to explain the consequences and the rationale why this is the right thing to do.By excluding the isolated CPUs from migration completely, any 'global'
timer, which is armed on such a CPU, has to be expired on that isolated
CPU. That's fundamentaly different from e.g. RCU isolation.
Quoted 8 lines
Quoted 3 lines
It might be the right thing to do and harmless, but without a proper explanation it's a silent side effect of your changes, which leaves people scratching their heads.
Mmh, essentially the idea is that global timer should not migrate from housekeeping to isolated cores. I assumed the opposite never occurs (as global timers /should/ not even start on isolated cores on a properly isolated system), but you're right, that's not quite true.
Indeed, they can definetly start there.
I'm tempted to propose to offline/reonline isolated CPUs in order to migrate away those timers. But that only works for timers that are currently queued.
Quoted 8 lines
Thinking about it now, since global timers /can/ start on isolated cores, that makes them quite different from offline ones and probably considering them the same is just not the right thing to do..
I'm going to have a deeper thought about this whole approach, perhaps something simpler just preventing migration in that one direction would suffice.
I think we can use your solution, which involves isolating the CPU from tmigr hierarchy. And also always queue global timers to non-isolated targets.
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Quoted 11 lines · Frederic Weisbecker
Le Thu, Apr 10, 2025 at 12:38:25PM +0200, Gabriele Monaco a écrit :
Speaking of, those are two different issues here:*
nohz_fullCPUs are handled just like idle CPUs. Once the tick is stopped, the global timers are handled by other CPUs (housekeeping). There is always one housekeeping CPU that never goes idle.
One subtle thing though: if thenohz_fullCPU fires a tick, because there is a local timer to be handled for example, it will also possibly handle some global timers along the way. If it happens to be a problem, it should be easy to resolve.
Quoted 3 lines
* Domain isolated CPUs are treated just like other CPUs. But there is not always a housekeeping CPU around. And no guarantee that there is always a non-idle CPU to take care of global timers.
That's an insianity.
Quoted 10 lines
Quoted 7 lines
Thinking about it now, since global timers /can/ start on isolated cores, that makes them quite different from offline ones and probably considering them the same is just not the right thing to do..
I'm going to have a deeper thought about this whole approach, perhaps something simpler just preventing migration in that one direction would suffice.
I think we can use your solution, which involves isolating the CPU from tmigr hierarchy. And also always queue global timers to non-isolated targets.
Why do we have to inflict extra complexity into the timer enqueue path instead of preventing the migration to, but not the migration from isolated CPUs?
Thanks,
tglx
Frederic Weisbecker
maintainerQuoted 12 lines · Thomas Gleixner
Quoted 11 lines · Frederic Weisbecker
Le Thu, Apr 10, 2025 at 12:38:25PM +0200, Gabriele Monaco a écrit :
Speaking of, those are two different issues here:*
nohz_fullCPUs are handled just like idle CPUs. Once the tick is stopped, the global timers are handled by other CPUs (housekeeping). There is always one housekeeping CPU that never goes idle.
One subtle thing though: if thenohz_fullCPU fires a tick, because there is a local timer to be handled for example, it will also possibly handle some global timers along the way. If it happens to be a problem, it should be easy to resolve.
Quoted 5 lines
Quoted 3 lines
* Domain isolated CPUs are treated just like other CPUs. But there is not always a housekeeping CPU around. And no guarantee that there is always a non-idle CPU to take care of global timers.
That's an insianity.
It works, but it doesn't make much sense arguably.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Thinking about it now, since global timers /can/ start on isolated cores, that makes them quite different from offline ones and probably considering them the same is just not the right thing to do..
I'm going to have a deeper thought about this whole approach, perhaps something simpler just preventing migration in that one direction would suffice.
Quoted 6 lines
Quoted 2 lines
I think we can use your solution, which involves isolating the CPU from tmigr hierarchy. And also always queue global timers to non-isolated targets.
Why do we have to inflict extra complexity into the timer enqueue path instead of preventing the migration to, but not the migration from isolated CPUs?
But how do we handle global timers that have been initialized and queued from isolated CPUs?
Thanks.
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Quoted 25 lines · Frederic Weisbecker
Quoted 24 lines · Thomas Gleixner
Quoted 22 lines · Frederic Weisbecker
Le Thu, Apr 10, 2025 at 12:38:25PM +0200, Gabriele Monaco a écrit :
Speaking of, those are two different issues here:*
nohz_fullCPUs are handled just like idle CPUs. Once the tick is stopped,
the global timers are handled by other CPUs (housekeeping). There is always
one housekeeping CPU that never goes idle.
One subtle thing though: if thenohz_fullCPU fires a tick, because there
is a local timer to be handled for example, it will also possibly handle
some global timers along the way. If it happens to be a problem, it should
be easy to resolve.* Domain isolated CPUs are treated just like other CPUs. But there is not
always a housekeeping CPU around. And no guarantee that there is always
a non-idle CPU to take care of global timers.
Quoted 3 lines
Quoted 1 line
That's an insianity.
It works, but it doesn't make much sense arguably.
I wonder if we should really worry about this scenario though.
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 8 lines
Thinking about it now, since global timers /can/ start on isolated
cores, that makes them quite different from offline ones and probably
considering them the same is just not the right thing to do..Quoted 5 lines
I'm going to have a deeper thought about this whole approach, perhaps
something simpler just preventing migration in that one direction would
suffice.I think we can use your solution, which involves isolating the CPU from tmigr
hierarchy. And also always queue global timers to non-isolated targets.
Quoted 8 lines
Quoted 4 lines
Why do we have to inflict extra complexity into the timer enqueue path
instead of preventing the migration to, but not the migration from isolated CPUs?But how do we handle global timers that have been initialized and queued from
isolated CPUs?
I need to sketch a bit more the solution but the rough idea is:
1. isolated CPUs don't pull remote timers
2. isolated CPUs ignore their global timers and let others pull them perhaps with some more logic to avoid it expiring
Wouldn't that be sufficient?
Also, I would definitely do 1. for any kind of isolation, but I'm not sure about 2.
Strictly speaking domain isolated cores don't claim to be free of kernel noise, even if they initiate it (but nohz_full ones do). What would be the expectation there?
Thanks,
Gabriele
Frederic Weisbecker
maintainerQuoted 7 lines · Gabriele Monaco
Quoted 3 lines · Frederic Weisbecker
But how do we handle global timers that have been initialized and queued from
isolated CPUs?I need to sketch a bit more the solution but the rough idea is:
1. isolated CPUs don't pull remote timers
That's the "easy" part.
Quoted 2 lines
2. isolated CPUs ignore their global timers and let others pull them perhaps with some more logic to avoid it expiring
This will always involve added overhead because you may need to wake up a CPU upon enqueueing a global timer to make sure it will be handled. At least when all other CPUs are idle.
Quoted 7 lines
Wouldn't that be sufficient?
Also, I would definitely do 1. for any kind of isolation, but I'm not sure about 2.
Strictly speaking domain isolated cores don't claim to be free of kernel noise, even if they initiate it (butnohz_fullones do). What would be the expectation there?
I don't know, I haven't heard complains about isolcpus handling global timers so far...
I wouldn't pay much attention to 2) until anybody complains. Does 1) even matter to anybody outside nohz_full ?
Thanks.
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Quoted 9 lines · Frederic Weisbecker
Quoted 7 lines · Gabriele Monaco
Quoted 3 lines · Frederic Weisbecker
But how do we handle global timers that have been initialized and queued from
isolated CPUs?I need to sketch a bit more the solution but the rough idea is:
1. isolated CPUs don't pull remote timers
Quoted 8 lines
That's the "easy" part.
Quoted 2 lines
2. isolated CPUs ignore their global timers and let others pull them perhaps with some more logic to avoid it expiring
This will always involve added overhead because you may need to wake up a CPU upon enqueueing a global timer to make sure it will be handled. At least when all other CPUs are idle.
Which is true for the remote enqueue path too. But you inflict the handling of this muck into the generic enqueue path as you have to turn a 'global' timer into a remote timer right in the hot path.
When you enqueue it in the regular way on the 'global' list, then you can delegate the expiry to a remote CPU on return to user, no?
Thanks,
tglx
Frederic Weisbecker
maintainerQuoted 15 lines · Thomas Gleixner
Quoted 14 lines · Frederic Weisbecker
Quoted 7 lines · Gabriele Monaco
Quoted 3 lines · Frederic Weisbecker
But how do we handle global timers that have been initialized and queued from
isolated CPUs?I need to sketch a bit more the solution but the rough idea is:
1. isolated CPUs don't pull remote timersThat's the "easy" part.
Quoted 2 lines
2. isolated CPUs ignore their global timers and let others pull them perhaps with some more logic to avoid it expiring
Quoted 7 lines
Quoted 3 lines
This will always involve added overhead because you may need to wake up a CPU upon enqueueing a global timer to make sure it will be handled. At least when all other CPUs are idle.
Which is true for the remote enqueue path too. But you inflict the handling of this muck into the generic enqueue path as you have to turn a 'global' timer into a remote timer right in the hot path.
Fair point.
Quoted 3 lines
When you enqueue it in the regular way on the 'global' list, then you can delegate the expiry to a remote CPU on return to user, no?
If you're referring to nohz_full, it's not a problem there because it's already considered as an idle CPU.
But for isolcpus alone that notification is necessary. I'm not sure if return to user is the best place. I hear that some kernel threads can spend a lot of time doing things...
But to begin with, is this all really necessary for isolcpus users?
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Quoted 23 lines · Frederic Weisbecker
Quoted 10 lines · Thomas Gleixner
Quoted 9 lines · Frederic Weisbecker
Quoted 6 lines · Gabriele Monaco
Quoted 3 lines · Frederic Weisbecker
But how do we handle global timers that have been initialized and queued from
isolated CPUs?I need to sketch a bit more the solution but the rough idea is:
1. isolated CPUs don't pull remote timersThat's the "easy" part.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
2. isolated CPUs ignore their global timers and let others pull them perhaps with some more logic to avoid it expiring
This will always involve added overhead because you may need to wake up a CPU upon enqueueing a global timer to make sure it will be handled. At least when all other CPUs are idle.
Which is true for the remote enqueue path too. But you inflict the handling of this muck into the generic enqueue path as you have to turn a 'global' timer into a remote timer right in the hot path.
Fair point.
Quoted 2 lines
When you enqueue it in the regular way on the 'global' list, then you can delegate the expiry to a remote CPU on return to user, no?
Quoted 9 lines
If you're referring to
nohz_full, it's not a problem there because it's already considered as an idle CPU.But for isolcpus alone that notification is necessary. I'm not sure if return to user is the best place. I hear that some kernel threads can spend a lot of time doing things...
But to begin with, is this all really necessary for isolcpus users?
In some of the actual customer use cases that I have seen, both "nohz_full" and "isolcpus" are set to the same set of CPUs to achieve maximum isolation. isolcpus have domain and managed_irq that are not covered by nohz_full. As isolcpus=nohz has been extended to be equivalent to nohz_full, users can now just use "isolcpus" to achieve that maximum CPU isolation.
Cheers,
Longman
Quoted 29 lines · Frederic Weisbecker
Quoted 7 lines · Gabriele Monaco
Quoted 3 lines · Frederic Weisbecker
But how do we handle global timers that have been initialized and queued from
isolated CPUs?I need to sketch a bit more the solution but the rough idea is:
1. isolated CPUs don't pull remote timersThat's the "easy" part.
Quoted 3 lines
2. isolated CPUs ignore their global timers and let others pull them
perhaps with some more logic to avoid it expiringThis will always involve added overhead because you may need to wake up
a CPU upon enqueueing a global timer to make sure it will be handled. At least when all other CPUs are idle.Quoted 8 lines
Wouldn't that be sufficient?
Also, I would definitely do 1. for any kind of isolation, but I'm not
sure about 2.
Strictly speaking domain isolated cores don't claim to be free of kernel noise, even if they initiate it (butnohz_fullones do). What would be the expectation there?
Quoted 8 lines
I don't know, I haven't heard complains about isolcpus handling global
timers so far...I wouldn't pay much attention to 2) until anybody complains. Does 1) even
matter to anybody outsidenohz_full?
Makes sense..
In our case, 2. is not a big issue because it can usually be solved by other configurations, but 1. is an issue.
Most people indeed use nohz_full in that scenario, but some users may not want its overhead.
I find it misleading at best for global timers to migrate from housekeeping to isolcpus cores and since it's "easy", I'd definitely change that.
Does it make sense?
Thanks,
Gabriele
Frederic Weisbecker
maintainerQuoted 47 lines · Gabriele Monaco
Quoted 29 lines · Frederic Weisbecker
Quoted 7 lines · Gabriele Monaco
Quoted 3 lines · Frederic Weisbecker
But how do we handle global timers that have been initialized and queued from
isolated CPUs?I need to sketch a bit more the solution but the rough idea is:
1. isolated CPUs don't pull remote timersThat's the "easy" part.
Quoted 3 lines
2. isolated CPUs ignore their global timers and let others pull them
perhaps with some more logic to avoid it expiringThis will always involve added overhead because you may need to wake up
a CPU upon enqueueing a global timer to make sure it will be handled. At least when all other CPUs are idle.Quoted 8 lines
Wouldn't that be sufficient?
Also, I would definitely do 1. for any kind of isolation, but I'm not
sure about 2.
Strictly speaking domain isolated cores don't claim to be free of kernel noise, even if they initiate it (butnohz_fullones do). What would be the expectation there?Quoted 8 lines
I don't know, I haven't heard complains about isolcpus handling global
timers so far...I wouldn't pay much attention to 2) until anybody complains. Does 1) even
matter to anybody outsidenohz_full?Makes sense..
In our case, 2. is not a big issue because it can usually be solved by other configurations, but 1. is an issue.
Most people indeed usenohz_fullin that scenario, but some users may not want its overhead.
Quoted 3 lines
I find it misleading at best for global timers to migrate from housekeeping to isolcpus cores and since it's "easy", I'd definitely change that.
Easy but still a bit invasive so:
Quoted 1 line
Does it make sense?
It makes sense but is there a real need for that? Have people complained about that?
Thanks.
Quoted 4 lines
Thanks,
Gabriele
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Quoted 57 lines · Frederic Weisbecker
Quoted 56 lines · Gabriele Monaco
Quoted 35 lines · Frederic Weisbecker
Le Thu, Apr 10, 2025 at 03:56:02PM +0200, Gabriele Monaco a écrit :
Quoted 8 lines · Frederic Weisbecker
Quoted 4 lines
But how do we handle global timers that have been initialized and
queued from
isolated CPUs?I need to sketch a bit more the solution but the rough idea is:
1. isolated CPUs don't pull remote timersThat's the "easy" part.
Quoted 3 lines
2. isolated CPUs ignore their global timers and let others pull them
perhaps with some more logic to avoid it expiringThis will always involve added overhead because you may need to wake
up
a CPU upon enqueueing a global timer to make sure it will be handled.
At least when all other CPUs are idle.Quoted 10 lines
Wouldn't that be sufficient?
Also, I would definitely do 1. for any kind of isolation, but I'm
not
sure about 2.
Strictly speaking domain isolated cores don't claim to be free of
kernel noise, even if they initiate it (butnohz_fullones do). What would be the expectation there?Quoted 9 lines
I don't know, I haven't heard complains about isolcpus handling global
timers so far...I wouldn't pay much attention to 2) until anybody complains. Does
1)
even
matter to anybody outsidenohz_full?Makes sense..
In our case, 2. is not a big issue because it can usually be solved by
other configurations, but 1. is an issue.
Most people indeed usenohz_fullin that scenario, but some users may
not want its overhead.
Quoted 7 lines
Quoted 4 lines
I find it misleading at best for global timers to migrate from housekeeping to isolcpus cores and since it's "easy", I'd definitely
change that.Easy but still a bit invasive so:
I'm not understanding what is going to be invasive in this case. Aren't we just talking about not allowing isolcpus to pull timers from other cpus?
Let's ignore for now the global timers started on those CPUs, I'm not aware of complaints regarding that.
As far as I understand, the change would allow timer migration to work normally out of isolcpus and among housekeeping ones, we are not forcing any migration that would potentially introduce overhead or missed timers.
Or am I oversimplifying it?
Thanks,
Gabriele
Frederic Weisbecker
maintainerQuoted 3 lines · Gabriele Monaco
I'm not understanding what is going to be invasive in this case. Aren't we just talking about not allowing isolcpus to pull timers from other cpus?
Right, but in order to do that you need to avoid remotely executing timers. And for that we need your initial patch (after reviews have been addressed). Right?
Quoted 8 lines
Let's ignore for now the global timers started on those CPUs, I'm not aware of complaints regarding that.
As far as I understand, the change would allow timer migration to work normally out of isolcpus and among housekeeping ones, we are not forcing any migration that would potentially introduce overhead or missed timers.
Or am I oversimplifying it?
Global timers only migrate:
a) When a CPU goes offline (but they should be migrated to a housekeeping CPU)
b) When a timer executes remotely and re-enqueues itself.
In order to handle b), you must make sure an isolated CPU can't execute timers remotely. Hence why it must be set as not available like you did.
Or am I missing something else?
Thanks.
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Quoted 26 lines · Frederic Weisbecker
Quoted 4 lines · Gabriele Monaco
I'm not understanding what is going to be invasive in this case. Aren't we just talking about not allowing isolcpus to pull timers from
other cpus?Right, but in order to do that you need to avoid remotely executing timers. And for that we need your initial patch (after reviews have been addressed). Right?
Quoted 10 lines
Let's ignore for now the global timers started on those CPUs, I'm not
aware of complaints regarding that.As far as I understand, the change would allow timer migration to work
normally out of isolcpus and among housekeeping ones, we are not forcing any migration that would potentially introduce overhead or missed timers.
Or am I oversimplifying it?Global timers only migrate:
a) When a CPU goes offline (but they should be migrated to a housekeeping CPU)
Quoted 8 lines
b) When a timer executes remotely and re-enqueues itself.
In order to handle b), you must make sure an isolated CPU can't execute timers remotely. Hence why it must be set as not available like you did.
Or am I missing something else?
Mmh, my patch is in fact allowing isolated cores to still migrate everything if they go offline.
However I don't think housekeeping CPUs can execute remote timers on isolated ones. That is not a problem for offline CPUs (they won't start anything and do the migration while offlining is enough), but we should allow it here.
I may be missing something, but isn't it what [1] is doing?
Thanks,
Gabriele
[1] -
https://elixir.bootlin.com/linux/v6.13.7/source/kernel/time/timer_migration.c#L976
Frederic Weisbecker
maintainerQuoted 2 lines · Gabriele Monaco
Mmh, my patch is in fact allowing isolated cores to still migrate everything if they go offline.
Sure that doesn't change.
Quoted 3 lines
However I don't think housekeeping CPUs can execute remote timers on isolated ones.
I'm confused, a CPU can't execute something on another CPU (except with an IPI). But:
Before your patch, a housekeeping or isolated CPU can pull timers from any other CPU and execute them on its behalf.
After your patch, a housekeeping CPU can only pull timers from other housekeeping CPUs. And isolated CPUs each execute their own global timers.
Quoted 4 lines
That is not a problem for offline CPUs (they won't start anything and do the migration while offlining is enough), but we should allow it here.
I may be missing something, but isn't it what [1] is doing?
That's only something that avoids pulling timers from offlining CPUs.
The real migration happens at timers_dead_cpu(), which is called directly by cpu_down() / cpu_up() callers context. And timers are migrated to the current CPU, which is fine if cpu_down()/cpu_up() are being called from a task that is affine to housekeeping.
Thanks.
Quoted 7 lines
Thanks,
Gabriele[1] -
https://elixir.bootlin.com/linux/v6.13.7/source/kernel/time/timer_migration.c#L976
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Quoted 15 lines · Frederic Weisbecker
Quoted 2 lines · Gabriele Monaco
Mmh, my patch is in fact allowing isolated cores to still migrate everything if they go offline.
Sure that doesn't change.
Quoted 4 lines
However I don't think housekeeping CPUs can execute remote timers on
isolated ones.I'm confused, a CPU can't execute something on another CPU (except with
an IPI). But:
Quoted 8 lines
Before your patch, a housekeeping or isolated CPU can pull timers from
any other CPU and execute them on its behalf.After your patch, a housekeeping CPU can only pull timers from other housekeeping CPUs. And isolated CPUs each execute their own global timers.
Right, the way I said it doesn't really make sense.
What I mean is: why wouldn't a housekeeping CPU pull global timers from an isolated one?
We want to prevent the other way around, but I think housekeeping should be encouraged to pull timers from isolated CPUs, even if those are not idle.
I see only preventing isolated CPUs from pulling remote timers may play bad with the algorithm since they'd register in the hierarchy but just not pull timers.
(This simpler approach works in our scenario though)
The idea in my patch could mostly work, but I'd explicitly let housekeeping CPUs pull timers from isolated (while of course not doing it for offline ones).
Does it make sense to you?
Thanks,
Gabriele
Frederic Weisbecker
maintainerQuoted 41 lines · Gabriele Monaco
Quoted 15 lines · Frederic Weisbecker
Quoted 2 lines · Gabriele Monaco
Mmh, my patch is in fact allowing isolated cores to still migrate everything if they go offline.
Sure that doesn't change.
Quoted 4 lines
However I don't think housekeeping CPUs can execute remote timers on
isolated ones.I'm confused, a CPU can't execute something on another CPU (except with
an IPI). But:Quoted 8 lines
Before your patch, a housekeeping or isolated CPU can pull timers from
any other CPU and execute them on its behalf.After your patch, a housekeeping CPU can only pull timers from other housekeeping CPUs. And isolated CPUs each execute their own global timers.
Right, the way I said it doesn't really make sense.
What I mean is: why wouldn't a housekeeping CPU pull global timers from an isolated one?
We want to prevent the other way around, but I think housekeeping should be encouraged to pull timers from isolated CPUs, even if those are not idle.
I see only preventing isolated CPUs from pulling remote timers may play bad with the algorithm since they'd register in the hierarchy but just not pull timers.
(This simpler approach works in our scenario though)
Quoted 5 lines
The idea in my patch could mostly work, but I'd explicitly let housekeeping CPUs pull timers from isolated (while of course not doing it for offline ones).
Does it make sense to you?
If you want housekeeping CPUs to pull timers from isolated ones, then you need isolated CPUs to eventually be part of the hierarchy (be "available"), because they would need to propagate their global timers up to the top.
If they propagate their global timers then they must play the whole hierarchy game and be ready to pull the timers from any other CPUs.
Because if they propagate their timers, they must also propagate their idle state to synchronize with the whole hierarchy and know if there is a non-idle housekeeping CPU to take care of their timers. And if they propagate their (non) idle state, the isolated CPUs also declare themselves as available to handle other's timers.
And working around that would be very nasty.
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Quoted 22 lines · Frederic Weisbecker
If you want housekeeping CPUs to pull timers from isolated ones, then you
need isolated CPUs to eventually be part of the hierarchy (be "available"),
because they would need to propagate their global timers up to the top.If they propagate their global timers then they must play the whole hierarchy
game and be ready to pull the timers from any other CPUs.Because if they propagate their timers, they must also propagate their
idle state to synchronize with the whole hierarchy and know if there is
a non-idle housekeeping CPU to take care of their timers. And if they propagate
their (non) idle state, the isolated CPUs also declare themselves as available
to handle other's timers.
Quoted 2 lines
And working around that would be very nasty.
Well, that's exactly what I was trying to do, thanks for pointing this out. I guess I won't go down that rabbit hole then.
Thanks,
Gabriele
Quoted 10 lines · Frederic Weisbecker
Quoted 9 lines · Gabriele Monaco
Quoted 3 lines · Thomas Gleixner
How can that happen? There is always at least _ONE_ housekeeping, non-isolated, CPU online, no?
In my understanding it shouldn't, but I'm not sure there's anything preventing the user from isolating everything via cpuset. Anyway that's something no one in their mind should do, so I guess I'd just opt for the
cpumask_first(or actuallycpumask_any, like before the change).
Quoted 4 lines
With "nohz_full=..." or "isolcpus=nohz,..." there is always at least one housekeeping CPU. But with isolcpus=[domain] or cpusets equivalents (v1 cpuset.sched_load_balance, v2 isolated partion) there is nothing that prevents all CPUs from being isolated.
Actually v2 won't allow users to isolate all the CPUs. Users can probably do that with v1's cpuset.sched_load_balance.
Cheers,
Longman
Frederic Weisbecker
maintainerQuoted 11 lines · Waiman Long
Quoted 10 lines · Frederic Weisbecker
Quoted 9 lines · Gabriele Monaco
Quoted 3 lines · Thomas Gleixner
How can that happen? There is always at least _ONE_ housekeeping, non-isolated, CPU online, no?
In my understanding it shouldn't, but I'm not sure there's anything preventing the user from isolating everything via cpuset. Anyway that's something no one in their mind should do, so I guess I'd just opt for the
cpumask_first(or actuallycpumask_any, like before the change).
Quoted 7 lines
Quoted 4 lines
With "nohz_full=..." or "isolcpus=nohz,..." there is always at least one housekeeping CPU. But with isolcpus=[domain] or cpusets equivalents (v1 cpuset.sched_load_balance, v2 isolated partion) there is nothing that prevents all CPUs from being isolated.
Actually v2 won't allow users to isolate all the CPUs. Users can probably do that with v1's cpuset.sched_load_balance.
Perhaps, and I think isolcpus= can too.
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Quoted 25 lines · Frederic Weisbecker
Quoted 24 lines · Waiman Long
Quoted 22 lines · Frederic Weisbecker
Le Thu, Apr 10, 2025 at 12:38:25PM +0200, Gabriele Monaco a écrit :
Quoted 5 lines · Thomas Gleixner
Quoted 4 lines
How can that happen? There is always at least _ONE_ housekeeping,
non-isolated, CPU online, no?Quoted 8 lines
In my understanding it shouldn't, but I'm not sure there's anything
preventing the user from isolating everything via cpuset. Anyway that's something no one in their mind should do, so I guess I'd
just opt for thecpumask_first(or actuallycpumask_any, like before
the change).With "nohz_full=..." or "isolcpus=nohz,..." there is always at least one
housekeeping CPU. But with isolcpus=[domain] or cpusets equivalents
(v1 cpuset.sched_load_balance, v2 isolated partion) there is nothing that
prevents all CPUs from being isolated.
Quoted 6 lines
Quoted 3 lines
Actually v2 won't allow users to isolate all the CPUs. Users can probably do
that with v1's cpuset.sched_load_balance.Perhaps, and I think isolcpus= can too.
# vng -a isolcpus=0-15 cat /sys/devices/system/cpu/isolated 1-15
Seems not..
Quoted 12 lines · Frederic Weisbecker
Quoted 11 lines · Waiman Long
Quoted 10 lines · Frederic Weisbecker
Quoted 9 lines · Gabriele Monaco
Quoted 3 lines · Thomas Gleixner
How can that happen? There is always at least _ONE_ housekeeping, non-isolated, CPU online, no?
In my understanding it shouldn't, but I'm not sure there's anything preventing the user from isolating everything via cpuset. Anyway that's something no one in their mind should do, so I guess I'd just opt for the
cpumask_first(or actuallycpumask_any, like before the change).
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
With "nohz_full=..." or "isolcpus=nohz,..." there is always at least one housekeeping CPU. But with isolcpus=[domain] or cpusets equivalents (v1 cpuset.sched_load_balance, v2 isolated partion) there is nothing that prevents all CPUs from being isolated.
Actually v2 won't allow users to isolate all the CPUs. Users can probably do that with v1's cpuset.sched_load_balance.
Perhaps, and I think isolcpus= can too.
No, I don't think so. The following code is in kernel/sched/isolation.c:
first_cpu = cpumask_first_and(cpu_present_mask, housekeeping_staging); if (first_cpu >= nr_cpu_ids || first_cpu >= setup_max_cpus) { __cpumask_set_cpu(smp_processor_id(), housekeeping_staging); __cpumask_clear_cpu(smp_processor_id(), non_housekeeping_mask); if (!housekeeping.flags) { pr_warn("Housekeeping: must include one present CPU, " "using boot CPU:%d\n", smp_processor_id()); } }
Cheers, Longman
Frederic Weisbecker
maintainerQuoted 22 lines · Waiman Long
Quoted 12 lines · Frederic Weisbecker
Quoted 11 lines · Waiman Long
Quoted 10 lines · Frederic Weisbecker
Quoted 9 lines · Gabriele Monaco
Quoted 3 lines · Thomas Gleixner
How can that happen? There is always at least _ONE_ housekeeping, non-isolated, CPU online, no?
In my understanding it shouldn't, but I'm not sure there's anything preventing the user from isolating everything via cpuset. Anyway that's something no one in their mind should do, so I guess I'd just opt for the
cpumask_first(or actuallycpumask_any, like before the change).Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
With "nohz_full=..." or "isolcpus=nohz,..." there is always at least one housekeeping CPU. But with isolcpus=[domain] or cpusets equivalents (v1 cpuset.sched_load_balance, v2 isolated partion) there is nothing that prevents all CPUs from being isolated.
Actually v2 won't allow users to isolate all the CPUs. Users can probably do that with v1's cpuset.sched_load_balance.
Perhaps, and I think isolcpus= can too.
Quoted 8 lines
No, I don't think so. The following code is in
kernel/sched/isolation.c:
first_cpu=cpumask_first_and(cpu_present_mask, housekeeping_staging); if (first_cpu>=nr_cpu_ids||first_cpu>=setup_max_cpus) {__cpumask_set_cpu(smp_processor_id(), housekeeping_staging);__cpumask_clear_cpu(smp_processor_id(), non_housekeeping_mask); if (!housekeeping.flags) {pr_warn("Housekeeping: must include one present CPU, " "using boot CPU:%d\n", smp_processor_id()); } }
Ok, good then!
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Quoted 7 lines · Gabriele Monaco
Quoted 5 lines · Thomas Gleixner
Quoted 1 line
+ /* Fall back to any online in case all are isolated. */
How can that happen? There is always at least _ONE_ housekeeping, non-isolated, CPU online, no?
Quoted 5 lines
In my understanding it shouldn't, but I'm not sure there's anything preventing the user from isolating everything via cpuset. Anyway that's something no one in their mind should do, so I guess I'd just opt for the
cpumask_first(or actuallycpumask_any, like before the change).
This should be prevented by the core infrastructure. Isolating _ALL_ CPUs is broken by definition.
Quoted 21 lines
Quoted 12 lines
That brings me to the general design decision here. Your changelog explains at great length WHAT the change is doing, but completely fails
to explain the consequences and the rationale why this is the right thing to do.By excluding the isolated CPUs from migration completely, any 'global'
timer, which is armed on such a CPU, has to be expired on that isolated
CPU. That's fundamentaly different from e.g. RCU isolation.Quoted 3 lines
It might be the right thing to do and harmless, but without a proper explanation it's a silent side effect of your changes, which leaves people scratching their heads.
Mmh, essentially the idea is that global timer should not migrate from housekeeping to isolated cores. I assumed the opposite never occurs (as global timers /should/ not even start on isolated cores on a properly isolated system), but you're right, that's not quite true.
Quoted 7 lines
Thinking about it now, since global timers /can/ start on isolated cores, that makes them quite different from offline ones and probably considering them the same is just not the right thing to do..
I'm going to have a deeper thought about this whole approach, perhaps something simpler just preventing migration in that one direction would suffice.
Indeed.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
+int
tmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask)
cpumask_var_tis wrong here. 'const struct cpumask *' is what you want.You mean in the function argument? That's exactly how it is handled in
workqueue_unbound_exclude_cpumask. I getcpumask_var_tis not necessarily a pointer, perhaps it's worth changing it there too..
Correct. cpumask_var_t is the magic macro construct which allows to switch from cpumask on stack to allocated ones at compile time, but what's handed around is a pointer to struct cpumask.
Thanks,
tglx
Quoted 25 lines · Gabriele Monaco
Quoted 6 lines · Thomas Gleixner
kernel/time/timer_migration.c static unsigned int tmigr_crossnode_level __read_mostly; · line 427
Quoted 3 lines · Gabriele Monaco
kernel/time/timer_migration.c +2
-0+/* cpumask excluded from migration */ +static cpumask_var_t tmigr_unavailable_cpumask;Why is this a negated mask instead of being the obvious and intuitive available mask?
Well, the way I started writing the patch I found it easier to do the double andnot in
tmigr_isolated_exclude_cpumaskto see what changed. I see the way it evolved is just messier..
I'll apply your solution which seems much neater!Quoted 13 lines
Quoted 4 lines
if (firstexp !=
KTIME_MAX) {
- migrator =cpumask_any_but(cpu_online_mask, cpu);
+ migrator = cpumask_nth_andnot(0,cpu_possible_mask,
+tmigr_unavailable_cpumask);That's exactly what this negated mask causes: incomprehensible code.
cpumask_clear_cpu(cpu, available_mask);
...
migrator =cpumask_first(available_mask);is too simple and obvious, right?
Quoted 1 line
+ /* Fall back to any online in case all are isolated. */
Quoted 8 lines
Quoted 3 lines
How can that happen? There is always at least _ONE_ housekeeping, non-isolated, CPU online, no?
In my understanding it shouldn't, but I'm not sure there's anything preventing the user from isolating everything via cpuset. Anyway that's something no one in their mind should do, so I guess I'd just opt for the
cpumask_first(or actuallycpumask_any, like before the change).
No, cpuset is not allowed to take all the CPUs from the cgroup root (housekeeping CPUs). So it can't happen.
Quoted 71 lines
Quoted 37 lines
Quoted 9 lines
+ if (migrator >=
nr_cpu_ids)
+ migrator =cpumask_any_but(cpu_online_mask, cpu);work_on_cpu(migrator, tmigr_trigger_active, NULL); }return 0;
}kernel/time/timer_migration.c +0
-1-static int tmigr_cpu_online (unsigned int cpu)kernel/time/timer_migration.c static long tmigr_trigger_active(void *unused) · line 1486
Quoted 10 lines
kernel/time/timer_migration.c +3
-1+static int tmigr_cpu_available (unsigned int cpu) { -struct tmigr_cpu *tmc =this_cpu_ptr (&tmigr_cpu); +struct tmigr_cpu *tmc =per_cpu_ptr (&tmigr_cpu, cpu); /* Check whether CPU data was successfully initialized */ if (WARN_ON_ONCE(!tmc->tmgroup)) return -EINVAL; +/* Silently ignore online requests if isolated */ This comment makes no sense.
/* Isolated CPUs are not participating in timer migration */
makes it entirely clear what this is about, no?
That brings me to the general design decision here. Your changelog explains at great length WHAT the change is doing, but completely fails
to explain the consequences and the rationale why this is the right thing to do.By excluding the isolated CPUs from migration completely, any 'global'
timer, which is armed on such a CPU, has to be expired on that isolated
CPU. That's fundamentaly different from e.g. RCU isolation.Quoted 3 lines
It might be the right thing to do and harmless, but without a proper explanation it's a silent side effect of your changes, which leaves people scratching their heads.
Mmh, essentially the idea is that global timer should not migrate from housekeeping to isolated cores. I assumed the opposite never occurs (as global timers /should/ not even start on isolated cores on a properly isolated system), but you're right, that's not quite true.
Thinking about it now, since global timers /can/ start on isolated cores, that makes them quite different from offline ones and probably considering them the same is just not the right thing to do..
I'm going to have a deeper thought about this whole approach, perhaps something simpler just preventing migration in that one direction would suffice.
Quoted 18 lines
Quoted 11 lines
+ if (
cpu_is_isolated(cpu))
+ return 0;
raw_spin_lock_irq(&tmc->lock);
-trace_tmigr_cpu_online(tmc);
+trace_tmigr_cpu_available(tmc);
tmc->idle=timer_base_is_idle();
if (!tmc->idle)
__tmigr_cpu_activate(tmc);
-tmc->online= true;
+tmc->available= true;
+tmc->idle= true;How so?
Quoted 5 lines
+
cpumask_clear_cpu(cpu, tmigr_unavailable_cpumask);raw_spin_unlock_irq(&tmc->lock);
return 0;
}
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+int
tmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask)
cpumask_var_tis wrong here. 'const struct cpumask *' is what you want.You mean in the function argument? That's exactly how it is handled in
workqueue_unbound_exclude_cpumask. I getcpumask_var_tis not necessarily a pointer, perhaps it's worth changing it there too.. Or am I missing your point?
cpumask_var_t can be interchangeable with "struct cpumask *" as long as the passed-in cpumask is not being modified.
Cheers,
Longman
Quoted 71 lines · Gabriele Monaco
The timer migration mechanism allows timers to move from idle CPUs to active ones to improve the overall idle time. This is however undesired when CPU intensive workloads run on isolated cores, as the algorithm would move the timers from housekeeping to isolated cores, negatively affecting the isolation.
Exclude isolated cores from the timer migration algorithm, extend the concept of unavailable cores, currently used for offline ones, to isolated ones:
* A core is unavailable if isolated or offline;
* A core is available if isolated and offline;Keep a cpumap to easily track unavailable cores and change the concept of online/offline tmigr to available/unavailable in code and tracepoints.
A core is considered unavailable as idle if:
* is in the isolcpus list
* is in thenohz_fulllist
* is in an isolated cpusetSigned-off-by Gabriele Monaco <[email protected]>--- include/linux/timer.h | 6 +++ include/trace/events/timer_migration.h | 4 +- kernel/cgroup/cpuset.c | 15 +++--- kernel/time/timer_migration.c | 72 +++++++++++++++++++++----- kernel/time/timer_migration.h | 2 +- 5 files changed, 76 insertions(+), 23 deletions(-)include/linux/timer.h +6
-0@@ -190,4 +190,10 @@ int timers_dead_cpu(unsigned int cpu);#define timers_dead_cpu NULL#endif +#if defined(CONFIG_SMP ) && defined(CONFIG_NO_HZ_COMMON ) +extern int tmigr_isolated_exclude_cpumask (cpumask_var_t exclude_cpumask); +#else +static inline int tmigr_isolated_exclude_cpumask (cpumask_var_t exclude_cpumask) { } +#endif +#endif include/trace/events/timer_migration.h +2
-2@@ -173,14 +173,14 @@ DEFINE_EVENT(tmigr_cpugroup, tmigr_cpu_active,TP_ARGS (tmc) ); -DEFINE_EVENT (tmigr_cpugroup, tmigr_cpu_online, +DEFINE_EVENT (tmigr_cpugroup, tmigr_cpu_available, TP_PROTO(struct tmigr_cpu *tmc),TP_ARGS (tmc) ); -DEFINE_EVENT(tmigr_cpugroup, tmigr_cpu_offline, +DEFINE_EVENT(tmigr_cpugroup, tmigr_cpu_unavailable, TP_PROTO(struct tmigr_cpu *tmc),kernel/cgroup/cpuset.c +0
-0
kernel/cgroup/cpuset.c static bool partition_xcpus_del(int old_prs, struct cpuset *parent, · line 1326
Quoted 5 lines
kernel/cgroup/cpuset.c +1
-1@@ -1323,7 +1323,7 @@ static bool partition_xcpus_del(int old_prs, struct cpuset *parent,return isolcpus_updated; } -static void update_unbound_workqueue_cpumask (bool isolcpus_updated) +static void update_unbound_interference_cpumask (bool isolcpus_updated)
Unbound workqueue is a special workqueue. The name "update_unbound_interference_cpumask" doesn't make sense. I would prefer you to use names like "update_exclusion_cpumasks" or "update_isolated_cpumasks".
Cheers,
Longman
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Gabriele,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 3b07108ada81a8ebcebf1fe61367b4e436c895bd]
url: https://github.com/intel-lab-lkp/linux/commits/Gabriele-Monaco/timers-Exclude-isolated-cpus-from-timer-migation/20250410-145629 base: 3b07108ada81a8ebcebf1fe61367b4e436c895bd patch link: https://lore.kernel.org/r/20250410065446.57304-2-gmonaco%40redhat.com patch subject: [PATCH] timers: Exclude isolated cpus from timer migation config: csky-randconfig-001-20250411 (https://download.01.org/0day-ci/archive/20250411/[email protected]/config) compiler: csky-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250411/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from include/linux/uprobes.h:18,
from include/linux/mm_types.h:16,
from include/linux/mmzone.h:22,
from include/linux/topology.h:33,
from include/linux/irq.h:19,
from include/asm-generic/hardirq.h:17, from ./arch/csky/include/generated/asm/hardirq.h:1, from include/linux/hardirq.h:11,
from include/linux/interrupt.h:11,
from include/linux/kernel_stat.h:8,
from arch/csky/kernel/asm-offsets.c:5:
include/linux/timer.h: In function 'tmigr_isolated_exclude_cpumask':
>> include/linux/timer.h:196:1: warning: no return statement in function returning non-void [-Wreturn-type]
196 | static inline int tmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask) { }
| ^~~~~~--
In file included from include/linux/uprobes.h:18,
from include/linux/mm_types.h:16,
from include/linux/mmzone.h:22,
from include/linux/topology.h:33,
from include/linux/irq.h:19,
from include/asm-generic/hardirq.h:17, from ./arch/csky/include/generated/asm/hardirq.h:1, from include/linux/hardirq.h:11,
from include/linux/interrupt.h:11,
from include/linux/kernel_stat.h:8,
from arch/csky/kernel/asm-offsets.c:5:
include/linux/timer.h: In function 'tmigr_isolated_exclude_cpumask':
>> include/linux/timer.h:196:1: warning: no return statement in function returning non-void [-Wreturn-type]
196 | static inline int tmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask) { }
| ^~~~~~vim +196 include/linux/timer.h
192
193 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
194 extern int tmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask);
195 #else
> 196 static inline int tmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask) { } 197 #endif
198
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Gabriele,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 3b07108ada81a8ebcebf1fe61367b4e436c895bd]
url: https://github.com/intel-lab-lkp/linux/commits/Gabriele-Monaco/timers-Exclude-isolated-cpus-from-timer-migation/20250410-145629 base: 3b07108ada81a8ebcebf1fe61367b4e436c895bd patch link: https://lore.kernel.org/r/20250410065446.57304-2-gmonaco%40redhat.com patch subject: [PATCH] timers: Exclude isolated cpus from timer migation config: hexagon-randconfig-002-20250411 (https://download.01.org/0day-ci/archive/20250411/[email protected]/config) compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project f819f46284f2a79790038e1f6649172789734ae8) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250411/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from arch/hexagon/kernel/asm-offsets.c:12:
In file included from include/linux/compat.h:15:
In file included from include/linux/socket.h:8:
In file included from include/linux/uio.h:9:
In file included from include/linux/mm_types.h:16:
In file included from include/linux/uprobes.h:18:
>> include/linux/timer.h:196:83: warning: non-void function does not return a value [-Wreturn-type]
196 | static inline int tmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask) { }
| ^ 1 warning generated.
--
In file included from drivers/spi/spi-pic32-sqi.c:9:
In file included from include/linux/clk.h:14:
In file included from include/linux/notifier.h:16:
In file included from include/linux/srcu.h:21:
In file included from include/linux/workqueue.h:9:
>> include/linux/timer.h:196:83: warning: non-void function does not return a value [-Wreturn-type]
196 | static inline int tmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask) { }
| ^
drivers/spi/spi-pic32-sqi.c:673:34: warning: unused variable 'pic32_sqi_of_ids' [-Wunused-const-variable]
673 | static const struct of_device_id pic32_sqi_of_ids[] = {
| ^~~~~~~~~~~~~~~~ 2 warnings generated.
--
In file included from drivers/spi/spi-orion.c:9:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:19:
In file included from include/linux/topology.h:33:
In file included from include/linux/mmzone.h:22:
In file included from include/linux/mm_types.h:16:
In file included from include/linux/uprobes.h:18:
>> include/linux/timer.h:196:83: warning: non-void function does not return a value [-Wreturn-type]
196 | static inline int tmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask) { }
| ^
drivers/spi/spi-orion.c:614:34: warning: unused variable 'orion_spi_of_match_table' [-Wunused-const-variable]
614 | static const struct of_device_id orion_spi_of_match_table[] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~ 2 warnings generated.
--
In file included from drivers/spi/spi-pic32.c:9:
In file included from include/linux/clk.h:14:
In file included from include/linux/notifier.h:16:
In file included from include/linux/srcu.h:21:
In file included from include/linux/workqueue.h:9:
>> include/linux/timer.h:196:83: warning: non-void function does not return a value [-Wreturn-type]
196 | static inline int tmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask) { }
| ^
drivers/spi/spi-pic32.c:850:34: warning: unused variable 'pic32_spi_of_match' [-Wunused-const-variable]
850 | static const struct of_device_id pic32_spi_of_match[] = {
| ^~~~~~~~~~~~~~~~~~ 2 warnings generated.
--
In file included from drivers/spi/spi-armada-3700.c:11:
In file included from include/linux/clk.h:14:
In file included from include/linux/notifier.h:16:
In file included from include/linux/srcu.h:21:
In file included from include/linux/workqueue.h:9:
>> include/linux/timer.h:196:83: warning: non-void function does not return a value [-Wreturn-type]
196 | static inline int tmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask) { }
| ^
drivers/spi/spi-armada-3700.c:806:34: warning: unused variable 'a3700_spi_dt_ids' [-Wunused-const-variable]
806 | static const struct of_device_id a3700_spi_dt_ids[] = {
| ^~~~~~~~~~~~~~~~ 2 warnings generated.
--
In file included from drivers/spi/spi-rockchip.c:7:
In file included from include/linux/clk.h:14:
In file included from include/linux/notifier.h:16:
In file included from include/linux/srcu.h:21:
In file included from include/linux/workqueue.h:9:
>> include/linux/timer.h:196:83: warning: non-void function does not return a value [-Wreturn-type]
196 | static inline int tmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask) { }
| ^
drivers/spi/spi-rockchip.c:1024:34: warning: unused variable 'rockchip_spi_dt_match' [-Wunused-const-variable]
1024 | static const struct of_device_id rockchip_spi_dt_match[] = {
| ^~~~~~~~~~~~~~~~~~~~~ 2 warnings generated.
--
In file included from drivers/spi/spi-s3c64xx.c:8:
In file included from include/linux/clk.h:14:
In file included from include/linux/notifier.h:16:
In file included from include/linux/srcu.h:21:
In file included from include/linux/workqueue.h:9:
>> include/linux/timer.h:196:83: warning: non-void function does not return a value [-Wreturn-type]
196 | static inline int tmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask) { }
| ^
drivers/spi/spi-s3c64xx.c:1644:34: warning: unused variable 's3c64xx_spi_dt_match' [-Wunused-const-variable]
1644 | static const struct of_device_id s3c64xx_spi_dt_match[] = {
| ^~~~~~~~~~~~~~~~~~~~ 2 warnings generated.
--
In file included from drivers/spi/spi-meson-spifc.c:8:
In file included from include/linux/clk.h:14:
In file included from include/linux/notifier.h:16:
In file included from include/linux/srcu.h:21:
In file included from include/linux/workqueue.h:9:
>> include/linux/timer.h:196:83: warning: non-void function does not return a value [-Wreturn-type]
196 | static inline int tmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask) { }
| ^
drivers/spi/spi-meson-spifc.c:423:34: warning: unused variable 'meson_spifc_dt_match' [-Wunused-const-variable]
423 | static const struct of_device_id meson_spifc_dt_match[] = {
| ^~~~~~~~~~~~~~~~~~~~ 2 warnings generated.
--
In file included from arch/hexagon/kernel/asm-offsets.c:12:
In file included from include/linux/compat.h:15:
In file included from include/linux/socket.h:8:
In file included from include/linux/uio.h:9:
In file included from include/linux/mm_types.h:16:
In file included from include/linux/uprobes.h:18:
>> include/linux/timer.h:196:83: warning: non-void function does not return a value [-Wreturn-type]
196 | static inline int tmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask) { }
| ^1 warning generated.
vim +196 include/linux/timer.h
192
193 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
194 extern int tmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask);
195 #else
> 196 static inline int tmigr_isolated_exclude_cpumask(cpumask_var_t exclude_cpumask) { } 197 #endif
198
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki