From: Thomas Gleixner <tglx@linutronix.de>
To: Fenghua Yu <fenghua.yu@intel.com>
Cc: Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
H Peter Anvin <hpa@zytor.com>, Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Ashok Raj <ashok.raj@intel.com>, Tony Luck <tony.luck@intel.com>,
Ravi V Shankar <ravi.v.shankar@intel.com>,
linux-kernel <linux-kernel@vger.kernel.org>, x86 <x86@kernel.org>
Subject: Re: [PATCH v5 4/5] x86/umwait: Add sysfs interface to control umwait maximum time
Date: Mon, 24 Jun 2019 00:40:33 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.21.1906232246380.32342@nanos.tec.linutronix.de> (raw)
In-Reply-To: <1560994438-235698-5-git-send-email-fenghua.yu@intel.com>
On Wed, 19 Jun 2019, Fenghua Yu wrote:
> Users can write an unsigned 32-bit number to
> /sys/devices/system/cpu/umwait_control/max_time to change the default
Users? Administrators can. Users NOT.
> value. Note that a value of zero means there is no limit. Low order
> two bits must be zero.
...
> +static ssize_t max_time_store(struct device *kobj,
> + struct device_attribute *attr,
> + const char *buf, size_t count)
> +{
> + u32 max_time;
> + int ret;
> +
> + ret = kstrtou32(buf, 0, &max_time);
> + if (ret)
> + return ret;
> +
> + /* bits[1:0] must be zero */
> + if (max_time & ~MSR_IA32_UMWAIT_CONTROL_MAX_TIME)
> + return -EINVAL;
> +
> + mutex_lock(&umwait_lock);
> +
> + if (max_time == get_umwait_ctrl_max_time())
> + goto out_unlock;
> +
> + WRITE_ONCE(umwait_control_cached,
> + UMWAIT_CTRL_VAL(max_time, get_umwait_ctrl_c02()));
Same convoluted logic with reading the cached value twice to confuse the
reader.
ctrl = READ_ONCE(umwait_control_cached);
if (max_time == umwait_ctrl_max_time(ctrl))
goto out_unlock;
ctrl = (ctrl & ~MSR_IA32_UMWAIT_CONTROL_TIME_MASK) | max_time;
WRITE_ONCE(umwait_control_cached, ctrl);
Simple, right?
But this can be done even simpler with a shared update function:
static void umwait_update_control(u32 maxtime, bool c02_enable)
{
u32 ctrl = maxtime & MSR_IA32_UMWAIT_CONTROL_TIME_MASK;
if (!c02_enable)
ctrl |= MSR_IA32_UMWAIT_CONTROL_C02_DISABLE;
WRITE_ONCE(umwait_control_cached, ctrl);
/* Propagate to all CPUs */
on_each_cpu(umwait_update_control_msr, NULL, 1);
}
With that both functions become trivial and do not have duplicated code.
Thanks,
tglx
next prev parent reply other threads:[~2019-06-24 3:02 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-20 1:33 [PATCH v5 0/5] x86/umwait: Enable user wait instructions Fenghua Yu
2019-06-20 1:33 ` [PATCH v5 1/5] x86/cpufeatures: Enumerate " Fenghua Yu
2019-06-24 0:01 ` [tip:x86/cpu] " tip-bot for Fenghua Yu
2019-06-20 1:33 ` [PATCH v5 2/5] x86/umwait: Initialize umwait control values Fenghua Yu
2019-06-23 22:39 ` Thomas Gleixner
2019-06-24 22:12 ` Fenghua Yu
2019-06-24 0:01 ` [tip:x86/cpu] " tip-bot for Fenghua Yu
2019-06-20 1:33 ` [PATCH v5 3/5] x86/umwait: Add sysfs interface to control umwait C0.2 state Fenghua Yu
2019-06-23 22:40 ` Thomas Gleixner
2019-06-24 0:02 ` [tip:x86/cpu] " tip-bot for Fenghua Yu
2019-06-20 1:33 ` [PATCH v5 4/5] x86/umwait: Add sysfs interface to control umwait maximum time Fenghua Yu
2019-06-23 22:40 ` Thomas Gleixner [this message]
2019-06-24 0:03 ` [tip:x86/cpu] " tip-bot for Fenghua Yu
2019-06-20 1:33 ` [PATCH v5 5/5] x86/umwait: Document umwait control sysfs interfaces Fenghua Yu
2019-06-23 22:42 ` Thomas Gleixner
2019-06-23 22:46 ` Thomas Gleixner
2019-06-24 0:03 ` [tip:x86/cpu] Documentation/ABI: " tip-bot for Fenghua Yu
2019-06-20 16:25 ` [PATCH v5 0/5] x86/umwait: Enable user wait instructions Andy Lutomirski
2019-06-20 23:28 ` Fenghua Yu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.21.1906232246380.32342@nanos.tec.linutronix.de \
--to=tglx@linutronix.de \
--cc=ashok.raj@intel.com \
--cc=bp@alien8.de \
--cc=fenghua.yu@intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=ravi.v.shankar@intel.com \
--cc=tony.luck@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).