Skip to content

Commit fb481ec

Browse files
author
James Morse
committed
arm_mpam: resctrl: Call resctrl_init() on platforms that can support resctrl
Now that MPAM links against resctrl, call resctrl_init() to register the filesystem and setup resctrl's structures. Tested-by: Gavin Shan <gshan@redhat.com> Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Zeng Heng <zengheng4@huawei.com> Tested-by: Punit Agrawal <punit.agrawal@oss.qualcomm.com> Tested-by: Jesse Chick <jessechick@os.amperecomputing.com> Reviewed-by: Zeng Heng <zengheng4@huawei.com> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Co-developed-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: James Morse <james.morse@arm.com>
1 parent 4aab135 commit fb481ec

3 files changed

Lines changed: 94 additions & 5 deletions

File tree

drivers/resctrl/mpam_devices.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ static DECLARE_WORK(mpam_broken_work, &mpam_disable);
7373
/* When mpam is disabled, the printed reason to aid debugging */
7474
static char *mpam_disable_reason;
7575

76+
/*
77+
* Whether resctrl has been setup. Used by cpuhp in preference to
78+
* mpam_is_enabled(). The disable call after an error interrupt makes
79+
* mpam_is_enabled() false before the cpuhp callbacks are made.
80+
* Reads/writes should hold mpam_cpuhp_state_lock, (or be cpuhp callbacks).
81+
*/
82+
static bool mpam_resctrl_enabled;
83+
7684
/*
7785
* An MSC is a physical container for controls and monitors, each identified by
7886
* their RIS index. These share a base-address, interrupts and some MMIO
@@ -1619,7 +1627,7 @@ static int mpam_cpu_online(unsigned int cpu)
16191627
mpam_reprogram_msc(msc);
16201628
}
16211629

1622-
if (mpam_is_enabled())
1630+
if (mpam_resctrl_enabled)
16231631
return mpam_resctrl_online_cpu(cpu);
16241632

16251633
return 0;
@@ -1665,7 +1673,7 @@ static int mpam_cpu_offline(unsigned int cpu)
16651673
{
16661674
struct mpam_msc *msc;
16671675

1668-
if (mpam_is_enabled())
1676+
if (mpam_resctrl_enabled)
16691677
mpam_resctrl_offline_cpu(cpu);
16701678

16711679
guard(srcu)(&mpam_srcu);
@@ -2526,6 +2534,7 @@ static void mpam_enable_once(void)
25262534
}
25272535

25282536
static_branch_enable(&mpam_enabled);
2537+
mpam_resctrl_enabled = true;
25292538
mpam_register_cpuhp_callbacks(mpam_cpu_online, mpam_cpu_offline,
25302539
"mpam:online");
25312540

@@ -2585,24 +2594,39 @@ static void mpam_reset_class(struct mpam_class *class)
25852594
void mpam_disable(struct work_struct *ignored)
25862595
{
25872596
int idx;
2597+
bool do_resctrl_exit;
25882598
struct mpam_class *class;
25892599
struct mpam_msc *msc, *tmp;
25902600

2601+
if (mpam_is_enabled())
2602+
static_branch_disable(&mpam_enabled);
2603+
25912604
mutex_lock(&mpam_cpuhp_state_lock);
25922605
if (mpam_cpuhp_state) {
25932606
cpuhp_remove_state(mpam_cpuhp_state);
25942607
mpam_cpuhp_state = 0;
25952608
}
2609+
2610+
/*
2611+
* Removing the cpuhp state called mpam_cpu_offline() and told resctrl
2612+
* all the CPUs are offline.
2613+
*/
2614+
do_resctrl_exit = mpam_resctrl_enabled;
2615+
mpam_resctrl_enabled = false;
25962616
mutex_unlock(&mpam_cpuhp_state_lock);
25972617

2598-
static_branch_disable(&mpam_enabled);
2618+
if (do_resctrl_exit)
2619+
mpam_resctrl_exit();
25992620

26002621
mpam_unregister_irqs();
26012622

26022623
idx = srcu_read_lock(&mpam_srcu);
26032624
list_for_each_entry_srcu(class, &mpam_classes, classes_list,
2604-
srcu_read_lock_held(&mpam_srcu))
2625+
srcu_read_lock_held(&mpam_srcu)) {
26052626
mpam_reset_class(class);
2627+
if (do_resctrl_exit)
2628+
mpam_resctrl_teardown_class(class);
2629+
}
26062630
srcu_read_unlock(&mpam_srcu, idx);
26072631

26082632
mutex_lock(&mpam_list_lock);

