Skip to content

Commit 164d44f

Browse files
committed
Merge branch 'timers-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'timers-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: clocksource: Add clocksource_register_hz/khz interface posix-cpu-timers: Optimize run_posix_cpu_timers() time: Remove xtime_cache mqueue: Convert message queue timeout to use hrtimers hrtimers: Provide schedule_hrtimeout for CLOCK_REALTIME timers: Introduce the concept of timer slack for legacy timers ntp: Remove tickadj ntp: Make time_adjust static time: Add xtime, wall_to_monotonic to feature-removal-schedule timer: Try to survive timer callback preempt_count leak timer: Split out timer function call timer: Print function name for timer callbacks modifying preemption count time: Clean up warp_clock() cpu-timers: Avoid iterating over all threads in fastpath_timer_check() cpu-timers: Change SIGEV_NONE timer implementation cpu-timers: Return correct previous timer reload value cpu-timers: Cleanup arm_timer() cpu-timers: Simplify RLIMIT_CPU handling
2 parents 5bfec46 + d7e81c2 commit 164d44f

14 files changed

Lines changed: 376 additions & 343 deletions

File tree

‎Documentation/feature-removal-schedule.txt‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,16 @@ Who: Avi Kivity <avi@redhat.com>
541541

542542
----------------------------
543543

544+
What: xtime, wall_to_monotonic
545+
When: 2.6.36+
546+
Files: kernel/time/timekeeping.c include/linux/time.h
547+
Why: Cleaning up timekeeping internal values. Please use
548+
existing timekeeping accessor functions to access
549+
the equivalent functionality.
550+
Who: John Stultz <johnstul@us.ibm.com>
551+
552+
----------------------------
553+
544554
What: KVM kernel-allocated memory slots
545555
When: July 2010
546556
Why: Since 2.6.25, kvm supports user-allocated memory slots, which are

‎include/linux/clocksource.h‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ static inline s64 clocksource_cyc2ns(cycle_t cycles, u32 mult, u32 shift)
273273
}
274274

275275

276-
/* used to install a new clocksource */
277276
extern int clocksource_register(struct clocksource*);
278277
extern void clocksource_unregister(struct clocksource*);
279278
extern void clocksource_touch_watchdog(void);
@@ -287,6 +286,24 @@ extern void clocksource_mark_unstable(struct clocksource *cs);
287286
extern void
288287
clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 minsec);
289288

