2 * Copyright (c) 2018 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef included_palloc_h
17 #define included_palloc_h
18 #include <vppinfra/format.h>
19 #include <vppinfra/pool.h>
21 #define PMALLOC_LOG2_BLOCK_SZ CLIB_LOG2_CACHE_LINE_BYTES
22 #define PMALLOC_BLOCK_SZ (1 << 6)
24 #define CLIB_PMALLOC_NUMA_LOCAL 0xffffffff
28 u32 start, prev, next;
31 } clib_pmalloc_chunk_t;
33 STATIC_ASSERT_SIZEOF (clib_pmalloc_chunk_t, 16);
40 clib_pmalloc_chunk_t *chunks;
41 u32 first_chunk_index;
44 } clib_pmalloc_page_t;
50 #define CLIB_PMALLOC_ARENA_F_SHARED_MEM (1 << 0)
58 } clib_pmalloc_arena_t;
66 clib_pmalloc_page_t *pages;
67 uword *chunk_index_by_va;
68 clib_pmalloc_arena_t *arenas;
69 u32 *default_arena_for_numa_node;
72 } clib_pmalloc_main_t;
75 int clib_pmalloc_init (clib_pmalloc_main_t * pm, uword size);
76 void *clib_pmalloc_alloc_aligned_on_numa (clib_pmalloc_main_t * pm,
77 uword size, uword align,
79 void *clib_pmalloc_alloc_aligned (clib_pmalloc_main_t * pm, uword size,
81 void clib_pmalloc_free (clib_pmalloc_main_t * pm, void *va);
83 void *clib_pmalloc_create_shared_arena (clib_pmalloc_main_t * pm, char *name,
84 uword size, u32 numa_node);
86 void *clib_pmalloc_alloc_from_arena (clib_pmalloc_main_t * pm, void *arena_va,
87 uword size, uword align);
89 format_function_t format_pmalloc;
91 always_inline clib_error_t *
92 clib_pmalloc_last_error (clib_pmalloc_main_t * pm)
98 clib_pmalloc_get_page_index (clib_pmalloc_main_t * pm, void *va)
100 uword index = (pointer_to_uword (va) - pointer_to_uword (pm->base)) >>
103 ASSERT (index < vec_len (pm->pages));
108 always_inline clib_pmalloc_arena_t *
109 clib_pmalloc_get_arena (clib_pmalloc_main_t * pm, void *va)
111 u32 index = clib_pmalloc_get_page_index (pm, va);
112 return pm->arenas + pm->pages[index].arena_index;
116 clib_pmalloc_get_pa (clib_pmalloc_main_t * pm, void *va)
118 u32 index = clib_pmalloc_get_page_index (pm, va);
119 return pointer_to_uword (va) - pm->va_pa_diffs[index];
123 #endif /* included_palloc_h */
126 * fd.io coding-style-patch-verification: ON
129 * eval: (c-set-style "gnu")