···4949 * struct hrtimer - the basic hrtimer structure5050 *5151 * @node: red black tree node for time ordered insertion5252- * @list: list head for easier access to the time ordered list,5353- * without walking the red black tree.5452 * @expires: the absolute expiry time in the hrtimers internal5553 * representation. The time is related to the clock on5654 * which the timer is based.···6163 */6264struct hrtimer {6365 struct rb_node node;6464- struct list_head list;6566 ktime_t expires;6667 enum hrtimer_state state;6768 int (*function)(void *);···7578 * to a base on another cpu.7679 * @lock: lock protecting the base and associated timers7780 * @active: red black tree root node for the active timers7878- * @pending: list of pending timers for simple time ordered access8181+ * @first: pointer to the timer node which expires first7982 * @resolution: the resolution of the clock, in nanoseconds8083 * @get_time: function to retrieve the current time of the clock8184 * @curr_timer: the timer which is executing a callback right now···8487 clockid_t index;8588 spinlock_t lock;8689 struct rb_root active;8787- struct list_head pending;8888- unsigned long resolution;9090+ struct rb_node *first;9191+ ktime_t resolution;8992 ktime_t (*get_time)(void);9093 struct hrtimer *curr_timer;9194};···122125}123126124127/* Forward a hrtimer so it expires after now: */125125-extern unsigned long hrtimer_forward(struct hrtimer *timer,126126- const ktime_t interval);128128+extern unsigned long hrtimer_forward(struct hrtimer *timer, ktime_t interval);127129128130/* Precise sleep: */129131extern long hrtimer_nanosleep(struct timespec *rqtp,
+2-2
include/linux/ktime.h
···272272 * idea of the (in)accuracy of timers. Timer values are rounded up to273273 * this resolution values.274274 */275275-#define KTIME_REALTIME_RES (NSEC_PER_SEC/HZ)276276-#define KTIME_MONOTONIC_RES (NSEC_PER_SEC/HZ)275275+#define KTIME_REALTIME_RES (ktime_t){ .tv64 = TICK_NSEC }276276+#define KTIME_MONOTONIC_RES (ktime_t){ .tv64 = TICK_NSEC }277277278278/* Get the monotonic time in timespec format: */279279extern void ktime_get_ts(struct timespec *ts);
+19-15
kernel/hrtimer.c
···275275 * The number of overruns is added to the overrun field.276276 */277277unsigned long278278-hrtimer_forward(struct hrtimer *timer, const ktime_t interval)278278+hrtimer_forward(struct hrtimer *timer, ktime_t interval)279279{280280 unsigned long orun = 1;281281 ktime_t delta, now;···286286287287 if (delta.tv64 < 0)288288 return 0;289289+290290+ if (interval.tv64 < timer->base->resolution.tv64)291291+ interval.tv64 = timer->base->resolution.tv64;289292290293 if (unlikely(delta.tv64 >= interval.tv64)) {291294 nsec_t incr = ktime_to_ns(interval);···317314static void enqueue_hrtimer(struct hrtimer *timer, struct hrtimer_base *base)318315{319316 struct rb_node **link = &base->active.rb_node;320320- struct list_head *prev = &base->pending;321317 struct rb_node *parent = NULL;322318 struct hrtimer *entry;323319···332330 */333331 if (timer->expires.tv64 < entry->expires.tv64)334332 link = &(*link)->rb_left;335335- else {333333+ else336334 link = &(*link)->rb_right;337337- prev = &entry->list;338338- }339335 }340336341337 /*342342- * Insert the timer to the rbtree and to the sorted list:338338+ * Insert the timer to the rbtree and check whether it339339+ * replaces the first pending timer343340 */344341 rb_link_node(&timer->node, parent, link);345342 rb_insert_color(&timer->node, &base->active);346346- list_add(&timer->list, prev);347343348344 timer->state = HRTIMER_PENDING;349349-}350345346346+ if (!base->first || timer->expires.tv64 <347347+ rb_entry(base->first, struct hrtimer, node)->expires.tv64)348348+ base->first = &timer->node;349349+}351350352351/*353352 * __remove_hrtimer - internal function to remove a timer···358355static void __remove_hrtimer(struct hrtimer *timer, struct hrtimer_base *base)359356{360357 /*361361- * Remove the timer from the sorted list and from the rbtree:358358+ * Remove the timer from the rbtree and replace the359359+ * first entry pointer if necessary.362360 */363363- list_del(&timer->list);361361+ if (base->first == &timer->node)362362+ base->first = rb_next(&timer->node);364363 rb_erase(&timer->node, &base->active);365364}366365···521516{522517 struct hrtimer_base *bases;523518524524- tp->tv_sec = 0;525519 bases = per_cpu(hrtimer_bases, raw_smp_processor_id());526526- tp->tv_nsec = bases[which_clock].resolution;520520+ *tp = ktime_to_timespec(bases[which_clock].resolution);527521528522 return 0;529523}···533529static inline void run_hrtimer_queue(struct hrtimer_base *base)534530{535531 ktime_t now = base->get_time();532532+ struct rb_node *node;536533537534 spin_lock_irq(&base->lock);538535539539- while (!list_empty(&base->pending)) {536536+ while ((node = base->first)) {540537 struct hrtimer *timer;541538 int (*fn)(void *);542539 int restart;543540 void *data;544541545545- timer = list_entry(base->pending.next, struct hrtimer, list);542542+ timer = rb_entry(node, struct hrtimer, node);546543 if (now.tv64 <= timer->expires.tv64)547544 break;548545···737732738733 for (i = 0; i < MAX_HRTIMER_BASES; i++) {739734 spin_lock_init(&base->lock);740740- INIT_LIST_HEAD(&base->pending);741735 base++;742736 }743737}