Debian Codegraph @

libhugetlbfs_internal.h

raw symbols SCIP
1 /*
2 * libhugetlbfs - Easy use of Linux hugepages
3 * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1 of
8 * the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 /*
21 * This file should only contain definitions of functions, data types, and
22 * constants which are used internally within the libhugetlbfs library.
23 *
24 * All external functions declared here are library static and must be
25 * internalised using a define of the following form:
26 *
27 * #define foo __lh_foo
28 */
29
30 #ifndef _LIBHUGETLBFS_INTERNAL_H
31 #define _LIBHUGETLBFS_INTERNAL_H
32
33 #include <elf.h>
34 #include <link.h>
35 #include <limits.h>
36 #include <stdbool.h>
37
38 #ifndef __LIBHUGETLBFS__
39 #error This header should not be included by library users.
40 #endif /* __LIBHUGETLBFS__ */
41
42 #include "libhugetlbfs_privutils.h"
43 #include "libhugetlbfs_testprobes.h"
44
45 #define stringify_1(x) #x
46 #define stringify(x) stringify_1(x)
47
48 #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
49 #define ALIGN_UP(x,a) ALIGN(x,a)
50 #define ALIGN_DOWN(x,a) ((x) & ~((a) - 1))
51
52 #if defined(__powerpc64__) || \
53 (defined(__powerpc__) && !defined(PPC_NO_SEGMENTS))
54 #define SLICE_LOW_SHIFT 28
55 #define SLICE_HIGH_SHIFT 40
56 #elif defined(__ia64__)
57 #define SLICE_HIGH_SHIFT 63
58 #endif
59
60 struct libhugeopts_t {
61 int sharing;
62 bool min_copy;
63 bool shrink_ok;
64 bool shm_enabled;
65 bool no_reserve;
66 bool map_hugetlb;
67 bool thp_morecore;
68 unsigned long force_elfmap;
69 char *ld_preload;
70 char *elfmap;
71 char *share_path;
72 char *features;
73 char *path;
74 char *def_page_size;
75 char *morecore;
76 char *heapbase;
77 };
78
79 /*
80 * When adding a library local variable externalise the symbol as
81 * normal, plus add a #define of the form below. This define effectively
82 * renames the routine into the local namespace __lh_* which is forced
83 * local in the linker script version.lds. Some routines may need to be
84 * exported in the utilities library these are marked __pu_* which marks
85 * them for export in libhugetlbfs_privutils; their definitions should
86 * appear in libhugetlbfs_privutils.h rather than here.
87 */
88 #define __hugetlbfs_verbose __lh___hugetlbfs_verbose
89 extern int __hugetlbfs_verbose;
90 #define __hugetlbfs_debug __lh___hugetlbfs_debug
91 extern bool __hugetlbfs_debug;
92 #define __hugetlbfs_prefault __lh___hugetlbfs_prefault
93 extern bool __hugetlbfs_prefault;
94 #define hugetlbfs_setup_env __lh_hugetlbfs_setup_env
95 extern void hugetlbfs_setup_env();
96 #define hugetlbfs_setup_elflink __lh_hugetlbfs_setup_elflink
97 extern void hugetlbfs_setup_elflink();
98 #define hugetlbfs_setup_morecore __lh_hugetlbfs_setup_morecore
99 extern void hugetlbfs_setup_morecore();
100 #define hugetlbfs_setup_debug __lh_hugetlbfs_setup_debug
101 extern void hugetlbfs_setup_debug();
102 #define setup_mounts __lh_setup_mounts
103 extern void setup_mounts();
104 #define setup_features __lh_setup_features
105 extern void setup_features();
106 #define hugetlbfs_check_priv_resv __lh_hugetlbfs_check_priv_resv
107 extern void hugetlbfs_check_priv_resv();
108 #define hugetlbfs_check_safe_noreserve __lh_hugetlbfs_check_safe_noreserve
109 extern void hugetlbfs_check_safe_noreserve();
110 #define hugetlbfs_check_map_hugetlb __lh_hugetblfs_check_map_hugetlb
111 extern void hugetlbfs_check_map_hugetlb();
112 #define __hugetlbfs_hostname __lh___hugetlbfs_hostname
113 extern char __hugetlbfs_hostname[];
114 #define hugetlbfs_prefault __lh_hugetlbfs_prefault
115 extern int hugetlbfs_prefault(void *addr, size_t length);
116 #define parse_page_size __lh_parse_page_size
117 extern long parse_page_size(const char *str);
118 #define probe_default_hpage_size __lh__probe_default_hpage_size
119 extern void probe_default_hpage_size(void);
120 #define debug_show_page_sizes __lh__debug_show_page_sizes
121 extern void debug_show_page_sizes(void);
122 #define hugetlbfs_setup_kernel_page_size __lh__hugetlbfs_setup_kernel_page_size
123 extern void hugetlbfs_setup_kernel_page_size(void);
124 #define __hugetlb_opts __lh__hugetlb_opts
125 extern struct libhugeopts_t __hugetlb_opts;
126
127 #ifndef REPORT_UTIL
128 #define REPORT_UTIL "libhugetlbfs"
129 #endif
130
131 #define VERBOSE_ERROR 1
132 #define VERBOSE_WARNING 2
133 #define VERBOSE_INFO 3
134 #define VERBOSE_DEBUG 4
135
136 #ifndef REPORT
137 #define REPORT(level, prefix, format, ...) \
138 do { \
139 if (__hugetlbfs_verbose >= level) { \
140 fprintf(stderr, REPORT_UTIL); \
141 if (__hugetlbfs_verbose >= VERBOSE_DEBUG) \
142 fprintf(stderr, " [%s:%d]", \
143 __hugetlbfs_hostname, getpid()); \
144 fprintf(stderr, ": " prefix ": " format, \
145 ##__VA_ARGS__); \
146 fflush(stderr); \
147 } \
148 } while (0)
149
150 #define REPORT_CONT(level, prefix, ...) \
151 do { \
152 if (__hugetlbfs_verbose >= level) { \
153 fprintf(stderr, ##__VA_ARGS__); \
154 fflush(stderr); \
155 } \
156 } while (0)
157 #endif
158
159 #include "libhugetlbfs_debug.h"
160
161 #if defined(__powerpc64__) && !defined(__LP64__)
162 /* Older binutils fail to provide this symbol */
163 #define __LP64__
164 #endif
165
166 /* Multiple huge page size support */
167 struct hpage_size {
168 unsigned long pagesize;
169 char mount[PATH_MAX+1];
170 };
171
172 struct hpage_pool {
173 unsigned long pagesize;
174 unsigned long minimum;
175 unsigned long maximum;
176 unsigned long size;
177 int is_default;
178 };
179
180 #define size_to_smaller_unit __lh_size_to_smaller_unit
181 extern unsigned long long size_to_smaller_unit(unsigned long long size);
182
183 #define file_read_ulong __lh_file_read_ulong
184 extern long file_read_ulong(char *file, const char *tag);
185 #define file_write_ulong __lh_file_write_ulong
186 extern int file_write_ulong(char *file, unsigned long val);
187
188 #define hpool_sizes __lh_hpool_sizes
189 extern int hpool_sizes(struct hpage_pool *, int);
190 #define get_pool_size __lh_get_pool_size
191 extern int get_pool_size(long, struct hpage_pool *);
192
193 /* Arch-specific callbacks */
194 extern int direct_syscall(int sysnum, ...);
195 extern ElfW(Word) plt_extrasz(ElfW(Dyn) *dyntab);
196
197 #define MEMINFO "/proc/meminfo"
198 #define PROC_HUGEPAGES_DIR "/proc/sys/vm/"
199 #define SYSFS_HUGEPAGES_DIR "/sys/kernel/mm/hugepages/"
200
201 #define hugetlbfs_test_pagesize __lh_hugetlbfs_test_pagesize
202 long hugetlbfs_test_pagesize(const char *mount);
203
204 /* Diagnoses/debugging only functions */
205 #define dump_proc_pid_maps __lh_dump_proc_pid_maps
206 long dump_proc_pid_maps(void);
207
208 #define plt_extrasz __lh_plt_extrasz
209 ElfW(Word) plt_extrasz(ElfW(Dyn) *dyntab);
210
211 #endif /* _LIBHUGETLBFS_INTERNAL_H */