blob: 7b625cbd2dd8075cee51658c3381ba3af6f99a1c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Ingo Molnar07800602009-04-20 15:00:56 +02002#ifndef GIT_COMPAT_UTIL_H
3#define GIT_COMPAT_UTIL_H
4
Ingo Molnar07800602009-04-20 15:00:56 +02005#define _BSD_SOURCE 1
Chanho Park512fe362014-09-12 11:10:17 +09006/* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
7#define _DEFAULT_SOURCE 1
Ingo Molnar07800602009-04-20 15:00:56 +02008
Jiri Olsaed93d0a2018-09-13 14:54:11 +02009#include <fcntl.h>
Arnaldo Carvalho de Meloe206d552010-04-03 10:19:26 -030010#include <stdbool.h>
Ingo Molnar07800602009-04-20 15:00:56 +020011#include <stddef.h>
Arnaldo Carvalho de Melo6c346642017-06-16 11:39:15 -030012#include <linux/compiler.h>
Arnaldo Carvalho de Meload0902e2018-04-06 14:53:56 -030013#include <sys/types.h>
Ian Rogers6d188042022-01-04 22:13:51 -080014#ifndef __cplusplus
15#include <internal/cpumap.h>
16#endif
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020017
Ingo Molnar07800602009-04-20 15:00:56 +020018/* General helper functions */
Arnaldo Carvalho de Melo6c346642017-06-16 11:39:15 -030019void usage(const char *err) __noreturn;
Arnaldo Carvalho de Meloafaed6d2017-06-16 11:57:54 -030020void die(const char *err, ...) __noreturn __printf(1, 2);
Ingo Molnar07800602009-04-20 15:00:56 +020021
Arnaldo Carvalho de Melo76b31a22017-04-18 12:26:44 -030022struct dirent;
Arnaldo Carvalho de Melo8ec20b12017-04-18 10:57:25 -030023struct strlist;
24
Arnaldo Carvalho de Melo4cf40132009-12-27 21:37:06 -020025int mkdir_p(char *path, mode_t mode);
Joe Stringer9a9c7332017-01-26 13:19:59 -080026int rm_rf(const char *path);
Jiri Olsac69e4c32019-02-24 20:06:39 +010027int rm_rf_perf_data(const char *path);
Masami Hiramatsue1ce7262016-04-26 18:02:42 +090028struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *));
29bool lsdir_no_dot_filter(const char *name, struct dirent *d);
Arnaldo Carvalho de Melo4cf40132009-12-27 21:37:06 -020030
Arnaldo Carvalho de Melo61e04b32012-04-19 13:15:24 -030031size_t hex_width(u64 v);
32
Arnaldo Carvalho de Melo029c75e2018-05-17 16:31:32 -030033int sysctl__max_stack(void);
34
Kan Liang2a14c1b2020-02-24 13:59:22 -080035bool sysctl__nmi_watchdog_enabled(void);
36
Wang Nan07bc5c62015-11-06 13:55:35 +000037int fetch_kernel_version(unsigned int *puint,
38 char *str, size_t str_sz);
Wang Nand3e0ce32015-11-06 13:58:09 +000039#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 Nan07bc5c62015-11-06 13:55:35 +000044
Ian Rogersd9fc7062021-11-17 23:38:04 -080045int perf_tip(char **strp, const char *dirpath);
Namhyung Kim14cbfbe2016-01-07 20:41:53 +090046
Arnaldo Carvalho de Melo120010c2017-03-02 12:55:49 -030047#ifndef HAVE_SCHED_GETCPU_SUPPORT
48int sched_getcpu(void);
Arnaldo Carvalho de Meloc7007e92016-07-12 10:29:31 -030049#endif
50
Arnaldo Carvalho de Melo0a7c74e2017-04-04 13:15:04 -030051extern bool perf_singlethreaded;
52
53void perf_set_singlethreaded(void);
54void perf_set_multithreaded(void);
55
Andi Kleen94816ad2019-02-24 07:37:19 -080056char *perf_exe(char *buf, int len);
57
Arnaldo Carvalho de Melo5c61d702018-01-22 17:11:30 -030058#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 Olsa8366f0d2020-08-27 21:32:01 +020068extern bool test_attr__enabled;
69void test_attr__ready(void);
70void test_attr__init(void);
71struct perf_event_attr;
Ian Rogers6d188042022-01-04 22:13:51 -080072void test_attr__open(struct perf_event_attr *attr, pid_t pid, struct perf_cpu cpu,
Jiri Olsa8366f0d2020-08-27 21:32:01 +020073 int fd, int group_fd, unsigned long flags);
Jiri Olsa9bce13e2021-12-09 21:04:25 +010074
75struct perf_debuginfod {
76 const char *urls;
77 bool set;
78};
79void perf_debuginfod_setup(struct perf_debuginfod *di);
Borislav Petkov13559152013-02-20 16:32:31 +010080#endif /* GIT_COMPAT_UTIL_H */