1 // SPDX-License-Identifier: GPL-2.0
3 * random utiility code, for bcache but in theory not specific to bcache
5 * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com>
6 * Copyright 2012 Google, Inc.
10 #include <linux/blkdev.h>
11 #include <linux/console.h>
12 #include <linux/ctype.h>
13 #include <linux/debugfs.h>
14 #include <linux/freezer.h>
15 #include <linux/kthread.h>
16 #include <linux/log2.h>
17 #include <linux/math64.h>
18 #include <linux/percpu.h>
19 #include <linux/preempt.h>
20 #include <linux/random.h>
21 #include <linux/seq_file.h>
22 #include <linux/string.h>
23 #include <linux/types.h>
24 #include <linux/sched/clock.h>
25 #include <linux/mean_and_variance.h>
27 #include "eytzinger.h"
30 static const char si_units[] = "?kMGTPEZY";
32 /* string_get_size units: */
33 static const char *const units_2[] = {
34 "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"
36 static const char *const units_10[] = {
37 "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"
40 static int parse_u64(const char *cp, u64 *res)
42 const char *start = cp;
52 if (v > U64_MAX - (*cp - '0'))
56 } while (isdigit(*cp));
62 static int bch2_pow(u64 n, u64 p, u64 *res)
67 if (*res > div_u64(U64_MAX, n))
74 static int parse_unit_suffix(const char *cp, u64 *res)
76 const char *start = cp;
84 for (u = 1; u < strlen(si_units); u++)
85 if (*cp == si_units[u]) {
90 for (u = 0; u < ARRAY_SIZE(units_2); u++)
91 if (!strncmp(cp, units_2[u], strlen(units_2[u]))) {
92 cp += strlen(units_2[u]);
96 for (u = 0; u < ARRAY_SIZE(units_10); u++)
97 if (!strncmp(cp, units_10[u], strlen(units_10[u]))) {
98 cp += strlen(units_10[u]);
106 ret = bch2_pow(base, u, res);
113 #define parse_or_ret(cp, _f) \
121 static int __bch2_strtou64_h(const char *cp, u64 *res)
123 const char *start = cp;
124 u64 v = 0, b, f_n = 0, f_d = 1;
127 parse_or_ret(cp, parse_u64(cp, &v));
131 ret = parse_u64(cp, &f_n);
136 ret = bch2_pow(10, ret, &f_d);
141 parse_or_ret(cp, parse_unit_suffix(cp, &b));
143 if (v > div_u64(U64_MAX, b))
147 if (f_n > div_u64(U64_MAX, b))
150 f_n = div_u64(f_n * b, f_d);
159 static int __bch2_strtoh(const char *cp, u64 *res,
160 u64 t_max, bool t_signed)
162 bool positive = *cp != '-';
165 if (*cp == '+' || *cp == '-')
168 parse_or_ret(cp, __bch2_strtou64_h(cp, &v));
191 #define STRTO_H(name, type) \
192 int bch2_ ## name ## _h(const char *cp, type *res) \
195 int ret = __bch2_strtoh(cp, &v, ANYSINT_MAX(type), \
196 ANYSINT_MAX(type) != ((type) ~0ULL)); \
201 STRTO_H(strtoint, int)
202 STRTO_H(strtouint, unsigned int)
203 STRTO_H(strtoll, long long)
204 STRTO_H(strtoull, unsigned long long)
205 STRTO_H(strtou64, u64)
207 u64 bch2_read_flag_list(char *opt, const char * const list[])
210 char *p, *s, *d = kstrdup(opt, GFP_KERNEL);
217 while ((p = strsep(&s, ","))) {
218 int flag = match_string(list, -1, p);
232 bool bch2_is_zero(const void *_p, size_t n)
237 for (i = 0; i < n; i++)
243 static void bch2_quantiles_update(struct quantiles *q, u64 v)
247 while (i < ARRAY_SIZE(q->entries)) {
248 struct quantile_entry *e = q->entries + i;
250 if (unlikely(!e->step)) {
252 e->step = max_t(unsigned, v / 2, 1024);
253 } else if (e->m > v) {
254 e->m = e->m >= e->step
257 } else if (e->m < v) {
258 e->m = e->m + e->step > e->m
263 if ((e->m > v ? e->m - v : v - e->m) < e->step)
264 e->step = max_t(unsigned, e->step / 2, 1);
269 i = eytzinger0_child(i, v > e->m);
273 void bch2_prt_u64_binary(struct printbuf *out, u64 v, unsigned nr_bits)
276 prt_char(out, '0' + ((v >> --nr_bits) & 1));
279 void bch2_print_string_as_lines(const char *prefix, const char *lines)
284 printk("%s (null)\n", prefix);
290 p = strchrnul(lines, '\n');
291 printk("%s%.*s\n", prefix, (int) (p - lines), lines);
300 int bch2_prt_backtrace(struct printbuf *out, struct task_struct *task)
302 unsigned long entries[32];
303 unsigned i, nr_entries;
306 ret = down_read_killable(&task->signal->exec_update_lock);
310 nr_entries = stack_trace_save_tsk(task, entries, ARRAY_SIZE(entries), 0);
311 for (i = 0; i < nr_entries; i++) {
312 prt_printf(out, "[<0>] %pB", (void *)entries[i]);
316 up_read(&task->signal->exec_update_lock);
322 static void bch2_time_stats_update_one(struct time_stats *stats,
327 if (time_after64(end, start)) {
328 duration = end - start;
329 stats->duration_stats = mean_and_variance_update(stats->duration_stats,
331 stats->duration_stats_weighted = mean_and_variance_weighted_update(
332 stats->duration_stats_weighted,
334 stats->max_duration = max(stats->max_duration, duration);
335 stats->min_duration = min(stats->min_duration, duration);
336 bch2_quantiles_update(&stats->quantiles, duration);
339 if (time_after64(end, stats->last_event)) {
340 freq = end - stats->last_event;
341 stats->freq_stats = mean_and_variance_update(stats->freq_stats, freq);
342 stats->freq_stats_weighted = mean_and_variance_weighted_update(
343 stats->freq_stats_weighted,
345 stats->max_freq = max(stats->max_freq, freq);
346 stats->min_freq = min(stats->min_freq, freq);
347 stats->last_event = end;
351 void __bch2_time_stats_update(struct time_stats *stats, u64 start, u64 end)
355 WARN_RATELIMIT(!stats->min_duration || !stats->min_freq,
356 "time_stats: min_duration = %llu, min_freq = %llu",
357 stats->min_duration, stats->min_freq);
359 if (!stats->buffer) {
360 spin_lock_irqsave(&stats->lock, flags);
361 bch2_time_stats_update_one(stats, start, end);
363 if (mean_and_variance_weighted_get_mean(stats->freq_stats_weighted) < 32 &&
364 stats->duration_stats.n > 1024)
366 alloc_percpu_gfp(struct time_stat_buffer,
368 spin_unlock_irqrestore(&stats->lock, flags);
370 struct time_stat_buffer_entry *i;
371 struct time_stat_buffer *b;
374 b = this_cpu_ptr(stats->buffer);
376 BUG_ON(b->nr >= ARRAY_SIZE(b->entries));
377 b->entries[b->nr++] = (struct time_stat_buffer_entry) {
382 if (b->nr == ARRAY_SIZE(b->entries)) {
383 spin_lock_irqsave(&stats->lock, flags);
385 i < b->entries + ARRAY_SIZE(b->entries);
387 bch2_time_stats_update_one(stats, i->start, i->end);
388 spin_unlock_irqrestore(&stats->lock, flags);
397 static const struct time_unit {
402 { "us", NSEC_PER_USEC },
403 { "ms", NSEC_PER_MSEC },
404 { "s", NSEC_PER_SEC },
405 { "m", NSEC_PER_SEC * 60},
406 { "h", NSEC_PER_SEC * 3600},
410 static const struct time_unit *pick_time_units(u64 ns)
412 const struct time_unit *u;
415 u + 1 < time_units + ARRAY_SIZE(time_units) &&
416 ns >= u[1].nsecs << 1;
423 static void pr_time_units(struct printbuf *out, u64 ns)
425 const struct time_unit *u = pick_time_units(ns);
427 prt_printf(out, "%llu ", div64_u64(ns, u->nsecs));
429 prt_printf(out, "%s", u->name);
432 #define TABSTOP_SIZE 12
434 static inline void pr_name_and_units(struct printbuf *out, const char *name, u64 ns)
438 pr_time_units(out, ns);
442 void bch2_time_stats_to_text(struct printbuf *out, struct time_stats *stats)
444 const struct time_unit *u;
445 s64 f_mean = 0, d_mean = 0;
446 u64 q, last_q = 0, f_stddev = 0, d_stddev = 0;
449 * avoid divide by zero
451 if (stats->freq_stats.n) {
452 f_mean = mean_and_variance_get_mean(stats->freq_stats);
453 f_stddev = mean_and_variance_get_stddev(stats->freq_stats);
454 d_mean = mean_and_variance_get_mean(stats->duration_stats);
455 d_stddev = mean_and_variance_get_stddev(stats->duration_stats);
458 printbuf_tabstop_push(out, out->indent + TABSTOP_SIZE);
459 prt_printf(out, "count:");
461 prt_printf(out, "%llu ",
462 stats->duration_stats.n);
463 printbuf_tabstop_pop(out);
466 printbuf_tabstops_reset(out);
468 printbuf_tabstop_push(out, out->indent + 20);
469 printbuf_tabstop_push(out, TABSTOP_SIZE + 2);
470 printbuf_tabstop_push(out, 0);
471 printbuf_tabstop_push(out, TABSTOP_SIZE + 2);
474 prt_printf(out, "since mount");
477 prt_printf(out, "recent");
481 printbuf_tabstops_reset(out);
482 printbuf_tabstop_push(out, out->indent + 20);
483 printbuf_tabstop_push(out, TABSTOP_SIZE);
484 printbuf_tabstop_push(out, 2);
485 printbuf_tabstop_push(out, TABSTOP_SIZE);
487 prt_printf(out, "duration of events");
489 printbuf_indent_add(out, 2);
491 pr_name_and_units(out, "min:", stats->min_duration);
492 pr_name_and_units(out, "max:", stats->max_duration);
494 prt_printf(out, "mean:");
496 pr_time_units(out, d_mean);
498 pr_time_units(out, mean_and_variance_weighted_get_mean(stats->duration_stats_weighted));
501 prt_printf(out, "stddev:");
503 pr_time_units(out, d_stddev);
505 pr_time_units(out, mean_and_variance_weighted_get_stddev(stats->duration_stats_weighted));
507 printbuf_indent_sub(out, 2);
510 prt_printf(out, "time between events");
512 printbuf_indent_add(out, 2);
514 pr_name_and_units(out, "min:", stats->min_freq);
515 pr_name_and_units(out, "max:", stats->max_freq);
517 prt_printf(out, "mean:");
519 pr_time_units(out, f_mean);
521 pr_time_units(out, mean_and_variance_weighted_get_mean(stats->freq_stats_weighted));
524 prt_printf(out, "stddev:");
526 pr_time_units(out, f_stddev);
528 pr_time_units(out, mean_and_variance_weighted_get_stddev(stats->freq_stats_weighted));
530 printbuf_indent_sub(out, 2);
533 printbuf_tabstops_reset(out);
535 i = eytzinger0_first(NR_QUANTILES);
536 u = pick_time_units(stats->quantiles.entries[i].m);
538 prt_printf(out, "quantiles (%s):\t", u->name);
539 eytzinger0_for_each(i, NR_QUANTILES) {
540 bool is_last = eytzinger0_next(i, NR_QUANTILES) == -1;
542 q = max(stats->quantiles.entries[i].m, last_q);
543 prt_printf(out, "%llu ",
544 div_u64(q, u->nsecs));
551 void bch2_time_stats_exit(struct time_stats *stats)
553 free_percpu(stats->buffer);
556 void bch2_time_stats_init(struct time_stats *stats)
558 memset(stats, 0, sizeof(*stats));
559 stats->duration_stats_weighted.w = 8;
560 stats->freq_stats_weighted.w = 8;
561 stats->min_duration = U64_MAX;
562 stats->min_freq = U64_MAX;
563 spin_lock_init(&stats->lock);
569 * bch2_ratelimit_delay() - return how long to delay until the next time to do
572 * @d - the struct bch_ratelimit to update
574 * Returns the amount of time to delay by, in jiffies
576 u64 bch2_ratelimit_delay(struct bch_ratelimit *d)
578 u64 now = local_clock();
580 return time_after64(d->next, now)
581 ? nsecs_to_jiffies(d->next - now)
586 * bch2_ratelimit_increment() - increment @d by the amount of work done
588 * @d - the struct bch_ratelimit to update
589 * @done - the amount of work done, in arbitrary units
591 void bch2_ratelimit_increment(struct bch_ratelimit *d, u64 done)
593 u64 now = local_clock();
595 d->next += div_u64(done * NSEC_PER_SEC, d->rate);
597 if (time_before64(now + NSEC_PER_SEC, d->next))
598 d->next = now + NSEC_PER_SEC;
600 if (time_after64(now - NSEC_PER_SEC * 2, d->next))
601 d->next = now - NSEC_PER_SEC * 2;
607 * Updates pd_controller. Attempts to scale inputed values to units per second.
608 * @target: desired value
609 * @actual: current value
611 * @sign: 1 or -1; 1 if increasing the rate makes actual go up, -1 if increasing
612 * it makes actual go down.
614 void bch2_pd_controller_update(struct bch_pd_controller *pd,
615 s64 target, s64 actual, int sign)
617 s64 proportional, derivative, change;
619 unsigned long seconds_since_update = (jiffies - pd->last_update) / HZ;
621 if (seconds_since_update == 0)
624 pd->last_update = jiffies;
626 proportional = actual - target;
627 proportional *= seconds_since_update;
628 proportional = div_s64(proportional, pd->p_term_inverse);
630 derivative = actual - pd->last_actual;
631 derivative = div_s64(derivative, seconds_since_update);
632 derivative = ewma_add(pd->smoothed_derivative, derivative,
633 (pd->d_term / seconds_since_update) ?: 1);
634 derivative = derivative * pd->d_term;
635 derivative = div_s64(derivative, pd->p_term_inverse);
637 change = proportional + derivative;
639 /* Don't increase rate if not keeping up */
642 time_after64(local_clock(),
643 pd->rate.next + NSEC_PER_MSEC))
646 change *= (sign * -1);
648 pd->rate.rate = clamp_t(s64, (s64) pd->rate.rate + change,
651 pd->last_actual = actual;
652 pd->last_derivative = derivative;
653 pd->last_proportional = proportional;
654 pd->last_change = change;
655 pd->last_target = target;
658 void bch2_pd_controller_init(struct bch_pd_controller *pd)
660 pd->rate.rate = 1024;
661 pd->last_update = jiffies;
662 pd->p_term_inverse = 6000;
664 pd->d_smooth = pd->d_term;
665 pd->backpressure = 1;
668 void bch2_pd_controller_debug_to_text(struct printbuf *out, struct bch_pd_controller *pd)
670 if (!out->nr_tabstops)
671 printbuf_tabstop_push(out, 20);
673 prt_printf(out, "rate:");
675 prt_human_readable_s64(out, pd->rate.rate);
678 prt_printf(out, "target:");
680 prt_human_readable_u64(out, pd->last_target);
683 prt_printf(out, "actual:");
685 prt_human_readable_u64(out, pd->last_actual);
688 prt_printf(out, "proportional:");
690 prt_human_readable_s64(out, pd->last_proportional);
693 prt_printf(out, "derivative:");
695 prt_human_readable_s64(out, pd->last_derivative);
698 prt_printf(out, "change:");
700 prt_human_readable_s64(out, pd->last_change);
703 prt_printf(out, "next io:");
705 prt_printf(out, "%llims", div64_s64(pd->rate.next - local_clock(), NSEC_PER_MSEC));
711 void bch2_bio_map(struct bio *bio, void *base, size_t size)
714 struct page *page = is_vmalloc_addr(base)
715 ? vmalloc_to_page(base)
716 : virt_to_page(base);
717 unsigned offset = offset_in_page(base);
718 unsigned len = min_t(size_t, PAGE_SIZE - offset, size);
720 BUG_ON(!bio_add_page(bio, page, len, offset));
726 int bch2_bio_alloc_pages(struct bio *bio, size_t size, gfp_t gfp_mask)
729 struct page *page = alloc_page(gfp_mask);
730 unsigned len = min_t(size_t, PAGE_SIZE, size);
735 if (unlikely(!bio_add_page(bio, page, len, 0))) {
746 size_t bch2_rand_range(size_t max)
754 rand = get_random_long();
755 rand &= roundup_pow_of_two(max) - 1;
756 } while (rand >= max);
761 void memcpy_to_bio(struct bio *dst, struct bvec_iter dst_iter, const void *src)
764 struct bvec_iter iter;
766 __bio_for_each_segment(bv, dst, iter, dst_iter) {
767 void *dstp = kmap_atomic(bv.bv_page);
768 memcpy(dstp + bv.bv_offset, src, bv.bv_len);
775 void memcpy_from_bio(void *dst, struct bio *src, struct bvec_iter src_iter)
778 struct bvec_iter iter;
780 __bio_for_each_segment(bv, src, iter, src_iter) {
781 void *srcp = kmap_atomic(bv.bv_page);
782 memcpy(dst, srcp + bv.bv_offset, bv.bv_len);
789 static int alignment_ok(const void *base, size_t align)
791 return IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) ||
792 ((unsigned long)base & (align - 1)) == 0;
795 static void u32_swap(void *a, void *b, size_t size)
798 *(u32 *)a = *(u32 *)b;
802 static void u64_swap(void *a, void *b, size_t size)
805 *(u64 *)a = *(u64 *)b;
809 static void generic_swap(void *a, void *b, size_t size)
815 *(char *)a++ = *(char *)b;
817 } while (--size > 0);
820 static inline int do_cmp(void *base, size_t n, size_t size,
821 int (*cmp_func)(const void *, const void *, size_t),
824 return cmp_func(base + inorder_to_eytzinger0(l, n) * size,
825 base + inorder_to_eytzinger0(r, n) * size,
829 static inline void do_swap(void *base, size_t n, size_t size,
830 void (*swap_func)(void *, void *, size_t),
833 swap_func(base + inorder_to_eytzinger0(l, n) * size,
834 base + inorder_to_eytzinger0(r, n) * size,
838 void eytzinger0_sort(void *base, size_t n, size_t size,
839 int (*cmp_func)(const void *, const void *, size_t),
840 void (*swap_func)(void *, void *, size_t))
845 if (size == 4 && alignment_ok(base, 4))
846 swap_func = u32_swap;
847 else if (size == 8 && alignment_ok(base, 8))
848 swap_func = u64_swap;
850 swap_func = generic_swap;
854 for (i = n / 2 - 1; i >= 0; --i) {
855 for (r = i; r * 2 + 1 < n; r = c) {
859 do_cmp(base, n, size, cmp_func, c, c + 1) < 0)
862 if (do_cmp(base, n, size, cmp_func, r, c) >= 0)
865 do_swap(base, n, size, swap_func, r, c);
870 for (i = n - 1; i > 0; --i) {
871 do_swap(base, n, size, swap_func, 0, i);
873 for (r = 0; r * 2 + 1 < i; r = c) {
877 do_cmp(base, n, size, cmp_func, c, c + 1) < 0)
880 if (do_cmp(base, n, size, cmp_func, r, c) >= 0)
883 do_swap(base, n, size, swap_func, r, c);
888 void sort_cmp_size(void *base, size_t num, size_t size,
889 int (*cmp_func)(const void *, const void *, size_t),
890 void (*swap_func)(void *, void *, size_t size))
892 /* pre-scale counters for performance */
893 int i = (num/2 - 1) * size, n = num * size, c, r;
896 if (size == 4 && alignment_ok(base, 4))
897 swap_func = u32_swap;
898 else if (size == 8 && alignment_ok(base, 8))
899 swap_func = u64_swap;
901 swap_func = generic_swap;
905 for ( ; i >= 0; i -= size) {
906 for (r = i; r * 2 + size < n; r = c) {
909 cmp_func(base + c, base + c + size, size) < 0)
911 if (cmp_func(base + r, base + c, size) >= 0)
913 swap_func(base + r, base + c, size);
918 for (i = n - size; i > 0; i -= size) {
919 swap_func(base, base + i, size);
920 for (r = 0; r * 2 + size < i; r = c) {
923 cmp_func(base + c, base + c + size, size) < 0)
925 if (cmp_func(base + r, base + c, size) >= 0)
927 swap_func(base + r, base + c, size);
932 static void mempool_free_vp(void *element, void *pool_data)
934 size_t size = (size_t) pool_data;
936 vpfree(element, size);
939 static void *mempool_alloc_vp(gfp_t gfp_mask, void *pool_data)
941 size_t size = (size_t) pool_data;
943 return vpmalloc(size, gfp_mask);
946 int mempool_init_kvpmalloc_pool(mempool_t *pool, int min_nr, size_t size)
948 return size < PAGE_SIZE
949 ? mempool_init_kmalloc_pool(pool, min_nr, size)
950 : mempool_init(pool, min_nr, mempool_alloc_vp,
951 mempool_free_vp, (void *) size);
955 void eytzinger1_test(void)
957 unsigned inorder, eytz, size;
959 pr_info("1 based eytzinger test:");
964 unsigned extra = eytzinger1_extra(size);
967 pr_info("tree size %u", size);
969 BUG_ON(eytzinger1_prev(0, size) != eytzinger1_last(size));
970 BUG_ON(eytzinger1_next(0, size) != eytzinger1_first(size));
972 BUG_ON(eytzinger1_prev(eytzinger1_first(size), size) != 0);
973 BUG_ON(eytzinger1_next(eytzinger1_last(size), size) != 0);
976 eytzinger1_for_each(eytz, size) {
977 BUG_ON(__inorder_to_eytzinger1(inorder, size, extra) != eytz);
978 BUG_ON(__eytzinger1_to_inorder(eytz, size, extra) != inorder);
979 BUG_ON(eytz != eytzinger1_last(size) &&
980 eytzinger1_prev(eytzinger1_next(eytz, size), size) != eytz);
987 void eytzinger0_test(void)
990 unsigned inorder, eytz, size;
992 pr_info("0 based eytzinger test:");
997 unsigned extra = eytzinger0_extra(size);
1000 pr_info("tree size %u", size);
1002 BUG_ON(eytzinger0_prev(-1, size) != eytzinger0_last(size));
1003 BUG_ON(eytzinger0_next(-1, size) != eytzinger0_first(size));
1005 BUG_ON(eytzinger0_prev(eytzinger0_first(size), size) != -1);
1006 BUG_ON(eytzinger0_next(eytzinger0_last(size), size) != -1);
1009 eytzinger0_for_each(eytz, size) {
1010 BUG_ON(__inorder_to_eytzinger0(inorder, size, extra) != eytz);
1011 BUG_ON(__eytzinger0_to_inorder(eytz, size, extra) != inorder);
1012 BUG_ON(eytz != eytzinger0_last(size) &&
1013 eytzinger0_prev(eytzinger0_next(eytz, size), size) != eytz);
1020 static inline int cmp_u16(const void *_l, const void *_r, size_t size)
1022 const u16 *l = _l, *r = _r;
1024 return (*l > *r) - (*r - *l);
1027 static void eytzinger0_find_test_val(u16 *test_array, unsigned nr, u16 search)
1029 int i, c1 = -1, c2 = -1;
1032 r = eytzinger0_find_le(test_array, nr,
1033 sizeof(test_array[0]),
1038 for (i = 0; i < nr; i++)
1039 if (test_array[i] <= search && test_array[i] > c2)
1043 eytzinger0_for_each(i, nr)
1044 pr_info("[%3u] = %12u", i, test_array[i]);
1045 pr_info("find_le(%2u) -> [%2zi] = %2i should be %2i",
1050 void eytzinger0_find_test(void)
1052 unsigned i, nr, allocated = 1 << 12;
1053 u16 *test_array = kmalloc_array(allocated, sizeof(test_array[0]), GFP_KERNEL);
1055 for (nr = 1; nr < allocated; nr++) {
1056 pr_info("testing %u elems", nr);
1058 get_random_bytes(test_array, nr * sizeof(test_array[0]));
1059 eytzinger0_sort(test_array, nr, sizeof(test_array[0]), cmp_u16, NULL);
1061 /* verify array is sorted correctly: */
1062 eytzinger0_for_each(i, nr)
1063 BUG_ON(i != eytzinger0_last(nr) &&
1064 test_array[i] > test_array[eytzinger0_next(i, nr)]);
1066 for (i = 0; i < U16_MAX; i += 1 << 12)
1067 eytzinger0_find_test_val(test_array, nr, i);
1069 for (i = 0; i < nr; i++) {
1070 eytzinger0_find_test_val(test_array, nr, test_array[i] - 1);
1071 eytzinger0_find_test_val(test_array, nr, test_array[i]);
1072 eytzinger0_find_test_val(test_array, nr, test_array[i] + 1);
1081 * Accumulate percpu counters onto one cpu's copy - only valid when access
1082 * against any percpu counter is guarded against
1084 u64 *bch2_acc_percpu_u64s(u64 __percpu *p, unsigned nr)
1089 /* access to pcpu vars has to be blocked by other locking */
1091 ret = this_cpu_ptr(p);
1094 for_each_possible_cpu(cpu) {
1095 u64 *i = per_cpu_ptr(p, cpu);
1098 acc_u64s(ret, i, nr);
1099 memset(i, 0, nr * sizeof(u64));