^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef GIT_COMPAT_UTIL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define GIT_COMPAT_UTIL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #define _BSD_SOURCE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) /* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define _DEFAULT_SOURCE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <stdbool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) /* General helper functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) void usage(const char *err) __noreturn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) void die(const char *err, ...) __noreturn __printf(1, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct dirent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct strlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) int mkdir_p(char *path, mode_t mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) int rm_rf(const char *path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) int rm_rf_perf_data(const char *path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) bool lsdir_no_dot_filter(const char *name, struct dirent *d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) size_t hex_width(u64 v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) int sysctl__max_stack(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) bool sysctl__nmi_watchdog_enabled(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int fetch_kernel_version(unsigned int *puint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) char *str, size_t str_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define KVER_VERSION(x) (((x) >> 16) & 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define KVER_PATCHLEVEL(x) (((x) >> 8) & 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define KVER_SUBLEVEL(x) ((x) & 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define KVER_FMT "%d.%d.%d"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) int perf_tip(char **strp, const char *dirpath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #ifndef HAVE_SCHED_GETCPU_SUPPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) int sched_getcpu(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) extern bool perf_singlethreaded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) void perf_set_singlethreaded(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) void perf_set_multithreaded(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) char *perf_exe(char *buf, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #ifndef O_CLOEXEC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #ifdef __sparc__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define O_CLOEXEC 0x400000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #elif defined(__alpha__) || defined(__hppa__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define O_CLOEXEC 010000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define O_CLOEXEC 02000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) extern bool test_attr__enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) void test_attr__ready(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) void test_attr__init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct perf_event_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int fd, int group_fd, unsigned long flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #endif /* GIT_COMPAT_UTIL_H */