Skip to content

Commit 193e226

Browse files
committed
Merge tag 'x86_cache_for_v6.1_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 cache resource control updates from Borislav Petkov: - More work by James Morse to disentangle the resctrl filesystem generic code from the architectural one with the endgoal of plugging ARM's MPAM implementation into it too so that the user interface remains the same - Properly restore the MSR_MISC_FEATURE_CONTROL value instead of blindly overwriting it to 0 * tag 'x86_cache_for_v6.1_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (22 commits) x86/resctrl: Make resctrl_arch_rmid_read() return values in bytes x86/resctrl: Add resctrl_rmid_realloc_limit to abstract x86's boot_cpu_data x86/resctrl: Rename and change the units of resctrl_cqm_threshold x86/resctrl: Move get_corrected_mbm_count() into resctrl_arch_rmid_read() x86/resctrl: Move mbm_overflow_count() into resctrl_arch_rmid_read() x86/resctrl: Pass the required parameters into resctrl_arch_rmid_read() x86/resctrl: Abstract __rmid_read() x86/resctrl: Allow per-rmid arch private storage to be reset x86/resctrl: Add per-rmid arch private storage for overflow and chunks x86/resctrl: Calculate bandwidth from the previous __mon_event_count() chunks x86/resctrl: Allow update_mba_bw() to update controls directly x86/resctrl: Remove architecture copy of mbps_val x86/resctrl: Switch over to the resctrl mbps_val list x86/resctrl: Create mba_sc configuration in the rdt_domain x86/resctrl: Abstract and use supports_mba_mbps() x86/resctrl: Remove set_mba_sc()s control array re-initialisation x86/resctrl: Add domain offline callback for resctrl work x86/resctrl: Group struct rdt_hw_domain cleanup x86/resctrl: Add domain online callback for resctrl work x86/resctrl: Merge mon_capable and mon_enabled ...
2 parents b5f0b11 + f7b1843 commit 193e226

File tree

8 files changed

+523
-265
lines changed

8 files changed

+523
-265
lines changed

arch/x86/include/asm/resctrl.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ static void __resctrl_sched_in(void)
8181
}
8282
}
8383

84+
static inline unsigned int resctrl_arch_round_mon_val(unsigned int val)
85+
{
86+
unsigned int scale = boot_cpu_data.x86_cache_occ_scale;
87+
88+
/* h/w works in units of "boot_cpu_data.x86_cache_occ_scale" */
89+
val /= scale;
90+
return val * scale;
91+
}
92+
8493
static inline void resctrl_sched_in(void)
8594
{
8695
if (static_branch_likely(&rdt_enable_key))

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

Lines changed: 38 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ static inline void cache_alloc_hsw_probe(void)
147147
r->cache.shareable_bits = 0xc0000;
148148
r->cache.min_cbm_bits = 2;
149149
r->alloc_capable = true;
150-
r->alloc_enabled = true;
151150

152151
rdt_alloc_capable = true;
153152
}
@@ -211,7 +210,6 @@ static bool __get_mem_config_intel(struct rdt_resource *r)
211210
thread_throttle_mode_init();
212211

213212
r->alloc_capable = true;
214-
r->alloc_enabled = true;
215213

216214
return true;
217215
}
@@ -242,7 +240,6 @@ static bool __rdt_get_mem_config_amd(struct rdt_resource *r)
242240
r->data_width = 4;
243241

244242
r->alloc_capable = true;
245-
r->alloc_enabled = true;
246243

247244
return true;
248245
}
@@ -261,7 +258,6 @@ static void rdt_get_cache_alloc_cfg(int idx, struct rdt_resource *r)
261258
r->cache.shareable_bits = ebx & r->default_ctrl;
262259
r->data_width = (r->cache.cbm_len + 3) / 4;
263260
r->alloc_capable = true;
264-
r->alloc_enabled = true;
265261
}
266262

