Merge tag 'pm-6.16-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
[linux-2.6-block.git] / tools / perf / util / util.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
fce9a619
IR
2#ifndef __PERF_UTIL_H
3#define __PERF_UTIL_H
07800601 4
07800601 5#define _BSD_SOURCE 1
512fe365
CP
6/* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
7#define _DEFAULT_SOURCE 1
07800601 8
8ece26ad 9#include <dirent.h>
ed93d0a2 10#include <fcntl.h>
e206d556 11#include <stdbool.h>
07800601 12#include <stddef.h>
6c346643 13#include <linux/compiler.h>
ad0902e0 14#include <sys/types.h>
6d18804b
IR
15#ifndef __cplusplus
16#include <internal/cpumap.h>
17#endif
1fe2c106 18
0adea51a
IR
19extern const char perf_usage_string[];
20extern const char perf_more_info_string[];
21
f12ad272
IR
22extern const char *input_name;
23
35c8d213
NK
24/* This will control if perf_{host,guest} will set attr.exclude_{host,guest}. */
25extern bool exclude_GH_default;
26
ea0c5239
IR
27extern bool perf_host;
28extern bool perf_guest;
29
07800601 30/* General helper functions */
6c346643 31void usage(const char *err) __noreturn;
afaed6d3 32void die(const char *err, ...) __noreturn __printf(1, 2);
07800601 33
76b31a29 34struct dirent;
8ec20b17
ACM
35struct strlist;
36
4cf40131 37int mkdir_p(char *path, mode_t mode);
9a9c733d 38int rm_rf(const char *path);
c69e4c37 39int rm_rf_perf_data(const char *path);
e1ce726e
MH
40struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *));
41bool lsdir_no_dot_filter(const char *name, struct dirent *d);
4cf40131 42
61e04b33
ACM
43size_t hex_width(u64 v);
44
029c75e5
ACM
45int sysctl__max_stack(void);
46
2a14c1bf
KL
47bool sysctl__nmi_watchdog_enabled(void);
48
d9fc7061 49int perf_tip(char **strp, const char *dirpath);
14cbfbeb 50
120010cb
ACM
51#ifndef HAVE_SCHED_GETCPU_SUPPORT
52int sched_getcpu(void);
c7007e98
ACM
53#endif
54
8ece26ad
IR
55#ifndef HAVE_SCANDIRAT_SUPPORT
56int scandirat(int dirfd, const char *dirp,
57 struct dirent ***namelist,
58 int (*filter)(const struct dirent *),
59 int (*compar)(const struct dirent **, const struct dirent **));
60#endif
61
0a7c74ea
ACM
62extern bool perf_singlethreaded;
63
64void perf_set_singlethreaded(void);
65void perf_set_multithreaded(void);
66
94816add
AK
67char *perf_exe(char *buf, int len);
68
5c61d70e
ACM
69#ifndef O_CLOEXEC
70#ifdef __sparc__
71#define O_CLOEXEC 0x400000
72#elif defined(__alpha__) || defined(__hppa__)
73#define O_CLOEXEC 010000000
74#else
75#define O_CLOEXEC 02000000
76#endif
77#endif
78
9bce13ea
JO
79struct perf_debuginfod {
80 const char *urls;
81 bool set;
82};
83void perf_debuginfod_setup(struct perf_debuginfod *di);
67fd1892
NK
84
85char *filename_with_chroot(int pid, const char *filename);
10d34700
AH
86
87int do_realloc_array_as_needed(void **arr, size_t *arr_sz, size_t x,
88 size_t msz, const void *init_val);
89
90#define realloc_array_as_needed(a, n, x, v) ({ \
91 typeof(x) __x = (x); \
92 __x >= (n) ? \
93 do_realloc_array_as_needed((void **)&(a), \
94 &(n), \
95 __x, \
96 sizeof(*(a)), \
97 (const void *)(v)) : \
98 0; \
99 })
100
5b7a29fb
IR
101static inline bool host_is_bigendian(void)
102{
103#ifdef __BYTE_ORDER__
104#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
105 return false;
106#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
107 return true;
108#else
109#error "Unrecognized __BYTE_ORDER__"
110#endif
111#else /* !__BYTE_ORDER__ */
112 unsigned char str[] = { 0x1, 0x2, 0x3, 0x4, 0x0, 0x0, 0x0, 0x0};
113 unsigned int *ptr;
114
115 ptr = (unsigned int *)(void *)str;
116 return *ptr == 0x01020304;
117#endif
118}
119
fce9a619 120#endif /* __PERF_UTIL_H */