Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17271604ybl; Thu, 2 Jan 2020 02:10:18 -0800 (PST) X-Google-Smtp-Source: APXvYqytcH/ykYDGiAdPn1VCKYHbjiBX0zT12gkAqkpPF84SWSuXH7pobYoZItVqtsRPpL0wjmJi X-Received: by 2002:a9d:6857:: with SMTP id c23mr75384768oto.351.1577959818502; Thu, 02 Jan 2020 02:10:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577959818; cv=none; d=google.com; s=arc-20160816; b=bGwIp3xS6PJaw6VBEABkqliA9uE2sl8RVFMjlH7tWwmSv/bTGLm4z9sU4md4MNDZTH hFCWc6Alkij3ZMdNbccf2ufSTMiYb+EHHOSUCPznVdqkJ4U8VtkAffp5+k3wuP+Lgv0h IYR3iFNusA5IDWwU2/6Lht++vt/0cCsSXObl9X6RYiZBREdlCLiT9Fj+dKcNKt0ZSNSH SNH+AmfJUcBdhNsWNHdK5QQjlzTvB3FeLslUkQAWfVrn4WyuwanpoWb5F2dMwGrSRIPW klCPZXwMXzRgpuFp/cfAbP7adJB5P7tvEhPdEeMIqUXPMvZhSI4T2TOf+xZIq1aXxFnC xwmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:in-reply-to:message-id:date :subject:cc:from; bh=6M1sZ5PJaAOZPyySuplRKU5d5NLaw3yYSgGO2wc83uU=; b=GRKsuKBLtDAENOR5lElKNHLFl9WZ8IHe5qXqn6BkfETZJtrqZ0K8Q4NWVcddUKnGua z4HL81nhzyC49Nctm+rzywj8gMXbcQtlDvgT0enm6uuuZ/u2yvcgfNjNu6a474X4XL3M G7yJfS2Nb0/p2aprEcCppLPi9ijHmxV2bmMkBRx8315mqqZS78BHl0p3VE/Wt75QnbbB 1uWx//45sP7s+7UoaUqaxxJcUC02TBWfU5GzQzmUx/KtfTeC75x72zXL4UDiu9qpIoq8 Hc2vbivoJCSj7FBJzrLzirfKm+6VK0Tkp7h3wjX3w3JoZHbZdlaIRZrzoyivOyJ5tPow hang== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w18si30574488otl.54.2020.01.02.02.10.06; Thu, 02 Jan 2020 02:10:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728045AbgABKIO (ORCPT + 99 others); Thu, 2 Jan 2020 05:08:14 -0500 Received: from out30-42.freemail.mail.aliyun.com ([115.124.30.42]:36138 "EHLO out30-42.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727978AbgABKIM (ORCPT ); Thu, 2 Jan 2020 05:08:12 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R291e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07488;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0TmbxjSZ_1577959689; Received: from localhost(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0TmbxjSZ_1577959689) by smtp.aliyun-inc.com(127.0.0.1); Thu, 02 Jan 2020 18:08:10 +0800 From: Alex Shi Cc: Ingo Molnar , Peter Zijlstra , Frederic Weisbecker , Wanpeng Li , Anna-Maria Gleixner , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] sched/cputime: cleanup account_process_tick/account_idle_ticks Date: Thu, 2 Jan 2020 18:07:54 +0800 Message-Id: <1577959674-255537-3-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1577959674-255537-1-git-send-email-alex.shi@linux.alibaba.com> References: <1577959674-255537-1-git-send-email-alex.shi@linux.alibaba.com> To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The irqtime_account_process_tick() was introduced for precise ns irq time account from commit abb74cefa9c6 ("sched: Export ns irqtimes through /proc/stat") which is necessary since account_process_tick() still use jiffes at that time. Now account_process_tick/account_idle_ticks functions do the actual same actions as irqtime_account_process_tick() to account ns precision cputime when !sched_clock_irqtime. which could be replaced by irqtime_account_process_tick(); So we move out irqtime_account_process_tick from IRQ_TIME_ACCOUNTING config, let it work w/o IRQ_TIME_ACCOUNTING. and remove the duplicated code in account_process_tick/account_idle_ticks. And furthmore I removed the function account_idle_ticks by a directly call. It can simplify the code, also reduce a bit object size. Signed-off-by: Alex Shi Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Frederic Weisbecker Cc: Wanpeng Li Cc: Anna-Maria Gleixner Cc: Thomas Gleixner Cc: linux-kernel@vger.kernel.org --- include/linux/kernel_stat.h | 2 +- kernel/sched/cputime.c | 58 ++------------------------------------------- kernel/time/tick-sched.c | 2 +- 3 files changed, 4 insertions(+), 58 deletions(-) diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h index 89f0745c096d..e924bdb8c874 100644 --- a/include/linux/kernel_stat.h +++ b/include/linux/kernel_stat.h @@ -113,6 +113,6 @@ static inline void account_process_tick(struct task_struct *tsk, int user) extern void account_process_tick(struct task_struct *, int user); #endif -extern void account_idle_ticks(unsigned long ticks); +extern void irqtime_account_process_tick(struct task_struct *, int , int); #endif /* _LINUX_KERNEL_STAT_H */ diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index 46b837e94fce..0e0c74c1b3c9 100644 --- a/kernel/sched/cputime.c +++ b/kernel/sched/cputime.c @@ -332,7 +332,6 @@ void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times) rcu_read_unlock(); } -#ifdef CONFIG_IRQ_TIME_ACCOUNTING /* * Account a tick to a process and cpustat * @p: the process that the CPU time gets accounted to @@ -354,7 +353,7 @@ void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times) * p->stime and friends are only updated on system time and not on irq * softirq as those do not count in task exec_runtime any more. */ -static void irqtime_account_process_tick(struct task_struct *p, int user_tick, +void irqtime_account_process_tick(struct task_struct *p, int user_tick, int ticks) { u64 other, cputime = TICK_NSEC * ticks; @@ -387,16 +386,6 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick, account_idle_time(cputime); } -static void irqtime_account_idle_ticks(int ticks) -{ - irqtime_account_process_tick(current, 0, ticks); -} -#else /* CONFIG_IRQ_TIME_ACCOUNTING */ -static inline void irqtime_account_idle_ticks(int ticks) { } -static inline void irqtime_account_process_tick(struct task_struct *p, int user_tick, - int nr_ticks) { } -#endif /* CONFIG_IRQ_TIME_ACCOUNTING */ - /* * Use precise platform statistics if available: */ @@ -467,53 +456,10 @@ void thread_group_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st) */ void account_process_tick(struct task_struct *p, int user_tick) { - u64 cputime, steal; - if (vtime_accounting_enabled_this_cpu()) return; - if (sched_clock_irqtime) { - irqtime_account_process_tick(p, user_tick, 1); - return; - } - - cputime = TICK_NSEC; - steal = steal_account_process_time(ULONG_MAX); - - if (steal >= cputime) - return; - - cputime -= steal; - - if (user_tick) - account_user_time(p, cputime); - else if ((p != this_rq()->idle) || (irq_count() != HARDIRQ_OFFSET)) - account_system_time(p, HARDIRQ_OFFSET, cputime); - else - account_idle_time(cputime); -} - -/* - * Account multiple ticks of idle time. - * @ticks: number of stolen ticks - */ -void account_idle_ticks(unsigned long ticks) -{ - u64 cputime, steal; - - if (sched_clock_irqtime) { - irqtime_account_idle_ticks(ticks); - return; - } - - cputime = ticks * TICK_NSEC; - steal = steal_account_process_time(ULONG_MAX); - - if (steal >= cputime) - return; - - cputime -= steal; - account_idle_time(cputime); + irqtime_account_process_tick(p, user_tick, 1); } /* diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 8b192e67aabc..92a0979633e9 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1142,7 +1142,7 @@ static void tick_nohz_account_idle_ticks(struct tick_sched *ts) * We might be one off. Do not randomly account a huge number of ticks! */ if (ticks && ticks < LONG_MAX) - account_idle_ticks(ticks); + irqtime_account_process_tick(current, 0, ticks); #endif } -- 1.8.3.1