Skip to content

Commit fb56b29

Browse files
author
James Morse
committed
arm_mpam: resctrl: Add resctrl_arch_rmid_read()
resctrl uses resctrl_arch_rmid_read() to read counters. CDP emulation means the counter may need reading in three different ways. The helpers behind the resctrl_arch_ functions will be re-used for the ABMC equivalent functions. Add the rounding helper for checking monitor values while we're here. 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: Jesse Chick <jessechick@os.amperecomputing.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 2a3c79c commit fb56b29

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

drivers/resctrl/mpam_resctrl.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,88 @@ void resctrl_arch_mon_ctx_free(struct rdt_resource *r,
356356
resctrl_arch_mon_ctx_free_no_wait(evtid, mon_idx);
357357
}
358358

359+
static int __read_mon(struct mpam_resctrl_mon *mon, struct mpam_component *mon_comp,
360+
enum mpam_device_features mon_type,
361+
int mon_idx,
362+
enum resctrl_conf_type cdp_type, u32 closid, u32 rmid, u64 *val)
363+
{
364+
struct mon_cfg cfg;
365+
366+
if (!mpam_is_enabled())
367+
return -EINVAL;
368+
369+
/* Shift closid to account for CDP */
370+
closid = resctrl_get_config_index(closid, cdp_type);
371+
372+
if (irqs_disabled()) {
373+
/* Check if we can access this domain without an IPI */
374+
return -EIO;
375+
}
376+
377+
cfg = (struct mon_cfg) {
378+
.mon = mon_idx,
379+
.match_pmg = true,
380+
.partid = closid,
381+
.pmg = rmid,
382+
};
383+
384+
return mpam_msmon_read(mon_comp, &cfg, mon_type, val);
385+
}
386+
387+
static int read_mon_cdp_safe(struct mpam_resctrl_mon *mon, struct mpam_component *mon_comp,
388+
enum mpam_device_features mon_type,
389+
int mon_idx, u32 closid, u32 rmid, u64 *val)
390+
{
391+
if (cdp_enabled) {
392+
u64 code_val = 0, data_val = 0;
393+
int err;
394+
395+
err = __read_mon(mon, mon_comp, mon_type, mon_idx,
396+
CDP_CODE, closid, rmid, &code_val);
397+
if (err)
398+
return err;
399+
400+
err = __read_mon(mon, mon_comp, mon_type, mon_idx,
401+
CDP_DATA, closid, rmid, &data_val);
402+
if (err)
403+
return err;
404+
405+
*val += code_val + data_val;
406+
return 0;
407+
}
408+
409+
return __read_mon(mon, mon_comp, mon_type, mon_idx,
410+
CDP_NONE, closid, rmid, val);
411+
}
412+
413+
/* MBWU when not in ABMC mode (not supported), and CSU counters. */
414+
int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,
415+
u32 closid, u32 rmid, enum resctrl_event_id eventid,
416+
void *arch_priv, u64 *val, void *arch_mon_ctx)
417+
{
418+
struct mpam_resctrl_dom *l3_dom;
419+
struct mpam_component *mon_comp;
420+
u32 mon_idx = *(u32 *)arch_mon_ctx;
421+
enum mpam_device_features mon_type;
422+
struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
423+
424+
resctrl_arch_rmid_read_context_check();
425+
426+
if (eventid >= QOS_NUM_EVENTS || !mon->class)
427+
return -EINVAL;
428+
429+
l3_dom = container_of(hdr, struct mpam_resctrl_dom, resctrl_mon_dom.hdr);
430+
mon_comp = l3_dom->mon_comp[eventid];
431+
432+
if (eventid != QOS_L3_OCCUP_EVENT_ID)
433+
return -EINVAL;
434+
435+
mon_type = mpam_feat_msmon_csu;
436+
437+
return read_mon_cdp_safe(mon, mon_comp, mon_type, mon_idx,
438+
closid, rmid, val);
439+
}
440+
359441
static bool cache_has_usable_cpor(struct mpam_class *class)
360442
{
361443
struct mpam_props *cprops = &class->props;

include/linux/arm_mpam.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ struct rdt_resource;
6767
void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r, enum resctrl_event_id evtid);
6868
void resctrl_arch_mon_ctx_free(struct rdt_resource *r, enum resctrl_event_id evtid, void *ctx);
6969

70+
static inline unsigned int resctrl_arch_round_mon_val(unsigned int val)
71+
{
72+
return val;
73+
}
74+
7075
/**
7176
* mpam_register_requestor() - Register a requestor with the MPAM driver
7277
* @partid_max: The maximum PARTID value the requestor can generate.

0 commit comments

Comments
 (0)