Lines Matching full:timer

13 #include <trace/events/timer.h>
21 static void posix_cpu_timer_rearm(struct k_itimer *timer);
33 * Called after updating RLIMIT_CPU to run cpu timer and update
60 * If the encoded PID is 0, then the timer is targeted at current in pid_for_clock()
106 static inline struct task_struct *cpu_timer_task_rcu(struct k_itimer *timer) in cpu_timer_task_rcu() argument
108 return pid_task(timer->it.cpu.pid, clock_pid_type(timer->it_clock)); in cpu_timer_task_rcu()
115 static u64 bump_cpu_timer(struct k_itimer *timer, u64 now) in bump_cpu_timer() argument
117 u64 delta, incr, expires = timer->it.cpu.node.expires; in bump_cpu_timer()
120 if (!timer->it_interval) in bump_cpu_timer()
126 incr = timer->it_interval; in bump_cpu_timer()
137 timer->it.cpu.node.expires += incr; in bump_cpu_timer()
138 timer->it_overrun += 1LL << i; in bump_cpu_timer()
141 return timer->it.cpu.node.expires; in bump_cpu_timer()
262 * timer. That means group cputime accounting is already active. Called
283 * CPU timers armed. Before starting a timer it's required to check whether
299 * The POSIX timer interface allows for absolute time expiry in thread_group_start_cputime()
301 * to synchronize the timer to the clock every time we start it. in thread_group_start_cputime()
374 * Validate the clockid_t for a new CPU-clock timer, and initialize the timer.
376 * new timer already all-zeros initialized.
391 * If posix timer expiry is handled in task work context then in posix_cpu_timer_create()
392 * timer::it_lock can be taken without disabling interrupts as all in posix_cpu_timer_create()
394 * lock class key otherwise regular posix timer expiry would record in posix_cpu_timer_create()
409 * Clean up a CPU-clock timer that is about to be destroyed.
410 * This is called from timer deletion with the timer already locked.
411 * If we return TIMER_RETRY, it's necessary to release the timer's lock
412 * and try again. (This happens when the timer is in the middle of firing.)
414 static int posix_cpu_timer_del(struct k_itimer *timer) in posix_cpu_timer_del() argument
416 struct cpu_timer *ctmr = &timer->it.cpu; in posix_cpu_timer_del()
423 p = cpu_timer_task_rcu(timer); in posix_cpu_timer_del()
429 * thread timer list entry concurrent read/writes. in posix_cpu_timer_del()
435 * should have removed this timer from the timer queue. in posix_cpu_timer_del()
439 if (timer->it.cpu.firing) in posix_cpu_timer_del()
496 * Insert the timer on the appropriate list before any timers that
499 static void arm_timer(struct k_itimer *timer, struct task_struct *p) in arm_timer() argument
501 int clkidx = CPUCLOCK_WHICH(timer->it_clock); in arm_timer()
502 struct cpu_timer *ctmr = &timer->it.cpu; in arm_timer()
506 if (CPUCLOCK_PERTHREAD(timer->it_clock)) in arm_timer()
515 * We are the new earliest-expiring POSIX 1.b timer, hence in arm_timer()
523 if (CPUCLOCK_PERTHREAD(timer->it_clock)) in arm_timer()
530 * The timer is locked, fire it and arrange for its reload.
532 static void cpu_timer_fire(struct k_itimer *timer) in cpu_timer_fire() argument
534 struct cpu_timer *ctmr = &timer->it.cpu; in cpu_timer_fire()
536 if ((timer->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE) { in cpu_timer_fire()
541 } else if (unlikely(timer->sigq == NULL)) { in cpu_timer_fire()
544 * not a normal timer from sys_timer_create. in cpu_timer_fire()
546 wake_up_process(timer->it_process); in cpu_timer_fire()
548 } else if (!timer->it_interval) { in cpu_timer_fire()
550 * One-shot timer. Clear it as soon as it's fired. in cpu_timer_fire()
552 posix_timer_event(timer, 0); in cpu_timer_fire()
554 } else if (posix_timer_event(timer, ++timer->it_requeue_pending)) { in cpu_timer_fire()
558 * reload the timer. But we need to keep it in cpu_timer_fire()
561 posix_cpu_timer_rearm(timer); in cpu_timer_fire()
562 ++timer->it_requeue_pending; in cpu_timer_fire()
568 * This is called with the timer locked and interrupts disabled.
569 * If we return TIMER_RETRY, it's necessary to release the timer's lock
570 * and try again. (This happens when the timer is in the middle of firing.)
572 static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags, in posix_cpu_timer_set() argument
575 clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock); in posix_cpu_timer_set()
577 struct cpu_timer *ctmr = &timer->it.cpu; in posix_cpu_timer_set()
584 p = cpu_timer_task_rcu(timer); in posix_cpu_timer_set()
615 * Disarm any old timer after extracting its expiry time. in posix_cpu_timer_set()
617 old_incr = timer->it_interval; in posix_cpu_timer_set()
620 if (unlikely(timer->it.cpu.firing)) { in posix_cpu_timer_set()
621 timer->it.cpu.firing = -1; in posix_cpu_timer_set()
631 * timer, we need a sample to balance the thread expiry in posix_cpu_timer_set()
635 if (CPUCLOCK_PERTHREAD(timer->it_clock)) in posix_cpu_timer_set()
646 * Update the timer in case it has overrun already. in posix_cpu_timer_set()
648 * with the next reloaded timer already ticking, in posix_cpu_timer_set()
652 u64 exp = bump_cpu_timer(timer, val); in posix_cpu_timer_set()
666 * We are colliding with the timer actually firing. in posix_cpu_timer_set()
667 * Punt after filling in the timer's old value, and in posix_cpu_timer_set()
681 * For a timer with no notification action, we don't actually in posix_cpu_timer_set()
682 * arm the timer (we'll just fake it for timer_gettime). in posix_cpu_timer_set()
686 arm_timer(timer, p); in posix_cpu_timer_set()
694 timer->it_interval = timespec64_to_ktime(new->it_interval); in posix_cpu_timer_set()
697 * This acts as a modification timestamp for the timer, in posix_cpu_timer_set()
699 * that we have reset the timer manually. in posix_cpu_timer_set()
701 timer->it_requeue_pending = (timer->it_requeue_pending + 2) & in posix_cpu_timer_set()
703 timer->it_overrun_last = 0; in posix_cpu_timer_set()
704 timer->it_overrun = -1; in posix_cpu_timer_set()
712 cpu_timer_fire(timer); in posix_cpu_timer_set()
724 static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp) in posix_cpu_timer_get() argument
726 clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock); in posix_cpu_timer_get()
727 struct cpu_timer *ctmr = &timer->it.cpu; in posix_cpu_timer_get()
732 p = cpu_timer_task_rcu(timer); in posix_cpu_timer_get()
739 itp->it_interval = ktime_to_timespec64(timer->it_interval); in posix_cpu_timer_get()
747 if (CPUCLOCK_PERTHREAD(timer->it_clock)) in posix_cpu_timer_get()
756 * The timer should have expired already, but the firing in posix_cpu_timer_get()
918 * RLIMIT_CPU) nothing to check. Also skip the process wide timer in check_process_timers()
979 * when the last timer signal was delivered and we have to reload the timer.
981 static void posix_cpu_timer_rearm(struct k_itimer *timer) in posix_cpu_timer_rearm() argument
983 clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock); in posix_cpu_timer_rearm()
990 p = cpu_timer_task_rcu(timer); in posix_cpu_timer_rearm()
995 * Fetch the current sample and update the timer's expiry time. in posix_cpu_timer_rearm()
997 if (CPUCLOCK_PERTHREAD(timer->it_clock)) in posix_cpu_timer_rearm()
1002 bump_cpu_timer(timer, now); in posix_cpu_timer_rearm()
1004 /* Protect timer list r/w in arm_timer() */ in posix_cpu_timer_rearm()
1012 arm_timer(timer, p); in posix_cpu_timer_rearm()
1047 * true if a timer has expired, else return false.
1070 * acquire the sighand lock to handle timer expiry. in fastpath_timer_check()
1074 * the change yet, the timer checks are delayed until the next in fastpath_timer_check()
1076 * timer. This isn't an issue in practice because these types of in fastpath_timer_check()
1158 * newly expired timers, reenable the fast path check in the timer in posix_cpu_timers_enable_work()
1193 struct k_itimer *timer, *next; in handle_posix_cpu_timers() local
1219 * The above timer checks have updated the exipry cache and in handle_posix_cpu_timers()
1222 * consistent. So the next timer interrupt fastpath check in handle_posix_cpu_timers()
1225 * If timer expiry runs in the timer interrupt context then in handle_posix_cpu_timers()
1231 * If timer expiry is deferred to task work context then in handle_posix_cpu_timers()
1240 * work ignored posix CPU timer handling because the in handle_posix_cpu_timers()
1243 * ticks have happened since the start of the timer in handle_posix_cpu_timers()
1251 * We must release sighand lock before taking any timer's lock. in handle_posix_cpu_timers()
1252 * There is a potential race with timer deletion here, as the in handle_posix_cpu_timers()
1254 * the firing flag in each timer, so that a deletion attempt in handle_posix_cpu_timers()
1255 * that gets the timer lock before we do will give it up and in handle_posix_cpu_timers()
1256 * spin until we've taken care of that timer below. in handle_posix_cpu_timers()
1263 * each timer's lock before clearing its firing flag, so no in handle_posix_cpu_timers()
1264 * timer call will interfere. in handle_posix_cpu_timers()
1266 list_for_each_entry_safe(timer, next, &firing, it.cpu.elist) { in handle_posix_cpu_timers()
1273 * because all other operations on timer::it_lock happen in in handle_posix_cpu_timers()
1276 spin_lock(&timer->it_lock); in handle_posix_cpu_timers()
1277 list_del_init(&timer->it.cpu.elist); in handle_posix_cpu_timers()
1278 cpu_firing = timer->it.cpu.firing; in handle_posix_cpu_timers()
1279 timer->it.cpu.firing = 0; in handle_posix_cpu_timers()
1282 * of the timer, which already reported this in handle_posix_cpu_timers()
1286 cpu_timer_fire(timer); in handle_posix_cpu_timers()
1287 spin_unlock(&timer->it_lock); in handle_posix_cpu_timers()
1292 * This is called from the timer interrupt handler. The irq handler has
1355 * Update expiration cache if this is the earliest timer. CPUCLOCK_PROF in set_process_cpu_timer()
1368 struct k_itimer timer; in do_cpu_nanosleep() local
1373 * Set up a temporary timer and then wait for it to go off. in do_cpu_nanosleep()
1375 memset(&timer, 0, sizeof timer); in do_cpu_nanosleep()
1376 spin_lock_init(&timer.it_lock); in do_cpu_nanosleep()
1377 timer.it_clock = which_clock; in do_cpu_nanosleep()
1378 timer.it_overrun = -1; in do_cpu_nanosleep()
1379 error = posix_cpu_timer_create(&timer); in do_cpu_nanosleep()
1380 timer.it_process = current; in do_cpu_nanosleep()
1389 spin_lock_irq(&timer.it_lock); in do_cpu_nanosleep()
1390 error = posix_cpu_timer_set(&timer, flags, &it, NULL); in do_cpu_nanosleep()
1392 spin_unlock_irq(&timer.it_lock); in do_cpu_nanosleep()
1397 if (!cpu_timer_getexpires(&timer.it.cpu)) { in do_cpu_nanosleep()
1399 * Our timer fired and was reset, below in do_cpu_nanosleep()
1402 posix_cpu_timer_del(&timer); in do_cpu_nanosleep()
1403 spin_unlock_irq(&timer.it_lock); in do_cpu_nanosleep()
1411 spin_unlock_irq(&timer.it_lock); in do_cpu_nanosleep()
1413 spin_lock_irq(&timer.it_lock); in do_cpu_nanosleep()
1419 expires = cpu_timer_getexpires(&timer.it.cpu); in do_cpu_nanosleep()
1420 error = posix_cpu_timer_set(&timer, 0, &zero_it, &it); in do_cpu_nanosleep()
1423 * Timer is now unarmed, deletion can not fail. in do_cpu_nanosleep()
1425 posix_cpu_timer_del(&timer); in do_cpu_nanosleep()
1427 spin_unlock_irq(&timer.it_lock); in do_cpu_nanosleep()
1431 * We need to handle case when timer was or is in the in do_cpu_nanosleep()
1435 spin_lock_irq(&timer.it_lock); in do_cpu_nanosleep()
1436 error = posix_cpu_timer_del(&timer); in do_cpu_nanosleep()
1437 spin_unlock_irq(&timer.it_lock); in do_cpu_nanosleep()
1512 static int process_cpu_timer_create(struct k_itimer *timer) in process_cpu_timer_create() argument
1514 timer->it_clock = PROCESS_CLOCK; in process_cpu_timer_create()
1515 return posix_cpu_timer_create(timer); in process_cpu_timer_create()
1532 static int thread_cpu_timer_create(struct k_itimer *timer) in thread_cpu_timer_create() argument
1534 timer->it_clock = THREAD_CLOCK; in thread_cpu_timer_create()
1535 return posix_cpu_timer_create(timer); in thread_cpu_timer_create()