drivers/resctrl/mpam_internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,16 @@ int mpam_get_cpumask_from_cache_id(unsigned long cache_id, u32 cache_level,
431431

432432
#ifdef CONFIG_RESCTRL_FS
433433
int mpam_resctrl_setup(void);
434+
void mpam_resctrl_exit(void);
434435
int mpam_resctrl_online_cpu(unsigned int cpu);
435436
void mpam_resctrl_offline_cpu(unsigned int cpu);
437+
void mpam_resctrl_teardown_class(struct mpam_class *class);
436438
#else
437439
static inline int mpam_resctrl_setup(void) { return 0; }
440+
static inline void mpam_resctrl_exit(void) { }
438441
static inline int mpam_resctrl_online_cpu(unsigned int cpu) { return 0; }
439442
static inline void mpam_resctrl_offline_cpu(unsigned int cpu) { }
443+
static inline void mpam_resctrl_teardown_class(struct mpam_class *class) { }
440444
#endif /* CONFIG_RESCTRL_FS */
441445

442446
/*

drivers/resctrl/mpam_resctrl.c

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ static bool cdp_enabled;
6969
static bool cacheinfo_ready;
7070
static DECLARE_WAIT_QUEUE_HEAD(wait_cacheinfo_ready);
7171

72+
/*
73+
* If resctrl_init() succeeded, resctrl_exit() can be used to remove support
74+
* for the filesystem in the event of an error.
75+
*/
76+
static bool resctrl_enabled;
77+
7278
bool resctrl_arch_alloc_capable(void)
7379
{
7480
struct mpam_resctrl_res *res;
@@ -360,6 +366,9 @@ static int resctrl_arch_mon_ctx_alloc_no_wait(enum resctrl_event_id evtid)
360366
{
361367
struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[evtid];
362368

369+
if (!mpam_is_enabled())
370+
return -EINVAL;
371+
363372
if (!mon->class)
364373
return -EINVAL;
365374

@@ -402,6 +411,9 @@ static void resctrl_arch_mon_ctx_free_no_wait(enum resctrl_event_id evtid,
402411
{
403412
struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[evtid];
404413

414+
if (!mpam_is_enabled())
415+
return;
416+
405417
if (!mon->class)
406418
return;
407419

@@ -488,6 +500,9 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,
488500

489501
resctrl_arch_rmid_read_context_check();
490502

503+
if (!mpam_is_enabled())
504+
return -EINVAL;
505+
491506
if (eventid >= QOS_NUM_EVENTS || !mon->class)
492507
return -EINVAL;
493508

@@ -1162,6 +1177,9 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d,
11621177
lockdep_assert_cpus_held();
11631178
lockdep_assert_irqs_enabled();
11641179

1180+
if (!mpam_is_enabled())
1181+
return -EINVAL;
1182+
11651183
/*
11661184
* No need to check the CPU as mpam_apply_config() doesn't care, and
11671185
* resctrl_arch_update_domains() relies on this.
@@ -1227,6 +1245,9 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)
12271245
lockdep_assert_cpus_held();
12281246
lockdep_assert_irqs_enabled();
12291247

1248+
if (!mpam_is_enabled())
1249+
return -EINVAL;
1250+
12301251
list_for_each_entry_rcu(d, &r->ctrl_domains, hdr.list) {
12311252
for (enum resctrl_conf_type t = 0; t < CDP_NUM_TYPES; t++) {
12321253
struct resctrl_staged_config *cfg = &d->staged_config[t];
@@ -1619,7 +1640,11 @@ int mpam_resctrl_setup(void)
16191640
return -EOPNOTSUPP;
16201641
}
16211642

1622-
/* TODO: call resctrl_init() */
1643+
err = resctrl_init();
1644+
if (err)
1645+
return err;
1646+
1647+
WRITE_ONCE(resctrl_enabled, true);
16231648

16241649
return 0;
16251650

@@ -1629,6 +1654,42 @@ int mpam_resctrl_setup(void)
16291654
return err;
16301655
}
16311656

1657+
void mpam_resctrl_exit(void)
1658+
{
1659+
if (!READ_ONCE(resctrl_enabled))
1660+
return;
1661+
1662+
WRITE_ONCE(resctrl_enabled, false);
1663+
resctrl_exit();
1664+
}
1665+
1666+
/*
1667+
* The driver is detaching an MSC from this class, if resctrl was using it,
1668+
* pull on resctrl_exit().
1669+
*/
1670+
void mpam_resctrl_teardown_class(struct mpam_class *class)
1671+
{
1672+
struct mpam_resctrl_res *res;
1673+
enum resctrl_res_level rid;
1674+
struct mpam_resctrl_mon *mon;
1675+
enum resctrl_event_id eventid;
1676+
1677+
might_sleep();
1678+
1679+
for_each_mpam_resctrl_control(res, rid) {
1680+
if (res->class == class) {
1681+
res->class = NULL;
1682+
break;
1683+
}
1684+
}
1685+
for_each_mpam_resctrl_mon(mon, eventid) {
1686+
if (mon->class == class) {
1687+
mon->class = NULL;
1688+
break;
1689+
}
1690+
}
1691+
}
1692+
16321693
static int __init __cacheinfo_ready(void)
16331694
{
16341695
cacheinfo_ready = true;

0 commit comments

Comments
 (0)