History

Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull timer updates from Thomas Gleixner: "The time/timekeeping/timer folks deliver with this update: - Fix a reintroduced signed/unsigned issue and cleanup the whole signed/unsigned mess in the timekeeping core so this wont happen accidentaly again. - Add a new trace clock based on boot time - Prevent injection of random sleep times when PM tracing abuses the RTC for storage - Make posix timers configurable for real tiny systems - Add tracepoints for the alarm timer subsystem so timer based suspend wakeups can be instrumented - The usual pile of fixes and updates to core and drivers" * 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (23 commits) timekeeping: Use mul_u64_u32_shr() instead of open coding it timekeeping: Get rid of pointless typecasts timekeeping: Make the conversion call chain consistently unsigned timekeeping_Force_unsigned_clocksource_to_nanoseconds_conversion alarmtimer: Add tracepoints for alarm timers trace: Update documentation for mono, mono_raw and boot clock trace: Add an option for boot clock as trace clock timekeeping: Add a fast and NMI safe boot clock timekeeping/clocksource_cyc2ns: Document intended range limitation timekeeping: Ignore the bogus sleep time if pm_trace is enabled selftests/timers: Fix spelling mistake "Asyncrhonous" -> "Asynchronous" clocksource/drivers/bcm2835_timer: Unmap region obtained by of_iomap clocksource/drivers/arm_arch_timer: Map frame with of_io_request_and_map() arm64: dts: rockchip: Arch counter doesn't tick in system suspend clocksource/drivers/arm_arch_timer: Don't assume clock runs in suspend posix-timers: Make them configurable posix_cpu_timers: Move the add_device_randomness() call to a proper place timer: Move sys_alarm from timer.c to itimer.c ptp_clock: Allow for it to be optional Kconfig: Regenerate *.c_shipped files after previous changes ...

Linus Torvalds committed 9 years ago

Commit 9465d9c2 parents e71c397 c029a2b61 files · +1479 −1041Browse files

Showing the changes to kernel/time (8 of 61 files). Show all

Unified · Split

8 files
  1. kernel/time/Makefile +8 −2
  2. kernel/time/alarmtimer.c +47 −12
  3. kernel/time/hrtimer.c +14 −6
  4. kernel/time/itimer.c +14 −1
  5. kernel/time/posix-cpu-timers.c +0 −4
  6. kernel/time/posix-stubs.c +123 −0
  7. kernel/time/timekeeping.c +51 −39
  8. kernel/time/timer.c +18 −30
