FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
interrupt.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef included_clib_interrupt_h
17 #define included_clib_interrupt_h
18 
19 #include <vppinfra/clib.h>
20 #include <vppinfra/bitops.h> /* for count_set_bits */
21 #include <vppinfra/vec.h>
22 
23 typedef struct
24 {
25  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
26  int n_int;
29 
30 void clib_interrupt_init (void **data, uword n_interrupts);
31 void clib_interrupt_resize (void **data, uword n_interrupts);
32 
35 {
36  if (data[0])
37  {
38  clib_mem_free (data[0]);
39  data[0] = 0;
40  }
41 }
42 
45 {
47  if (h)
48  return h->n_int;
49  return 0;
50 }
51 
54 {
55  return d + sizeof (clib_interrupt_header_t);
56 }
57 
60 {
62  return clib_interrupt_get_bitmap (d) + h->n_uword_alloc;
63 }
64 
66 clib_interrupt_set (void *in, int int_num)
67 {
68  uword *bmp = clib_interrupt_get_bitmap (in);
69  uword mask = 1ULL << (int_num & (uword_bits - 1));
70  bmp += int_num >> log2_uword_bits;
71 
72  ASSERT (int_num < ((clib_interrupt_header_t *) in)->n_int);
73 
74  *bmp |= mask;
75 }
76 
78 clib_interrupt_set_atomic (void *in, int int_num)
79 {
81  uword mask = 1ULL << (int_num & (uword_bits - 1));
82  bmp += int_num >> log2_uword_bits;
83 
84  ASSERT (int_num < ((clib_interrupt_header_t *) in)->n_int);
85 
86  __atomic_fetch_or (bmp, mask, __ATOMIC_RELAXED);
87 }
88 
90 clib_interrupt_clear (void *in, int int_num)
91 {
92  uword *bmp = clib_interrupt_get_bitmap (in);
94  uword mask = 1ULL << (int_num & (uword_bits - 1));
95  uword off = int_num >> log2_uword_bits;
96 
97  ASSERT (int_num < ((clib_interrupt_header_t *) in)->n_int);
98 
99  bmp[off] |= __atomic_exchange_n (abm + off, 0, __ATOMIC_SEQ_CST);
100  bmp[off] &= ~mask;
101 }
102 
105 {
106  uword *bmp = clib_interrupt_get_bitmap (in);
109  uword bmp_uword, off;
110 
111  ASSERT (last >= -1 && last < h->n_int);
112 
113  off = (last + 1) >> log2_uword_bits;
114 
115  last -= off << log2_uword_bits;
116  bmp[off] |= __atomic_exchange_n (abm + off, 0, __ATOMIC_SEQ_CST);
117  bmp_uword = bmp[off] & ~pow2_mask (last + 1);
118 
119 next:
120  if (bmp_uword)
121  return (off << log2_uword_bits) + count_trailing_zeros (bmp_uword);
122 
123  off++;
124 
125  if (off > h->n_int >> log2_uword_bits)
126  return -1;
127 
128  bmp[off] |= __atomic_exchange_n (abm + off, 0, __ATOMIC_SEQ_CST);
129  bmp_uword = bmp[off];
130 
131  goto next;
132 }
133 
134 #endif /* included_clib_interrupt_h */
135 
136 /*
137  * fd.io coding-style-patch-verification: ON
138  *
139  * Local Variables:
140  * eval: (c-set-style "gnu")
141  * End:
142  */
clib_interrupt_free
static_always_inline void clib_interrupt_free(void **data)
Definition: interrupt.h:34
count_trailing_zeros
#define count_trailing_zeros(x)
Definition: clib.h:161
clib_interrupt_header_t
Definition: interrupt.h:23
pow2_mask
static uword pow2_mask(uword x)
Definition: clib.h:252
CLIB_CACHE_LINE_ALIGN_MARK
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
clib.h
next
u16 * next
Definition: nat44_ei_out2in.c:718
clib_mem_free
static void clib_mem_free(void *p)
Definition: mem.h:314
clib_interrupt_get_next
static_always_inline int clib_interrupt_get_next(void *in, int last)
Definition: interrupt.h:104
clib_interrupt_set_atomic
static_always_inline void clib_interrupt_set_atomic(void *in, int int_num)
Definition: interrupt.h:78
h
h
Definition: flowhash_template.h:372
log2_uword_bits
#define log2_uword_bits
Definition: types.h:80
clib_interrupt_get_atomic_bitmap
static_always_inline uword * clib_interrupt_get_atomic_bitmap(void *d)
Definition: interrupt.h:59
clib_interrupt_clear
static_always_inline void clib_interrupt_clear(void *in, int int_num)
Definition: interrupt.h:90
bitops.h
static_always_inline
#define static_always_inline
Definition: clib.h:112
uword
u64 uword
Definition: types.h:112
last
static heap_elt_t * last(heap_header_t *h)
Definition: heap.c:53
clib_interrupt_set
static_always_inline void clib_interrupt_set(void *in, int int_num)
Definition: interrupt.h:66
mask
vl_api_pnat_mask_t mask
Definition: pnat.api:45
clib_interrupt_get_n_int
static_always_inline int clib_interrupt_get_n_int(void *d)
Definition: interrupt.h:44
data
u8 data[128]
Definition: ipsec_types.api:95
clib_interrupt_resize
void clib_interrupt_resize(void **data, uword n_interrupts)
Definition: interrupt.c:38
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
off
u32 off
Definition: interface_output.c:1096
clib_interrupt_init
void clib_interrupt_init(void **data, uword n_interrupts)
Definition: interrupt.c:24
clib_interrupt_get_bitmap
static_always_inline uword * clib_interrupt_get_bitmap(void *d)
Definition: interrupt.h:53
vec.h
clib_interrupt_header_t::n_int
int n_int
Definition: interrupt.h:26
uword_bits
#define uword_bits
Definition: types.h:102
clib_interrupt_header_t::n_uword_alloc
uword n_uword_alloc
Definition: interrupt.h:27