Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751727AbdCCIAN (ORCPT ); Fri, 3 Mar 2017 03:00:13 -0500 Received: from mail.windriver.com ([147.11.1.11]:51176 "EHLO mail.windriver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751676AbdCCIAK (ORCPT ); Fri, 3 Mar 2017 03:00:10 -0500 From: Zhang Xiao To: CC: , Subject: [PATCH] taskstats: Add e/u/stime for TGID command Date: Fri, 3 Mar 2017 10:33:44 +0800 Message-ID: <1488508424-12322-1-git-send-email-xiao.zhang@windriver.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1190 Lines: 39 Add elapsed time, user CPU time and system CPU time to thread group status request. Signed-off-by: Zhang Xiao --- kernel/taskstats.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kernel/taskstats.c b/kernel/taskstats.c index 8a5e442..802a2bb 100644 --- a/kernel/taskstats.c +++ b/kernel/taskstats.c @@ -210,6 +210,7 @@ static int fill_stats_for_tgid(pid_t tgid, struct taskstats *stats) struct task_struct *tsk, *first; unsigned long flags; int rc = -ESRCH; + u64 delta, utime, stime; /* * Add additional stats from live tasks except zombie thread group @@ -238,6 +239,16 @@ static int fill_stats_for_tgid(pid_t tgid, struct taskstats *stats) */ delayacct_add_tsk(stats, tsk); + /* calculate task elapsed time in nsec */ + delta = ktime_get_ns() - tsk->start_time; + /* Convert to micro seconds */ + do_div(delta, NSEC_PER_USEC); + stats->ac_etime += delta; + + task_cputime(tsk, &utime, &stime); + stats->ac_utime += div_u64(utime, NSEC_PER_USEC); + stats->ac_stime += div_u64(stime, NSEC_PER_USEC); + stats->nvcsw += tsk->nvcsw; stats->nivcsw += tsk->nivcsw; } while_each_thread(first, tsk); -- 2.1.4