Commit bd9a0c97 authored by Fenghua Yu's avatar Fenghua Yu Committed by Thomas Gleixner
Browse files

x86/umwait: Add sysfs interface to control umwait maximum time

IA32_UMWAIT_CONTROL[31:2] determines the maximum time in TSC-quanta
that processor can stay in C0.1 or C0.2. A zero value means no maximum

Each instruction sets its own deadline in the instruction's implicit
input EDX:EAX value. The instruction wakes up if the time-stamp counter
reaches or exceeds the specified deadline, or the umwait maximum time
expires, or a store happens in the monitored address range in umwait.

The administrator can write an unsigned 32-bit number to
/sys/devices/system/cpu/umwait_control/max_time to change the default
value. Note that a value of zero means there is no limit. The lower two
bits of the value must be zero.

[ tglx: Simplify the write function. Massage changelog ]
Signed-off-by: default avatarFenghua Yu <>
Signed-off-by: default avatarThomas Gleixner <>
Reviewed-by: default avatarAshok Raj <>
Reviewed-by: default avatarTony Luck <>
Cc: "Borislav Petkov" <>
Cc: "H Peter Anvin" <>
Cc: "Andy Lutomirski" <>
Cc: "Peter Zijlstra" <>
Cc: "Ravi V Shankar" <>
parent ff4b353f
...@@ -131,8 +131,44 @@ static ssize_t enable_c02_store(struct device *dev, ...@@ -131,8 +131,44 @@ static ssize_t enable_c02_store(struct device *dev,
} }
static DEVICE_ATTR_RW(enable_c02); static DEVICE_ATTR_RW(enable_c02);
static ssize_t
max_time_show(struct device *kobj, struct device_attribute *attr, char *buf)
u32 ctrl = READ_ONCE(umwait_control_cached);
return sprintf(buf, "%u\n", umwait_ctrl_max_time(ctrl));
static ssize_t max_time_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t count)
u32 max_time, ctrl;
int ret;
ret = kstrtou32(buf, 0, &max_time);
if (ret)
return ret;
/* bits[1:0] must be zero */
return -EINVAL;
ctrl = READ_ONCE(umwait_control_cached);
if (max_time != umwait_ctrl_max_time(ctrl))
umwait_update_control(max_time, umwait_ctrl_c02_enabled(ctrl));
return count;
static DEVICE_ATTR_RW(max_time);
static struct attribute *umwait_attrs[] = { static struct attribute *umwait_attrs[] = {
&dev_attr_enable_c02.attr, &dev_attr_enable_c02.attr,
}; };
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment