Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

* 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (62 commits)
posix-clocks: Check write permissions in posix syscalls
hrtimer: Remove empty hrtimer_init_hres_timer()
hrtimer: Update hrtimer->state documentation
hrtimer: Update base[CLOCK_BOOTTIME].offset correctly
timers: Export CLOCK_BOOTTIME via the posix timers interface
timers: Add CLOCK_BOOTTIME hrtimer base
time: Extend get_xtime_and_monotonic_offset() to also return sleep
time: Introduce get_monotonic_boottime and ktime_get_boottime
hrtimers: extend hrtimer base code to handle more then 2 clockids
ntp: Remove redundant and incorrect parameter check
mn10300: Switch do_timer() to xtimer_update()
posix clocks: Introduce dynamic clocks
posix-timers: Cleanup namespace
posix-timers: Add support for fd based clocks
x86: Add clock_adjtime for x86
posix-timers: Introduce a syscall for clock tuning.
time: Splitout compat timex accessors
ntp: Add ADJ_SETOFFSET mode bit
time: Introduce timekeeping_inject_offset
posix-timer: Update comment
...

Fix up new system-call-related conflicts in
arch/x86/ia32/ia32entry.S
arch/x86/include/asm/unistd_32.h
arch/x86/include/asm/unistd_64.h
arch/x86/kernel/syscall_table_32.S
(name_to_handle_at()/open_by_handle_at() vs clock_adjtime()), and some
due to movement of get_jiffies_64() in:
kernel/time.c

