[hrtimer] Remove listhead from hrtimer struct

The list_head in the hrtimer structure was introduced for easy access
to the first timer with the further extensions of real high resolution
timers in mind, but it turned out in the course of development that
it is not necessary for the standard use case. Remove the list head
and access the first expiry timer by a datafield in the timer base.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

+16 -17
+2 -5
include/linux/hrtimer.h
··· 49 49 * struct hrtimer - the basic hrtimer structure 50 50 * 51 51 * @node: red black tree node for time ordered insertion 52 - * @list: list head for easier access to the time ordered list, 53 - * without walking the red black tree. 54 52 * @expires: the absolute expiry time in the hrtimers internal 55 53 * representation. The time is related to the clock on 56 54 * which the timer is based. ··· 61 63 */ 62 64 struct hrtimer { 63 65 struct rb_node node; 64 - struct list_head list; 65 66 ktime_t expires; 66 67 enum hrtimer_state state; 67 68 int (*function)(void *); ··· 75 78 * to a base on another cpu. 76 79 * @lock: lock protecting the base and associated timers 77 80 * @active: red black tree root node for the active timers 78 - * @pending: list of pending timers for simple time ordered access 81 + * @first: pointer to the timer node which expires first 79 82 * @resolution: the resolution of the clock, in nanoseconds 80 83 * @get_time: function to retrieve the current time of the clock 81 84 * @curr_timer: the timer which is executing a callback right now ··· 84 87 clockid_t index; 85 88 spinlock_t lock; 86 89 struct rb_root active; 87 - struct list_head pending; 90 + struct rb_node *first; 88 91 unsigned long resolution; 89 92 ktime_t (*get_time)(void); 90 93 struct hrtimer *curr_timer;
+14 -12
kernel/hrtimer.c
··· 314 314 static void enqueue_hrtimer(struct hrtimer *timer, struct hrtimer_base *base) 315 315 { 316 316 struct rb_node **link = &base->active.rb_node; 317 - struct list_head *prev = &base->pending; 318 317 struct rb_node *parent = NULL; 319 318 struct hrtimer *entry; 320 319 ··· 329 330 */ 330 331 if (timer->expires.tv64 < entry->expires.tv64) 331 332 link = &(*link)->rb_left; 332 - else { 333 + else 333 334 link = &(*link)->rb_right; 334 - prev = &entry->list; 335 - } 336 335 } 337 336 338 337 /* 339 - * Insert the timer to the rbtree and to the sorted list: 338 + * Insert the timer to the rbtree and check whether it 339 + * replaces the first pending timer 340 340 */ 341 341 rb_link_node(&timer->node, parent, link); 342 342 rb_insert_color(&timer->node, &base->active); 343 - list_add(&timer->list, prev); 344 343 345 344 timer->state = HRTIMER_PENDING; 346 - } 347 345 346 + if (!base->first || timer->expires.tv64 < 347 + rb_entry(base->first, struct hrtimer, node)->expires.tv64) 348 + base->first = &timer->node; 349 + } 348 350 349 351 /* 350 352 * __remove_hrtimer - internal function to remove a timer ··· 355 355 static void __remove_hrtimer(struct hrtimer *timer, struct hrtimer_base *base) 356 356 { 357 357 /* 358 - * Remove the timer from the sorted list and from the rbtree: 358 + * Remove the timer from the rbtree and replace the 359 + * first entry pointer if necessary. 359 360 */ 360 - list_del(&timer->list); 361 + if (base->first == &timer->node) 362 + base->first = rb_next(&timer->node); 361 363 rb_erase(&timer->node, &base->active); 362 364 } 363 365 ··· 531 529 static inline void run_hrtimer_queue(struct hrtimer_base *base) 532 530 { 533 531 ktime_t now = base->get_time(); 532 + struct rb_node *node; 534 533 535 534 spin_lock_irq(&base->lock); 536 535 537 - while (!list_empty(&base->pending)) { 536 + while ((node = base->first)) { 538 537 struct hrtimer *timer; 539 538 int (*fn)(void *); 540 539 int restart; 541 540 void *data; 542 541 543 - timer = list_entry(base->pending.next, struct hrtimer, list); 542 + timer = rb_entry(node, struct hrtimer, node); 544 543 if (now.tv64 <= timer->expires.tv64) 545 544 break; 546 545 ··· 735 732 736 733 for (i = 0; i < MAX_HRTIMER_BASES; i++) { 737 734 spin_lock_init(&base->lock); 738 - INIT_LIST_HEAD(&base->pending); 739 735 base++; 740 736 } 741 737 }