Skip to content

Commit 089050c

Browse files
Sebastian Andrzej SiewiorIngo Molnar
authored andcommitted
rbtree: Split out the rbtree type definitions into <linux/rbtree_types.h>
So we have this header dependency problem on RT: - <linux/rtmutex.h> needs the definition of 'struct rb_root_cached'. - <linux/rbtree.h> includes <linux/kernel.h>, which includes <linux/spinlock.h>. That works nicely for non-RT enabled kernels, but on RT enabled kernels spinlocks are based on rtmutexes, which creates another circular header dependency, as <linux/spinlocks.h> will require <linux/rtmutex.h>. Split out the type definitions and move them into their own header file so the rtmutex header can include just those. Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent cbcebf5 commit 089050c

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

include/linux/rbtree.h

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,14 @@
1717
#ifndef _LINUX_RBTREE_H
1818
#define _LINUX_RBTREE_H
1919

20+
#include <linux/rbtree_types.h>
21+
2022
#include <linux/kernel.h>
2123
#include <linux/stddef.h>
2224
#include <linux/rcupdate.h>
2325

24-
struct rb_node {
25-
unsigned long __rb_parent_color;
26-
struct rb_node *rb_right;
27-
struct rb_node *rb_left;
28-
} __attribute__((aligned(sizeof(long))));
29-
/* The alignment might seem pointless, but allegedly CRIS needs it */
30-
31-
struct rb_root {
32-
struct rb_node *rb_node;
33-
};
34-
3526
#define rb_parent(r) ((struct rb_node *)((r)->__rb_parent_color & ~3))
3627

37-
#define RB_ROOT (struct rb_root) { NULL, }
3828
#define rb_entry(ptr, type, member) container_of(ptr, type, member)
3929

4030
#define RB_EMPTY_ROOT(root) (READ_ONCE((root)->rb_node) == NULL)
@@ -112,23 +102,6 @@ static inline void rb_link_node_rcu(struct rb_node *node, struct rb_node *parent
112102
typeof(*pos), field); 1; }); \
113103
pos = n)
114104

115-
/*
116-
* Leftmost-cached rbtrees.
117-
*
118-
* We do not cache the rightmost node based on footprint
119-
* size vs number of potential users that could benefit
120-
* from O(1) rb_last(). Just not worth it, users that want
121-
* this feature can always implement the logic explicitly.
122-
* Furthermore, users that want to cache both pointers may
123-
* find it a bit asymmetric, but that's ok.
124-
*/
125-
struct rb_root_cached {
126-
struct rb_root rb_root;
127-
struct rb_node *rb_leftmost;
128-
};
129-
130-
#define RB_ROOT_CACHED (struct rb_root_cached) { {NULL, }, NULL }
131-
132105
/* Same as rb_first(), but O(1) */
133106
#define rb_first_cached(root) (root)->rb_leftmost
134107

include/linux/rbtree_types.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
#ifndef _LINUX_RBTREE_TYPES_H
3+
#define _LINUX_RBTREE_TYPES_H
4+
5+
struct rb_node {
6+
unsigned long __rb_parent_color;
7+
struct rb_node *rb_right;
8+
struct rb_node *rb_left;
9+
} __attribute__((aligned(sizeof(long))));
10+
/* The alignment might seem pointless, but allegedly CRIS needs it */
11+
12+
struct rb_root {
13+
struct rb_node *rb_node;
14+
};
15+
16+
/*
17+
* Leftmost-cached rbtrees.
18+
*
19+
* We do not cache the rightmost node based on footprint
20+
* size vs number of potential users that could benefit
21+
* from O(1) rb_last(). Just not worth it, users that want
22+
* this feature can always implement the logic explicitly.
23+
* Furthermore, users that want to cache both pointers may
24+
* find it a bit asymmetric, but that's ok.
25+
*/
26+
struct rb_root_cached {
27+
struct rb_root rb_root;
28+
struct rb_node *rb_leftmost;
29+
};
30+
31+
#define RB_ROOT (struct rb_root) { NULL, }
32+
#define RB_ROOT_CACHED (struct rb_root_cached) { {NULL, }, NULL }
33+
34+
#endif

0 commit comments

Comments
 (0)