1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <stdbool.h>
3 #include <stdlib.h>
4 
5 #include "../kselftest.h"
6 
7 #define PAGE_SIZE 4096
8 
9 #define MB(x) (x << 20)
10 
11 #define USEC_PER_SEC	1000000L
12 #define NSEC_PER_SEC	1000000000L
13 
14 /*
15  * Checks if two given values differ by less than err% of their sum.
16  */
17 static inline int values_close(long a, long b, int err)
18 {
19 	return abs(a - b) <= (a + b) / 100 * err;
20 }
21 
22 extern int cg_find_unified_root(char *root, size_t len);
23 extern char *cg_name(const char *root, const char *name);
24 extern char *cg_name_indexed(const char *root, const char *name, int index);
25 extern char *cg_control(const char *cgroup, const char *control);
26 extern int cg_create(const char *cgroup);
27 extern int cg_destroy(const char *cgroup);
28 extern int cg_read(const char *cgroup, const char *control,
29 		   char *buf, size_t len);
30 extern int cg_read_strcmp(const char *cgroup, const char *control,
31 			  const char *expected);
32 extern int cg_read_strstr(const char *cgroup, const char *control,
33 			  const char *needle);
34 extern long cg_read_long(const char *cgroup, const char *control);
35 long cg_read_key_long(const char *cgroup, const char *control, const char *key);
36 extern long cg_read_lc(const char *cgroup, const char *control);
37 extern int cg_write(const char *cgroup, const char *control, char *buf);
38 int cg_write_numeric(const char *cgroup, const char *control, long value);
39 extern int cg_run(const char *cgroup,
40 		  int (*fn)(const char *cgroup, void *arg),
41 		  void *arg);
42 extern int cg_enter(const char *cgroup, int pid);
43 extern int cg_enter_current(const char *cgroup);
44 extern int cg_enter_current_thread(const char *cgroup);
45 extern int cg_run_nowait(const char *cgroup,
46 			 int (*fn)(const char *cgroup, void *arg),
47 			 void *arg);
48 extern int get_temp_fd(void);
49 extern int alloc_pagecache(int fd, size_t size);
50 extern int alloc_anon(const char *cgroup, void *arg);
51 extern int is_swap_enabled(void);
52 extern int set_oom_adj_score(int pid, int score);
53 extern int cg_wait_for_proc_count(const char *cgroup, int count);
54 extern int cg_killall(const char *cgroup);
55 int proc_mount_contains(const char *option);
56 extern ssize_t proc_read_text(int pid, bool thread, const char *item, char *buf, size_t size);
57 extern int proc_read_strstr(int pid, bool thread, const char *item, const char *needle);
58 extern pid_t clone_into_cgroup(int cgroup_fd);
59 extern int clone_reap(pid_t pid, int options);
60 extern int clone_into_cgroup_run_wait(const char *cgroup);
61 extern int dirfd_open_opath(const char *dir);
62 extern int cg_prepare_for_wait(const char *cgroup);
63 extern int memcg_prepare_for_wait(const char *cgroup);
64 extern int cg_wait_for(int fd);
65