From patchwork Thu Jan 5 00:51:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 13089343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46030C46467 for ; Thu, 5 Jan 2023 00:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230479AbjAEAz3 (ORCPT ); Wed, 4 Jan 2023 19:55:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230226AbjAEAyn (ORCPT ); Wed, 4 Jan 2023 19:54:43 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9658B4D725; Wed, 4 Jan 2023 16:51:28 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3592B61883; Thu, 5 Jan 2023 00:51:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94E93C433F0; Thu, 5 Jan 2023 00:51:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672879887; bh=NWSPmqPtnSB+GjAOqFi44AyevCau+gcT+vefcRYY03w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M50iFfXGCcAnPZ8l78Kh9X49SXipU0UAVMQiAoCz6DVJ/5bbAMvbnMUjFloCWG99A PWodxkEnTq5cFcsKYdoAnOf/STsamLmqIIuvo99/KUcQ07KHGLM8SqDWqoXYQ4C3qf Ca86GmQLIPXlgSHqGiVGX3hxPzBjB9E9eClyITbBuJEqqwwJM9RloW0wRoN+3+ss9C GTsZFuLom8WXnGJ4JA8Z9MQYZPuCXYTUexMSx1kCoPGu4wnTpWGl3ts1Xv1dojOLso 1UZj4nEAf8vV3u7NFKwzzETkbQNtEprR4kObiFXnivZtFVhyXRdA4GgXexsm0TjR/Q J670JA8N63SJQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 5340F5C1456; Wed, 4 Jan 2023 16:51:27 -0800 (PST) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, Zhen Lei , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Frederic Weisbecker , "Paul E . McKenney" Subject: [PATCH rcu 3/6] sched: Add helper nr_context_switches_cpu() Date: Wed, 4 Jan 2023 16:51:23 -0800 Message-Id: <20230105005126.1772294-3-paulmck@kernel.org> X-Mailer: git-send-email 2.31.1.189.g2e36527f23 In-Reply-To: <20230105005105.GA1772125@paulmck-ThinkPad-P17-Gen-1> References: <20230105005105.GA1772125@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: rcu@vger.kernel.org From: Zhen Lei Add a function nr_context_switches_cpu() that returns number of context switches since boot on the specified CPU. This information will be used to diagnose RCU CPU stalls. Signed-off-by: Zhen Lei Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Valentin Schneider Reviewed-by: Frederic Weisbecker Signed-off-by: Paul E. McKenney --- include/linux/kernel_stat.h | 1 + kernel/sched/core.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h index 898076e173a92..9935f7ecbfb9e 100644 --- a/include/linux/kernel_stat.h +++ b/include/linux/kernel_stat.h @@ -52,6 +52,7 @@ DECLARE_PER_CPU(struct kernel_cpustat, kernel_cpustat); #define kstat_cpu(cpu) per_cpu(kstat, cpu) #define kcpustat_cpu(cpu) per_cpu(kernel_cpustat, cpu) +extern unsigned long long nr_context_switches_cpu(int cpu); extern unsigned long long nr_context_switches(void); extern unsigned int kstat_irqs_cpu(unsigned int irq, int cpu); diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 25b582b6ee5f7..2e40a6c116e1c 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5282,6 +5282,11 @@ bool single_task_running(void) } EXPORT_SYMBOL(single_task_running); +unsigned long long nr_context_switches_cpu(int cpu) +{ + return cpu_rq(cpu)->nr_switches; +} + unsigned long long nr_context_switches(void) { int i;