Lines Matching +full:fifo +full:- +full:size
1 /* SPDX-License-Identifier: GPL-2.0 */
35 size_t size, used; \
42 (heap)->used = 0; \
43 (heap)->size = (_size); \
44 _bytes = (heap)->size * sizeof(*(heap)->data); \
45 (heap)->data = kvmalloc(_bytes, (gfp) & GFP_KERNEL); \
46 (heap)->data; \
51 kvfree((heap)->data); \
52 (heap)->data = NULL; \
55 #define heap_swap(h, i, j) swap((h)->data[i], (h)->data[j])
61 for (; _j * 2 + 1 < (h)->used; _j = _r) { \
63 if (_r + 1 < (h)->used && \
64 cmp((h)->data[_r], (h)->data[_r + 1])) \
67 if (cmp((h)->data[_r], (h)->data[_j])) \
76 size_t p = (i - 1) / 2; \
77 if (cmp((h)->data[i], (h)->data[p])) \
88 size_t _i = (h)->used++; \
89 (h)->data[_i] = d; \
99 bool _r = (h)->used; \
101 (d) = (h)->data[0]; \
102 (h)->used--; \
103 heap_swap(h, 0, (h)->used); \
109 #define heap_peek(h) ((h)->used ? (h)->data[0] : NULL)
111 #define heap_full(h) ((h)->used == (h)->size)
115 size_t front, back, size, mask; \
119 #define fifo_for_each(c, fifo, iter) \ argument
120 for (iter = (fifo)->front; \
121 c = (fifo)->data[iter], iter != (fifo)->back; \
122 iter = (iter + 1) & (fifo)->mask)
124 #define __init_fifo(fifo, gfp) \ argument
127 BUG_ON(!(fifo)->size); \
129 _allocated_size = roundup_pow_of_two((fifo)->size + 1); \
130 _bytes = _allocated_size * sizeof(*(fifo)->data); \
132 (fifo)->mask = _allocated_size - 1; \
133 (fifo)->front = (fifo)->back = 0; \
135 (fifo)->data = kvmalloc(_bytes, (gfp) & GFP_KERNEL); \
136 (fifo)->data; \
139 #define init_fifo_exact(fifo, _size, gfp) \ argument
141 (fifo)->size = (_size); \
142 __init_fifo(fifo, gfp); \
145 #define init_fifo(fifo, _size, gfp) \ argument
147 (fifo)->size = (_size); \
148 if ((fifo)->size > 4) \
149 (fifo)->size = roundup_pow_of_two((fifo)->size) - 1; \
150 __init_fifo(fifo, gfp); \
153 #define free_fifo(fifo) \ argument
155 kvfree((fifo)->data); \
156 (fifo)->data = NULL; \
159 #define fifo_used(fifo) (((fifo)->back - (fifo)->front) & (fifo)->mask) argument
160 #define fifo_free(fifo) ((fifo)->size - fifo_used(fifo)) argument
162 #define fifo_empty(fifo) (!fifo_used(fifo)) argument
163 #define fifo_full(fifo) (!fifo_free(fifo)) argument
165 #define fifo_front(fifo) ((fifo)->data[(fifo)->front]) argument
166 #define fifo_back(fifo) \ argument
167 ((fifo)->data[((fifo)->back - 1) & (fifo)->mask])
169 #define fifo_idx(fifo, p) (((p) - &fifo_front(fifo)) & (fifo)->mask) argument
171 #define fifo_push_back(fifo, i) \ argument
173 bool _r = !fifo_full((fifo)); \
175 (fifo)->data[(fifo)->back++] = (i); \
176 (fifo)->back &= (fifo)->mask; \
181 #define fifo_pop_front(fifo, i) \ argument
183 bool _r = !fifo_empty((fifo)); \
185 (i) = (fifo)->data[(fifo)->front++]; \
186 (fifo)->front &= (fifo)->mask; \
191 #define fifo_push_front(fifo, i) \ argument
193 bool _r = !fifo_full((fifo)); \
195 --(fifo)->front; \
196 (fifo)->front &= (fifo)->mask; \
197 (fifo)->data[(fifo)->front] = (i); \
202 #define fifo_pop_back(fifo, i) \ argument
204 bool _r = !fifo_empty((fifo)); \
206 --(fifo)->back; \
207 (fifo)->back &= (fifo)->mask; \
208 (i) = (fifo)->data[(fifo)->back] \
213 #define fifo_push(fifo, i) fifo_push_back(fifo, (i)) argument
214 #define fifo_pop(fifo, i) fifo_pop_front(fifo, (i)) argument
218 swap((l)->front, (r)->front); \
219 swap((l)->back, (r)->back); \
220 swap((l)->size, (r)->size); \
221 swap((l)->mask, (r)->mask); \
222 swap((l)->data, (r)->data); \
227 typeof(*((dest)->data)) _t; \
234 * Simple array based allocator - preallocates a number of elements and you can
242 * freelist as a stack - allocating and freeing push and pop off the freelist.
245 #define DECLARE_ARRAY_ALLOCATOR(type, name, size) \ argument
248 type data[size]; \
253 typeof((array)->freelist) _ret = (array)->freelist; \
256 (array)->freelist = *((typeof((array)->freelist) *) _ret);\
263 typeof((array)->freelist) _ptr = ptr; \
265 *((typeof((array)->freelist) *) _ptr) = (array)->freelist; \
266 (array)->freelist = _ptr; \
271 typeof((array)->freelist) _i; \
273 BUILD_BUG_ON(sizeof((array)->data[0]) < sizeof(void *)); \
274 (array)->freelist = NULL; \
276 for (_i = (array)->data; \
277 _i < (array)->data + ARRAY_SIZE((array)->data); \
282 #define array_freelist_empty(array) ((array)->freelist == NULL)
285 ((((t) 1 << (sizeof(t) * 8 - 2)) - (t) 1) * (t) 2 + (t) 1)
322 ? bch_strtoull_h(cp, (void *) res) : -EINVAL)
373 div_u64((stats)->stat >> 8, NSEC_PER_ ## units))
384 div_u64((stats)->max_duration, \
387 sysfs_print(name ## _last_ ## frequency_units, (stats)->last \
388 ? div_s64(local_clock() - (stats)->last, \
390 : -1LL); \
411 (ewma) *= (weight) - 1; \
430 d->next = local_clock(); in bch_ratelimit_reset()
453 struct rb_node **n = &(root)->rb_node, *parent = NULL; \
455 int res, ret = -1; \
464 ? &(*n)->rb_left \
465 : &(*n)->rb_right; \
468 rb_link_node(&(new)->member, parent, n); \
469 rb_insert_color(&(new)->member, root); \
477 struct rb_node *n = (root)->rb_node; \
489 ? n->rb_left \
490 : n->rb_right; \
497 struct rb_node *n = (root)->rb_node; \
506 n = n->rb_left; \
508 n = n->rb_right; \
520 container_of_or_null(rb_next(&(ptr)->member), typeof(*ptr), member)
523 container_of_or_null(rb_prev(&(ptr)->member), typeof(*ptr), member)
534 * A stepwise-linear pseudo-exponential. This returns 1 << (x >>
535 * frac_bits), with the less-significant bits filled in by linear
538 * This can also be interpreted as a floating-point number format,
544 * input is CONGESTED_MAX-1 = 1023 (exponent 16, mantissa 0x1.fc),
552 mantissa += x & (mantissa - 1); in fract_exp_two()