at v6.13 2.6 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, ...); 22 23long parse_seconds_duration(char *val); 24void get_duration(time_t start_time, char *output, int output_size); 25 26int parse_cpu_list(char *cpu_list, char **monitored_cpus); 27long long get_llong_from_str(char *start); 28 29static inline void 30update_min(unsigned long long *a, unsigned long long *b) 31{ 32 if (*a > *b) 33 *a = *b; 34} 35 36static inline void 37update_max(unsigned long long *a, unsigned long long *b) 38{ 39 if (*a < *b) 40 *a = *b; 41} 42 43static inline void 44update_sum(unsigned long long *a, unsigned long long *b) 45{ 46 *a += *b; 47} 48 49#ifndef SCHED_ATTR_SIZE_VER0 50struct sched_attr { 51 uint32_t size; 52 uint32_t sched_policy; 53 uint64_t sched_flags; 54 int32_t sched_nice; 55 uint32_t sched_priority; 56 uint64_t sched_runtime; 57 uint64_t sched_deadline; 58 uint64_t sched_period; 59}; 60#endif /* SCHED_ATTR_SIZE_VER0 */ 61 62int parse_prio(char *arg, struct sched_attr *sched_param); 63int parse_cpu_set(char *cpu_list, cpu_set_t *set); 64int __set_sched_attr(int pid, struct sched_attr *attr); 65int set_comm_sched_attr(const char *comm_prefix, struct sched_attr *attr); 66int set_comm_cgroup(const char *comm_prefix, const char *cgroup); 67int set_pid_cgroup(pid_t pid, const char *cgroup); 68int set_cpu_dma_latency(int32_t latency); 69#ifdef HAVE_LIBCPUPOWER_SUPPORT 70int save_cpu_idle_disable_state(unsigned int cpu); 71int restore_cpu_idle_disable_state(unsigned int cpu); 72void free_cpu_idle_disable_states(void); 73int set_deepest_cpu_idle_state(unsigned int cpu, unsigned int state); 74static inline int have_libcpupower_support(void) { return 1; } 75#else 76static inline int save_cpu_idle_disable_state(unsigned int cpu) { return -1; } 77static inline int restore_cpu_idle_disable_state(unsigned int cpu) { return -1; } 78static inline void free_cpu_idle_disable_states(void) { } 79static inline int set_deepest_cpu_idle_state(unsigned int cpu, unsigned int state) { return -1; } 80static inline int have_libcpupower_support(void) { return 0; } 81#endif /* HAVE_LIBCPUPOWER_SUPPORT */ 82int auto_house_keeping(cpu_set_t *monitored_cpus); 83 84#define ns_to_usf(x) (((double)x/1000)) 85#define ns_to_per(total, part) ((part * 100) / (double)total)