Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1743667ybg; Sat, 19 Oct 2019 01:33:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqxaXkcT44aQQT+p7RjRSuiQLGAVq4Ts/1m4J90FOnzpxgRCvXkZQ4JTvKAqU3DVbH+rU/7T X-Received: by 2002:a17:906:5e50:: with SMTP id b16mr12505681eju.156.1571473999341; Sat, 19 Oct 2019 01:33:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571473999; cv=none; d=google.com; s=arc-20160816; b=qB+MBHFIAAetWRQ2KhmHsPnu3iv2q6QYfmSx9e072TsXz9kapZ/x42YuKMVjpoLPKp JI/MtngUBisXhqg00V/FP5d3kPkAPhjB4EC4fCK/Yh7L03nDGfXQFJKM5ypdk17yhMJf /UUvzIOGWGlpj3nLkrIjjlKrJsnlXHW0BBY228MD0Pvx1ezv5NC+RVhf4oPTjynCoMKO jD+bzsgI80uqHewb+hgGKJfPM9zJzi9OIaXDtEfIvv2KEnaQcUtUodkAK6yJdGcZgk1m PNx+Q8ZQfqIJEAT7p5jpQgG4T/emkEgyFQnSETzsvziBTNeI5a5uHOarX2S7kEDAxOKu jlnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=TJDLjD/EIRColwg8HoY5YztYO4bo1iRFSPlFTZN1y8c=; b=LuU40GNUkAasgXH5likym9OgtpeYCFxEO8ViBP3SsA6d4GIkZ4OtCHXMxLoHm/tEpP ETQpRjtKR5yMfedKtrp3E7pjKRqh8jdEaJ0raLYel5qPBMYSC/rW23PuKQ8gUXh/UdiM wFr6VtEtfcbQ8fRWGfHNUmtMQVCowDxb1t7sJGqkVXPZArvHsKTGFHZGeNKcUykKfEqW C/3IkOng09UJQDCcL20b+bMV4amJaiDl+ja8BJfv5efgwblRhMUOABQHQ4uUCOU+/3eE LR7s5sHO+Z63p7F8MH1ix+K9HLkVQH3VbI6MAzx78E6mAiK50Yz+Shx0ZfbJux/3oLhD Og4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=J9sSMfyq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ay2si5190772edb.343.2019.10.19.01.32.56; Sat, 19 Oct 2019 01:33:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=J9sSMfyq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2505128AbfJRPJN (ORCPT + 99 others); Fri, 18 Oct 2019 11:09:13 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:34215 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387953AbfJRPJA (ORCPT ); Fri, 18 Oct 2019 11:09:00 -0400 Received: by mail-wr1-f68.google.com with SMTP id t16so1518536wrr.1 for ; Fri, 18 Oct 2019 08:08:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TJDLjD/EIRColwg8HoY5YztYO4bo1iRFSPlFTZN1y8c=; b=J9sSMfyqN6L7XYW+2AHS26ZzmYWN0l7Gt0B/iwdhtBDefJUf+xHp7nAjSJE+oi0W4J eT/YRvsMfP4Ffpj/6AKmwUxc+tYz5Z3jMu6rKSQLqzyex1slPTaQwcfPDps8hczBiDvN 50nRrx2O8+t1D95T4nmjiHfc/R34X21jA5HUZ9oDXIaRFv7BksfLFZS/mKEHULRVQGC2 Eq3GkvmdVSLqFAQH7X1PMsgpip8oUcto/cudGd8MjKhBkB2Pja7SlSd9V+Sm7oQID2sy TR6WBOXn2PQksuXrfgobYk/gy/PP/AEfLGlEUH27dFLki7WfwS7tHAGH6hUfq6UCUAbz cifw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TJDLjD/EIRColwg8HoY5YztYO4bo1iRFSPlFTZN1y8c=; b=F7bz0FWEuiY5M1lixlRSPOBmZiZtu52VgS+4p01H7sIUobQCD7gt3f7LKKeGuprlAS pGQsz5pe6go7gOEz4s0bo8fcQpTHAvsvVw+BimV1WyhuVrPO7VdvqHZsGkfBvzmWOnsg aS9kkOUslM0e7iWOEqYe4QfPDHheznXrJ78GHAUSaNQANRkIJJ0G0pllC2Ye9cEdR+ph HTJ+fcr6jxudkxzQ598FofF7Y2NWfU6pccigaeKEP2EqwtI69bpOCDc+hj/Lzmll+J47 xRdzYxSx2WNjSj6bTq28AnepPNQB4HTs0XA/ENMXdzzChE82aBSDd+jq8szLUmq3AM3v 5Snw== X-Gm-Message-State: APjAAAUBXPwBBx+90FYLAK667K498edKXuLgmGhmwHJrCAEsM+pB+qtH 3Rx7eBhnpSgych7hmEmkHg== X-Received: by 2002:a5d:408f:: with SMTP id o15mr7490760wrp.139.1571411338672; Fri, 18 Oct 2019 08:08:58 -0700 (PDT) Received: from buster-jangle.bmw-carit.intra ([217.89.178.117]) by smtp.gmail.com with ESMTPSA id z6sm6035074wro.16.2019.10.18.08.08.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2019 08:08:58 -0700 (PDT) From: "Viktor Rosendahl (BMW)" To: Steven Rostedt , Ingo Molnar , linux-kernel@vger.kernel.org Cc: Joel Fernandes , "Viktor Rosendahl (BMW)" Subject: [PATCH v10 4/4] ftrace: Add an option for tracing console latencies Date: Fri, 18 Oct 2019 17:08:52 +0200 Message-Id: <20191018150852.4322-5-viktor.rosendahl@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191018150852.4322-1-viktor.rosendahl@gmail.com> References: <20191018150852.4322-1-viktor.rosendahl@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This new kernel parameter "trace_console_latency" will enable the latency tracers to trace the console latencies. Previously this has always been implicitely disabled. I guess this is because they are considered to be well known and unavoidable. However, for some organizations it may nevertheless be desirable to trace them. Basically, we want to be able to tell that there are latencies in the system under test because someone has incorrectly enabled the serial console. Signed-off-by: Viktor Rosendahl (BMW) --- .../admin-guide/kernel-parameters.txt | 4 +++ include/linux/irqflags.h | 22 +++++++++++++ kernel/printk/printk.c | 6 ++-- kernel/trace/trace_irqsoff.c | 32 +++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index a84a83f8881e..3f96a380c528 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4768,6 +4768,10 @@ trace_buf_size=nn[KMG] [FTRACE] will set tracing buffer size on each cpu. + trace_console_latency=[0|1] + [FTRACE] Trace the console latencies if 1 is given. Do + not trace the latencies if 0 or no parameter is given. + trace_event=[event-list] [FTRACE] Set and start specified trace events in order to facilitate early boot debugging. The event-list is a diff --git a/include/linux/irqflags.h b/include/linux/irqflags.h index 21619c92c377..3de891723331 100644 --- a/include/linux/irqflags.h +++ b/include/linux/irqflags.h @@ -13,6 +13,7 @@ #define _LINUX_TRACE_IRQFLAGS_H #include +#include #include /* Currently trace_softirqs_on/off is used only by lockdep */ @@ -68,9 +69,30 @@ do { \ defined(CONFIG_PREEMPT_TRACER) extern void stop_critical_timings(void); extern void start_critical_timings(void); + extern bool console_tracing_disabled(void); + +# define console_stop_critical_timings(flag) \ + do { \ + typecheck(bool, flag); \ + flag = console_tracing_disabled(); \ + if (flag) \ + stop_critical_timings(); \ + } while (0) + +# define console_start_critical_timings(flag) \ + do { \ + typecheck(bool, flag); \ + if (flag) \ + start_critical_timings(); \ + } while (0) + #else # define stop_critical_timings() do { } while (0) # define start_critical_timings() do { } while (0) +# define console_stop_critical_timings(flag) \ + do { typecheck(bool, flag); } while (0) +# define console_start_critical_timings(flag) \ + do { typecheck(bool, flag); } while (0) #endif /* diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index ca65327a6de8..f27e96273453 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2369,6 +2369,7 @@ void console_unlock(void) static char ext_text[CONSOLE_EXT_LOG_MAX]; static char text[LOG_LINE_MAX + PREFIX_MAX]; unsigned long flags; + bool cflag; bool do_cond_resched, retry; if (console_suspended) { @@ -2469,9 +2470,10 @@ void console_unlock(void) */ console_lock_spinning_enable(); - stop_critical_timings(); /* don't trace print latency */ + /* don't trace print latency if it's disabled */ + console_stop_critical_timings(cflag); call_console_drivers(ext_text, ext_len, text, len); - start_critical_timings(); + console_start_critical_timings(cflag); if (console_lock_spinning_disable_and_check()) { printk_safe_exit_irqrestore(flags); diff --git a/kernel/trace/trace_irqsoff.c b/kernel/trace/trace_irqsoff.c index a745b0cee5d3..84876192cc73 100644 --- a/kernel/trace/trace_irqsoff.c +++ b/kernel/trace/trace_irqsoff.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "trace.h" @@ -456,6 +457,37 @@ void stop_critical_timings(void) EXPORT_SYMBOL_GPL(stop_critical_timings); NOKPROBE_SYMBOL(stop_critical_timings); +static bool no_console_latency __read_mostly = true; + +static int __init trace_console_latency(char *str) +{ + int param; + + get_option(&str, ¶m); + no_console_latency = !(param == 1); + + return 0; +} + +early_param("trace_console_latency", trace_console_latency); + +bool console_tracing_disabled(void) +{ + int pc = preempt_count(); + + /* + * If tracing is disabled, then the question of whether to trace console + * latencies is moot. By always returning false here we save the caller + * the calls to start/stop_critical_timings(). These calls would not do + * anything anyway. + */ + if (!preempt_trace(pc) && !irq_trace()) + return false; + + return no_console_latency; +} +EXPORT_SYMBOL_GPL(console_tracing_disabled); + #ifdef CONFIG_FUNCTION_TRACER static bool function_enabled; -- 2.17.1