Re: [PATCH] powercap/rapl: reduce ipi calls

From: Peter Zijlstra
Date: Tue Dec 08 2015 - 03:48:52 EST


On Mon, Dec 07, 2015 at 03:23:22PM -0800, Srinivas Pandruvada wrote:
> On Mon, 2015-12-07 at 15:01 -0800, Jacob Pan wrote:
> > +struct rapl_msr_action {
> > + u32 msr;
> > + unsigned long long value;
> > + int shift;
> > + u64 mask;
> > +};
> > +
> > +static void rapl_write_data_cpu(void *info)
> > +{
> > + u64 msr_val;
> > + struct rapl_msr_action *ra = (struct rapl_msr_action *)info;
> > +
> > + rdmsrl_safe(ra->msr, &msr_val);
> > + msr_val &= ~ra->mask;
> > + msr_val |= ra->value << ra->shift;
> > + wrmsrl_safe(ra->msr, msr_val);
> What about adding additional common interface
> wrmsrl_safe_update(), so that everyone can use this?
>

In which case you want a return value. Also, instead of the value,shift
pair I would add another u64.

Something like:

struct msr_action {
u32 msr;
int ret;
u64 mask, bits;
};

static void msr_update_function(void *info)
{
struct msr_action *ma = info;
int ret = 0;
u64 val;

ret = rdmsrl_safe(ma->msr, &val);
if (ret)
goto out;

val &= ma->mask;
val |= ma->bits;

ret = wrmsrl_safe(ma->msr, val);

out:
ma->ret = ret;
}

int rmwmsrl_safe_on_cpu(u32 msr, int cpu, u64 mask, u64 bits)
{
struct msr_action ma = {
.msr = msr,
.mask = mask,
.bits = bits,
};
int ret;

ret = smp_call_function_single(cpu, msr_update_func, &ma, 1);
if (!ret)
ret = ma.ret;

return ret;
}

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/