289+
/*
290+
* Don't call __clocksource_register_scale directly, use
291+
* clocksource_register_hz/khz
292+
*/
293+
extern int
294+
__clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq);
295+
296+
static inline int clocksource_register_hz(struct clocksource *cs, u32 hz)
297+
{
298+
return __clocksource_register_scale(cs, 1, hz);
299+
}
300+
301+
static inline int clocksource_register_khz(struct clocksource *cs, u32 khz)
302+
{
303+
return __clocksource_register_scale(cs, 1000, khz);
304+
}
305+
306+
290307
static inline void
291308
clocksource_calc_mult_shift(struct clocksource *cs, u32 freq, u32 minsec)
292309
{

‎include/linux/hrtimer.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl,
422422

423423
extern int schedule_hrtimeout_range(ktime_t *expires, unsigned long delta,
424424
const enum hrtimer_mode mode);
425+
extern int schedule_hrtimeout_range_clock(ktime_t *expires,
426+
unsigned long delta, const enum hrtimer_mode mode, int clock);
425427
extern int schedule_hrtimeout(ktime_t *expires, const enum hrtimer_mode mode);
426428

427429
/* Soft interrupt function to run the hrtimer queues: */

‎include/linux/time.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ extern struct timespec timespec_trunc(struct timespec t, unsigned gran);
150150
extern int timekeeping_valid_for_hres(void);
151151
extern u64 timekeeping_max_deferment(void);
152152
extern void update_wall_time(void);
153-
extern void update_xtime_cache(u64 nsec);
154153
extern void timekeeping_leap_insert(int leapsecond);
155154

156155
struct tms;

‎include/linux/timer.h‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@
1010
struct tvec_base;
1111

1212
struct timer_list {
13+
/*
14+
* All fields that change during normal runtime grouped to the
15+
* same cacheline
16+
*/
1317
struct list_head entry;
1418
unsigned long expires;
19+
struct tvec_base *base;
1520

1621
void (*function)(unsigned long);
1722
unsigned long data;
1823

19-
struct tvec_base *base;
24+
int slack;
25+
2026
#ifdef CONFIG_TIMER_STATS
2127
void *start_site;
2228
char start_comm[16];
@@ -165,6 +171,8 @@ extern int mod_timer(struct timer_list *timer, unsigned long expires);
165171
extern int mod_timer_pending(struct timer_list *timer, unsigned long expires);
166172
extern int mod_timer_pinned(struct timer_list *timer, unsigned long expires);
167173

174+
extern void set_timer_slack(struct timer_list *time, int slack_hz);
175+
168176
#define TIMER_NOT_PINNED 0
169177
#define TIMER_PINNED 1
170178
/*

‎include/linux/timex.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,11 @@ struct timex {
232232
*/
233233
extern unsigned long tick_usec; /* USER_HZ period (usec) */
234234
extern unsigned long tick_nsec; /* ACTHZ period (nsec) */
235-
extern int tickadj; /* amount of adjustment per tick */
236235

237236
/*
238237
* phase-lock loop variables
239238
*/
240239
extern int time_status; /* clock synchronization status bits */
241-
extern long time_adjust; /* The amount of adjtime left */
242240

243241
extern void ntp_init(void);
244242
extern void ntp_clear(void);
@@ -271,9 +269,6 @@ extern void second_overflow(void);
271269
extern void update_ntp_one_tick(void);
272270
extern int do_adjtimex(struct timex *);
273271

274-
/* Don't use! Compatibility define for existing users. */
275-
#define tickadj (500/HZ ? : 1)
276-
277272
int read_current_timer(unsigned long *timer_val);
278273

279274
/* The clock frequency of the i8253/i8254 PIT */

‎ipc/mqueue.c‎

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ static void wq_add(struct mqueue_inode_info *info, int sr,
429429
* sr: SEND or RECV
430430
*/
431431
static int wq_sleep(struct mqueue_inode_info *info, int sr,
432-
long timeout, struct ext_wait_queue *ewp)
432+
ktime_t *timeout, struct ext_wait_queue *ewp)
433433
{
434434
int retval;
435435
signed long time;
@@ -440,7 +440,8 @@ static int wq_sleep(struct mqueue_inode_info *info, int sr,
440440
set_current_state(TASK_INTERRUPTIBLE);
441441

442442
spin_unlock(&info->lock);
443-
time = schedule_timeout(timeout);
443+
time = schedule_hrtimeout_range_clock(timeout,
444+
HRTIMER_MODE_ABS, 0, CLOCK_REALTIME);
444445

445446
while (ewp->state == STATE_PENDING)
446447
cpu_relax();
@@ -552,31 +553,16 @@ static void __do_notify(struct mqueue_inode_info *info)
552553
wake_up(&info->wait_q);
553554
}
554555

555-
static long prepare_timeout(struct timespec *p)
556+
static int prepare_timeout(const struct timespec __user *u_abs_timeout,
557+
ktime_t *expires, struct timespec *ts)
556558
{
557-
struct timespec nowts;
558-
long timeout;
559-
560-
if (p) {
561-
if (unlikely(p->tv_nsec < 0 || p->tv_sec < 0
562-
|| p->tv_nsec >= NSEC_PER_SEC))
563-
return -EINVAL;
564-
nowts = CURRENT_TIME;
565-
/* first subtract as jiffies can't be too big */
566-
p->tv_sec -= nowts.tv_sec;
567-
if (p->tv_nsec < nowts.tv_nsec) {
568-
p->tv_nsec += NSEC_PER_SEC;
569-
p->tv_sec--;
570-
}
571-
p->tv_nsec -= nowts.tv_nsec;
572-
if (p->tv_sec < 0)
573-
return 0;
574-
575-
timeout = timespec_to_jiffies(p) + 1;
576-
} else
577-
return MAX_SCHEDULE_TIMEOUT;
559+
if (copy_from_user(ts, u_abs_timeout, sizeof(struct timespec)))
560+
return -EFAULT;
561+
if (!timespec_valid(ts))
562+
return -EINVAL;
578563

579-
return timeout;
564+
*expires = timespec_to_ktime(*ts);
565+
return 0;
580566
}
581567

582568
static void remove_notification(struct mqueue_inode_info *info)
@@ -862,22 +848,21 @@ SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char __user *, u_msg_ptr,
862848
struct ext_wait_queue *receiver;
863849
struct msg_msg *msg_ptr;
864850
struct mqueue_inode_info *info;
865-
struct timespec ts, *p = NULL;
866-
long timeout;
851+
ktime_t expires, *timeout = NULL;
852+
struct timespec ts;
867853
int ret;
868854

869855
if (u_abs_timeout) {
870-
if (copy_from_user(&ts, u_abs_timeout,
871-
sizeof(struct timespec)))
872-
return -EFAULT;
873-
p = &ts;
856+
int res = prepare_timeout(u_abs_timeout, &expires, &ts);
857+
if (res)
858+
return res;
859+
timeout = &expires;
874860
}
875861

876862
if (unlikely(msg_prio >= (unsigned long) MQ_PRIO_MAX))
877863
return -EINVAL;
878864

879-
audit_mq_sendrecv(mqdes, msg_len, msg_prio, p);
880-
timeout = prepare_timeout(p);
865+
audit_mq_sendrecv(mqdes, msg_len, msg_prio, timeout ? &ts : NULL);
881866

882867
filp = fget(mqdes);
883868
if (unlikely(!filp)) {
@@ -919,9 +904,6 @@ SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char __user *, u_msg_ptr,
919904
if (filp->f_flags & O_NONBLOCK) {
920905
spin_unlock(&info->lock);
921906
ret = -EAGAIN;
922-
} else if (unlikely(timeout < 0)) {
923-
spin_unlock(&info->lock);
924-
ret = timeout;
925907
} else {
926908
wait.task = current;
927909
wait.msg = (void *) msg_ptr;
@@ -954,24 +936,23 @@ SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, char __user *, u_msg_ptr,
954936
size_t, msg_len, unsigned int __user *, u_msg_prio,
955937
const struct timespec __user *, u_abs_timeout)
956938
{
957-
long timeout;
958939
ssize_t ret;
959940
struct msg_msg *msg_ptr;
960941
struct file *filp;
961942
struct inode *inode;
962943
struct mqueue_inode_info *info;
963944
struct ext_wait_queue wait;
964-
struct timespec ts, *p = NULL;
945+
ktime_t expires, *timeout = NULL;
946+
struct timespec ts;
965947

966948
if (u_abs_timeout) {
967-
if (copy_from_user(&ts, u_abs_timeout,
968-
sizeof(struct timespec)))
969-
return -EFAULT;
970-
p = &ts;
949+
int res = prepare_timeout(u_abs_timeout, &expires, &ts);
950+
if (res)
951+
return res;
952+
timeout = &expires;
971953
}
972954

973-
audit_mq_sendrecv(mqdes, msg_len, 0, p);
974-
timeout = prepare_timeout(p);
955+
audit_mq_sendrecv(mqdes, msg_len, 0, timeout ? &ts : NULL);
975956

976957
filp = fget(mqdes);
977958
if (unlikely(!filp)) {
@@ -1003,11 +984,6 @@ SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, char __user *, u_msg_ptr,
1003984
if (filp->f_flags & O_NONBLOCK) {
1004985
spin_unlock(&info->lock);
1005986
ret = -EAGAIN;
1006-
msg_ptr = NULL;
1007-
} else if (unlikely(timeout < 0)) {
1008-
spin_unlock(&info->lock);
1009-
ret = timeout;
1010-
msg_ptr = NULL;
1011987
} else {
1012988
wait.task = current;
1013989
wait.state = STATE_NONE;

‎kernel/hrtimer.c‎

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,35 +1749,15 @@ void __init hrtimers_init(void)
17491749
}
17501750

17511751
/**
1752-
* schedule_hrtimeout_range - sleep until timeout
1752+
* schedule_hrtimeout_range_clock - sleep until timeout
17531753
* @expires: timeout value (ktime_t)
17541754
* @delta: slack in expires timeout (ktime_t)
17551755
* @mode: timer mode, HRTIMER_MODE_ABS or HRTIMER_MODE_REL
1756-
*
1757-
* Make the current task sleep until the given expiry time has
1758-
* elapsed. The routine will return immediately unless
1759-
* the current task state has been set (see set_current_state()).
1760-
*
1761-
* The @delta argument gives the kernel the freedom to schedule the
1762-
* actual wakeup to a time that is both power and performance friendly.
1763-
* The kernel give the normal best effort behavior for "@expires+@delta",
1764-
* but may decide to fire the timer earlier, but no earlier than @expires.
1765-
*
1766-
* You can set the task state as follows -
1767-
*
1768-
* %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to
1769-
* pass before the routine returns.
1770-
*
1771-
* %TASK_INTERRUPTIBLE - the routine may return early if a signal is
1772-
* delivered to the current task.
1773-
*
1774-
* The current task state is guaranteed to be TASK_RUNNING when this
1775-
* routine returns.
1776-
*
1777-
* Returns 0 when the timer has expired otherwise -EINTR
1756+
* @clock: timer clock, CLOCK_MONOTONIC or CLOCK_REALTIME
17781757
*/
1779-
int __sched schedule_hrtimeout_range(ktime_t *expires, unsigned long delta,
1780-
const enum hrtimer_mode mode)
1758+
int __sched
1759+
schedule_hrtimeout_range_clock(ktime_t *expires, unsigned long delta,
1760+
const enum hrtimer_mode mode, int clock)
17811761
{
17821762
struct hrtimer_sleeper t;
17831763

@@ -1799,7 +1779,7 @@ int __sched schedule_hrtimeout_range(ktime_t *expires, unsigned long delta,
17991779
return -EINTR;
18001780
}
18011781

1802-
hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, mode);
1782+
hrtimer_init_on_stack(&t.timer, clock, mode);
18031783
hrtimer_set_expires_range_ns(&t.timer, *expires, delta);
18041784

18051785
hrtimer_init_sleeper(&t, current);
@@ -1818,6 +1798,41 @@ int __sched schedule_hrtimeout_range(ktime_t *expires, unsigned long delta,
18181798

18191799
return !t.task ? 0 : -EINTR;
18201800
}
1801+
1802+
/**
1803+
* schedule_hrtimeout_range - sleep until timeout
1804+
* @expires: timeout value (ktime_t)
1805+
* @delta: slack in expires timeout (ktime_t)
1806+
* @mode: timer mode, HRTIMER_MODE_ABS or HRTIMER_MODE_REL
1807+
*
1808+
* Make the current task sleep until the given expiry time has
1809+
* elapsed. The routine will return immediately unless
1810+
* the current task state has been set (see set_current_state()).
1811+
*
1812+
* The @delta argument gives the kernel the freedom to schedule the
1813+
* actual wakeup to a time that is both power and performance friendly.
1814+
* The kernel give the normal best effort behavior for "@expires+@delta",
1815+
* but may decide to fire the timer earlier, but no earlier than @expires.
1816+
*
1817+
* You can set the task state as follows -
1818+
*
1819+
* %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to
1820+
* pass before the routine returns.
1821+
*
1822+
* %TASK_INTERRUPTIBLE - the routine may return early if a signal is
1823+
* delivered to the current task.
1824+
*
1825+
* The current task state is guaranteed to be TASK_RUNNING when this
1826+
* routine returns.
1827+
*
1828+
* Returns 0 when the timer has expired otherwise -EINTR
1829+
*/
1830+
int __sched schedule_hrtimeout_range(ktime_t *expires, unsigned long delta,
1831+
const enum hrtimer_mode mode)
1832+
{
1833+
return schedule_hrtimeout_range_clock(expires, delta, mode,
1834+
CLOCK_MONOTONIC);
1835+
}
18211836
EXPORT_SYMBOL_GPL(schedule_hrtimeout_range);
18221837

18231838
/**

0 commit comments

Comments
 (0)