From patchwork Tue Dec 6 14:18:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 30316 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2856343wrr; Tue, 6 Dec 2022 06:35:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf7T9HYgh10DcjxkX9ZOO7v/2IRly5B0pLdb3pTNnxZVWJQ/wTvRD4S/rOjQyzeOpnFIF+tD X-Received: by 2002:a17:906:b142:b0:7c1:b65:8d0f with SMTP id bt2-20020a170906b14200b007c10b658d0fmr2587586ejb.445.1670337334632; Tue, 06 Dec 2022 06:35:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670337334; cv=none; d=google.com; s=arc-20160816; b=diEHZ4Yy8305Jykiy50iVUTYaATatPJm8CX6AaTY2Zg/BjgZ7RU2uoca0MvysBmT9n dwNeCZtSksmOIxSfKcD+44dl9zwSgApFdgtzCWqpOsE1PjVICeg3jmhSlXgyVpcAJ8wP yYzEVaOdShjmRqUSo27dIgQvDBwe71r0Q/MPhiHrBuaIMCZ8m9El6qVKH/KEOIwXbAWb J3BE96jv2STzFsK3GwXKvs4gcFBtVmSY/WTUZrLJ0yTxnwNJeDsOoNo2s/LuERr1yEvZ M/PXRGmyrFsVwHAf9LRTsYhrgMl/Y7/9RuMVzyoRuB7BiwEV/9yX8xDn1hBIier6Kdq0 IIDA== 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 :user-agent:message-id:date:subject:cc:to:from:dkim-signature; bh=y58kaCfkm9E0cB1QIAO/QK1b3Ijb4bjdpgKkOReoN60=; b=c0hx7x/wSMyPyEEcTCJRfVbXKx+9okmbJmxN3oopzHkmHPItPHUDYE1Xnga57Av29a ibSH95xY404JXTZ/iX1Gp1SmOU7X022O+hlUTqF1Ki5hGESZhbKdHuOEh1ojWTGcDFDq J44zw7+0ZFc5IR6VTumNZHTJuF+whNr53BpEsNScouStIq4iAXZK/0e4KcmgnGhgSQH3 zUjAfaeQguqKl6PF6Sf2+sRGbj72r+qIJNzcKfe/36QnoIb5zFRubCGqd/6aSwbIkGAN RtLiNNJb0AGO7DV3XENWkWebB2c9fdTFLpFr4W74rhikZi9KQNdIJQYcXuCFR8q2CJ+R IyIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YcHLqD7+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f20-20020a170906c09400b0079b9f472d85si12590919ejz.698.2022.12.06.06.35.09; Tue, 06 Dec 2022 06:35:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YcHLqD7+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234345AbiLFOSJ (ORCPT + 99 others); Tue, 6 Dec 2022 09:18:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234184AbiLFOSH (ORCPT ); Tue, 6 Dec 2022 09:18:07 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C73192704; Tue, 6 Dec 2022 06:18:05 -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 5DD606177D; Tue, 6 Dec 2022 14:18:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AACE6C433D7; Tue, 6 Dec 2022 14:18:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670336284; bh=mpgmLtxApFpUSQKdKYFDzG4TOA9FB0+pXAvUDsCjAOA=; h=From:To:Cc:Subject:Date:From; b=YcHLqD7+jwKRKwnxPT8RKOibhc5hz+2bPrImUZ/b559xCjQrfJhk0zUHUbLn6YMeU kGBUHrvnl2b8G3IoQmZq1rMruUUBBmuBeyFY7jjdvAOADvrd90w6gTd1eQf8UwWkaV 2zuODZruSgVilaQ2FecS8yG7jvOQLyHGaA79nIj3ehusaNtMz1BdpnLtyVd0nViPL4 eZUSTsc1+faujcwOjBzqKhdjNbuCfOIYj2J/v0GDUucqA+QJwCjLty70NeJPyVo2+P NMe+L+lmjYUfrlajFt9RkitMnjISl86Xk/lSFTkorT4P9julsBnU8/pdRaf97AFooC Jw38bLv8iMXlg== From: "Masami Hiramatsu (Google)" To: LKML Cc: Linux Trace Kernel , Masami Hiramatsu , Steven Rostedt , David Howells , Daniel Bristot de Oliveira Subject: [PATCH v2] tracing: Fix complicated dependency of CONFIG_TRACER_MAX_TRACE Date: Tue, 6 Dec 2022 23:18:01 +0900 Message-Id: <167033628155.4111793.12185405690820208159.stgit@devnote3> X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751475640630419766?= X-GMAIL-MSGID: =?utf-8?q?1751475640630419766?= From: Masami Hiramatsu (Google) Both CONFIG_OSNOISE_TRACER and CONFIG_HWLAT_TRACER partially enables the CONFIG_TRACER_MAX_TRACE code, but that is complicated and has introduced a bug; It declares tracing_max_lat_fops data structure outside of #ifdefs, but since it is defined only when CONFIG_TRACER_MAX_TRACE=y or CONFIG_HWLAT_TRACER=y, if only CONFIG_OSNOISE_TRACER=y, that declaration comes to a definition(!). To fix this issue, and do not repeat the similar problem, makes CONFIG_OSNOISE_TRACER and CONFIG_HWLAT_TRACER enables the CONFIG_TRACER_MAX_TRACE always. It has there benefits; - Fix the tracing_max_lat_fops bug - Simplify the #ifdefs - CONFIG_TRACER_MAX_TRACE code is fully enabled, or not. Fixes: 424b650f35c7 ("tracing: Fix missing osnoise tracer on max_latency") Cc: stable@vger.kernel.org Reported-by: David Howells Reported-by: kernel test robot Signed-off-by: Masami Hiramatsu (Google) Link: https://lore.kernel.org/all/166992525941.1716618.13740663757583361463.stgit@warthog.procyon.org.uk/ (original thread and v1) Link: https://lore.kernel.org/all/202212052253.VuhZ2ulJ-lkp@intel.com/T/#u (v1 error report) --- Changes in v2: - Fix errors with the combination of CONFIG_TRACER_MAX_TRACE=y and CONFIG_TRACER_SNAPSHOT=n. --- kernel/trace/Kconfig | 2 ++ kernel/trace/trace.c | 23 +++++++++++++---------- kernel/trace/trace.h | 8 +++----- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index e9e95c790b8e..93d724996283 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig @@ -375,6 +375,7 @@ config SCHED_TRACER config HWLAT_TRACER bool "Tracer to detect hardware latencies (like SMIs)" select GENERIC_TRACER + select TRACER_MAX_TRACE help This tracer, when enabled will create one or more kernel threads, depending on what the cpumask file is set to, which each thread @@ -410,6 +411,7 @@ config HWLAT_TRACER config OSNOISE_TRACER bool "OS Noise tracer" select GENERIC_TRACER + select TRACER_MAX_TRACE help In the context of high-performance computing (HPC), the Operating System Noise (osnoise) refers to the interference experienced by an diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 5cfc95a52bc3..459ff8cf768a 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -1421,6 +1421,7 @@ int tracing_snapshot_cond_disable(struct trace_array *tr) return false; } EXPORT_SYMBOL_GPL(tracing_snapshot_cond_disable); +#define free_snapshot(tr) do { } while (0) #endif /* CONFIG_TRACER_SNAPSHOT */ void tracer_tracing_off(struct trace_array *tr) @@ -1692,6 +1693,8 @@ static ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt) } unsigned long __read_mostly tracing_thresh; + +#ifdef CONFIG_TRACER_MAX_TRACE static const struct file_operations tracing_max_lat_fops; #ifdef LATENCY_FS_NOTIFY @@ -1748,18 +1751,14 @@ void latency_fsnotify(struct trace_array *tr) irq_work_queue(&tr->fsnotify_irqwork); } -#elif defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER) \ - || defined(CONFIG_OSNOISE_TRACER) +#else /* !LATENCY_FS_NOTIFY */ #define trace_create_maxlat_file(tr, d_tracer) \ trace_create_file("tracing_max_latency", TRACE_MODE_WRITE, \ d_tracer, &tr->max_latency, &tracing_max_lat_fops) -#else -#define trace_create_maxlat_file(tr, d_tracer) do { } while (0) #endif -#ifdef CONFIG_TRACER_MAX_TRACE /* * Copy the new maximum trace into the separate maximum-trace * structure. (this way the maximum trace is permanently saved, @@ -1834,14 +1833,15 @@ update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu, ring_buffer_record_off(tr->max_buffer.buffer); #ifdef CONFIG_TRACER_SNAPSHOT - if (tr->cond_snapshot && !tr->cond_snapshot->update(tr, cond_data)) - goto out_unlock; + if (tr->cond_snapshot && !tr->cond_snapshot->update(tr, cond_data)) { + arch_spin_unlock(&tr->max_lock); + return; + } #endif swap(tr->array_buffer.buffer, tr->max_buffer.buffer); __update_max_tr(tr, tsk, cpu); - out_unlock: arch_spin_unlock(&tr->max_lock); } @@ -1888,6 +1888,7 @@ update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu) __update_max_tr(tr, tsk, cpu); arch_spin_unlock(&tr->max_lock); } + #endif /* CONFIG_TRACER_MAX_TRACE */ static int wait_on_pipe(struct trace_iterator *iter, int full) @@ -6572,7 +6573,7 @@ tracing_thresh_write(struct file *filp, const char __user *ubuf, return ret; } -#if defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER) +#ifdef CONFIG_TRACER_MAX_TRACE static ssize_t tracing_max_lat_read(struct file *filp, char __user *ubuf, @@ -7587,7 +7588,7 @@ static const struct file_operations tracing_thresh_fops = { .llseek = generic_file_llseek, }; -#if defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER) +#ifdef CONFIG_TRACER_MAX_TRACE static const struct file_operations tracing_max_lat_fops = { .open = tracing_open_generic, .read = tracing_max_lat_read, @@ -9601,7 +9602,9 @@ init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer) create_trace_options_dir(tr); +#ifdef CONFIG_TRACER_MAX_TRACE trace_create_maxlat_file(tr, d_tracer); +#endif if (ftrace_create_function_files(tr, d_tracer)) MEM_FAIL(1, "Could not allocate function filter files"); diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index d42e24507152..8b69698780a1 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -308,8 +308,7 @@ struct trace_array { struct array_buffer max_buffer; bool allocated_snapshot; #endif -#if defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER) \ - || defined(CONFIG_OSNOISE_TRACER) +#ifdef CONFIG_TRACER_MAX_TRACE unsigned long max_latency; #ifdef CONFIG_FSNOTIFY struct dentry *d_max_latency; @@ -688,12 +687,11 @@ void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu, void *cond_data); void update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu); -#endif /* CONFIG_TRACER_MAX_TRACE */ -#if (defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER) \ - || defined(CONFIG_OSNOISE_TRACER)) && defined(CONFIG_FSNOTIFY) +#ifdef CONFIG_FSNOTIFY #define LATENCY_FS_NOTIFY #endif +#endif /* CONFIG_TRACER_MAX_TRACE */ #ifdef LATENCY_FS_NOTIFY void latency_fsnotify(struct trace_array *tr);