Skip to content

Commit 1458c4f

Browse files
author
James Morse
committed
arm_mpam: resctrl: Add support for csu counters
resctrl exposes a counter via a file named llc_occupancy. This isn't really a counter as its value goes up and down, this is a snapshot of the cache storage usage monitor. Add some picking code which will only find an L3. The resctrl counter file is called llc_occupancy but we don't check it is the last one as it is already identified as L3. Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Zeng Heng <zengheng4@huawei.com> Tested-by: Punit Agrawal <punit.agrawal@oss.qualcomm.com> Tested-by: Gavin Shan <gshan@redhat.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: Dave Martin <dave.martin@arm.com> Signed-off-by: Dave Martin <dave.martin@arm.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 264c285 commit 1458c4f

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

drivers/resctrl/mpam_resctrl.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,28 @@ static bool class_has_usable_mba(struct mpam_props *cprops)
311311
return mba_class_use_mbw_max(cprops);
312312
}
313313

314+
static bool cache_has_usable_csu(struct mpam_class *class)
315+
{
316+
struct mpam_props *cprops;
317+
318+
if (!class)
319+
return false;
320+
321+
cprops = &class->props;
322+
323+
if (!mpam_has_feature(mpam_feat_msmon_csu, cprops))
324+
return false;
325+
326+
/*
327+
* CSU counters settle on the value, so we can get away with
328+
* having only one.
329+
*/
330+
if (!cprops->num_csu_mon)
331+
return false;
332+
333+
return true;
334+
}
335+
314336
/*
315337
* Calculate the worst-case percentage change from each implemented step
316338
* in the control.
@@ -630,6 +652,64 @@ static void mpam_resctrl_pick_mba(void)
630652
}
631653
}
632654

655+
static void counter_update_class(enum resctrl_event_id evt_id,
656+
struct mpam_class *class)
657+
{
658+
struct mpam_class *existing_class = mpam_resctrl_counters[evt_id].class;
659+
660+
if (existing_class) {
661+
if (class->level == 3) {
662+
pr_debug("Existing class is L3 - L3 wins\n");
663+
return;
664+
}
665+
666+
if (existing_class->level < class->level) {
667+
pr_debug("Existing class is closer to L3, %u versus %u - closer is better\n",
668+
existing_class->level, class->level);
669+
return;
670+
}
671+
}
672+
673+
mpam_resctrl_counters[evt_id].class = class;
674+
}
675+
676+
static void mpam_resctrl_pick_counters(void)
677+
{
678+
struct mpam_class *class;
679+
680+
lockdep_assert_cpus_held();
681+
682+
guard(srcu)(&mpam_srcu);
683+
list_for_each_entry_srcu(class, &mpam_classes, classes_list,
684+
srcu_read_lock_held(&mpam_srcu)) {
685+
/* The name of the resource is L3... */
686+
if (class->type == MPAM_CLASS_CACHE && class->level != 3) {
687+
pr_debug("class %u is a cache but not the L3", class->level);
688+
continue;
689+
}
690+
691+
if (!cpumask_equal(&class->affinity, cpu_possible_mask)) {
692+
pr_debug("class %u does not cover all CPUs",
693+
class->level);
694+
continue;
695+
}
696+
697+
if (cache_has_usable_csu(class)) {
698+
pr_debug("class %u has usable CSU",
699+
class->level);
700+
701+
/* CSU counters only make sense on a cache. */
702+
switch (class->type) {
703+
case MPAM_CLASS_CACHE:
704+
counter_update_class(QOS_L3_OCCUP_EVENT_ID, class);
705+
break;
706+
default:
707+
break;
708+
}
709+
}
710+
}
711+
}
712+
633713
static int mpam_resctrl_control_init(struct mpam_resctrl_res *res)
634714
{
635715
struct mpam_class *class = res->class;
@@ -1264,6 +1344,9 @@ int mpam_resctrl_setup(void)
12641344
}
12651345
}
12661346

1347+
/* Find some classes to use for monitors */
1348+
mpam_resctrl_pick_counters();
1349+
12671350
for_each_mpam_resctrl_mon(mon, eventid) {
12681351
if (!mon->class)
12691352
continue; // dummy resource

0 commit comments

Comments
 (0)