Rev 1408 | Rev 1967 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1408 | Rev 1964 | ||
---|---|---|---|
Line 10... | Line 10... | ||
10 | */ |
10 | */ |
Line 11... | Line 11... | ||
11 | 11 | ||
12 | #ifndef __IDR_H__ |
12 | #ifndef __IDR_H__ |
Line 13... | Line 13... | ||
13 | #define __IDR_H__ |
13 | #define __IDR_H__ |
14 | - | ||
15 | #include |
- | |
16 | #include |
14 | |
17 | 15 | #include |
|
18 | //#include |
16 | #include |
Line 19... | Line 17... | ||
19 | //#include |
17 | //#include |
20 | //#include |
18 | //#include |
21 | 19 | ||
22 | struct rcu_head { |
20 | struct rcu_head { |
Line -... | Line 21... | ||
- | 21 | struct rcu_head *next; |
|
23 | struct rcu_head *next; |
22 | void (*func)(struct rcu_head *head); |
24 | void (*func)(struct rcu_head *head); |
23 | }; |
25 | }; |
24 | |
26 | 25 | ||
27 | 26 | #if BITS_PER_LONG == 32 |
|
28 | # define IDR_BITS 5 |
27 | # define IDR_BITS 5 |
- | 28 | # define IDR_FULL 0xfffffffful |
|
- | 29 | /* We can only use two of the bits in the top level because there is |
|
- | 30 | only one possible bit in the top level (5 bits * 7 levels = 35 |
|
- | 31 | bits, but you only use 31 bits in the id). */ |
|
- | 32 | # define TOP_LEVEL_FULL (IDR_FULL >> 30) |
|
- | 33 | #elif BITS_PER_LONG == 64 |
|
- | 34 | # define IDR_BITS 6 |
|
- | 35 | # define IDR_FULL 0xfffffffffffffffful |
|
- | 36 | /* We can only use two of the bits in the top level because there is |
|
- | 37 | only one possible bit in the top level (6 bits * 6 levels = 36 |
|
Line 29... | Line 38... | ||
29 | # define IDR_FULL 0xfffffffful |
38 | bits, but you only use 31 bits in the id). */ |
30 | /* We can only use two of the bits in the top level because there is |
39 | # define TOP_LEVEL_FULL (IDR_FULL >> 62) |
Line 31... | Line 40... | ||
31 | only one possible bit in the top level (5 bits * 7 levels = 35 |
40 | #else |
Line 45... | Line 54... | ||
45 | /* Number of id_layer structs to leave in free list */ |
54 | /* Number of id_layer structs to leave in free list */ |
46 | #define IDR_FREE_MAX MAX_LEVEL + MAX_LEVEL |
55 | #define IDR_FREE_MAX MAX_LEVEL + MAX_LEVEL |
Line 47... | Line 56... | ||
47 | 56 | ||
48 | struct idr_layer { |
57 | struct idr_layer { |
49 | unsigned long bitmap; /* A zero bit means "space here" */ |
58 | unsigned long bitmap; /* A zero bit means "space here" */ |
50 | struct idr_layer *ary[1< |
59 | struct idr_layer __rcu *ary[1< |
51 | int count; /* When zero, we can release it */ |
60 | int count; /* When zero, we can release it */ |
52 | int layer; /* distance from leaf */ |
61 | int layer; /* distance from leaf */ |
53 | struct rcu_head rcu_head; |
62 | struct rcu_head rcu_head; |
Line 54... | Line 63... | ||
54 | }; |
63 | }; |
55 | 64 | ||
56 | struct idr { |
65 | struct idr { |
57 | struct idr_layer *top; |
66 | struct idr_layer __rcu *top; |
58 | struct idr_layer *id_free; |
67 | struct idr_layer *id_free; |
59 | int layers; /* only valid without concurrent changes */ |
68 | int layers; /* only valid without concurrent changes */ |
60 | int id_free_cnt; |
69 | int id_free_cnt; |
Line 76... | Line 85... | ||
76 | #define IDR_NOMORE_SPACE -3 |
85 | #define IDR_NOMORE_SPACE -3 |
Line 77... | Line 86... | ||
77 | 86 | ||
Line 78... | Line 87... | ||
78 | #define _idr_rc_to_errno(rc) ((rc) == -1 ? -EAGAIN : -ENOSPC) |
87 | #define _idr_rc_to_errno(rc) ((rc) == -1 ? -EAGAIN : -ENOSPC) |
- | 88 | ||
79 | 89 | /** |
|
80 | /** |
90 | * DOC: idr sync |
81 | * idr synchronization (stolen from radix-tree.h) |
91 | * idr synchronization (stolen from radix-tree.h) |
82 | * |
92 | * |
83 | * idr_find() is able to be called locklessly, using RCU. The caller must |
93 | * idr_find() is able to be called locklessly, using RCU. The caller must |
Line 96... | Line 106... | ||
96 | /* |
106 | /* |
97 | * This is what we export. |
107 | * This is what we export. |
98 | */ |
108 | */ |
Line 99... | Line 109... | ||
99 | 109 | ||
100 | void *idr_find(struct idr *idp, int id); |
110 | void *idr_find(struct idr *idp, int id); |
101 | int idr_pre_get(struct idr *idp, u32_t gfp_mask); |
111 | int idr_pre_get(struct idr *idp, gfp_t gfp_mask); |
102 | int idr_get_new(struct idr *idp, void *ptr, int *id); |
112 | int idr_get_new(struct idr *idp, void *ptr, int *id); |
103 | int idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id); |
113 | int idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id); |
104 | int idr_for_each(struct idr *idp, |
114 | int idr_for_each(struct idr *idp, |
105 | int (*fn)(int id, void *p, void *data), void *data); |
115 | int (*fn)(int id, void *p, void *data), void *data); |
Line 112... | Line 122... | ||
112 | 122 | ||
113 | 123 | ||
114 | /* |
124 | /* |
- | 125 | * IDA - IDR based id allocator, use when translation from id to |
|
- | 126 | * pointer isn't necessary. |
|
- | 127 | * |
|
115 | * IDA - IDR based id allocator, use when translation from id to |
128 | * IDA_BITMAP_LONGS is calculated to be one less to accommodate |
116 | * pointer isn't necessary. |
129 | * ida_bitmap->nr_busy so that the whole struct fits in 128 bytes. |
117 | */ |
130 | */ |
118 | #define IDA_CHUNK_SIZE 128 /* 128 bytes per chunk */ |
131 | #define IDA_CHUNK_SIZE 128 /* 128 bytes per chunk */ |
Line 119... | Line 132... | ||
119 | #define IDA_BITMAP_LONGS (128 / sizeof(long) - 1) |
132 | #define IDA_BITMAP_LONGS (IDA_CHUNK_SIZE / sizeof(long) - 1) |
120 | #define IDA_BITMAP_BITS (IDA_BITMAP_LONGS * sizeof(long) * 8) |
133 | #define IDA_BITMAP_BITS (IDA_BITMAP_LONGS * sizeof(long) * 8) |
121 | 134 | ||
Line 130... | Line 143... | ||
130 | }; |
143 | }; |
Line 131... | Line 144... | ||
131 | 144 | ||
132 | #define IDA_INIT(name) { .idr = IDR_INIT(name), .free_bitmap = NULL, } |
145 | #define IDA_INIT(name) { .idr = IDR_INIT(name), .free_bitmap = NULL, } |
Line 133... | Line 146... | ||
133 | #define DEFINE_IDA(name) struct ida name = IDA_INIT(name) |
146 | #define DEFINE_IDA(name) struct ida name = IDA_INIT(name) |
134 | 147 | ||
135 | int ida_pre_get(struct ida *ida, u32_t gfp_mask); |
148 | int ida_pre_get(struct ida *ida, gfp_t gfp_mask); |
136 | int ida_get_new_above(struct ida *ida, int starting_id, int *p_id); |
149 | int ida_get_new_above(struct ida *ida, int starting_id, int *p_id); |
137 | int ida_get_new(struct ida *ida, int *p_id); |
150 | int ida_get_new(struct ida *ida, int *p_id); |
138 | void ida_remove(struct ida *ida, int id); |
151 | void ida_remove(struct ida *ida, int id); |