Lines Matching +full:fifo +full:- +full:size
1 /* SPDX-License-Identifier: GPL-2.0 */
36 size_t size, used; \
43 (heap)->used = 0; \
44 (heap)->size = (_size); \
45 _bytes = (heap)->size * sizeof(*(heap)->data); \
46 (heap)->data = kvmalloc(_bytes, (gfp) & GFP_KERNEL); \
47 (heap)->data; \
52 kvfree((heap)->data); \
53 (heap)->data = NULL; \
56 #define heap_swap(h, i, j) swap((h)->data[i], (h)->data[j])
62 for (; _j * 2 + 1 < (h)->used; _j = _r) { \
64 if (_r + 1 < (h)->used && \
65 cmp((h)->data[_r], (h)->data[_r + 1])) \
68 if (cmp((h)->data[_r], (h)->data[_j])) \
77 size_t p = (i - 1) / 2; \
78 if (cmp((h)->data[i], (h)->data[p])) \
89 size_t _i = (h)->used++; \
90 (h)->data[_i] = d; \
100 bool _r = (h)->used; \
102 (d) = (h)->data[0]; \
103 (h)->used--; \
104 heap_swap(h, 0, (h)->used); \
110 #define heap_peek(h) ((h)->used ? (h)->data[0] : NULL)
112 #define heap_full(h) ((h)->used == (h)->size)
116 size_t front, back, size, mask; \
120 #define fifo_for_each(c, fifo, iter) \ argument
121 for (iter = (fifo)->front; \
122 c = (fifo)->data[iter], iter != (fifo)->back; \
123 iter = (iter + 1) & (fifo)->mask)
125 #define __init_fifo(fifo, gfp) \ argument
128 BUG_ON(!(fifo)->size); \
130 _allocated_size = roundup_pow_of_two((fifo)->size + 1); \
131 _bytes = _allocated_size * sizeof(*(fifo)->data); \
133 (fifo)->mask = _allocated_size - 1; \
134 (fifo)->front = (fifo)->back = 0; \
136 (fifo)->data = kvmalloc(_bytes, (gfp) & GFP_KERNEL); \
137 (fifo)->data; \
140 #define init_fifo_exact(fifo, _size, gfp) \ argument
142 (fifo)->size = (_size); \
143 __init_fifo(fifo, gfp); \
146 #define init_fifo(fifo, _size, gfp) \ argument
148 (fifo)->size = (_size); \
149 if ((fifo)->size > 4) \
150 (fifo)->size = roundup_pow_of_two((fifo)->size) - 1; \
151 __init_fifo(fifo, gfp); \
154 #define free_fifo(fifo) \ argument
156 kvfree((fifo)->data); \
157 (fifo)->data = NULL; \
160 #define fifo_used(fifo) (((fifo)->back - (fifo)->front) & (fifo)->mask) argument
161 #define fifo_free(fifo) ((fifo)->size - fifo_used(fifo)) argument
163 #define fifo_empty(fifo) (!fifo_used(fifo)) argument
164 #define fifo_full(fifo) (!fifo_free(fifo)) argument
166 #define fifo_front(fifo) ((fifo)->data[(fifo)->front]) argument
167 #define fifo_back(fifo) \ argument
168 ((fifo)->data[((fifo)->back - 1) & (fifo)->mask])
170 #define fifo_idx(fifo, p) (((p) - &fifo_front(fifo)) & (fifo)->mask) argument
172 #define fifo_push_back(fifo, i) \ argument
174 bool _r = !fifo_full((fifo)); \
176 (fifo)->data[(fifo)->back++] = (i); \
177 (fifo)->back &= (fifo)->mask; \
182 #define fifo_pop_front(fifo, i) \ argument
184 bool _r = !fifo_empty((fifo)); \
186 (i) = (fifo)->data[(fifo)->front++]; \
187 (fifo)->front &= (fifo)->mask; \
192 #define fifo_push_front(fifo, i) \ argument
194 bool _r = !fifo_full((fifo)); \
196 --(fifo)->front; \
197 (fifo)->front &= (fifo)->mask; \
198 (fifo)->data[(fifo)->front] = (i); \
203 #define fifo_pop_back(fifo, i) \ argument
205 bool _r = !fifo_empty((fifo)); \
207 --(fifo)->back; \
208 (fifo)->back &= (fifo)->mask; \
209 (i) = (fifo)->data[(fifo)->back] \
214 #define fifo_push(fifo, i) fifo_push_back(fifo, (i)) argument
215 #define fifo_pop(fifo, i) fifo_pop_front(fifo, (i)) argument
219 swap((l)->front, (r)->front); \
220 swap((l)->back, (r)->back); \
221 swap((l)->size, (r)->size); \
222 swap((l)->mask, (r)->mask); \
223 swap((l)->data, (r)->data); \
228 typeof(*((dest)->data)) _t; \
235 * Simple array based allocator - preallocates a number of elements and you can
243 * freelist as a stack - allocating and freeing push and pop off the freelist.
246 #define DECLARE_ARRAY_ALLOCATOR(type, name, size) \ argument
249 type data[size]; \
254 typeof((array)->freelist) _ret = (array)->freelist; \
257 (array)->freelist = *((typeof((array)->freelist) *) _ret);\
264 typeof((array)->freelist) _ptr = ptr; \
266 *((typeof((array)->freelist) *) _ptr) = (array)->freelist; \
267 (array)->freelist = _ptr; \
272 typeof((array)->freelist) _i; \
274 BUILD_BUG_ON(sizeof((array)->data[0]) < sizeof(void *)); \
275 (array)->freelist = NULL; \
277 for (_i = (array)->data; \
278 _i < (array)->data + ARRAY_SIZE((array)->data); \
283 #define array_freelist_empty(array) ((array)->freelist == NULL)
286 ((((t) 1 << (sizeof(t) * 8 - 2)) - (t) 1) * (t) 2 + (t) 1)
323 ? bch_strtoull_h(cp, (void *) res) : -EINVAL)
374 div_u64((stats)->stat >> 8, NSEC_PER_ ## units))
385 div_u64((stats)->max_duration, \
388 sysfs_print(name ## _last_ ## frequency_units, (stats)->last \
389 ? div_s64(local_clock() - (stats)->last, \
391 : -1LL); \
412 (ewma) *= (weight) - 1; \
431 d->next = local_clock(); in bch_ratelimit_reset()
454 struct rb_node **n = &(root)->rb_node, *parent = NULL; \
456 int res, ret = -1; \
465 ? &(*n)->rb_left \
466 : &(*n)->rb_right; \
469 rb_link_node(&(new)->member, parent, n); \
470 rb_insert_color(&(new)->member, root); \
478 struct rb_node *n = (root)->rb_node; \
490 ? n->rb_left \
491 : n->rb_right; \
498 struct rb_node *n = (root)->rb_node; \
507 n = n->rb_left; \
509 n = n->rb_right; \
521 container_of_or_null(rb_next(&(ptr)->member), typeof(*ptr), member)
524 container_of_or_null(rb_prev(&(ptr)->member), typeof(*ptr), member)
535 * A stepwise-linear pseudo-exponential. This returns 1 << (x >>
536 * frac_bits), with the less-significant bits filled in by linear
539 * This can also be interpreted as a floating-point number format,
545 * input is CONGESTED_MAX-1 = 1023 (exponent 16, mantissa 0x1.fc),
553 mantissa += x & (mantissa - 1); in fract_exp_two()