lkml.org 
[lkml]   [2022]   [Jun]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH v4 15/21] x86/resctrl: Abstract __rmid_read()
Hi, James,

On Tue, Apr 12, 2022 at 12:44:13PM +0000, James Morse wrote:
> diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
> index 71a13c04a846..20c54cbadc0c 100644
> --- a/arch/x86/kernel/cpu/resctrl/monitor.c
> +++ b/arch/x86/kernel/cpu/resctrl/monitor.c
> @@ -167,9 +167,9 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,
> memset(am, 0, sizeof(*am));
> }
>
> -static u64 __rmid_read(u32 rmid, enum resctrl_event_id eventid)
> +int resctrl_arch_rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)
> {
> - u64 val;
> + u64 msr_val;
>
> /*
> * As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured
> @@ -180,14 +180,24 @@ static u64 __rmid_read(u32 rmid, enum resctrl_event_id eventid)
> * are error bits.
> */
> wrmsr(MSR_IA32_QM_EVTSEL, eventid, rmid);
> - rdmsrl(MSR_IA32_QM_CTR, val);
> + rdmsrl(MSR_IA32_QM_CTR, msr_val);
>
> - return val;
> + if (msr_val & RMID_VAL_ERROR)
> + return -EIO;
> + if (msr_val & RMID_VAL_UNAVAIL)
> + return -EINVAL;
> +
> + *val = msr_val;
> +
> + return 0;
> }
>
> static bool rmid_dirty(struct rmid_entry *entry)
> {
> - u64 val = __rmid_read(entry->rmid, QOS_L3_OCCUP_EVENT_ID);
> + u64 val = 0;
> +
> + if (resctrl_arch_rmid_read(entry->rmid, QOS_L3_OCCUP_EVENT_ID, &val))
> + return true;
>
> return val >= resctrl_cqm_threshold;
> }
> @@ -259,8 +269,8 @@ static void add_rmid_to_limbo(struct rmid_entry *entry)
> {
> struct rdt_resource *r;
> struct rdt_domain *d;
> - int cpu;
> - u64 val;
> + int cpu, err;
> + u64 val = 0;
>
> r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
>
> @@ -268,8 +278,10 @@ static void add_rmid_to_limbo(struct rmid_entry *entry)
> cpu = get_cpu();
> list_for_each_entry(d, &r->domains, list) {
> if (cpumask_test_cpu(cpu, &d->cpu_mask)) {
> - val = __rmid_read(entry->rmid, QOS_L3_OCCUP_EVENT_ID);
> - if (val <= resctrl_cqm_threshold)
> + err = resctrl_arch_rmid_read(entry->rmid,
> + QOS_L3_OCCUP_EVENT_ID,
> + &val);
> + if (err || val <= resctrl_cqm_threshold)
> continue;
> }
>
> @@ -315,19 +327,19 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)
> return chunks >> shift;
> }
>
> -static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
> +static int __mon_event_count(u32 rmid, struct rmid_read *rr)
> {
> struct rdt_hw_resource *hw_res = resctrl_to_arch_res(rr->r);
> struct mbm_state *m;
> - u64 chunks, tval;
> + u64 chunks, tval = 0;
>
> if (rr->first)
> resctrl_arch_reset_rmid(rr->r, rr->d, rmid, rr->evtid);
>
> - tval = __rmid_read(rmid, rr->evtid);
> - if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL)) {
> - return tval;
> - }
> + rr->err = resctrl_arch_rmid_read(rmid, rr->evtid, &tval);
> + if (rr->err)
> + return rr->err;
> +
> switch (rr->evtid) {
> case QOS_L3_OCCUP_EVENT_ID:
> rr->val += tval;
> @@ -343,7 +355,7 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
> * Code would never reach here because an invalid
> * event id would fail the __rmid_read.
> */
> - return RMID_VAL_ERROR;
> + return -EINVAL;
> }
>
> if (rr->first) {
> @@ -399,7 +411,7 @@ void mon_event_count(void *info)
> struct rdtgroup *rdtgrp, *entry;
> struct rmid_read *rr = info;
> struct list_head *head;
> - u64 ret_val;
> + int ret_val;

Now ret_val's meaning is changed from rmid value to error value.
I would suggest to name it as "ret" to avoid confusion that this is still a
returned rmid value.

>
> rdtgrp = rr->rgrp;
>
> @@ -419,9 +431,13 @@ void mon_event_count(void *info)
> }
> }
>
> - /* Report error if none of rmid_reads are successful */
> - if (ret_val)
> - rr->val = ret_val;
> + /*
> + * __mon_event_count() calls for newly created monitor groups may
> + * report -EINVAL/Unavailable if the monitor hasn't seen any traffic.
> + * Discard error if any of the monitor event reads succeeded.
> + */
> + if (ret_val == 0)
> + rr->err = 0;
> }
>

Thanks.

-Fenghua

\
 
 \ /
  Last update: 2022-06-08 05:23    [W:0.261 / U:0.100 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site