Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1580124imu; Wed, 16 Jan 2019 23:16:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN51QHopRCet6gM06uwU+QGsE4A2tgAPP92w4PNF0P/SpQRhHTie6KJIoa0nsNK5D7lVS1fe X-Received: by 2002:a63:1204:: with SMTP id h4mr12439197pgl.51.1547709366682; Wed, 16 Jan 2019 23:16:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547709366; cv=none; d=google.com; s=arc-20160816; b=r2EGdxdGntLvAp6p11NFyufdU1DzgBvcAP4yIg/77Y9hLyYpQy5gAW86KhKzYHDIN8 hJ3B6INWe65LRCEFUD1cpyqDHCa8CSCPrVrNEH9AwCDnhZDgfCvPGPujZNU7odvmFOPY dYX6ZkW/RsUWQIICvnFejbaJQ82yI6sLF5DsY6Mls/J1gy710ppfnEHcR518gNhqBYfv cukYIkU7ssu7Y7Js/aNssSqLKA8yGLPMT6tCwFJVmh3bEQ7qxllPXiKVUUpLY7RNIrAZ vZW0z9xjcojdKeQIqyFUTIEU2GyhXQCBedCnea4SlPVJ99H+TU50wCnAi7f7OtuRTwt1 77yQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=dss5QL+RRg6SOfDvA7mMbqZF+GS9Ej+1gmlPfRw4xqs=; b=Gon6qQlBdhxpo0hDrXBeoTO40+40KB6RvW873MKDUMzdpckgKOdKJWELhaTeAkJqsz Sw+SFLcfg+R5RDH6783J1iKkHvICJph+bsni5kRSpC0wracgntX9Iwnk4jTnAzY5k1sh VHCL7nUNWlUUvwpCpvznTcKWADZHcEDff+705hzqgN77PwWiP/MdAiBb67XOpCmbNRKk IIz8JRA17QZ0xXcKBTiQjSau1yO/49Ui/tkIGOcET+1V09I0tbkMBSWVVOv3Mt7oGAk6 dRvELnbqHZNpf2Go0FMrznllwfxQlKMCcI/WytUJ21ltZsvfm1w/+c/yWYITLXuuiYpu 8omg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z10si987407pfm.37.2019.01.16.23.15.50; Wed, 16 Jan 2019 23:16:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729592AbfAPVYh (ORCPT + 99 others); Wed, 16 Jan 2019 16:24:37 -0500 Received: from mga11.intel.com ([192.55.52.93]:32309 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729481AbfAPVYf (ORCPT ); Wed, 16 Jan 2019 16:24:35 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jan 2019 13:24:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,487,1539673200"; d="scan'208";a="117269591" Received: from romley-ivt3.sc.intel.com ([172.25.110.60]) by fmsmga008.fm.intel.com with ESMTP; 16 Jan 2019 13:24:34 -0800 From: Fenghua Yu To: "Thomas Gleixner" , "Borislav Petkov" , "Ingo Molnar" , "H Peter Anvin" , "Andy Lutomirski" , "Andrew Cooper" , "Ashok Raj" , "Ravi V Shankar" Cc: "linux-kernel" , "x86" , Fenghua Yu Subject: [PATCH v2 3/3] x86/umwait: Control umwait maximum time Date: Wed, 16 Jan 2019 13:18:38 -0800 Message-Id: <1547673522-226408-4-git-send-email-fenghua.yu@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1547673522-226408-1-git-send-email-fenghua.yu@intel.com> References: <1547673522-226408-1-git-send-email-fenghua.yu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org IA32_UMWAIT_CONTROL[31:2] determines the maximum time in TSC-quanta that processor can stay in C0.1 or C0.2. The maximum time value in IA32_UMWAIT_CONTROL[31-2] is set as zero which means there is no global time limit for UMWAIT and TPAUSE instructions. Each process sets its own umwait maximum time as the instructions operand. User can specify global umwait maximum time through interface: /sys/devices/system/cpu/umwait_control/umwait_max_time The value in the interface is in decimal in TSC-quanta. Bits[1:0] are cleared when the value is stored. Signed-off-by: Fenghua Yu --- arch/x86/include/asm/msr-index.h | 2 ++ arch/x86/power/umwait.c | 42 +++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index b56bfecae0de..42b9104fc15b 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -62,6 +62,8 @@ #define MSR_IA32_UMWAIT_CONTROL 0xe1 #define UMWAIT_CONTROL_C02_BIT 0x0 #define UMWAIT_CONTROL_C02_MASK 0x00000001 +#define UMWAIT_CONTROL_MAX_TIME_BIT 0x2 +#define UMWAIT_CONTROL_MAX_TIME_MASK 0xfffffffc #define MSR_PKG_CST_CONFIG_CONTROL 0x000000e2 #define NHM_C3_AUTO_DEMOTE (1UL << 25) diff --git a/arch/x86/power/umwait.c b/arch/x86/power/umwait.c index 95b3867aac1e..4a1a507d3bb7 100644 --- a/arch/x86/power/umwait.c +++ b/arch/x86/power/umwait.c @@ -10,6 +10,7 @@ #include static int umwait_enable_c0_2 = 1; /* 0: disable C0.2. 1: enable C0.2. */ +static u32 umwait_max_time; /* In TSC-quanta. Only bits [31:2] are used. */ static DEFINE_MUTEX(umwait_lock); /* Return value that will be used to set umwait control MSR */ @@ -20,7 +21,8 @@ static inline u32 umwait_control_val(void) * When bit 0 is 1, C0.2 is disabled. Otherwise, C0.2 is enabled. * So value in bit 0 is opposite of umwait_enable_c0_2. */ - return ~umwait_enable_c0_2 & UMWAIT_CONTROL_C02_MASK; + return (~umwait_enable_c0_2 & UMWAIT_CONTROL_C02_MASK) | + umwait_max_time; } static ssize_t umwait_enable_c0_2_show(struct device *dev, @@ -61,8 +63,46 @@ static ssize_t umwait_enable_c0_2_store(struct device *dev, static DEVICE_ATTR_RW(umwait_enable_c0_2); +static ssize_t umwait_max_time_show(struct device *kobj, + struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "%u\n", umwait_max_time); +} + +static ssize_t umwait_max_time_store(struct device *kobj, + struct device_attribute *attr, + const char *buf, size_t count) +{ + u32 msr_val, max_time; + int cpu, ret; + + ret = kstrtou32(buf, 10, &max_time); + if (ret) + return ret; + + mutex_lock(&umwait_lock); + + /* Only get max time value from bits [31:2] */ + max_time &= UMWAIT_CONTROL_MAX_TIME_MASK; + /* Update the max time value in memory */ + umwait_max_time = max_time; + msr_val = umwait_control_val(); + get_online_cpus(); + /* All CPUs have same umwait max time */ + for_each_online_cpu(cpu) + wrmsr_on_cpu(cpu, MSR_IA32_UMWAIT_CONTROL, msr_val, 0); + put_online_cpus(); + + mutex_unlock(&umwait_lock); + + return count; +} + +static DEVICE_ATTR_RW(umwait_max_time); + static struct attribute *umwait_attrs[] = { &dev_attr_umwait_enable_c0_2.attr, + &dev_attr_umwait_max_time.attr, NULL }; -- 2.19.1