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 ...
Showing the changes to kernel/time (8 of 61 files). Show all
Unified · Split
| @@ -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 | |
| 2 | 2 | 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 | |
| 4 | 10 | |
| 5 | 11 | obj-$(CONFIG_GENERIC_CLOCKEVENTS) += clockevents.o tick-common.o |
| 6 | 12 | ifeq ($(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST),y) |
| @@ -26,6 +26,9 @@ · 25 unmodified lines | ||
| 26 | 26 | #include <linux/workqueue.h> |
| 27 | 27 | #include <linux/freezer.h> |
| 28 | 28 | |
| 29 | +#define CREATE_TRACE_POINTS | |
| 30 | +#include <trace/events/alarmtimer.h> | |
| 31 | + | |
| 29 | 32 | /** |
| 30 | 33 | * struct alarm_base - Alarm timer bases |
| 31 | 34 | * @lock: Lock for syncrhonized access to the base |
| @@ -40,7 +43,9 @@ static struct alarm_base { · 8 unmodified lines | ||
| 40 | 43 | clockid_t base_clockid; |
| 41 | 44 | } alarm_bases[ALARM_NUMTYPE]; |
| 42 | 45 | |
| 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; | |
| 44 | 49 | static ktime_t freezer_delta; |
| 45 | 50 | static DEFINE_SPINLOCK(freezer_delta_lock); |
| 46 | 51 | |
| @@ -194,6 +199,7 @@ static enum hrtimer_restart alarmtimer_fired(struct hrtimer *timer) · 147 unmodified lines | ||
| 194 | 199 | } |
| 195 | 200 | spin_unlock_irqrestore(&base->lock, flags); |
| 196 | 201 | |
| 202 | + trace_alarmtimer_fired(alarm, base->gettime()); | |
| 197 | 203 | return ret; |
| 198 | 204 | |
| 199 | 205 | } |
| @@ -218,15 +224,16 @@ EXPORT_SYMBOL_GPL(alarm_expires_remaining); · 18 unmodified lines | ||
| 218 | 224 | */ |
| 219 | 225 | static int alarmtimer_suspend(struct device *dev) |
| 220 | 226 | { |
| 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; | |
| 224 | 229 | struct rtc_device *rtc; |
| 225 | − int i; | |
| 226 | − int ret; | |
| 230 | + unsigned long flags; | |
| 231 | + struct rtc_time tm; | |
| 227 | 232 | |
| 228 | 233 | spin_lock_irqsave(&freezer_delta_lock, flags); |
| 229 | 234 | min = freezer_delta; |
| 235 | + expires = freezer_expires; | |
| 236 | + type = freezer_alarmtype; | |
| 230 | 237 | freezer_delta = ktime_set(0, 0); |
| 231 | 238 | spin_unlock_irqrestore(&freezer_delta_lock, flags); |
| 232 | 239 | |
| @@ -247,8 +254,11 @@ static int alarmtimer_suspend(struct device *dev) · 14 unmodified lines | ||
| 247 | 254 | if (!next) |
| 248 | 255 | continue; |
| 249 | 256 | 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; | |
| 251 | 259 | min = delta; |
| 260 | + type = i; | |
| 261 | + } | |
| 252 | 262 | } |
| 253 | 263 | if (min.tv64 == 0) |
| 254 | 264 | return 0; |
| @@ -258,6 +268,8 @@ static int alarmtimer_suspend(struct device *dev) · 3 unmodified lines | ||
| 258 | 268 | return -EBUSY; |
| 259 | 269 | } |
| 260 | 270 | |
| 271 | + trace_alarmtimer_suspend(expires, type); | |
| 272 | + | |
| 261 | 273 | /* Setup an rtc timer to fire that far in the future */ |
| 262 | 274 | rtc_timer_cancel(rtc, &rtctimer); |
| 263 | 275 | rtc_read_time(rtc, &tm); |
| @@ -295,15 +307,32 @@ static int alarmtimer_resume(struct device *dev) · 31 unmodified lines | ||
| 295 | 307 | |
| 296 | 308 | static void alarmtimer_freezerset(ktime_t absexp, enum alarmtimer_type type) |
| 297 | 309 | { |
| 298 | − ktime_t delta; | |
| 310 | + struct alarm_base *base; | |
| 299 | 311 | 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 | + } | |
| 301 | 327 | |
| 302 | 328 | delta = ktime_sub(absexp, base->gettime()); |
| 303 | 329 | |
| 304 | 330 | 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)) { | |
| 306 | 332 | freezer_delta = delta; |
| 333 | + freezer_expires = absexp; | |
| 334 | + freezer_alarmtype = type; | |
| 335 | + } | |
| 307 | 336 | spin_unlock_irqrestore(&freezer_delta_lock, flags); |
| 308 | 337 | } |
| 309 | 338 | |
| @@ -342,6 +371,8 @@ void alarm_start(struct alarm *alarm, ktime_t start) · 32 unmodified lines | ||
| 342 | 371 | alarmtimer_enqueue(base, alarm); |
| 343 | 372 | hrtimer_start(&alarm->timer, alarm->node.expires, HRTIMER_MODE_ABS); |
| 344 | 373 | spin_unlock_irqrestore(&base->lock, flags); |
| 374 | + | |
| 375 | + trace_alarmtimer_start(alarm, base->gettime()); | |
| 345 | 376 | } |
| 346 | 377 | EXPORT_SYMBOL_GPL(alarm_start); |
| 347 | 378 | |
| @@ -390,6 +421,8 @@ int alarm_try_to_cancel(struct alarm *alarm) · 42 unmodified lines | ||
| 390 | 421 | if (ret >= 0) |
| 391 | 422 | alarmtimer_dequeue(base, alarm); |
| 392 | 423 | spin_unlock_irqrestore(&base->lock, flags); |
| 424 | + | |
| 425 | + trace_alarmtimer_cancel(alarm, base->gettime()); | |
| 393 | 426 | return ret; |
| 394 | 427 | } |
| 395 | 428 | EXPORT_SYMBOL_GPL(alarm_try_to_cancel); |
| @@ -846,8 +879,10 @@ static int __init alarmtimer_init(void) · 450 unmodified lines | ||
| 846 | 879 | |
| 847 | 880 | alarmtimer_rtc_timer_init(); |
| 848 | 881 | |
| 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 | + } | |
| 851 | 886 | |
| 852 | 887 | /* Initialize alarm bases */ |
| 853 | 888 | alarm_bases[ALARM_REALTIME].base_clockid = CLOCK_REALTIME; |
| @@ -1742,15 +1742,19 @@ schedule_hrtimeout_range_clock(ktime_t *expires, u64 delta, · 1741 unmodified lines | ||
| 1742 | 1742 | * You can set the task state as follows - |
| 1743 | 1743 | * |
| 1744 | 1744 | * %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()). | |
| 1746 | 1747 | * |
| 1747 | 1748 | * %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. | |
| 1749 | 1751 | * |
| 1750 | 1752 | * The current task state is guaranteed to be TASK_RUNNING when this |
| 1751 | 1753 | * routine returns. |
| 1752 | 1754 | * |
| 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. | |
| 1754 | 1758 | */ |
| 1755 | 1759 | int __sched schedule_hrtimeout_range(ktime_t *expires, u64 delta, |
| 1756 | 1760 | const enum hrtimer_mode mode) |
| @@ -1772,15 +1776,19 @@ EXPORT_SYMBOL_GPL(schedule_hrtimeout_range); · 15 unmodified lines | ||
| 1772 | 1776 | * You can set the task state as follows - |
| 1773 | 1777 | * |
| 1774 | 1778 | * %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()). | |
| 1776 | 1781 | * |
| 1777 | 1782 | * %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. | |
| 1779 | 1785 | * |
| 1780 | 1786 | * The current task state is guaranteed to be TASK_RUNNING when this |
| 1781 | 1787 | * routine returns. |
| 1782 | 1788 | * |
| 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. | |
| 1784 | 1792 | */ |
| 1785 | 1793 | int __sched schedule_hrtimeout(ktime_t *expires, |
| 1786 | 1794 | const enum hrtimer_mode mode) |
| @@ -238,6 +238,8 @@ again: · 237 unmodified lines | ||
| 238 | 238 | return 0; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | +#ifdef __ARCH_WANT_SYS_ALARM | |
| 242 | + | |
| 241 | 243 | /** |
| 242 | 244 | * alarm_setitimer - set alarm in seconds |
| 243 | 245 | * |
| @@ -250,7 +252,7 @@ again: · 6 unmodified lines | ||
| 250 | 252 | * On 32 bit machines the seconds value is limited to (INT_MAX/2) to avoid |
| 251 | 253 | * negative timeval settings which would cause immediate expiry. |
| 252 | 254 | */ |
| 253 | −unsigned int alarm_setitimer(unsigned int seconds) | |
| 255 | +static unsigned int alarm_setitimer(unsigned int seconds) | |
| 254 | 256 | { |
| 255 | 257 | struct itimerval it_new, it_old; |
| 256 | 258 | |
| @@ -275,6 +277,17 @@ unsigned int alarm_setitimer(unsigned int seconds) · 18 unmodified lines | ||
| 275 | 277 | return it_old.it_value.tv_sec; |
| 276 | 278 | } |
| 277 | 279 | |
| 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 | + | |
| 278 | 291 | SYSCALL_DEFINE3(setitimer, int, which, struct itimerval __user *, value, |
| 279 | 292 | struct itimerval __user *, ovalue) |
| 280 | 293 | { |
| @@ -9,7 +9,6 @@ · 8 unmodified lines | ||
| 9 | 9 | #include <asm/uaccess.h> |
| 10 | 10 | #include <linux/kernel_stat.h> |
| 11 | 11 | #include <trace/events/timer.h> |
| 12 | −#include <linux/random.h> | |
| 13 | 12 | #include <linux/tick.h> |
| 14 | 13 | #include <linux/workqueue.h> |
| 15 | 14 | |
| @@ -447,10 +446,7 @@ static void cleanup_timers(struct list_head *head) · 431 unmodified lines | ||
| 447 | 446 | */ |
| 448 | 447 | void posix_cpu_timers_exit(struct task_struct *tsk) |
| 449 | 448 | { |
| 450 | − add_device_randomness((const void*) &tsk->se.sum_exec_runtime, | |
| 451 | − sizeof(unsigned long long)); | |
| 452 | 449 | cleanup_timers(tsk->cpu_timers); |
| 453 | − | |
| 454 | 450 | } |
| 455 | 451 | void posix_cpu_timers_exit_group(struct task_struct *tsk) |
| 456 | 452 | { |
| @@ -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 | |
| @@ -258,10 +258,9 @@ static void tk_setup_internals(struct timekeeper *tk, struct clocksource *clock) · 257 unmodified lines | ||
| 258 | 258 | tk->cycle_interval = interval; |
| 259 | 259 | |
| 260 | 260 | /* Go back from cycles -> shifted ns */ |
| 261 | − tk->xtime_interval = (u64) interval * clock->mult; | |
| 261 | + tk->xtime_interval = interval * clock->mult; | |
| 262 | 262 | 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; | |
| 265 | 264 | |
| 266 | 265 | /* if changing clocks, convert xtime_nsec shift units */ |
| 267 | 266 | if (old_clock) { |
| @@ -299,10 +298,10 @@ u32 (*arch_gettimeoffset)(void) = default_arch_gettimeoffset; · 31 unmodified lines | ||
| 299 | 298 | static inline u32 arch_gettimeoffset(void) { return 0; } |
| 300 | 299 | #endif |
| 301 | 300 | |
| 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, | |
| 303 | 302 | cycle_t delta) |
| 304 | 303 | { |
| 305 | − s64 nsec; | |
| 304 | + u64 nsec; | |
| 306 | 305 | |
| 307 | 306 | nsec = delta * tkr->mult + tkr->xtime_nsec; |
| 308 | 307 | nsec >>= tkr->shift; |
| @@ -311,7 +310,7 @@ static inline s64 timekeeping_delta_to_ns(struct tk_read_base *tkr, · 2 unmodified lines | ||
| 311 | 310 | return nsec + arch_gettimeoffset(); |
| 312 | 311 | } |
| 313 | 312 | |
| 314 | −static inline s64 timekeeping_get_ns(struct tk_read_base *tkr) | |
| 313 | +static inline u64 timekeeping_get_ns(struct tk_read_base *tkr) | |
| 315 | 314 | { |
| 316 | 315 | cycle_t delta; |
| 317 | 316 | |
| @@ -319,8 +318,8 @@ static inline s64 timekeeping_get_ns(struct tk_read_base *tkr) · 1 unmodified line | ||
| 319 | 318 | return timekeeping_delta_to_ns(tkr, delta); |
| 320 | 319 | } |
| 321 | 320 | |
| 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) | |
| 324 | 323 | { |
| 325 | 324 | cycle_t delta; |
| 326 | 325 | |
| @@ -425,6 +424,35 @@ u64 ktime_get_raw_fast_ns(void) · 98 unmodified lines | ||
| 425 | 424 | } |
| 426 | 425 | EXPORT_SYMBOL_GPL(ktime_get_raw_fast_ns); |
| 427 | 426 | |
| 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 | + | |
| 428 | 456 | /* Suspend-time cycles value for halted fast timekeeper. */ |
| 429 | 457 | static cycle_t cycles_at_suspend; |
| 430 | 458 | |
| @@ -623,7 +651,7 @@ static void timekeeping_forward_now(struct timekeeper *tk) · 192 unmodified lines | ||
| 623 | 651 | { |
| 624 | 652 | struct clocksource *clock = tk->tkr_mono.clock; |
| 625 | 653 | cycle_t cycle_now, delta; |
| 626 | − s64 nsec; | |
| 654 | + u64 nsec; | |
| 627 | 655 | |
| 628 | 656 | cycle_now = tk->tkr_mono.read(clock); |
| 629 | 657 | 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 | ||
| 652 | 680 | { |
| 653 | 681 | struct timekeeper *tk = &tk_core.timekeeper; |
| 654 | 682 | unsigned long seq; |
| 655 | − s64 nsecs = 0; | |
| 683 | + u64 nsecs; | |
| 656 | 684 | |
| 657 | 685 | do { |
| 658 | 686 | seq = read_seqcount_begin(&tk_core.seq); |
| @@ -692,7 +720,7 @@ ktime_t ktime_get(void) · 33 unmodified lines | ||
| 692 | 720 | struct timekeeper *tk = &tk_core.timekeeper; |
| 693 | 721 | unsigned int seq; |
| 694 | 722 | ktime_t base; |
| 695 | − s64 nsecs; | |
| 723 | + u64 nsecs; | |
| 696 | 724 | |
| 697 | 725 | WARN_ON(timekeeping_suspended); |
| 698 | 726 | |
| @@ -735,7 +763,7 @@ ktime_t ktime_get_with_offset(enum tk_offsets offs) · 36 unmodified lines | ||
| 735 | 763 | struct timekeeper *tk = &tk_core.timekeeper; |
| 736 | 764 | unsigned int seq; |
| 737 | 765 | ktime_t base, *offset = offsets[offs]; |
| 738 | − s64 nsecs; | |
| 766 | + u64 nsecs; | |
| 739 | 767 | |
| 740 | 768 | WARN_ON(timekeeping_suspended); |
| 741 | 769 | |
| @@ -779,7 +807,7 @@ ktime_t ktime_get_raw(void) · 37 unmodified lines | ||
| 779 | 807 | struct timekeeper *tk = &tk_core.timekeeper; |
| 780 | 808 | unsigned int seq; |
| 781 | 809 | ktime_t base; |
| 782 | − s64 nsecs; | |
| 810 | + u64 nsecs; | |
| 783 | 811 | |
| 784 | 812 | do { |
| 785 | 813 | seq = read_seqcount_begin(&tk_core.seq); |
| @@ -804,8 +832,8 @@ void ktime_get_ts64(struct timespec64 *ts) · 18 unmodified lines | ||
| 804 | 832 | { |
| 805 | 833 | struct timekeeper *tk = &tk_core.timekeeper; |
| 806 | 834 | struct timespec64 tomono; |
| 807 | − s64 nsec; | |
| 808 | 835 | unsigned int seq; |
| 836 | + u64 nsec; | |
| 809 | 837 | |
| 810 | 838 | WARN_ON(timekeeping_suspended); |
| 811 | 839 | |
| @@ -893,8 +921,8 @@ void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot) · 81 unmodified lines | ||
| 893 | 921 | unsigned long seq; |
| 894 | 922 | ktime_t base_raw; |
| 895 | 923 | ktime_t base_real; |
| 896 | − s64 nsec_raw; | |
| 897 | − s64 nsec_real; | |
| 924 | + u64 nsec_raw; | |
| 925 | + u64 nsec_real; | |
| 898 | 926 | cycle_t now; |
| 899 | 927 | |
| 900 | 928 | WARN_ON_ONCE(timekeeping_suspended); |
| @@ -1052,7 +1080,7 @@ int get_device_system_crosststamp(int (*get_time_fn) · 151 unmodified lines | ||
| 1052 | 1080 | cycle_t cycles, now, interval_start; |
| 1053 | 1081 | unsigned int clock_was_set_seq = 0; |
| 1054 | 1082 | ktime_t base_real, base_raw; |
| 1055 | − s64 nsec_real, nsec_raw; | |
| 1083 | + u64 nsec_real, nsec_raw; | |
| 1056 | 1084 | u8 cs_was_changed_seq; |
| 1057 | 1085 | unsigned long seq; |
| 1058 | 1086 | bool do_interp; |
| @@ -1365,7 +1393,7 @@ void getrawmonotonic64(struct timespec64 *ts) · 306 unmodified lines | ||
| 1365 | 1393 | struct timekeeper *tk = &tk_core.timekeeper; |
| 1366 | 1394 | struct timespec64 ts64; |
| 1367 | 1395 | unsigned long seq; |
| 1368 | − s64 nsecs; | |
| 1396 | + u64 nsecs; | |
| 1369 | 1397 | |
| 1370 | 1398 | do { |
| 1371 | 1399 | seq = read_seqcount_begin(&tk_core.seq); |
| @@ -1616,7 +1644,7 @@ void timekeeping_resume(void) · 244 unmodified lines | ||
| 1616 | 1644 | struct clocksource *clock = tk->tkr_mono.clock; |
| 1617 | 1645 | unsigned long flags; |
| 1618 | 1646 | struct timespec64 ts_new, ts_delta; |
| 1619 | − cycle_t cycle_now, cycle_delta; | |
| 1647 | + cycle_t cycle_now; | |
| 1620 | 1648 | |
| 1621 | 1649 | sleeptime_injected = false; |
| 1622 | 1650 | read_persistent_clock64(&ts_new); |
| @@ -1642,27 +1670,11 @@ void timekeeping_resume(void) · 19 unmodified lines | ||
| 1642 | 1670 | cycle_now = tk->tkr_mono.read(clock); |
| 1643 | 1671 | if ((clock->flags & CLOCK_SOURCE_SUSPEND_NONSTOP) && |
| 1644 | 1672 | 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; | |
| 1665 | 1674 | |
| 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); | |
| 1666 | 1678 | ts_delta = ns_to_timespec64(nsec); |
| 1667 | 1679 | sleeptime_injected = true; |
| 1668 | 1680 | } else if (timespec64_compare(&ts_new, &timekeeping_suspend_time) > 0) { |
| @@ -1615,7 +1615,8 @@ void update_process_times(int user_tick) · 1614 unmodified lines | ||
| 1615 | 1615 | irq_work_tick(); |
| 1616 | 1616 | #endif |
| 1617 | 1617 | scheduler_tick(); |
| 1618 | − run_posix_cpu_timers(p); | |
| 1618 | + if (IS_ENABLED(CONFIG_POSIX_TIMERS)) | |
| 1619 | + run_posix_cpu_timers(p); | |
| 1619 | 1620 | } |
| 1620 | 1621 | |
| 1621 | 1622 | /** |
| @@ -1676,19 +1677,6 @@ void run_local_timers(void) · 54 unmodified lines | ||
| 1676 | 1677 | raise_softirq(TIMER_SOFTIRQ); |
| 1677 | 1678 | } |
| 1678 | 1679 | |
| 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 | − | |
| 1692 | 1680 | static void process_timeout(unsigned long __data) |
| 1693 | 1681 | { |
| 1694 | 1682 | wake_up_process((struct task_struct *)__data); |
| @@ -1705,11 +1693,12 @@ static void process_timeout(unsigned long __data) · 10 unmodified lines | ||
| 1705 | 1693 | * You can set the task state as follows - |
| 1706 | 1694 | * |
| 1707 | 1695 | * %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())". | |
| 1709 | 1698 | * |
| 1710 | 1699 | * %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. | |
| 1713 | 1702 | * |
| 1714 | 1703 | * The current task state is guaranteed to be TASK_RUNNING when this |
| 1715 | 1704 | * routine returns. |
| @@ -1718,7 +1707,9 @@ static void process_timeout(unsigned long __data) · 2 unmodified lines | ||
| 1718 | 1707 | * the CPU away without a bound on the timeout. In this case the return |
| 1719 | 1708 | * value will be %MAX_SCHEDULE_TIMEOUT. |
| 1720 | 1709 | * |
| 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. | |
| 1722 | 1713 | */ |
| 1723 | 1714 | signed long __sched schedule_timeout(signed long timeout) |
| 1724 | 1715 | { |
| @@ -1910,16 +1901,6 @@ unsigned long msleep_interruptible(unsigned int msecs) · 185 unmodified lines | ||
| 1910 | 1901 | |
| 1911 | 1902 | EXPORT_SYMBOL(msleep_interruptible); |
| 1912 | 1903 | |
| 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 | − | |
| 1923 | 1904 | /** |
| 1924 | 1905 | * usleep_range - Sleep for an approximate time |
| 1925 | 1906 | * @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 | ||
| 1933 | 1914 | */ |
| 1934 | 1915 | void __sched usleep_range(unsigned long min, unsigned long max) |
| 1935 | 1916 | { |
| 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 | + } | |
| 1938 | 1926 | } |
| 1939 | 1927 | EXPORT_SYMBOL(usleep_range); |