1 /* SPDX-License-Identifier: Apache-2.0
2 * Copyright (c) 2023 Cisco Systems, Inc.
5 #include <vppinfra/clib.h>
6 #include <vppinfra/interrupt.h>
9 clib_interrupt_init (void **data, u32 n_int)
11 clib_interrupt_header_t *h;
12 const u32 bits_in_cl = 8 << CLIB_LOG2_CACHE_LINE_BYTES;
13 u32 sz = sizeof (clib_interrupt_header_t);
14 u32 n_cl = round_pow2 (n_int, bits_in_cl) / bits_in_cl;
16 sz += 2 * n_cl * CLIB_CACHE_LINE_BYTES;
17 h = data[0] = clib_mem_alloc_aligned (sz, CLIB_CACHE_LINE_BYTES);
18 clib_memset (data[0], 0, sz);
20 h->uwords_allocated = n_cl * bits_in_cl / uword_bits;
21 h->uwords_used = round_pow2 (n_int, uword_bits) / uword_bits;
22 h->local = (uword *) (h + 1);
23 h->remote = h->local + h->uwords_allocated;
27 clib_interrupt_resize (void **data, u32 n_int)
29 clib_interrupt_header_t *h = data[0];
34 clib_interrupt_init (data, n_int);
38 if (n_int == h->n_int)
41 new_n_uwords = round_pow2 (n_int, uword_bits) / uword_bits;
43 if (new_n_uwords > h->uwords_allocated)
45 clib_interrupt_header_t *nh;
46 clib_interrupt_init ((void **) &nh, n_int);
47 for (int i = 0; i < h->uwords_used; i++)
48 nh->local[i] = h->local[i] | h->remote[i];
49 clib_mem_free (data[0]);
55 h->uwords_used = new_n_uwords;
57 for (i = 0; i < new_n_uwords; i++)
58 h->local[i] |= h->remote[i];
60 for (i = 0; i < h->uwords_allocated; i++)
63 for (i = new_n_uwords; i < h->uwords_allocated; i++)
66 n_int &= pow2_mask (log2_uword_bits);
69 h->local[n_int >> log2_uword_bits] &= pow2_mask (n_int);