FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
interrupt.c
Go to the documentation of this file.
1 
2 /*
3  * Copyright (c) 2020 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <vppinfra/clib.h>
18 #include <vppinfra/bitops.h> /* for count_set_bits */
19 #include <vppinfra/vec.h>
20 #include <vppinfra/interrupt.h>
21 #include <vppinfra/format.h>
22 
23 __clib_export void
25 {
27  uword sz = sizeof (clib_interrupt_header_t);
28  uword data_size = round_pow2 (n_int, CLIB_CACHE_LINE_BYTES * 8) / 8;
29 
30  sz += 2 * data_size;
32  clib_memset (data[0], 0, sz);
33  h->n_int = n_int;
34  h->n_uword_alloc = (data_size * 8) >> log2_uword_bits;
35 }
36 
37 __clib_export void
39 {
41 
42  if (data[0] == 0)
43  {
44  clib_interrupt_init (data, n_int);
45  return;
46  }
47 
48  if (n_int < h->n_int)
49  {
50  uword *old_bmp, *old_abp, v;
51  old_bmp = clib_interrupt_get_bitmap (data[0]);
53  for (uword i = 0; i < h->n_uword_alloc; i++)
54  {
55  v = old_abp[i];
56  old_abp[i] = 0;
57  if (n_int > ((i + 1) * uword_bits))
58  old_bmp[i] |= v;
59  else if (n_int > (i * uword_bits))
60  old_bmp[i] = (old_bmp[i] | v) & pow2_mask (n_int - i * uword_bits);
61  else
62  old_bmp[i] = 0;
63  }
64  }
65  else if (n_int > h->n_uword_alloc * uword_bits)
66  {
67  void *old = data[0];
68  uword *old_bmp, *old_abp, *new_bmp;
69  uword n_uwords = round_pow2 (h->n_int, uword_bits) / uword_bits;
70 
71  clib_interrupt_init (data, n_int);
72  h = data[0];
73 
74  new_bmp = clib_interrupt_get_bitmap (data[0]);
75  old_bmp = clib_interrupt_get_bitmap (old);
76  old_abp = clib_interrupt_get_atomic_bitmap (old);
77 
78  for (uword i = 0; i < n_uwords; i++)
79  new_bmp[i] = old_bmp[i] | old_abp[i];
80 
81  clib_mem_free (old);
82  }
83  h->n_int = n_int;
84 }
85 
86 /*
87  * fd.io coding-style-patch-verification: ON
88  *
89  * Local Variables:
90  * eval: (c-set-style "gnu")
91  * End:
92  */
clib_interrupt_header_t
Definition: interrupt.h:23
pow2_mask
static uword pow2_mask(uword x)
Definition: clib.h:252
clib.h
clib_mem_free
static void clib_mem_free(void *p)
Definition: mem.h:311
h
h
Definition: flowhash_template.h:372
round_pow2
static uword round_pow2(uword x, uword pow2)
Definition: clib.h:279
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
interrupt.h
clib_interrupt_resize
__clib_export void clib_interrupt_resize(void **data, uword n_int)
Definition: interrupt.c:38
bitops.h
uword
u64 uword
Definition: types.h:112
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
format.h
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
data
u8 data[128]
Definition: ipsec_types.api:92
clib_interrupt_get_bitmap
static_always_inline uword * clib_interrupt_get_bitmap(void *d)
Definition: interrupt.h:53
vec.h
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
clib_mem_alloc_aligned
static void * clib_mem_alloc_aligned(uword size, uword align)
Definition: mem.h:261
uword_bits
#define uword_bits
Definition: types.h:102
clib_interrupt_init
__clib_export void clib_interrupt_init(void **data, uword n_int)
Definition: interrupt.c:24