267263
static void rdt_get_cdp_config(int level)
@@ -300,7 +296,7 @@ mba_wrmsr_amd(struct rdt_domain *d, struct msr_param *m, struct rdt_resource *r)
300296
* that can be written to QOS_MSRs.
301297
* There are currently no SKUs which support non linear delay values.
302298
*/
303-
u32 delay_bw_map(unsigned long bw, struct rdt_resource *r)
299+
static u32 delay_bw_map(unsigned long bw, struct rdt_resource *r)
304300
{
305301
if (r->membw.delay_linear)
306302
return MAX_MBA_BW - bw;
@@ -401,7 +397,7 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,
401397
return NULL;
402398
}
403399

404-
void setup_default_ctrlval(struct rdt_resource *r, u32 *dc, u32 *dm)
400+
static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc)
405401
{
406402
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
407403
int i;
@@ -410,76 +406,65 @@ void setup_default_ctrlval(struct rdt_resource *r, u32 *dc, u32 *dm)
410406
* Initialize the Control MSRs to having no control.
411407
* For Cache Allocation: Set all bits in cbm
412408
* For Memory Allocation: Set b/w requested to 100%
413-
* and the bandwidth in MBps to U32_MAX
414409
*/
415-
for (i = 0; i < hw_res->num_closid; i++, dc++, dm++) {
410+
for (i = 0; i < hw_res->num_closid; i++, dc++)
416411
*dc = r->default_ctrl;
417-
*dm = MBA_MAX_MBPS;
418-
}
412+
}
413+
414+
static void domain_free(struct rdt_hw_domain *hw_dom)
415+
{
416+
kfree(hw_dom->arch_mbm_total);
417+
kfree(hw_dom->arch_mbm_local);
418+
kfree(hw_dom->ctrl_val);
419+
kfree(hw_dom);
419420
}
420421

421422
static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_domain *d)
422423
{
423424
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
424425
struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
425426
struct msr_param m;
426-
u32 *dc, *dm;
427+
u32 *dc;
427428

428429
dc = kmalloc_array(hw_res->num_closid, sizeof(*hw_dom->ctrl_val),
429430
GFP_KERNEL);
430431
if (!dc)
431432
return -ENOMEM;
432433

433-
dm = kmalloc_array(hw_res->num_closid, sizeof(*hw_dom->mbps_val),
434-
GFP_KERNEL);
435-
if (!dm) {
436-
kfree(dc);
437-
return -ENOMEM;
438-
}
439-
440434
hw_dom->ctrl_val = dc;
441-
hw_dom->mbps_val = dm;
442-
setup_default_ctrlval(r, dc, dm);
435+
setup_default_ctrlval(r, dc);
443436

444437
m.low = 0;
445438
m.high = hw_res->num_closid;
446439
hw_res->msr_update(d, &m, r);
447440
return 0;
448441
}
449442

450-
static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_domain *d)
443+
/**
444+
* arch_domain_mbm_alloc() - Allocate arch private storage for the MBM counters
445+
* @num_rmid: The size of the MBM counter array
446+
* @hw_dom: The domain that owns the allocated arrays
447+
*/
448+
static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)
451449
{
452450
size_t tsize;
453451

454-
if (is_llc_occupancy_enabled()) {
455-
d->rmid_busy_llc = bitmap_zalloc(r->num_rmid, GFP_KERNEL);
456-
if (!d->rmid_busy_llc)
457-
return -ENOMEM;
458-
INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo);
459-
}
460452
if (is_mbm_total_enabled()) {
461-
tsize = sizeof(*d->mbm_total);
462-
d->mbm_total = kcalloc(r->num_rmid, tsize, GFP_KERNEL);
463-
if (!d->mbm_total) {
464-
bitmap_free(d->rmid_busy_llc);
453+
tsize = sizeof(*hw_dom->arch_mbm_total);
454+
hw_dom->arch_mbm_total = kcalloc(num_rmid, tsize, GFP_KERNEL);
455+
if (!hw_dom->arch_mbm_total)
465456
return -ENOMEM;
466-
}
467457
}
468458
if (is_mbm_local_enabled()) {
469-
tsize = sizeof(*d->mbm_local);
470-
d->mbm_local = kcalloc(r->num_rmid, tsize, GFP_KERNEL);
471-
if (!d->mbm_local) {
472-
bitmap_free(d->rmid_busy_llc);
473-
kfree(d->mbm_total);
459+
tsize = sizeof(*hw_dom->arch_mbm_local);
460+
hw_dom->arch_mbm_local = kcalloc(num_rmid, tsize, GFP_KERNEL);
461+
if (!hw_dom->arch_mbm_local) {
462+
kfree(hw_dom->arch_mbm_total);
463+
hw_dom->arch_mbm_total = NULL;
474464
return -ENOMEM;
475465
}
476466
}
477467

478-
if (is_mbm_enabled()) {
479-
INIT_DELAYED_WORK(&d->mbm_over, mbm_handle_overflow);
480-
mbm_setup_overflow_handler(d, MBM_OVERFLOW_INTERVAL);
481-
}
482-
483468
return 0;
484469
}
485470

