Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 2 | #ifndef GIT_COMPAT_UTIL_H |
| 3 | #define GIT_COMPAT_UTIL_H |
| 4 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 5 | #define _BSD_SOURCE 1 |
Chanho Park | 512fe36 | 2014-09-12 11:10:17 +0900 | [diff] [blame] | 6 | /* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */ |
| 7 | #define _DEFAULT_SOURCE 1 |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 8 | |
Jiri Olsa | ed93d0a | 2018-09-13 14:54:11 +0200 | [diff] [blame] | 9 | #include <fcntl.h> |
Arnaldo Carvalho de Melo | e206d55 | 2010-04-03 10:19:26 -0300 | [diff] [blame] | 10 | #include <stdbool.h> |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 11 | #include <stddef.h> |
Arnaldo Carvalho de Melo | 6c34664 | 2017-06-16 11:39:15 -0300 | [diff] [blame] | 12 | #include <linux/compiler.h> |
Arnaldo Carvalho de Melo | ad0902e | 2018-04-06 14:53:56 -0300 | [diff] [blame] | 13 | #include <sys/types.h> |
Ian Rogers | 6d18804 | 2022-01-04 22:13:51 -0800 | [diff] [blame] | 14 | #ifndef __cplusplus |
| 15 | #include <internal/cpumap.h> |
| 16 | #endif |
Frederic Weisbecker | 1fe2c10 | 2009-08-12 10:19:53 +0200 | [diff] [blame] | 17 | |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 18 | /* General helper functions */ |
Arnaldo Carvalho de Melo | 6c34664 | 2017-06-16 11:39:15 -0300 | [diff] [blame] | 19 | void usage(const char *err) __noreturn; |
Arnaldo Carvalho de Melo | afaed6d | 2017-06-16 11:57:54 -0300 | [diff] [blame] | 20 | void die(const char *err, ...) __noreturn __printf(1, 2); |
Ingo Molnar | 0780060 | 2009-04-20 15:00:56 +0200 | [diff] [blame] | 21 | |
Arnaldo Carvalho de Melo | 76b31a2 | 2017-04-18 12:26:44 -0300 | [diff] [blame] | 22 | struct dirent; |
Arnaldo Carvalho de Melo | 8ec20b1 | 2017-04-18 10:57:25 -0300 | [diff] [blame] | 23 | struct strlist; |
| 24 | |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 25 | int mkdir_p(char *path, mode_t mode); |
Joe Stringer | 9a9c733 | 2017-01-26 13:19:59 -0800 | [diff] [blame] | 26 | int rm_rf(const char *path); |
Jiri Olsa | c69e4c3 | 2019-02-24 20:06:39 +0100 | [diff] [blame] | 27 | int rm_rf_perf_data(const char *path); |
Masami Hiramatsu | e1ce726 | 2016-04-26 18:02:42 +0900 | [diff] [blame] | 28 | struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *)); |
| 29 | bool lsdir_no_dot_filter(const char *name, struct dirent *d); |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 30 | |
Arnaldo Carvalho de Melo | 61e04b3 | 2012-04-19 13:15:24 -0300 | [diff] [blame] | 31 | size_t hex_width(u64 v); |
| 32 | |
Arnaldo Carvalho de Melo | 029c75e | 2018-05-17 16:31:32 -0300 | [diff] [blame] | 33 | int sysctl__max_stack(void); |
| 34 | |
Kan Liang | 2a14c1b | 2020-02-24 13:59:22 -0800 | [diff] [blame] | 35 | bool sysctl__nmi_watchdog_enabled(void); |
| 36 | |
Wang Nan | 07bc5c6 | 2015-11-06 13:55:35 +0000 | [diff] [blame] | 37 | int fetch_kernel_version(unsigned int *puint, |
| 38 | char *str, size_t str_sz); |
Wang Nan | d3e0ce3 | 2015-11-06 13:58:09 +0000 | [diff] [blame] | 39 | #define KVER_VERSION(x) (((x) >> 16) & 0xff) |
| 40 | #define KVER_PATCHLEVEL(x) (((x) >> 8) & 0xff) |
| 41 | #define KVER_SUBLEVEL(x) ((x) & 0xff) |
| 42 | #define KVER_FMT "%d.%d.%d" |
| 43 | #define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x) |
Wang Nan | 07bc5c6 | 2015-11-06 13:55:35 +0000 | [diff] [blame] | 44 | |
Ian Rogers | d9fc706 | 2021-11-17 23:38:04 -0800 | [diff] [blame] | 45 | int perf_tip(char **strp, const char *dirpath); |
Namhyung Kim | 14cbfbe | 2016-01-07 20:41:53 +0900 | [diff] [blame] | 46 | |
Arnaldo Carvalho de Melo | 120010c | 2017-03-02 12:55:49 -0300 | [diff] [blame] | 47 | #ifndef HAVE_SCHED_GETCPU_SUPPORT |
| 48 | int sched_getcpu(void); |
Arnaldo Carvalho de Melo | c7007e9 | 2016-07-12 10:29:31 -0300 | [diff] [blame] | 49 | #endif |
| 50 | |
Arnaldo Carvalho de Melo | 0a7c74e | 2017-04-04 13:15:04 -0300 | [diff] [blame] | 51 | extern bool perf_singlethreaded; |
| 52 | |
| 53 | void perf_set_singlethreaded(void); |
| 54 | void perf_set_multithreaded(void); |
| 55 | |
Andi Kleen | 94816ad | 2019-02-24 07:37:19 -0800 | [diff] [blame] | 56 | char *perf_exe(char *buf, int len); |
| 57 | |
Arnaldo Carvalho de Melo | 5c61d70 | 2018-01-22 17:11:30 -0300 | [diff] [blame] | 58 | #ifndef O_CLOEXEC |
| 59 | #ifdef __sparc__ |
| 60 | #define O_CLOEXEC 0x400000 |
| 61 | #elif defined(__alpha__) || defined(__hppa__) |
| 62 | #define O_CLOEXEC 010000000 |
| 63 | #else |
| 64 | #define O_CLOEXEC 02000000 |
| 65 | #endif |
| 66 | #endif |
| 67 | |
Jiri Olsa | 8366f0d | 2020-08-27 21:32:01 +0200 | [diff] [blame] | 68 | extern bool test_attr__enabled; |
| 69 | void test_attr__ready(void); |
| 70 | void test_attr__init(void); |
| 71 | struct perf_event_attr; |
Ian Rogers | 6d18804 | 2022-01-04 22:13:51 -0800 | [diff] [blame] | 72 | void test_attr__open(struct perf_event_attr *attr, pid_t pid, struct perf_cpu cpu, |
Jiri Olsa | 8366f0d | 2020-08-27 21:32:01 +0200 | [diff] [blame] | 73 | int fd, int group_fd, unsigned long flags); |
Jiri Olsa | 9bce13e | 2021-12-09 21:04:25 +0100 | [diff] [blame] | 74 | |
| 75 | struct perf_debuginfod { |
| 76 | const char *urls; |
| 77 | bool set; |
| 78 | }; |
| 79 | void perf_debuginfod_setup(struct perf_debuginfod *di); |
Borislav Petkov | 1355915 | 2013-02-20 16:32:31 +0100 | [diff] [blame] | 80 | #endif /* GIT_COMPAT_UTIL_H */ |