taskstats: extended taskstats2 with acct fields

Add basic accounting stats in taskstats2 struct

Change-Id: Ieb5aa751381f889628eba143db3988a56ef0f096
Signed-off-by: Jasleen Kalsi <jkalsi@codeaurora.org>
This commit is contained in:
Jasleen Kalsi 2020-05-02 01:22:55 +05:30 committed by Gerrit - the friendly Code Review server
parent 17d718ca15
commit d402af84df
2 changed files with 49 additions and 1 deletions

View File

@ -35,7 +35,7 @@
#define TASKSTATS_VERSION 9
#define TASKSTATS2_VERSION 1
#define TASKSTATS2_VERSION 2
#define TS_COMM_LEN 32 /* should be >= TASK_COMM_LEN
* in linux/sched.h */
@ -181,6 +181,20 @@ struct taskstats2 {
__u64 shmem_rss; /* KB */
__u64 unreclaimable; /* KB */
/* version 1 ends here */
/* version 2 begins here */
__u64 utime; /* User CPU time [usec] */
__u64 stime; /* System CPU time [usec] */
__u64 cutime; /* Cumulative User CPU time [usec] */
__u64 cstime; /* Cumulative System CPU time [usec] */
__u32 uid __attribute__((aligned(8)));
/* User ID */
__u32 ppid; /* Parent process ID */
char name[TS_COMM_LEN]; /* Command name */
char state[TS_COMM_LEN]; /* Process state */
/* version 2 ends here*/
};
/*

View File

@ -650,6 +650,11 @@ static int taskstats2_cmd_attr_pid(struct genl_info *info)
size_t size;
u32 pid;
int rc;
u64 utime, stime;
const struct cred *tcred;
struct cgroup_subsys_state *css;
unsigned long flags;
struct signal_struct *sig;
size = nla_total_size_64bit(sizeof(struct taskstats2));
@ -691,6 +696,35 @@ static int taskstats2_cmd_attr_pid(struct genl_info *info)
#undef K
task_unlock(p);
}
/* version 2 fields begin here */
task_cputime(tsk, &utime, &stime);
stats->utime = div_u64(utime, NSEC_PER_USEC);
stats->stime = div_u64(stime, NSEC_PER_USEC);
if (lock_task_sighand(tsk, &flags)) {
sig = tsk->signal;
stats->cutime = sig->cutime;
stats->cstime = sig->cstime;
unlock_task_sighand(tsk, &flags);
}
rcu_read_lock();
tcred = __task_cred(tsk);
stats->uid = from_kuid_munged(current_user_ns(), tcred->uid);
stats->ppid = pid_alive(tsk) ?
task_tgid_nr_ns(rcu_dereference(tsk->real_parent),
task_active_pid_ns(current)) : 0;
rcu_read_unlock();
strlcpy(stats->name, tsk->comm, sizeof(stats->name));
css = task_get_css(tsk, cpuset_cgrp_id);
cgroup_path_ns(css->cgroup, stats->state, sizeof(stats->state),
current->nsproxy->cgroup_ns);
css_put(css);
/* version 2 fields end here */
put_task_struct(tsk);
return send_reply(rep_skb, info);