mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: john stultz <johnstul@us.ibm.com>
Cc: lkml <linux-kernel@vger.kernel.org>,
	Darren Hart <dvhltc@us.ibm.com>,
	Nishanth Aravamudan <nacc@us.ibm.com>,
	Frank Sorenson <frank@tuxrocks.com>,
	George Anzinger <george@mvista.com>,
	Roman Zippel <zippel@linux-m68k.org>,
	Ulrich Windl <ulrich.windl@rz.uni-regensburg.de>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH 11/13] Time: x86-64 Conversion to Generic Timekeeping
Date: Sat, 26 Nov 2005 15:55:28 +0100	[thread overview]
Message-ID: <20051126145528.GJ12999@elte.hu> (raw)
In-Reply-To: <20051122013628.18537.58457.sendpatchset@cog.beaverton.ibm.com>


- clean up timeofday-arch-x86-64-part1.patch

Signed-off-by: Ingo Molnar <mingo@elte.hu>

 arch/x86_64/kernel/time.c     |   91 ++++++++++++++++++++++--------------------
 arch/x86_64/kernel/vsyscall.c |   45 ++++++++++++--------
 2 files changed, 75 insertions(+), 61 deletions(-)

Index: linux/arch/x86_64/kernel/time.c
===================================================================
--- linux.orig/arch/x86_64/kernel/time.c
+++ linux/arch/x86_64/kernel/time.c
@@ -42,6 +42,8 @@
 #ifdef CONFIG_X86_LOCAL_APIC
 #include <asm/apic.h>
 #endif
+#include <linux/clocksource.h>
+#include <asm/vsyscall.h>
 
 extern void i8254_timer_resume(void);
 extern int using_apic_timer;
@@ -251,9 +253,10 @@ unsigned long long sched_clock(void)
 	return cycles_2_ns(a);
 }
 
-/* Code to compensate for TSC C3 stalls */
+/* code to compensate for TSC C3 stalls: */
 static u64 tsc_c3_offset;
 static int tsc_unstable;
+
 static inline int check_tsc_unstable(void)
 {
 	return tsc_unstable;
@@ -266,6 +269,7 @@ static inline void mark_tsc_unstable(voi
 void tsc_c3_compensate(unsigned long nsecs)
 {
 	u64 cycles = ((u64)nsecs * tsc_khz)/1000000;
+
 	tsc_c3_offset += cycles;
 }
 
@@ -334,7 +338,7 @@ unsigned long get_cmos_time(void)
 	return mktime(year, mon, day, hour, min, sec);
 }
 
-/* arch specific timeofday hooks */
+/* arch specific timeofday hooks: */
 u64 read_persistent_clock(void)
 {
 	return (u64)get_cmos_time() * NSEC_PER_SEC;
@@ -1042,55 +1046,60 @@ static int __init notsc_setup(char *s)
 __setup("notsc", notsc_setup);
 
 
-/* Clock source code */
-#include <linux/clocksource.h>
-#include <asm/vsyscall.h>
+/* clock-source code: */
 
 static unsigned long current_tsc_khz = 0;
+
 static int tsc_update_callback(void);
 
 #ifdef CONFIG_PARANOID_GENERIC_TIME
 /* This will hurt performance! */
-DEFINE_SPINLOCK(checktsc_lock);
-cycle_t last_tsc;
+static DEFINE_SPINLOCK(checktsc_lock);
+static cycle_t last_tsc;
 
 static cycle_t read_tsc(void)
 {
-	cycle_t ret;
 	unsigned long flags;
+	cycle_t ret;
+
 	spin_lock_irqsave(&checktsc_lock, flags);
 
 	rdtscll(ret);
 
-	if(ret < last_tsc)
+	if (ret < last_tsc)
 		printk("read_tsc: ACK! TSC went backward! Unsynced TSCs?\n");
 	last_tsc = ret;
 
 	spin_unlock_irqrestore(&checktsc_lock, flags);
+
 	return ret;
 }
 
 static cycle_t __vsyscall_fn vread_tsc(void* unused)
 {
 	cycle_t ret;
+
 	rdtscll(ret);
+
 	return ret;
 }
 
 static cycle_t read_tsc_c3(void)
 {
-	cycle_t ret;
 	unsigned long flags;
+	cycle_t ret;
+
 	spin_lock_irqsave(&checktsc_lock, flags);
 
 	rdtscll(ret);
 	ret += tsc_read_c3_time();
 
-	if(ret < last_tsc)
+	if (ret < last_tsc)
 		printk("read_tsc_c3: ACK! TSC went backward! Unsynced TSCs?\n");
 	last_tsc = ret;
 
 	spin_unlock_irqrestore(&checktsc_lock, flags);
+
 	return ret;
 }
 
@@ -1099,43 +1108,37 @@ static cycle_t read_tsc_c3(void)
 static cycle_t read_tsc(void)
 {
 	cycle_t ret;
+
 	rdtscll(ret);
+
 	return ret;
 }
 
 static cycle_t __vsyscall_fn vread_tsc(void* unused)
 {
 	cycle_t ret;
+
 	rdtscll(ret);
+
 	return ret;
 }
 
 static cycle_t read_tsc_c3(void)
 {
 	cycle_t ret;
+
 	rdtscll(ret);
+
 	return ret + tsc_read_c3_time();
 }
 
 #endif /* CONFIG_PARANOID_GENERIC_TIME */
 
-static struct clocksource clocksource_tsc = {
-	.name = "tsc",
-	.rating = 300,
-	.read = read_tsc,
-	.vread = vread_tsc,
-	.mask = (cycle_t)-1,
-	.mult = 0, /* to be set */
-	.shift = 22,
-	.update_callback = tsc_update_callback,
-	.is_continuous = 1,
-};
-
-
 static int tsc_update_callback(void)
 {
 	int change = 0;
-	/* check to see if we should switch to the safe clocksource */
+
+	/* check to see if we should switch to the safe clocksource: */
 	if (tsc_read_c3_time() &&
 		strncmp(clocksource_tsc.name, "c3tsc", 5)) {
 		printk("Falling back to C3 safe TSC\n");
@@ -1150,7 +1153,8 @@ static int tsc_update_callback(void)
 		reselect_clocksource();
 		change = 1;
 	}
-	/* only update if tsc_khz has changed */
+
+	/* only update if tsc_khz has changed: */
 	if (current_tsc_khz != tsc_khz){
 		current_tsc_khz = tsc_khz;
 		clocksource_tsc.mult = clocksource_khz2mult(current_tsc_khz,
@@ -1174,12 +1178,11 @@ static int __init init_tsc_clocksource(v
 module_init(init_tsc_clocksource);
 
 
-#define HPET_MASK (0xFFFFFFFF)
-#define HPET_SHIFT 22
+#define HPET_MASK	0xFFFFFFFF
+#define HPET_SHIFT	22
 
 /* FSEC = 10^-15 NSEC = 10^-9 */
-#define FSEC_PER_NSEC 1000000
-
+#define FSEC_PER_NSEC	1000000
 
 static void *hpet_ptr;
 
@@ -1194,35 +1197,35 @@ static cycle_t __vsyscall_fn vread_hpet(
 }
 
 struct clocksource clocksource_hpet = {
-	.name = "hpet",
-	.rating = 250,
-	.read = read_hpet,
-	.vread = vread_hpet,
-	.mask = (cycle_t)HPET_MASK,
-	.mult = 0, /* set below */
-	.shift = HPET_SHIFT,
-	.is_continuous = 1,
+	.name		= "hpet",
+	.rating		= 250,
+	.read		= read_hpet,
+	.vread		= vread_hpet,
+	.mask		= (cycle_t)HPET_MASK,
+	.mult		= 0, /* set below */
+	.shift		= HPET_SHIFT,
+	.is_continuous	= 1,
 };
 
 static int __init init_hpet_clocksource(void)
 {
 	unsigned long hpet_period;
-	void __iomem* hpet_base;
+	void __iomem *hpet_base;
 	u64 tmp;
 
 	if (!hpet_address)
 		return -ENODEV;
 
-	/* calculate the hpet address */
+	/* calculate the hpet address: */
 	hpet_base =
 		(void __iomem*)ioremap_nocache(hpet_address, HPET_MMAP_SIZE);
 	hpet_ptr = hpet_base + HPET_COUNTER;
 
-	/* calculate the frequency */
+	/* calculate the frequency: */
 	hpet_period = readl(hpet_base + HPET_PERIOD);
 
-
-	/* hpet period is in femto seconds per cycle
+	/*
+	 * hpet period is in femto seconds per cycle
 	 * so we need to convert this to ns/cyc units
 	 * aproximated by mult/2^shift
 	 *
@@ -1237,6 +1240,8 @@ static int __init init_hpet_clocksource(
 	clocksource_hpet.mult = (u32)tmp;
 
 	register_clocksource(&clocksource_hpet);
+
 	return 0;
 }
+
 module_init(init_hpet_clocksource);
Index: linux/arch/x86_64/kernel/vsyscall.c
===================================================================
--- linux.orig/arch/x86_64/kernel/vsyscall.c
+++ linux/arch/x86_64/kernel/vsyscall.c
@@ -29,8 +29,10 @@
 #include <linux/jiffies.h>
 #include <linux/sysctl.h>
 
+
 #include <asm/vsyscall.h>
 #include <asm/pgtable.h>
+#include <asm/unistd.h>
 #include <asm/page.h>
 #include <asm/fixmap.h>
 #include <asm/errno.h>
@@ -42,7 +44,6 @@
 int __sysctl_vsyscall __section_sysctl_vsyscall = 1;
 seqlock_t __xtime_lock __section_xtime_lock = SEQLOCK_UNLOCKED;
 
-
 struct vsyscall_gtod_data_t {
 	struct timeval wall_time_tv;
 	struct timezone sys_tz;
@@ -56,9 +57,6 @@ struct vsyscall_gtod_data_t __vsyscall_g
 extern seqlock_t vsyscall_gtod_lock;
 seqlock_t __vsyscall_gtod_lock __section_vsyscall_gtod_lock = SEQLOCK_UNLOCKED;
 
-
-#include <asm/unistd.h>
-
 static force_inline void timeval_normalize(struct timeval * tv)
 {
 	time_t __sec;
@@ -70,22 +68,28 @@ static force_inline void timeval_normali
 	}
 }
 
-/* XXX - this is ugly. gettimeofday() has a label in it so we can't
-	call it twice.
+/*
+ * XXX - this is ugly. gettimeofday() has a label in it so we can't
+ *       call it twice.
  */
 static force_inline int syscall_gtod(struct timeval *tv, struct timezone *tz)
 {
 	int ret;
+
 	asm volatile("syscall"
 		: "=a" (ret)
-		: "0" (__NR_gettimeofday),"D" (tv),"S" (tz) : __syscall_clobber );
+		: "0" (__NR_gettimeofday),"D" (tv),"S" (tz)
+		: __syscall_clobber);
+
 	return ret;
 }
-static force_inline void do_vgettimeofday(struct timeval* tv)
+
+static force_inline void do_vgettimeofday(struct timeval *tv)
 {
 	cycle_t now, cycle_delta;
 	nsec_t nsec_delta;
 	unsigned long seq;
+
 	do {
 		seq = read_seqbegin(&__vsyscall_gtod_lock);
 
@@ -109,6 +113,7 @@ static force_inline void do_vgettimeofda
 		*tv = __vsyscall_gtod_data.wall_time_tv;
 		do_div(nsec_delta, NSEC_PER_USEC);
 		tv->tv_usec += (unsigned long) nsec_delta;
+
 		while (tv->tv_usec > USEC_PER_SEC) {
 			tv->tv_sec += 1;
 			tv->tv_usec -= USEC_PER_SEC;
@@ -116,7 +121,10 @@ static force_inline void do_vgettimeofda
 	} while (read_seqretry(&__vsyscall_gtod_lock, seq));
 }
 
-/* RED-PEN may want to readd seq locking, but then the variable should be write-once. */
+/*
+ * RED-PEN may want to readd seq locking, but then the variable should be
+ * write-once.
+ */
 static force_inline void do_get_tz(struct timezone * tz)
 {
 	*tz = __vsyscall_gtod_data.sys_tz;
@@ -156,11 +164,14 @@ int __vsyscall(0) vgettimeofday(struct t
 time_t __vsyscall(1) vtime(time_t *t)
 {
 	struct timeval tv;
+
 	if (unlikely(!__sysctl_vsyscall))
 		return time_syscall(t);
+
 	vgettimeofday(&tv, 0);
 	if (t)
 		*t = tv.tv_sec;
+
 	return tv.tv_sec;
 }
 
@@ -174,7 +185,7 @@ long __vsyscall(3) venosys_1(void)
 	return -ENOSYS;
 }
 
-struct clocksource* curr_clock;
+struct clocksource *curr_clock;
 
 void arch_update_vsyscall_gtod(struct timespec wall_time, cycle_t offset_base,
 				struct clocksource *clock, int ntp_adj)
@@ -184,28 +195,26 @@ void arch_update_vsyscall_gtod(struct ti
 	write_seqlock_irqsave(&vsyscall_gtod_lock, flags);
 
 	/* XXX - hackitty hack hack. this is terrible! */
-	if (curr_clock != clock) {
+	if (curr_clock != clock)
 		curr_clock = clock;
-	}
 
-	/* save off wall time as timeval */
+	/* save off wall time as timeval: */
 	vsyscall_gtod_data.wall_time_tv.tv_sec = wall_time.tv_sec;
 	vsyscall_gtod_data.wall_time_tv.tv_usec = wall_time.tv_nsec/1000;
 
-	/* save offset_base */
+	/* save offset_base: */
 	vsyscall_gtod_data.offset_base = offset_base;
 
-	/* copy current clocksource */
+	/* copy current clocksource: */
 	vsyscall_gtod_data.clock = *clock;
 
-	/* apply ntp adjustment to clocksource mult */
+	/* apply ntp adjustment to clocksource mult: */
 	vsyscall_gtod_data.clock.mult += ntp_adj;
 
-	/* save off current timezone */
+	/* save off current timezone: */
 	vsyscall_gtod_data.sys_tz = sys_tz;
 
 	write_sequnlock_irqrestore(&vsyscall_gtod_lock, flags);
-
 }
 
 #ifdef CONFIG_SYSCTL

  reply	other threads:[~2005-11-26 14:55 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-22  1:35 [PATCH 0/13] Time: Generic Timeofday Subsystem (v B11) john stultz
2005-11-22  1:35 ` [PATCH 1/13] Time: Reduced NTP rework (part 1) john stultz
2005-11-26 14:52   ` [patch] warn-on-once.patch Ingo Molnar
2005-11-26 15:03     ` Tim Schmielau
2005-11-26 15:03     ` Michal Schmidt
2005-11-26 15:17     ` Ingo Molnar
2005-11-26 15:21       ` Ingo Molnar
2005-11-26 14:52   ` [PATCH 1/13] Time: Reduced NTP rework (part 1) Ingo Molnar
2005-11-22  1:35 ` [PATCH 2/13] Time: Reduced NTP Rework (part 2) john stultz
2005-11-26 14:53   ` Ingo Molnar
2005-11-22  1:35 ` [PATCH 3/13] Time: Clocksource Infrastructure john stultz
2005-11-26 14:53   ` Ingo Molnar
2005-11-22  1:35 ` [PATCH 4/13] Time: Generic Timekeeping Infrastructure john stultz
2005-11-26 14:54   ` Ingo Molnar
2005-11-22  1:35 ` [PATCH 5/13] Time: i386 Conversion - part 1: Move timer_pit.c to i8253.c john stultz
2005-11-26 14:54   ` Ingo Molnar
2005-11-22  1:35 ` [PATCH 6/13] Time: i386 Conversion - part 2: Move timer_tsc.c to tsc.c john stultz
2005-11-26 14:54   ` Ingo Molnar
2005-11-22  1:36 ` [PATCH 7/13] Time: i386 Conversion - part 3: Rework TSC Support john stultz
2005-11-22  1:36 ` [PATCH 8/13] Time: i386 Conversion - part 4: ACPI PM variable renaming john stultz
2005-11-22  1:36 ` [PATCH 9/13] Time: i386 Conversion - part 5: Enable Generic Timekeeping john stultz
2005-11-26 14:55   ` Ingo Molnar
2005-11-22  1:36 ` [PATCH 10/13] Time: i386 Conversion - part 6: Remove Old Code john stultz
2005-11-22  1:36 ` [PATCH 11/13] Time: x86-64 Conversion to Generic Timekeeping john stultz
2005-11-26 14:55   ` Ingo Molnar [this message]
2005-11-26 15:11     ` Ingo Molnar
2005-11-22  1:36 ` [PATCH 12/13] Time: i386/x86-64 Clocksource Drivers john stultz
2005-11-26 14:55   ` Ingo Molnar
2005-11-22  1:36 ` [PATCH 13/13] Time: Generic Timekeeping Paraniod Debug Patch john stultz
2005-11-22  2:03 ` [PATCH 0/13] Time: Generic Timeofday Subsystem (v B11) john stultz
2005-11-26 14:50 ` Ingo Molnar
2005-11-26 14:58   ` Ingo Molnar
  -- strict thread matches above, loose matches on Subject: below --
2005-11-12  4:48 [PATCH 0/13] Time: Generic Timeofday Subsystem (v B10) john stultz
2005-11-12  4:50 ` [PATCH 11/13] Time: x86-64 Conversion to Generic Timekeeping john stultz

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=20051126145528.GJ12999@elte.hu \
    --to=mingo@elte.hu \
    --cc=dvhltc@us.ibm.com \
    --cc=frank@tuxrocks.com \
    --cc=george@mvista.com \
    --cc=johnstul@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nacc@us.ibm.com \
    --cc=tglx@linutronix.de \
    --cc=ulrich.windl@rz.uni-regensburg.de \
    --cc=zippel@linux-m68k.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®