mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
timerqueue: Provide linked timerqueue
The hrtimer subsystem wants to peak ahead to the next and previous timer to evaluated whether a to be rearmed timer can stay at the same position in the RB tree with the new expiry time. The linked RB tree provides the infrastructure for this as it maintains links to the previous and next nodes for each entry in the tree. Provide timerqueue wrappers around that. Signed-off-by: Thomas Gleixner <tglx@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://patch.msgid.link/20260224163431.734827095@kernel.org
This commit is contained in:
committed by
Peter Zijlstra
parent
671047943d
commit
1339eeb73d
@@ -5,12 +5,11 @@
|
||||
#include <linux/rbtree.h>
|
||||
#include <linux/timerqueue_types.h>
|
||||
|
||||
extern bool timerqueue_add(struct timerqueue_head *head,
|
||||
struct timerqueue_node *node);
|
||||
extern bool timerqueue_del(struct timerqueue_head *head,
|
||||
struct timerqueue_node *node);
|
||||
extern struct timerqueue_node *timerqueue_iterate_next(
|
||||
struct timerqueue_node *node);
|
||||
bool timerqueue_add(struct timerqueue_head *head, struct timerqueue_node *node);
|
||||
bool timerqueue_del(struct timerqueue_head *head, struct timerqueue_node *node);
|
||||
struct timerqueue_node *timerqueue_iterate_next(struct timerqueue_node *node);
|
||||
|
||||
bool timerqueue_linked_add(struct timerqueue_linked_head *head, struct timerqueue_linked_node *node);
|
||||
|
||||
/**
|
||||
* timerqueue_getnext - Returns the timer with the earliest expiration time
|
||||
@@ -19,8 +18,7 @@ extern struct timerqueue_node *timerqueue_iterate_next(
|
||||
*
|
||||
* Returns a pointer to the timer node that has the earliest expiration time.
|
||||
*/
|
||||
static inline
|
||||
struct timerqueue_node *timerqueue_getnext(struct timerqueue_head *head)
|
||||
static inline struct timerqueue_node *timerqueue_getnext(struct timerqueue_head *head)
|
||||
{
|
||||
struct rb_node *leftmost = rb_first_cached(&head->rb_root);
|
||||
|
||||
@@ -41,4 +39,46 @@ static inline void timerqueue_init_head(struct timerqueue_head *head)
|
||||
{
|
||||
head->rb_root = RB_ROOT_CACHED;
|
||||
}
|
||||
|
||||
/* Timer queues with linked nodes */
|
||||
|
||||
static __always_inline
|
||||
struct timerqueue_linked_node *timerqueue_linked_first(struct timerqueue_linked_head *head)
|
||||
{
|
||||
return rb_entry_safe(head->rb_root.rb_leftmost, struct timerqueue_linked_node, node);
|
||||
}
|
||||
|
||||
static __always_inline
|
||||
struct timerqueue_linked_node *timerqueue_linked_next(struct timerqueue_linked_node *node)
|
||||
{
|
||||
return rb_entry_safe(node->node.next, struct timerqueue_linked_node, node);
|
||||
}
|
||||
|
||||
static __always_inline
|
||||
struct timerqueue_linked_node *timerqueue_linked_prev(struct timerqueue_linked_node *node)
|
||||
{
|
||||
return rb_entry_safe(node->node.prev, struct timerqueue_linked_node, node);
|
||||
}
|
||||
|
||||
static __always_inline
|
||||
bool timerqueue_linked_del(struct timerqueue_linked_head *head, struct timerqueue_linked_node *node)
|
||||
{
|
||||
return rb_erase_linked(&node->node, &head->rb_root);
|
||||
}
|
||||
|
||||
static __always_inline void timerqueue_linked_init(struct timerqueue_linked_node *node)
|
||||
{
|
||||
RB_CLEAR_LINKED_NODE(&node->node);
|
||||
}
|
||||
|
||||
static __always_inline bool timerqueue_linked_node_queued(struct timerqueue_linked_node *node)
|
||||
{
|
||||
return !RB_EMPTY_LINKED_NODE(&node->node);
|
||||
}
|
||||
|
||||
static __always_inline void timerqueue_linked_init_head(struct timerqueue_linked_head *head)
|
||||
{
|
||||
head->rb_root = RB_ROOT_LINKED;
|
||||
}
|
||||
|
||||
#endif /* _LINUX_TIMERQUEUE_H */
|
||||
|
||||
@@ -6,12 +6,21 @@
|
||||
#include <linux/types.h>
|
||||
|
||||
struct timerqueue_node {
|
||||
struct rb_node node;
|
||||
ktime_t expires;
|
||||
struct rb_node node;
|
||||
ktime_t expires;
|
||||
};
|
||||
|
||||
struct timerqueue_head {
|
||||
struct rb_root_cached rb_root;
|
||||
struct rb_root_cached rb_root;
|
||||
};
|
||||
|
||||
struct timerqueue_linked_node {
|
||||
struct rb_node_linked node;
|
||||
ktime_t expires;
|
||||
};
|
||||
|
||||
struct timerqueue_linked_head {
|
||||
struct rb_root_linked rb_root;
|
||||
};
|
||||
|
||||
#endif /* _LINUX_TIMERQUEUE_TYPES_H */
|
||||
|
||||
@@ -82,3 +82,17 @@ struct timerqueue_node *timerqueue_iterate_next(struct timerqueue_node *node)
|
||||
return container_of(next, struct timerqueue_node, node);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(timerqueue_iterate_next);
|
||||
|
||||
#define __node_2_tq_linked(_n) \
|
||||
container_of(rb_entry((_n), struct rb_node_linked, node), struct timerqueue_linked_node, node)
|
||||
|
||||
static __always_inline bool __tq_linked_less(struct rb_node *a, const struct rb_node *b)
|
||||
{
|
||||
return __node_2_tq_linked(a)->expires < __node_2_tq_linked(b)->expires;
|
||||
}
|
||||
|
||||
bool timerqueue_linked_add(struct timerqueue_linked_head *head, struct timerqueue_linked_node *node)
|
||||
{
|
||||
return rb_add_linked(&node->node, &head->rb_root, __tq_linked_less);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(timerqueue_linked_add);
|
||||
|
||||
Reference in New Issue
Block a user