@@ -502,6 +487,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)
502487
struct list_head *add_pos = NULL;
503488
struct rdt_hw_domain *hw_dom;
504489
struct rdt_domain *d;
490+
int err;
505491

506492
d = rdt_find_domain(r, id, &add_pos);
507493
if (IS_ERR(d)) {
@@ -527,25 +513,22 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)
527513
rdt_domain_reconfigure_cdp(r);
528514

529515
if (r->alloc_capable && domain_setup_ctrlval(r, d)) {
530-
kfree(hw_dom);
516+
domain_free(hw_dom);
531517
return;
532518
}
533519

534-
if (r->mon_capable && domain_setup_mon_state(r, d)) {
535-
kfree(hw_dom->ctrl_val);
536-
kfree(hw_dom->mbps_val);
537-
kfree(hw_dom);
520+
if (r->mon_capable && arch_domain_mbm_alloc(r->num_rmid, hw_dom)) {
521+
domain_free(hw_dom);
538522
return;
539523
}
540524

541525
list_add_tail(&d->list, add_pos);
542526

543-
/*
544-
* If resctrl is mounted, add
545-
* per domain monitor data directories.
546-
*/
547-
if (static_branch_unlikely(&rdt_mon_enable_key))
548-
mkdir_mondata_subdir_allrdtgrp(r, d);
527+
err = resctrl_online_domain(r, d);
528+
if (err) {
529+
list_del(&d->list);
530+
domain_free(hw_dom);
531+
}
549532
}
550533

551534
static void domain_remove_cpu(int cpu, struct rdt_resource *r)
@@ -563,41 +546,17 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)
563546

564547
cpumask_clear_cpu(cpu, &d->cpu_mask);
565548
if (cpumask_empty(&d->cpu_mask)) {
566-
/*
567-
* If resctrl is mounted, remove all the
568-
* per domain monitor data directories.
569-
*/
570-
if (static_branch_unlikely(&rdt_mon_enable_key))
571-
rmdir_mondata_subdir_allrdtgrp(r, d->id);
549+
resctrl_offline_domain(r, d);
572550
list_del(&d->list);
573-
if (r->mon_capable && is_mbm_enabled())
574-
cancel_delayed_work(&d->mbm_over);
575-
if (is_llc_occupancy_enabled() && has_busy_rmid(r, d)) {
576-
/*
577-
* When a package is going down, forcefully
578-
* decrement rmid->ebusy. There is no way to know
579-
* that the L3 was flushed and hence may lead to
580-
* incorrect counts in rare scenarios, but leaving
581-
* the RMID as busy creates RMID leaks if the
582-
* package never comes back.
583-
*/
584-
__check_limbo(d, true);
585-
cancel_delayed_work(&d->cqm_limbo);
586-
}
587551

588552
/*
589553
* rdt_domain "d" is going to be freed below, so clear
590554
* its pointer from pseudo_lock_region struct.
591555
*/
592556
if (d->plr)
593557
d->plr->d = NULL;
558+
domain_free(hw_dom);
594559

595-
kfree(hw_dom->ctrl_val);
596-
kfree(hw_dom->mbps_val);
597-
bitmap_free(d->rmid_busy_llc);
598-
kfree(d->mbm_total);
599-
kfree(d->mbm_local);
600-
kfree(hw_dom);
601560
return;
602561
}
603562

0 commit comments

Comments
 (0)