FD.io VPP  v17.01-9-ge7dcee4
Vector Packet Processing
smp_fifo.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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  Copyright (c) 2012 Eliot Dresselhaus
17 
18  Permission is hereby granted, free of charge, to any person obtaining
19  a copy of this software and associated documentation files (the
20  "Software"), to deal in the Software without restriction, including
21  without limitation the rights to use, copy, modify, merge, publish,
22  distribute, sublicense, and/or sell copies of the Software, and to
23  permit persons to whom the Software is furnished to do so, subject to
24  the following conditions:
25 
26  The above copyright notice and this permission notice shall be
27  included in all copies or substantial portions of the Software.
28 
29  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 */
37 
38 #include <vppinfra/smp_fifo.h>
39 #include <vppinfra/mem.h>
40 
42 clib_smp_fifo_init (uword max_n_elts, uword n_bytes_per_elt)
43 {
44  clib_smp_fifo_t *f;
45  uword n_bytes_per_elt_cache_aligned;
46 
47  f = clib_mem_alloc_aligned (sizeof (f[0]), CLIB_CACHE_LINE_BYTES);
48 
49  memset (f, 0, sizeof (f[0]));
50 
51  max_n_elts = max_n_elts ? max_n_elts : 32;
52  f->log2_max_n_elts = max_log2 (max_n_elts);
53  f->max_n_elts_less_one = (1 << f->log2_max_n_elts) - 1;
54 
55  n_bytes_per_elt_cache_aligned =
56  clib_smp_fifo_round_elt_bytes (n_bytes_per_elt);
57  clib_exec_on_global_heap (
58  {
59  f->data =
61  (n_bytes_per_elt_cache_aligned <<
63  );
64 
65  /* Zero all data and mark all elements free. */
66  {
67  uword i;
68  for (i = 0; i <= f->max_n_elts_less_one; i++)
69  {
70  void *d = clib_smp_fifo_elt_at_index (f, n_bytes_per_elt, i);
72 
73  memset (d, 0, n_bytes_per_elt_cache_aligned);
74 
75  t = clib_smp_fifo_get_data_footer (d, n_bytes_per_elt);
77  CLIB_SMP_FIFO_DATA_STATE_free);
78  }
79  }
80 
81  return f;
82 }
83 
84 
85 /*
86  * fd.io coding-style-patch-verification: ON
87  *
88  * Local Variables:
89  * eval: (c-set-style "gnu")
90  * End:
91  */
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:343
static uword clib_smp_fifo_round_elt_bytes(uword n_bytes_per_elt)
Definition: smp_fifo.h:106
void * data
Definition: smp_fifo.h:98
static clib_smp_fifo_data_footer_t * clib_smp_fifo_get_data_footer(void *d, uword n_bytes_per_elt)
Definition: smp_fifo.h:120
clib_smp_fifo_t * clib_smp_fifo_init(uword max_n_elts, uword n_bytes_per_elt)
Definition: smp_fifo.c:42
u32 log2_max_n_elts
Definition: smp_fifo.h:95
static void clib_smp_fifo_data_footer_set_state(clib_smp_fifo_data_footer_t *f, clib_smp_fifo_data_state_t s)
Definition: smp_fifo.h:79
u64 uword
Definition: types.h:112
static uword max_log2(uword x)
Definition: clib.h:222
static void * clib_mem_alloc_aligned(uword size, uword align)
Definition: mem.h:117
static void * clib_smp_fifo_elt_at_index(clib_smp_fifo_t *f, uword n_bytes_per_elt, uword i)
Definition: smp_fifo.h:128
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
u32 max_n_elts_less_one
Definition: smp_fifo.h:92