Re: [PATCH v2 09/18] x86/resctrl: Allow resctrl_arch_rmid_read() to sleep

From: Peter Newman
Date: Mon Jan 23 2023 - 08:55:12 EST


Hi James,

On Fri, Jan 13, 2023 at 6:56 PM James Morse <james.morse@xxxxxxx> wrote:
> diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
> index d309b830aeb2..d6ae4b713801 100644
> --- a/arch/x86/kernel/cpu/resctrl/monitor.c
> +++ b/arch/x86/kernel/cpu/resctrl/monitor.c
> @@ -206,17 +206,19 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)
> return chunks >> shift;
> }
>
> -int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
> - u32 closid, u32 rmid, enum resctrl_event_id eventid,
> - u64 *val)
> +struct __rmid_read_arg
> {
> - struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
> - struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
> - struct arch_mbm_state *am;
> - u64 msr_val, chunks;
> + u32 rmid;
> + enum resctrl_event_id eventid;
>
> - if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask))
> - return -EINVAL;
> + u64 msr_val;
> +};
> +
> +static void __rmid_read(void *arg)
> +{
> + enum resctrl_event_id eventid = ((struct __rmid_read_arg *)arg)->eventid;
> + u32 rmid = ((struct __rmid_read_arg *)arg)->rmid;
> + u64 msr_val;
>
> /*
> * As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured
> @@ -229,6 +231,28 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
> wrmsr(MSR_IA32_QM_EVTSEL, eventid, rmid);
> rdmsrl(MSR_IA32_QM_CTR, msr_val);
>
> + ((struct __rmid_read_arg *)arg)->msr_val = msr_val;
> +}
> +
> +int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
> + u32 closid, u32 rmid, enum resctrl_event_id eventid,
> + u64 *val)
> +{
> + struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
> + struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
> + struct __rmid_read_arg arg;
> + struct arch_mbm_state *am;
> + u64 msr_val, chunks;
> + int err;
> +
> + arg.rmid = rmid;
> + arg.eventid = eventid;
> +
> + err = smp_call_function_any(&d->cpu_mask, __rmid_read, &arg, true);
> + if (err)
> + return err;
> +
> + msr_val = arg.msr_val;

These changes are conflicting now after v6.2-rc4 due to my recent
changes in resctrl_arch_rmid_read(), which include my own
reintroduction of __rmid_read():

https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=2a81160d29d65b5876ab3f824fda99ae0219f05e

Fortunately it looks like our respective versions of __rmid_read()
aren't too much different from the original, but __rmid_read() does
have a new call site in resctrl_arch_reset_rmid() to record initial
event counts.

-Peter