Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3738539ybk; Tue, 19 May 2020 11:46:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJBedx77Jrl9J5TBJw9x4rKgU8zeFLGo1sKhav+Tl2G9u29xUAX4knRH88+lCuCpKmz6su X-Received: by 2002:a50:fb1a:: with SMTP id d26mr267467edq.83.1589913975130; Tue, 19 May 2020 11:46:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589913975; cv=none; d=google.com; s=arc-20160816; b=WDT8h7WtIzEAD2xeSoT438nPTAZxVdfmH5HeWhh/3Q13fNgrf1w6JAgC2Cw6JMvu4K Zi+1RVgzpxgTEyPyBsgFbNq4UF+eGD5XA2Vaay4jRKbNcrPI/SMomkB5EsRvxqkJNx4f tq705dKotu+wqKEsx2VLjtxpjcSQSwp4Nr/GsKQUZvTV2u12mj+pM9ZvvzYRkrAjfkwP GhRYdAomF6oMLdWPzbp12t8aOdgRXOYNu2P1lFzxMnUvJ8CU+LKvjRUE5BegNttxlOSL pGbgm6XN3fxs63RGQkIiU+V383CfbNS9CgpOdE/HmDSk50peZnIivfI3eKvdj0y9JevV Ru5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=IWTrx/gmhuqaNvSrtNmItbUjSyZO++FiNqSMMLeVips=; b=bSoe1e2S4rqLz6T3u7utBl0NSsMHEw41FeP6WdVXZspp9hoCdJMh8TW6D0Rpsl7F/w dvfmHFU2vnPyTeXPQLxtv2QaGJFrDm3Ol2b3I+5uXC97rLQAoLQnXsHSlOKTiCJu6Tjr 9Kc6Xsm4rgqxj8eEY8Xk3Qh+AJYAU49Pf3Lo9PLfZbzFu9mVneQUMs5lPsvQHKMGvUU7 li+CYZPGdPP6KW/wfHvJeIKlj9mh8+tcSaXy07sQZoaajeW+cc76SMRStY6wOYSCuXiw 0fySSSj4zKYmG1/x1s9CETixIzHyk4DLOwPVmeeRvfeFH3fim0UDJrp6osgf1/AacElF T+Eg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q12si378511ejt.692.2020.05.19.11.45.52; Tue, 19 May 2020 11:46:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727922AbgESSoY (ORCPT + 99 others); Tue, 19 May 2020 14:44:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726966AbgESSoT (ORCPT ); Tue, 19 May 2020 14:44:19 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17AF5C08C5C1; Tue, 19 May 2020 11:44:19 -0700 (PDT) Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jb7Dr-0006cn-2Q; Tue, 19 May 2020 20:44:15 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id AC86C1C0178; Tue, 19 May 2020 20:44:14 +0200 (CEST) Date: Tue, 19 May 2020 18:44:14 -0000 From: "tip-bot2 for Muchun Song" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/cpuacct: Fix charge cpuacct.usage_sys Cc: Muchun Song , "Peter Zijlstra (Intel)" , x86 , LKML In-Reply-To: <20200420070453.76815-1-songmuchun@bytedance.com> References: <20200420070453.76815-1-songmuchun@bytedance.com> MIME-Version: 1.0 Message-ID: <158991385462.17951.12607883978950306262.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/core branch of tip: Commit-ID: dbe9337109c2705f08e6a00392f991eb2d2570a5 Gitweb: https://git.kernel.org/tip/dbe9337109c2705f08e6a00392f991eb2d2570a5 Author: Muchun Song AuthorDate: Mon, 20 Apr 2020 15:04:53 +08:00 Committer: Peter Zijlstra CommitterDate: Tue, 19 May 2020 20:34:14 +02:00 sched/cpuacct: Fix charge cpuacct.usage_sys The user_mode(task_pt_regs(tsk)) always return true for user thread, and false for kernel thread. So it means that the cpuacct.usage_sys is the time that kernel thread uses not the time that thread uses in the kernel mode. We can try get_irq_regs() first, if it is NULL, then we can fall back to task_pt_regs(). Signed-off-by: Muchun Song Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20200420070453.76815-1-songmuchun@bytedance.com --- kernel/sched/cpuacct.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c index 6448b04..941c28c 100644 --- a/kernel/sched/cpuacct.c +++ b/kernel/sched/cpuacct.c @@ -5,6 +5,7 @@ * Based on the work by Paul Menage (menage@google.com) and Balbir Singh * (balbir@in.ibm.com). */ +#include #include "sched.h" /* Time spent by the tasks of the CPU accounting group executing in ... */ @@ -339,7 +340,7 @@ void cpuacct_charge(struct task_struct *tsk, u64 cputime) { struct cpuacct *ca; int index = CPUACCT_STAT_SYSTEM; - struct pt_regs *regs = task_pt_regs(tsk); + struct pt_regs *regs = get_irq_regs() ? : task_pt_regs(tsk); if (regs && user_mode(regs)) index = CPUACCT_STAT_USER;