at master 2.8 kB view raw
1// SPDX-License-Identifier: GPL-2.0 2 3#include <stdint.h> 4#include <time.h> 5#include <sched.h> 6 7/* 8 * '18446744073709551615\0' 9 */ 10#define BUFF_U64_STR_SIZE 24 11#define MAX_PATH 1024 12#define MAX_NICE 20 13#define MIN_NICE -19 14 15#define container_of(ptr, type, member)({ \ 16 const typeof(((type *)0)->member) *__mptr = (ptr); \ 17 (type *)((char *)__mptr - offsetof(type, member)) ; }) 18 19extern int config_debug; 20void debug_msg(const char *fmt, ...); 21void err_msg(const char *fmt, ...); 22void fatal(const char *fmt, ...); 23 24long parse_seconds_duration(char *val); 25void get_duration(time_t start_time, char *output, int output_size); 26 27int parse_cpu_list(char *cpu_list, char **monitored_cpus); 28char *parse_optional_arg(int argc, char **argv); 29long long get_llong_from_str(char *start); 30 31static inline void 32update_min(unsigned long long *a, unsigned long long *b) 33{ 34 if (*a > *b) 35 *a = *b; 36} 37 38static inline void 39update_max(unsigned long long *a, unsigned long long *b) 40{ 41 if (*a < *b) 42 *a = *b; 43} 44 45static inline void 46update_sum(unsigned long long *a, unsigned long long *b) 47{ 48 *a += *b; 49} 50 51#ifndef SCHED_ATTR_SIZE_VER0 52struct sched_attr { 53 uint32_t size; 54 uint32_t sched_policy; 55 uint64_t sched_flags; 56 int32_t sched_nice; 57 uint32_t sched_priority; 58 uint64_t sched_runtime; 59 uint64_t sched_deadline; 60 uint64_t sched_period; 61}; 62#endif /* SCHED_ATTR_SIZE_VER0 */ 63 64int parse_prio(char *arg, struct sched_attr *sched_param); 65int parse_cpu_set(char *cpu_list, cpu_set_t *set); 66int __set_sched_attr(int pid, struct sched_attr *attr); 67int set_comm_sched_attr(const char *comm_prefix, struct sched_attr *attr); 68int set_comm_cgroup(const char *comm_prefix, const char *cgroup); 69int set_pid_cgroup(pid_t pid, const char *cgroup); 70int set_cpu_dma_latency(int32_t latency); 71#ifdef HAVE_LIBCPUPOWER_SUPPORT 72int save_cpu_idle_disable_state(unsigned int cpu); 73int restore_cpu_idle_disable_state(unsigned int cpu); 74void free_cpu_idle_disable_states(void); 75int set_deepest_cpu_idle_state(unsigned int cpu, unsigned int state); 76static inline int have_libcpupower_support(void) { return 1; } 77#else 78static inline int save_cpu_idle_disable_state(unsigned int cpu) { return -1; } 79static inline int restore_cpu_idle_disable_state(unsigned int cpu) { return -1; } 80static inline void free_cpu_idle_disable_states(void) { } 81static inline int set_deepest_cpu_idle_state(unsigned int cpu, unsigned int state) { return -1; } 82static inline int have_libcpupower_support(void) { return 0; } 83#endif /* HAVE_LIBCPUPOWER_SUPPORT */ 84int auto_house_keeping(cpu_set_t *monitored_cpus); 85 86#define ns_to_usf(x) (((double)x/1000)) 87#define ns_to_per(total, part) ((part * 100) / (double)total) 88 89enum result { 90 PASSED = 0, /* same as EXIT_SUCCESS */ 91 ERROR = 1, /* same as EXIT_FAILURE, an error in arguments */ 92 FAILED = 2, /* test hit the stop tracing condition */ 93};