History

lib/timerqueue: Rely on rbtree semantics for next timer

Simplify the timerqueue code by using cached rbtrees and rely on the tree leftmost node semantics to get the timer with earliest expiration time. This is a drop in conversion, and therefore semantics remain untouched. The runtime overhead of cached rbtrees is be pretty much the same as the current head->next method, noting that when removing the leftmost node, a common operation for the timerqueue, the rb_next(leftmost) is O(1) as well, so the next timer will either be the right node or its parent. Therefore no extra pointer chasing. Finally, the size of the struct timerqueue_head remains the same. Passes several hours of rcutorture.

Davidlohr Bueso committed 7 years ago

Commit 511885d1 parent ad5e4272 files · +18 −25Browse files

Showing the changes to include/linux/timerqueue.h (1 of 2 files). Show all

Unified · Split

include/linux/timerqueue.h+6−7
@@ -12,8 +12,7 @@ struct timerqueue_node { · 11 unmodified lines
1212 };
1313
1414 struct timerqueue_head {
15− struct rb_root head;
16− struct timerqueue_node *next;
15+ struct rb_root_cached rb_root;
1716 };
1817
1918
@@ -29,13 +28,14 @@ extern struct timerqueue_node *timerqueue_iterate_next( · 9 unmodified lines
2928 *
3029 * @head: head of timerqueue
3130 *
32− * Returns a pointer to the timer node that has the
33− * earliest expiration time.
31+ * Returns a pointer to the timer node that has the earliest expiration time.
3432 */
3533 static inline
3634 struct timerqueue_node *timerqueue_getnext(struct timerqueue_head *head)
3735 {
38− return head->next;
36+ struct rb_node *leftmost = rb_first_cached(&head->rb_root);
37+
38+ return rb_entry(leftmost, struct timerqueue_node, node);
3939 }
4040
4141 static inline void timerqueue_init(struct timerqueue_node *node)
@@ -45,7 +45,6 @@ static inline void timerqueue_init(struct timerqueue_node *node) · 3 unmodified lines
4545
4646 static inline void timerqueue_init_head(struct timerqueue_head *head)
4747 {
48− head->head = RB_ROOT;
49− head->next = NULL;
48+ head->rb_root = RB_ROOT_CACHED;
5049 }
5150 #endif /* _LINUX_TIMERQUEUE_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t