Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1673981pxj; Fri, 18 Jun 2021 12:18:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbSO/0UX7PCKawkHUnQmw/uj6kWIkCNViu1BR0DMgaFavAUyw0EMl271JMrSsLBYDcuMK6 X-Received: by 2002:a17:906:8688:: with SMTP id g8mr12468055ejx.470.1624043910943; Fri, 18 Jun 2021 12:18:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624043910; cv=none; d=google.com; s=arc-20160816; b=DDuA7HwHQzOPoMLcUxRbFjVMpYwqenkmnns2dsGtnkeYIM5EN77RkGNRJPva+yGHQi H2aESa/MQvGinKs/9xbmcc2Lx3HUVvnWApnsbaJ8WldG6SPt23tiOFMVQWLCk4q1e9RK 7ShXMPFTH21I22HfJTPr89lIy8kQ65b3NINwP5b8bWtgkOpB3voD/BV+7xW6Kk1z6d6M ivWKvj/5Bn5+FZDe1Dgn2DIEa968mCwNFnyotlwUstHkEUtQC44sM5tV6qvCpDlyf71B O7dATgoXK+021Dl3VI8s7mhjmWK/w/hvW9077/sOnR2cwbsqtw/S844eMbMjNEcznbE7 hV7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=+ZnpErV0Yd5avn0Sa93Xa4PHwfCfbkRz0QWoon/b0F0=; b=qP+xOHu43hEM+HJ4fFeKuo8KDp1mmBIkC1O0IxrQ2RSBmQjCsDYxtsSA/Xex33Pcc6 jK+x2u1KtewAZI97GQ52WRZoUIKdcui3jQw5UbiIseziM8SaGjzEY57K3YrlRUkUvd6+ rfl+GjRgrx+dobhxdfwn1gsleGyrbuA4SMHCAynAmgOLoOoksFPrGfciwBw8RZ7a0BIx hHtyZxqAyFdvSvZyWXiPpNlQj6yZhREIG52ec6UomHqMHD1mWezwKowIrD4TRNLrRP4o 0md5LifGPyxXeiT7i+hxYBaU9ognMnCuAK+p9oQfByeb3k3iVI0IX2i47Ps00fyWbKly sM+A== 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 yc20si3225903ejb.387.2021.06.18.12.18.07; Fri, 18 Jun 2021 12:18:30 -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 S234386AbhFRQrT (ORCPT + 99 others); Fri, 18 Jun 2021 12:47:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:49834 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231977AbhFRQrR (ORCPT ); Fri, 18 Jun 2021 12:47:17 -0400 Received: from oasis.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2A9ED610C7; Fri, 18 Jun 2021 16:45:06 +0000 (UTC) Date: Fri, 18 Jun 2021 12:45:03 -0400 From: Steven Rostedt To: Daniel Bristot de Oliveira Cc: Phil Auld , Sebastian Andrzej Siewior , Kate Carcia , Jonathan Corbet , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexandre Chartre , Clark Willaims , John Kacur , Juri Lelli , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH V4 05/12] trace/hwlat: Support hotplug operations Message-ID: <20210618124503.388fe4d4@oasis.local.home> In-Reply-To: <8899f8a8bec38bc600f7a2c61bc6ca664aa7beeb.1623746916.git.bristot@redhat.com> References: <8899f8a8bec38bc600f7a2c61bc6ca664aa7beeb.1623746916.git.bristot@redhat.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 15 Jun 2021 11:28:44 +0200 Daniel Bristot de Oliveira wrote: > Enable and disable hwlat thread during cpu hotplug online > and offline operations, respectivelly. > > Cc: Jonathan Corbet > Cc: Steven Rostedt > Cc: Ingo Molnar > Cc: Peter Zijlstra > Cc: Thomas Gleixner > Cc: Alexandre Chartre > Cc: Clark Willaims > Cc: John Kacur > Cc: Juri Lelli > Cc: Borislav Petkov > Cc: "H. Peter Anvin" > Cc: x86@kernel.org > Cc: linux-doc@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Daniel Bristot de Oliveira > --- > kernel/trace/trace.c | 6 ++++++ > kernel/trace/trace_hwlat.c | 34 ++++++++++++++++++++++++++++++++++ > 2 files changed, 40 insertions(+) > > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c > index 9299057feb56..c094865e2f71 100644 > --- a/kernel/trace/trace.c > +++ b/kernel/trace/trace.c > @@ -5064,7 +5064,13 @@ int tracing_set_cpumask(struct trace_array *tr, > arch_spin_unlock(&tr->max_lock); > local_irq_enable(); > > + /* > + * tracing_cpumask is read by tracers that support CPU > + * hotplug. > + */ > + get_online_cpus(); > cpumask_copy(tr->tracing_cpumask, tracing_cpumask_new); > + put_online_cpus(); > > return 0; > } > diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c > index 6c6918e86087..9fcfd588c4f6 100644 > --- a/kernel/trace/trace_hwlat.c > +++ b/kernel/trace/trace_hwlat.c > @@ -490,6 +490,35 @@ static int start_cpu_kthread(unsigned int cpu) > return 0; > } > > +/* > + * hwlat_cpu_init - CPU hotplug online callback function > + */ > +static int hwlat_cpu_init(unsigned int cpu) > +{ > + struct trace_array *tr = hwlat_trace; > + You need to take the trace_types_lock here, between testing the hwlat_busy and starting the threads. Otherwise, between the two, the hwlat tracer could be turned off while a CPU is coming on line, and then you just started a per cpu thread, while the hwlat tracer is not enabled. > + if (!hwlat_busy) > + return 0; > + > + if (!cpumask_test_cpu(cpu, tr->tracing_cpumask)) > + return 0; > + > + return start_cpu_kthread(cpu); > +} > + > +/* > + * hwlat_cpu_die - CPU hotplug offline callback function > + */ > +static int hwlat_cpu_die(unsigned int cpu) > +{ Same here. -- Steve > + if (!hwlat_busy) > + return 0; > + > + stop_cpu_kthread(cpu); > + > + return 0; > +} > + > /* > * start_per_cpu_kthreads - Kick off the hardware latency sampling/detector kthreads > * > @@ -903,6 +932,11 @@ __init static int init_hwlat_tracer(void) > if (ret) > return ret; > > + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "trace/hwlat:online", > + hwlat_cpu_init, hwlat_cpu_die); > + if (ret < 0) > + pr_warn(BANNER "Error to init cpu hotplug support\n"); > + > init_tracefs(); > > return 0;