FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
mem.c
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 #include <vppinfra/clib.h>
17 #include <vppinfra/mem.h>
18 #include <vppinfra/time.h>
19 #include <vppinfra/format.h>
20 #include <vppinfra/clib_error.h>
21 
23 
24 __clib_export void *
25 clib_mem_vm_map (void *base, uword size, clib_mem_page_sz_t log2_page_sz,
26  char *fmt, ...)
27 {
28  va_list va;
29  void *rv;
30  u8 *s;
31 
32  va_start (va, fmt);
33  s = va_format (0, fmt, &va);
34  vec_add1 (s, 0);
35  rv = clib_mem_vm_map_internal (base, log2_page_sz, size, -1, 0, (char *) s);
36  va_end (va);
37  vec_free (s);
38  return rv;
39 }
40 
41 __clib_export void *
43  char *fmt, ...)
44 {
45  va_list va;
46  void *rv;
47  u8 *s;
48 
49  va_start (va, fmt);
50  s = va_format (0, fmt, &va);
51  vec_add1 (s, 0);
52  rv = clib_mem_vm_map_internal (0, log2_page_sz, size, -1, 0, (char *) s);
53  va_end (va);
54  vec_free (s);
55  return rv;
56 }
57 
58 __clib_export void *
60  char *fmt, ...)
61 {
62  va_list va;
63  void *rv;
64  u8 *s;
65  va_start (va, fmt);
66  s = va_format (0, fmt, &va);
67  vec_add1 (s, 0);
68  rv = clib_mem_vm_map_internal (base, 0, size, fd, offset, (char *) s);
69  va_end (va);
70  vec_free (s);
71  return rv;
72 }
73 
74 u8 *
75 format_clib_mem_page_stats (u8 * s, va_list * va)
76 {
78  u32 indent = format_get_indent (s) + 2;
79 
80  s = format (s, "page stats: page-size %U, total %lu, mapped %lu, "
81  "not-mapped %lu", format_log2_page_size, stats->log2_page_sz,
82  stats->total, stats->mapped, stats->not_mapped);
83 
84  if (stats->unknown)
85  s = format (s, ", unknown %lu", stats->unknown);
86 
87  for (int i = 0; i < CLIB_MAX_NUMAS; i++)
88  if (stats->per_numa[i])
89  s = format (s, "\n%Unuma %u: %lu pages, %U bytes",
90  format_white_space, indent, i,
91  stats->per_numa[i],
93  stats->per_numa[i] << stats->log2_page_sz);
94 
95  return s;
96 }
97 
98 /*
99  * fd.io coding-style-patch-verification: ON
100  *
101  * Local Variables:
102  * eval: (c-set-style "gnu")
103  * End:
104  */
clib_mem_page_stats_t
Definition: mem.h:523
clib.h
clib_mem_vm_map_shared
__clib_export void * clib_mem_vm_map_shared(void *base, uword size, int fd, uword offset, char *fmt,...)
Definition: mem.c:59
clib_mem_vm_map
__clib_export void * clib_mem_vm_map(void *base, uword size, clib_mem_page_sz_t log2_page_sz, char *fmt,...)
Definition: mem.c:25
va_format
__clib_export u8 * va_format(u8 *s, const char *fmt, va_list *va)
Definition: format.c:391
stats
vl_api_ikev2_sa_stats_t stats
Definition: ikev2_types.api:162
clib_mem_main_t
Definition: mem.h:128
format_log2_page_size
u8 * format_log2_page_size(u8 *s, va_list *va)
Definition: std-formats.c:273
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
uword
u64 uword
Definition: types.h:112
time.h
format.h
clib_mem_vm_map_internal
void * clib_mem_vm_map_internal(void *base, clib_mem_page_sz_t log2_page_sz, uword size, int fd, uword offset, char *name)
Definition: mem.c:375
fmt
int cJSON_bool fmt
Definition: cJSON.h:160
format_memory_size
u8 * format_memory_size(u8 *s, va_list *va)
Definition: std-formats.c:209
clib_mem_main
__clib_export clib_mem_main_t clib_mem_main
Definition: mem.c:22
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
size
u32 size
Definition: vhost_user.h:125
clib_bihash_value
template key/value backing page structure
Definition: bihash_doc.h:44
format
description fragment has unexpected format
Definition: map.api:433
format_get_indent
static u32 format_get_indent(u8 *s)
Definition: format.h:72
u32
unsigned int u32
Definition: types.h:88
CLIB_MAX_NUMAS
#define CLIB_MAX_NUMAS
Definition: mem.h:53
format_clib_mem_page_stats
u8 * format_clib_mem_page_stats(u8 *s, va_list *va)
Definition: mem.c:75
clib_mem_page_sz_t
clib_mem_page_sz_t
Definition: mem.h:57
u8
unsigned char u8
Definition: types.h:56
clib_error.h
i
int i
Definition: flowhash_template.h:376
clib_mem_vm_map_stack
__clib_export void * clib_mem_vm_map_stack(uword size, clib_mem_page_sz_t log2_page_sz, char *fmt,...)
Definition: mem.c:42
rv
int __clib_unused rv
Definition: application.c:491
mem.h
format_white_space
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129