Skip to content

Commit 978fcca

Browse files
James Morsebp3tk0v
authored andcommitted
x86/resctrl: Allow overflow/limbo handlers to be scheduled on any-but CPU
When a CPU is taken offline resctrl may need to move the overflow or limbo handlers to run on a different CPU. Once the offline callbacks have been split, cqm_setup_limbo_handler() will be called while the CPU that is going offline is still present in the CPU mask. Pass the CPU to exclude to cqm_setup_limbo_handler() and mbm_setup_overflow_handler(). These functions can use a variant of cpumask_any_but() when selecting the CPU. -1 is used to indicate no CPUs need excluding. Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com> Reviewed-by: Babu Moger <babu.moger@amd.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Babu Moger <babu.moger@amd.com> Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64 Link: https://lore.kernel.org/r/20240213184438.16675-22-james.morse@arm.com Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
1 parent 1b3e50c commit 978fcca

File tree

6 files changed

+72
-21
lines changed

6 files changed

+72
-21
lines changed

arch/x86/kernel/cpu/resctrl/core.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,16 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)
584584
if (r == &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl) {
585585
if (is_mbm_enabled() && cpu == d->mbm_work_cpu) {
586586
cancel_delayed_work(&d->mbm_over);
587-
mbm_setup_overflow_handler(d, 0);
587+
/*
588+
* temporary: exclude_cpu=-1 as this CPU has already
589+
* been removed by cpumask_clear_cpu()d
590+
*/
591+
mbm_setup_overflow_handler(d, 0, RESCTRL_PICK_ANY_CPU);
588592
}
589593
if (is_llc_occupancy_enabled() && cpu == d->cqm_work_cpu &&
590594
has_busy_rmid(d)) {
591595
cancel_delayed_work(&d->cqm_limbo);
592-
cqm_setup_limbo_handler(d, 0);
596+
cqm_setup_limbo_handler(d, 0, RESCTRL_PICK_ANY_CPU);
593597
}
594598
}
595599
}

arch/x86/kernel/cpu/resctrl/ctrlmondata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
552552
return;
553553
}
554554

555-
cpu = cpumask_any_housekeeping(&d->cpu_mask);
555+
cpu = cpumask_any_housekeeping(&d->cpu_mask, RESCTRL_PICK_ANY_CPU);
556556

