diff options
Diffstat (limited to 'kernel/tsacct.c')
| -rw-r--r-- | kernel/tsacct.c | 73 | 
1 files changed, 50 insertions, 23 deletions
diff --git a/kernel/tsacct.c b/kernel/tsacct.c index 24dc60d9fa1..a1dd9a1b132 100644 --- a/kernel/tsacct.c +++ b/kernel/tsacct.c @@ -26,10 +26,13 @@  /*   * fill in basic accounting fields   */ -void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk) +void bacct_add_tsk(struct user_namespace *user_ns, +		   struct pid_namespace *pid_ns, +		   struct taskstats *stats, struct task_struct *tsk)  {  	const struct cred *tcred;  	struct timespec uptime, ts; +	cputime_t utime, stime, utimescaled, stimescaled;  	u64 ac_etime;  	BUILD_BUG_ON(TS_COMM_LEN < TASK_COMM_LEN); @@ -55,18 +58,23 @@ void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk)  		stats->ac_flag |= AXSIG;  	stats->ac_nice	 = task_nice(tsk);  	stats->ac_sched	 = tsk->policy; -	stats->ac_pid	 = tsk->pid; +	stats->ac_pid	 = task_pid_nr_ns(tsk, pid_ns);  	rcu_read_lock();  	tcred = __task_cred(tsk); -	stats->ac_uid	 = tcred->uid; -	stats->ac_gid	 = tcred->gid; +	stats->ac_uid	 = from_kuid_munged(user_ns, tcred->uid); +	stats->ac_gid	 = from_kgid_munged(user_ns, tcred->gid);  	stats->ac_ppid	 = pid_alive(tsk) ? -				rcu_dereference(tsk->real_parent)->tgid : 0; +		task_tgid_nr_ns(rcu_dereference(tsk->real_parent), pid_ns) : 0;  	rcu_read_unlock(); -	stats->ac_utime = cputime_to_usecs(tsk->utime); -	stats->ac_stime = cputime_to_usecs(tsk->stime); -	stats->ac_utimescaled = cputime_to_usecs(tsk->utimescaled); -	stats->ac_stimescaled = cputime_to_usecs(tsk->stimescaled); + +	task_cputime(tsk, &utime, &stime); +	stats->ac_utime = cputime_to_usecs(utime); +	stats->ac_stime = cputime_to_usecs(stime); + +	task_cputime_scaled(tsk, &utimescaled, &stimescaled); +	stats->ac_utimescaled = cputime_to_usecs(utimescaled); +	stats->ac_stimescaled = cputime_to_usecs(stimescaled); +  	stats->ac_minflt = tsk->min_flt;  	stats->ac_majflt = tsk->maj_flt; @@ -78,6 +86,7 @@ void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk)  #define KB 1024  #define MB (1024*KB) +#define KB_MASK (~(KB-1))  /*   * fill in extended accounting fields   */ @@ -95,14 +104,14 @@ void xacct_add_tsk(struct taskstats *stats, struct task_struct *p)  		stats->hiwater_vm    = get_mm_hiwater_vm(mm)  * PAGE_SIZE / KB;  		mmput(mm);  	} -	stats->read_char	= p->ioac.rchar; -	stats->write_char	= p->ioac.wchar; -	stats->read_syscalls	= p->ioac.syscr; -	stats->write_syscalls	= p->ioac.syscw; +	stats->read_char	= p->ioac.rchar & KB_MASK; +	stats->write_char	= p->ioac.wchar & KB_MASK; +	stats->read_syscalls	= p->ioac.syscr & KB_MASK; +	stats->write_syscalls	= p->ioac.syscw & KB_MASK;  #ifdef CONFIG_TASK_IO_ACCOUNTING -	stats->read_bytes	= p->ioac.read_bytes; -	stats->write_bytes	= p->ioac.write_bytes; -	stats->cancelled_write_bytes = p->ioac.cancelled_write_bytes; +	stats->read_bytes	= p->ioac.read_bytes & KB_MASK; +	stats->write_bytes	= p->ioac.write_bytes & KB_MASK; +	stats->cancelled_write_bytes = p->ioac.cancelled_write_bytes & KB_MASK;  #else  	stats->read_bytes	= 0;  	stats->write_bytes	= 0; @@ -112,11 +121,8 @@ void xacct_add_tsk(struct taskstats *stats, struct task_struct *p)  #undef KB  #undef MB -/** - * acct_update_integrals - update mm integral fields in task_struct - * @tsk: task_struct for accounting - */ -void acct_update_integrals(struct task_struct *tsk) +static void __acct_update_integrals(struct task_struct *tsk, +				    cputime_t utime, cputime_t stime)  {  	if (likely(tsk->mm)) {  		cputime_t time, dtime; @@ -125,8 +131,8 @@ void acct_update_integrals(struct task_struct *tsk)  		u64 delta;  		local_irq_save(flags); -		time = tsk->stime + tsk->utime; -		dtime = cputime_sub(time, tsk->acct_timexpd); +		time = stime + utime; +		dtime = time - tsk->acct_timexpd;  		jiffies_to_timeval(cputime_to_jiffies(dtime), &value);  		delta = value.tv_sec;  		delta = delta * USEC_PER_SEC + value.tv_usec; @@ -142,6 +148,27 @@ void acct_update_integrals(struct task_struct *tsk)  }  /** + * acct_update_integrals - update mm integral fields in task_struct + * @tsk: task_struct for accounting + */ +void acct_update_integrals(struct task_struct *tsk) +{ +	cputime_t utime, stime; + +	task_cputime(tsk, &utime, &stime); +	__acct_update_integrals(tsk, utime, stime); +} + +/** + * acct_account_cputime - update mm integral after cputime update + * @tsk: task_struct for accounting + */ +void acct_account_cputime(struct task_struct *tsk) +{ +	__acct_update_integrals(tsk, tsk->utime, tsk->stime); +} + +/**   * acct_clear_integrals - clear the mm integral fields in task_struct   * @tsk: task_struct whose accounting fields are cleared   */  | 
