Lines Matching full:timer
13 #include <trace/events/timer.h>
22 static void posix_cpu_timer_rearm(struct k_itimer *timer);
34 * Called after updating RLIMIT_CPU to run cpu timer and update
67 * If the encoded PID is 0, then the timer is targeted at current in pid_for_clock()
113 static inline struct task_struct *cpu_timer_task_rcu(struct k_itimer *timer) in cpu_timer_task_rcu() argument
115 return pid_task(timer->it.cpu.pid, clock_pid_type(timer->it_clock)); in cpu_timer_task_rcu()
122 static u64 bump_cpu_timer(struct k_itimer *timer, u64 now) in bump_cpu_timer() argument
124 u64 delta, incr, expires = timer->it.cpu.node.expires; in bump_cpu_timer()
127 if (!timer->it_interval) in bump_cpu_timer()
133 incr = timer->it_interval; in bump_cpu_timer()
144 timer->it.cpu.node.expires += incr; in bump_cpu_timer()
145 timer->it_overrun += 1LL << i; in bump_cpu_timer()
148 return timer->it.cpu.node.expires; in bump_cpu_timer()
269 * timer. That means group cputime accounting is already active. Called
290 * CPU timers armed. Before starting a timer it's required to check whether
308 * The POSIX timer interface allows for absolute time expiry in thread_group_start_cputime()
310 * to synchronize the timer to the clock every time we start it. in thread_group_start_cputime()
383 * Validate the clockid_t for a new CPU-clock timer, and initialize the timer.
385 * new timer already all-zeros initialized.
400 * If posix timer expiry is handled in task work context then in posix_cpu_timer_create()
401 * timer::it_lock can be taken without disabling interrupts as all in posix_cpu_timer_create()
403 * lock class key otherwise regular posix timer expiry would record in posix_cpu_timer_create()
417 static struct posix_cputimer_base *timer_base(struct k_itimer *timer, in timer_base() argument
420 int clkidx = CPUCLOCK_WHICH(timer->it_clock); in timer_base()
422 if (CPUCLOCK_PERTHREAD(timer->it_clock)) in timer_base()
434 static void trigger_base_recalc_expires(struct k_itimer *timer, in trigger_base_recalc_expires() argument
437 struct posix_cputimer_base *base = timer_base(timer, tsk); in trigger_base_recalc_expires()
443 * Dequeue the timer and reset the base if it was its earliest expiration.
448 * If another timer gets queued between this and the next tick, its
452 static void disarm_timer(struct k_itimer *timer, struct task_struct *p) in disarm_timer() argument
454 struct cpu_timer *ctmr = &timer->it.cpu; in disarm_timer()
460 base = timer_base(timer, p); in disarm_timer()
462 trigger_base_recalc_expires(timer, p); in disarm_timer()
467 * Clean up a CPU-clock timer that is about to be destroyed.
468 * This is called from timer deletion with the timer already locked.
469 * If we return TIMER_RETRY, it's necessary to release the timer's lock
470 * and try again. (This happens when the timer is in the middle of firing.)
472 static int posix_cpu_timer_del(struct k_itimer *timer) in posix_cpu_timer_del() argument
474 struct cpu_timer *ctmr = &timer->it.cpu; in posix_cpu_timer_del()
481 p = cpu_timer_task_rcu(timer); in posix_cpu_timer_del()
487 * thread timer list entry concurrent read/writes. in posix_cpu_timer_del()
493 * should have removed this timer from the timer queue. in posix_cpu_timer_del()
497 if (timer->it.cpu.firing) in posix_cpu_timer_del()
500 disarm_timer(timer, p); in posix_cpu_timer_del()
554 * Insert the timer on the appropriate list before any timers that
557 static void arm_timer(struct k_itimer *timer, struct task_struct *p) in arm_timer() argument
559 struct posix_cputimer_base *base = timer_base(timer, p); in arm_timer()
560 struct cpu_timer *ctmr = &timer->it.cpu; in arm_timer()
567 * We are the new earliest-expiring POSIX 1.b timer, hence in arm_timer()
575 if (CPUCLOCK_PERTHREAD(timer->it_clock)) in arm_timer()
582 * The timer is locked, fire it and arrange for its reload.
584 static void cpu_timer_fire(struct k_itimer *timer) in cpu_timer_fire() argument
586 struct cpu_timer *ctmr = &timer->it.cpu; in cpu_timer_fire()
588 if ((timer->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE) { in cpu_timer_fire()
593 } else if (unlikely(timer->sigq == NULL)) { in cpu_timer_fire()
596 * not a normal timer from sys_timer_create. in cpu_timer_fire()
598 wake_up_process(timer->it_process); in cpu_timer_fire()
600 } else if (!timer->it_interval) { in cpu_timer_fire()
602 * One-shot timer. Clear it as soon as it's fired. in cpu_timer_fire()
604 posix_timer_event(timer, 0); in cpu_timer_fire()
606 } else if (posix_timer_event(timer, ++timer->it_requeue_pending)) { in cpu_timer_fire()
610 * reload the timer. But we need to keep it in cpu_timer_fire()
613 posix_cpu_timer_rearm(timer); in cpu_timer_fire()
614 ++timer->it_requeue_pending; in cpu_timer_fire()
620 * This is called with the timer locked and interrupts disabled.
621 * If we return TIMER_RETRY, it's necessary to release the timer's lock
622 * and try again. (This happens when the timer is in the middle of firing.)
624 static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags, in posix_cpu_timer_set() argument
627 clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock); in posix_cpu_timer_set()
629 struct cpu_timer *ctmr = &timer->it.cpu; in posix_cpu_timer_set()
636 p = cpu_timer_task_rcu(timer); in posix_cpu_timer_set()
667 * Disarm any old timer after extracting its expiry time. in posix_cpu_timer_set()
669 old_incr = timer->it_interval; in posix_cpu_timer_set()
672 if (unlikely(timer->it.cpu.firing)) { in posix_cpu_timer_set()
673 timer->it.cpu.firing = -1; in posix_cpu_timer_set()
683 * timer, we need a sample to balance the thread expiry in posix_cpu_timer_set()
687 if (CPUCLOCK_PERTHREAD(timer->it_clock)) in posix_cpu_timer_set()
698 * Update the timer in case it has overrun already. in posix_cpu_timer_set()
700 * with the next reloaded timer already ticking, in posix_cpu_timer_set()
704 u64 exp = bump_cpu_timer(timer, val); in posix_cpu_timer_set()
718 * We are colliding with the timer actually firing. in posix_cpu_timer_set()
719 * Punt after filling in the timer's old value, and in posix_cpu_timer_set()
733 * For a timer with no notification action, we don't actually in posix_cpu_timer_set()
734 * arm the timer (we'll just fake it for timer_gettime). in posix_cpu_timer_set()
738 arm_timer(timer, p); in posix_cpu_timer_set()
746 timer->it_interval = timespec64_to_ktime(new->it_interval); in posix_cpu_timer_set()
749 * This acts as a modification timestamp for the timer, in posix_cpu_timer_set()
751 * that we have reset the timer manually. in posix_cpu_timer_set()
753 timer->it_requeue_pending = (timer->it_requeue_pending + 2) & in posix_cpu_timer_set()
755 timer->it_overrun_last = 0; in posix_cpu_timer_set()
756 timer->it_overrun = -1; in posix_cpu_timer_set()
765 cpu_timer_fire(timer); in posix_cpu_timer_set()
777 trigger_base_recalc_expires(timer, p); in posix_cpu_timer_set()
789 static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp) in posix_cpu_timer_get() argument
791 clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock); in posix_cpu_timer_get()
792 struct cpu_timer *ctmr = &timer->it.cpu; in posix_cpu_timer_get()
797 p = cpu_timer_task_rcu(timer); in posix_cpu_timer_get()
804 itp->it_interval = ktime_to_timespec64(timer->it_interval); in posix_cpu_timer_get()
812 if (CPUCLOCK_PERTHREAD(timer->it_clock)) in posix_cpu_timer_get()
821 * The timer should have expired already, but the firing in posix_cpu_timer_get()
983 * RLIMIT_CPU) nothing to check. Also skip the process wide timer in check_process_timers()
1044 * when the last timer signal was delivered and we have to reload the timer.
1046 static void posix_cpu_timer_rearm(struct k_itimer *timer) in posix_cpu_timer_rearm() argument
1048 clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock); in posix_cpu_timer_rearm()
1055 p = cpu_timer_task_rcu(timer); in posix_cpu_timer_rearm()
1059 /* Protect timer list r/w in arm_timer() */ in posix_cpu_timer_rearm()
1065 * Fetch the current sample and update the timer's expiry time. in posix_cpu_timer_rearm()
1067 if (CPUCLOCK_PERTHREAD(timer->it_clock)) in posix_cpu_timer_rearm()
1072 bump_cpu_timer(timer, now); in posix_cpu_timer_rearm()
1077 arm_timer(timer, p); in posix_cpu_timer_rearm()
1112 * true if a timer has expired, else return false.
1135 * acquire the sighand lock to handle timer expiry. in fastpath_timer_check()
1139 * the change yet, the timer checks are delayed until the next in fastpath_timer_check()
1141 * timer. This isn't an issue in practice because these types of in fastpath_timer_check()
1238 * newly expired timers, reenable the fast path check in the timer in posix_cpu_timers_enable_work()
1273 struct k_itimer *timer, *next; in handle_posix_cpu_timers() local
1299 * The above timer checks have updated the expiry cache and in handle_posix_cpu_timers()
1302 * consistent. So the next timer interrupt fastpath check in handle_posix_cpu_timers()
1305 * If timer expiry runs in the timer interrupt context then in handle_posix_cpu_timers()
1311 * If timer expiry is deferred to task work context then in handle_posix_cpu_timers()
1320 * work ignored posix CPU timer handling because the in handle_posix_cpu_timers()
1323 * ticks have happened since the start of the timer in handle_posix_cpu_timers()
1331 * We must release sighand lock before taking any timer's lock. in handle_posix_cpu_timers()
1332 * There is a potential race with timer deletion here, as the in handle_posix_cpu_timers()
1334 * the firing flag in each timer, so that a deletion attempt in handle_posix_cpu_timers()
1335 * that gets the timer lock before we do will give it up and in handle_posix_cpu_timers()
1336 * spin until we've taken care of that timer below. in handle_posix_cpu_timers()
1343 * each timer's lock before clearing its firing flag, so no in handle_posix_cpu_timers()
1344 * timer call will interfere. in handle_posix_cpu_timers()
1346 list_for_each_entry_safe(timer, next, &firing, it.cpu.elist) { in handle_posix_cpu_timers()
1353 * because all other operations on timer::it_lock happen in in handle_posix_cpu_timers()
1356 spin_lock(&timer->it_lock); in handle_posix_cpu_timers()
1357 list_del_init(&timer->it.cpu.elist); in handle_posix_cpu_timers()
1358 cpu_firing = timer->it.cpu.firing; in handle_posix_cpu_timers()
1359 timer->it.cpu.firing = 0; in handle_posix_cpu_timers()
1362 * of the timer, which already reported this in handle_posix_cpu_timers()
1366 cpu_timer_fire(timer); in handle_posix_cpu_timers()
1367 spin_unlock(&timer->it_lock); in handle_posix_cpu_timers()
1372 * This is called from the timer interrupt handler. The irq handler has
1434 * Update expiration cache if this is the earliest timer. CPUCLOCK_PROF in set_process_cpu_timer()
1447 struct k_itimer timer; in do_cpu_nanosleep() local
1452 * Set up a temporary timer and then wait for it to go off. in do_cpu_nanosleep()
1454 memset(&timer, 0, sizeof timer); in do_cpu_nanosleep()
1455 spin_lock_init(&timer.it_lock); in do_cpu_nanosleep()
1456 timer.it_clock = which_clock; in do_cpu_nanosleep()
1457 timer.it_overrun = -1; in do_cpu_nanosleep()
1458 error = posix_cpu_timer_create(&timer); in do_cpu_nanosleep()
1459 timer.it_process = current; in do_cpu_nanosleep()
1468 spin_lock_irq(&timer.it_lock); in do_cpu_nanosleep()
1469 error = posix_cpu_timer_set(&timer, flags, &it, NULL); in do_cpu_nanosleep()
1471 spin_unlock_irq(&timer.it_lock); in do_cpu_nanosleep()
1476 if (!cpu_timer_getexpires(&timer.it.cpu)) { in do_cpu_nanosleep()
1478 * Our timer fired and was reset, below in do_cpu_nanosleep()
1481 posix_cpu_timer_del(&timer); in do_cpu_nanosleep()
1482 spin_unlock_irq(&timer.it_lock); in do_cpu_nanosleep()
1490 spin_unlock_irq(&timer.it_lock); in do_cpu_nanosleep()
1492 spin_lock_irq(&timer.it_lock); in do_cpu_nanosleep()
1498 expires = cpu_timer_getexpires(&timer.it.cpu); in do_cpu_nanosleep()
1499 error = posix_cpu_timer_set(&timer, 0, &zero_it, &it); in do_cpu_nanosleep()
1502 * Timer is now unarmed, deletion can not fail. in do_cpu_nanosleep()
1504 posix_cpu_timer_del(&timer); in do_cpu_nanosleep()
1506 spin_unlock_irq(&timer.it_lock); in do_cpu_nanosleep()
1510 * We need to handle case when timer was or is in the in do_cpu_nanosleep()
1514 spin_lock_irq(&timer.it_lock); in do_cpu_nanosleep()
1515 error = posix_cpu_timer_del(&timer); in do_cpu_nanosleep()
1516 spin_unlock_irq(&timer.it_lock); in do_cpu_nanosleep()
1591 static int process_cpu_timer_create(struct k_itimer *timer) in process_cpu_timer_create() argument
1593 timer->it_clock = PROCESS_CLOCK; in process_cpu_timer_create()
1594 return posix_cpu_timer_create(timer); in process_cpu_timer_create()
1611 static int thread_cpu_timer_create(struct k_itimer *timer) in thread_cpu_timer_create() argument
1613 timer->it_clock = THREAD_CLOCK; in thread_cpu_timer_create()
1614 return posix_cpu_timer_create(timer); in thread_cpu_timer_create()