Skip to content

Commit 7d27558

Browse files
john stultzKAGA-KOKO
authored andcommitted
timekeeping: create arch_gettimeoffset infrastructure
Some arches don't supply their own clocksource. This is mainly the case in architectures that get their inter-tick times by reading the counter on their interval timer. Since these timers wrap every tick, they're not really useful as clocksources. Wrapping them to act like one is possible but not very efficient. So we provide a callout these arches can implement for use with the jiffies clocksource to provide finer then tick granular time. [ Impact: ease the migration to generic time keeping ] Signed-off-by: John Stultz <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]>
1 parent a25cbd0 commit 7d27558

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

include/linux/time.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ struct timespec current_kernel_time(void);
113113
#define CURRENT_TIME (current_kernel_time())
114114
#define CURRENT_TIME_SEC ((struct timespec) { get_seconds(), 0 })
115115

116+
/* Some architectures do not supply their own clocksource.
117+
* This is mainly the case in architectures that get their
118+
* inter-tick times by reading the counter on their interval
119+
* timer. Since these timers wrap every tick, they're not really
120+
* useful as clocksources. Wrapping them to act like one is possible
121+
* but not very efficient. So we provide a callout these arches
122+
* can implement for use with the jiffies clocksource to provide
123+
* finer then tick granular time.
124+
*/
125+
#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
126+
extern u32 arch_gettimeoffset(void);
127+
#else
128+
static inline u32 arch_gettimeoffset(void) { return 0; }
129+
#endif
130+
116131
extern void do_gettimeofday(struct timeval *tv);
117132
extern int do_settimeofday(struct timespec *tv);
118133
extern int do_sys_settimeofday(struct timespec *tv, struct timezone *tz);

kernel/time/timekeeping.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ static void clocksource_forward_now(void)
7777
clock->cycle_last = cycle_now;
7878

7979
nsec = cyc2ns(clock, cycle_delta);
80+
81+
/* If arch requires, add in gettimeoffset() */
82+
nsec += arch_gettimeoffset();
83+
8084
timespec_add_ns(&xtime, nsec);
8185

8286
nsec = ((s64)cycle_delta * clock->mult_orig) >> clock->shift;
@@ -111,6 +115,9 @@ void getnstimeofday(struct timespec *ts)
111115
/* convert to nanoseconds: */
112116
nsecs = cyc2ns(clock, cycle_delta);
113117

118+
/* If arch requires, add in gettimeoffset() */
119+
nsecs += arch_gettimeoffset();
120+
114121
} while (read_seqretry(&xtime_lock, seq));
115122

116123
timespec_add_ns(ts, nsecs);

0 commit comments

Comments
 (0)