public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Brian Bloniarz <bmb@athenacr.com>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: Dan Magenheimer <dan.magenheimer@oracle.com>,
	john stultz <johnstul@us.ibm.com>, Ingo Molnar <mingo@elte.hu>,
	Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Andi Kleen <andi@firstfloor.org>,
	Arjan van de Ven <arjan@infradead.org>,
	Venkatesh Pallipadi <venki@google.com>,
	chris.mason@oracle.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86: Export tsc related information in sysfs
Date: Tue, 25 May 2010 20:16:58 -0400	[thread overview]
Message-ID: <4BFC687A.9040304@athenacr.com> (raw)
In-Reply-To: <4BFB2902.50308@athenacr.com>

On 05/24/2010 09:33 PM, Brian Bloniarz wrote:
> So what's wrong with just adding a
> /sys/devices/system/clocksource/clocksource0/tsc_khz?

As an RFC:

Add clocksource.sys_register & sys_unregister so the
current clocksource can add supplemental information to
/sys/devices/system/clocksource/clocksource0/

Export tsc_khz when current_clocksource==tsc so that
daemons like NTP can account for the variability of
calibration results.

diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 9faf91a..9c99965 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -76,6 +76,11 @@ unsigned long long
 sched_clock(void) __attribute__((alias("native_sched_clock")));
 #endif
 
+int sysfs_tsc_register(struct sys_device *clocksource_dev,
+		       struct clocksource *cs);
+void sysfs_tsc_unregister(struct sys_device *clocksource_dev,
+			  struct clocksource *cs);
+
 int check_tsc_unstable(void)
 {
 	return tsc_unstable;
@@ -757,6 +762,8 @@ static struct clocksource clocksource_tsc = {
 #ifdef CONFIG_X86_64
 	.vread                  = vread_tsc,
 #endif
+	.sys_register           = sysfs_tsc_register,
+	.sys_unregister         = sysfs_tsc_unregister,
 };
 
 void mark_tsc_unstable(char *reason)
@@ -967,3 +974,22 @@ void __init tsc_init(void)
 	init_tsc_clocksource();
 }
 
+static ssize_t show_tsc_khz(
+	struct sys_device *dev, struct sysdev_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%u\n", tsc_khz);
+}
+
+static SYSDEV_ATTR(tsc_khz, 0444, show_tsc_khz, NULL);
+
+int sysfs_tsc_register(struct sys_device *clocksource_dev,
+                         struct clocksource *cs)
+{
+    return sysdev_create_file(clocksource_dev, &attr_tsc_khz);
+}
+
+void sysfs_tsc_unregister(struct sys_device *clocksource_dev,
+                          struct clocksource *cs)
+{
+    sysdev_remove_file(clocksource_dev, &attr_tsc_khz);
+}
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index 5ea3c60..d9f6f13 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -15,6 +15,7 @@
 #include <linux/cache.h>
 #include <linux/timer.h>
 #include <linux/init.h>
+#include <linux/sysdev.h>
 #include <asm/div64.h>
 #include <asm/io.h>
 
