FD.io VPP  v17.04.2-2-ga8f93f8
Vector Packet Processing
refcount.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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 #include <lb/refcount.h>
17 
18 void __vlib_refcount_resize(vlib_refcount_per_cpu_t *per_cpu, u32 size)
19 {
20  u32 *new_counter = 0, *old_counter;
21  vec_validate(new_counter, size);
22  memcpy(new_counter, per_cpu->counters, per_cpu->length);
23  old_counter = per_cpu->counters;
24  per_cpu->counters = new_counter;
26  per_cpu->length = vec_len(new_counter);
27  vec_free(old_counter);
28 }
29 
31 {
32  u64 count = 0;
34  u32 cpu_index;
35  for (cpu_index = 0; cpu_index < tm->n_vlib_mains; cpu_index++) {
36  if (r->per_cpu[cpu_index].length > index)
37  count += r->per_cpu[cpu_index].counters[index];
38  }
39  return count;
40 }
41 
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:436
unsigned long u64
Definition: types.h:89
u64 vlib_refcount_get(vlib_refcount_t *r, u32 index)
Definition: refcount.c:30
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:340
unsigned int u32
Definition: types.h:88
u64 size
Definition: vhost-user.h:77
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
#define CLIB_MEMORY_BARRIER()
Definition: clib.h:101
vlib_refcount_per_cpu_t * per_cpu
Definition: refcount.h:42