Damjan Marion | 7f75e80 | 2023-11-03 21:57:42 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright (c) 2023 Cisco Systems, Inc. |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 3 | */ |
| 4 | |
| 5 | #include <vppinfra/clib.h> |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 6 | #include <vppinfra/interrupt.h> |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 7 | |
| 8 | __clib_export void |
Damjan Marion | 7f75e80 | 2023-11-03 21:57:42 +0000 | [diff] [blame] | 9 | clib_interrupt_init (void **data, u32 n_int) |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 10 | { |
| 11 | clib_interrupt_header_t *h; |
Damjan Marion | 7f75e80 | 2023-11-03 21:57:42 +0000 | [diff] [blame] | 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; |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 15 | |
Damjan Marion | 7f75e80 | 2023-11-03 21:57:42 +0000 | [diff] [blame] | 16 | sz += 2 * n_cl * CLIB_CACHE_LINE_BYTES; |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 17 | h = data[0] = clib_mem_alloc_aligned (sz, CLIB_CACHE_LINE_BYTES); |
| 18 | clib_memset (data[0], 0, sz); |
| 19 | h->n_int = n_int; |
Damjan Marion | 7f75e80 | 2023-11-03 21:57:42 +0000 | [diff] [blame] | 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; |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | __clib_export void |
Damjan Marion | 7f75e80 | 2023-11-03 21:57:42 +0000 | [diff] [blame] | 27 | clib_interrupt_resize (void **data, u32 n_int) |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 28 | { |
| 29 | clib_interrupt_header_t *h = data[0]; |
Damjan Marion | 7f75e80 | 2023-11-03 21:57:42 +0000 | [diff] [blame] | 30 | u32 new_n_uwords, i; |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 31 | |
| 32 | if (data[0] == 0) |
| 33 | { |
| 34 | clib_interrupt_init (data, n_int); |
| 35 | return; |
| 36 | } |
| 37 | |
Damjan Marion | 7f75e80 | 2023-11-03 21:57:42 +0000 | [diff] [blame] | 38 | if (n_int == h->n_int) |
| 39 | return; |
| 40 | |
| 41 | new_n_uwords = round_pow2 (n_int, uword_bits) / uword_bits; |
| 42 | |
| 43 | if (new_n_uwords > h->uwords_allocated) |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 44 | { |
Damjan Marion | 7f75e80 | 2023-11-03 21:57:42 +0000 | [diff] [blame] | 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]); |
| 50 | data[0] = nh; |
| 51 | return; |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 52 | } |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 53 | |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 54 | h->n_int = n_int; |
Damjan Marion | 7f75e80 | 2023-11-03 21:57:42 +0000 | [diff] [blame] | 55 | h->uwords_used = new_n_uwords; |
| 56 | |
| 57 | for (i = 0; i < new_n_uwords; i++) |
| 58 | h->local[i] |= h->remote[i]; |
| 59 | |
| 60 | for (i = 0; i < h->uwords_allocated; i++) |
| 61 | h->remote[i] = 0; |
| 62 | |
| 63 | for (i = new_n_uwords; i < h->uwords_allocated; i++) |
| 64 | h->local[i] = 0; |
| 65 | |
| 66 | n_int &= pow2_mask (log2_uword_bits); |
| 67 | |
| 68 | if (n_int) |
| 69 | h->local[n_int >> log2_uword_bits] &= pow2_mask (n_int); |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 70 | } |
| 71 | |