All of lore.kernel.org
 help / color / mirror / Atom feed
From: davidwang <davidwang@zhaoxin.com>
To: <tglx@linutronix.de>, <mingo@redhat.com>, <hpa@zytor.com>,
	<mingo@kernel.org>, <x86@kernel.org>, <linux-pm@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Cc: <brucechang@via-alliance.com>, <cooperyan@zhaoxin.com>,
	<qiyuanwang@zhaoxin.com>, <benjaminpan@viatech.com>,
	davidwang <davidwang@zhaoxin.com>
Subject: [PATCH] x86/centaur: Mark TSC invariant
Date: Mon, 22 Jan 2018 18:14:17 +0800	[thread overview]
Message-ID: <1516616057-5158-1-git-send-email-davidwang@zhaoxin.com> (raw)

Centaur CPU has a constant frequency TSC and that TSC does not stop in
C-States. But because the flags are not set for that CPU, the TSC is
treated as not constant frequency and assumed to stop in C-States, which
makes it an unreliable and unusable clock source. Setting those flags
tells the kernel that the TSC is usable, so it will select it over HPET.
The effect of this is that reading time stamps (from kernel or user space)
will be faster and more efficent.

Signed-off-by: davidwang <davidwang@zhaoxin.com>
---
 arch/x86/kernel/cpu/centaur.c | 4 ++++
 drivers/acpi/processor_idle.c | 1 +
 2 files changed, 5 insertions(+)

diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c
index 68bc6d9..c578cd2 100644
--- a/arch/x86/kernel/cpu/centaur.c
+++ b/arch/x86/kernel/cpu/centaur.c
@@ -106,6 +106,10 @@ static void early_init_centaur(struct cpuinfo_x86 *c)
 #ifdef CONFIG_X86_64
 	set_cpu_cap(c, X86_FEATURE_SYSENTER32);
 #endif
+	if (c->x86_power & (1 << 8)) {
+		set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
+		set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
+	}
 }
 
 static void init_centaur(struct cpuinfo_x86 *c)
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index d50a7b6..5f0071c 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -207,6 +207,7 @@ static void tsc_check_state(int state)
 	switch (boot_cpu_data.x86_vendor) {
 	case X86_VENDOR_AMD:
 	case X86_VENDOR_INTEL:
+	case X86_VENDOR_CENTAUR:
 		/*
 		 * AMD Fam10h TSC will tick in all
 		 * C/P/S0/S1 states when this bit is set.
-- 
1.9.1

WARNING: multiple messages have this Message-ID (diff)
From: davidwang <davidwang@zhaoxin.com>
To: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com,
	mingo@kernel.org, x86@kernel.org, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: brucechang@via-alliance.com, cooperyan@zhaoxin.com,
	qiyuanwang@zhaoxin.com, benjaminpan@viatech.com,
	davidwang <davidwang@zhaoxin.com>
Subject: [PATCH] x86/centaur: Mark TSC invariant
Date: Mon, 22 Jan 2018 18:14:17 +0800	[thread overview]
Message-ID: <1516616057-5158-1-git-send-email-davidwang@zhaoxin.com> (raw)

Centaur CPU has a constant frequency TSC and that TSC does not stop in
C-States. But because the flags are not set for that CPU, the TSC is
treated as not constant frequency and assumed to stop in C-States, which
makes it an unreliable and unusable clock source. Setting those flags
tells the kernel that the TSC is usable, so it will select it over HPET.
The effect of this is that reading time stamps (from kernel or user space)
will be faster and more efficent.

Signed-off-by: davidwang <davidwang@zhaoxin.com>
---
 arch/x86/kernel/cpu/centaur.c | 4 ++++
 drivers/acpi/processor_idle.c | 1 +
 2 files changed, 5 insertions(+)

diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c
index 68bc6d9..c578cd2 100644
--- a/arch/x86/kernel/cpu/centaur.c
+++ b/arch/x86/kernel/cpu/centaur.c
@@ -106,6 +106,10 @@ static void early_init_centaur(struct cpuinfo_x86 *c)
 #ifdef CONFIG_X86_64
 	set_cpu_cap(c, X86_FEATURE_SYSENTER32);
 #endif
+	if (c->x86_power & (1 << 8)) {
+		set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
+		set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
+	}
 }
 
 static void init_centaur(struct cpuinfo_x86 *c)
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index d50a7b6..5f0071c 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -207,6 +207,7 @@ static void tsc_check_state(int state)
 	switch (boot_cpu_data.x86_vendor) {
 	case X86_VENDOR_AMD:
 	case X86_VENDOR_INTEL:
+	case X86_VENDOR_CENTAUR:
 		/*
 		 * AMD Fam10h TSC will tick in all
 		 * C/P/S0/S1 states when this bit is set.
-- 
1.9.1

             reply	other threads:[~2018-01-22 10:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-22 10:14 davidwang [this message]
2018-01-22 10:14 ` [PATCH] x86/centaur: Mark TSC invariant davidwang
2018-01-24 12:43 ` [tip:x86/timers] " tip-bot for davidwang
  -- strict thread matches above, loose matches on Subject: below --
2018-01-15  1:35 [PATCH] " TimGuo
2018-01-15  1:35 ` TimGuo
2018-01-15  9:49 ` Thomas Gleixner
2018-01-24 18:26 ` Alan Cox
2018-01-24 18:26   ` Alan Cox
2018-01-10 10:27 TimGuo
2018-01-14 12:06 ` [PATCH] x86/centaur: Mark TSC invariant Thomas Gleixner

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=1516616057-5158-1-git-send-email-davidwang@zhaoxin.com \
    --to=davidwang@zhaoxin.com \
    --cc=benjaminpan@viatech.com \
    --cc=brucechang@via-alliance.com \
    --cc=cooperyan@zhaoxin.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=qiyuanwang@zhaoxin.com \
    --cc=tglx@linutronix.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.