557557
/*
558558
* cpumask_any_housekeeping() prefers housekeeping CPUs, but

arch/x86/kernel/cpu/resctrl/internal.h

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,36 @@
6060
* cpumask_any_housekeeping() - Choose any CPU in @mask, preferring those that
6161
* aren't marked nohz_full
6262
* @mask: The mask to pick a CPU from.
63+
* @exclude_cpu:The CPU to avoid picking.
6364
*
64-
* Returns a CPU in @mask. If there are housekeeping CPUs that don't use
65-
* nohz_full, these are preferred.
65+
* Returns a CPU from @mask, but not @exclude_cpu. If there are housekeeping
66+
* CPUs that don't use nohz_full, these are preferred. Pass
67+
* RESCTRL_PICK_ANY_CPU to avoid excluding any CPUs.
68+
*
69+
* When a CPU is excluded, returns >= nr_cpu_ids if no CPUs are available.
6670
*/
67-
static inline unsigned int cpumask_any_housekeeping(const struct cpumask *mask)
71+
static inline unsigned int
72+
cpumask_any_housekeeping(const struct cpumask *mask, int exclude_cpu)
6873
{
6974
unsigned int cpu, hk_cpu;
7075

71-
cpu = cpumask_any(mask);
72-
if (!tick_nohz_full_cpu(cpu))
76+
if (exclude_cpu == RESCTRL_PICK_ANY_CPU)
77+
cpu = cpumask_any(mask);
78+
else
79+
cpu = cpumask_any_but(mask, exclude_cpu);
80+
81+
if (!IS_ENABLED(CONFIG_NO_HZ_FULL))
7382
return cpu;
7483

84+
/* If the CPU picked isn't marked nohz_full nothing more needs doing. */
85+
if (cpu < nr_cpu_ids && !tick_nohz_full_cpu(cpu))
86+
return cpu;
87+
88+
/* Try to find a CPU that isn't nohz_full to use in preference */
7589
hk_cpu = cpumask_nth_andnot(0, mask, tick_nohz_full_mask);
90+
if (hk_cpu == exclude_cpu)
91+
hk_cpu = cpumask_nth_andnot(1, mask, tick_nohz_full_mask);
92+
7693
if (hk_cpu < nr_cpu_ids)
7794
cpu = hk_cpu;
7895

@@ -573,11 +590,13 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
573590
struct rdt_domain *d, struct rdtgroup *rdtgrp,
574591
int evtid, int first);
575592
void mbm_setup_overflow_handler(struct rdt_domain *dom,
576-
unsigned long delay_ms);
593+
unsigned long delay_ms,
594+
int exclude_cpu);
577595
void mbm_handle_overflow(struct work_struct *work);
578596
void __init intel_rdt_mbm_apply_quirk(void);
579597
bool is_mba_sc(struct rdt_resource *r);
580-
void cqm_setup_limbo_handler(struct rdt_domain *dom, unsigned long delay_ms);
598+
void cqm_setup_limbo_handler(struct rdt_domain *dom, unsigned long delay_ms,
599+
int exclude_cpu);
581600
void cqm_handle_limbo(struct work_struct *work);
582601
bool has_busy_rmid(struct rdt_domain *d);
583602
void __check_limbo(struct rdt_domain *d, bool force_free);

arch/x86/kernel/cpu/resctrl/monitor.c

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ static void add_rmid_to_limbo(struct rmid_entry *entry)
481481
* setup up the limbo worker.
482482
*/
483483
if (!has_busy_rmid(d))
484-
cqm_setup_limbo_handler(d, CQM_LIMBOCHECK_INTERVAL);
484+
cqm_setup_limbo_handler(d, CQM_LIMBOCHECK_INTERVAL,
485+
RESCTRL_PICK_ANY_CPU);
485486
set_bit(idx, d->rmid_busy_llc);
486487
entry->busy++;
487488
}
@@ -784,23 +785,34 @@ void cqm_handle_limbo(struct work_struct *work)
784785
__check_limbo(d, false);
785786

786787
if (has_busy_rmid(d)) {
787-
d->cqm_work_cpu = cpumask_any_housekeeping(&d->cpu_mask);
788+
d->cqm_work_cpu = cpumask_any_housekeeping(&d->cpu_mask,
789+
RESCTRL_PICK_ANY_CPU);
788790
schedule_delayed_work_on(d->cqm_work_cpu, &d->cqm_limbo,
789791
delay);
790792
}
791793

792794
mutex_unlock(&rdtgroup_mutex);
793795
}
794796

795-
void cqm_setup_limbo_handler(struct rdt_domain *dom, unsigned long delay_ms)
797+
/**
798+
* cqm_setup_limbo_handler() - Schedule the limbo handler to run for this
799+
* domain.
800+
* @dom: The domain the limbo handler should run for.
801+
* @delay_ms: How far in the future the handler should run.
802+
* @exclude_cpu: Which CPU the handler should not run on,
803+
* RESCTRL_PICK_ANY_CPU to pick any CPU.
804+
*/
805+
void cqm_setup_limbo_handler(struct rdt_domain *dom, unsigned long delay_ms,
806+
int exclude_cpu)
796807
{
797808
unsigned long delay = msecs_to_jiffies(delay_ms);
798809
int cpu;
799810

800-
cpu = cpumask_any_housekeeping(&dom->cpu_mask);
811+
cpu = cpumask_any_housekeeping(&dom->cpu_mask, exclude_cpu);
801812
dom->cqm_work_cpu = cpu;
802813

803-
schedule_delayed_work_on(cpu, &dom->cqm_limbo, delay);
814+
if (cpu < nr_cpu_ids)
815+
schedule_delayed_work_on(cpu, &dom->cqm_limbo, delay);
804816
}
805817

