From nobody Tue Dec 16 07:27:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95AEB270548; Mon, 5 May 2025 21:22:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480148; cv=none; b=nYUv7NwF80djl6aNFf8ZNVpxG+M/31YBIg3LV/ntVRHYxM23d+CabS0sT1y8+BdXMLRejjI5DbEkVR51fHoL/jAAYgRESeHCRWSmGWVKbvRQ+Y+fs/73+2OMgXXZU6rf+SNyj1YC0L8/SmAE/NDjQEL2swlmxlQpChsPsfb4rrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480148; c=relaxed/simple; bh=eGoXC6PxV7+R1ceOCIV5HnJX5yRFgYWLtD6ouKR5GnQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=GwBLsl9NhMA2kYyv7P2k+h9nWQjMqkyY27FfVPxzxxGlY7gz8X8weDu+U7PTN4dhUfCd6dLfA2OjV9NmnFHqhn3MSqeMLVKLW1uKLZpzQPWVA5JM2VU+/29pFJXFB6T587jtMxlRE6g+HFjE+vNq3B78qK0g/MIkpOufmqRyZfk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D349C4CEEE; Mon, 5 May 2025 21:22:28 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uC3Gk-00000000yBG-3YLk; Mon, 05 May 2025 17:22:34 -0400 Message-ID: <20250505212234.696945463@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 05 May 2025 17:21:05 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH v2 01/13] tracing/mmiotrace: Remove reference to unused per CPU data pointer References: <20250505212104.986494754@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The mmiotracer referenced the per CPU array_buffer->data descriptor but never actually used it. Remove the references to it. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_mmiotrace.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c index ba5858866b2f..c706544be60c 100644 --- a/kernel/trace/trace_mmiotrace.c +++ b/kernel/trace/trace_mmiotrace.c @@ -291,7 +291,6 @@ __init static int init_mmio_trace(void) device_initcall(init_mmio_trace); =20 static void __trace_mmiotrace_rw(struct trace_array *tr, - struct trace_array_cpu *data, struct mmiotrace_rw *rw) { struct trace_buffer *buffer =3D tr->array_buffer.buffer; @@ -315,12 +314,10 @@ static void __trace_mmiotrace_rw(struct trace_array *= tr, void mmio_trace_rw(struct mmiotrace_rw *rw) { struct trace_array *tr =3D mmio_trace_array; - struct trace_array_cpu *data =3D per_cpu_ptr(tr->array_buffer.data, smp_p= rocessor_id()); - __trace_mmiotrace_rw(tr, data, rw); + __trace_mmiotrace_rw(tr, rw); } =20 static void __trace_mmiotrace_map(struct trace_array *tr, - struct trace_array_cpu *data, struct mmiotrace_map *map) { struct trace_buffer *buffer =3D tr->array_buffer.buffer; @@ -344,12 +341,7 @@ static void __trace_mmiotrace_map(struct trace_array *= tr, void mmio_trace_mapping(struct mmiotrace_map *map) { struct trace_array *tr =3D mmio_trace_array; - struct trace_array_cpu *data; - - preempt_disable(); - data =3D per_cpu_ptr(tr->array_buffer.data, smp_processor_id()); - __trace_mmiotrace_map(tr, data, map); - preempt_enable(); + __trace_mmiotrace_map(tr, map); } =20 int mmio_trace_printk(const char *fmt, va_list args) --=20 2.47.2 From nobody Tue Dec 16 07:27:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1096270565; Mon, 5 May 2025 21:22:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480148; cv=none; b=qWLiY+G7BfpxptA2zzxYQn/KDQ/go7iA4damwIeI1CwNvTT0J1BfaezKd5WX+fCjztawrlUD+ev94WlSO+QOQypexaIX2RWDtlepCvIA3j4OfVv+ZthYbMJRRuFG/GUByqdsGjSJjMFoWKrixY2Tbl1zfrUZGhwM6dnZDw9006g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480148; c=relaxed/simple; bh=TqkD8LxtVBklZh0dnSpjx7PjTTWwl2OLh6qRcV+8HgA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=i8ybn8Ys+bUFBkB9VzTk+vqOCLB5OR7sPD63f3qk+aAnVHNSVO4zlPH7HP2TdTWBz9L0tvw3nJdo7sGZeiMdCb5gK7p9HSGJcGYyokdQ7Vc9KfLu7HykHArabQ5LgzyRY/3LYupVn53X+QG7dpIpd/X6mwH6Rjkh5pfQvJU4m1g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4402EC4CEEF; Mon, 5 May 2025 21:22:28 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uC3Gl-00000000yBl-04qZ; Mon, 05 May 2025 17:22:35 -0400 Message-ID: <20250505212234.868972758@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 05 May 2025 17:21:06 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH v2 02/13] ftrace: Do not bother checking per CPU "disabled" flag References: <20250505212104.986494754@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The per CPU "disabled" value was the original way to disable tracing when the tracing subsystem was first created. Today, the ring buffer infrastructure has its own way to disable tracing. In fact, things have changed so much since 2008 that many things ignore the disable flag. There's no reason for the function tracer to check it, if tracing is disabled, the ring buffer will not record the event anyway. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_functions.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c index 98ccf3f00c51..bd153219a712 100644 --- a/kernel/trace/trace_functions.c +++ b/kernel/trace/trace_functions.c @@ -209,7 +209,6 @@ function_trace_call(unsigned long ip, unsigned long par= ent_ip, struct ftrace_ops *op, struct ftrace_regs *fregs) { struct trace_array *tr =3D op->private; - struct trace_array_cpu *data; unsigned int trace_ctx; int bit; =20 @@ -224,9 +223,7 @@ function_trace_call(unsigned long ip, unsigned long par= ent_ip, =20 trace_ctx =3D tracing_gen_ctx_dec(); =20 - data =3D this_cpu_ptr(tr->array_buffer.data); - if (!atomic_read(&data->disabled)) - trace_function(tr, ip, parent_ip, trace_ctx, NULL); + trace_function(tr, ip, parent_ip, trace_ctx, NULL); =20 ftrace_test_recursion_unlock(bit); } @@ -236,10 +233,8 @@ function_args_trace_call(unsigned long ip, unsigned lo= ng parent_ip, struct ftrace_ops *op, struct ftrace_regs *fregs) { struct trace_array *tr =3D op->private; - struct trace_array_cpu *data; unsigned int trace_ctx; int bit; - int cpu; =20 if (unlikely(!tr->function_enabled)) return; @@ -250,10 +245,7 @@ function_args_trace_call(unsigned long ip, unsigned lo= ng parent_ip, =20 trace_ctx =3D tracing_gen_ctx(); =20 - cpu =3D smp_processor_id(); - data =3D per_cpu_ptr(tr->array_buffer.data, cpu); - if (!atomic_read(&data->disabled)) - trace_function(tr, ip, parent_ip, trace_ctx, fregs); + trace_function(tr, ip, parent_ip, trace_ctx, fregs); =20 ftrace_test_recursion_unlock(bit); } @@ -352,7 +344,6 @@ function_no_repeats_trace_call(unsigned long ip, unsign= ed long parent_ip, { struct trace_func_repeats *last_info; struct trace_array *tr =3D op->private; - struct trace_array_cpu *data; unsigned int trace_ctx; int bit; =20 @@ -364,8 +355,7 @@ function_no_repeats_trace_call(unsigned long ip, unsign= ed long parent_ip, return; =20 parent_ip =3D function_get_true_parent_ip(parent_ip, fregs); - data =3D this_cpu_ptr(tr->array_buffer.data); - if (atomic_read(&data->disabled)) + if (!tracer_tracing_is_on(tr)) goto out; =20 /* --=20 2.47.2 From nobody Tue Dec 16 07:27:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A10F7270EA1; Mon, 5 May 2025 21:22:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480148; cv=none; b=nljj3qXeIjfJD36PqnPZ9tR+I0sT6hj3FJyqbjbqrttj9/i3ga0d8A2H3DsFzMTzoaI0UgjzpGTB7VLdHLJZmqnZcgYuhhE8YnJ4zVoJSM9MGofu6dytJJrEyy0MJBkwwN03X8qfzu51uX1tYeFOzNZfuGUnFEJmbgxbI7CLZtE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480148; c=relaxed/simple; bh=RD0ncGsvrCJ0pZLeWa6ErfBpjmRnol++5MfNHvNqgks=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=KFSkJBe2nAf2tRL3Q0aeCul8jUoU2djFFKnk6RjneJvudvOBLZrD3C+Y/1269pRtZUDKWshzDT1hz0EPAw14dkSfE7b7cttsgeUkuBInj2pdJaUo/LOmN6X1M+BfG15JLTnVs67Cyp3+wl34FIuduC8Sgpo4OtPyEdrhEvaH1cA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E278C4CEF3; Mon, 5 May 2025 21:22:28 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uC3Gl-00000000yCF-0moi; Mon, 05 May 2025 17:22:35 -0400 Message-ID: <20250505212235.038958766@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 05 May 2025 17:21:07 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH v2 03/13] tracing: Just use this_cpu_read() to access ignore_pid References: <20250505212104.986494754@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The ignore_pid boolean on the per CPU data descriptor is updated at sched_switch when a new task is scheduled in. If the new task is to be ignored, it is set to true, otherwise it is set to false. The current task should always have the correct value as it is updated when the task is scheduled in. Instead of breaking up the read of this value, which requires preemption to be disabled, just use this_cpu_read() which gives a snapshot of the value. Since the value will always be correct for a given task (because it's updated at sched switch) it doesn't need preemption disabled. This will also allow trace events to be called with preemption enabled. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index 069e92856bda..fe0ea14d809e 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -622,7 +622,6 @@ EXPORT_SYMBOL_GPL(trace_event_raw_init); bool trace_event_ignore_this_pid(struct trace_event_file *trace_file) { struct trace_array *tr =3D trace_file->tr; - struct trace_array_cpu *data; struct trace_pid_list *no_pid_list; struct trace_pid_list *pid_list; =20 @@ -632,9 +631,11 @@ bool trace_event_ignore_this_pid(struct trace_event_fi= le *trace_file) if (!pid_list && !no_pid_list) return false; =20 - data =3D this_cpu_ptr(tr->array_buffer.data); - - return data->ignore_pid; + /* + * This is recorded at every sched_switch for this task. + * Thus, even if the task migrates the ignore value will be the same. + */ + return this_cpu_read(tr->array_buffer.data->ignore_pid) !=3D 0; } EXPORT_SYMBOL_GPL(trace_event_ignore_this_pid); =20 --=20 2.47.2 From nobody Tue Dec 16 07:27:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C22672741C0; Mon, 5 May 2025 21:22:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480148; cv=none; b=VQeC5CdfOydLaMNvLCQPTYHyOXJlvqA/r9d7/1Yjr02fx2O+o++FBOUuRorBkQTXPMTbTGfCkR8g/9nsPPrKSALGa9d2ILsNGojlxFpQplFaX7qDsbi05HfuBVx9TC5aLopMa6rdjRg5NSUPDydinOaq/8XFklGgn+3DBy2RTZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480148; c=relaxed/simple; bh=AtbwyqvdErRJG3wewcNLOmRcFKegEF41KY1o+ID/ICI=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=cUbh03uUw9pczeWZ9u1P5UaolnOX6+U5oho6tCdUjwfxbcH1GyHxsWkI5IWX0git0ezuMAnIr+7S8hoN1wOI3YMW7XYEQx/khaZSn5hECdOKfRB/M4R6FMsHUqJ8jIgmVsexvSneBS4xPGEVJtVOZKT8CF2qDcLZtSaDjgwWYWs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75E7DC4CEF5; Mon, 5 May 2025 21:22:28 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uC3Gl-00000000yCj-1VSq; Mon, 05 May 2025 17:22:35 -0400 Message-ID: <20250505212235.210330010@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 05 May 2025 17:21:08 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Jason Wessel , Daniel Thompson , Douglas Anderson Subject: [PATCH v2 04/13] tracing: Add tracer_tracing_disable/enable() functions References: <20250505212104.986494754@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt Allow a tracer to disable writing to its buffer for a temporary amount of time and re-enable it. The tracer_tracing_disable() will disable writing to the trace array buffer, and requires a tracer_tracing_enable() to re-enable it. The difference between tracer_tracing_disable() and tracer_tracing_off() is that the disable version can nest, and requires as many enable() calls as disable() calls to re-enable the buffer. Where as the off() function can be called multiple times and only requires a singe tracer_tracing_on() to re-enable the buffer. Cc: Jason Wessel Cc: Daniel Thompson Cc: Douglas Anderson Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 33 +++++++++++++++++++++++++++++++++ kernel/trace/trace.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 5b8db27fb6ef..e36b1244fa82 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -1582,6 +1582,39 @@ void tracer_tracing_off(struct trace_array *tr) smp_wmb(); } =20 +/** + * tracer_tracing_disable() - temporary disable the buffer from write + * @tr: The trace array to disable its buffer for + * + * Expects trace_tracing_enable() to re-enable tracing. + * The difference between this and tracer_tracing_off() is that this + * is a counter and can nest, whereas, tracer_tracing_off() can + * be called multiple times and a single trace_tracing_on() will + * enable it. + */ +void tracer_tracing_disable(struct trace_array *tr) +{ + if (WARN_ON_ONCE(!tr->array_buffer.buffer)) + return; + + ring_buffer_record_disable(tr->array_buffer.buffer); +} + +/** + * tracer_tracing_enable() - counter part of tracer_tracing_disable() + * @tr: The trace array that had tracer_tracincg_disable() called on it + * + * This is called after tracer_tracing_disable() has been called on @tr, + * when it's safe to re-enable tracing. + */ +void tracer_tracing_enable(struct trace_array *tr) +{ + if (WARN_ON_ONCE(!tr->array_buffer.buffer)) + return; + + ring_buffer_record_enable(tr->array_buffer.buffer); +} + /** * tracing_off - turn off tracing buffers * diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 79be1995db44..74f1fe5788d4 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -665,6 +665,8 @@ bool tracing_is_disabled(void); bool tracer_tracing_is_on(struct trace_array *tr); void tracer_tracing_on(struct trace_array *tr); void tracer_tracing_off(struct trace_array *tr); +void tracer_tracing_disable(struct trace_array *tr); +void tracer_tracing_enable(struct trace_array *tr); struct dentry *trace_create_file(const char *name, umode_t mode, struct dentry *parent, --=20 2.47.2 From nobody Tue Dec 16 07:27:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B6682749C3; Mon, 5 May 2025 21:22:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480149; cv=none; b=dDGoCKeaYZRHX3zNL1JZIf7eZfvjlFOqqxIWKqEqpGYwuWtXTd803Eu02xZ6si0qlLSvC2Rf+pqpJxErs6qcNgDFnrRhzoWVxZ3WTaa5s9QDXifarHTpwtJ5KtuXwGHZom8Jc+a6X/aM+UkB3Yyph3UWDZts9UK/AB02b8d1/s0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480149; c=relaxed/simple; bh=RxtgXCfcqWA6ooX95AsP5Gn57jVm1MgA5swttk/JuWo=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=esLNtEi8SyMKc9gx+7elluFX+9zwK01Yn2yLhIA61e4VWm9VazK6yB98bCwVKIlZ25rUalAPBDNudAKXJ6GFCGg2pg1H8k1xKJ/G9ceBaMJwdb/7QmxtUXcNVIhXMcZWmFX6kK52zHZLWLhCAEoA0IQ0DMAcsz1Ae8p3fZnoJFU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE137C4CEED; Mon, 5 May 2025 21:22:28 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uC3Gl-00000000yDE-2DL1; Mon, 05 May 2025 17:22:35 -0400 Message-ID: <20250505212235.381188238@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 05 May 2025 17:21:09 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH v2 05/13] tracing: Use tracer_tracing_disable() instead of "disabled" field for ftrace_dump_one() References: <20250505212104.986494754@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The per CPU "disabled" value was the original way to disable tracing when the tracing subsystem was first created. Today, the ring buffer infrastructure has its own way to disable tracing. In fact, things have changed so much since 2008 that many things ignore the disable flag. The ftrace_dump_one() function iterates over all the current tracing CPUs a= nd increments the "disabled" counter before doing the dump, and decrements it afterward. As the disabled flag can be ignored, doing this today is not reliable. Instead use the new tracer_tracing_disable() that calls into the ring buffer code to do the disabling. Signed-off-by: Steven Rostedt (Google) --- Changes since v1: https://lore.kernel.org/20250502205348.131916206@goodmis.= org - Use tracer_tracing_disable() instead of tracer_tracing_on() kernel/trace/trace.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index e36b1244fa82..490c24271a3d 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -10481,7 +10481,7 @@ static void ftrace_dump_one(struct trace_array *tr,= enum ftrace_dump_mode dump_m static struct trace_iterator iter; unsigned int old_userobj; unsigned long flags; - int cnt =3D 0, cpu; + int cnt =3D 0; =20 /* * Always turn off tracing when we dump. @@ -10498,9 +10498,8 @@ static void ftrace_dump_one(struct trace_array *tr,= enum ftrace_dump_mode dump_m /* Simulate the iterator */ trace_init_iter(&iter, tr); =20 - for_each_tracing_cpu(cpu) { - atomic_inc(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled); - } + /* While dumping, do not allow the buffer to be enable */ + tracer_tracing_disable(tr); =20 old_userobj =3D tr->trace_flags & TRACE_ITER_SYM_USEROBJ; =20 @@ -10559,9 +10558,7 @@ static void ftrace_dump_one(struct trace_array *tr,= enum ftrace_dump_mode dump_m =20 tr->trace_flags |=3D old_userobj; =20 - for_each_tracing_cpu(cpu) { - atomic_dec(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled); - } + tracer_tracing_enable(tr); local_irq_restore(flags); } =20 --=20 2.47.2 From nobody Tue Dec 16 07:27:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3EEE27465A; Mon, 5 May 2025 21:22:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480148; cv=none; b=Fe1XEmxQ8F7wNGJtpXhTqBEp0CB0S7SUE/DFcefMdnrK6a5YAPOAf5KZlVaaXafqYvqYlU/kKsQCPfKvbtFqwO9MAI1tfnXvF0spLIvJ+pPQ6nexMbg7HTWygDzNpX5uZPqkxl544xfy+VNIBkllK3PSVT/X5QcPis8ICWEirBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480148; c=relaxed/simple; bh=e2yzUrlsAIvxL3H3QyPwr4CTnM9tzN8vsHBbBq12A7c=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=RaMWZwMmu3omfZd6UEwoRnyh2/82vBR0EQMWiSVd4yNGxWcIpZCFGgw05QWrQcq8j2CVAF+B+/UgsdZKK5EXXPMmtKDEBUL2fDx9Ojx9L6By9d2ebPzdoQzS/1YF/8eYLOHvAW+bLMjLVAdytCDBSQhpJcKmq+4bANUE0Cfdl0A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9795C4CEF1; Mon, 5 May 2025 21:22:28 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uC3Gl-00000000yDj-2uat; Mon, 05 May 2025 17:22:35 -0400 Message-ID: <20250505212235.549033722@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 05 May 2025 17:21:10 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Jason Wessel , Daniel Thompson , Douglas Anderson Subject: [PATCH v2 06/13] tracing: kdb: Use tracer_tracing_on/off() instead of setting per CPU disabled References: <20250505212104.986494754@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The per CPU "disabled" value was the original way to disable tracing when the tracing subsystem was first created. Today, the ring buffer infrastructure has its own way to disable tracing. In fact, things have changed so much since 2008 that many things ignore the disable flag. The kdb_ftdump() function iterates over all the current tracing CPUs and increments the "disabled" counter before doing the dump, and decrements it afterward. As the disabled flag can be ignored, doing this today is not reliable. Instead, simply call tracer_tracing_off() and then tracer_tracing_on() to disable and then enabled the entire ring buffer in one go! Cc: Jason Wessel Cc: Daniel Thompson Cc: Douglas Anderson Signed-off-by: Steven Rostedt (Google) --- Changes since v2: https://lore.kernel.org/20250502205348.643055437@goodmis.= org - Fixed unused "int cpu;" (kernel test robot) - Use the new tracer_tracing_disable() instead of tracer_tracing_off() (Doug Anderson) kernel/trace/trace_kdb.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/kernel/trace/trace_kdb.c b/kernel/trace/trace_kdb.c index 1e72d20b3c2f..d7b135de958a 100644 --- a/kernel/trace/trace_kdb.c +++ b/kernel/trace/trace_kdb.c @@ -98,7 +98,6 @@ static int kdb_ftdump(int argc, const char **argv) long cpu_file; int err; int cnt; - int cpu; =20 if (argc > 2) return KDB_ARGCOUNT; @@ -120,9 +119,7 @@ static int kdb_ftdump(int argc, const char **argv) trace_init_global_iter(&iter); iter.buffer_iter =3D buffer_iter; =20 - for_each_tracing_cpu(cpu) { - atomic_inc(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled); - } + tracer_tracing_disable(iter.tr); =20 /* A negative skip_entries means skip all but the last entries */ if (skip_entries < 0) { @@ -135,9 +132,7 @@ static int kdb_ftdump(int argc, const char **argv) =20 ftrace_dump_buf(skip_entries, cpu_file); =20 - for_each_tracing_cpu(cpu) { - atomic_dec(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled); - } + tracer_tracing_enable(iter.tr); =20 kdb_trap_printk--; =20 --=20 2.47.2 From nobody Tue Dec 16 07:27:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 100C827467B; Mon, 5 May 2025 21:22:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480149; cv=none; b=QbnXm2rowJBVVX/UIdCvA9YVF5FX/AHLLFT2Z15Xh49BWVxoBKTJyKXXzvfNxI+jLGR9mqunQwUtJeg6YojHFIP2cvqVE74/jlMbtdy7toyGYbw/3NyYPCoZago1trMT26gwarYNf2axfEuAEot+/1BxDrp8GHIyHIFVqGehHMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480149; c=relaxed/simple; bh=PD0PEZGjhOGV9Ehhf7jbkf7/uE2maQPnTBmxaJdraT4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=eteq1++QNWFFBiKg3P44GYTGxjCZU3+s0Ig5+pFY++G1WHXgswKD4hMKTbHrA/WXtDjqcj9X+ilKEnK3WYhs6Sw4Iru09LCA7MPj32uwwhUiwWUOXOX2QJF/ESaycX/i9Jl3UaTzOKJ+We8rdmID6ea0TPBTqILX5fuFmYtW0Vw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB4A0C4AF09; Mon, 5 May 2025 21:22:28 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uC3Gl-00000000yEE-3cXe; Mon, 05 May 2025 17:22:35 -0400 Message-ID: <20250505212235.715752008@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 05 May 2025 17:21:11 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH v2 07/13] ftrace: Do not disabled function graph based on "disabled" field References: <20250505212104.986494754@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The per CPU "disabled" value was the original way to disable tracing when the tracing subsystem was first created. Today, the ring buffer infrastructure has its own way to disable tracing. In fact, things have changed so much since 2008 that many things ignore the disable flag. Do not bother disabling the function graph tracer if the per CPU disabled field is set. Just record as normal. If tracing is disabled in the ring buffer it will not be recorded. Also, when tracing is enabled again, it will not drop the return call of the function. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_functions_graph.c | 38 +++++++--------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_func= tions_graph.c index 0c357a89c58e..9234e2c39abf 100644 --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c @@ -202,12 +202,9 @@ static int graph_entry(struct ftrace_graph_ent *trace, { unsigned long *task_var =3D fgraph_get_task_var(gops); struct trace_array *tr =3D gops->private; - struct trace_array_cpu *data; struct fgraph_times *ftimes; unsigned int trace_ctx; - long disabled; int ret =3D 0; - int cpu; =20 if (*task_var & TRACE_GRAPH_NOTRACE) return 0; @@ -257,21 +254,14 @@ static int graph_entry(struct ftrace_graph_ent *trace, if (tracing_thresh) return 1; =20 - preempt_disable_notrace(); - cpu =3D raw_smp_processor_id(); - data =3D per_cpu_ptr(tr->array_buffer.data, cpu); - disabled =3D atomic_read(&data->disabled); - if (likely(!disabled)) { - trace_ctx =3D tracing_gen_ctx(); - if (IS_ENABLED(CONFIG_FUNCTION_GRAPH_RETADDR) && - tracer_flags_is_set(TRACE_GRAPH_PRINT_RETADDR)) { - unsigned long retaddr =3D ftrace_graph_top_ret_addr(current); - ret =3D __trace_graph_retaddr_entry(tr, trace, trace_ctx, retaddr); - } else { - ret =3D __graph_entry(tr, trace, trace_ctx, fregs); - } + trace_ctx =3D tracing_gen_ctx(); + if (IS_ENABLED(CONFIG_FUNCTION_GRAPH_RETADDR) && + tracer_flags_is_set(TRACE_GRAPH_PRINT_RETADDR)) { + unsigned long retaddr =3D ftrace_graph_top_ret_addr(current); + ret =3D __trace_graph_retaddr_entry(tr, trace, trace_ctx, retaddr); + } else { + ret =3D __graph_entry(tr, trace, trace_ctx, fregs); } - preempt_enable_notrace(); =20 return ret; } @@ -351,13 +341,10 @@ void trace_graph_return(struct ftrace_graph_ret *trac= e, { unsigned long *task_var =3D fgraph_get_task_var(gops); struct trace_array *tr =3D gops->private; - struct trace_array_cpu *data; struct fgraph_times *ftimes; unsigned int trace_ctx; u64 calltime, rettime; - long disabled; int size; - int cpu; =20 rettime =3D trace_clock_local(); =20 @@ -376,15 +363,8 @@ void trace_graph_return(struct ftrace_graph_ret *trace, =20 calltime =3D ftimes->calltime; =20 - preempt_disable_notrace(); - cpu =3D raw_smp_processor_id(); - data =3D per_cpu_ptr(tr->array_buffer.data, cpu); - disabled =3D atomic_read(&data->disabled); - if (likely(!disabled)) { - trace_ctx =3D tracing_gen_ctx(); - __trace_graph_return(tr, trace, trace_ctx, calltime, rettime); - } - preempt_enable_notrace(); + trace_ctx =3D tracing_gen_ctx(); + __trace_graph_return(tr, trace, trace_ctx, calltime, rettime); } =20 static void trace_graph_thresh_return(struct ftrace_graph_ret *trace, --=20 2.47.2 From nobody Tue Dec 16 07:27:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 370292749F0; Mon, 5 May 2025 21:22:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480149; cv=none; b=qHiWWl0+qh0Tr3Kom/hGChlLbPCO5KEsIFTkeg/7sUyMwqmW8yOoXu3DHpnRgTcmcVaXTkJdmnncuTJpAH9M7bSLH9ZXaScueRDykD2q/47sEcVjKOHklfTM2Er0XAteWLuK1UKG1o0G7eOWefHrR4wfiW49Sc/d/Rhd1DueJRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480149; c=relaxed/simple; bh=G1pGPlHq1Jc2R/Q7ktIrkeXiE9v4GRByBNqYLb9M9uM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=YK9cmIyHNgzu5F+EXcEao6kN9n0fzlXp5HqcO+NJllkDcX+GYFPG/JVKfu8eD1MdDjSbTs928etkacUOrG8jIKifQ6VJmbNqX+52l7alf9mS4e3kzp+JBkGNVsCiBIpU4BVYhRtZqr1r4wCvtaqiLl+RKg0fmLWozCRf5nPObXU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E7FEC4CEF1; Mon, 5 May 2025 21:22:29 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uC3Gm-00000000yEj-09d5; Mon, 05 May 2025 17:22:36 -0400 Message-ID: <20250505212235.885452497@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 05 May 2025 17:21:12 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH v2 08/13] tracing: Do not use per CPU array_buffer.data->disabled for cpumask References: <20250505212104.986494754@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The per CPU "disabled" value was the original way to disable tracing when the tracing subsystem was first created. Today, the ring buffer infrastructure has its own way to disable tracing. In fact, things have changed so much since 2008 that many things ignore the disable flag. Do not bother setting the per CPU disabled flag of the array_buffer data to use to determine what CPUs can write to the buffer and only rely on the ring buffer code itself to disabled it. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 490c24271a3d..395d1229da77 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -5081,7 +5081,6 @@ int tracing_set_cpumask(struct trace_array *tr, */ if (cpumask_test_cpu(cpu, tr->tracing_cpumask) && !cpumask_test_cpu(cpu, tracing_cpumask_new)) { - atomic_inc(&per_cpu_ptr(tr->array_buffer.data, cpu)->disabled); ring_buffer_record_disable_cpu(tr->array_buffer.buffer, cpu); #ifdef CONFIG_TRACER_MAX_TRACE ring_buffer_record_disable_cpu(tr->max_buffer.buffer, cpu); @@ -5089,7 +5088,6 @@ int tracing_set_cpumask(struct trace_array *tr, } if (!cpumask_test_cpu(cpu, tr->tracing_cpumask) && cpumask_test_cpu(cpu, tracing_cpumask_new)) { - atomic_dec(&per_cpu_ptr(tr->array_buffer.data, cpu)->disabled); ring_buffer_record_enable_cpu(tr->array_buffer.buffer, cpu); #ifdef CONFIG_TRACER_MAX_TRACE ring_buffer_record_enable_cpu(tr->max_buffer.buffer, cpu); --=20 2.47.2 From nobody Tue Dec 16 07:27:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9B6A27510B; Mon, 5 May 2025 21:22:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480149; cv=none; b=lKOSHQbpBmF9BSzr+BdwDqN281WGl8szNhWqzDEnPnCeCNI364xMqioJZxVq6O8pl750QPXZj1AO8K6EYpuyb2xgreQLriqQNvBDgg9r3jhsmQU9NAOqL6yd9+xdQfSP8CPEC8pAAbFNczxoC36MjFKQyUALScO2lpI+RM741wc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480149; c=relaxed/simple; bh=3SGqRucYvzm4r1ZRppD5xh4448hzq4HUOiq6525cB54=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=B3YYkLUNy9aRxMpTlDZUNjEJt9bsadMRXrxRaMloYkxaRXvAoS8Bg+WLDrmjrfQ4Sm1YMhLtqGvgfxCpV3kFflMhcjUPfyhdu4Z47YKdYLyS/Ucp5YGPLBSA+ZRiHfCje0CLRlSFtJfmW/w5rj4yAp7ei3pSgRqR6++ws1rP25w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FFD8C4CEF1; Mon, 5 May 2025 21:22:29 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uC3Gm-00000000yFE-0r8E; Mon, 05 May 2025 17:22:36 -0400 Message-ID: <20250505212236.059853898@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 05 May 2025 17:21:13 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH v2 09/13] ring-buffer: Add ring_buffer_record_is_on_cpu() References: <20250505212104.986494754@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt Add the function ring_buffer_record_is_on_cpu() that returns true if the ring buffer for a give CPU is writable and false otherwise. Also add tracer_tracing_is_on_cpu() to return if the ring buffer for a given CPU is writeable for a given trace_array. Signed-off-by: Steven Rostedt (Google) --- include/linux/ring_buffer.h | 1 + kernel/trace/ring_buffer.c | 18 ++++++++++++++++++ kernel/trace/trace.h | 15 +++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h index 56e27263acf8..cd7f0ae26615 100644 --- a/include/linux/ring_buffer.h +++ b/include/linux/ring_buffer.h @@ -192,6 +192,7 @@ void ring_buffer_record_off(struct trace_buffer *buffer= ); void ring_buffer_record_on(struct trace_buffer *buffer); bool ring_buffer_record_is_on(struct trace_buffer *buffer); bool ring_buffer_record_is_set_on(struct trace_buffer *buffer); +bool ring_buffer_record_is_on_cpu(struct trace_buffer *buffer, int cpu); void ring_buffer_record_disable_cpu(struct trace_buffer *buffer, int cpu); void ring_buffer_record_enable_cpu(struct trace_buffer *buffer, int cpu); =20 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index c0f877d39a24..1ca482955dae 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -4882,6 +4882,24 @@ bool ring_buffer_record_is_set_on(struct trace_buffe= r *buffer) return !(atomic_read(&buffer->record_disabled) & RB_BUFFER_OFF); } =20 +/** + * ring_buffer_record_is_on_cpu - return true if the ring buffer can write + * @buffer: The ring buffer to see if write is enabled + * @cpu: The CPU to test if the ring buffer can write too + * + * Returns true if the ring buffer is in a state that it accepts writes + * for a particular CPU. + */ +bool ring_buffer_record_is_on_cpu(struct trace_buffer *buffer, int cpu) +{ + struct ring_buffer_per_cpu *cpu_buffer; + + cpu_buffer =3D buffer->buffers[cpu]; + + return ring_buffer_record_is_set_on(buffer) && + !atomic_read(&cpu_buffer->record_disabled); +} + /** * ring_buffer_record_disable_cpu - stop all writes into the cpu_buffer * @buffer: The ring buffer to stop writes to. diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 74f1fe5788d4..69c1ecfb2290 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -673,6 +673,21 @@ struct dentry *trace_create_file(const char *name, void *data, const struct file_operations *fops); =20 + +/** + * tracer_tracing_is_on_cpu - show real state of ring buffer enabled on fo= r a cpu + * @tr : the trace array to know if ring buffer is enabled + * @cpu: The cpu buffer to check if enabled + * + * Shows real state of the per CPU buffer if it is enabled or not. + */ +static inline bool tracer_tracing_is_on_cpu(struct trace_array *tr, int cp= u) +{ + if (tr->array_buffer.buffer) + return ring_buffer_record_is_on_cpu(tr->array_buffer.buffer, cpu); + return false; +} + int tracing_init_dentry(void); =20 struct ring_buffer_event; --=20 2.47.2 From nobody Tue Dec 16 07:27:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05F3B27587D; Mon, 5 May 2025 21:22:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480150; cv=none; b=n5k5ndbiEgS4qBSaCn186JbRhPmBQ3tdmFIYVzYd4PEAA7325KkWdek8vL6OqaC+nlsqaTwY1KKp3Tmub8bFNXEsqpgs8vmVXsVLuaVvJJ5GwNFrnizxbxJXjhYMiA90OACJ17qh0q5nu5jkOzKIZIHclD16wgL0HlWsYGz1FsA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480150; c=relaxed/simple; bh=kDDwdzFGDecCKLKcAFTEIhC27hC7gy2Pe7+JNQFKbjg=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=ghdzIXHKtpdeTBk9VGyZe30kriih++/AA4RkbBZcyp7TUZWynoe60eTA1ZEU20b9/N8827u/6BphJWatSndspHt7Qvjs+AJtILzoJbSVWE4pw54ccJhmrbKwXONzKXAzsqpsW0LhNm6pNQHimpoiPUYCRdgMHUZckREBq38c4E4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8548CC4CEE4; Mon, 5 May 2025 21:22:29 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uC3Gm-00000000yFk-1ZKj; Mon, 05 May 2025 17:22:36 -0400 Message-ID: <20250505212236.224658526@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 05 May 2025 17:21:14 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH v2 10/13] tracing: branch: Use trace_tracing_is_on_cpu() instead of "disabled" field References: <20250505212104.986494754@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The branch tracer currently checks the per CPU "disabled" field to know if tracing is enabled or not for the CPU. As the "disabled" value is not used anymore to turn of tracing generically, use tracing_tracer_is_on_cpu() instead. Signed-off-by: Steven Rostedt (Google) --- Changes since v1: https://lore.kernel.org/20250502205349.299144667@goodmis.= org - Fixed "raw_smp_process_id()" to "raw_smp_processor_id()" (kernel test robot) kernel/trace/trace_branch.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kernel/trace/trace_branch.c b/kernel/trace/trace_branch.c index 6d08a5523ce0..6809b370e991 100644 --- a/kernel/trace/trace_branch.c +++ b/kernel/trace/trace_branch.c @@ -32,7 +32,6 @@ probe_likely_condition(struct ftrace_likely_data *f, int = val, int expect) { struct trace_array *tr =3D branch_tracer; struct trace_buffer *buffer; - struct trace_array_cpu *data; struct ring_buffer_event *event; struct trace_branch *entry; unsigned long flags; @@ -54,8 +53,7 @@ probe_likely_condition(struct ftrace_likely_data *f, int = val, int expect) =20 raw_local_irq_save(flags); current->trace_recursion |=3D TRACE_BRANCH_BIT; - data =3D this_cpu_ptr(tr->array_buffer.data); - if (atomic_read(&data->disabled)) + if (!tracer_tracing_is_on_cpu(tr, raw_smp_processor_id())) goto out; =20 trace_ctx =3D tracing_gen_ctx_flags(flags); --=20 2.47.2 From nobody Tue Dec 16 07:27:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 430AE277026; Mon, 5 May 2025 21:22:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480150; cv=none; b=rxGicBq7D+wVCvUEOd2tkcB24g/0Vc7A6TClbb9OM/bNEDSErDCFTTnnIcH/3pVjTiM+DMEXSYs6I0bFULl8L3wvTeFUFepsW/n7tRhfQ/wt7gnUY7cxPy9H0riKlQ3lWj1JPkMLnNRIXBfHrHQ4zsybYDTpLB0/7eNTP3qlbF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480150; c=relaxed/simple; bh=oUrVdDvwvG6+mSyGGQx/AYyGQ5s9g9qRhH4UvipaHpo=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=lC8flxdMpkSn+6N24Inuq3ji1FNlI1/htdx8SYBmgaspNd9TWrzQLz86zI+qXqU81zNTcIH7k7MccXGu/WEni78FhbPmcPF4el1CKWc8opbTAFIyapnKkEZ9Xi6BjnLORlJTSlK6XWQS0phrf4cyQ+I11gu8WSQkGx3nl6iiFps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3157C4CEF8; Mon, 5 May 2025 21:22:29 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uC3Gm-00000000yGE-2I73; Mon, 05 May 2025 17:22:36 -0400 Message-ID: <20250505212236.394925376@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 05 May 2025 17:21:15 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH v2 11/13] tracing: Convert the per CPU "disabled" counter to local from atomic References: <20250505212104.986494754@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The per CPU "disabled" counter is used for the latency tracers and stack tracers to make sure that their accounting isn't messed up by an NMI or interrupt coming in and affecting the same CPU data. But the counter is an atomic_t type. As it only needs to synchronize against the current CPU, switch it over to local_t type. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.h | 2 +- kernel/trace/trace_functions.c | 8 ++++---- kernel/trace/trace_irqsoff.c | 22 +++++++++++----------- kernel/trace/trace_sched_wakeup.c | 18 +++++++++--------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 69c1ecfb2290..188032d4ab69 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -183,7 +183,7 @@ struct trace_array; * the trace, etc.) */ struct trace_array_cpu { - atomic_t disabled; + local_t disabled; void *buffer_page; /* ring buffer spare */ =20 unsigned long entries; diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c index bd153219a712..99a90f182485 100644 --- a/kernel/trace/trace_functions.c +++ b/kernel/trace/trace_functions.c @@ -291,7 +291,7 @@ function_stack_trace_call(unsigned long ip, unsigned lo= ng parent_ip, parent_ip =3D function_get_true_parent_ip(parent_ip, fregs); cpu =3D raw_smp_processor_id(); data =3D per_cpu_ptr(tr->array_buffer.data, cpu); - disabled =3D atomic_inc_return(&data->disabled); + disabled =3D local_inc_return(&data->disabled); =20 if (likely(disabled =3D=3D 1)) { trace_ctx =3D tracing_gen_ctx_flags(flags); @@ -303,7 +303,7 @@ function_stack_trace_call(unsigned long ip, unsigned lo= ng parent_ip, __trace_stack(tr, trace_ctx, skip); } =20 - atomic_dec(&data->disabled); + local_dec(&data->disabled); local_irq_restore(flags); } =20 @@ -402,7 +402,7 @@ function_stack_no_repeats_trace_call(unsigned long ip, = unsigned long parent_ip, parent_ip =3D function_get_true_parent_ip(parent_ip, fregs); cpu =3D raw_smp_processor_id(); data =3D per_cpu_ptr(tr->array_buffer.data, cpu); - disabled =3D atomic_inc_return(&data->disabled); + disabled =3D local_inc_return(&data->disabled); =20 if (likely(disabled =3D=3D 1)) { last_info =3D per_cpu_ptr(tr->last_func_repeats, cpu); @@ -417,7 +417,7 @@ function_stack_no_repeats_trace_call(unsigned long ip, = unsigned long parent_ip, } =20 out: - atomic_dec(&data->disabled); + local_dec(&data->disabled); local_irq_restore(flags); } =20 diff --git a/kernel/trace/trace_irqsoff.c b/kernel/trace/trace_irqsoff.c index 40c39e946940..0b6d932a931e 100644 --- a/kernel/trace/trace_irqsoff.c +++ b/kernel/trace/trace_irqsoff.c @@ -123,12 +123,12 @@ static int func_prolog_dec(struct trace_array *tr, return 0; =20 *data =3D per_cpu_ptr(tr->array_buffer.data, cpu); - disabled =3D atomic_inc_return(&(*data)->disabled); + disabled =3D local_inc_return(&(*data)->disabled); =20 if (likely(disabled =3D=3D 1)) return 1; =20 - atomic_dec(&(*data)->disabled); + local_dec(&(*data)->disabled); =20 return 0; } @@ -152,7 +152,7 @@ irqsoff_tracer_call(unsigned long ip, unsigned long par= ent_ip, =20 trace_function(tr, ip, parent_ip, trace_ctx, fregs); =20 - atomic_dec(&data->disabled); + local_dec(&data->disabled); } #endif /* CONFIG_FUNCTION_TRACER */ =20 @@ -209,7 +209,7 @@ static int irqsoff_graph_entry(struct ftrace_graph_ent = *trace, =20 trace_ctx =3D tracing_gen_ctx_flags(flags); ret =3D __trace_graph_entry(tr, trace, trace_ctx); - atomic_dec(&data->disabled); + local_dec(&data->disabled); =20 return ret; } @@ -238,7 +238,7 @@ static void irqsoff_graph_return(struct ftrace_graph_re= t *trace, =20 trace_ctx =3D tracing_gen_ctx_flags(flags); __trace_graph_return(tr, trace, trace_ctx, *calltime, rettime); - atomic_dec(&data->disabled); + local_dec(&data->disabled); } =20 static struct fgraph_ops fgraph_ops =3D { @@ -408,10 +408,10 @@ start_critical_timing(unsigned long ip, unsigned long= parent_ip) =20 data =3D per_cpu_ptr(tr->array_buffer.data, cpu); =20 - if (unlikely(!data) || atomic_read(&data->disabled)) + if (unlikely(!data) || local_read(&data->disabled)) return; =20 - atomic_inc(&data->disabled); + local_inc(&data->disabled); =20 data->critical_sequence =3D max_sequence; data->preempt_timestamp =3D ftrace_now(cpu); @@ -421,7 +421,7 @@ start_critical_timing(unsigned long ip, unsigned long p= arent_ip) =20 per_cpu(tracing_cpu, cpu) =3D 1; =20 - atomic_dec(&data->disabled); + local_dec(&data->disabled); } =20 static nokprobe_inline void @@ -445,16 +445,16 @@ stop_critical_timing(unsigned long ip, unsigned long = parent_ip) data =3D per_cpu_ptr(tr->array_buffer.data, cpu); =20 if (unlikely(!data) || - !data->critical_start || atomic_read(&data->disabled)) + !data->critical_start || local_read(&data->disabled)) return; =20 - atomic_inc(&data->disabled); + local_inc(&data->disabled); =20 trace_ctx =3D tracing_gen_ctx(); __trace_function(tr, ip, parent_ip, trace_ctx); check_critical_timing(tr, data, parent_ip ? : ip, cpu); data->critical_start =3D 0; - atomic_dec(&data->disabled); + local_dec(&data->disabled); } =20 /* start and stop critical timings used to for stoppage (in idle) */ diff --git a/kernel/trace/trace_sched_wakeup.c b/kernel/trace/trace_sched_w= akeup.c index a0db3404f7f7..bf1cb80742ae 100644 --- a/kernel/trace/trace_sched_wakeup.c +++ b/kernel/trace/trace_sched_wakeup.c @@ -83,14 +83,14 @@ func_prolog_preempt_disable(struct trace_array *tr, goto out_enable; =20 *data =3D per_cpu_ptr(tr->array_buffer.data, cpu); - disabled =3D atomic_inc_return(&(*data)->disabled); + disabled =3D local_inc_return(&(*data)->disabled); if (unlikely(disabled !=3D 1)) goto out; =20 return 1; =20 out: - atomic_dec(&(*data)->disabled); + local_dec(&(*data)->disabled); =20 out_enable: preempt_enable_notrace(); @@ -144,7 +144,7 @@ static int wakeup_graph_entry(struct ftrace_graph_ent *= trace, *calltime =3D trace_clock_local(); =20 ret =3D __trace_graph_entry(tr, trace, trace_ctx); - atomic_dec(&data->disabled); + local_dec(&data->disabled); preempt_enable_notrace(); =20 return ret; @@ -173,7 +173,7 @@ static void wakeup_graph_return(struct ftrace_graph_ret= *trace, return; =20 __trace_graph_return(tr, trace, trace_ctx, *calltime, rettime); - atomic_dec(&data->disabled); + local_dec(&data->disabled); =20 preempt_enable_notrace(); return; @@ -243,7 +243,7 @@ wakeup_tracer_call(unsigned long ip, unsigned long pare= nt_ip, trace_function(tr, ip, parent_ip, trace_ctx, fregs); local_irq_restore(flags); =20 - atomic_dec(&data->disabled); + local_dec(&data->disabled); preempt_enable_notrace(); } =20 @@ -471,7 +471,7 @@ probe_wakeup_sched_switch(void *ignore, bool preempt, =20 /* disable local data, not wakeup_cpu data */ cpu =3D raw_smp_processor_id(); - disabled =3D atomic_inc_return(&per_cpu_ptr(wakeup_trace->array_buffer.da= ta, cpu)->disabled); + disabled =3D local_inc_return(&per_cpu_ptr(wakeup_trace->array_buffer.dat= a, cpu)->disabled); if (likely(disabled !=3D 1)) goto out; =20 @@ -508,7 +508,7 @@ probe_wakeup_sched_switch(void *ignore, bool preempt, arch_spin_unlock(&wakeup_lock); local_irq_restore(flags); out: - atomic_dec(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled); + local_dec(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled); } =20 static void __wakeup_reset(struct trace_array *tr) @@ -563,7 +563,7 @@ probe_wakeup(void *ignore, struct task_struct *p) (!dl_task(p) && (p->prio >=3D wakeup_prio || p->prio >=3D current->pr= io))) return; =20 - disabled =3D atomic_inc_return(&per_cpu_ptr(wakeup_trace->array_buffer.da= ta, cpu)->disabled); + disabled =3D local_inc_return(&per_cpu_ptr(wakeup_trace->array_buffer.dat= a, cpu)->disabled); if (unlikely(disabled !=3D 1)) goto out; =20 @@ -610,7 +610,7 @@ probe_wakeup(void *ignore, struct task_struct *p) out_locked: arch_spin_unlock(&wakeup_lock); out: - atomic_dec(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled); + local_dec(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled); } =20 static void start_wakeup_tracer(struct trace_array *tr) --=20 2.47.2 From nobody Tue Dec 16 07:27:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7283275868; Mon, 5 May 2025 21:22:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480150; cv=none; b=Rbj7xJ4Cm5rJDYiMcqtwix8tbDZvyj9IFxaAWrlsnIax9Zfq/KS4jF+Z2Wk5CQquTGZ6RxoG1aABJsyxfdtRSvNG1qXC9Ll7/qMLt7Bg/3LbyiT01XGjS6OzGo1vXY3eFKdTcXOCZcYbiL19TYyDOsJMH/JA6ThQncNIjcNTnoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480150; c=relaxed/simple; bh=LfbYZrkrwSHhr03nwF7TAzWMZMSOM7lGFrPKQJo3J/Y=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=VNykoLMHSCmuvjPHvsE+7cQ6KbeKEHVPD3lb0+yKKkT3Mk6ohsPQ7urP0hpxt6CHq3qxhiANq9ivQyCarJbtaO4kMsp4dC+B8pzufohw8ni8kNr2VIzxgGLmMMTHNK6qYje9mtGNFfqCY1QNxdmbw2Iyy/7cYVz40FdLeIjA8s4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1C3AC4CEEE; Mon, 5 May 2025 21:22:29 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uC3Gm-00000000yGk-2zaX; Mon, 05 May 2025 17:22:36 -0400 Message-ID: <20250505212236.567884756@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 05 May 2025 17:21:16 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH v2 12/13] tracing: Use atomic_inc_return() for updating "disabled" counter in irqsoff tracer References: <20250505212104.986494754@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The irqsoff tracer uses the per CPU "disabled" field to prevent corruption of the accounting when it starts to trace interrupts disabled, but there's a slight race that could happen if for some reason it was called twice. Use atomic_inc_return() instead. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_irqsoff.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/kernel/trace/trace_irqsoff.c b/kernel/trace/trace_irqsoff.c index 0b6d932a931e..5496758b6c76 100644 --- a/kernel/trace/trace_irqsoff.c +++ b/kernel/trace/trace_irqsoff.c @@ -397,6 +397,7 @@ start_critical_timing(unsigned long ip, unsigned long p= arent_ip) int cpu; struct trace_array *tr =3D irqsoff_trace; struct trace_array_cpu *data; + long disabled; =20 if (!tracer_enabled || !tracing_is_enabled()) return; @@ -411,15 +412,17 @@ start_critical_timing(unsigned long ip, unsigned long= parent_ip) if (unlikely(!data) || local_read(&data->disabled)) return; =20 - local_inc(&data->disabled); + disabled =3D local_inc_return(&data->disabled); =20 - data->critical_sequence =3D max_sequence; - data->preempt_timestamp =3D ftrace_now(cpu); - data->critical_start =3D parent_ip ? : ip; + if (disabled =3D=3D 1) { + data->critical_sequence =3D max_sequence; + data->preempt_timestamp =3D ftrace_now(cpu); + data->critical_start =3D parent_ip ? : ip; =20 - __trace_function(tr, ip, parent_ip, tracing_gen_ctx()); + __trace_function(tr, ip, parent_ip, tracing_gen_ctx()); =20 - per_cpu(tracing_cpu, cpu) =3D 1; + per_cpu(tracing_cpu, cpu) =3D 1; + } =20 local_dec(&data->disabled); } @@ -431,6 +434,7 @@ stop_critical_timing(unsigned long ip, unsigned long pa= rent_ip) struct trace_array *tr =3D irqsoff_trace; struct trace_array_cpu *data; unsigned int trace_ctx; + long disabled; =20 cpu =3D raw_smp_processor_id(); /* Always clear the tracing cpu on stopping the trace */ @@ -448,12 +452,15 @@ stop_critical_timing(unsigned long ip, unsigned long = parent_ip) !data->critical_start || local_read(&data->disabled)) return; =20 - local_inc(&data->disabled); + disabled =3D local_inc_return(&data->disabled); + + if (disabled =3D=3D 1) { + trace_ctx =3D tracing_gen_ctx(); + __trace_function(tr, ip, parent_ip, trace_ctx); + check_critical_timing(tr, data, parent_ip ? : ip, cpu); + data->critical_start =3D 0; + } =20 - trace_ctx =3D tracing_gen_ctx(); - __trace_function(tr, ip, parent_ip, trace_ctx); - check_critical_timing(tr, data, parent_ip ? : ip, cpu); - data->critical_start =3D 0; local_dec(&data->disabled); } =20 --=20 2.47.2 From nobody Tue Dec 16 07:27:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13816276046; Mon, 5 May 2025 21:22:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480150; cv=none; b=DRnALTZN6L6xHnnG+mZKkGr0s+8fUMNilKa/8/JMeTWSrWHT0U/db859DSj1oMnoNSwiCCB4gIQWDd0EnjsVIhYQKqW+6M2uqmL9b04dMqWn+jyuTBStf4y8ktb5K7FbXld1oZ52sg9KCHO7dqV9VjloS3UD0sL4Dqw+68WzouY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746480150; c=relaxed/simple; bh=DBxt4t6Rrj4G2JNo0WXoN5xIbZVuiCWQuVMsCr/1jl4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=S+a0VIQFh69dcl8K3HVIGtRebr6jUt+qv3DGKL50HI7KeT4eXAuX57M5YkDqkFXKDQufHiM+1ugh9icOgRU5iLJXV9p+0fhTT0XDwAYA7rEFv7Z3UlvvuiG7r1zdpeqaaKWuDre8hoHYMwHOGwqGqO9d4rU2oFkjWC2KMvLKlY8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3EF4C4CEED; Mon, 5 May 2025 21:22:29 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uC3Gm-00000000yHF-3ipV; Mon, 05 May 2025 17:22:36 -0400 Message-ID: <20250505212236.738849456@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 05 May 2025 17:21:17 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [PATCH v2 13/13] tracing: Remove unused buffer_page field from trace_array_cpu structure References: <20250505212104.986494754@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The trace_array_cpu had a "buffer_page" field that was originally going to be used as a backup page for the ring buffer. But the ring buffer has its own way of reusing pages and this field was never used. Remove it. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.h | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 188032d4ab69..4e67ee92e05c 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -184,7 +184,6 @@ struct trace_array; */ struct trace_array_cpu { local_t disabled; - void *buffer_page; /* ring buffer spare */ =20 unsigned long entries; unsigned long saved_latency; --=20 2.47.2