• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-WNDR4500-V1.0.1.40_1.0.68/src/linux/linux-2.6/kernel/

Lines Matching refs:timer

11  *  kernel/timer.c, hrtimers provide finer resolution and accuracy
23 * based on kernel/timer.c
81 * The timer bases:
83 * Note: If we want to add new timer bases, we have to skip the two
160 * Helper function to check, whether the timer is running the callback
163 static inline int hrtimer_callback_running(struct hrtimer *timer)
165 return timer->state & HRTIMER_STATE_CALLBACK;
176 * means that all timers which are tied to this base via timer->base are
182 * When the timer's base is locked, and the timer removed from list, it is
183 * possible to set timer->base = NULL and drop the lock: the timer remains
187 struct hrtimer_clock_base *lock_hrtimer_base(const struct hrtimer *timer,
193 base = timer->base;
196 if (likely(base == timer->base))
198 /* The timer has migrated to another CPU: */
206 * Switch the timer base to the current CPU when possible.
209 switch_hrtimer_base(struct hrtimer *timer, struct hrtimer_clock_base *base)
219 * We are trying to schedule the timer on the local CPU.
220 * However we can't change timer's base while it is running,
223 * code will take care of this when the timer function has
225 * the timer is enqueued.
227 if (unlikely(hrtimer_callback_running(timer)))
231 timer->base = NULL;
234 timer->base = new_base;
242 lock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
244 struct hrtimer_clock_base *base = timer->base;
308 /* High resolution timer related functions */
312 * High resolution timer enabled ?
362 struct hrtimer *timer;
366 timer = rb_entry(base->first, struct hrtimer, node);
367 expires = ktime_sub(timer->expires, base->offset);
379 * When a timer is enqueued and expires earlier than the already enqueued
380 * timers, we have to check, whether it expires earlier than the timer for
385 static int hrtimer_reprogram(struct hrtimer *timer,
389 ktime_t expires = ktime_sub(timer->expires, base->offset);
394 * device. The timer callback is either running on a different CPU or
399 if (hrtimer_callback_running(timer))
453 * We might have to reprogram the high resolution timer interrupt. On
455 * resolution timer interrupts. On UP we just disable interrupts and
465 * During resume we might have to reprogram the high resolution timer
477 * Check, whether the timer is on the callback pending list
479 static inline int hrtimer_cb_pending(const struct hrtimer *timer)
481 return timer->state & HRTIMER_STATE_PENDING;
485 * Remove a timer from the callback pending list
487 static inline void hrtimer_remove_cb_pending(struct hrtimer *timer)
489 list_del_init(&timer->cb_entry);
505 static inline void hrtimer_init_timer_hres(struct hrtimer *timer)
507 INIT_LIST_HEAD(&timer->cb_entry);
513 * check happens. The timer gets enqueued into the rbtree. The reprogramming
516 static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
519 if (base->cpu_base->hres_active && hrtimer_reprogram(timer, base)) {
522 switch(timer->cb_mode) {
528 BUG_ON(timer->function(timer) != HRTIMER_NORESTART);
535 * the tick timer in the softirq ! The calling site
544 list_add_tail(&timer->cb_entry,
546 timer->state = HRTIMER_STATE_PENDING;
593 static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
598 static inline int hrtimer_cb_pending(struct hrtimer *timer) { return 0; }
599 static inline void hrtimer_remove_cb_pending(struct hrtimer *timer) { }
601 static inline void hrtimer_init_timer_hres(struct hrtimer *timer) { }
606 void __timer_stats_hrtimer_set_start_info(struct hrtimer *timer, void *addr)
608 if (timer->start_site)
611 timer->start_site = addr;
612 memcpy(timer->start_comm, current->comm, TASK_COMM_LEN);
613 timer->start_pid = current->pid;
621 void unlock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
623 spin_unlock_irqrestore(&timer->base->cpu_base->lock, *flags);
627 * hrtimer_forward - forward the timer expiry
628 * @timer: hrtimer to forward
632 * Forward the timer expiry so it will expire in the future.
636 hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval)
641 delta = ktime_sub(now, timer->expires);
646 if (interval.tv64 < timer->base->resolution.tv64)
647 interval.tv64 = timer->base->resolution.tv64;
653 timer->expires = ktime_add_ns(timer->expires, incr * orun);
654 if (timer->expires.tv64 > now.tv64)
662 timer->expires = ktime_add(timer->expires, interval);
667 if (timer->expires.tv64 < 0)
668 timer->expires = ktime_set(KTIME_SEC_MAX, 0);
675 * enqueue_hrtimer - internal function to (re)start a timer
677 * The timer is inserted in expiry order. Insertion into the
680 static void enqueue_hrtimer(struct hrtimer *timer,
697 if (timer->expires.tv64 < entry->expires.tv64)
704 * Insert the timer to the rbtree and check whether it
705 * replaces the first pending timer
707 if (!base->first || timer->expires.tv64 <
710 * Reprogram the clock event device. When the timer is already
717 if (reprogram && hrtimer_enqueue_reprogram(timer, base))
720 base->first = &timer->node;
723 rb_link_node(&timer->node, parent, link);
724 rb_insert_color(&timer->node, &base->active);
729 timer->state |= HRTIMER_STATE_ENQUEUED;
733 * __remove_hrtimer - internal function to remove a timer
737 * High resolution timer mode reprograms the clock event device when the
738 * timer is the one which expires next. The caller can disable this by setting
740 * anyway (e.g. timer interrupt)
742 static void __remove_hrtimer(struct hrtimer *timer,
747 if (hrtimer_cb_pending(timer))
748 hrtimer_remove_cb_pending(timer);
751 * Remove the timer from the rbtree and replace the
754 if (base->first == &timer->node) {
755 base->first = rb_next(&timer->node);
760 rb_erase(&timer->node, &base->active);
762 timer->state = newstate;
769 remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base)
771 if (hrtimer_is_queued(timer)) {
775 * Remove the timer and force reprogramming when high
776 * resolution mode is active and the timer is on the current
777 * CPU. If we remove a timer on another CPU, reprogramming is
782 timer_stats_hrtimer_clear_start_info(timer);
784 __remove_hrtimer(timer, base, HRTIMER_STATE_INACTIVE,
792 * hrtimer_start - (re)start an relative timer on the current CPU
793 * @timer: the timer to be added
799 * 1 when the timer was active
802 hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode)
808 base = lock_hrtimer_base(timer, &flags);
810 /* Remove an active timer from the queue: */
811 ret = remove_hrtimer(timer, base);
813 /* Switch the timer base, if necessary: */
814 new_base = switch_hrtimer_base(timer, base);
822 * resolution when starting a relative timer, to avoid short
829 timer->expires = tim;
831 timer_stats_hrtimer_set_start_info(timer);
835 * (it might still be on another CPU if the timer was pending)
837 enqueue_hrtimer(timer, new_base,
840 unlock_hrtimer_base(timer, &flags);
847 * hrtimer_try_to_cancel - try to deactivate a timer
848 * @timer: hrtimer to stop
851 * 0 when the timer was not active
852 * 1 when the timer was active
853 * -1 when the timer is currently excuting the callback function and
856 int hrtimer_try_to_cancel(struct hrtimer *timer)
862 base = lock_hrtimer_base(timer, &flags);
864 if (!hrtimer_callback_running(timer))
865 ret = remove_hrtimer(timer, base);
867 unlock_hrtimer_base(timer, &flags);
875 * hrtimer_cancel - cancel a timer and wait for the handler to finish.
876 * @timer: the timer to be cancelled
879 * 0 when the timer was not active
880 * 1 when the timer was active
882 int hrtimer_cancel(struct hrtimer *timer)
885 int ret = hrtimer_try_to_cancel(timer);
895 * hrtimer_get_remaining - get remaining time for the timer
896 * @timer: the timer to read
898 ktime_t hrtimer_get_remaining(const struct hrtimer *timer)
904 base = lock_hrtimer_base(timer, &flags);
905 rem = ktime_sub(timer->expires, base->get_time());
906 unlock_hrtimer_base(timer, &flags);
916 * Returns the delta to the next expiry event or KTIME_MAX if no timer
931 struct hrtimer *timer;
936 timer = rb_entry(base->first, struct hrtimer, node);
937 delta.tv64 = timer->expires.tv64;
953 * hrtimer_init - initialize a timer to the given clock
954 * @timer: the timer to be initialized
956 * @mode: timer mode abs/rel
958 void hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
963 memset(timer, 0, sizeof(struct hrtimer));
970 timer->base = &cpu_base->clock_base[clock_id];
971 hrtimer_init_timer_hres(timer);
974 timer->start_site = NULL;
975 timer->start_pid = -1;
976 memset(timer->start_comm, 0, TASK_COMM_LEN);
982 * hrtimer_get_res - get the timer resolution for a clock
1003 * High resolution timer interrupt
1033 struct hrtimer *timer;
1035 timer = rb_entry(node, struct hrtimer, node);
1037 if (basenow.tv64 < timer->expires.tv64) {
1040 expires = ktime_sub(timer->expires,
1048 if (timer->cb_mode == HRTIMER_CB_SOFTIRQ) {
1049 __remove_hrtimer(timer, base,
1051 list_add_tail(&timer->cb_entry,
1057 __remove_hrtimer(timer, base,
1059 timer_stats_account_hrtimer(timer);
1067 if (timer->function(timer) != HRTIMER_NORESTART) {
1068 BUG_ON(timer->state != HRTIMER_STATE_CALLBACK);
1069 enqueue_hrtimer(timer, base, 0);
1071 timer->state &= ~HRTIMER_STATE_CALLBACK;
1098 struct hrtimer *timer;
1101 timer = list_entry(cpu_base->cb_pending.next,
1104 timer_stats_account_hrtimer(timer);
1106 fn = timer->function;
1107 __remove_hrtimer(timer, timer->base, HRTIMER_STATE_CALLBACK, 0);
1110 restart = fn(timer);
1114 timer->state &= ~HRTIMER_STATE_CALLBACK;
1116 BUG_ON(hrtimer_active(timer));
1118 * Enqueue the timer, allow reprogramming of the event
1121 enqueue_hrtimer(timer, timer->base, 1);
1122 } else if (hrtimer_active(timer)) {
1124 * If the timer was rearmed on another CPU, reprogram
1127 if (timer->base->first == &timer->node)
1128 hrtimer_reprogram(timer, timer->base);
1154 struct hrtimer *timer;
1158 timer = rb_entry(node, struct hrtimer, node);
1159 if (base->softirq_time.tv64 <= timer->expires.tv64)
1163 WARN_ON_ONCE(timer->cb_mode == HRTIMER_CB_IRQSAFE_NO_SOFTIRQ);
1165 timer_stats_account_hrtimer(timer);
1167 fn = timer->function;
1168 __remove_hrtimer(timer, base, HRTIMER_STATE_CALLBACK, 0);
1171 restart = fn(timer);
1175 timer->state &= ~HRTIMER_STATE_CALLBACK;
1177 BUG_ON(hrtimer_active(timer));
1178 enqueue_hrtimer(timer, base, 0);
1185 * Called from timer softirq every jiffy, expire hrtimers:
1187 * For HRT its the fall back code to run the softirq in the timer
1202 * clocksource switch happens in the timer interrupt with
1220 static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer)
1223 container_of(timer, struct hrtimer_sleeper, timer);
1235 sl->timer.function = hrtimer_wakeup;
1238 sl->timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_RESTART;
1248 hrtimer_start(&t->timer, t->timer.expires, mode);
1253 hrtimer_cancel(&t->timer);
1270 hrtimer_init(&t.timer, restart->arg0, HRTIMER_MODE_ABS);
1271 t.timer.expires.tv64 = ((u64)restart->arg3 << 32) | (u64) restart->arg2;
1278 time = ktime_sub(t.timer.expires, t.timer.base->get_time());
1300 hrtimer_init(&t.timer, clockid, mode);
1301 t.timer.expires = timespec_to_ktime(*rqtp);
1310 rem = ktime_sub(t.timer.expires, t.timer.base->get_time());
1320 restart->arg0 = (unsigned long) t.timer.base->index;
1322 restart->arg2 = t.timer.expires.tv64 & 0xFFFFFFFF;
1323 restart->arg3 = t.timer.expires.tv64 >> 32;
1364 struct hrtimer *timer;
1368 timer = rb_entry(node, struct hrtimer, node);
1369 BUG_ON(hrtimer_callback_running(timer));
1370 __remove_hrtimer(timer, old_base, HRTIMER_STATE_INACTIVE, 0);
1371 timer->base = new_base;
1373 * Enqueue the timer. Allow reprogramming of the event device
1375 enqueue_hrtimer(timer, new_base, 1);