kernel/time/Makefile+8−2
@@ -1,6 +1,12 @@
1−obj-y += time.o timer.o hrtimer.o itimer.o posix-timers.o posix-cpu-timers.o
1+obj-y += time.o timer.o hrtimer.o
22 obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o
3−obj-y += timeconv.o timecounter.o posix-clock.o alarmtimer.o
3+obj-y += timeconv.o timecounter.o alarmtimer.o
4+
5+ifeq ($(CONFIG_POSIX_TIMERS),y)
6+ obj-y += posix-timers.o posix-cpu-timers.o posix-clock.o itimer.o
7+else
8+ obj-y += posix-stubs.o
9+endif
410
511 obj-$(CONFIG_GENERIC_CLOCKEVENTS) += clockevents.o tick-common.o
612 ifeq ($(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST),y)
kernel/time/alarmtimer.c+47−12
@@ -26,6 +26,9 @@ · 25 unmodified lines
2626 #include <linux/workqueue.h>
2727 #include <linux/freezer.h>
2828
29+#define CREATE_TRACE_POINTS
30+#include <trace/events/alarmtimer.h>
31+
2932 /**
3033 * struct alarm_base - Alarm timer bases
3134 * @lock: Lock for syncrhonized access to the base
@@ -40,7 +43,9 @@ static struct alarm_base { · 8 unmodified lines
4043 clockid_t base_clockid;
4144 } alarm_bases[ALARM_NUMTYPE];
4245
43−/* freezer delta & lock used to handle clock_nanosleep triggered wakeups */
46+/* freezer information to handle clock_nanosleep triggered wakeups */
47+static enum alarmtimer_type freezer_alarmtype;
48+static ktime_t freezer_expires;
4449 static ktime_t freezer_delta;
4550 static DEFINE_SPINLOCK(freezer_delta_lock);
4651
@@ -194,6 +199,7 @@ static enum hrtimer_restart alarmtimer_fired(struct hrtimer *timer) · 147 unmodified lines
194199 }
195200 spin_unlock_irqrestore(&base->lock, flags);
196201
202+ trace_alarmtimer_fired(alarm, base->gettime());
197203 return ret;
198204
199205 }
@@ -218,15 +224,16 @@ EXPORT_SYMBOL_GPL(alarm_expires_remaining); · 18 unmodified lines
218224 */
219225 static int alarmtimer_suspend(struct device *dev)
220226 {
221− struct rtc_time tm;
222− ktime_t min, now;
223− unsigned long flags;
227+ ktime_t min, now, expires;
228+ int i, ret, type;
224229 struct rtc_device *rtc;
225− int i;
226− int ret;
230+ unsigned long flags;
231+ struct rtc_time tm;
227232
228233 spin_lock_irqsave(&freezer_delta_lock, flags);
229234 min = freezer_delta;
235+ expires = freezer_expires;
236+ type = freezer_alarmtype;
230237 freezer_delta = ktime_set(0, 0);
231238 spin_unlock_irqrestore(&freezer_delta_lock, flags);
232239
@@ -247,8 +254,11 @@ static int alarmtimer_suspend(struct device *dev) · 14 unmodified lines
247254 if (!next)
248255 continue;
249256 delta = ktime_sub(next->expires, base->gettime());
250− if (!min.tv64 || (delta.tv64 < min.tv64))
257+ if (!min.tv64 || (delta.tv64 < min.tv64)) {
258+ expires = next->expires;
251259 min = delta;
260+ type = i;
261+ }
252262 }
253263 if (min.tv64 == 0)
254264 return 0;
@@ -258,6 +268,8 @@ static int alarmtimer_suspend(struct device *dev) · 3 unmodified lines
258268 return -EBUSY;
259269 }
260270
271+ trace_alarmtimer_suspend(expires, type);
272+
261273 /* Setup an rtc timer to fire that far in the future */
262274 rtc_timer_cancel(rtc, &rtctimer);
263275 rtc_read_time(rtc, &tm);
@@ -295,15 +307,32 @@ static int alarmtimer_resume(struct device *dev) · 31 unmodified lines
295307
296308 static void alarmtimer_freezerset(ktime_t absexp, enum alarmtimer_type type)
297309 {
298− ktime_t delta;
310+ struct alarm_base *base;
299311 unsigned long flags;
300− struct alarm_base *base = &alarm_bases[type];
312+ ktime_t delta;
313+
314+ switch(type) {
315+ case ALARM_REALTIME:
316+ base = &alarm_bases[ALARM_REALTIME];
317+ type = ALARM_REALTIME_FREEZER;
318+ break;
319+ case ALARM_BOOTTIME:
320+ base = &alarm_bases[ALARM_BOOTTIME];
321+ type = ALARM_BOOTTIME_FREEZER;
322+ break;
323+ default:
324+ WARN_ONCE(1, "Invalid alarm type: %d\n", type);
325+ return;
326+ }
301327
302328 delta = ktime_sub(absexp, base->gettime());
303329
304330 spin_lock_irqsave(&freezer_delta_lock, flags);
305− if (!freezer_delta.tv64 || (delta.tv64 < freezer_delta.tv64))
331+ if (!freezer_delta.tv64 || (delta.tv64 < freezer_delta.tv64)) {
306332 freezer_delta = delta;
333+ freezer_expires = absexp;
334+ freezer_alarmtype = type;
335+ }
307336 spin_unlock_irqrestore(&freezer_delta_lock, flags);
308337 }
309338
@@ -342,6 +371,8 @@ void alarm_start(struct alarm *alarm, ktime_t start) · 32 unmodified lines
342371 alarmtimer_enqueue(base, alarm);
343372 hrtimer_start(&alarm->timer, alarm->node.expires, HRTIMER_MODE_ABS);
344373 spin_unlock_irqrestore(&base->lock, flags);
374+
375+ trace_alarmtimer_start(alarm, base->gettime());
345376 }
346377 EXPORT_SYMBOL_GPL(alarm_start);
347378
@@ -390,6 +421,8 @@ int alarm_try_to_cancel(struct alarm *alarm) · 42 unmodified lines
390421 if (ret >= 0)
391422 alarmtimer_dequeue(base, alarm);
392423 spin_unlock_irqrestore(&base->lock, flags);
424+
425+ trace_alarmtimer_cancel(alarm, base->gettime());
393426 return ret;
394427 }
395428 EXPORT_SYMBOL_GPL(alarm_try_to_cancel);
@@ -846,8 +879,10 @@ static int __init alarmtimer_init(void) · 450 unmodified lines
846879
847880 alarmtimer_rtc_timer_init();
848881
849− posix_timers_register_clock(CLOCK_REALTIME_ALARM, &alarm_clock);
850− posix_timers_register_clock(CLOCK_BOOTTIME_ALARM, &alarm_clock);
882+ if (IS_ENABLED(CONFIG_POSIX_TIMERS)) {
883+ posix_timers_register_clock(CLOCK_REALTIME_ALARM, &alarm_clock);
884+ posix_timers_register_clock(CLOCK_BOOTTIME_ALARM, &alarm_clock);
885+ }
851886
852887 /* Initialize alarm bases */
853888 alarm_bases[ALARM_REALTIME].base_clockid = CLOCK_REALTIME;
kernel/time/hrtimer.c+14−6
@@ -1742,15 +1742,19 @@ schedule_hrtimeout_range_clock(ktime_t *expires, u64 delta, · 1741 unmodified lines
17421742 * You can set the task state as follows -
17431743 *
17441744 * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to
1745− * pass before the routine returns.
1745+ * pass before the routine returns unless the current task is explicitly
1746+ * woken up, (e.g. by wake_up_process()).
17461747 *
17471748 * %TASK_INTERRUPTIBLE - the routine may return early if a signal is
1748− * delivered to the current task.
1749+ * delivered to the current task or the current task is explicitly woken
1750+ * up.
17491751 *
17501752 * The current task state is guaranteed to be TASK_RUNNING when this
17511753 * routine returns.
17521754 *
1753− * Returns 0 when the timer has expired otherwise -EINTR
1755+ * Returns 0 when the timer has expired. If the task was woken before the
1756+ * timer expired by a signal (only possible in state TASK_INTERRUPTIBLE) or
1757+ * by an explicit wakeup, it returns -EINTR.
17541758 */
17551759 int __sched schedule_hrtimeout_range(ktime_t *expires, u64 delta,
17561760 const enum hrtimer_mode mode)
@@ -1772,15 +1776,19 @@ EXPORT_SYMBOL_GPL(schedule_hrtimeout_range); · 15 unmodified lines
17721776 * You can set the task state as follows -
17731777 *
17741778 * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to
1775− * pass before the routine returns.
1779+ * pass before the routine returns unless the current task is explicitly
1780+ * woken up, (e.g. by wake_up_process()).
17761781 *
17771782 * %TASK_INTERRUPTIBLE - the routine may return early if a signal is
1778− * delivered to the current task.
1783+ * delivered to the current task or the current task is explicitly woken
1784+ * up.
17791785 *
17801786 * The current task state is guaranteed to be TASK_RUNNING when this
17811787 * routine returns.
17821788 *
1783− * Returns 0 when the timer has expired otherwise -EINTR
1789+ * Returns 0 when the timer has expired. If the task was woken before the
1790+ * timer expired by a signal (only possible in state TASK_INTERRUPTIBLE) or
1791+ * by an explicit wakeup, it returns -EINTR.
17841792 */
17851793 int __sched schedule_hrtimeout(ktime_t *expires,
17861794 const enum hrtimer_mode mode)
kernel/time/itimer.c+14−1
@@ -238,6 +238,8 @@ again: · 237 unmodified lines
238238 return 0;
239239 }
240240
241+#ifdef __ARCH_WANT_SYS_ALARM
242+
241243 /**
242244 * alarm_setitimer - set alarm in seconds
243245 *
@@ -250,7 +252,7 @@ again: · 6 unmodified lines
250252 * On 32 bit machines the seconds value is limited to (INT_MAX/2) to avoid
251253 * negative timeval settings which would cause immediate expiry.
252254 */
253−unsigned int alarm_setitimer(unsigned int seconds)
255+static unsigned int alarm_setitimer(unsigned int seconds)
254256 {
255257 struct itimerval it_new, it_old;
256258
@@ -275,6 +277,17 @@ unsigned int alarm_setitimer(unsigned int seconds) · 18 unmodified lines
275277 return it_old.it_value.tv_sec;
276278 }
277279
280+/*
281+ * For backwards compatibility? This can be done in libc so Alpha
282+ * and all newer ports shouldn't need it.
283+ */
284+SYSCALL_DEFINE1(alarm, unsigned int, seconds)
285+{
286+ return alarm_setitimer(seconds);
287+}
288+
289+#endif
290+
278291 SYSCALL_DEFINE3(setitimer, int, which, struct itimerval __user *, value,
279292 struct itimerval __user *, ovalue)
280293 {
kernel/time/posix-cpu-timers.c+0−4
@@ -9,7 +9,6 @@ · 8 unmodified lines
99 #include <asm/uaccess.h>
1010 #include <linux/kernel_stat.h>
1111 #include <trace/events/timer.h>
12−#include <linux/random.h>
1312 #include <linux/tick.h>
1413 #include <linux/workqueue.h>
1514
@@ -447,10 +446,7 @@ static void cleanup_timers(struct list_head *head) · 431 unmodified lines
447446 */
448447 void posix_cpu_timers_exit(struct task_struct *tsk)
449448 {
450− add_device_randomness((const void*) &tsk->se.sum_exec_runtime,
451− sizeof(unsigned long long));
452449 cleanup_timers(tsk->cpu_timers);
453−
454450 }
455451 void posix_cpu_timers_exit_group(struct task_struct *tsk)
456452 {
kernel/time/posix-stubs.c+123−0
@@ -0,0 +1,123 @@
1+/*
2+ * Dummy stubs used when CONFIG_POSIX_TIMERS=n
3+ *
4+ * Created by: Nicolas Pitre, July 2016
5+ * Copyright: (C) 2016 Linaro Limited
6+ *
7+ * This program is free software; you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License version 2 as
9+ * published by the Free Software Foundation.
10+ */
11+
12+#include <linux/linkage.h>
13+#include <linux/kernel.h>
14+#include <linux/sched.h>
15+#include <linux/errno.h>
16+#include <linux/syscalls.h>
17+#include <linux/ktime.h>
18+#include <linux/timekeeping.h>
19+#include <linux/posix-timers.h>
20+
21+asmlinkage long sys_ni_posix_timers(void)
22+{
23+ pr_err_once("process %d (%s) attempted a POSIX timer syscall "
24+ "while CONFIG_POSIX_TIMERS is not set\n",
25+ current->pid, current->comm);
26+ return -ENOSYS;
27+}
28+
29+#define SYS_NI(name) SYSCALL_ALIAS(sys_##name, sys_ni_posix_timers)
30+
31+SYS_NI(timer_create);
32+SYS_NI(timer_gettime);
33+SYS_NI(timer_getoverrun);
34+SYS_NI(timer_settime);
35+SYS_NI(timer_delete);
36+SYS_NI(clock_adjtime);
37+SYS_NI(getitimer);
38+SYS_NI(setitimer);
39+#ifdef __ARCH_WANT_SYS_ALARM
40+SYS_NI(alarm);
41+#endif
42+
43+/*
44+ * We preserve minimal support for CLOCK_REALTIME and CLOCK_MONOTONIC
45+ * as it is easy to remain compatible with little code. CLOCK_BOOTTIME
46+ * is also included for convenience as at least systemd uses it.
47+ */
48+
49+SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
50+ const struct timespec __user *, tp)
51+{
52+ struct timespec new_tp;
53+
54+ if (which_clock != CLOCK_REALTIME)
55+ return -EINVAL;
56+ if (copy_from_user(&new_tp, tp, sizeof (*tp)))
57+ return -EFAULT;
58+ return do_sys_settimeofday(&new_tp, NULL);
59+}
60+
61+SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
62+ struct timespec __user *,tp)
63+{
64+ struct timespec kernel_tp;
65+
66+ switch (which_clock) {
67+ case CLOCK_REALTIME: ktime_get_real_ts(&kernel_tp); break;
68+ case CLOCK_MONOTONIC: ktime_get_ts(&kernel_tp); break;
69+ case CLOCK_BOOTTIME: get_monotonic_boottime(&kernel_tp); break;
70+ default: return -EINVAL;
71+ }
72+ if (copy_to_user(tp, &kernel_tp, sizeof (kernel_tp)))
73+ return -EFAULT;
74+ return 0;
75+}
76+
77+SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, struct timespec __user *, tp)
78+{
79+ struct timespec rtn_tp = {
80+ .tv_sec = 0,
81+ .tv_nsec = hrtimer_resolution,
82+ };
83+
84+ switch (which_clock) {
85+ case CLOCK_REALTIME:
86+ case CLOCK_MONOTONIC:
87+ case CLOCK_BOOTTIME:
88+ if (copy_to_user(tp, &rtn_tp, sizeof(rtn_tp)))
89+ return -EFAULT;
90+ return 0;
91+ default:
92+ return -EINVAL;
93+ }
94+}
95+
96+SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags,
97+ const struct timespec __user *, rqtp,
98+ struct timespec __user *, rmtp)
99+{
100+ struct timespec t;
101+
102+ switch (which_clock) {
103+ case CLOCK_REALTIME:
104+ case CLOCK_MONOTONIC:
105+ case CLOCK_BOOTTIME:
106+ if (copy_from_user(&t, rqtp, sizeof (struct timespec)))
107+ return -EFAULT;
108+ if (!timespec_valid(&t))
109+ return -EINVAL;
110+ return hrtimer_nanosleep(&t, rmtp, flags & TIMER_ABSTIME ?
111+ HRTIMER_MODE_ABS : HRTIMER_MODE_REL,
112+ which_clock);
113+ default:
114+ return -EINVAL;
115+ }
116+}
117+
118+#ifdef CONFIG_COMPAT
119+long clock_nanosleep_restart(struct restart_block *restart_block)
120+{
121+ return hrtimer_nanosleep_restart(restart_block);
122+}
123+#endif
kernel/time/timekeeping.c+51−39
@@ -258,10 +258,9 @@ static void tk_setup_internals(struct timekeeper *tk, struct clocksource *clock) · 257 unmodified lines
258258 tk->cycle_interval = interval;
259259
260260 /* Go back from cycles -> shifted ns */
261− tk->xtime_interval = (u64) interval * clock->mult;
261+ tk->xtime_interval = interval * clock->mult;
262262 tk->xtime_remainder = ntpinterval - tk->xtime_interval;
263− tk->raw_interval =
264− ((u64) interval * clock->mult) >> clock->shift;
263+ tk->raw_interval = (interval * clock->mult) >> clock->shift;
265264
266265 /* if changing clocks, convert xtime_nsec shift units */
267266 if (old_clock) {
@@ -299,10 +298,10 @@ u32 (*arch_gettimeoffset)(void) = default_arch_gettimeoffset; · 31 unmodified lines
299298 static inline u32 arch_gettimeoffset(void) { return 0; }
300299 #endif
301300
302−static inline s64 timekeeping_delta_to_ns(struct tk_read_base *tkr,
301+static inline u64 timekeeping_delta_to_ns(struct tk_read_base *tkr,
303302 cycle_t delta)
304303 {
305− s64 nsec;
304+ u64 nsec;
306305
307306 nsec = delta * tkr->mult + tkr->xtime_nsec;
308307 nsec >>= tkr->shift;
@@ -311,7 +310,7 @@ static inline s64 timekeeping_delta_to_ns(struct tk_read_base *tkr, · 2 unmodified lines
311310 return nsec + arch_gettimeoffset();
312311 }
313312
314−static inline s64 timekeeping_get_ns(struct tk_read_base *tkr)
313+static inline u64 timekeeping_get_ns(struct tk_read_base *tkr)
315314 {
316315 cycle_t delta;
317316
@@ -319,8 +318,8 @@ static inline s64 timekeeping_get_ns(struct tk_read_base *tkr) · 1 unmodified line
319318 return timekeeping_delta_to_ns(tkr, delta);
320319 }
321320
322−static inline s64 timekeeping_cycles_to_ns(struct tk_read_base *tkr,
323− cycle_t cycles)
321+static inline u64 timekeeping_cycles_to_ns(struct tk_read_base *tkr,
322+ cycle_t cycles)
324323 {
325324 cycle_t delta;
326325
@@ -425,6 +424,35 @@ u64 ktime_get_raw_fast_ns(void) · 98 unmodified lines
425424 }
426425 EXPORT_SYMBOL_GPL(ktime_get_raw_fast_ns);
427426
427+/**
428+ * ktime_get_boot_fast_ns - NMI safe and fast access to boot clock.
429+ *
430+ * To keep it NMI safe since we're accessing from tracing, we're not using a
431+ * separate timekeeper with updates to monotonic clock and boot offset
432+ * protected with seqlocks. This has the following minor side effects:
433+ *
434+ * (1) Its possible that a timestamp be taken after the boot offset is updated
435+ * but before the timekeeper is updated. If this happens, the new boot offset
436+ * is added to the old timekeeping making the clock appear to update slightly
437+ * earlier:
438+ * CPU 0 CPU 1
439+ * timekeeping_inject_sleeptime64()
440+ * __timekeeping_inject_sleeptime(tk, delta);
441+ * timestamp();
442+ * timekeeping_update(tk, TK_CLEAR_NTP...);
443+ *
444+ * (2) On 32-bit systems, the 64-bit boot offset (tk->offs_boot) may be
445+ * partially updated. Since the tk->offs_boot update is a rare event, this
446+ * should be a rare occurrence which postprocessing should be able to handle.
447+ */
448+u64 notrace ktime_get_boot_fast_ns(void)
449+{
450+ struct timekeeper *tk = &tk_core.timekeeper;
451+
452+ return (ktime_get_mono_fast_ns() + ktime_to_ns(tk->offs_boot));
453+}
454+EXPORT_SYMBOL_GPL(ktime_get_boot_fast_ns);
455+
428456 /* Suspend-time cycles value for halted fast timekeeper. */
429457 static cycle_t cycles_at_suspend;
430458
@@ -623,7 +651,7 @@ static void timekeeping_forward_now(struct timekeeper *tk) · 192 unmodified lines
623651 {
624652 struct clocksource *clock = tk->tkr_mono.clock;
625653 cycle_t cycle_now, delta;
626− s64 nsec;
654+ u64 nsec;
627655
628656 cycle_now = tk->tkr_mono.read(clock);
629657 delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last, tk->tkr_mono.mask);
@@ -652,7 +680,7 @@ int __getnstimeofday64(struct timespec64 *ts) · 22 unmodified lines
652680 {
653681 struct timekeeper *tk = &tk_core.timekeeper;
654682 unsigned long seq;
655− s64 nsecs = 0;
683+ u64 nsecs;
656684
657685 do {
658686 seq = read_seqcount_begin(&tk_core.seq);
@@ -692,7 +720,7 @@ ktime_t ktime_get(void) · 33 unmodified lines
692720 struct timekeeper *tk = &tk_core.timekeeper;
693721 unsigned int seq;
694722 ktime_t base;
695− s64 nsecs;
723+ u64 nsecs;
696724
697725 WARN_ON(timekeeping_suspended);
698726
@@ -735,7 +763,7 @@ ktime_t ktime_get_with_offset(enum tk_offsets offs) · 36 unmodified lines
735763 struct timekeeper *tk = &tk_core.timekeeper;
736764 unsigned int seq;
737765 ktime_t base, *offset = offsets[offs];
738− s64 nsecs;
766+ u64 nsecs;
739767
740768 WARN_ON(timekeeping_suspended);
741769
@@ -779,7 +807,7 @@ ktime_t ktime_get_raw(void) · 37 unmodified lines
779807 struct timekeeper *tk = &tk_core.timekeeper;
780808 unsigned int seq;
781809 ktime_t base;
782− s64 nsecs;
810+ u64 nsecs;
783811
784812 do {
785813 seq = read_seqcount_begin(&tk_core.seq);
@@ -804,8 +832,8 @@ void ktime_get_ts64(struct timespec64 *ts) · 18 unmodified lines
804832 {
805833 struct timekeeper *tk = &tk_core.timekeeper;
806834 struct timespec64 tomono;
807− s64 nsec;
808835 unsigned int seq;
836+ u64 nsec;
809837
810838 WARN_ON(timekeeping_suspended);
811839
@@ -893,8 +921,8 @@ void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot) · 81 unmodified lines
893921 unsigned long seq;
894922 ktime_t base_raw;
895923 ktime_t base_real;
896− s64 nsec_raw;
897− s64 nsec_real;
924+ u64 nsec_raw;
925+ u64 nsec_real;
898926 cycle_t now;
899927
900928 WARN_ON_ONCE(timekeeping_suspended);
@@ -1052,7 +1080,7 @@ int get_device_system_crosststamp(int (*get_time_fn) · 151 unmodified lines
10521080 cycle_t cycles, now, interval_start;
10531081 unsigned int clock_was_set_seq = 0;
10541082 ktime_t base_real, base_raw;
1055− s64 nsec_real, nsec_raw;
1083+ u64 nsec_real, nsec_raw;
10561084 u8 cs_was_changed_seq;
10571085 unsigned long seq;
10581086 bool do_interp;
@@ -1365,7 +1393,7 @@ void getrawmonotonic64(struct timespec64 *ts) · 306 unmodified lines
13651393 struct timekeeper *tk = &tk_core.timekeeper;
13661394 struct timespec64 ts64;
13671395 unsigned long seq;
1368− s64 nsecs;
1396+ u64 nsecs;
13691397
13701398 do {
13711399 seq = read_seqcount_begin(&tk_core.seq);
@@ -1616,7 +1644,7 @@ void timekeeping_resume(void) · 244 unmodified lines
16161644 struct clocksource *clock = tk->tkr_mono.clock;
16171645 unsigned long flags;
16181646 struct timespec64 ts_new, ts_delta;
1619− cycle_t cycle_now, cycle_delta;
1647+ cycle_t cycle_now;
16201648
16211649 sleeptime_injected = false;
16221650 read_persistent_clock64(&ts_new);
@@ -1642,27 +1670,11 @@ void timekeeping_resume(void) · 19 unmodified lines
16421670 cycle_now = tk->tkr_mono.read(clock);
16431671 if ((clock->flags & CLOCK_SOURCE_SUSPEND_NONSTOP) &&
16441672 cycle_now > tk->tkr_mono.cycle_last) {
1645− u64 num, max = ULLONG_MAX;
1646− u32 mult = clock->mult;
1647− u32 shift = clock->shift;
1648− s64 nsec = 0;
1649−
1650− cycle_delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last,
1651− tk->tkr_mono.mask);
1652−
1653− /*
1654− * "cycle_delta * mutl" may cause 64 bits overflow, if the
1655− * suspended time is too long. In that case we need do the
1656− * 64 bits math carefully
1657− */
1658− do_div(max, mult);
1659− if (cycle_delta > max) {
1660− num = div64_u64(cycle_delta, max);
1661− nsec = (((u64) max * mult) >> shift) * num;
1662− cycle_delta -= num * max;
1663− }
1664− nsec += ((u64) cycle_delta * mult) >> shift;
1673+ u64 nsec, cyc_delta;
16651674
1675+ cyc_delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last,
1676+ tk->tkr_mono.mask);
1677+ nsec = mul_u64_u32_shr(cyc_delta, clock->mult, clock->shift);
16661678 ts_delta = ns_to_timespec64(nsec);
16671679 sleeptime_injected = true;
16681680 } else if (timespec64_compare(&ts_new, &timekeeping_suspend_time) > 0) {
kernel/time/timer.c+18−30
@@ -1615,7 +1615,8 @@ void update_process_times(int user_tick) · 1614 unmodified lines
16151615 irq_work_tick();
16161616 #endif
16171617 scheduler_tick();
1618− run_posix_cpu_timers(p);
1618+ if (IS_ENABLED(CONFIG_POSIX_TIMERS))
1619+ run_posix_cpu_timers(p);
16191620 }
16201621
16211622 /**
@@ -1676,19 +1677,6 @@ void run_local_timers(void) · 54 unmodified lines
16761677 raise_softirq(TIMER_SOFTIRQ);
16771678 }
16781679
1679−#ifdef __ARCH_WANT_SYS_ALARM
1680−
1681−/*
1682− * For backwards compatibility? This can be done in libc so Alpha
1683− * and all newer ports shouldn't need it.
1684− */
1685−SYSCALL_DEFINE1(alarm, unsigned int, seconds)
1686−{
1687− return alarm_setitimer(seconds);
1688−}
1689−
1690−#endif
1691−
16921680 static void process_timeout(unsigned long __data)
16931681 {
16941682 wake_up_process((struct task_struct *)__data);
@@ -1705,11 +1693,12 @@ static void process_timeout(unsigned long __data) · 10 unmodified lines
17051693 * You can set the task state as follows -
17061694 *
17071695 * %TASK_UNINTERRUPTIBLE - at least @timeout jiffies are guaranteed to
1708− * pass before the routine returns. The routine will return 0
1696+ * pass before the routine returns unless the current task is explicitly
1697+ * woken up, (e.g. by wake_up_process())".
17091698 *
17101699 * %TASK_INTERRUPTIBLE - the routine may return early if a signal is
1711− * delivered to the current task. In this case the remaining time
1712− * in jiffies will be returned, or 0 if the timer expired in time
1700+ * delivered to the current task or the current task is explicitly woken
1701+ * up.
17131702 *
17141703 * The current task state is guaranteed to be TASK_RUNNING when this
17151704 * routine returns.
@@ -1718,7 +1707,9 @@ static void process_timeout(unsigned long __data) · 2 unmodified lines
17181707 * the CPU away without a bound on the timeout. In this case the return
17191708 * value will be %MAX_SCHEDULE_TIMEOUT.
17201709 *
1721− * In all cases the return value is guaranteed to be non-negative.
1710+ * Returns 0 when the timer has expired otherwise the remaining time in
1711+ * jiffies will be returned. In all cases the return value is guaranteed
1712+ * to be non-negative.
17221713 */
17231714 signed long __sched schedule_timeout(signed long timeout)
17241715 {
@@ -1910,16 +1901,6 @@ unsigned long msleep_interruptible(unsigned int msecs) · 185 unmodified lines
19101901
19111902 EXPORT_SYMBOL(msleep_interruptible);
19121903
1913−static void __sched do_usleep_range(unsigned long min, unsigned long max)
1914−{
1915− ktime_t kmin;
1916− u64 delta;
1917−
1918− kmin = ktime_set(0, min * NSEC_PER_USEC);
1919− delta = (u64)(max - min) * NSEC_PER_USEC;
1920− schedule_hrtimeout_range(&kmin, delta, HRTIMER_MODE_REL);
1921−}
1922−
19231904 /**
19241905 * usleep_range - Sleep for an approximate time
19251906 * @min: Minimum time in usecs to sleep
@@ -1933,7 +1914,14 @@ static void __sched do_usleep_range(unsigned long min, unsigned long max) · 7 unmodified lines
19331914 */
19341915 void __sched usleep_range(unsigned long min, unsigned long max)
19351916 {
1936− __set_current_state(TASK_UNINTERRUPTIBLE);
1937− do_usleep_range(min, max);
1917+ ktime_t exp = ktime_add_us(ktime_get(), min);
1918+ u64 delta = (u64)(max - min) * NSEC_PER_USEC;
1919+
1920+ for (;;) {
1921+ __set_current_state(TASK_UNINTERRUPTIBLE);
1922+ /* Do not return before the requested sleep time has elapsed */
1923+ if (!schedule_hrtimeout_range(&exp, delta, HRTIMER_MODE_ABS))
1924+ break;
1925+ }
19381926 }
19391927 EXPORT_SYMBOL(usleep_range);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t