From d4bae8390a23595c3507e7870bba4fe7b0700f0f Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Fri, 11 Dec 2020 13:21:38 +0900 Subject: [PATCH] Support Linux kernel earilier version than v4.11 From Linux kernel 4.11, sched header is splited and cputime_t is fixed as u64. Before the kernel version, do not use splitter headers and use cputime_t for task_cputime_adjusted(). Change-Id: Iac5d4e1d89366c54a59cc3092afd56f2df01918b Ref: v4.11 commit 1050b27c52f6 ("sched/headers: Move cputime functionality from and into ") Ref: v4.11 commit c3edc4010e9d ("sched/headers: Move task_struct::signal and task_struct::sighand types and accessors into ") Ref: v4.11 commit 5613fda9a503 ("sched/cputime: Convert task/group cputime to nsecs") Signed-off-by: Seung-Woo Kim --- kernel/proc-tsm.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kernel/proc-tsm.c b/kernel/proc-tsm.c index 3f25335..74cc11b 100644 --- a/kernel/proc-tsm.c +++ b/kernel/proc-tsm.c @@ -27,8 +27,10 @@ #include #include #include +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) #include #include +#endif #include #include #include @@ -61,11 +63,13 @@ static u64 time_now(void) return div64_ul(ktime_get_boot_ns(), NSEC_PER_USEC); } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) static inline u64 cputime_to_usecs(const u64 cputime) { // return cputime >> 12; return div64_ul(cputime, NSEC_PER_USEC); } +#endif static unsigned int count_open_files(struct files_struct *files) { @@ -101,7 +105,11 @@ static int stability_monitor_show(struct seq_file *m, void *v) struct task_struct *task, *t; struct pid *pid = NULL; pid_t ppid = 0; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) u64 uptime, utime, stime, ut, st; +#else + cputime_t uptime, utime, stime, ut, st; +#endif unsigned long long vm_rss, total_ram; struct task_io_accounting task_ioac; unsigned int open_fds; -- 2.34.1