806818
void mbm_handle_overflow(struct work_struct *work)
@@ -838,14 +850,24 @@ void mbm_handle_overflow(struct work_struct *work)
838850
* Re-check for housekeeping CPUs. This allows the overflow handler to
839851
* move off a nohz_full CPU quickly.
840852
*/
841-
d->mbm_work_cpu = cpumask_any_housekeeping(&d->cpu_mask);
853+
d->mbm_work_cpu = cpumask_any_housekeeping(&d->cpu_mask,
854+
RESCTRL_PICK_ANY_CPU);
842855
schedule_delayed_work_on(d->mbm_work_cpu, &d->mbm_over, delay);
843856

844857
out_unlock:
845858
mutex_unlock(&rdtgroup_mutex);
846859
}
847860

848-
void mbm_setup_overflow_handler(struct rdt_domain *dom, unsigned long delay_ms)
861+
/**
862+
* mbm_setup_overflow_handler() - Schedule the overflow handler to run for this
863+
* domain.
864+
* @dom: The domain the overflow handler should run for.
865+
* @delay_ms: How far in the future the handler should run.
866+
* @exclude_cpu: Which CPU the handler should not run on,
867+
* RESCTRL_PICK_ANY_CPU to pick any CPU.
868+
*/
869+
void mbm_setup_overflow_handler(struct rdt_domain *dom, unsigned long delay_ms,
870+
int exclude_cpu)
849871
{
850872
unsigned long delay = msecs_to_jiffies(delay_ms);
851873
int cpu;
@@ -856,9 +878,11 @@ void mbm_setup_overflow_handler(struct rdt_domain *dom, unsigned long delay_ms)
856878
*/
857879
if (!resctrl_mounted || !resctrl_arch_mon_capable())
858880
return;
859-
cpu = cpumask_any_housekeeping(&dom->cpu_mask);
881+
cpu = cpumask_any_housekeeping(&dom->cpu_mask, exclude_cpu);
860882
dom->mbm_work_cpu = cpu;
861-
schedule_delayed_work_on(cpu, &dom->mbm_over, delay);
883+
884+
if (cpu < nr_cpu_ids)
885+
schedule_delayed_work_on(cpu, &dom->mbm_over, delay);
862886
}
863887

864888
static int dom_data_init(struct rdt_resource *r)

arch/x86/kernel/cpu/resctrl/rdtgroup.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,7 +2678,8 @@ static int rdt_get_tree(struct fs_context *fc)
26782678
if (is_mbm_enabled()) {
26792679
r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
26802680
list_for_each_entry(dom, &r->domains, list)
2681-
mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL);
2681+
mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL,
2682+
RESCTRL_PICK_ANY_CPU);
26822683
}
26832684

26842685
goto out;
@@ -3989,7 +3990,8 @@ int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d)
39893990

39903991
if (is_mbm_enabled()) {
39913992
INIT_DELAYED_WORK(&d->mbm_over, mbm_handle_overflow);
3992-
mbm_setup_overflow_handler(d, MBM_OVERFLOW_INTERVAL);
3993+
mbm_setup_overflow_handler(d, MBM_OVERFLOW_INTERVAL,
3994+
RESCTRL_PICK_ANY_CPU);
39933995
}
39943996

39953997
if (is_llc_occupancy_enabled())

include/linux/resctrl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#define RESCTRL_RESERVED_CLOSID 0
1111
#define RESCTRL_RESERVED_RMID 0
1212

13+
#define RESCTRL_PICK_ANY_CPU -1
14+
1315
#ifdef CONFIG_PROC_CPU_RESCTRL
1416

1517
int proc_resctrl_show(struct seq_file *m,

0 commit comments

Comments
 (0)