+1276 -508
+2 -6
arch/alpha/kernel/time.c
··· 159 159 160 160 /* 161 161 * timer_interrupt() needs to keep up the real-time clock, 162 - * as well as call the "do_timer()" routine every clocktick 162 + * as well as call the "xtime_update()" routine every clocktick 163 163 */ 164 164 irqreturn_t timer_interrupt(int irq, void *dev) 165 165 { ··· 171 171 /* Not SMP, do kernel PC profiling here. */ 172 172 profile_tick(CPU_PROFILING); 173 173 #endif 174 - 175 - write_seqlock(&xtime_lock); 176 174 177 175 /* 178 176 * Calculate how many ticks have passed since the last update, ··· 185 187 nticks = delta >> FIX_SHIFT; 186 188 187 189 if (nticks) 188 - do_timer(nticks); 189 - 190 - write_sequnlock(&xtime_lock); 190 + xtime_update(nticks); 191 191 192 192 if (test_irq_work_pending()) { 193 193 clear_irq_work_pending();
+1 -3
arch/arm/kernel/time.c
··· 107 107 { 108 108 profile_tick(CPU_PROFILING); 109 109 do_leds(); 110 - write_seqlock(&xtime_lock); 111 - do_timer(1); 112 - write_sequnlock(&xtime_lock); 110 + xtime_update(1); 113 111 #ifndef CONFIG_SMP 114 112 update_process_times(user_mode(get_irq_regs())); 115 113 #endif
+1 -1
arch/arm/mach-clps711x/include/mach/time.h
··· 30 30 { 31 31 struct pt_regs *regs = get_irq_regs(); 32 32 do_leds(); 33 - do_timer(1); 33 + xtime_update(1); 34 34 #ifndef CONFIG_SMP 35 35 update_process_times(user_mode(regs)); 36 36 #endif
+2 -4
arch/blackfin/kernel/time.c
··· 114 114 115 115 /* 116 116 * timer_interrupt() needs to keep up the real-time clock, 117 - * as well as call the "do_timer()" routine every clocktick 117 + * as well as call the "xtime_update()" routine every clocktick 118 118 */ 119 119 #ifdef CONFIG_CORE_TIMER_IRQ_L1 120 120 __attribute__((l1_text)) 121 121 #endif 122 122 irqreturn_t timer_interrupt(int irq, void *dummy) 123 123 { 124 - write_seqlock(&xtime_lock); 125 - do_timer(1); 126 - write_sequnlock(&xtime_lock); 124 + xtime_update(1); 127 125 128 126 #ifdef CONFIG_IPIPE 129 127 update_root_process_times(get_irq_regs());
+2 -2
arch/cris/arch-v10/kernel/time.c
··· 140 140 141 141 /* 142 142 * timer_interrupt() needs to keep up the real-time clock, 143 - * as well as call the "do_timer()" routine every clocktick 143 + * as well as call the "xtime_update()" routine every clocktick 144 144 */ 145 145 146 146 //static unsigned short myjiff; /* used by our debug routine print_timestamp */ ··· 176 176 177 177 /* call the real timer interrupt handler */ 178 178 179 - do_timer(1); 179 + xtime_update(1); 180 180 181 181 cris_do_profile(regs); /* Save profiling information */ 182 182 return IRQ_HANDLED;
+2 -4
arch/cris/arch-v32/kernel/time.c
··· 183 183 184 184 /* 185 185 * timer_interrupt() needs to keep up the real-time clock, 186 - * as well as call the "do_timer()" routine every clocktick. 186 + * as well as call the "xtime_update()" routine every clocktick. 187 187 */ 188 188 extern void cris_do_profile(struct pt_regs *regs); 189 189 ··· 216 216 return IRQ_HANDLED; 217 217 218 218 /* Call the real timer interrupt handler */ 219 - write_seqlock(&xtime_lock); 220 - do_timer(1); 221 - write_sequnlock(&xtime_lock); 219 + xtime_update(1); 222 220 return IRQ_HANDLED; 223 221 } 224 222
+2 -12
arch/frv/kernel/time.c
··· 50 50 51 51 /* 52 52 * timer_interrupt() needs to keep up the real-time clock, 53 - * as well as call the "do_timer()" routine every clocktick 53 + * as well as call the "xtime_update()" routine every clocktick 54 54 */ 55 55 static irqreturn_t timer_interrupt(int irq, void *dummy) 56 56 { 57 57 profile_tick(CPU_PROFILING); 58 - /* 59 - * Here we are in the timer irq handler. We just have irqs locally 60 - * disabled but we don't know if the timer_bh is running on the other 61 - * CPU. We need to avoid to SMP race with it. NOTE: we don't need 62 - * the irq version of write_lock because as just said we have irq 63 - * locally disabled. -arca 64 - */ 65 - write_seqlock(&xtime_lock); 66 58 67 - do_timer(1); 59 + xtime_update(1); 68 60 69 61 #ifdef CONFIG_HEARTBEAT 70 62 static unsigned short n; 71 63 n++; 72 64 __set_LEDS(n); 73 65 #endif /* CONFIG_HEARTBEAT */ 74 - 75 - write_sequnlock(&xtime_lock); 76 66 77 67 update_process_times(user_mode(get_irq_regs())); 78 68
+1 -3
arch/h8300/kernel/time.c
··· 35 35 { 36 36 if (current->pid) 37 37 profile_tick(CPU_PROFILING); 38 - write_seqlock(&xtime_lock); 39 - do_timer(1); 40 - write_sequnlock(&xtime_lock); 38 + xtime_update(1); 41 39 update_process_times(user_mode(get_irq_regs())); 42 40 } 43 41
+1 -1
arch/h8300/kernel/timer/timer8.c
··· 61 61 62 62 /* 63 63 * timer_interrupt() needs to keep up the real-time clock, 64 - * as well as call the "do_timer()" routine every clocktick 64 + * as well as call the "xtime_update()" routine every clocktick 65 65 */ 66 66 67 67 static irqreturn_t timer_interrupt(int irq, void *dev_id)
+5 -14
arch/ia64/kernel/time.c
··· 190 190 191 191 new_itm += local_cpu_data->itm_delta; 192 192 193 - if (smp_processor_id() == time_keeper_id) { 194 - /* 195 - * Here we are in the timer irq handler. We have irqs locally 196 - * disabled, but we don't know if the timer_bh is running on 197 - * another CPU. We need to avoid to SMP race by acquiring the 198 - * xtime_lock. 199 - */ 200 - write_seqlock(&xtime_lock); 201 - do_timer(1); 202 - local_cpu_data->itm_next = new_itm; 203 - write_sequnlock(&xtime_lock); 204 - } else 205 - local_cpu_data->itm_next = new_itm; 193 + if (smp_processor_id() == time_keeper_id) 194 + xtime_update(1); 195 + 196 + local_cpu_data->itm_next = new_itm; 206 197 207 198 if (time_after(new_itm, ia64_get_itc())) 208 199 break; ··· 213 222 * comfort, we increase the safety margin by 214 223 * intentionally dropping the next tick(s). We do NOT 215 224 * update itm.next because that would force us to call 216 - * do_timer() which in turn would let our clock run 225 + * xtime_update() which in turn would let our clock run 217 226 * too fast (with the potentially devastating effect 218 227 * of losing monotony of time). 219 228 */
+5 -8
arch/ia64/xen/time.c
··· 139 139 run_posix_cpu_timers(p); 140 140 delta_itm += local_cpu_data->itm_delta * (stolen + blocked); 141 141 142 - if (cpu == time_keeper_id) { 143 - write_seqlock(&xtime_lock); 144 - do_timer(stolen + blocked); 145 - local_cpu_data->itm_next = delta_itm + new_itm; 146 - write_sequnlock(&xtime_lock); 147 - } else { 148 - local_cpu_data->itm_next = delta_itm + new_itm; 149 - } 142 + if (cpu == time_keeper_id) 143 + xtime_update(stolen + blocked); 144 + 145 + local_cpu_data->itm_next = delta_itm + new_itm; 146 + 150 147 per_cpu(xen_stolen_time, cpu) += NS_PER_TICK * stolen; 151 148 per_cpu(xen_blocked_time, cpu) += NS_PER_TICK * blocked; 152 149 }
+2 -3
arch/m32r/kernel/time.c
··· 107 107 108 108 /* 109 109 * timer_interrupt() needs to keep up the real-time clock, 110 - * as well as call the "do_timer()" routine every clocktick 110 + * as well as call the "xtime_update()" routine every clocktick 111 111 */ 112 112 static irqreturn_t timer_interrupt(int irq, void *dev_id) 113 113 { 114 114 #ifndef CONFIG_SMP 115 115 profile_tick(CPU_PROFILING); 116 116 #endif 117 - /* XXX FIXME. Uh, the xtime_lock should be held here, no? */ 118 - do_timer(1); 117 + xtime_update(1); 119 118 120 119 #ifndef CONFIG_SMP 121 120 update_process_times(user_mode(get_irq_regs()));
+2 -2
arch/m68k/bvme6000/config.c
··· 45 45 extern void bvme6000_reset (void); 46 46 void bvme6000_set_vectors (void); 47 47 48 - /* Save tick handler routine pointer, will point to do_timer() in 49 - * kernel/sched.c, called via bvme6000_process_int() */ 48 + /* Save tick handler routine pointer, will point to xtime_update() in 49 + * kernel/timer/timekeeping.c, called via bvme6000_process_int() */ 50 50 51 51 static irq_handler_t tick_handler; 52 52
+2 -2
arch/m68k/kernel/time.c
··· 37 37 38 38 /* 39 39 * timer_interrupt() needs to keep up the real-time clock, 40 - * as well as call the "do_timer()" routine every clocktick 40 + * as well as call the "xtime_update()" routine every clocktick 41 41 */ 42 42 static irqreturn_t timer_interrupt(int irq, void *dummy) 43 43 { 44 - do_timer(1); 44 + xtime_update(1); 45 45 update_process_times(user_mode(get_irq_regs())); 46 46 profile_tick(CPU_PROFILING); 47 47
+2 -2
arch/m68k/mvme147/config.c
··· 46 46 47 47 static int bcd2int (unsigned char b); 48 48 49 - /* Save tick handler routine pointer, will point to do_timer() in 50 - * kernel/sched.c, called via mvme147_process_int() */ 49 + /* Save tick handler routine pointer, will point to xtime_update() in 50 + * kernel/time/timekeeping.c, called via mvme147_process_int() */ 51 51 52 52 irq_handler_t tick_handler; 53 53
+2 -2
arch/m68k/mvme16x/config.c
··· 51 51 52 52 int bcd2int (unsigned char b); 53 53 54 - /* Save tick handler routine pointer, will point to do_timer() in 55 - * kernel/sched.c, called via mvme16x_process_int() */ 54 + /* Save tick handler routine pointer, will point to xtime_update() in 55 + * kernel/time/timekeeping.c, called via mvme16x_process_int() */ 56 56 57 57 static irq_handler_t tick_handler; 58 58
+1 -1
arch/m68k/sun3/sun3ints.c
··· 66 66 #ifdef CONFIG_SUN3 67 67 intersil_clear(); 68 68 #endif 69 - do_timer(1); 69 + xtime_update(1); 70 70 update_process_times(user_mode(get_irq_regs())); 71 71 if (!(kstat_cpu(0).irqs[irq] % 20)) 72 72 sun3_leds(led_pattern[(kstat_cpu(0).irqs[irq] % 160) / 20]);
+2 -6
arch/m68knommu/kernel/time.c
··· 36 36 #ifndef CONFIG_GENERIC_CLOCKEVENTS 37 37 /* 38 38 * timer_interrupt() needs to keep up the real-time clock, 39 - * as well as call the "do_timer()" routine every clocktick 39 + * as well as call the "xtime_update()" routine every clocktick 40 40 */ 41 41 irqreturn_t arch_timer_interrupt(int irq, void *dummy) 42 42 { ··· 44 44 if (current->pid) 45 45 profile_tick(CPU_PROFILING); 46 46 47 - write_seqlock(&xtime_lock); 48 - 49 - do_timer(1); 50 - 51 - write_sequnlock(&xtime_lock); 47 + xtime_update(1); 52 48 53 49 update_process_times(user_mode(get_irq_regs())); 54 50
+1 -5
arch/mn10300/kernel/time.c
··· 104 104 unsigned tsc, elapse; 105 105 irqreturn_t ret; 106 106 107 - write_seqlock(&xtime_lock); 108 - 109 107 while (tsc = get_cycles(), 110 108 elapse = tsc - mn10300_last_tsc, /* time elapsed since last 111 109 * tick */ ··· 112 114 mn10300_last_tsc += MN10300_TSC_PER_HZ; 113 115 114 116 /* advance the kernel's time tracking system */ 115 - do_timer(1); 117 + xtime_update(1); 116 118 } 117 - 118 - write_sequnlock(&xtime_lock); 119 119 120 120 ret = local_timer_interrupt(); 121 121 #ifdef CONFIG_SMP
+2 -5
arch/parisc/kernel/time.c
··· 162 162 update_process_times(user_mode(get_irq_regs())); 163 163 } 164 164 165 - if (cpu == 0) { 166 - write_seqlock(&xtime_lock); 167 - do_timer(ticks_elapsed); 168 - write_sequnlock(&xtime_lock); 169 - } 165 + if (cpu == 0) 166 + xtime_update(ticks_elapsed); 170 167 171 168 return IRQ_HANDLED; 172 169 }
+1 -3
arch/sparc/kernel/pcic.c
··· 700 700 701 701 static irqreturn_t pcic_timer_handler (int irq, void *h) 702 702 { 703 - write_seqlock(&xtime_lock); /* Dummy, to show that we remember */ 704 703 pcic_clear_clock_irq(); 705 - do_timer(1); 706 - write_sequnlock(&xtime_lock); 704 + xtime_update(1); 707 705 #ifndef CONFIG_SMP 708 706 update_process_times(user_mode(get_irq_regs())); 709 707 #endif
+2 -7
arch/sparc/kernel/time_32.c
··· 85 85 86 86 /* 87 87 * timer_interrupt() needs to keep up the real-time clock, 88 - * as well as call the "do_timer()" routine every clocktick 88 + * as well as call the "xtime_update()" routine every clocktick 89 89 */ 90 90 91 91 #define TICK_SIZE (tick_nsec / 1000) ··· 96 96 profile_tick(CPU_PROFILING); 97 97 #endif 98 98 99 - /* Protect counter clear so that do_gettimeoffset works */ 100 - write_seqlock(&xtime_lock); 101 - 102 99 clear_clock_irq(); 103 100 104 - do_timer(1); 105 - 106 - write_sequnlock(&xtime_lock); 101 + xtime_update(1); 107 102 108 103 #ifndef CONFIG_SMP 109 104 update_process_times(user_mode(get_irq_regs()));
+1
arch/x86/ia32/ia32entry.S
··· 855 855 .quad sys_prlimit64 /* 340 */ 856 856 .quad sys_name_to_handle_at 857 857 .quad compat_sys_open_by_handle_at 858 + .quad compat_sys_clock_adjtime 858 859 ia32_syscall_end:
+2 -1
arch/x86/include/asm/unistd_32.h
··· 348 348 #define __NR_prlimit64 340 349 349 #define __NR_name_to_handle_at 341 350 350 #define __NR_open_by_handle_at 342 351 + #define __NR_clock_adjtime 343 351 352 352 353 #ifdef __KERNEL__ 353 354 354 - #define NR_syscalls 343 355 + #define NR_syscalls 344 355 356 356 357 #define __ARCH_WANT_IPC_PARSE_VERSION 357 358 #define __ARCH_WANT_OLD_READDIR
+2
arch/x86/include/asm/unistd_64.h
··· 673 673 __SYSCALL(__NR_name_to_handle_at, sys_name_to_handle_at) 674 674 #define __NR_open_by_handle_at 304 675 675 __SYSCALL(__NR_open_by_handle_at, sys_open_by_handle_at) 676 + #define __NR_clock_adjtime 305 677 + __SYSCALL(__NR_clock_adjtime, sys_clock_adjtime) 676 678 677 679 #ifndef __NO_STUBS 678 680 #define __ARCH_WANT_OLD_READDIR
+1
arch/x86/kernel/syscall_table_32.S
··· 342 342 .long sys_prlimit64 /* 340 */ 343 343 .long sys_name_to_handle_at 344 344 .long sys_open_by_handle_at 345 + .long sys_clock_adjtime
+1 -5
arch/xtensa/kernel/time.c
··· 96 96 update_process_times(user_mode(get_irq_regs())); 97 97 #endif 98 98 99 - write_seqlock(&xtime_lock); 100 - 101 - do_timer(1); /* Linux handler in kernel/timer.c */ 99 + xtime_update(1); /* Linux handler in kernel/time/timekeeping */ 102 100 103 101 /* Note that writing CCOMPARE clears the interrupt. */ 104 102 105 103 next += CCOUNT_PER_JIFFY; 106 104 set_linux_timer(next); 107 - 108 - write_sequnlock(&xtime_lock); 109 105 } 110 106 111 107 /* Allow platform to do something useful (Wdog). */
+19 -11
drivers/char/mmtimer.c
··· 53 53 54 54 #define RTC_BITS 55 /* 55 bits for this implementation */ 55 55 56 + static struct k_clock sgi_clock; 57 + 56 58 extern unsigned long sn_rtc_cycles_per_second; 57 59 58 60 #define RTC_COUNTER_ADDR ((long *)LOCAL_MMR_ADDR(SH_RTC)) ··· 489 487 return 0; 490 488 }; 491 489 492 - static int sgi_clock_set(clockid_t clockid, struct timespec *tp) 490 + static int sgi_clock_set(const clockid_t clockid, const struct timespec *tp) 493 491 { 494 492 495 493 u64 nsec; ··· 765 763 return err; 766 764 } 767 765 766 + static int sgi_clock_getres(const clockid_t which_clock, struct timespec *tp) 767 + { 768 + tp->tv_sec = 0; 769 + tp->tv_nsec = sgi_clock_period; 770 + return 0; 771 + } 772 + 768 773 static struct k_clock sgi_clock = { 769 - .res = 0, 770 - .clock_set = sgi_clock_set, 771 - .clock_get = sgi_clock_get, 772 - .timer_create = sgi_timer_create, 773 - .nsleep = do_posix_clock_nonanosleep, 774 - .timer_set = sgi_timer_set, 775 - .timer_del = sgi_timer_del, 776 - .timer_get = sgi_timer_get 774 + .clock_set = sgi_clock_set, 775 + .clock_get = sgi_clock_get, 776 + .clock_getres = sgi_clock_getres, 777 + .timer_create = sgi_timer_create, 778 + .timer_set = sgi_timer_set, 779 + .timer_del = sgi_timer_del, 780 + .timer_get = sgi_timer_get 777 781 }; 778 782 779 783 /** ··· 839 831 (unsigned long) node); 840 832 } 841 833 842 - sgi_clock_period = sgi_clock.res = NSEC_PER_SEC / sn_rtc_cycles_per_second; 843 - register_posix_clock(CLOCK_SGI_CYCLE, &sgi_clock); 834 + sgi_clock_period = NSEC_PER_SEC / sn_rtc_cycles_per_second; 835 + posix_timers_register_clock(CLOCK_SGI_CYCLE, &sgi_clock); 844 836 845 837 printk(KERN_INFO "%s: v%s, %ld MHz\n", MMTIMER_DESC, MMTIMER_VERSION, 846 838 sn_rtc_cycles_per_second/(unsigned long)1E6);
+18 -6
include/linux/hrtimer.h
··· 54 54 * 0x00 inactive 55 55 * 0x01 enqueued into rbtree 56 56 * 0x02 callback function running 57 + * 0x04 timer is migrated to another cpu 57 58 * 58 59 * Special cases: 59 60 * 0x03 callback function running and enqueued 60 61 * (was requeued on another CPU) 61 - * 0x09 timer was migrated on CPU hotunplug 62 + * 0x05 timer was migrated on CPU hotunplug 63 + * 62 64 * The "callback function running and enqueued" status is only possible on 63 65 * SMP. It happens for example when a posix timer expired and the callback 64 66 * queued a signal. Between dropping the lock which protects the posix timer ··· 69 67 * as otherwise the timer could be removed before the softirq code finishes the 70 68 * the handling of the timer. 71 69 * 72 - * The HRTIMER_STATE_ENQUEUED bit is always or'ed to the current state to 73 - * preserve the HRTIMER_STATE_CALLBACK bit in the above scenario. 70 + * The HRTIMER_STATE_ENQUEUED bit is always or'ed to the current state 71 + * to preserve the HRTIMER_STATE_CALLBACK in the above scenario. This 72 + * also affects HRTIMER_STATE_MIGRATE where the preservation is not 73 + * necessary. HRTIMER_STATE_MIGRATE is cleared after the timer is 74 + * enqueued on the new cpu. 74 75 * 75 76 * All state transitions are protected by cpu_base->lock. 76 77 */ ··· 153 148 #endif 154 149 }; 155 150 156 - #define HRTIMER_MAX_CLOCK_BASES 2 151 + enum hrtimer_base_type { 152 + HRTIMER_BASE_REALTIME, 153 + HRTIMER_BASE_MONOTONIC, 154 + HRTIMER_BASE_BOOTTIME, 155 + HRTIMER_MAX_CLOCK_BASES, 156 + }; 157 157 158 158 /* 159 159 * struct hrtimer_cpu_base - the per cpu clock bases ··· 318 308 319 309 extern ktime_t ktime_get(void); 320 310 extern ktime_t ktime_get_real(void); 311 + extern ktime_t ktime_get_boottime(void); 321 312 322 313 323 314 DECLARE_PER_CPU(struct tick_device, tick_cpu_device); ··· 381 370 extern ktime_t hrtimer_get_next_event(void); 382 371 383 372 /* 384 - * A timer is active, when it is enqueued into the rbtree or the callback 385 - * function is running. 373 + * A timer is active, when it is enqueued into the rbtree or the 374 + * callback function is running or it's in the state of being migrated 375 + * to another cpu. 386 376 */ 387 377 static inline int hrtimer_active(const struct hrtimer *timer) 388 378 {
+150
include/linux/posix-clock.h
··· 1 + /* 2 + * posix-clock.h - support for dynamic clock devices 3 + * 4 + * Copyright (C) 2010 OMICRON electronics GmbH 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + * You should have received a copy of the GNU General Public License 17 + * along with this program; if not, write to the Free Software 18 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 + */ 20 + #ifndef _LINUX_POSIX_CLOCK_H_ 21 + #define _LINUX_POSIX_CLOCK_H_ 22 + 23 + #include <linux/cdev.h> 24 + #include <linux/fs.h> 25 + #include <linux/poll.h> 26 + #include <linux/posix-timers.h> 27 + 28 + struct posix_clock; 29 + 30 + /** 31 + * struct posix_clock_operations - functional interface to the clock 32 + * 33 + * Every posix clock is represented by a character device. Drivers may 34 + * optionally offer extended capabilities by implementing the 35 + * character device methods. The character device file operations are 36 + * first handled by the clock device layer, then passed on to the 37 + * driver by calling these functions. 38 + * 39 + * @owner: The clock driver should set to THIS_MODULE 40 + * @clock_adjtime: Adjust the clock 41 + * @clock_gettime: Read the current time 42 + * @clock_getres: Get the clock resolution 43 + * @clock_settime: Set the current time value 44 + * @timer_create: Create a new timer 45 + * @timer_delete: Remove a previously created timer 46 + * @timer_gettime: Get remaining time and interval of a timer 47 + * @timer_setttime: Set a timer's initial expiration and interval 48 + * @fasync: Optional character device fasync method 49 + * @mmap: Optional character device mmap method 50 + * @open: Optional character device open method 51 + * @release: Optional character device release method 52 + * @ioctl: Optional character device ioctl method 53 + * @read: Optional character device read method 54 + * @poll: Optional character device poll method 55 + */ 56 + struct posix_clock_operations { 57 + struct module *owner; 58 + 59 + int (*clock_adjtime)(struct posix_clock *pc, struct timex *tx); 60 + 61 + int (*clock_gettime)(struct posix_clock *pc, struct timespec *ts); 62 + 63 + int (*clock_getres) (struct posix_clock *pc, struct timespec *ts); 64 + 65 + int (*clock_settime)(struct posix_clock *pc, 66 + const struct timespec *ts); 67 + 68 + int (*timer_create) (struct posix_clock *pc, struct k_itimer *kit); 69 + 70 + int (*timer_delete) (struct posix_clock *pc, struct k_itimer *kit); 71 + 72 + void (*timer_gettime)(struct posix_clock *pc, 73 + struct k_itimer *kit, struct itimerspec *tsp); 74 + 75 + int (*timer_settime)(struct posix_clock *pc, 76 + struct k_itimer *kit, int flags, 77 + struct itimerspec *tsp, struct itimerspec *old); 78 + /* 79 + * Optional character device methods: 80 + */ 81 + int (*fasync) (struct posix_clock *pc, 82 + int fd, struct file *file, int on); 83 + 84 + long (*ioctl) (struct posix_clock *pc, 85 + unsigned int cmd, unsigned long arg); 86 + 87 + int (*mmap) (struct posix_clock *pc, 88 + struct vm_area_struct *vma); 89 + 90 + int (*open) (struct posix_clock *pc, fmode_t f_mode); 91 + 92 + uint (*poll) (struct posix_clock *pc, 93 + struct file *file, poll_table *wait); 94 + 95 + int (*release) (struct posix_clock *pc); 96 + 97 + ssize_t (*read) (struct posix_clock *pc, 98 + uint flags, char __user *buf, size_t cnt); 99 + }; 100 + 101 + /** 102 + * struct posix_clock - represents a dynamic posix clock 103 + * 104 + * @ops: Functional interface to the clock 105 + * @cdev: Character device instance for this clock 106 + * @kref: Reference count. 107 + * @mutex: Protects the 'zombie' field from concurrent access. 108 + * @zombie: If 'zombie' is true, then the hardware has disappeared. 109 + * @release: A function to free the structure when the reference count reaches 110 + * zero. May be NULL if structure is statically allocated. 111 + * 112 + * Drivers should embed their struct posix_clock within a private 113 + * structure, obtaining a reference to it during callbacks using 114 + * container_of(). 115 + */ 116 + struct posix_clock { 117 + struct posix_clock_operations ops; 118 + struct cdev cdev; 119 + struct kref kref; 120 + struct mutex mutex; 121 + bool zombie; 122 + void (*release)(struct posix_clock *clk); 123 + }; 124 + 125 + /** 126 + * posix_clock_register() - register a new clock 127 + * @clk: Pointer to the clock. Caller must provide 'ops' and 'release' 128 + * @devid: Allocated device id 129 + * 130 + * A clock driver calls this function to register itself with the 131 + * clock device subsystem. If 'clk' points to dynamically allocated 132 + * memory, then the caller must provide a 'release' function to free 133 + * that memory. 134 + * 135 + * Returns zero on success, non-zero otherwise. 136 + */ 137 + int posix_clock_register(struct posix_clock *clk, dev_t devid); 138 + 139 + /** 140 + * posix_clock_unregister() - unregister a clock 141 + * @clk: Clock instance previously registered via posix_clock_register() 142 + * 143 + * A clock driver calls this function to remove itself from the clock 144 + * device subsystem. The posix_clock itself will remain (in an 145 + * inactive state) until its reference count drops to zero, at which 146 + * point it will be deallocated with its 'release' method. 147 + */ 148 + void posix_clock_unregister(struct posix_clock *clk); 149 + 150 + #endif
+24 -20
include/linux/posix-timers.h
··· 4 4 #include <linux/spinlock.h> 5 5 #include <linux/list.h> 6 6 #include <linux/sched.h> 7 + #include <linux/timex.h> 7 8 8 9 union cpu_time_count { 9 10 cputime_t cpu; ··· 18 17 int firing; 19 18 }; 20 19 20 + /* 21 + * Bit fields within a clockid: 22 + * 23 + * The most significant 29 bits hold either a pid or a file descriptor. 24 + * 25 + * Bit 2 indicates whether a cpu clock refers to a thread or a process. 26 + * 27 + * Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3. 28 + * 29 + * A clockid is invalid if bits 2, 1, and 0 are all set. 30 + */ 21 31 #define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3)) 22 32 #define CPUCLOCK_PERTHREAD(clock) \ 23 33 (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0) 24 - #define CPUCLOCK_PID_MASK 7 34 + 25 35 #define CPUCLOCK_PERTHREAD_MASK 4 26 36 #define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK) 27 37 #define CPUCLOCK_CLOCK_MASK 3 ··· 40 28 #define CPUCLOCK_VIRT 1 41 29 #define CPUCLOCK_SCHED 2 42 30 #define CPUCLOCK_MAX 3 31 + #define CLOCKFD CPUCLOCK_MAX 32 + #define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK) 43 33 44 34 #define MAKE_PROCESS_CPUCLOCK(pid, clock) \ 45 35 ((~(clockid_t) (pid) << 3) | (clockid_t) (clock)) 46 36 #define MAKE_THREAD_CPUCLOCK(tid, clock) \ 47 37 MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK) 38 + 39 + #define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD) 40 + #define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3)) 48 41 49 42 /* POSIX.1b interval timer structure. */ 50 43 struct k_itimer { ··· 84 67 }; 85 68 86 69 struct k_clock { 87 - int res; /* in nanoseconds */ 88 70 int (*clock_getres) (const clockid_t which_clock, struct timespec *tp); 89 - int (*clock_set) (const clockid_t which_clock, struct timespec * tp); 71 + int (*clock_set) (const clockid_t which_clock, 72 + const struct timespec *tp); 90 73 int (*clock_get) (const clockid_t which_clock, struct timespec * tp); 74 + int (*clock_adj) (const clockid_t which_clock, struct timex *tx); 91 75 int (*timer_create) (struct k_itimer *timer); 92 76 int (*nsleep) (const clockid_t which_clock, int flags, 93 77 struct timespec *, struct timespec __user *); ··· 102 84 struct itimerspec * cur_setting); 103 85 }; 104 86 105 - void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock); 87 + extern struct k_clock clock_posix_cpu; 88 + extern struct k_clock clock_posix_dynamic; 106 89 107 - /* error handlers for timer_create, nanosleep and settime */ 108 - int do_posix_clock_nonanosleep(const clockid_t, int flags, struct timespec *, 109 - struct timespec __user *); 110 - int do_posix_clock_nosettime(const clockid_t, struct timespec *tp); 90 + void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock); 111 91 112 92 /* function to call to trigger timer event */ 113 93 int posix_timer_event(struct k_itimer *timr, int si_private); 114 - 115 - int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *ts); 116 - int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *ts); 117 - int posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *ts); 118 - int posix_cpu_timer_create(struct k_itimer *timer); 119 - int posix_cpu_nsleep(const clockid_t which_clock, int flags, 120 - struct timespec *rqtp, struct timespec __user *rmtp); 121 - long posix_cpu_nsleep_restart(struct restart_block *restart_block); 122 - int posix_cpu_timer_set(struct k_itimer *timer, int flags, 123 - struct itimerspec *new, struct itimerspec *old); 124 - int posix_cpu_timer_del(struct k_itimer *timer); 125 - void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp); 126 94 127 95 void posix_cpu_timer_schedule(struct k_itimer *timer); 128 96
+1 -1
include/linux/sched.h
··· 2046 2046 2047 2047 #include <asm/current.h> 2048 2048 2049 - extern void do_timer(unsigned long ticks); 2049 + extern void xtime_update(unsigned long ticks); 2050 2050 2051 2051 extern int wake_up_state(struct task_struct *tsk, unsigned int state); 2052 2052 extern int wake_up_process(struct task_struct *tsk);
+5 -4
include/linux/security.h
··· 53 53 */ 54 54 extern int cap_capable(struct task_struct *tsk, const struct cred *cred, 55 55 int cap, int audit); 56 - extern int cap_settime(struct timespec *ts, struct timezone *tz); 56 + extern int cap_settime(const struct timespec *ts, const struct timezone *tz); 57 57 extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode); 58 58 extern int cap_ptrace_traceme(struct task_struct *parent); 59 59 extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted); ··· 1387 1387 int (*quotactl) (int cmds, int type, int id, struct super_block *sb); 1388 1388 int (*quota_on) (struct dentry *dentry); 1389 1389 int (*syslog) (int type); 1390 - int (*settime) (struct timespec *ts, struct timezone *tz); 1390 + int (*settime) (const struct timespec *ts, const struct timezone *tz); 1391 1391 int (*vm_enough_memory) (struct mm_struct *mm, long pages); 1392 1392 1393 1393 int (*bprm_set_creds) (struct linux_binprm *bprm); ··· 1669 1669 int security_quotactl(int cmds, int type, int id, struct super_block *sb); 1670 1670 int security_quota_on(struct dentry *dentry); 1671 1671 int security_syslog(int type); 1672 - int security_settime(struct timespec *ts, struct timezone *tz); 1672 + int security_settime(const struct timespec *ts, const struct timezone *tz); 1673 1673 int security_vm_enough_memory(long pages); 1674 1674 int security_vm_enough_memory_mm(struct mm_struct *mm, long pages); 1675 1675 int security_vm_enough_memory_kern(long pages); ··· 1904 1904 return 0; 1905 1905 } 1906 1906 1907 - static inline int security_settime(struct timespec *ts, struct timezone *tz) 1907 + static inline int security_settime(const struct timespec *ts, 1908 + const struct timezone *tz) 1908 1909 { 1909 1910 return cap_settime(ts, tz); 1910 1911 }
+2
include/linux/syscalls.h
··· 316 316 const struct timespec __user *tp); 317 317 asmlinkage long sys_clock_gettime(clockid_t which_clock, 318 318 struct timespec __user *tp); 319 + asmlinkage long sys_clock_adjtime(clockid_t which_clock, 320 + struct timex __user *tx); 319 321 asmlinkage long sys_clock_getres(clockid_t which_clock, 320 322 struct timespec __user *tp); 321 323 asmlinkage long sys_clock_nanosleep(clockid_t which_clock, int flags,
-3
include/linux/thread_info.h
··· 18 18 struct restart_block { 19 19 long (*fn)(struct restart_block *); 20 20 union { 21 - struct { 22 - unsigned long arg0, arg1, arg2, arg3; 23 - }; 24 21 /* For futex_wait and futex_wait_requeue_pi */ 25 22 struct { 26 23 u32 __user *uaddr;
+8 -6
include/linux/time.h
··· 113 113 #define timespec_valid(ts) \ 114 114 (((ts)->tv_sec >= 0) && (((unsigned long) (ts)->tv_nsec) < NSEC_PER_SEC)) 115 115 116 - extern seqlock_t xtime_lock; 117 - 118 116 extern void read_persistent_clock(struct timespec *ts); 119 117 extern void read_boot_clock(struct timespec *ts); 120 118 extern int update_persistent_clock(struct timespec now); ··· 123 125 unsigned long get_seconds(void); 124 126 struct timespec current_kernel_time(void); 125 127 struct timespec __current_kernel_time(void); /* does not take xtime_lock */ 126 - struct timespec __get_wall_to_monotonic(void); /* does not take xtime_lock */ 127 128 struct timespec get_monotonic_coarse(void); 129 + void get_xtime_and_monotonic_and_sleep_offset(struct timespec *xtim, 130 + struct timespec *wtom, struct timespec *sleep); 128 131 129 132 #define CURRENT_TIME (current_kernel_time()) 130 133 #define CURRENT_TIME_SEC ((struct timespec) { get_seconds(), 0 }) ··· 146 147 #endif 147 148 148 149 extern void do_gettimeofday(struct timeval *tv); 149 - extern int do_settimeofday(struct timespec *tv); 150 - extern int do_sys_settimeofday(struct timespec *tv, struct timezone *tz); 150 + extern int do_settimeofday(const struct timespec *tv); 151 + extern int do_sys_settimeofday(const struct timespec *tv, 152 + const struct timezone *tz); 151 153 #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts) 152 154 extern long do_utimes(int dfd, const char __user *filename, struct timespec *times, int flags); 153 155 struct itimerval; ··· 162 162 struct timespec *ts_real); 163 163 extern void getboottime(struct timespec *ts); 164 164 extern void monotonic_to_bootbased(struct timespec *ts); 165 + extern void get_monotonic_boottime(struct timespec *ts); 165 166 166 167 extern struct timespec timespec_trunc(struct timespec t, unsigned gran); 167 168 extern int timekeeping_valid_for_hres(void); 168 169 extern u64 timekeeping_max_deferment(void); 169 - extern void update_wall_time(void); 170 170 extern void timekeeping_leap_insert(int leapsecond); 171 + extern int timekeeping_inject_offset(struct timespec *ts); 171 172 172 173 struct tms; 173 174 extern void do_sys_times(struct tms *); ··· 293 292 #define CLOCK_MONOTONIC_RAW 4 294 293 #define CLOCK_REALTIME_COARSE 5 295 294 #define CLOCK_MONOTONIC_COARSE 6 295 + #define CLOCK_BOOTTIME 7 296 296 297 297 /* 298 298 * The IDs of various hardware clocks:
+2 -1
include/linux/timex.h
··· 73 73 long tolerance; /* clock frequency tolerance (ppm) 74 74 * (read only) 75 75 */ 76 - struct timeval time; /* (read only) */ 76 + struct timeval time; /* (read only, except for ADJ_SETOFFSET) */ 77 77 long tick; /* (modified) usecs between clock ticks */ 78 78 79 79 long ppsfreq; /* pps frequency (scaled ppm) (ro) */ ··· 102 102 #define ADJ_STATUS 0x0010 /* clock status */ 103 103 #define ADJ_TIMECONST 0x0020 /* pll time constant */ 104 104 #define ADJ_TAI 0x0080 /* set TAI offset */ 105 + #define ADJ_SETOFFSET 0x0100 /* add 'time' to current time */ 105 106 #define ADJ_MICRO 0x1000 /* select microsecond resolution */ 106 107 #define ADJ_NANO 0x2000 /* select nanosecond resolution */ 107 108 #define ADJ_TICK 0x4000 /* tick value */
+88 -48
kernel/compat.c
··· 52 52 put_user(i->tv_usec, &o->tv_usec)) ? -EFAULT : 0; 53 53 } 54 54 55 + static int compat_get_timex(struct timex *txc, struct compat_timex __user *utp) 56 + { 57 + memset(txc, 0, sizeof(struct timex)); 58 + 59 + if (!access_ok(VERIFY_READ, utp, sizeof(struct compat_timex)) || 60 + __get_user(txc->modes, &utp->modes) || 61 + __get_user(txc->offset, &utp->offset) || 62 + __get_user(txc->freq, &utp->freq) || 63 + __get_user(txc->maxerror, &utp->maxerror) || 64 + __get_user(txc->esterror, &utp->esterror) || 65 + __get_user(txc->status, &utp->status) || 66 + __get_user(txc->constant, &utp->constant) || 67 + __get_user(txc->precision, &utp->precision) || 68 + __get_user(txc->tolerance, &utp->tolerance) || 69 + __get_user(txc->time.tv_sec, &utp->time.tv_sec) || 70 + __get_user(txc->time.tv_usec, &utp->time.tv_usec) || 71 + __get_user(txc->tick, &utp->tick) || 72 + __get_user(txc->ppsfreq, &utp->ppsfreq) || 73 + __get_user(txc->jitter, &utp->jitter) || 74 + __get_user(txc->shift, &utp->shift) || 75 + __get_user(txc->stabil, &utp->stabil) || 76 + __get_user(txc->jitcnt, &utp->jitcnt) || 77 + __get_user(txc->calcnt, &utp->calcnt) || 78 + __get_user(txc->errcnt, &utp->errcnt) || 79 + __get_user(txc->stbcnt, &utp->stbcnt)) 80 + return -EFAULT; 81 + 82 + return 0; 83 + } 84 + 85 + static int compat_put_timex(struct compat_timex __user *utp, struct timex *txc) 86 + { 87 + if (!access_ok(VERIFY_WRITE, utp, sizeof(struct compat_timex)) || 88 + __put_user(txc->modes, &utp->modes) || 89 + __put_user(txc->offset, &utp->offset) || 90 + __put_user(txc->freq, &utp->freq) || 91 + __put_user(txc->maxerror, &utp->maxerror) || 92 + __put_user(txc->esterror, &utp->esterror) || 93 + __put_user(txc->status, &utp->status) || 94 + __put_user(txc->constant, &utp->constant) || 95 + __put_user(txc->precision, &utp->precision) || 96 + __put_user(txc->tolerance, &utp->tolerance) || 97 + __put_user(txc->time.tv_sec, &utp->time.tv_sec) || 98 + __put_user(txc->time.tv_usec, &utp->time.tv_usec) || 99 + __put_user(txc->tick, &utp->tick) || 100 + __put_user(txc->ppsfreq, &utp->ppsfreq) || 101 + __put_user(txc->jitter, &utp->jitter) || 102 + __put_user(txc->shift, &utp->shift) || 103 + __put_user(txc->stabil, &utp->stabil) || 104 + __put_user(txc->jitcnt, &utp->jitcnt) || 105 + __put_user(txc->calcnt, &utp->calcnt) || 106 + __put_user(txc->errcnt, &utp->errcnt) || 107 + __put_user(txc->stbcnt, &utp->stbcnt) || 108 + __put_user(txc->tai, &utp->tai)) 109 + return -EFAULT; 110 + return 0; 111 + } 112 + 55 113 asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv, 56 114 struct timezone __user *tz) 57 115 { ··· 675 617 return err; 676 618 } 677 619 620 + long compat_sys_clock_adjtime(clockid_t which_clock, 621 + struct compat_timex __user *utp) 622 + { 623 + struct timex txc; 624 + mm_segment_t oldfs; 625 + int err, ret; 626 + 627 + err = compat_get_timex(&txc, utp); 628 + if (err) 629 + return err; 630 + 631 + oldfs = get_fs(); 632 + set_fs(KERNEL_DS); 633 + ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc); 634 + set_fs(oldfs); 635 + 636 + err = compat_put_timex(utp, &txc); 637 + if (err) 638 + return err; 639 + 640 + return ret; 641 + } 642 + 678 643 long compat_sys_clock_getres(clockid_t which_clock, 679 644 struct compat_timespec __user *tp) 680 645 { ··· 1032 951 asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp) 1033 952 { 1034 953 struct timex txc; 1035 - int ret; 954 + int err, ret; 1036 955 1037 - memset(&txc, 0, sizeof(struct timex)); 1038 - 1039 - if (!access_ok(VERIFY_READ, utp, sizeof(struct compat_timex)) || 1040 - __get_user(txc.modes, &utp->modes) || 1041 - __get_user(txc.offset, &utp->offset) || 1042 - __get_user(txc.freq, &utp->freq) || 1043 - __get_user(txc.maxerror, &utp->maxerror) || 1044 - __get_user(txc.esterror, &utp->esterror) || 1045 - __get_user(txc.status, &utp->status) || 1046 - __get_user(txc.constant, &utp->constant) || 1047 - __get_user(txc.precision, &utp->precision) || 1048 - __get_user(txc.tolerance, &utp->tolerance) || 1049 - __get_user(txc.time.tv_sec, &utp->time.tv_sec) || 1050 - __get_user(txc.time.tv_usec, &utp->time.tv_usec) || 1051 - __get_user(txc.tick, &utp->tick) || 1052 - __get_user(txc.ppsfreq, &utp->ppsfreq) || 1053 - __get_user(txc.jitter, &utp->jitter) || 1054 - __get_user(txc.shift, &utp->shift) || 1055 - __get_user(txc.stabil, &utp->stabil) || 1056 - __get_user(txc.jitcnt, &utp->jitcnt) || 1057 - __get_user(txc.calcnt, &utp->calcnt) || 1058 - __get_user(txc.errcnt, &utp->errcnt) || 1059 - __get_user(txc.stbcnt, &utp->stbcnt)) 1060 - return -EFAULT; 956 + err = compat_get_timex(&txc, utp); 957 + if (err) 958 + return err; 1061 959 1062 960 ret = do_adjtimex(&txc); 1063 961 1064 - if (!access_ok(VERIFY_WRITE, utp, sizeof(struct compat_timex)) || 1065 - __put_user(txc.modes, &utp->modes) || 1066 - __put_user(txc.offset, &utp->offset) || 1067 - __put_user(txc.freq, &utp->freq) || 1068 - __put_user(txc.maxerror, &utp->maxerror) || 1069 - __put_user(txc.esterror, &utp->esterror) || 1070 - __put_user(txc.status, &utp->status) || 1071 - __put_user(txc.constant, &utp->constant) || 1072 - __put_user(txc.precision, &utp->precision) || 1073 - __put_user(txc.tolerance, &utp->tolerance) || 1074 - __put_user(txc.time.tv_sec, &utp->time.tv_sec) || 1075 - __put_user(txc.time.tv_usec, &utp->time.tv_usec) || 1076 - __put_user(txc.tick, &utp->tick) || 1077 - __put_user(txc.ppsfreq, &utp->ppsfreq) || 1078 - __put_user(txc.jitter, &utp->jitter) || 1079 - __put_user(txc.shift, &utp->shift) || 1080 - __put_user(txc.stabil, &utp->stabil) || 1081 - __put_user(txc.jitcnt, &utp->jitcnt) || 1082 - __put_user(txc.calcnt, &utp->calcnt) || 1083 - __put_user(txc.errcnt, &utp->errcnt) || 1084 - __put_user(txc.stbcnt, &utp->stbcnt) || 1085 - __put_user(txc.tai, &utp->tai)) 1086 - ret = -EFAULT; 962 + err = compat_put_timex(utp, &txc); 963 + if (err) 964 + return err; 1087 965 1088 966 return ret; 1089 967 }
+45 -39
kernel/hrtimer.c
··· 53 53 /* 54 54 * The timer bases: 55 55 * 56 - * Note: If we want to add new timer bases, we have to skip the two 57 - * clock ids captured by the cpu-timers. We do this by holding empty 58 - * entries rather than doing math adjustment of the clock ids. 59 - * This ensures that we capture erroneous accesses to these clock ids 60 - * rather than moving them into the range of valid clock id's. 56 + * There are more clockids then hrtimer bases. Thus, we index 57 + * into the timer bases by the hrtimer_base_type enum. When trying 58 + * to reach a base using a clockid, hrtimer_clockid_to_base() 59 + * is used to convert from clockid to the proper hrtimer_base_type. 61 60 */ 62 61 DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) = 63 62 { ··· 73 74 .get_time = &ktime_get, 74 75 .resolution = KTIME_LOW_RES, 75 76 }, 77 + { 78 + .index = CLOCK_BOOTTIME, 79 + .get_time = &ktime_get_boottime, 80 + .resolution = KTIME_LOW_RES, 81 + }, 76 82 } 77 83 }; 84 + 85 + static int hrtimer_clock_to_base_table[MAX_CLOCKS]; 86 + 87 + static inline int hrtimer_clockid_to_base(clockid_t clock_id) 88 + { 89 + return hrtimer_clock_to_base_table[clock_id]; 90 + } 91 + 78 92 79 93 /* 80 94 * Get the coarse grained time at the softirq based on xtime and ··· 95 83 */ 96 84 static void hrtimer_get_softirq_time(struct hrtimer_cpu_base *base) 97 85 { 98 - ktime_t xtim, tomono; 99 - struct timespec xts, tom; 100 - unsigned long seq; 86 + ktime_t xtim, mono, boot; 87 + struct timespec xts, tom, slp; 101 88 102 - do { 103 - seq = read_seqbegin(&xtime_lock); 104 - xts = __current_kernel_time(); 105 - tom = __get_wall_to_monotonic(); 106 - } while (read_seqretry(&xtime_lock, seq)); 89 + get_xtime_and_monotonic_and_sleep_offset(&xts, &tom, &slp); 107 90 108 91 xtim = timespec_to_ktime(xts); 109 - tomono = timespec_to_ktime(tom); 110 - base->clock_base[CLOCK_REALTIME].softirq_time = xtim; 111 - base->clock_base[CLOCK_MONOTONIC].softirq_time = 112 - ktime_add(xtim, tomono); 92 + mono = ktime_add(xtim, timespec_to_ktime(tom)); 93 + boot = ktime_add(mono, timespec_to_ktime(slp)); 94 + base->clock_base[HRTIMER_BASE_REALTIME].softirq_time = xtim; 95 + base->clock_base[HRTIMER_BASE_MONOTONIC].softirq_time = mono; 96 + base->clock_base[HRTIMER_BASE_BOOTTIME].softirq_time = boot; 113 97 } 114 98 115 99 /* ··· 192 184 struct hrtimer_cpu_base *new_cpu_base; 193 185 int this_cpu = smp_processor_id(); 194 186 int cpu = hrtimer_get_target(this_cpu, pinned); 187 + int basenum = hrtimer_clockid_to_base(base->index); 195 188 196 189 again: 197 190 new_cpu_base = &per_cpu(hrtimer_bases, cpu); 198 - new_base = &new_cpu_base->clock_base[base->index]; 191 + new_base = &new_cpu_base->clock_base[basenum]; 199 192 200 193 if (base != new_base) { 201 194 /* ··· 626 617 static void retrigger_next_event(void *arg) 627 618 { 628 619 struct hrtimer_cpu_base *base; 629 - struct timespec realtime_offset, wtm; 630 - unsigned long seq; 620 + struct timespec realtime_offset, wtm, sleep; 631 621 632 622 if (!hrtimer_hres_active()) 633 623 return; 634 624 635 - do { 636 - seq = read_seqbegin(&xtime_lock); 637 - wtm = __get_wall_to_monotonic(); 638 - } while (read_seqretry(&xtime_lock, seq)); 625 + get_xtime_and_monotonic_and_sleep_offset(&realtime_offset, &wtm, 626 + &sleep); 639 627 set_normalized_timespec(&realtime_offset, -wtm.tv_sec, -wtm.tv_nsec); 640 628 641 629 base = &__get_cpu_var(hrtimer_bases); 642 630 643 631 /* Adjust CLOCK_REALTIME offset */ 644 632 raw_spin_lock(&base->lock); 645 - base->clock_base[CLOCK_REALTIME].offset = 633 + base->clock_base[HRTIMER_BASE_REALTIME].offset = 646 634 timespec_to_ktime(realtime_offset); 635 + base->clock_base[HRTIMER_BASE_BOOTTIME].offset = 636 + timespec_to_ktime(sleep); 647 637 648 638 hrtimer_force_reprogram(base, 0); 649 639 raw_spin_unlock(&base->lock); ··· 685 677 base->expires_next.tv64 = KTIME_MAX; 686 678 base->hres_active = 0; 687 679 } 688 - 689 - /* 690 - * Initialize the high resolution related parts of a hrtimer 691 - */ 692 - static inline void hrtimer_init_timer_hres(struct hrtimer *timer) 693 - { 694 - } 695 - 696 680 697 681 /* 698 682 * When High resolution timers are active, try to reprogram. Note, that in case ··· 731 731 return 0; 732 732 } 733 733 base->hres_active = 1; 734 - base->clock_base[CLOCK_REALTIME].resolution = KTIME_HIGH_RES; 735 - base->clock_base[CLOCK_MONOTONIC].resolution = KTIME_HIGH_RES; 734 + base->clock_base[HRTIMER_BASE_REALTIME].resolution = KTIME_HIGH_RES; 735 + base->clock_base[HRTIMER_BASE_MONOTONIC].resolution = KTIME_HIGH_RES; 736 + base->clock_base[HRTIMER_BASE_BOOTTIME].resolution = KTIME_HIGH_RES; 736 737 737 738 tick_setup_sched_timer(); 738 739 ··· 757 756 return 0; 758 757 } 759 758 static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base) { } 760 - static inline void hrtimer_init_timer_hres(struct hrtimer *timer) { } 761 759 762 760 #endif /* CONFIG_HIGH_RES_TIMERS */ 763 761 ··· 1127 1127 enum hrtimer_mode mode) 1128 1128 { 1129 1129 struct hrtimer_cpu_base *cpu_base; 1130 + int base; 1130 1131 1131 1132 memset(timer, 0, sizeof(struct hrtimer)); 1132 1133 ··· 1136 1135 if (clock_id == CLOCK_REALTIME && mode != HRTIMER_MODE_ABS) 1137 1136 clock_id = CLOCK_MONOTONIC; 1138 1137 1139 - timer->base = &cpu_base->clock_base[clock_id]; 1140 - hrtimer_init_timer_hres(timer); 1138 + base = hrtimer_clockid_to_base(clock_id); 1139 + timer->base = &cpu_base->clock_base[base]; 1141 1140 timerqueue_init(&timer->node); 1142 1141 1143 1142 #ifdef CONFIG_TIMER_STATS ··· 1172 1171 int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp) 1173 1172 { 1174 1173 struct hrtimer_cpu_base *cpu_base; 1174 + int base = hrtimer_clockid_to_base(which_clock); 1175 1175 1176 1176 cpu_base = &__raw_get_cpu_var(hrtimer_bases); 1177 - *tp = ktime_to_timespec(cpu_base->clock_base[which_clock].resolution); 1177 + *tp = ktime_to_timespec(cpu_base->clock_base[base].resolution); 1178 1178 1179 1179 return 0; 1180 1180 } ··· 1722 1720 1723 1721 void __init hrtimers_init(void) 1724 1722 { 1723 + hrtimer_clock_to_base_table[CLOCK_REALTIME] = HRTIMER_BASE_REALTIME; 1724 + hrtimer_clock_to_base_table[CLOCK_MONOTONIC] = HRTIMER_BASE_MONOTONIC; 1725 + hrtimer_clock_to_base_table[CLOCK_BOOTTIME] = HRTIMER_BASE_BOOTTIME; 1726 + 1725 1727 hrtimer_cpu_notify(&hrtimers_nb, (unsigned long)CPU_UP_PREPARE, 1726 1728 (void *)(long)smp_processor_id()); 1727 1729 register_cpu_notifier(&hrtimers_nb);
+52 -58
kernel/posix-cpu-timers.c
··· 176 176 return p->utime; 177 177 } 178 178 179 - int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp) 179 + static int 180 + posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp) 180 181 { 181 182 int error = check_clock(which_clock); 182 183 if (!error) { ··· 195 194 return error; 196 195 } 197 196 198 - int posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp) 197 + static int 198 + posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp) 199 199 { 200 200 /* 201 201 * You can never reset a CPU clock, but we check for other errors ··· 319 317 } 320 318 321 319 322 - int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp) 320 + static int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp) 323 321 { 324 322 const pid_t pid = CPUCLOCK_PID(which_clock); 325 323 int error = -EINVAL; ··· 381 379 * This is called from sys_timer_create() and do_cpu_nanosleep() with the 382 380 * new timer already all-zeros initialized. 383 381 */ 384 - int posix_cpu_timer_create(struct k_itimer *new_timer) 382 + static int posix_cpu_timer_create(struct k_itimer *new_timer) 385 383 { 386 384 int ret = 0; 387 385 const pid_t pid = CPUCLOCK_PID(new_timer->it_clock); ··· 427 425 * If we return TIMER_RETRY, it's necessary to release the timer's lock 428 426 * and try again. (This happens when the timer is in the middle of firing.) 429 427 */ 430 - int posix_cpu_timer_del(struct k_itimer *timer) 428 + static int posix_cpu_timer_del(struct k_itimer *timer) 431 429 { 432 430 struct task_struct *p = timer->it.cpu.task; 433 431 int ret = 0; ··· 667 665 * If we return TIMER_RETRY, it's necessary to release the timer's lock 668 666 * and try again. (This happens when the timer is in the middle of firing.) 669 667 */ 670 - int posix_cpu_timer_set(struct k_itimer *timer, int flags, 671 - struct itimerspec *new, struct itimerspec *old) 668 + static int posix_cpu_timer_set(struct k_itimer *timer, int flags, 669 + struct itimerspec *new, struct itimerspec *old) 672 670 { 673 671 struct task_struct *p = timer->it.cpu.task; 674 672 union cpu_time_count old_expires, new_expires, old_incr, val; ··· 822 820 return ret; 823 821 } 824 822 825 - void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp) 823 + static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp) 826 824 { 827 825 union cpu_time_count now; 828 826 struct task_struct *p = timer->it.cpu.task; ··· 1483 1481 return error; 1484 1482 } 1485 1483 1486 - int posix_cpu_nsleep(const clockid_t which_clock, int flags, 1487 - struct timespec *rqtp, struct timespec __user *rmtp) 1484 + static long posix_cpu_nsleep_restart(struct restart_block *restart_block); 1485 + 1486 + static int posix_cpu_nsleep(const clockid_t which_clock, int flags, 1487 + struct timespec *rqtp, struct timespec __user *rmtp) 1488 1488 { 1489 1489 struct restart_block *restart_block = 1490 - &current_thread_info()->restart_block; 1490 + &current_thread_info()->restart_block; 1491 1491 struct itimerspec it; 1492 1492 int error; 1493 1493 ··· 1505 1501 1506 1502 if (error == -ERESTART_RESTARTBLOCK) { 1507 1503 1508 - if (flags & TIMER_ABSTIME) 1504 + if (flags & TIMER_ABSTIME) 1509 1505 return -ERESTARTNOHAND; 1510 1506 /* 1511 - * Report back to the user the time still remaining. 1512 - */ 1513 - if (rmtp != NULL && copy_to_user(rmtp, &it.it_value, sizeof *rmtp)) 1507 + * Report back to the user the time still remaining. 1508 + */ 1509 + if (rmtp && copy_to_user(rmtp, &it.it_value, sizeof *rmtp)) 1514 1510 return -EFAULT; 1515 1511 1516 1512 restart_block->fn = posix_cpu_nsleep_restart; 1517 - restart_block->arg0 = which_clock; 1518 - restart_block->arg1 = (unsigned long) rmtp; 1519 - restart_block->arg2 = rqtp->tv_sec; 1520 - restart_block->arg3 = rqtp->tv_nsec; 1513 + restart_block->nanosleep.index = which_clock; 1514 + restart_block->nanosleep.rmtp = rmtp; 1515 + restart_block->nanosleep.expires = timespec_to_ns(rqtp); 1521 1516 } 1522 1517 return error; 1523 1518 } 1524 1519 1525 - long posix_cpu_nsleep_restart(struct restart_block *restart_block) 1520 + static long posix_cpu_nsleep_restart(struct restart_block *restart_block) 1526 1521 { 1527 - clockid_t which_clock = restart_block->arg0; 1528 - struct timespec __user *rmtp; 1522 + clockid_t which_clock = restart_block->nanosleep.index; 1529 1523 struct timespec t; 1530 1524 struct itimerspec it; 1531 1525 int error; 1532 1526 1533 - rmtp = (struct timespec __user *) restart_block->arg1; 1534 - t.tv_sec = restart_block->arg2; 1535 - t.tv_nsec = restart_block->arg3; 1527 + t = ns_to_timespec(restart_block->nanosleep.expires); 1536 1528 1537 - restart_block->fn = do_no_restart_syscall; 1538 1529 error = do_cpu_nanosleep(which_clock, TIMER_ABSTIME, &t, &it); 1539 1530 1540 1531 if (error == -ERESTART_RESTARTBLOCK) { 1532 + struct timespec __user *rmtp = restart_block->nanosleep.rmtp; 1541 1533 /* 1542 - * Report back to the user the time still remaining. 1543 - */ 1544 - if (rmtp != NULL && copy_to_user(rmtp, &it.it_value, sizeof *rmtp)) 1534 + * Report back to the user the time still remaining. 1535 + */ 1536 + if (rmtp && copy_to_user(rmtp, &it.it_value, sizeof *rmtp)) 1545 1537 return -EFAULT; 1546 1538 1547 - restart_block->fn = posix_cpu_nsleep_restart; 1548 - restart_block->arg0 = which_clock; 1549 - restart_block->arg1 = (unsigned long) rmtp; 1550 - restart_block->arg2 = t.tv_sec; 1551 - restart_block->arg3 = t.tv_nsec; 1539 + restart_block->nanosleep.expires = timespec_to_ns(&t); 1552 1540 } 1553 1541 return error; 1554 1542 1555 1543 } 1556 - 1557 1544 1558 1545 #define PROCESS_CLOCK MAKE_PROCESS_CPUCLOCK(0, CPUCLOCK_SCHED) 1559 1546 #define THREAD_CLOCK MAKE_THREAD_CPUCLOCK(0, CPUCLOCK_SCHED) ··· 1589 1594 timer->it_clock = THREAD_CLOCK; 1590 1595 return posix_cpu_timer_create(timer); 1591 1596 } 1592 - static int thread_cpu_nsleep(const clockid_t which_clock, int flags, 1593 - struct timespec *rqtp, struct timespec __user *rmtp) 1594 - { 1595 - return -EINVAL; 1596 - } 1597 - static long thread_cpu_nsleep_restart(struct restart_block *restart_block) 1598 - { 1599 - return -EINVAL; 1600 - } 1597 + 1598 + struct k_clock clock_posix_cpu = { 1599 + .clock_getres = posix_cpu_clock_getres, 1600 + .clock_set = posix_cpu_clock_set, 1601 + .clock_get = posix_cpu_clock_get, 1602 + .timer_create = posix_cpu_timer_create, 1603 + .nsleep = posix_cpu_nsleep, 1604 + .nsleep_restart = posix_cpu_nsleep_restart, 1605 + .timer_set = posix_cpu_timer_set, 1606 + .timer_del = posix_cpu_timer_del, 1607 + .timer_get = posix_cpu_timer_get, 1608 + }; 1601 1609 1602 1610 static __init int init_posix_cpu_timers(void) 1603 1611 { 1604 1612 struct k_clock process = { 1605 - .clock_getres = process_cpu_clock_getres, 1606 - .clock_get = process_cpu_clock_get, 1607 - .clock_set = do_posix_clock_nosettime, 1608 - .timer_create = process_cpu_timer_create, 1609 - .nsleep = process_cpu_nsleep, 1610 - .nsleep_restart = process_cpu_nsleep_restart, 1613 + .clock_getres = process_cpu_clock_getres, 1614 + .clock_get = process_cpu_clock_get, 1615 + .timer_create = process_cpu_timer_create, 1616 + .nsleep = process_cpu_nsleep, 1617 + .nsleep_restart = process_cpu_nsleep_restart, 1611 1618 }; 1612 1619 struct k_clock thread = { 1613 - .clock_getres = thread_cpu_clock_getres, 1614 - .clock_get = thread_cpu_clock_get, 1615 - .clock_set = do_posix_clock_nosettime, 1616 - .timer_create = thread_cpu_timer_create, 1617 - .nsleep = thread_cpu_nsleep, 1618 - .nsleep_restart = thread_cpu_nsleep_restart, 1620 + .clock_getres = thread_cpu_clock_getres, 1621 + .clock_get = thread_cpu_clock_get, 1622 + .timer_create = thread_cpu_timer_create, 1619 1623 }; 1620 1624 struct timespec ts; 1621 1625 1622 - register_posix_clock(CLOCK_PROCESS_CPUTIME_ID, &process); 1623 - register_posix_clock(CLOCK_THREAD_CPUTIME_ID, &thread); 1626 + posix_timers_register_clock(CLOCK_PROCESS_CPUTIME_ID, &process); 1627 + posix_timers_register_clock(CLOCK_THREAD_CPUTIME_ID, &thread); 1624 1628 1625 1629 cputime_to_timespec(cputime_one_jiffy, &ts); 1626 1630 onecputick = ts.tv_nsec;
+181 -161
kernel/posix-timers.c
··· 41 41 #include <linux/init.h> 42 42 #include <linux/compiler.h> 43 43 #include <linux/idr.h> 44 + #include <linux/posix-clock.h> 44 45 #include <linux/posix-timers.h> 45 46 #include <linux/syscalls.h> 46 47 #include <linux/wait.h> ··· 82 81 #error "SIGEV_THREAD_ID must not share bit with other SIGEV values!" 83 82 #endif 84 83 84 + /* 85 + * parisc wants ENOTSUP instead of EOPNOTSUPP 86 + */ 87 + #ifndef ENOTSUP 88 + # define ENANOSLEEP_NOTSUP EOPNOTSUPP 89 + #else 90 + # define ENANOSLEEP_NOTSUP ENOTSUP 91 + #endif 85 92 86 93 /* 87 94 * The timer ID is turned into a timer address by idr_find(). ··· 103 94 /* 104 95 * CLOCKs: The POSIX standard calls for a couple of clocks and allows us 105 96 * to implement others. This structure defines the various 106 - * clocks and allows the possibility of adding others. We 107 - * provide an interface to add clocks to the table and expect 108 - * the "arch" code to add at least one clock that is high 109 - * resolution. Here we define the standard CLOCK_REALTIME as a 110 - * 1/HZ resolution clock. 97 + * clocks. 111 98 * 112 99 * RESOLUTION: Clock resolution is used to round up timer and interval 113 100 * times, NOT to report clock times, which are reported with as ··· 113 108 * necessary code is written. The standard says we should say 114 109 * something about this issue in the documentation... 115 110 * 116 - * FUNCTIONS: The CLOCKs structure defines possible functions to handle 117 - * various clock functions. For clocks that use the standard 118 - * system timer code these entries should be NULL. This will 119 - * allow dispatch without the overhead of indirect function 120 - * calls. CLOCKS that depend on other sources (e.g. WWV or GPS) 121 - * must supply functions here, even if the function just returns 122 - * ENOSYS. The standard POSIX timer management code assumes the 123 - * following: 1.) The k_itimer struct (sched.h) is used for the 124 - * timer. 2.) The list, it_lock, it_clock, it_id and it_pid 125 - * fields are not modified by timer code. 111 + * FUNCTIONS: The CLOCKs structure defines possible functions to 112 + * handle various clock functions. 126 113 * 127 - * At this time all functions EXCEPT clock_nanosleep can be 128 - * redirected by the CLOCKS structure. Clock_nanosleep is in 129 - * there, but the code ignores it. 114 + * The standard POSIX timer management code assumes the 115 + * following: 1.) The k_itimer struct (sched.h) is used for 116 + * the timer. 2.) The list, it_lock, it_clock, it_id and 117 + * it_pid fields are not modified by timer code. 130 118 * 131 119 * Permissions: It is assumed that the clock_settime() function defined 132 120 * for each clock will take care of permission checks. Some ··· 136 138 */ 137 139 static int common_nsleep(const clockid_t, int flags, struct timespec *t, 138 140 struct timespec __user *rmtp); 141 + static int common_timer_create(struct k_itimer *new_timer); 139 142 static void common_timer_get(struct k_itimer *, struct itimerspec *); 140 143 static int common_timer_set(struct k_itimer *, int, 141 144 struct itimerspec *, struct itimerspec *); ··· 157 158 spin_unlock_irqrestore(&timr->it_lock, flags); 158 159 } 159 160 160 - /* 161 - * Call the k_clock hook function if non-null, or the default function. 162 - */ 163 - #define CLOCK_DISPATCH(clock, call, arglist) \ 164 - ((clock) < 0 ? posix_cpu_##call arglist : \ 165 - (posix_clocks[clock].call != NULL \ 166 - ? (*posix_clocks[clock].call) arglist : common_##call arglist)) 167 - 168 - /* 169 - * Default clock hook functions when the struct k_clock passed 170 - * to register_posix_clock leaves a function pointer null. 171 - * 172 - * The function common_CALL is the default implementation for 173 - * the function pointer CALL in struct k_clock. 174 - */ 175 - 176 - static inline int common_clock_getres(const clockid_t which_clock, 177 - struct timespec *tp) 178 - { 179 - tp->tv_sec = 0; 180 - tp->tv_nsec = posix_clocks[which_clock].res; 181 - return 0; 182 - } 183 - 184 - /* 185 - * Get real time for posix timers 186 - */ 187 - static int common_clock_get(clockid_t which_clock, struct timespec *tp) 161 + /* Get clock_realtime */ 162 + static int posix_clock_realtime_get(clockid_t which_clock, struct timespec *tp) 188 163 { 189 164 ktime_get_real_ts(tp); 190 165 return 0; 191 166 } 192 167 193 - static inline int common_clock_set(const clockid_t which_clock, 194 - struct timespec *tp) 168 + /* Set clock_realtime */ 169 + static int posix_clock_realtime_set(const clockid_t which_clock, 170 + const struct timespec *tp) 195 171 { 196 172 return do_sys_settimeofday(tp, NULL); 197 173 } 198 174 199 - static int common_timer_create(struct k_itimer *new_timer) 175 + static int posix_clock_realtime_adj(const clockid_t which_clock, 176 + struct timex *t) 200 177 { 201 - hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0); 202 - return 0; 203 - } 204 - 205 - static int no_timer_create(struct k_itimer *new_timer) 206 - { 207 - return -EOPNOTSUPP; 208 - } 209 - 210 - static int no_nsleep(const clockid_t which_clock, int flags, 211 - struct timespec *tsave, struct timespec __user *rmtp) 212 - { 213 - return -EOPNOTSUPP; 214 - } 215 - 216 - /* 217 - * Return nonzero if we know a priori this clockid_t value is bogus. 218 - */ 219 - static inline int invalid_clockid(const clockid_t which_clock) 220 - { 221 - if (which_clock < 0) /* CPU clock, posix_cpu_* will check it */ 222 - return 0; 223 - if ((unsigned) which_clock >= MAX_CLOCKS) 224 - return 1; 225 - if (posix_clocks[which_clock].clock_getres != NULL) 226 - return 0; 227 - if (posix_clocks[which_clock].res != 0) 228 - return 0; 229 - return 1; 178 + return do_adjtimex(t); 230 179 } 231 180 232 181 /* ··· 187 240 } 188 241 189 242 /* 190 - * Get monotonic time for posix timers 243 + * Get monotonic-raw time for posix timers 191 244 */ 192 245 static int posix_get_monotonic_raw(clockid_t which_clock, struct timespec *tp) 193 246 { ··· 214 267 *tp = ktime_to_timespec(KTIME_LOW_RES); 215 268 return 0; 216 269 } 270 + 271 + static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp) 272 + { 273 + get_monotonic_boottime(tp); 274 + return 0; 275 + } 276 + 277 + 217 278 /* 218 279 * Initialize everything, well, just everything in Posix clocks/timers ;) 219 280 */ 220 281 static __init int init_posix_timers(void) 221 282 { 222 283 struct k_clock clock_realtime = { 223 - .clock_getres = hrtimer_get_res, 284 + .clock_getres = hrtimer_get_res, 285 + .clock_get = posix_clock_realtime_get, 286 + .clock_set = posix_clock_realtime_set, 287 + .clock_adj = posix_clock_realtime_adj, 288 + .nsleep = common_nsleep, 289 + .nsleep_restart = hrtimer_nanosleep_restart, 290 + .timer_create = common_timer_create, 291 + .timer_set = common_timer_set, 292 + .timer_get = common_timer_get, 293 + .timer_del = common_timer_del, 224 294 }; 225 295 struct k_clock clock_monotonic = { 226 - .clock_getres = hrtimer_get_res, 227 - .clock_get = posix_ktime_get_ts, 228 - .clock_set = do_posix_clock_nosettime, 296 + .clock_getres = hrtimer_get_res, 297 + .clock_get = posix_ktime_get_ts, 298 + .nsleep = common_nsleep, 299 + .nsleep_restart = hrtimer_nanosleep_restart, 300 + .timer_create = common_timer_create, 301 + .timer_set = common_timer_set, 302 + .timer_get = common_timer_get, 303 + .timer_del = common_timer_del, 229 304 }; 230 305 struct k_clock clock_monotonic_raw = { 231 - .clock_getres = hrtimer_get_res, 232 - .clock_get = posix_get_monotonic_raw, 233 - .clock_set = do_posix_clock_nosettime, 234 - .timer_create = no_timer_create, 235 - .nsleep = no_nsleep, 306 + .clock_getres = hrtimer_get_res, 307 + .clock_get = posix_get_monotonic_raw, 236 308 }; 237 309 struct k_clock clock_realtime_coarse = { 238 - .clock_getres = posix_get_coarse_res, 239 - .clock_get = posix_get_realtime_coarse, 240 - .clock_set = do_posix_clock_nosettime, 241 - .timer_create = no_timer_create, 242 - .nsleep = no_nsleep, 310 + .clock_getres = posix_get_coarse_res, 311 + .clock_get = posix_get_realtime_coarse, 243 312 }; 244 313 struct k_clock clock_monotonic_coarse = { 245 - .clock_getres = posix_get_coarse_res, 246 - .clock_get = posix_get_monotonic_coarse, 247 - .clock_set = do_posix_clock_nosettime, 248 - .timer_create = no_timer_create, 249 - .nsleep = no_nsleep, 314 + .clock_getres = posix_get_coarse_res, 315 + .clock_get = posix_get_monotonic_coarse, 316 + }; 317 + struct k_clock clock_boottime = { 318 + .clock_getres = hrtimer_get_res, 319 + .clock_get = posix_get_boottime, 320 + .nsleep = common_nsleep, 321 + .nsleep_restart = hrtimer_nanosleep_restart, 322 + .timer_create = common_timer_create, 323 + .timer_set = common_timer_set, 324 + .timer_get = common_timer_get, 325 + .timer_del = common_timer_del, 250 326 }; 251 327 252 - register_posix_clock(CLOCK_REALTIME, &clock_realtime); 253 - register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic); 254 - register_posix_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw); 255 - register_posix_clock(CLOCK_REALTIME_COARSE, &clock_realtime_coarse); 256 - register_posix_clock(CLOCK_MONOTONIC_COARSE, &clock_monotonic_coarse); 328 + posix_timers_register_clock(CLOCK_REALTIME, &clock_realtime); 329 + posix_timers_register_clock(CLOCK_MONOTONIC, &clock_monotonic); 330 + posix_timers_register_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw); 331 + posix_timers_register_clock(CLOCK_REALTIME_COARSE, &clock_realtime_coarse); 332 + posix_timers_register_clock(CLOCK_MONOTONIC_COARSE, &clock_monotonic_coarse); 333 + posix_timers_register_clock(CLOCK_BOOTTIME, &clock_boottime); 257 334 258 335 posix_timers_cache = kmem_cache_create("posix_timers_cache", 259 336 sizeof (struct k_itimer), 0, SLAB_PANIC, ··· 453 482 return task_pid(rtn); 454 483 } 455 484 456 - void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock) 485 + void posix_timers_register_clock(const clockid_t clock_id, 486 + struct k_clock *new_clock) 457 487 { 458 488 if ((unsigned) clock_id >= MAX_CLOCKS) { 459 - printk("POSIX clock register failed for clock_id %d\n", 489 + printk(KERN_WARNING "POSIX clock register failed for clock_id %d\n", 490 + clock_id); 491 + return; 492 + } 493 + 494 + if (!new_clock->clock_get) { 495 + printk(KERN_WARNING "POSIX clock id %d lacks clock_get()\n", 496 + clock_id); 497 + return; 498 + } 499 + if (!new_clock->clock_getres) { 500 + printk(KERN_WARNING "POSIX clock id %d lacks clock_getres()\n", 460 501 clock_id); 461 502 return; 462 503 } 463 504 464 505 posix_clocks[clock_id] = *new_clock; 465 506 } 466 - EXPORT_SYMBOL_GPL(register_posix_clock); 507 + EXPORT_SYMBOL_GPL(posix_timers_register_clock); 467 508 468 509 static struct k_itimer * alloc_posix_timer(void) 469 510 { ··· 506 523 kmem_cache_free(posix_timers_cache, tmr); 507 524 } 508 525 526 + static struct k_clock *clockid_to_kclock(const clockid_t id) 527 + { 528 + if (id < 0) 529 + return (id & CLOCKFD_MASK) == CLOCKFD ? 530 + &clock_posix_dynamic : &clock_posix_cpu; 531 + 532 + if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres) 533 + return NULL; 534 + return &posix_clocks[id]; 535 + } 536 + 537 + static int common_timer_create(struct k_itimer *new_timer) 538 + { 539 + hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0); 540 + return 0; 541 + } 542 + 509 543 /* Create a POSIX.1b interval timer. */ 510 544 511 545 SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock, 512 546 struct sigevent __user *, timer_event_spec, 513 547 timer_t __user *, created_timer_id) 514 548 { 549 + struct k_clock *kc = clockid_to_kclock(which_clock); 515 550 struct k_itimer *new_timer; 516 551 int error, new_timer_id; 517 552 sigevent_t event; 518 553 int it_id_set = IT_ID_NOT_SET; 519 554 520 - if (invalid_clockid(which_clock)) 555 + if (!kc) 521 556 return -EINVAL; 557 + if (!kc->timer_create) 558 + return -EOPNOTSUPP; 522 559 523 560 new_timer = alloc_posix_timer(); 524 561 if (unlikely(!new_timer)) ··· 600 597 goto out; 601 598 } 602 599 603 - error = CLOCK_DISPATCH(which_clock, timer_create, (new_timer)); 600 + error = kc->timer_create(new_timer); 604 601 if (error) 605 602 goto out; 606 603 ··· 610 607 spin_unlock_irq(&current->sighand->siglock); 611 608 612 609 return 0; 613 - /* 610 + /* 614 611 * In the case of the timer belonging to another task, after 615 612 * the task is unlocked, the timer is owned by the other task 616 613 * and may cease to exist at any time. Don't use or modify ··· 712 709 SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id, 713 710 struct itimerspec __user *, setting) 714 711 { 715 - struct k_itimer *timr; 716 712 struct itimerspec cur_setting; 713 + struct k_itimer *timr; 714 + struct k_clock *kc; 717 715 unsigned long flags; 716 + int ret = 0; 718 717 719 718 timr = lock_timer(timer_id, &flags); 720 719 if (!timr) 721 720 return -EINVAL; 722 721 723 - CLOCK_DISPATCH(timr->it_clock, timer_get, (timr, &cur_setting)); 722 + kc = clockid_to_kclock(timr->it_clock); 723 + if (WARN_ON_ONCE(!kc || !kc->timer_get)) 724 + ret = -EINVAL; 725 + else 726 + kc->timer_get(timr, &cur_setting); 724 727 725 728 unlock_timer(timr, flags); 726 729 727 - if (copy_to_user(setting, &cur_setting, sizeof (cur_setting))) 730 + if (!ret && copy_to_user(setting, &cur_setting, sizeof (cur_setting))) 728 731 return -EFAULT; 729 732 730 - return 0; 733 + return ret; 731 734 } 732 735 733 736 /* ··· 822 813 int error = 0; 823 814 unsigned long flag; 824 815 struct itimerspec *rtn = old_setting ? &old_spec : NULL; 816 + struct k_clock *kc; 825 817 826 818 if (!new_setting) 827 819 return -EINVAL; ··· 838 828 if (!timr) 839 829 return -EINVAL; 840 830 841 - error = CLOCK_DISPATCH(timr->it_clock, timer_set, 842 - (timr, flags, &new_spec, rtn)); 831 + kc = clockid_to_kclock(timr->it_clock); 832 + if (WARN_ON_ONCE(!kc || !kc->timer_set)) 833 + error = -EINVAL; 834 + else 835 + error = kc->timer_set(timr, flags, &new_spec, rtn); 843 836 844 837 unlock_timer(timr, flag); 845 838 if (error == TIMER_RETRY) { ··· 857 844 return error; 858 845 } 859 846 860 - static inline int common_timer_del(struct k_itimer *timer) 847 + static int common_timer_del(struct k_itimer *timer) 861 848 { 862 849 timer->it.real.interval.tv64 = 0; 863 850 ··· 868 855 869 856 static inline int timer_delete_hook(struct k_itimer *timer) 870 857 { 871 - return CLOCK_DISPATCH(timer->it_clock, timer_del, (timer)); 858 + struct k_clock *kc = clockid_to_kclock(timer->it_clock); 859 + 860 + if (WARN_ON_ONCE(!kc || !kc->timer_del)) 861 + return -EINVAL; 862 + return kc->timer_del(timer); 872 863 } 873 864 874 865 /* Delete a POSIX.1b interval timer. */ ··· 944 927 } 945 928 } 946 929 947 - /* Not available / possible... functions */ 948 - int do_posix_clock_nosettime(const clockid_t clockid, struct timespec *tp) 949 - { 950 - return -EINVAL; 951 - } 952 - EXPORT_SYMBOL_GPL(do_posix_clock_nosettime); 953 - 954 - int do_posix_clock_nonanosleep(const clockid_t clock, int flags, 955 - struct timespec *t, struct timespec __user *r) 956 - { 957 - #ifndef ENOTSUP 958 - return -EOPNOTSUPP; /* aka ENOTSUP in userland for POSIX */ 959 - #else /* parisc does define it separately. */ 960 - return -ENOTSUP; 961 - #endif 962 - } 963 - EXPORT_SYMBOL_GPL(do_posix_clock_nonanosleep); 964 - 965 930 SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock, 966 931 const struct timespec __user *, tp) 967 932 { 933 + struct k_clock *kc = clockid_to_kclock(which_clock); 968 934 struct timespec new_tp; 969 935 970 - if (invalid_clockid(which_clock)) 936 + if (!kc || !kc->clock_set) 971 937 return -EINVAL; 938 + 972 939 if (copy_from_user(&new_tp, tp, sizeof (*tp))) 973 940 return -EFAULT; 974 941 975 - return CLOCK_DISPATCH(which_clock, clock_set, (which_clock, &new_tp)); 942 + return kc->clock_set(which_clock, &new_tp); 976 943 } 977 944 978 945 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock, 979 946 struct timespec __user *,tp) 980 947 { 948 + struct k_clock *kc = clockid_to_kclock(which_clock); 981 949 struct timespec kernel_tp; 982 950 int error; 983 951 984 - if (invalid_clockid(which_clock)) 952 + if (!kc) 985 953 return -EINVAL; 986 - error = CLOCK_DISPATCH(which_clock, clock_get, 987 - (which_clock, &kernel_tp)); 954 + 955 + error = kc->clock_get(which_clock, &kernel_tp); 956 + 988 957 if (!error && copy_to_user(tp, &kernel_tp, sizeof (kernel_tp))) 989 958 error = -EFAULT; 990 959 991 960 return error; 961 + } 992 962 963 + SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock, 964 + struct timex __user *, utx) 965 + { 966 + struct k_clock *kc = clockid_to_kclock(which_clock); 967 + struct timex ktx; 968 + int err; 969 + 970 + if (!kc) 971 + return -EINVAL; 972 + if (!kc->clock_adj) 973 + return -EOPNOTSUPP; 974 + 975 + if (copy_from_user(&ktx, utx, sizeof(ktx))) 976 + return -EFAULT; 977 + 978 + err = kc->clock_adj(which_clock, &ktx); 979 + 980 + if (!err && copy_to_user(utx, &ktx, sizeof(ktx))) 981 + return -EFAULT; 982 + 983 + return err; 993 984 } 994 985 995 986 SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, 996 987 struct timespec __user *, tp) 997 988 { 989 + struct k_clock *kc = clockid_to_kclock(which_clock); 998 990 struct timespec rtn_tp; 999 991 int error; 1000 992 1001 - if (invalid_clockid(which_clock)) 993 + if (!kc) 1002 994 return -EINVAL; 1003 995 1004 - error = CLOCK_DISPATCH(which_clock, clock_getres, 1005 - (which_clock, &rtn_tp)); 996 + error = kc->clock_getres(which_clock, &rtn_tp); 1006 997 1007 - if (!error && tp && copy_to_user(tp, &rtn_tp, sizeof (rtn_tp))) { 998 + if (!error && tp && copy_to_user(tp, &rtn_tp, sizeof (rtn_tp))) 1008 999 error = -EFAULT; 1009 - } 1010 1000 1011 1001 return error; 1012 1002 } ··· 1033 1009 const struct timespec __user *, rqtp, 1034 1010 struct timespec __user *, rmtp) 1035 1011 { 1012 + struct k_clock *kc = clockid_to_kclock(which_clock); 1036 1013 struct timespec t; 1037 1014 1038 - if (invalid_clockid(which_clock)) 1015 + if (!kc) 1039 1016 return -EINVAL; 1017 + if (!kc->nsleep) 1018 + return -ENANOSLEEP_NOTSUP; 1040 1019 1041 1020 if (copy_from_user(&t, rqtp, sizeof (struct timespec))) 1042 1021 return -EFAULT; ··· 1047 1020 if (!timespec_valid(&t)) 1048 1021 return -EINVAL; 1049 1022 1050 - return CLOCK_DISPATCH(which_clock, nsleep, 1051 - (which_clock, flags, &t, rmtp)); 1052 - } 1053 - 1054 - /* 1055 - * nanosleep_restart for monotonic and realtime clocks 1056 - */ 1057 - static int common_nsleep_restart(struct restart_block *restart_block) 1058 - { 1059 - return hrtimer_nanosleep_restart(restart_block); 1023 + return kc->nsleep(which_clock, flags, &t, rmtp); 1060 1024 } 1061 1025 1062 1026 /* 1063 1027 * This will restart clock_nanosleep. This is required only by 1064 1028 * compat_clock_nanosleep_restart for now. 1065 1029 */ 1066 - long 1067 - clock_nanosleep_restart(struct restart_block *restart_block) 1030 + long clock_nanosleep_restart(struct restart_block *restart_block) 1068 1031 { 1069 - clockid_t which_clock = restart_block->arg0; 1032 + clockid_t which_clock = restart_block->nanosleep.index; 1033 + struct k_clock *kc = clockid_to_kclock(which_clock); 1070 1034 1071 - return CLOCK_DISPATCH(which_clock, nsleep_restart, 1072 - (restart_block)); 1035 + if (WARN_ON_ONCE(!kc || !kc->nsleep_restart)) 1036 + return -EINVAL; 1037 + 1038 + return kc->nsleep_restart(restart_block); 1073 1039 }
+1 -19
kernel/time.c
··· 150 150 * various programs will get confused when the clock gets warped. 151 151 */ 152 152 153 - int do_sys_settimeofday(struct timespec *tv, struct timezone *tz) 153 + int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz) 154 154 { 155 155 static int firsttime = 1; 156 156 int error = 0; ··· 674 674 #endif 675 675 } 676 676 677 - 678 677 /** 679 678 * nsecs_to_jiffies - Convert nsecs in u64 to jiffies 680 679 * ··· 691 692 { 692 693 return (unsigned long)nsecs_to_jiffies64(n); 693 694 } 694 - 695 - #if (BITS_PER_LONG < 64) 696 - u64 get_jiffies_64(void) 697 - { 698 - unsigned long seq; 699 - u64 ret; 700 - 701 - do { 702 - seq = read_seqbegin(&xtime_lock); 703 - ret = jiffies_64; 704 - } while (read_seqretry(&xtime_lock, seq)); 705 - return ret; 706 - } 707 - EXPORT_SYMBOL(get_jiffies_64); 708 - #endif 709 - 710 - EXPORT_SYMBOL(jiffies); 711 695 712 696 /* 713 697 * Add two timespec values and do a safety check for overflow.
+2 -1
kernel/time/Makefile
··· 1 - obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o timecompare.o timeconv.o 1 + obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o timecompare.o 2 + obj-y += timeconv.o posix-clock.o 2 3 3 4 obj-$(CONFIG_GENERIC_CLOCKEVENTS_BUILD) += clockevents.o 4 5 obj-$(CONFIG_GENERIC_CLOCKEVENTS) += tick-common.o
-1
kernel/time/clockevents.c
··· 18 18 #include <linux/notifier.h> 19 19 #include <linux/smp.h> 20 20 #include <linux/sysdev.h> 21 - #include <linux/tick.h> 22 21 23 22 #include "tick-internal.h" 24 23
+20
kernel/time/jiffies.c
··· 22 22 ************************************************************************/ 23 23 #include <linux/clocksource.h> 24 24 #include <linux/jiffies.h> 25 + #include <linux/module.h> 25 26 #include <linux/init.h> 27 + 28 + #include "tick-internal.h" 26 29 27 30 /* The Jiffies based clocksource is the lowest common 28 31 * denominator clock source which should function on ··· 66 63 .mult = NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */ 67 64 .shift = JIFFIES_SHIFT, 68 65 }; 66 + 67 + #if (BITS_PER_LONG < 64) 68 + u64 get_jiffies_64(void) 69 + { 70 + unsigned long seq; 71 + u64 ret; 72 + 73 + do { 74 + seq = read_seqbegin(&xtime_lock); 75 + ret = jiffies_64; 76 + } while (read_seqretry(&xtime_lock, seq)); 77 + return ret; 78 + } 79 + EXPORT_SYMBOL(get_jiffies_64); 80 + #endif 81 + 82 + EXPORT_SYMBOL(jiffies); 69 83 70 84 static int __init init_jiffies_clocksource(void) 71 85 {
+13
kernel/time/ntp.c
··· 16 16 #include <linux/mm.h> 17 17 #include <linux/module.h> 18 18 19 + #include "tick-internal.h" 20 + 19 21 /* 20 22 * NTP timekeeping variables: 21 23 */ ··· 646 644 647 645 if (txc->modes & ADJ_STATUS && time_state != TIME_OK) 648 646 hrtimer_cancel(&leap_timer); 647 + } 648 + 649 + if (txc->modes & ADJ_SETOFFSET) { 650 + struct timespec delta; 651 + delta.tv_sec = txc->time.tv_sec; 652 + delta.tv_nsec = txc->time.tv_usec; 653 + if (!(txc->modes & ADJ_NANO)) 654 + delta.tv_nsec *= 1000; 655 + result = timekeeping_inject_offset(&delta); 656 + if (result) 657 + return result; 649 658 } 650 659 651 660 getnstimeofday(&ts);
+451
kernel/time/posix-clock.c
··· 1 + /* 2 + * posix-clock.c - support for dynamic clock devices 3 + * 4 + * Copyright (C) 2010 OMICRON electronics GmbH 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + * You should have received a copy of the GNU General Public License 17 + * along with this program; if not, write to the Free Software 18 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 + */ 20 + #include <linux/device.h> 21 + #include <linux/file.h> 22 + #include <linux/mutex.h> 23 + #include <linux/posix-clock.h> 24 + #include <linux/slab.h> 25 + #include <linux/syscalls.h> 26 + #include <linux/uaccess.h> 27 + 28 + static void delete_clock(struct kref *kref); 29 + 30 + /* 31 + * Returns NULL if the posix_clock instance attached to 'fp' is old and stale. 32 + */ 33 + static struct posix_clock *get_posix_clock(struct file *fp) 34 + { 35 + struct posix_clock *clk = fp->private_data; 36 + 37 + mutex_lock(&clk->mutex); 38 + 39 + if (!clk->zombie) 40 + return clk; 41 + 42 + mutex_unlock(&clk->mutex); 43 + 44 + return NULL; 45 + } 46 + 47 + static void put_posix_clock(struct posix_clock *clk) 48 + { 49 + mutex_unlock(&clk->mutex); 50 + } 51 + 52 + static ssize_t posix_clock_read(struct file *fp, char __user *buf, 53 + size_t count, loff_t *ppos) 54 + { 55 + struct posix_clock *clk = get_posix_clock(fp); 56 + int err = -EINVAL; 57 + 58 + if (!clk) 59 + return -ENODEV; 60 + 61 + if (clk->ops.read) 62 + err = clk->ops.read(clk, fp->f_flags, buf, count); 63 + 64 + put_posix_clock(clk); 65 + 66 + return err; 67 + } 68 + 69 + static unsigned int posix_clock_poll(struct file *fp, poll_table *wait) 70 + { 71 + struct posix_clock *clk = get_posix_clock(fp); 72 + int result = 0; 73 + 74 + if (!clk) 75 + return -ENODEV; 76 + 77 + if (clk->ops.poll) 78 + result = clk->ops.poll(clk, fp, wait); 79 + 80 + put_posix_clock(clk); 81 + 82 + return result; 83 + } 84 + 85 + static int posix_clock_fasync(int fd, struct file *fp, int on) 86 + { 87 + struct posix_clock *clk = get_posix_clock(fp); 88 + int err = 0; 89 + 90 + if (!clk) 91 + return -ENODEV; 92 + 93 + if (clk->ops.fasync) 94 + err = clk->ops.fasync(clk, fd, fp, on); 95 + 96 + put_posix_clock(clk); 97 + 98 + return err; 99 + } 100 + 101 + static int posix_clock_mmap(struct file *fp, struct vm_area_struct *vma) 102 + { 103 + struct posix_clock *clk = get_posix_clock(fp); 104 + int err = -ENODEV; 105 + 106 + if (!clk) 107 + return -ENODEV; 108 + 109 + if (clk->ops.mmap) 110 + err = clk->ops.mmap(clk, vma); 111 + 112 + put_posix_clock(clk); 113 + 114 + return err; 115 + } 116 + 117 + static long posix_clock_ioctl(struct file *fp, 118 + unsigned int cmd, unsigned long arg) 119 + { 120 + struct posix_clock *clk = get_posix_clock(fp); 121 + int err = -ENOTTY; 122 + 123 + if (!clk) 124 + return -ENODEV; 125 + 126 + if (clk->ops.ioctl) 127 + err = clk->ops.ioctl(clk, cmd, arg); 128 + 129 + put_posix_clock(clk); 130 + 131 + return err; 132 + } 133 + 134 + #ifdef CONFIG_COMPAT 135 + static long posix_clock_compat_ioctl(struct file *fp, 136 + unsigned int cmd, unsigned long arg) 137 + { 138 + struct posix_clock *clk = get_posix_clock(fp); 139 + int err = -ENOTTY; 140 + 141 + if (!clk) 142 + return -ENODEV; 143 + 144 + if (clk->ops.ioctl) 145 + err = clk->ops.ioctl(clk, cmd, arg); 146 + 147 + put_posix_clock(clk); 148 + 149 + return err; 150 + } 151 + #endif 152 + 153 + static int posix_clock_open(struct inode *inode, struct file *fp) 154 + { 155 + int err; 156 + struct posix_clock *clk = 157 + container_of(inode->i_cdev, struct posix_clock, cdev); 158 + 159 + mutex_lock(&clk->mutex); 160 + 161 + if (clk->zombie) { 162 + err = -ENODEV; 163 + goto out; 164 + } 165 + if (clk->ops.open) 166 + err = clk->ops.open(clk, fp->f_mode); 167 + else 168 + err = 0; 169 + 170 + if (!err) { 171 + kref_get(&clk->kref); 172 + fp->private_data = clk; 173 + } 174 + out: 175 + mutex_unlock(&clk->mutex); 176 + return err; 177 + } 178 + 179 + static int posix_clock_release(struct inode *inode, struct file *fp) 180 + { 181 + struct posix_clock *clk = fp->private_data; 182 + int err = 0; 183 + 184 + if (clk->ops.release) 185 + err = clk->ops.release(clk); 186 + 187 + kref_put(&clk->kref, delete_clock); 188 + 189 + fp->private_data = NULL; 190 + 191 + return err; 192 + } 193 + 194 + static const struct file_operations posix_clock_file_operations = { 195 + .owner = THIS_MODULE, 196 + .llseek = no_llseek, 197 + .read = posix_clock_read, 198 + .poll = posix_clock_poll, 199 + .unlocked_ioctl = posix_clock_ioctl, 200 + .open = posix_clock_open, 201 + .release = posix_clock_release, 202 + .fasync = posix_clock_fasync, 203 + .mmap = posix_clock_mmap, 204 + #ifdef CONFIG_COMPAT 205 + .compat_ioctl = posix_clock_compat_ioctl, 206 + #endif 207 + }; 208 + 209 + int posix_clock_register(struct posix_clock *clk, dev_t devid) 210 + { 211 + int err; 212 + 213 + kref_init(&clk->kref); 214 + mutex_init(&clk->mutex); 215 + 216 + cdev_init(&clk->cdev, &posix_clock_file_operations); 217 + clk->cdev.owner = clk->ops.owner; 218 + err = cdev_add(&clk->cdev, devid, 1); 219 + if (err) 220 + goto no_cdev; 221 + 222 + return err; 223 + no_cdev: 224 + mutex_destroy(&clk->mutex); 225 + return err; 226 + } 227 + EXPORT_SYMBOL_GPL(posix_clock_register); 228 + 229 + static void delete_clock(struct kref *kref) 230 + { 231 + struct posix_clock *clk = container_of(kref, struct posix_clock, kref); 232 + mutex_destroy(&clk->mutex); 233 + if (clk->release) 234 + clk->release(clk); 235 + } 236 + 237 + void posix_clock_unregister(struct posix_clock *clk) 238 + { 239 + cdev_del(&clk->cdev); 240 + 241 + mutex_lock(&clk->mutex); 242 + clk->zombie = true; 243 + mutex_unlock(&clk->mutex); 244 + 245 + kref_put(&clk->kref, delete_clock); 246 + } 247 + EXPORT_SYMBOL_GPL(posix_clock_unregister); 248 + 249 + struct posix_clock_desc { 250 + struct file *fp; 251 + struct posix_clock *clk; 252 + }; 253 + 254 + static int get_clock_desc(const clockid_t id, struct posix_clock_desc *cd) 255 + { 256 + struct file *fp = fget(CLOCKID_TO_FD(id)); 257 + int err = -EINVAL; 258 + 259 + if (!fp) 260 + return err; 261 + 262 + if (fp->f_op->open != posix_clock_open || !fp->private_data) 263 + goto out; 264 + 265 + cd->fp = fp; 266 + cd->clk = get_posix_clock(fp); 267 + 268 + err = cd->clk ? 0 : -ENODEV; 269 + out: 270 + if (err) 271 + fput(fp); 272 + return err; 273 + } 274 + 275 + static void put_clock_desc(struct posix_clock_desc *cd) 276 + { 277 + put_posix_clock(cd->clk); 278 + fput(cd->fp); 279 + } 280 + 281 + static int pc_clock_adjtime(clockid_t id, struct timex *tx) 282 + { 283 + struct posix_clock_desc cd; 284 + int err; 285 + 286 + err = get_clock_desc(id, &cd); 287 + if (err) 288 + return err; 289 + 290 + if ((cd.fp->f_mode & FMODE_WRITE) == 0) { 291 + err = -EACCES; 292 + goto out; 293 + } 294 + 295 + if (cd.clk->ops.clock_adjtime) 296 + err = cd.clk->ops.clock_adjtime(cd.clk, tx); 297 + else 298 + err = -EOPNOTSUPP; 299 + out: 300 + put_clock_desc(&cd); 301 + 302 + return err; 303 + } 304 + 305 + static int pc_clock_gettime(clockid_t id, struct timespec *ts) 306 + { 307 + struct posix_clock_desc cd; 308 + int err; 309 + 310 + err = get_clock_desc(id, &cd); 311 + if (err) 312 + return err; 313 + 314 + if (cd.clk->ops.clock_gettime) 315 + err = cd.clk->ops.clock_gettime(cd.clk, ts); 316 + else 317 + err = -EOPNOTSUPP; 318 + 319 + put_clock_desc(&cd); 320 + 321 + return err; 322 + } 323 + 324 + static int pc_clock_getres(clockid_t id, struct timespec *ts) 325 + { 326 + struct posix_clock_desc cd; 327 + int err; 328 + 329 + err = get_clock_desc(id, &cd); 330 + if (err) 331 + return err; 332 + 333 + if (cd.clk->ops.clock_getres) 334 + err = cd.clk->ops.clock_getres(cd.clk, ts); 335 + else 336 + err = -EOPNOTSUPP; 337 + 338 + put_clock_desc(&cd); 339 + 340 + return err; 341 + } 342 + 343 + static int pc_clock_settime(clockid_t id, const struct timespec *ts) 344 + { 345 + struct posix_clock_desc cd; 346 + int err; 347 + 348 + err = get_clock_desc(id, &cd); 349 + if (err) 350 + return err; 351 + 352 + if ((cd.fp->f_mode & FMODE_WRITE) == 0) { 353 + err = -EACCES; 354 + goto out; 355 + } 356 + 357 + if (cd.clk->ops.clock_settime) 358 + err = cd.clk->ops.clock_settime(cd.clk, ts); 359 + else 360 + err = -EOPNOTSUPP; 361 + out: 362 + put_clock_desc(&cd); 363 + 364 + return err; 365 + } 366 + 367 + static int pc_timer_create(struct k_itimer *kit) 368 + { 369 + clockid_t id = kit->it_clock; 370 + struct posix_clock_desc cd; 371 + int err; 372 + 373 + err = get_clock_desc(id, &cd); 374 + if (err) 375 + return err; 376 + 377 + if (cd.clk->ops.timer_create) 378 + err = cd.clk->ops.timer_create(cd.clk, kit); 379 + else 380 + err = -EOPNOTSUPP; 381 + 382 + put_clock_desc(&cd); 383 + 384 + return err; 385 + } 386 + 387 + static int pc_timer_delete(struct k_itimer *kit) 388 + { 389 + clockid_t id = kit->it_clock; 390 + struct posix_clock_desc cd; 391 + int err; 392 + 393 + err = get_clock_desc(id, &cd); 394 + if (err) 395 + return err; 396 + 397 + if (cd.clk->ops.timer_delete) 398 + err = cd.clk->ops.timer_delete(cd.clk, kit); 399 + else 400 + err = -EOPNOTSUPP; 401 + 402 + put_clock_desc(&cd); 403 + 404 + return err; 405 + } 406 + 407 + static void pc_timer_gettime(struct k_itimer *kit, struct itimerspec *ts) 408 + { 409 + clockid_t id = kit->it_clock; 410 + struct posix_clock_desc cd; 411 + 412 + if (get_clock_desc(id, &cd)) 413 + return; 414 + 415 + if (cd.clk->ops.timer_gettime) 416 + cd.clk->ops.timer_gettime(cd.clk, kit, ts); 417 + 418 + put_clock_desc(&cd); 419 + } 420 + 421 + static int pc_timer_settime(struct k_itimer *kit, int flags, 422 + struct itimerspec *ts, struct itimerspec *old) 423 + { 424 + clockid_t id = kit->it_clock; 425 + struct posix_clock_desc cd; 426 + int err; 427 + 428 + err = get_clock_desc(id, &cd); 429 + if (err) 430 + return err; 431 + 432 + if (cd.clk->ops.timer_settime) 433 + err = cd.clk->ops.timer_settime(cd.clk, kit, flags, ts, old); 434 + else 435 + err = -EOPNOTSUPP; 436 + 437 + put_clock_desc(&cd); 438 + 439 + return err; 440 + } 441 + 442 + struct k_clock clock_posix_dynamic = { 443 + .clock_getres = pc_clock_getres, 444 + .clock_set = pc_clock_settime, 445 + .clock_get = pc_clock_gettime, 446 + .clock_adj = pc_clock_adjtime, 447 + .timer_create = pc_timer_create, 448 + .timer_set = pc_timer_settime, 449 + .timer_del = pc_timer_delete, 450 + .timer_get = pc_timer_gettime, 451 + };
-1
kernel/time/tick-broadcast.c
··· 18 18 #include <linux/percpu.h> 19 19 #include <linux/profile.h> 20 20 #include <linux/sched.h> 21 - #include <linux/tick.h> 22 21 23 22 #include "tick-internal.h" 24 23
-1
kernel/time/tick-common.c
··· 18 18 #include <linux/percpu.h> 19 19 #include <linux/profile.h> 20 20 #include <linux/sched.h> 21 - #include <linux/tick.h> 22 21 23 22 #include <asm/irq_regs.h> 24 23
+9
kernel/time/tick-internal.h
··· 1 1 /* 2 2 * tick internal variable and functions used by low/high res code 3 3 */ 4 + #include <linux/hrtimer.h> 5 + #include <linux/tick.h> 6 + 7 + #ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD 4 8 5 9 #define TICK_DO_TIMER_NONE -1 6 10 #define TICK_DO_TIMER_BOOT -2 ··· 139 135 { 140 136 return !(dev->features & CLOCK_EVT_FEAT_DUMMY); 141 137 } 138 + 139 + #endif 140 + 141 + extern void do_timer(unsigned long ticks); 142 + extern seqlock_t xtime_lock;
-1
kernel/time/tick-oneshot.c
··· 18 18 #include <linux/percpu.h> 19 19 #include <linux/profile.h> 20 20 #include <linux/sched.h> 21 - #include <linux/tick.h> 22 21 23 22 #include "tick-internal.h" 24 23
-1
kernel/time/tick-sched.c
··· 19 19 #include <linux/percpu.h> 20 20 #include <linux/profile.h> 21 21 #include <linux/sched.h> 22 - #include <linux/tick.h> 23 22 #include <linux/module.h> 24 23 25 24 #include <asm/irq_regs.h>
+133 -8
kernel/time/timekeeping.c
··· 353 353 * 354 354 * Sets the time of day to the new time and update NTP and notify hrtimers 355 355 */ 356 - int do_settimeofday(struct timespec *tv) 356 + int do_settimeofday(const struct timespec *tv) 357 357 { 358 358 struct timespec ts_delta; 359 359 unsigned long flags; ··· 386 386 } 387 387 388 388 EXPORT_SYMBOL(do_settimeofday); 389 + 390 + 391 + /** 392 + * timekeeping_inject_offset - Adds or subtracts from the current time. 393 + * @tv: pointer to the timespec variable containing the offset 394 + * 395 + * Adds or subtracts an offset value from the current time. 396 + */ 397 + int timekeeping_inject_offset(struct timespec *ts) 398 + { 399 + unsigned long flags; 400 + 401 + if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC) 402 + return -EINVAL; 403 + 404 + write_seqlock_irqsave(&xtime_lock, flags); 405 + 406 + timekeeping_forward_now(); 407 + 408 + xtime = timespec_add(xtime, *ts); 409 + wall_to_monotonic = timespec_sub(wall_to_monotonic, *ts); 410 + 411 + timekeeper.ntp_error = 0; 412 + ntp_clear(); 413 + 414 + update_vsyscall(&xtime, &wall_to_monotonic, timekeeper.clock, 415 + timekeeper.mult); 416 + 417 + write_sequnlock_irqrestore(&xtime_lock, flags); 418 + 419 + /* signal hrtimers about time change */ 420 + clock_was_set(); 421 + 422 + return 0; 423 + } 424 + EXPORT_SYMBOL(timekeeping_inject_offset); 389 425 390 426 /** 391 427 * change_clocksource - Swaps clocksources if a new one is available ··· 815 779 * 816 780 * Called from the timer interrupt, must hold a write on xtime_lock. 817 781 */ 818 - void update_wall_time(void) 782 + static void update_wall_time(void) 819 783 { 820 784 struct clocksource *clock; 821 785 cycle_t offset; ··· 907 871 * getboottime - Return the real time of system boot. 908 872 * @ts: pointer to the timespec to be set 909 873 * 910 - * Returns the time of day in a timespec. 874 + * Returns the wall-time of boot in a timespec. 911 875 * 912 876 * This is based on the wall_to_monotonic offset and the total suspend 913 877 * time. Calls to settimeofday will affect the value returned (which ··· 924 888 set_normalized_timespec(ts, -boottime.tv_sec, -boottime.tv_nsec); 925 889 } 926 890 EXPORT_SYMBOL_GPL(getboottime); 891 + 892 + 893 + /** 894 + * get_monotonic_boottime - Returns monotonic time since boot 895 + * @ts: pointer to the timespec to be set 896 + * 897 + * Returns the monotonic time since boot in a timespec. 898 + * 899 + * This is similar to CLOCK_MONTONIC/ktime_get_ts, but also 900 + * includes the time spent in suspend. 901 + */ 902 + void get_monotonic_boottime(struct timespec *ts) 903 + { 904 + struct timespec tomono, sleep; 905 + unsigned int seq; 906 + s64 nsecs; 907 + 908 + WARN_ON(timekeeping_suspended); 909 + 910 + do { 911 + seq = read_seqbegin(&xtime_lock); 912 + *ts = xtime; 913 + tomono = wall_to_monotonic; 914 + sleep = total_sleep_time; 915 + nsecs = timekeeping_get_ns(); 916 + 917 + } while (read_seqretry(&xtime_lock, seq)); 918 + 919 + set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec + sleep.tv_sec, 920 + ts->tv_nsec + tomono.tv_nsec + sleep.tv_nsec + nsecs); 921 + } 922 + EXPORT_SYMBOL_GPL(get_monotonic_boottime); 923 + 924 + /** 925 + * ktime_get_boottime - Returns monotonic time since boot in a ktime 926 + * 927 + * Returns the monotonic time since boot in a ktime 928 + * 929 + * This is similar to CLOCK_MONTONIC/ktime_get, but also 930 + * includes the time spent in suspend. 931 + */ 932 + ktime_t ktime_get_boottime(void) 933 + { 934 + struct timespec ts; 935 + 936 + get_monotonic_boottime(&ts); 937 + return timespec_to_ktime(ts); 938 + } 939 + EXPORT_SYMBOL_GPL(ktime_get_boottime); 927 940 928 941 /** 929 942 * monotonic_to_bootbased - Convert the monotonic time to boot based. ··· 993 908 struct timespec __current_kernel_time(void) 994 909 { 995 910 return xtime; 996 - } 997 - 998 - struct timespec __get_wall_to_monotonic(void) 999 - { 1000 - return wall_to_monotonic; 1001 911 } 1002 912 1003 913 struct timespec current_kernel_time(void) ··· 1025 945 set_normalized_timespec(&now, now.tv_sec + mono.tv_sec, 1026 946 now.tv_nsec + mono.tv_nsec); 1027 947 return now; 948 + } 949 + 950 + /* 951 + * The 64-bit jiffies value is not atomic - you MUST NOT read it 952 + * without sampling the sequence number in xtime_lock. 953 + * jiffies is defined in the linker script... 954 + */ 955 + void do_timer(unsigned long ticks) 956 + { 957 + jiffies_64 += ticks; 958 + update_wall_time(); 959 + calc_global_load(ticks); 960 + } 961 + 962 + /** 963 + * get_xtime_and_monotonic_and_sleep_offset() - get xtime, wall_to_monotonic, 964 + * and sleep offsets. 965 + * @xtim: pointer to timespec to be set with xtime 966 + * @wtom: pointer to timespec to be set with wall_to_monotonic 967 + * @sleep: pointer to timespec to be set with time in suspend 968 + */ 969 + void get_xtime_and_monotonic_and_sleep_offset(struct timespec *xtim, 970 + struct timespec *wtom, struct timespec *sleep) 971 + { 972 + unsigned long seq; 973 + 974 + do { 975 + seq = read_seqbegin(&xtime_lock); 976 + *xtim = xtime; 977 + *wtom = wall_to_monotonic; 978 + *sleep = total_sleep_time; 979 + } while (read_seqretry(&xtime_lock, seq)); 980 + } 981 + 982 + /** 983 + * xtime_update() - advances the timekeeping infrastructure 984 + * @ticks: number of ticks, that have elapsed since the last call. 985 + * 986 + * Must be called with interrupts disabled. 987 + */ 988 + void xtime_update(unsigned long ticks) 989 + { 990 + write_seqlock(&xtime_lock); 991 + do_timer(ticks); 992 + write_sequnlock(&xtime_lock); 1028 993 }
-13
kernel/timer.c
··· 1324 1324 raise_softirq(TIMER_SOFTIRQ); 1325 1325 } 1326 1326 1327 - /* 1328 - * The 64-bit jiffies value is not atomic - you MUST NOT read it 1329 - * without sampling the sequence number in xtime_lock. 1330 - * jiffies is defined in the linker script... 1331 - */ 1332 - 1333 - void do_timer(unsigned long ticks) 1334 - { 1335 - jiffies_64 += ticks; 1336 - update_wall_time(); 1337 - calc_global_load(ticks); 1338 - } 1339 - 1340 1327 #ifdef __ARCH_WANT_SYS_ALARM 1341 1328 1342 1329 /*
+1 -1
security/commoncap.c
··· 93 93 * Determine whether the current process may set the system clock and timezone 94 94 * information, returning 0 if permission granted, -ve if denied. 95 95 */ 96 - int cap_settime(struct timespec *ts, struct timezone *tz) 96 + int cap_settime(const struct timespec *ts, const struct timezone *tz) 97 97 { 98 98 if (!capable(CAP_SYS_TIME)) 99 99 return -EPERM;
+1 -1
security/security.c
··· 201 201 return security_ops->syslog(type); 202 202 } 203 203 204 - int security_settime(struct timespec *ts, struct timezone *tz) 204 + int security_settime(const struct timespec *ts, const struct timezone *tz) 205 205 { 206 206 return security_ops->settime(ts, tz); 207 207 }