lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20201231122819.13980-1-redha.gouicem@gmail.com>
Date:   Thu, 31 Dec 2020 13:28:18 +0100
From:   Redha Gouicem <redha.gouicem@...il.com>
To:     unlisted-recipients:; (no To-header on input)
Cc:     Redha Gouicem <redha.gouicem@...il.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        x86@...nel.org, "H. Peter Anvin" <hpa@...or.com>,
        Juergen Gross <jgross@...e.com>,
        Vincenzo Frascino <vincenzo.frascino@....com>,
        Michael Kelley <mikelley@...rosoft.com>,
        Paolo Bonzini <pbonzini@...hat.com>,
        Krzysztof Piecuch <piecuch@...tonmail.com>,
        Martin Molnar <martin.molnar.programming@...il.com>,
        linux-kernel@...r.kernel.org
Subject: [PATCH] x86/tsc: export tsc_khz to sysfs

Export the frequency of the tsc clock to user space. This is particularly
useful for benchmarking purposes because it allows to convert tsc cycles
into time. The value is available at:
     /sys/devices/system/cpu/tsc_khz

Signed-off-by: Redha Gouicem <redha.gouicem@...il.com>
---
 arch/x86/kernel/tsc.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 49d925043171..6ea991516d08 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -14,6 +14,7 @@
 #include <linux/percpu.h>
 #include <linux/timex.h>
 #include <linux/static_key.h>
+#include <linux/cpu.h>
 
 #include <asm/hpet.h>
 #include <asm/timer.h>
@@ -1412,6 +1413,15 @@ static int __init init_tsc_clocksource(void)
  */
 device_initcall(init_tsc_clocksource);
 
+/* sysfs file to export tsc_khz */
+static ssize_t tsc_khz_show(struct kobject *kobj,
+			    struct kobj_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%u\n", tsc_khz);
+}
+
+struct kobj_attribute tsc_khz_attr = __ATTR_RO(tsc_khz);
+
 static bool __init determine_cpu_tsc_frequencies(bool early)
 {
 	/* Make sure that cpu and tsc are not already calibrated */
@@ -1530,6 +1540,19 @@ void __init tsc_init(void)
 	detect_art();
 }
 
+static int __init tsc_khz_sysfs_init(void)
+{
+	int ret = sysfs_create_file(&cpu_subsys.dev_root->kobj, &tsc_khz_attr.attr);
+
+	if (!ret)
+		pr_info("tsc_khz exported in sysfs\n");
+	else
+		pr_warn("tsc_khz failed to be exported in sysfs\n");
+
+	return ret;
+}
+late_initcall(tsc_khz_sysfs_init);
+
 #ifdef CONFIG_SMP
 /*
  * If we have a constant TSC and are using the TSC for the delay loop,
-- 
2.30.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