FD.io VPP
v21.06-3-gbb25fbf28
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 <
vnet/util/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
vlib_refcount_lock
(per_cpu->
counter_lock
);
23
memcpy(new_counter, per_cpu->
counters
,
vec_len
(per_cpu->
counters
)*4);
24
old_counter = per_cpu->
counters
;
25
per_cpu->
counters
= new_counter;
26
vlib_refcount_unlock
(per_cpu->
counter_lock
);
27
CLIB_MEMORY_BARRIER
();
28
vec_free
(old_counter);
29
}
30
31
u64
vlib_refcount_get
(
vlib_refcount_t
*
r
,
u32
index
)
32
{
33
u64
count
= 0;
34
vlib_thread_main_t
*tm =
vlib_get_thread_main
();
35
u32
thread_index
;
36
for
(
thread_index
= 0;
thread_index
< tm->
n_vlib_mains
;
thread_index
++) {
37
vlib_refcount_lock
(
r
->per_cpu[
thread_index
].counter_lock);
38
if
(
index
<
vec_len
(
r
->per_cpu[
thread_index
].counters))
39
{
40
count
+=
r
->per_cpu[
thread_index
].counters[
index
];
41
}
42
vlib_refcount_unlock
(
r
->per_cpu[
thread_index
].counter_lock);
43
}
44
return
count
;
45
}
46
thread_index
u32 thread_index
Definition:
nat44_ei_hairpinning.c:492
vlib_refcount_lock
static_always_inline void vlib_refcount_lock(clib_spinlock_t counter_lock)
Definition:
refcount.h:54
r
vnet_hw_if_output_node_runtime_t * r
Definition:
interface_output.c:1071
vlib_thread_main_t::n_vlib_mains
u32 n_vlib_mains
Definition:
threads.h:283
count
u8 count
Definition:
dhcp.api:208
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition:
vec_bootstrap.h:142
vlib_refcount_per_cpu_t
Definition:
refcount.h:43
vlib_refcount_unlock
static_always_inline void vlib_refcount_unlock(clib_spinlock_t counter_lock)
Definition:
refcount.h:60
vlib_refcount_per_cpu_t::counter_lock
clib_spinlock_t counter_lock
Definition:
refcount.h:45
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition:
vec.h:523
CLIB_MEMORY_BARRIER
#define CLIB_MEMORY_BARRIER()
Definition:
clib.h:137
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition:
vec.h:395
size
u32 size
Definition:
vhost_user.h:125
index
u32 index
Definition:
flow_types.api:221
u64
unsigned long u64
Definition:
types.h:89
u32
unsigned int u32
Definition:
types.h:88
vlib_thread_main_t
Definition:
threads.h:264
refcount.h
vlib_refcount_t
Definition:
refcount.h:49
vlib_refcount_get
u64 vlib_refcount_get(vlib_refcount_t *r, u32 index)
Definition:
refcount.c:31
vlib_get_thread_main
static vlib_thread_main_t * vlib_get_thread_main()
Definition:
global_funcs.h:56
vlib_refcount_per_cpu_t::counters
u32 * counters
Definition:
refcount.h:44
src
vnet
util
refcount.c
Generated on Sat Jan 8 2022 10:05:36 for FD.io VPP by
1.8.17