Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8472249ybi; Tue, 23 Jul 2019 09:09:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4PA1J23rtyWrz4wOzREM9BAzmzPc9enkRzFwQKGuYWV8eGhcHnpwZZUwuWz/BDw3t2VMh X-Received: by 2002:a63:c302:: with SMTP id c2mr72595640pgd.300.1563898181040; Tue, 23 Jul 2019 09:09:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563898181; cv=none; d=google.com; s=arc-20160816; b=r3/Y/BjLouKJCFY3du2AreTFyMEKcq5AHKvN3DUIzH2/7dLXne80Bc1z5hCKC067CZ kz43VXUe59xytd+BKdIX61aO/zWWZIfKiKTALvb0hmZeeHaukNuzIvueJ7vKN7wp0f4V tYj55Bw0jTFUkOTyGGi5gRDQRICJkaT0u9BTDl7RQn8cUq70GJuGF+w30iaIPAkHLsSF qEPujxzcGxbg/9GxIJN5fuHw/aLxPrjC2sI7GdnNu0+B2ug0Gq0V0uiA3n6y5dYQFArt g5aKxauc9MitwbdZUWnW6LyZL6TF/xbzuxO58HS48IYGjgenZoWYvZ5EEkJQ2eQl9Cjp glfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from; bh=Zvj+vdIraj+NNxuDYve++LY9wbM1gSlLheZ2cEQK+XU=; b=ZWYU4fBy3OEk9GUQsMDrLP2bQcqT2SJm9SvxqvTsY96fsTDXV5xlbqxPzfrA9x2RJW T9UU/smQKGeFpRL6vEyq9MVsl/AGdrTU5NM56grg0zfDB7DDsuMOH1zusOSEcenL6Wh2 dsajZOxDwkO0lBw5VZngNo9Ze87uKCdCOLNvNE7apzKQgDfqe+Zba9mfx6RvqUqAXS0d lcIUCaaCZg4x32SYBaA0mv61u7oDXvghn/hE7PQtL+w4swhy4drR7QCdP0i9O6Ow7B/M EXOrafRQ1QZCWeC9FikCzi3pjyBUQgv2utM8taI54QImVjXYDIigvpgblwe+sxxzBAPr 1Srw== 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 f5si11847835pgk.184.2019.07.23.09.09.25; Tue, 23 Jul 2019 09:09:40 -0700 (PDT) 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 S2388007AbfGWGIK (ORCPT + 99 others); Tue, 23 Jul 2019 02:08:10 -0400 Received: from out30-56.freemail.mail.aliyun.com ([115.124.30.56]:45703 "EHLO out30-56.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729098AbfGWGIG (ORCPT ); Tue, 23 Jul 2019 02:08:06 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0TXbg7o6_1563862083; Received: from localhost(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0TXbg7o6_1563862083) by smtp.aliyun-inc.com(127.0.0.1); Tue, 23 Jul 2019 14:08:04 +0800 From: Alex Shi Cc: Alex Shi , Ingo Molnar , Peter Zijlstra , Frederic Weisbecker , Wanpeng Li , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [RFC PATCH 3/3] cputime: unify account_process_tick func Date: Tue, 23 Jul 2019 14:01:42 +0800 Message-Id: <20190723060142.145747-3-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.856.g8858448bb In-Reply-To: <20190723060142.145747-1-alex.shi@linux.alibaba.com> References: <20190723060142.145747-1-alex.shi@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 path was introduced for precise ns irq time account from commit abb74cefa9c6 ("sched: Export ns irqtimes through /proc/stat") while account_process_tick still use jiffes. This divide isn't necessary especially now both paths are ns precison. Move out the irqtime_account_process_tick func from IRQ_TIME_ACCOUNTING. and combine the code for both *account_process_tick funcs for 2 paths. Then remove the useless irqtime_account_process_tick(). Signed-off-by: Alex Shi Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Frederic Weisbecker Cc: Wanpeng Li Cc: Thomas Gleixner Cc: linux-kernel@vger.kernel.org --- kernel/sched/cputime.c | 84 ++++++------------------------------------ 1 file changed, 12 insertions(+), 72 deletions(-) diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index 3bf94eb7b7c6..3cc581409252 100644 --- a/kernel/sched/cputime.c +++ b/kernel/sched/cputime.c @@ -332,68 +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 - * @user_tick: is the tick from userspace - * @rq: the pointer to rq - * - * Tick demultiplexing follows the order - * - pending hardirq update - * - pending softirq update - * - user_time - * - idle_time - * - system time - * - check for guest_time - * - else account as system_time - * - * Check for hardirq is done both for system and user time as there is - * no timer going off while we are on hardirq and hence we may never get an - * opportunity to update it solely in system time. - * 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, - struct rq *rq, int ticks) -{ - u64 other, cputime = TICK_NSEC * ticks; - - /* - * When returning from idle, many ticks can get accounted at - * once, including some ticks of steal, irq, and softirq time. - * Subtract those ticks from the amount of time accounted to - * idle, or potentially user or system time. Due to rounding, - * other time can exceed ticks occasionally. - */ - other = account_other_time(ULONG_MAX); - if (other >= cputime) - return; - - cputime -= other; - - if (this_cpu_ksoftirqd() == p) { - /* - * ksoftirqd time do not get accounted in cpu_softirq_time. - * So, we have to handle it separately here. - * Also, p->stime needs to be updated for ksoftirqd. - */ - account_system_index_time(p, cputime, CPUTIME_SYSTEM); - } else if (user_tick) { - account_user_time(p, cputime); - } else if (p == rq->idle) { - account_idle_time(cputime); - } else if (p->flags & PF_VCPU) { /* System time or guest time */ - account_guest_time(p, cputime); - } else { - account_system_index_time(p, cputime, CPUTIME_SYSTEM); - } -} -#else /* CONFIG_IRQ_TIME_ACCOUNTING */ -static inline void irqtime_account_process_tick(struct task_struct *p, int user_tick, - struct rq *rq, int nr_ticks) { } -#endif /* CONFIG_IRQ_TIME_ACCOUNTING */ - /* * Use precise platform statistics if available: */ @@ -466,26 +404,28 @@ 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; + u64 cputime, other; struct rq *rq = this_rq(); if (vtime_accounting_cpu_enabled()) return; - if (sched_clock_irqtime) { - irqtime_account_process_tick(p, user_tick, rq, 1); - return; - } - cputime = TICK_NSEC; - steal = steal_account_process_time(ULONG_MAX); + other = account_other_time(ULONG_MAX); - if (steal >= cputime) + if (other >= cputime) return; - cputime -= steal; + cputime -= other; - if (user_tick) + if (this_cpu_ksoftirqd() == p) + /* + * ksoftirqd time do not get accounted in cpu_softirq_time. + * So, we have to handle it separately here. + * Also, p->stime needs to be updated for ksoftirqd. + */ + account_system_index_time(p, cputime, CPUTIME_SYSTEM); + else if (user_tick) account_user_time(p, cputime); else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET)) account_system_time(p, HARDIRQ_OFFSET, cputime); -- 2.19.1.856.g8858448bb