Lines Matching +full:fifo +full:- +full:size
1 /* SPDX-License-Identifier: GPL-2.0 */
37 (heap)->nr = 0; \
38 (heap)->size = (_size); \
39 _bytes = (heap)->size * sizeof(*(heap)->data); \
40 (heap)->data = kvmalloc(_bytes, (gfp) & GFP_KERNEL); \
41 (heap)->data; \
46 kvfree((heap)->data); \
47 (heap)->data = NULL; \
52 size_t front, back, size, mask; \
56 #define fifo_for_each(c, fifo, iter) \ argument
57 for (iter = (fifo)->front; \
58 c = (fifo)->data[iter], iter != (fifo)->back; \
59 iter = (iter + 1) & (fifo)->mask)
61 #define __init_fifo(fifo, gfp) \ argument
64 BUG_ON(!(fifo)->size); \
66 _allocated_size = roundup_pow_of_two((fifo)->size + 1); \
67 _bytes = _allocated_size * sizeof(*(fifo)->data); \
69 (fifo)->mask = _allocated_size - 1; \
70 (fifo)->front = (fifo)->back = 0; \
72 (fifo)->data = kvmalloc(_bytes, (gfp) & GFP_KERNEL); \
73 (fifo)->data; \
76 #define init_fifo_exact(fifo, _size, gfp) \ argument
78 (fifo)->size = (_size); \
79 __init_fifo(fifo, gfp); \
82 #define init_fifo(fifo, _size, gfp) \ argument
84 (fifo)->size = (_size); \
85 if ((fifo)->size > 4) \
86 (fifo)->size = roundup_pow_of_two((fifo)->size) - 1; \
87 __init_fifo(fifo, gfp); \
90 #define free_fifo(fifo) \ argument
92 kvfree((fifo)->data); \
93 (fifo)->data = NULL; \
96 #define fifo_used(fifo) (((fifo)->back - (fifo)->front) & (fifo)->mask) argument
97 #define fifo_free(fifo) ((fifo)->size - fifo_used(fifo)) argument
99 #define fifo_empty(fifo) (!fifo_used(fifo)) argument
100 #define fifo_full(fifo) (!fifo_free(fifo)) argument
102 #define fifo_front(fifo) ((fifo)->data[(fifo)->front]) argument
103 #define fifo_back(fifo) \ argument
104 ((fifo)->data[((fifo)->back - 1) & (fifo)->mask])
106 #define fifo_idx(fifo, p) (((p) - &fifo_front(fifo)) & (fifo)->mask) argument
108 #define fifo_push_back(fifo, i) \ argument
110 bool _r = !fifo_full((fifo)); \
112 (fifo)->data[(fifo)->back++] = (i); \
113 (fifo)->back &= (fifo)->mask; \
118 #define fifo_pop_front(fifo, i) \ argument
120 bool _r = !fifo_empty((fifo)); \
122 (i) = (fifo)->data[(fifo)->front++]; \
123 (fifo)->front &= (fifo)->mask; \
128 #define fifo_push_front(fifo, i) \ argument
130 bool _r = !fifo_full((fifo)); \
132 --(fifo)->front; \
133 (fifo)->front &= (fifo)->mask; \
134 (fifo)->data[(fifo)->front] = (i); \
139 #define fifo_pop_back(fifo, i) \ argument
141 bool _r = !fifo_empty((fifo)); \
143 --(fifo)->back; \
144 (fifo)->back &= (fifo)->mask; \
145 (i) = (fifo)->data[(fifo)->back] \
150 #define fifo_push(fifo, i) fifo_push_back(fifo, (i)) argument
151 #define fifo_pop(fifo, i) fifo_pop_front(fifo, (i)) argument
155 swap((l)->front, (r)->front); \
156 swap((l)->back, (r)->back); \
157 swap((l)->size, (r)->size); \
158 swap((l)->mask, (r)->mask); \
159 swap((l)->data, (r)->data); \
164 typeof(*((dest)->data)) _t; \
171 * Simple array based allocator - preallocates a number of elements and you can
179 * freelist as a stack - allocating and freeing push and pop off the freelist.
182 #define DECLARE_ARRAY_ALLOCATOR(type, name, size) \ argument
185 type data[size]; \
190 typeof((array)->freelist) _ret = (array)->freelist; \
193 (array)->freelist = *((typeof((array)->freelist) *) _ret);\
200 typeof((array)->freelist) _ptr = ptr; \
202 *((typeof((array)->freelist) *) _ptr) = (array)->freelist; \
203 (array)->freelist = _ptr; \
208 typeof((array)->freelist) _i; \
210 BUILD_BUG_ON(sizeof((array)->data[0]) < sizeof(void *)); \
211 (array)->freelist = NULL; \
213 for (_i = (array)->data; \
214 _i < (array)->data + ARRAY_SIZE((array)->data); \
219 #define array_freelist_empty(array) ((array)->freelist == NULL)
222 ((((t) 1 << (sizeof(t) * 8 - 2)) - (t) 1) * (t) 2 + (t) 1)
259 ? bch_strtoull_h(cp, (void *) res) : -EINVAL)
310 div_u64((stats)->stat >> 8, NSEC_PER_ ## units))
321 div_u64((stats)->max_duration, \
324 sysfs_print(name ## _last_ ## frequency_units, (stats)->last \
325 ? div_s64(local_clock() - (stats)->last, \
327 : -1LL); \
348 (ewma) *= (weight) - 1; \
367 d->next = local_clock(); in bch_ratelimit_reset()
390 struct rb_node **n = &(root)->rb_node, *parent = NULL; \
392 int res, ret = -1; \
401 ? &(*n)->rb_left \
402 : &(*n)->rb_right; \
405 rb_link_node(&(new)->member, parent, n); \
406 rb_insert_color(&(new)->member, root); \
414 struct rb_node *n = (root)->rb_node; \
426 ? n->rb_left \
427 : n->rb_right; \
434 struct rb_node *n = (root)->rb_node; \
443 n = n->rb_left; \
445 n = n->rb_right; \
457 container_of_or_null(rb_next(&(ptr)->member), typeof(*ptr), member)
460 container_of_or_null(rb_prev(&(ptr)->member), typeof(*ptr), member)
471 * A stepwise-linear pseudo-exponential. This returns 1 << (x >>
472 * frac_bits), with the less-significant bits filled in by linear
475 * This can also be interpreted as a floating-point number format,
481 * input is CONGESTED_MAX-1 = 1023 (exponent 16, mantissa 0x1.fc),
489 mantissa += x & (mantissa - 1); in fract_exp_two()