[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1529118375-90191-6-git-send-email-fenghua.yu@intel.com>
Date: Fri, 15 Jun 2018 20:06:12 -0700
From: Fenghua Yu <fenghua.yu@...el.com>
To: "Thomas Gleixner" <tglx@...utronix.de>,
"Ingo Molnar" <mingo@...hat.com>, "H Peter Anvin" <hpa@...or.com>
Cc: "Ashok Raj" <ashok.raj@...el.com>,
"Alan Cox" <alan@...ux.intel.com>,
"Ravi V Shankar" <ravi.v.shankar@...el.com>,
"linux-kernel" <linux-kernel@...r.kernel.org>,
"x86" <x86@...nel.org>, Fenghua Yu <fenghua.yu@...el.com>
Subject: [RFC PATCH 5/8] x86/umwait.c: Add sysfs interface to show tsc_khz
User wait process or any other process wants to know tsc frequency to
convert seconds to tsc ticks. Kernel already gets tsc freqency in kernel
internal variable tsc_khz. The sysfs interface /sys/devices/system/cpu/
user_mwait/tsc_khz exposes the internal variable tsc_khz in decimal to
user.
tsc_khz and the interface are available only on CPU that supports
X86_FEATURE_TSC_KNOW_FREQ.
Signed-off-by: Fenghua Yu <fenghua.yu@...el.com>
---
arch/x86/power/umwait.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/arch/x86/power/umwait.c b/arch/x86/power/umwait.c
index fd7b18d9ed02..33b3ccb40cb9 100644
--- a/arch/x86/power/umwait.c
+++ b/arch/x86/power/umwait.c
@@ -7,7 +7,8 @@
*/
/*
* umwait.c adds control of user wait states that user enters through user wait
- * instructions umwait or tpause.
+ * instructions umwait or tpause. It also dumps tsc_khz to user so user process
+ * can convert seconds to tsc for umwait or other usages.
*/
#include <linux/cpu.h>
#include <asm/msr.h>
@@ -49,7 +50,14 @@ static ssize_t umwait_disable_c0_2_store(struct device *dev,
return count;
}
+static ssize_t tsc_khz_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ return sprintf(buf, "%d\n", tsc_khz);
+}
+
static DEVICE_ATTR_RW(umwait_disable_c0_2);
+static DEVICE_ATTR_RO(tsc_khz);
static struct attribute *umwait_attrs[] = {
&dev_attr_umwait_disable_c0_2.attr,
@@ -92,6 +100,15 @@ static int __init umwait_init(void)
if (ret)
return ret;
+ /* Only add the tsc_khz interface when the value is known. */
+ if (boot_cpu_has(X86_FEATURE_TSC_KNOWN_FREQ)) {
+ ret = sysfs_add_file_to_group(&dev->kobj,
+ &dev_attr_tsc_khz.attr,
+ umwait_attr_group.name);
+ if (ret)
+ goto out_group;
+ }
+
ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "umwait/intel:online",
umwait_cpu_online, NULL);
if (ret < 0)
--
2.5.0
Powered by blists - more mailing lists