@@ -156,6 +157,8 @@ extern u64 timecounter_cyc2time(struct timecounter *tc,
  * @vread:		vsyscall based read
  * @suspend:		suspend function for the clocksource, if necessary
  * @resume:		resume function for the clocksource, if necessary
+ * @sys_register:	optional, register additional sysfs attributes
+ * @sys_unregister:	optional, unregister sysfs attributes
  */
 struct clocksource {
 	/*
@@ -194,6 +197,10 @@ struct clocksource {
 	struct list_head wd_list;
 	cycle_t wd_last;
 #endif
+	int (*sys_register)(struct sys_device *clocksource_dev,
+			    struct clocksource *cs);
+	void (*sys_unregister)(struct sys_device *clocksource_dev,
+			       struct clocksource *cs);
 };
 
 /*
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index f08e99c..d8b69a5 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -41,6 +41,8 @@ void timecounter_init(struct timecounter *tc,
 }
 EXPORT_SYMBOL_GPL(timecounter_init);
 
+void sysfs_alter_clocksource(struct clocksource *old, struct clocksource *new);
+
 /**
  * timecounter_read_delta - get nanoseconds since last call of this function
  * @tc:         Pointer to time counter
@@ -572,6 +574,7 @@ static void clocksource_select(void)
 	}
 	if (curr_clocksource != best) {
 		printk(KERN_INFO "Switching to clocksource %s\n", best->name);
+		sysfs_alter_clocksource(curr_clocksource, best);
 		curr_clocksource = best;
 		timekeeping_notify(curr_clocksource);
 	}
@@ -834,6 +837,8 @@ static struct sys_device device_clocksource = {
 	.cls	= &clocksource_sysclass,
 };
 
+static int sysfs_active = 0;
+
 static int __init init_clocksource_sysfs(void)
 {
 	int error = sysdev_class_register(&clocksource_sysclass);
@@ -848,10 +853,34 @@ static int __init init_clocksource_sysfs(void)
 		error = sysdev_create_file(
 				&device_clocksource,
 				&attr_available_clocksource);
+
+	if (!error)
+	{
+		mutex_lock(&clocksource_mutex);
+		if(curr_clocksource->sys_register)
+			error = curr_clocksource->sys_register(
+				&device_clocksource, curr_clocksource);
+		mutex_unlock(&clocksource_mutex);
+	}
+
+	if (!error)
+		sysfs_active = 1;
 	return error;
 }
 
 device_initcall(init_clocksource_sysfs);
+
+void sysfs_alter_clocksource(struct clocksource *old,
+        struct clocksource *new)
+{
+	if(!sysfs_active)
+		return;
+	if(old->sys_unregister)
+		old->sys_unregister(&device_clocksource, old);
+	if(new->sys_register)
+		new->sys_register(&device_clocksource, new);
+}
+
 #endif /* CONFIG_SYSFS */
 
 /**

  reply	other threads:[~2010-05-26  0:17 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-20 19:19 [PATCH] x86: Export tsc related information in sysfs Brian Bloniarz
2010-05-22  2:03 ` john stultz
2010-05-22  3:33   ` H. Peter Anvin
2010-05-24 18:13   ` Dan Magenheimer
2010-05-24 18:19     ` H. Peter Anvin
2010-05-24 18:51     ` john stultz
2010-05-24 20:20       ` H. Peter Anvin
2010-05-24 20:39         ` john stultz
2010-05-24 21:26           ` H. Peter Anvin
2010-05-24 22:04           ` Dan Magenheimer
2010-05-24 22:30             ` H. Peter Anvin
2010-05-24 22:49               ` john stultz
2010-05-24 23:16                 ` Dan Magenheimer
2010-05-24 23:19                   ` H. Peter Anvin
2010-05-24 23:30                   ` john stultz
2010-05-24 23:42                     ` Andi Kleen
2010-05-25  0:01                     ` Dan Magenheimer
2010-05-25  0:07                       ` H. Peter Anvin
2010-05-25  1:33               ` Brian Bloniarz
2010-05-26  0:16                 ` Brian Bloniarz [this message]
2010-05-26  0:48                   ` john stultz
2010-05-26  2:50                     ` Brian Bloniarz
2010-05-26 12:35                       ` Thomas Gleixner
2010-05-26 14:26                         ` Dan Magenheimer
2010-05-26 14:41                           ` Thomas Gleixner
2010-05-26 15:04                       ` john stultz
2010-05-26 16:02                         ` Brian Bloniarz
2010-05-26 16:25                           ` john stultz
2010-05-26 18:24                             ` H. Peter Anvin
2010-05-26 18:44                             ` Brian Bloniarz
2010-05-26 18:51                               ` H. Peter Anvin
2010-05-26 20:19                                 ` john stultz
2010-05-26 21:06                                   ` H. Peter Anvin
2010-05-26 19:49                               ` john stultz
2010-05-26 20:22                                 ` Brian Bloniarz
2010-05-26 12:30                   ` Thomas Gleixner
  -- strict thread matches above, loose matches on Subject: below --
2010-05-15  1:40 Venkatesh Pallipadi
2010-05-15  9:57 ` Andi Kleen
2010-05-15 13:29   ` Dan Magenheimer
2010-05-15 16:48     ` Venkatesh Pallipadi
2010-05-15 19:14     ` Arjan van de Ven
2010-05-15 22:32       ` Dan Magenheimer
2010-05-16  5:43         ` Arjan van de Ven
2010-05-16  9:20           ` Thomas Gleixner
2010-05-16 16:42             ` Dan Magenheimer
2010-05-16 19:14               ` Thomas Gleixner
2010-05-17  1:31                 ` Dan Magenheimer
2010-05-17  5:06                   ` Arjan van de Ven
2010-05-18  9:58                     ` Peter Zijlstra
2010-05-18 10:03                       ` Peter Zijlstra
2010-05-18 11:25                       ` Andi Kleen
2010-05-18 11:58                         ` Peter Zijlstra
2010-05-18 15:13                           ` Dan Magenheimer
2010-05-18 16:40                           ` H. Peter Anvin
2010-05-18 16:52                             ` Peter Zijlstra
2010-05-18 17:04                               ` H. Peter Anvin
2010-05-18 17:49                                 ` Dan Magenheimer
2010-05-18 18:46                                   ` H. Peter Anvin
2010-05-18 19:00                                     ` Dan Magenheimer
2010-05-18 19:16                                       ` Dan Magenheimer
2010-05-18 19:26                                         ` H. Peter Anvin
2010-05-18 20:29                                           ` Dan Magenheimer
2010-05-18 20:34                                             ` H. Peter Anvin
2010-05-18 21:02                                               ` Dan Magenheimer
2010-05-18 21:13                                               ` Andi Kleen
2010-05-19  6:26                                                 ` Peter Zijlstra
2010-05-17 10:20                   ` Thomas Gleixner
2010-05-16 20:29               ` Arjan van de Ven
2010-05-17 10:26         ` Andi Kleen
2010-06-04 14:24           ` Pavel Machek
2010-05-15 22:45     ` Thomas Gleixner
2010-05-17 10:22     ` Andi Kleen
2010-05-17 15:23       ` Dan Magenheimer
2010-05-17 16:56         ` Andi Kleen
2010-05-17 22:36         ` Thomas Gleixner
2010-05-17 23:33           ` Dan Magenheimer
2010-05-18  0:00             ` Ingo Molnar
2010-05-18  0:02             ` Ingo Molnar
2010-05-15 12:35 ` Jaswinder Singh Rajput
2010-05-15 14:37   ` Venkatesh Pallipadi

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=4BFC687A.9040304@athenacr.com \
    --to=bmb@athenacr.com \
    --cc=andi@firstfloor.org \
    --cc=arjan@infradead.org \
    --cc=chris.mason@oracle.com \
    --cc=dan.magenheimer@oracle.com \
    --cc=hpa@zytor.com \
    --cc=johnstul@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=venki@google.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox