Skip to contentSkip to conversation

ia64: convert to use clocksource code

PATCH In review Peter Keilty 6 participants 21 messages Apr 26, 2007 – May 2, 2007

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 ia64: convert to use clocksource code

From: Peter Keilty <[email protected]>

Initial ia64 conversion to the generic timekeeping/clocksource code.

---

 arch/ia64/Kconfig                     |    6 +-
 arch/ia64/configs/bigsur_defconfig    |    2 
 arch/ia64/configs/gensparse_defconfig |    2 
 arch/ia64/configs/sim_defconfig       |    2 
 arch/ia64/configs/sn2_defconfig       |    2 
 arch/ia64/configs/tiger_defconfig     |    2 
 arch/ia64/configs/zx1_defconfig       |    2 
 arch/ia64/defconfig                   |    2 
 arch/ia64/kernel/asm-offsets.c        |   18 ++----
 arch/ia64/kernel/cyclone.c            |   45 +++++++++++-----
 arch/ia64/kernel/fsys.S               |   93 ++++++++++++++--------------------
 arch/ia64/kernel/time.c               |   70 ++++++++++++++++++++++---
 arch/ia64/sn/kernel/sn2/timer.c       |   28 +++++++---
 drivers/acpi/processor_idle.c         |    4 +
 drivers/char/hpet.c                   |   68 +++++++++++++-----------
 include/linux/clocksource.h           |    3 +
 16 files changed, 214 insertions(+), 135 deletions(-)

linux-2.6.21-rc1_timeofday-arch-ia64_C7.patch
======================

arch/ia64/Kconfig +5 -1
index d51f0f1..9a7260a 100644
@@ -56,7 +56,11 @@ config GENERIC_CALIBRATE_DELAY
 	bool
 	default y
 
-config TIME_INTERPOLATION
+config GENERIC_TIME
+	bool
+	default y
+
+config GENERIC_TIME_VSYSCALL
 	bool
 	default y
 
arch/ia64/configs/bigsur_defconfig +1 -1
index 90e9c2e..9eb48c0 100644
@@ -85,7 +85,7 @@ CONFIG_MMU=y
 CONFIG_SWIOTLB=y
 CONFIG_RWSEM_XCHGADD_ALGORITHM=y
 CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_TIME_INTERPOLATION=y
+CONFIG_GENERIC_TIME=y
 CONFIG_EFI=y
 CONFIG_GENERIC_IOMAP=y
 CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
arch/ia64/configs/gensparse_defconfig +1 -1
index 0d29aa2..3a9ed95 100644
@@ -86,7 +86,7 @@ CONFIG_MMU=y
 CONFIG_SWIOTLB=y
 CONFIG_RWSEM_XCHGADD_ALGORITHM=y
 CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_TIME_INTERPOLATION=y
+CONFIG_GENERIC_TIME=y
 CONFIG_EFI=y
 CONFIG_GENERIC_IOMAP=y
 CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
arch/ia64/configs/sim_defconfig +1 -1
index d9146c3..c420d9f 100644
@@ -86,7 +86,7 @@ CONFIG_MMU=y
 CONFIG_SWIOTLB=y
 CONFIG_RWSEM_XCHGADD_ALGORITHM=y
 CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_TIME_INTERPOLATION=y
+CONFIG_GENERIC_TIME=y
 CONFIG_EFI=y
 CONFIG_GENERIC_IOMAP=y
 CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
arch/ia64/configs/sn2_defconfig +1 -1
index 64e951d..4c9ffc4 100644
@@ -93,7 +93,7 @@ CONFIG_SWIOTLB=y
 CONFIG_RWSEM_XCHGADD_ALGORITHM=y
 CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_TIME_INTERPOLATION=y
+CONFIG_GENERIC_TIME=y
 CONFIG_DMI=y
 CONFIG_EFI=y
 CONFIG_GENERIC_IOMAP=y
arch/ia64/configs/tiger_defconfig +1 -1
index 9d1cffb..5bd072a 100644
@@ -86,7 +86,7 @@ CONFIG_MMU=y
 CONFIG_SWIOTLB=y
 CONFIG_RWSEM_XCHGADD_ALGORITHM=y
 CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_TIME_INTERPOLATION=y
+CONFIG_GENERIC_TIME=y
 CONFIG_EFI=y
 CONFIG_GENERIC_IOMAP=y
 CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
arch/ia64/configs/zx1_defconfig +1 -1
index 949dc46..17bdfc8 100644
@@ -84,7 +84,7 @@ CONFIG_MMU=y
 CONFIG_SWIOTLB=y
 CONFIG_RWSEM_XCHGADD_ALGORITHM=y
 CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_TIME_INTERPOLATION=y
+CONFIG_GENERIC_TIME=y
 CONFIG_EFI=y
 CONFIG_GENERIC_IOMAP=y
 CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
arch/ia64/defconfig +1 -1
index 9001b3f..61ad76a 100644
@@ -86,7 +86,7 @@ CONFIG_MMU=y
 CONFIG_SWIOTLB=y
 CONFIG_RWSEM_XCHGADD_ALGORITHM=y
 CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_TIME_INTERPOLATION=y
+CONFIG_GENERIC_TIME=y
 CONFIG_EFI=y
 CONFIG_GENERIC_IOMAP=y
 CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
arch/ia64/kernel/asm-offsets.c +6 -12
index 75a2a2c..3e4039e 100644
@@ -7,6 +7,7 @@
 #define ASM_OFFSETS_C 1
 
 #include <linux/sched.h>
+#include <linux/clocksource.h>
 
 #include <asm-ia64/processor.h>
 #include <asm-ia64/ptrace.h>
@@ -255,17 +256,10 @@ #endif
 	BLANK();
 
 	/* used by fsys_gettimeofday in arch/ia64/kernel/fsys.S */
-	DEFINE(IA64_TIME_INTERPOLATOR_ADDRESS_OFFSET, offsetof (struct time_interpolator, addr));
-	DEFINE(IA64_TIME_INTERPOLATOR_SOURCE_OFFSET, offsetof (struct time_interpolator, source));
-	DEFINE(IA64_TIME_INTERPOLATOR_SHIFT_OFFSET, offsetof (struct time_interpolator, shift));
-	DEFINE(IA64_TIME_INTERPOLATOR_NSEC_OFFSET, offsetof (struct time_interpolator, nsec_per_cyc));
-	DEFINE(IA64_TIME_INTERPOLATOR_OFFSET_OFFSET, offsetof (struct time_interpolator, offset));
-	DEFINE(IA64_TIME_INTERPOLATOR_LAST_CYCLE_OFFSET, offsetof (struct time_interpolator, last_cycle));
-	DEFINE(IA64_TIME_INTERPOLATOR_LAST_COUNTER_OFFSET, offsetof (struct time_interpolator, last_counter));
-	DEFINE(IA64_TIME_INTERPOLATOR_JITTER_OFFSET, offsetof (struct time_interpolator, jitter));
-	DEFINE(IA64_TIME_INTERPOLATOR_MASK_OFFSET, offsetof (struct time_interpolator, mask));
-	DEFINE(IA64_TIME_SOURCE_CPU, TIME_SOURCE_CPU);
-	DEFINE(IA64_TIME_SOURCE_MMIO64, TIME_SOURCE_MMIO64);
-	DEFINE(IA64_TIME_SOURCE_MMIO32, TIME_SOURCE_MMIO32);
 	DEFINE(IA64_TIMESPEC_TV_NSEC_OFFSET, offsetof (struct timespec, tv_nsec));
+	DEFINE(IA64_CLOCKSOURCE_MASK_OFFSET, offsetof (struct clocksource, mask));
+	DEFINE(IA64_CLOCKSOURCE_MULT_OFFSET, offsetof (struct clocksource, mult));
+	DEFINE(IA64_CLOCKSOURCE_SHIFT_OFFSET, offsetof (struct clocksource, shift));
+	DEFINE(IA64_CLOCKSOURCE_MMIO_PTR_OFFSET, offsetof (struct clocksource, fsys_mmio_ptr));
+	DEFINE(IA64_CLOCKSOURCE_CYCLE_LAST_OFFSET, offsetof (struct clocksource, cycle_last));
 }
arch/ia64/kernel/cyclone.c +31 -14

99 lines not on this page · raw message

arch/ia64/kernel/fsys.S +39 -54

163 lines not on this page · raw message

arch/ia64/kernel/time.c +62 -8

111 lines not on this page · raw message

arch/ia64/sn/kernel/sn2/timer.c +20 -8
index 56a88b6..f6a160b 100644
@@ -11,6 +11,7 @@ #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/time.h>
 #include <linux/interrupt.h>
+#include <linux/clocksource.h>
 
 #include <asm/hw_irq.h>
 #include <asm/system.h>
@@ -22,11 +23,21 @@ #include <asm/sn/clksupport.h>
 
 extern unsigned long sn_rtc_cycles_per_second;
 
-static struct time_interpolator sn2_interpolator = {
-	.drift = -1,
-	.shift = 10,
-	.mask = (1LL << 55) - 1,
-	.source = TIME_SOURCE_MMIO64
+static void __iomem *sn2_mc_ptr;
+
+static cycle_t read_sn2(void)
+{
+	return (cycle_t)readq(sn2_mc_ptr);
+}
+
+static struct clocksource clocksource_sn2 = {
+        .name           = "sn2_rtc",
+        .rating         = 300,
+        .read           = read_sn2,
+        .mask           = (1LL << 55) - 1,
+        .mult           = 0,
+        .shift          = 10,
+        .is_continuous  = 1,
 };
 
 /*
@@ -47,9 +58,10 @@ ia64_sn_udelay (unsigned long usecs)
 
 void __init sn_timer_init(void)
 {
-	sn2_interpolator.frequency = sn_rtc_cycles_per_second;
-	sn2_interpolator.addr = RTC_COUNTER_ADDR;
-	register_time_interpolator(&sn2_interpolator);
+	clocksource_sn2.fsys_mmio_ptr = sn2_mc_ptr = RTC_COUNTER_ADDR;
+	clocksource_sn2.mult = clocksource_hz2mult(sn_rtc_cycles_per_second,
+							clocksource_sn2.shift);
+	clocksource_register(&clocksource_sn2);
 
 	ia64_udelay = &ia64_sn_udelay;
 }
drivers/acpi/processor_idle.c +4 -0
index 6077300..35ad71f 100644
@@ -480,10 +480,12 @@ #endif
 		/* Get end time (ticks) */
 		t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
 
+#ifndef CONFIG_IA64
 #ifdef CONFIG_GENERIC_TIME
 		/* TSC halts in C2, so notify users */
 		mark_tsc_unstable();
 #endif
+#endif
 		/* Re-enable interrupts */
 		local_irq_enable();
 		current_thread_info()->status |= TS_POLLING;
@@ -522,10 +524,12 @@ #endif
 			acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
 		}
 
+#ifndef CONFIG_IA64
 #ifdef CONFIG_GENERIC_TIME
 		/* TSC halts in C3, so notify users */
 		mark_tsc_unstable();
 #endif
+#endif
 		/* Re-enable interrupts */
 		local_irq_enable();
 		current_thread_info()->status |= TS_POLLING;
drivers/char/hpet.c +37 -31

112 lines not on this page · raw message

include/linux/clocksource.h +3 -0
index daa4940..a20b4d6 100644
@@ -61,6 +61,9 @@ struct clocksource {
 	u32 shift;
 	unsigned long flags;
 	cycle_t (*vread)(void);
+#ifdef CONFIG_IA64
+	void *fsys_mmio_ptr;	/* used by fsyscall asm code */
+#endif
 
 	/* timekeeping specific data, ignore */
 	cycle_t cycle_last, cycle_interval;
#1 lore raw

PATCH 2/3 ia64: remove interpolater code

From: Peter Keilty <[email protected]>

Remove time_interpolator code.

---

 include/linux/timex.h |   60 ---------------
 kernel/time.c         |    1 
 kernel/timer.c        |  193 --------------------------------------------------
 3 files changed, 254 deletions(-)

linux-2.6.21-rc1_timeofday-remove-interp_C7.patch
======================

include/linux/timex.h +0 -60
index da929db..37ac3ff 100644
@@ -224,66 +224,6 @@ #define shift_right(x, s) ({	\
 	__x < 0 ? -(-__x >> __s) : __x >> __s;	\
 })
 
-
-#ifdef CONFIG_TIME_INTERPOLATION
-
-#define TIME_SOURCE_CPU 0
-#define TIME_SOURCE_MMIO64 1
-#define TIME_SOURCE_MMIO32 2
-#define TIME_SOURCE_FUNCTION 3
-
-/* For proper operations time_interpolator clocks must run slightly slower
- * than the standard clock since the interpolator may only correct by having
- * time jump forward during a tick. A slower clock is usually a side effect
- * of the integer divide of the nanoseconds in a second by the frequency.
- * The accuracy of the division can be increased by specifying a shift.
- * However, this may cause the clock not to be slow enough.
- * The interpolator will self-tune the clock by slowing down if no
- * resets occur or speeding up if the time jumps per analysis cycle
- * become too high.
- *
- * Setting jitter compensates for a fluctuating timesource by comparing
- * to the last value read from the timesource to insure that an earlier value
- * is not returned by a later call. The price to pay
- * for the compensation is that the timer routines are not as scalable anymore.
- */
-
-struct time_interpolator {
-	u16 source;			/* time source flags */
-	u8 shift;			/* increases accuracy of multiply by shifting. */
-				/* Note that bits may be lost if shift is set too high */
-	u8 jitter;			/* if set compensate for fluctuations */
-	u32 nsec_per_cyc;		/* set by register_time_interpolator() */
-	void *addr;			/* address of counter or function */
-	cycles_t mask;			/* mask the valid bits of the counter */
-	unsigned long offset;		/* nsec offset at last update of interpolator */
-	u64 last_counter;		/* counter value in units of the counter at last update */
-	cycles_t last_cycle;		/* Last timer value if TIME_SOURCE_JITTER is set */
-	u64 frequency;			/* frequency in counts/second */
-	long drift;			/* drift in parts-per-million (or -1) */
-	unsigned long skips;		/* skips forward */
-	unsigned long ns_skipped;	/* nanoseconds skipped */
-	struct time_interpolator *next;
-};
-
-extern void register_time_interpolator(struct time_interpolator *);
-extern void unregister_time_interpolator(struct time_interpolator *);
-extern void time_interpolator_reset(void);
-extern unsigned long time_interpolator_get_offset(void);
-extern void time_interpolator_update(long delta_nsec);
-
-#else /* !CONFIG_TIME_INTERPOLATION */
-
-static inline void time_interpolator_reset(void)
-{
-}
-
-static inline void time_interpolator_update(long delta_nsec)
-{
-}
-
-#endif /* !CONFIG_TIME_INTERPOLATION */
-
 #define TICK_LENGTH_SHIFT	32
 
 #ifdef CONFIG_NO_HZ
kernel/time.c +0 -1
index c6c80ea..53b73fd 100644
@@ -134,7 +134,6 @@ static inline void warp_clock(void)
 	write_seqlock_irq(&xtime_lock);
 	wall_to_monotonic.tv_sec -= sys_tz.tz_minuteswest * 60;
 	xtime.tv_sec += sys_tz.tz_minuteswest * 60;
-	time_interpolator_reset();
 	write_sequnlock_irq(&xtime_lock);
 	clock_was_set();
 }
kernel/timer.c +0 -193

211 lines not on this page · raw message

#2 lore raw

Re: [PATCH 2/3] ia64: remove interpolater code

Quoted 7 lines · Peter Keilty

From: Peter Keilty <[email protected]>

Remove time_interpolator code.

Quoted 6 lines

---

 include/linux/timex.h |   60 ---------------
 kernel/time.c         |    1 
 kernel/timer.c        |  193 --------------------------------------------------
 3 files changed, 254 deletions(-)

This specific patch may need to be held off until Dave Miller pushes his SPARC64 GENERIC_TIME conversion (as SPARC64 currently uses the time_interpolator code).

I think Dave intends to push it soon, so it shouldn't be a long wait.

thanks
-john

#3 lore raw

Re: [PATCH 2/3] ia64: remove interpolater code

From: john stultz <[email protected]>
Date: Thu, 26 Apr 2007 13:52:47 -0700

Quoted 5 lines

This specific patch may need to be held off until Dave Miller pushes his SPARC64 GENERIC_TIME conversion (as SPARC64 currently uses the time_interpolator code).

I think Dave intends to push it soon, so it shouldn't be a long wait.

Feel free to break the tree meanwhile in order to delete this, I won't mind as I'll have it fixed as soon as I merge my sparc tree to Linus.

#4 lore raw

PATCH 3/3 ia64: update fsyscall for performance, enable build/run on 2.6.21-rc1

In reply to Peter Keilty

From: Peter Keilty <[email protected]>

Update ia64 conversion to the generic timekeeping/clocksource code. Modified fast syscall path for gettimeofday to get performance equal to orginal code and handle clocksource change at clock hz time.

Performance measurements for single calls (ITC cycles):

A. 32 way Intel IA64 SMP system 8640 (montecito) A.1. Current code itc cmpxchg
gettimeofday cycles: 39 37 37 37 37 37 37 37 37 37 clock_gettime(REAL) cycles: 49 35 35 35 35 35 35 35 35 35 clock_gettime(MONO) cycles: 42 36 36 36 36 36 36 36 36 36

A.2 New code itc cmpxchg
gettimeofday cycles: 39 38 37 37 38 37 38 37 37 37 clock_gettime(REAL) cycles: 53 35 35 36 35 35 35 35 35 35 clock_gettime(MONO) cycles: 44 38 36 36 36 36 36 36 36 36

A.3 New code itc cmpxchg switched off (nojitter kernel option) gettimeofday cycles: 35 35 36 35 36 35 36 35 35 35 clock_gettime(REAL) cycles: 49 33 33 34 33 33 33 33 33 33 clock_gettime(MONO) cycles: 38 33 33 33 33 33 33 33 33 33

A.4 New code with hpet as clocksource, mmio space read gettimeofday cycles: 183 183 181 180 182 185 182 183 184 182 clock_gettime(REAL) cycles: 196 180 179 179 183 181 182 183 183 181 clock_gettime(MONO) cycles: 185 180 182 180 182 182 179 179 179 181

---

 arch/ia64/kernel/asm-offsets.c        |   15 ++++---
 arch/ia64/kernel/cyclone.c            |    2 -
 arch/ia64/kernel/fsys.S               |   64 ++++++++++++++++++----------------
 arch/ia64/kernel/fsyscall_gtod_data.h |   18 +++++++++
 arch/ia64/kernel/time.c               |   37 +++++++++++++------
 arch/ia64/sn/kernel/sn2/timer.c       |    2 -
 drivers/char/hpet.c                   |    2 -
 kernel/time/ntp.c                     |   10 -----
 8 files changed, 90 insertions(+), 60 deletions(-)

Index: Linux/arch/ia64/kernel/asm-offsets.c
=================================--- Linux.orig/arch/ia64/kernel/asm-offsets.c 2007-04-24 11:40:44.000000000 -0400
+++ Linux/arch/ia64/kernel/asm-offsets.c 2007-04-24 12:58:49.000000000 -0400
@@ -16,6 +16,7 @@
#include <asm-ia64/mca.h>

#include "../kernel/sigframe.h"
+#include "../kernel/fsyscall_gtod_data.h"

 #define DEFINE(sym, val) \
         asm volatile("\n->" #sym " %0 " #val : : "i" (val))

@@ -256,10 +257,12 @@ void foo(void)
BLANK();

/* used by fsys_gettimeofday in arch/ia64/kernel/fsys.S */
- DEFINE(IA64_TIMESPEC_TV_NSEC_OFFSET, offsetof (struct timespec, tv_nsec));
- DEFINE(IA64_CLOCKSOURCE_MASK_OFFSET, offsetof (struct clocksource, mask));
- DEFINE(IA64_CLOCKSOURCE_MULT_OFFSET, offsetof (struct clocksource, mult));
- DEFINE(IA64_CLOCKSOURCE_SHIFT_OFFSET, offsetof (struct clocksource, shift));
- DEFINE(IA64_CLOCKSOURCE_MMIO_PTR_OFFSET, offsetof (struct clocksource, fsys_mmio_ptr));
- DEFINE(IA64_CLOCKSOURCE_CYCLE_LAST_OFFSET, offsetof (struct clocksource, cycle_last));
+ DEFINE(IA64_GTOD_LOCK_OFFSET, offsetof (struct fsyscall_gtod_data_t, lock));
+ DEFINE(IA64_CLKSRC_MASK_OFFSET, offsetof (struct fsyscall_gtod_data_t, clk_mask));
+ DEFINE(IA64_CLKSRC_MULT_OFFSET, offsetof (struct fsyscall_gtod_data_t, clk_mult));
+ DEFINE(IA64_CLKSRC_SHIFT_OFFSET, offsetof (struct fsyscall_gtod_data_t, clk_shift));
+ DEFINE(IA64_CLKSRC_MMIO_PTR_OFFSET, offsetof (struct fsyscall_gtod_data_t, clk_fsys_mmio_ptr));
+ DEFINE(IA64_CLKSRC_CYCLE_LAST_OFFSET, offsetof (struct fsyscall_gtod_data_t, clk_cycle_last));
+ DEFINE(IA64_ITC_LASTCYCLE_OFFSET, offsetof (struct fsyscall_gtod_data_t, itc_lastcycle));
+ DEFINE(IA64_ITC_JITTER_OFFSET, offsetof (struct fsyscall_gtod_data_t, itc_jitter));
}
Index: Linux/arch/ia64/kernel/cyclone.c
=================================--- Linux.orig/arch/ia64/kernel/cyclone.c 2007-04-24 11:40:44.000000000 -0400
+++ Linux/arch/ia64/kernel/cyclone.c 2007-04-24 12:31:20.000000000 -0400
@@ -33,7 +33,7 @@ static struct clocksource clocksource_cy

         .mask           = (1LL << 40) - 1,
         .mult           = 0, /*to be caluclated*/
         .shift          = 16,
-        .is_continuous  = 1,
+        .flags          = CLOCK_SOURCE_IS_CONTINUOUS,

};

int __init init_cyclone_clock(void)
Index: Linux/arch/ia64/kernel/fsys.S
=================================--- Linux.orig/arch/ia64/kernel/fsys.S 2007-04-24 11:40:44.000000000 -0400
+++ Linux/arch/ia64/kernel/fsys.S 2007-04-25 16:39:25.000000000 -0400
@@ -145,6 +145,9 @@ ENTRY(fsys_set_tid_address)
FSYS_RETURN
END(fsys_set_tid_address)

+#if IA64_GTOD_LOCK_OFFSET !=0
+#error fsys_gettimeofday incompatible with changes to struct fsyscall_gtod_data_t +#endif
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 1
#define CLOCK_DIVIDE_BY_1000 0x4000
@@ -175,10 +178,10 @@ ENTRY(fsys_gettimeofday)
// r16 = preserved: current task pointer
// r17 = wall to monotonic use
// r19 = address of itc_lastcycle
- // r20 = struct clocksource / address of first element
- // r21 = shift value
- // r22 = address of itc_jitter/ wall_to_monotonic
- // r23 = address of shift
+ // r20 = struct fsyscall_gtod_data / address of first element
+ // r21 = address of mmio_ptr
+ // r22 = address of wall_to_monotonic
+ // r23 = address of shift/ value
// r24 = address mult factor / cycle_last value
// r25 = itc_lastcycle value
// r26 = address clocksource cycle_last
@@ -204,46 +207,47 @@ ENTRY(fsys_gettimeofday)
tnat.nz p6,p0 = r31 // branch deferred since it does not fit into bundle structure
mov pr = r30,0xc000 // Set predicates according to function
add r2 = TI_FLAGS+IA64_TASK_SIZE,r16
- movl r20 = fsyscall_clock // load fsyscall clocksource address
+ movl r20 = fsyscall_gtod_data // load fsyscall gettimeofday data address
;;
- add r10 = IA64_CLOCKSOURCE_MMIO_PTR_OFFSET,r20
- movl r29 = xtime_lock
- ld4 r2 = [r2] // process work pending flags
+ add r29 = IA64_ITC_JITTER_OFFSET,r20
movl r27 = xtime
- ;; // only one bundle here
- add r14 = IA64_CLOCKSOURCE_MASK_OFFSET,r20
- movl r22 = itc_jitter
- add r24 = IA64_CLOCKSOURCE_MULT_OFFSET,r20
+ ld4 r2 = [r2] // process work pending flags
+(p15) movl r22 = wall_to_monotonic
+ ;;
+ add r21 = IA64_CLKSRC_MMIO_PTR_OFFSET,r20
+ add r19 = IA64_ITC_LASTCYCLE_OFFSET,r20
and r2 = TIF_ALLWORK_MASK,r2
(p6) br.cond.spnt.few .fail_einval // deferred branch
;;
- ld8 r30 = [r10] // clocksource->mmio_ptr
- movl r19 = itc_lastcycle
- add r23 = IA64_CLOCKSOURCE_SHIFT_OFFSET,r20
+ add r26 = IA64_CLKSRC_CYCLE_LAST_OFFSET,r20 // clksrc_cycle_last
cmp.ne p6, p0 = 0, r2 // Fallback if work is scheduled
(p6) br.cond.spnt.many fsys_fallback_syscall
+ ;; // get lock.seq here new code, outer loop2!
+.time_redo:
+ ld4.acq r28 = [r20] // gtod_lock.sequence, Must be first in struct
+ ld8 r30 = [r21] // clocksource->mmio_ptr
+ add r24 = IA64_CLKSRC_MULT_OFFSET,r20
+ ld4 r2 = [r29] // itc_jitter value
+ add r23 = IA64_CLKSRC_SHIFT_OFFSET,r20
+ add r14 = IA64_CLKSRC_MASK_OFFSET,r20
;;
+ ld4 r3 = [r24] // clocksource mult value
ld8 r14 = [r14] // clocksource mask value
- ld4 r2 = [r22] // itc_jitter value
- add r26 = IA64_CLOCKSOURCE_CYCLE_LAST_OFFSET,r20 // clock fsyscall_cycle_last
- ld4 r3 = [r24] // clocksource->mult value
cmp.eq p8,p9 = 0,r30 // Check for cpu timer, no mmio_ptr, set p8, clear p9
;;
setf.sig f7 = r3 // Setup for mult scaling of counter
-(p15) movl r22 = wall_to_monotonic
- ld4 r21 = [r23] // shift value
-(p8) cmp.ne p13,p0 = r2,r0 // need jitter compensation, set p13
+(p8) cmp.ne p13,p0 = r2,r0 // need itc_jitter compensation, set p13
+ ld4 r23 = [r23] // clocksource shift value
+ ld8 r24 = [r26] // get clksrc_cycle_last value
(p9) cmp.eq p13,p0 = 0,r30 // if mmio_ptr, clear p13 jitter control
- ;;
-.time_redo:
- .pred.rel.mutex p8,p9,p10
- ld4.acq r28 = [r29] // xtime_lock.sequence. Must come first for locking purposes
+ ;; // old position for lock seq, new inner loop1!
+.cmpxchg_redo:
+ .pred.rel.mutex p8,p9
(p8) mov r2 = ar.itc // CPU_TIMER. 36 clocks latency!!!
(p9) ld8 r2 = [r30] // readq(ti->address). Could also have latency issues..
(p13) ld8 r25 = [r19] // get itc_lastcycle value
;; // could be removed by moving the last add upward
ld8 r9 = [r27],IA64_TIMESPEC_TV_NSEC_OFFSET
- ld8 r24 = [r26] // get fsyscall_cycle_last value
(p15) ld8 r17 = [r22],IA64_TIMESPEC_TV_NSEC_OFFSET
;;
ld8 r8 = [r27],-IA64_TIMESPEC_TV_NSEC_OFFSET // xtime.tv_nsec
@@ -265,21 +269,23 @@ EX(.fail_efault, probe.w.fault r31, 3) /
xmpy.l f8 = f8,f7 // nsec_per_cyc*(counter-last_counter)
(p15) add r9 = r9,r17 // Add wall to monotonic.secs to result secs
;;
+ // End cmpxchg critical section loop1
(p15) ld8 r17 = [r22],-IA64_TIMESPEC_TV_NSEC_OFFSET
(p7) cmp.ne p7,p0 = r25,r3 // if cmpxchg not successful redo
+(p7) br.cond.dpnt.few .cmpxchg_redo // inner loop1
// simulate tbit.nz.or p7,p0 = r28,0
and r28 = ~1,r28 // Make sequence even to force retry if odd
getf.sig r2 = f8
mf
;;
- ld4 r10 = [r29] // xtime_lock.sequence
+ ld4 r10 = [r20] // gtod_lock.sequence, old xtime_lock.sequence
(p15) add r8 = r8, r17 // Add monotonic.nsecs to nsecs
- shr.u r2 = r2,r21 // shift by factor
+ shr.u r2 = r2,r23 // shift by factor
;; // overloaded 3 bundles!
// End critical section.
add r8 = r8,r2 // Add xtime.nsecs
cmp4.ne.or p7,p0 = r28,r10
-(p7) br.cond.dpnt.few .time_redo // sequence number changed ?
+(p7) br.cond.dpnt.few .time_redo // sequence number changed, outer loop2
// Now r8=tv->tv_nsec and r9=tv->tv_sec
mov r10 = r0
movl r2 = 1000000000
Index: Linux/arch/ia64/kernel/fsyscall_gtod_data.h
=================================--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ Linux/arch/ia64/kernel/fsyscall_gtod_data.h 2007-04-24 12:54:52.000000000 -0400
@@ -0,0 +1,18 @@
+/*
+ * (c) Copyright 2007 Hewlett-Packard Development Company, L.P.
+ * Contributed by Peter Keilty <[email protected]>
+ *
+ * fsyscall gettimeofday data
+ */
+
+struct fsyscall_gtod_data_t {

+        seqlock_t lock;
+        cycle_t   clk_mask;
+        u32       clk_mult;
+        u32       clk_shift;
+        void     *clk_fsys_mmio_ptr;
+        cycle_t   clk_cycle_last;
+        cycle_t   itc_lastcycle;
+        int       itc_jitter;

+} __attribute__ ((aligned (L1_CACHE_BYTES)));
+
Index: Linux/arch/ia64/kernel/time.c
=================================--- Linux.orig/arch/ia64/kernel/time.c 2007-04-24 11:40:44.000000000 -0400
+++ Linux/arch/ia64/kernel/time.c 2007-04-24 12:41:28.000000000 -0400
@@ -30,9 +30,13 @@
#include <asm/sections.h>
#include <asm/system.h>

+#include "fsyscall_gtod_data.h"
+
static cycle_t itc_get_cycles(void);
-cycle_t itc_lastcycle __attribute__((aligned(L1_CACHE_BYTES)));
-int itc_jitter __attribute__((aligned(L1_CACHE_BYTES)));
+
+struct fsyscall_gtod_data_t fsyscall_gtod_data = {
+ .lock = SEQLOCK_UNLOCKED,
+};

volatile int time_keeper_id = 0; /* smp_processor_id() of time-keeper */

@@ -50,7 +54,7 @@ static struct clocksource clocksource_it

         .mask           = 0xffffffffffffffffLL,
         .mult           = 0, /*to be caluclated*/
         .shift          = 16,
-        .is_continuous  = 1,
+        .flags          = CLOCK_SOURCE_IS_CONTINUOUS,

};
static struct clocksource *clocksource_itc_p;

@@ -232,7 +236,7 @@ ia64_init_itm (void)
* even going backward) if the ITC offsets between the individual CPUs
* are too large.
*/
- if (!nojitter) itc_jitter = 1;
+ if (!nojitter) fsyscall_gtod_data.itc_jitter = 1;
#endif
}

@@ -248,15 +252,14 @@ ia64_init_itm (void)
}
}

-
static cycle_t itc_get_cycles()
{
- if (itc_jitter) {
+ if (fsyscall_gtod_data.itc_jitter) {
u64 lcycle;
u64 now;

do {
- lcycle = itc_lastcycle;
+ lcycle = fsyscall_gtod_data.itc_lastcycle;
now = get_cycles();
if (lcycle && time_after(lcycle, now))
return lcycle;
@@ -266,14 +269,14 @@ static cycle_t itc_get_cycles()
* force to retry until the write lock is released. */
if (spin_is_locked(&xtime_lock.lock)) {
- itc_lastcycle = now;
+ fsyscall_gtod_data.itc_lastcycle = now;
return now;
}
/* Keep track of the last timer value returned.
* The use of cmpxchg here will cause contention in
* an SMP environment.
*/
- } while (unlikely(cmpxchg(&itc_lastcycle, lcycle, now) != lcycle));
+ } while (likely(cmpxchg(&fsyscall_gtod_data.itc_lastcycle, lcycle, now) != lcycle));
return now;
} else
return get_cycles();
@@ -356,9 +359,19 @@ ia64_setup_printk_clock(void)
ia64_printk_clock = ia64_itc_printk_clock;
}

-struct clocksource fsyscall_clock __attribute__((aligned(L1_CACHE_BYTES))); -
void update_vsyscall(struct timespec *wall, struct clocksource *c) {
- fsyscall_clock = *c;
+ unsigned long flags;
+
+ write_seqlock_irqsave(&fsyscall_gtod_data.lock, flags);
+

+        /* copy fsyscall clock data */
+        fsyscall_gtod_data.clk_mask = c->mask;
+        fsyscall_gtod_data.clk_mult = c->mult;
+        fsyscall_gtod_data.clk_shift = c->shift;
+        fsyscall_gtod_data.clk_fsys_mmio_ptr = c->fsys_mmio_ptr;
+        fsyscall_gtod_data.clk_cycle_last = c->cycle_last;

+
+ write_sequnlock_irqrestore(&fsyscall_gtod_data.lock, flags);
}
+
Index: Linux/arch/ia64/sn/kernel/sn2/timer.c
=================================--- Linux.orig/arch/ia64/sn/kernel/sn2/timer.c 2007-04-24 11:40:44.000000000 -0400
+++ Linux/arch/ia64/sn/kernel/sn2/timer.c 2007-04-24 12:32:33.000000000 -0400
@@ -37,7 +37,7 @@ static struct clocksource clocksource_sn

         .mask           = (1LL << 55) - 1,
         .mult           = 0,
         .shift          = 10,
-        .is_continuous  = 1,
+        .flags          = CLOCK_SOURCE_IS_CONTINUOUS,

};

/*
Index: Linux/drivers/char/hpet.c
=================================--- Linux.orig/drivers/char/hpet.c 2007-04-24 11:40:44.000000000 -0400
+++ Linux/drivers/char/hpet.c 2007-04-26 09:36:31.000000000 -0400
@@ -76,7 +76,7 @@ static struct clocksource clocksource_hp

         .mask           = 0xffffffffffffffffLL,
         .mult           = 0, /*to be caluclated*/
         .shift          = 10,
-        .is_continuous  = 1,
+        .flags          = CLOCK_SOURCE_IS_CONTINUOUS,

};
static struct clocksource *hpet_clocksource_p;

Index: Linux/kernel/time/ntp.c
=================================--- Linux.orig/kernel/time/ntp.c 2007-04-24 11:40:44.000000000 -0400
+++ Linux/kernel/time/ntp.c 2007-04-24 12:33:24.000000000 -0400
@@ -114,11 +114,6 @@ void second_overflow(void)
if (xtime.tv_sec % 86400 = 0) {
xtime.tv_sec--; wall_to_monotonic.tv_sec++;
- /*
- * The timer interpolator will make time change
- * gradually instead of an immediate jump by one second
- */
- time_interpolator_update(-NSEC_PER_SEC);
time_state = TIME_OOP; clock_was_set();
printk(KERN_NOTICE "Clock: inserting leap second "
@@ -129,11 +124,6 @@ void second_overflow(void)
if ((xtime.tv_sec + 1) % 86400 = 0) {
xtime.tv_sec++; wall_to_monotonic.tv_sec--;
- /*
- * Use of time interpolator for a gradual change of
- * time
- */
- time_interpolator_update(NSEC_PER_SEC);
time_state = TIME_WAIT; clock_was_set();
printk(KERN_NOTICE "Clock: deleting leap second "

#5 lore raw
In reply to Peter Keilty
Quoted 6 lines · Peter Keilty

From: Peter Keilty <[email protected]>

Initial ia64 conversion to the generic timekeeping/clocksource code.

The "Signed-off-by:" should reflect the order in which a path is processed with the last submitter at the bottom of the list.
So if this patch came from John then he should be first in the list and since the patch passes you and you submit it you should be in the bottom of the list.

And "Signed-off-by:" tell the path that the patch takes. It is not to be used to let others say "I have seen it and I think the patch is ok". For the latter we have "Acked-by:".

I did not look at the code so ne feedback there.

Sam

#6 lore raw
Quoted 14 lines · Sam Ravnborg
Quoted 6 lines · Peter Keilty

From: Peter Keilty <[email protected]>

Initial ia64 conversion to the generic timekeeping/clocksource code.

The "Signed-off-by:" should reflect the order in which a path is processed with the last submitter at the bottom of the list.
So if this patch came from John then he should be first in the list and since the patch passes you and you submit it you should be in the bottom of the list.

Quoted 3 lines

And "Signed-off-by:" tell the path that the patch takes. It is not to be used to let others say "I have seen it and I think the patch is ok". For the latter we have "Acked-by:".

Yea. Its a little odd in this case, because Peter sent me the signed off code, then I've made tweaks to it and signed it off, then peter picked that up and has made further improvements.

So I don't think it is inaccurate, but I see how it could be confusing. Maybe Peter should add an extra signed-off so its more clear?

thanks
-john

#7 lore raw
In reply to Peter Keilty

arch/ia64/kernel/cyclone.c void __init cyclone_setup(void) · line 37

Quoted 5 lines · Peter Keilty
arch/ia64/kernel/cyclone.c +4 -0
+        .mask           = (1LL << 40) - 1,
+        .mult           = 0, /*to be caluclated*/
+        .shift          = 16,
+        .is_continuous  = 1,
 };

You should use CLOCKSOURCE_MASK() here ..

include/linux/clocksource.h struct clocksource { · line 66

Quoted 12 lines
include/linux/clocksource.h +3 -0
index daa4940..a20b4d6 100644
@@ -61,6 +61,9 @@ struct clocksource {
 	u32 shift;
 	unsigned long flags;
 	cycle_t (*vread)(void);
+#ifdef CONFIG_IA64
+	void *fsys_mmio_ptr;	/* used by fsyscall asm code */
+#endif

Could you explain in detail why this is needed?

Daniel

#8 lore raw
Quoted 12 lines · Daniel Walker
Quoted 7 lines · Peter Keilty
arch/ia64/kernel/cyclone.c +4 -0
+        .mask           = (1LL << 40) - 1,
+        .mult           = 0, /*to be caluclated*/
+        .shift          = 16,
+        .is_continuous  = 1,

};

Quoted 4 lines

You should use CLOCKSOURCE_MASK() here ..

It is correct in patch 3, I believe.

Quoted 20 lines
Quoted 8 lines
include/linux/clocksource.h +0 -0
index daa4940..a20b4d6 100644

include/linux/clocksource.h struct clocksource { · line 68

Quoted 8 lines
include/linux/clocksource.h +3 -0
@@ -61,6 +61,9 @@ struct clocksource {
 	u32 shift;
 	unsigned long flags;
 	cycle_t (*vread)(void);
+#ifdef CONFIG_IA64
+	void *fsys_mmio_ptr;	/* used by fsyscall asm code */
+#endif
 
 

Could you explain in detail why this is needed?

This ptr is needed to hold the mmio address to read the cycle value. The fast ia64 path utilizies a special gate page which can allow user code to execute small amount of kernel code, normal calling a function not done and so the address is need. The fast syscall path executes on user stack, between user/kernel state. And if the the fast path has to fallback
to the slow syscall code the vread will be needed and used. Hope this helps.

Quoted 4 lines

Daniel

#9 lore raw
Quoted 14 lines · Peter Keilty
Quoted 12 lines · Daniel Walker
Quoted 7 lines · Peter Keilty
arch/ia64/kernel/cyclone.c +4 -0
+        .mask           = (1LL << 40) - 1,
+        .mult           = 0, /*to be caluclated*/
+        .shift          = 16,
+        .is_continuous  = 1,

};

Quoted 5 lines
Quoted 4 lines

You should use CLOCKSOURCE_MASK() here ..

It is correct in patch 3, I believe.

There's another spot that should use CLOCKSOURE_MASK() in the hpet I think .

Quoted 20 lines
Quoted 20 lines
Quoted 8 lines
include/linux/clocksource.h +0 -0
index daa4940..a20b4d6 100644

include/linux/clocksource.h struct clocksource { · line 68

Quoted 8 lines
include/linux/clocksource.h +3 -0
@@ -61,6 +61,9 @@ struct clocksource {
 	u32 shift;
 	unsigned long flags;
 	cycle_t (*vread)(void);
+#ifdef CONFIG_IA64
+	void *fsys_mmio_ptr;	/* used by fsyscall asm code */
+#endif
 
 

Could you explain in detail why this is needed?

Quoted 7 lines

This ptr is needed to hold the mmio address to read the cycle value. The fast ia64 path utilizies a special gate page which can allow user code to execute small amount of kernel code, normal calling a function not done and so the address is need. The fast syscall path executes on user stack, between user/kernel state. And if the the fast path has to fallback
to the slow syscall code the vread will be needed and used.

There is a read(), and a vread() did you modify the slow syscall path to use the vread()?

Daniel

#10 lore raw
Quoted 28 lines · Daniel Walker
Quoted 25 lines · Peter Keilty
Quoted 21 lines · Daniel Walker
Quoted 9 lines · Peter Keilty
arch/ia64/kernel/cyclone.c +4 -0
+        .mask           = (1LL << 40) - 1,
+        .mult           = 0, /*to be caluclated*/
+        .shift          = 16,
+        .is_continuous  = 1,

};

You should use CLOCKSOURCE_MASK() here ..

Quoted 8 lines
Quoted 3 lines

It is correct in patch 3, I believe.

There's another spot that should use CLOCKSOURE_MASK() in the hpet I think .

Correct that was change in patch 3 also.

Quoted 36 lines
Quoted 26 lines
Quoted 6 lines
Quoted 20 lines
Quoted 6 lines
include/linux/clocksource.h +0 -0
index daa4940..a20b4d6 100644

include/linux/clocksource.h struct clocksource { · line 69

Quoted 9 lines
include/linux/clocksource.h +3 -0
@@ -61,6 +61,9 @@ struct clocksource {
 	u32 shift;
 	unsigned long flags;
 	cycle_t (*vread)(void);
+#ifdef CONFIG_IA64
+	void *fsys_mmio_ptr;	/* used by fsyscall asm code */
+#endif
 
 
 

Could you explain in detail why this is needed?

Quoted 9 lines

This ptr is needed to hold the mmio address to read the cycle value. The fast ia64 path utilizies a special gate page which can allow user code to execute small amount of kernel code, normal calling a function not done and so the address is need. The fast syscall path executes on user stack, between user/kernel state. And if the the fast path has to fallback
to the slow syscall code the vread will be needed and used.

Quoted 4 lines

There is a read(), and a vread() did you modify the slow syscall path to use the vread()?

I miss type, read().

Quoted 4 lines

Daniel

#11 lore raw
Quoted 6 lines · Peter Keilty
Quoted 5 lines

There is a read(), and a vread() did you modify the slow syscall path to use the vread()?

I miss type, read().

John mentioned that he thought fsys_mmio_ptr could be held in the vread pointer. vread() is used in x86 for vsyscalls. It looks like you've used the update_vsyscall() which is also used for vsyscalls. So vread could also be used .. Have you considered that at all?

Daniel

#12 lore raw
Quoted 10 lines · Daniel Walker
Quoted 6 lines · Peter Keilty
Quoted 6 lines

There is a read(), and a vread() did you modify the slow syscall path to use the vread()?

Quoted 10 lines
Quoted 3 lines

I miss type, read().

John mentioned that he thought fsys_mmio_ptr could be held in the vread pointer. vread() is used in x86 for vsyscalls. It looks like you've used the update_vsyscall() which is also used for vsyscalls. So vread could also be used .. Have you considered that at all?

No, but yes it can be done, overloading the meaning.
It would need to change in the future if vread was needed.
I have no strong argument against using it.
Although we may still need the IA64 define, I removed 32bit read mmio and if that is brought back the fast syscall patch call will need to have a field in the
clocksource struct that would indicated that. Waiting on comments about that...
John and discuss this awhile back felt it was not needed, may prove wrong.

Quoted 4 lines

Daniel

#13 lore raw
Quoted 10 lines · Peter Keilty
Quoted 1 line

No, but yes it can be done, overloading the meaning.
It would need to change in the future if vread was needed.
I have no strong argument against using it.
Although we may still need the IA64 define, I removed 32bit read mmio and if that is brought back the fast syscall patch call will need to have a field in the
clocksource struct that would indicated that. Waiting on comments about that...
John and discuss this awhile back felt it was not needed, may prove wrong.

The vread field is just a pointer, which should be 64bits on ia64. Why do you mention 32bits above? The two variables similar enough ..

Daniel

#14 lore raw
In reply to Peter Keilty
Quoted 5 lines · Peter Keilty
Quoted 4 lines · Daniel Walker
Quoted 3 lines · Peter Keilty
Quoted 3 lines

There is a read(), and a vread() did you modify the slow syscall path to use the vread()?

Quoted 7 lines
Quoted 6 lines

John mentioned that he thought fsys_mmio_ptr could be held in the vread pointer. vread() is used in x86 for vsyscalls. It looks like you've used the update_vsyscall() which is also used for vsyscalls. So vread could also be used .. Have you considered that at all?

No, but yes it can be done, overloading the meaning.

Yea. I'm not really psyched about overloading the vread pointer's use. I mentioned it could be done if the #ifdef was objected to, but it seems a bit abusive. The #ifdef isn't great, but I think its something I can live with for now. At least its explicit.

Quoted 2 lines

It would need to change in the future if vread was needed. I have no strong argument against using it.

Yea. I'd hold off on that for now.

thanks
-john

#15 lore raw
Quoted 12 lines · john stultz
Quoted 11 lines · Peter Keilty
Quoted 10 lines · Daniel Walker
Quoted 3 lines · Peter Keilty
Quoted 3 lines

There is a read(), and a vread() did you modify the slow syscall path to use the vread()?

John mentioned that he thought fsys_mmio_ptr could be held in the vread pointer. vread() is used in x86 for vsyscalls. It looks like you've used the update_vsyscall() which is also used for vsyscalls. So vread could also be used .. Have you considered that at all?

Quoted 6 lines
Quoted 1 line

No, but yes it can be done, overloading the meaning.

Yea. I'm not really psyched about overloading the vread pointer's use. I mentioned it could be done if the #ifdef was objected to, but it seems a bit abusive. The #ifdef isn't great, but I think its something I can live with for now. At least its explicit.

Use of config options like that is a bad precedence I think, which is why I commented on it .. Since we have a vread pointer that exists already, and it's used a very similar purpose it seems like bloat to just add another pointer..

We could change the vread to be a plain void pointer, then let each architecture use it however they want.

Daniel

#16 lore raw
In reply to Peter Keilty
Quoted 6 lines · Peter Keilty

From: Peter Keilty <[email protected]>

Initial ia64 conversion to the generic timekeeping/clocksource code.

Peter,
Thanks so much for pushing this on! I suspect this patch needs to be
updated a touch, as I'm not sure if it still compiles in light of recent changes...

Quoted 24 lines
arch/ia64/kernel/cyclone.c +2 -6
index e00b215..280383b 100644
@@ -3,6 +3,7 @@ #include <linux/smp.h>
 #include <linux/time.h>
 #include <linux/errno.h>
 #include <linux/timex.h>
+#include <linux/clocksource.h>
 #include <asm/io.h>
 
 /* IBM Summit (EXA) Cyclone counter code*/
@@ -18,13 +19,21 @@ void __init cyclone_setup(void)
 	use_cyclone = 1;
 }
 
+static void __iomem *cyclone_mc_ptr;
 
-struct time_interpolator cyclone_interpolator = {
-	.source =	TIME_SOURCE_MMIO64,
-	.shift =	16,
-	.frequency =	CYCLONE_TIMER_FREQ,
-	.drift =	-100,
-	.mask =		(1LL << 40) - 1

arch/ia64/kernel/cyclone.c void __init cyclone_setup(void) · line 33

Quoted 10 lines
arch/ia64/kernel/cyclone.c +10 -0
+static cycle_t read_cyclone(void)
+{
+	return (cycle_t)readq((void __iomem *)cyclone_mc_ptr);
+}
+
+static struct clocksource clocksource_cyclone = {
+        .name           = "cyclone",
+        .rating         = 300,
+        .read           = read_cyclone,
+        .mask           = (1LL << 40) - 1,

Daniel Walker pointed out to me on IRC that CLOCKSOURCE_MASK() should probably be used here.

arch/ia64/kernel/cyclone.c void __init cyclone_setup(void) · line 36

Quoted 3 lines
arch/ia64/kernel/cyclone.c +3 -0
+        .mult           = 0, /*to be caluclated*/
+        .shift          = 16,
+        .is_continuous  = 1,

.is_continuous no longer exists.

You want to use:
.flags = CLOCK_SOURCE_IS_CONTINUOUS

This holds for all the clocksources introduced.

thanks
-john

#17 lore raw
Quoted 12 lines · john stultz
Quoted 8 lines · Peter Keilty

From: Peter Keilty <[email protected]>

Initial ia64 conversion to the generic timekeeping/clocksource code.

Quoted 7 lines

Peter,
Thanks so much for pushing this on! I suspect this patch needs to be
updated a touch, as I'm not sure if it still compiles in light of recent changes...

John,

You are correct, you need patch 3/3 for it to compile and run. I did a patch to the orginal patch, thought that was correct thing to do. But I can make a new patch 1 from the orginal of ours and my #3. I would also make an update to the #2 patch from #3 for ntp correct change. That would be just 2 patches then, the enable_ia64 and remove_interpolater. What do you think?

Quoted 64 lines
Quoted 28 lines
arch/ia64/kernel/cyclone.c +4 -6
index e00b215..280383b 100644
@@ -3,6 +3,7 @@ #include <linux/smp.h>
 #include <linux/time.h>
 #include <linux/errno.h>
 #include <linux/timex.h>
+#include <linux/clocksource.h>
 #include <asm/io.h>
 
 /* IBM Summit (EXA) Cyclone counter code*/
@@ -18,13 +19,21 @@ void __init cyclone_setup(void)
 	use_cyclone = 1;
 }
 
+static void __iomem *cyclone_mc_ptr;
 
-struct time_interpolator cyclone_interpolator = {
-	.source =	TIME_SOURCE_MMIO64,
-	.shift =	16,
-	.frequency =	CYCLONE_TIMER_FREQ,
-	.drift =	-100,
-	.mask =		(1LL << 40) - 1
+static cycle_t read_cyclone(void)
+{

arch/ia64/kernel/cyclone.c void __init cyclone_setup(void) · line 35

Quoted 10 lines
arch/ia64/kernel/cyclone.c +8 -0
+	return (cycle_t)readq((void __iomem *)cyclone_mc_ptr);
+}
+
+static struct clocksource clocksource_cyclone = {
+        .name           = "cyclone",
+        .rating         = 300,
+        .read           = read_cyclone,
+        .mask           = (1LL << 40) - 1,
 
 

Daniel Walker pointed out to me on IRC that CLOCKSOURCE_MASK() should probably be used here.

arch/ia64/kernel/cyclone.c void __init cyclone_setup(void) · line 38

Quoted 5 lines
arch/ia64/kernel/cyclone.c +3 -0
+        .mult           = 0, /*to be caluclated*/
+        .shift          = 16,
+        .is_continuous  = 1,
 

.is_continuous no longer exists.

You want to use:
.flags = CLOCK_SOURCE_IS_CONTINUOUS

This holds for all the clocksources introduced.

thanks
-john

#18 lore raw
Quoted 13 lines · Peter Keilty
Quoted 12 lines · john stultz
Quoted 7 lines · Peter Keilty

From: Peter Keilty <[email protected]>

Initial ia64 conversion to the generic timekeeping/clocksource code.

Thanks so much for pushing this on! I suspect this patch needs to be
updated a touch, as I'm not sure if it still compiles in light of recent changes...

Quoted 6 lines

You are correct, you need patch 3/3 for it to compile and run. I did a patch to the orginal patch, thought that was correct thing to do. But I can make a new patch 1 from the orginal of ours and my #3. I would also make an update to the #2 patch from #3 for ntp correct change. That would be just 2 patches then, the enable_ia64 and remove_interpolater. What do you think?

Yep. That sounds like the right path to me. Its a good idea to make sure your patch set compiles each step of the way, so later folks can properly bisect through it looking for other issues.

thanks
-john

#19 lore raw
In reply to Peter Keilty
Quoted 5 lines · * Peter Keilty ([email protected]) wrote:
drivers/acpi/processor_idle.c +0 -0
index 6077300..35ad71f 100644

drivers/acpi/processor_idle.c #endif · line 488

Quoted 9 lines
drivers/acpi/processor_idle.c +2 -0
@@ -480,10 +480,12 @@ #endif
 		/* Get end time (ticks) */
 		t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
 
+#ifndef CONFIG_IA64
 #ifdef CONFIG_GENERIC_TIME
 		/* TSC halts in C2, so notify users */
 		mark_tsc_unstable();
 #endif
+#endif

Is this a better description of the dependency?

  #if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86_TSC)

drivers/acpi/processor_idle.c #endif · line 532

Quoted 13 lines
drivers/acpi/processor_idle.c +2 -0
 		/* Re-enable interrupts */
 		local_irq_enable();
 		current_thread_info()->status |= TS_POLLING;
@@ -522,10 +524,12 @@ #endif
 			acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
 		}
 
+#ifndef CONFIG_IA64
 #ifdef CONFIG_GENERIC_TIME
 		/* TSC halts in C3, so notify users */
 		mark_tsc_unstable();
 #endif
+#endif

ditto

Quoted 20 lines
drivers/acpi/processor_idle.c +0 -0
 		/* Re-enable interrupts */
 		local_irq_enable();
 		current_thread_info()->status |= TS_POLLING;
drivers/char/hpet.c +2 -0
index 0be700f..5ea7d3e 100644
@@ -29,6 +29,7 @@ #include <linux/wait.h>
 #include <linux/bcd.h>
 #include <linux/seq_file.h>
 #include <linux/bitops.h>
+#include <linux/clocksource.h>
 
 #include <asm/current.h>
 #include <asm/uaccess.h>
@@ -51,8 +52,34 @@ #define	HPET_DRIFT	(500)
 
 #define HPET_RANGE_SIZE		1024	/* from HPET spec */
 
+#if BITS_PER_LONG = 64

drivers/char/hpet.c #define HPET_DRIFT (500) · line 65

Quoted 10 lines
drivers/char/hpet.c +8 -0
+#define	write_counter(V, MC)	writeq(V, MC)
+#define	read_counter(MC)	readq(MC)
+#else
+#define	write_counter(V, MC) 	writel(V, MC)
+#define	read_counter(MC)	readl(MC)
+#endif
+
 static u32 hpet_nhpet, hpet_max_freq = HPET_USER_FREQ;
 
+static void __iomem *hpet_mc_ptr;

CodingStyle nit: we don't need all this _ptr...

Quoted 5 lines
drivers/char/hpet.c +5 -0
+static cycle_t read_hpet(void)
+{
+	return (cycle_t)read_counter((void __iomem *)hpet_mc_ptr);
+}
+

drivers/char/hpet.c #define HPET_DRIFT (500) · line 81

Quoted 10 lines
drivers/char/hpet.c +10 -0
+static struct clocksource clocksource_hpet = {
+        .name           = "hpet",
+        .rating         = 300,
+        .read           = read_hpet,
+        .mask           = 0xffffffffffffffffLL,
+        .mult           = 0, /*to be caluclated*/
+        .shift          = 10,
+        .is_continuous  = 1,
+};
+static struct clocksource *hpet_clocksource_p;

and _p naming.

Quoted 58 lines
drivers/char/hpet.c +2 -29
+
 /* A lock for concurrent access by app and isr hpet activity. */
 static DEFINE_SPINLOCK(hpet_lock);
 /* A lock for concurrent intermodule access to hpet and isr hpet activity. */
@@ -79,7 +106,7 @@ struct hpets {
 	struct hpets *hp_next;
 	struct hpet __iomem *hp_hpet;
 	unsigned long hp_hpet_phys;
-	struct time_interpolator *hp_interpolator;
+	struct clocksource *hp_clocksource;
 	unsigned long long hp_tick_freq;
 	unsigned long hp_delta;
 	unsigned int hp_ntimer;
@@ -94,13 +121,6 @@ #define	HPET_IE			0x0002	/* interrupt en
 #define	HPET_PERIODIC		0x0004
 #define	HPET_SHARED_IRQ		0x0008
 
-#if BITS_PER_LONG = 64
-#define	write_counter(V, MC)	writeq(V, MC)
-#define	read_counter(MC)	readq(MC)
-#else
-#define	write_counter(V, MC) 	writel(V, MC)
-#define	read_counter(MC)	readl(MC)
-#endif
 
 #ifndef readq
 static inline unsigned long long readq(void __iomem *addr)
@@ -737,27 +757,6 @@ static ctl_table dev_root[] = {
 
 static struct ctl_table_header *sysctl_header;
 
-static void hpet_register_interpolator(struct hpets *hpetp)
-{
-#ifdef	CONFIG_TIME_INTERPOLATION
-	struct time_interpolator *ti;
-
-	ti = kzalloc(sizeof(*ti), GFP_KERNEL);
-	if (!ti)
-		return;
-
-	ti->source = TIME_SOURCE_MMIO64;
-	ti->shift = 10;
-	ti->addr = &hpetp->hp_hpet->hpet_mc;
-	ti->frequency = hpetp->hp_tick_freq;
-	ti->drift = HPET_DRIFT;
-	ti->mask = -1;
-
-	hpetp->hp_interpolator = ti;
-	register_time_interpolator(ti);
-#endif
-}
-
 /*
  * Adjustment for when arming the timer with
  * initial conditions.  That is, main counter
@@ -909,7 +908,14 @@ int hpet_alloc(struct hpet_data *hdp)
 	}
 

drivers/char/hpet.c int hpet_alloc(struct hpet_data *hdp) · line 918

Quoted 10 lines
drivers/char/hpet.c +8 -1
 	hpetp->hp_delta = hpet_calibrate(hpetp);
-	hpet_register_interpolator(hpetp);
+
+	if (!hpet_clocksource_p) {
+        	clocksource_hpet.fsys_mmio_ptr = hpet_mc_ptr = &hpetp->hp_hpet->hpet_mc;
+        	clocksource_hpet.mult = clocksource_hz2mult(hpetp->hp_tick_freq,
+						clocksource_hpet.shift);
+        	clocksource_register(&clocksource_hpet);
+		hpet_clocksource_p = hpetp->hp_clocksource = &clocksource_hpet;
+	}

This looks like a change in behaviour for non-ia64. Now i386 and x86_64 will get this clocksource twice (and this one has a higher rating). Doesn't look like this will even compile since fsys_mmio_ptr (more extraneous _ptr suffix) is ia64 only? And sparc64 is left out in the cold.

Quoted 25 lines
drivers/char/hpet.c +1 -1
 	return 0;
 }
@@ -995,7 +1001,7 @@ static int hpet_acpi_add(struct acpi_dev
 
 static int hpet_acpi_remove(struct acpi_device *device, int type)
 {
-	/* XXX need to unregister interpolator, dealloc mem, etc */
+	/* XXX need to unregister clocksource, dealloc mem, etc */
 	return -EINVAL;
 }
 
include/linux/clocksource.h +3 -0
index daa4940..a20b4d6 100644
@@ -61,6 +61,9 @@ struct clocksource {
 	u32 shift;
 	unsigned long flags;
 	cycle_t (*vread)(void);
+#ifdef CONFIG_IA64
+	void *fsys_mmio_ptr;	/* used by fsyscall asm code */
+#endif
 
 	/* timekeeping specific data, ignore */
 	cycle_t cycle_last, cycle_interval;
#20 lore raw
Quoted 22 lines · Chris Wright
Quoted 6 lines · * Peter Keilty ([email protected]) wrote:
drivers/acpi/processor_idle.c +0 -0
index 6077300..35ad71f 100644
@@ -480,10 +480,12 @@ #endif
 		/* Get end time (ticks) */

drivers/acpi/processor_idle.c #endif · line 490

Quoted 10 lines
drivers/acpi/processor_idle.c +2 -0
 		t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
 
+#ifndef CONFIG_IA64
 #ifdef CONFIG_GENERIC_TIME
 		/* TSC halts in C2, so notify users */
 		mark_tsc_unstable();
 #endif
+#endif
 
 

Is this a better description of the dependency?

Quoted 3 lines

#if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86_TSC)

yes, ok.

Quoted 139 lines
Quoted 7 lines
drivers/acpi/processor_idle.c +0 -0
 		/* Re-enable interrupts */
		local_irq_enable();
		current_thread_info()->status |= TS_POLLING;
drivers/acpi/processor_idle.c +0 -0
@@ -522,10 +524,12 @@ #endif
 			acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);

drivers/acpi/processor_idle.c #endif · line 534

Quoted 10 lines
drivers/acpi/processor_idle.c +2 -0
 		}
 
+#ifndef CONFIG_IA64
 #ifdef CONFIG_GENERIC_TIME
 		/* TSC halts in C3, so notify users */
 		mark_tsc_unstable();
 #endif
+#endif
 
 

ditto

Quoted 22 lines
drivers/acpi/processor_idle.c +0 -0
 		/* Re-enable interrupts */
		local_irq_enable();
		current_thread_info()->status |= TS_POLLING;
drivers/char/hpet.c +4 -0
index 0be700f..5ea7d3e 100644
@@ -29,6 +29,7 @@ #include <linux/wait.h>
 #include <linux/bcd.h>
 #include <linux/seq_file.h>
 #include <linux/bitops.h>
+#include <linux/clocksource.h>
 
 #include <asm/current.h>
 #include <asm/uaccess.h>
@@ -51,8 +52,34 @@ #define	HPET_DRIFT	(500)
 
 #define HPET_RANGE_SIZE		1024	/* from HPET spec */
 
+#if BITS_PER_LONG = 64
+#define	write_counter(V, MC)	writeq(V, MC)
+#define	read_counter(MC)	readq(MC)

drivers/char/hpet.c #define HPET_DRIFT (500) · line 67

Quoted 10 lines
drivers/char/hpet.c +6 -0
+#else
+#define	write_counter(V, MC) 	writel(V, MC)
+#define	read_counter(MC)	readl(MC)
+#endif
+
 static u32 hpet_nhpet, hpet_max_freq = HPET_USER_FREQ;
 
+static void __iomem *hpet_mc_ptr;
 
 

CodingStyle nit: we don't need all this _ptr...

Quoted 7 lines
drivers/char/hpet.c +6 -0
+static cycle_t read_hpet(void)
+{
+	return (cycle_t)read_counter((void __iomem *)hpet_mc_ptr);
+}
+
+static struct clocksource clocksource_hpet = {

drivers/char/hpet.c #define HPET_DRIFT (500)

Quoted 10 lines
drivers/char/hpet.c +9 -0
+        .name           = "hpet",
+        .rating         = 300,
+        .read           = read_hpet,
+        .mask           = 0xffffffffffffffffLL,
+        .mult           = 0, /*to be caluclated*/
+        .shift          = 10,
+        .is_continuous  = 1,
+};
+static struct clocksource *hpet_clocksource_p;
 

and _p naming.

Quoted 58 lines
drivers/char/hpet.c +1 -0
+

/* A lock for concurrent access by app and isr hpet activity. */ static DEFINE_SPINLOCK(hpet_lock);
/* A lock for concurrent intermodule access to hpet and isr hpet activity. */

drivers/char/hpet.c +1 -29
@@ -79,7 +106,7 @@ struct hpets {
 	struct hpets *hp_next;
 	struct hpet __iomem *hp_hpet;
 	unsigned long hp_hpet_phys;
-	struct time_interpolator *hp_interpolator;
+	struct clocksource *hp_clocksource;
 	unsigned long long hp_tick_freq;
 	unsigned long hp_delta;
 	unsigned int hp_ntimer;
@@ -94,13 +121,6 @@ #define	HPET_IE			0x0002	/* interrupt en
 #define	HPET_PERIODIC		0x0004
 #define	HPET_SHARED_IRQ		0x0008
 
-#if BITS_PER_LONG = 64
-#define	write_counter(V, MC)	writeq(V, MC)
-#define	read_counter(MC)	readq(MC)
-#else
-#define	write_counter(V, MC) 	writel(V, MC)
-#define	read_counter(MC)	readl(MC)
-#endif
 
 #ifndef readq
 static inline unsigned long long readq(void __iomem *addr)
@@ -737,27 +757,6 @@ static ctl_table dev_root[] = {
 
 static struct ctl_table_header *sysctl_header;
 
-static void hpet_register_interpolator(struct hpets *hpetp)
-{
-#ifdef	CONFIG_TIME_INTERPOLATION
-	struct time_interpolator *ti;
-
-	ti = kzalloc(sizeof(*ti), GFP_KERNEL);
-	if (!ti)
-		return;
-
-	ti->source = TIME_SOURCE_MMIO64;
-	ti->shift = 10;
-	ti->addr = &hpetp->hp_hpet->hpet_mc;
-	ti->frequency = hpetp->hp_tick_freq;
-	ti->drift = HPET_DRIFT;
-	ti->mask = -1;
-
-	hpetp->hp_interpolator = ti;
-	register_time_interpolator(ti);
-#endif
-}
-
 /*
 * Adjustment for when arming the timer with
 * initial conditions.  That is, main counter
@@ -909,7 +908,14 @@ int hpet_alloc(struct hpet_data *hdp)
 	}
 
Quoted 18 lines

drivers/char/hpet.c int hpet_alloc(struct hpet_data *hdp)

Quoted 12 lines
drivers/char/hpet.c +8 -1
 	hpetp->hp_delta = hpet_calibrate(hpetp);
-	hpet_register_interpolator(hpetp);
+
+	if (!hpet_clocksource_p) {
+        	clocksource_hpet.fsys_mmio_ptr = hpet_mc_ptr = &hpetp->hp_hpet->hpet_mc;
+        	clocksource_hpet.mult = clocksource_hz2mult(hpetp->hp_tick_freq,
+						clocksource_hpet.shift);
+        	clocksource_register(&clocksource_hpet);
+		hpet_clocksource_p = hpetp->hp_clocksource = &clocksource_hpet;
+	}
 
 

This looks like a change in behaviour for non-ia64. Now i386 and x86_64 will get this clocksource twice (and this one has a higher rating). Doesn't look like this will even compile since fsys_mmio_ptr (more

Yes need to change setting for fsys_mmio just for ia64. I will check the load multiple clocksources, before it was limited.

Quoted 32 lines

extraneous _ptr suffix) is ia64 only? And sparc64 is left out in the cold.

Quoted 27 lines
drivers/char/hpet.c +0 -0
 	return 0;

}

drivers/char/hpet.c +1 -1
@@ -995,7 +1001,7 @@ static int hpet_acpi_add(struct acpi_dev
 
 static int hpet_acpi_remove(struct acpi_device *device, int type)
 {
-	/* XXX need to unregister interpolator, dealloc mem, etc */
+	/* XXX need to unregister clocksource, dealloc mem, etc */
 	return -EINVAL;
 }
 
include/linux/clocksource.h +3 -0
index daa4940..a20b4d6 100644
@@ -61,6 +61,9 @@ struct clocksource {
 	u32 shift;
 	unsigned long flags;
 	cycle_t (*vread)(void);
+#ifdef CONFIG_IA64
+	void *fsys_mmio_ptr;	/* used by fsyscall asm code */
+#endif
 
 	/* timekeeping specific data, ignore */
 	cycle_t cycle_last, cycle_interval;