Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp142011pxk; Wed, 2 Sep 2020 17:19:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZizeNrpVUEehU3FmgHZjNgFD8No2apfRP3sQRzVH+we73ERIjZtZOAGBXAuZNBs3jjCzz X-Received: by 2002:a17:906:a2d9:: with SMTP id by25mr689335ejb.326.1599092354092; Wed, 02 Sep 2020 17:19:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599092354; cv=none; d=google.com; s=arc-20160816; b=iawW9vUVajC4lgGjMCT/Ose/toJdhtrK7Q8nvoBv1E5+VbgxC6ovLhr5r4FHZpQq5u asKDCvdbwLa2M/GeD7smqpTXycrUR/V/RAn7qrmx1QG1vAzop37sGjAdH4zgIjcTcp3D U1angnwOoPdp99zn8mc6/7GxcgqvGoKGHcSh7MEy93Sb9HSCuBsqmMau6S8ifdF6H48z XvU1/oPTVZ/AKt2sqC8EdyARF9scrIsVAFc8MwtkfEqyR9w2dBPW2ufdf1T7QGPy2rec Y4NKE/9FUWBCxBTdcxyNjtrrH+sfhA47xwiNlI15PpX5cviq/nH8/cloqvksRaErGJ6z ueBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature; bh=TkFuY0ECli/sCKgYmNqUO1n0Jk8nvCqHM1OFgJ1hDxQ=; b=s4HP5FdwHCf8WIwIo309GViztZhbQ45QETDzRn2nCvcz1/GBm1pxpXpZh1Lj1ByENl EUxTCd9rJrcpjuN3suvUmc0uqEG2mACcmZx5vLKRS9TnaaBIS3wjur8CxCP+d5imq3EE TTvmggWmlgVXagaZjSlZ44CSejXBooA7UJfahtaAzYkt2QZDBK6YWlSdWixM+it3lkvQ 1PSetTNgFOhsLFiy+33C5AzzVJ77lIRWF/3Hxv5H2+FehsXDV0pGyFgahP/Ux2vhLshS yX0t/vCgM1IL3I161P437Q09FysEVEkjnmgZiFMF/KNpOT3vgMxZ89os2B/zn2GBS7H5 ECOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=pO7ZUrpQ; 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 b7si605217edz.404.2020.09.02.17.18.51; Wed, 02 Sep 2020 17:19:14 -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; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=pO7ZUrpQ; 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 S1727088AbgICARs (ORCPT + 99 others); Wed, 2 Sep 2020 20:17:48 -0400 Received: from m43-7.mailgun.net ([69.72.43.7]:58089 "EHLO m43-7.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726594AbgICARr (ORCPT ); Wed, 2 Sep 2020 20:17:47 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1599092265; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=TkFuY0ECli/sCKgYmNqUO1n0Jk8nvCqHM1OFgJ1hDxQ=; b=pO7ZUrpQPX8bTuNUEoL/ochhwLhmu655q7zHRQVYnTFfpqJodZD/GHBviVaLnE2gPeU1I1CG JdUkNJCI5sf+hm9+IkqxzpgQ26v0XH5btPruCfuBMLQTtq9Ll1J44Qhtw1e80VMOJWA84WrW p742Tg6Pph8og1dqBVqp7SaBROk= X-Mailgun-Sending-Ip: 69.72.43.7 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n01.prod.us-east-1.postgun.com with SMTP id 5f503622ba408b30ce88b538 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Thu, 03 Sep 2020 00:17:38 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id A6B8CC433AD; Thu, 3 Sep 2020 00:17:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.0 Received: from tingweiz-gv.qualcomm.com (unknown [180.166.53.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: tingwei) by smtp.codeaurora.org (Postfix) with ESMTPSA id 11BA5C433C9; Thu, 3 Sep 2020 00:17:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 11BA5C433C9 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=tingwei@codeaurora.org From: Tingwei Zhang To: Steven Rostedt , Ingo Molnar , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue Cc: Tingwei Zhang , Mathieu Poirier , Suzuki K Poulose , tsoni@codeaurora.org, Sai Prakash Ranjan , Mao Jinlong , linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 2/6] tracing: add flag to control different traces Date: Thu, 3 Sep 2020 08:17:02 +0800 Message-Id: <20200903001706.28147-3-tingwei@codeaurora.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20200903001706.28147-1-tingwei@codeaurora.org> References: <20200903001706.28147-1-tingwei@codeaurora.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org More traces like event trace or trace marker will be supported. Add flag for difference traces, so that they can be controlled separately. Move current function trace to it's own flag instead of global ftrace enable flag. Signed-off-by: Tingwei Zhang Reviewed-by: Steven Rostedt (VMware) --- include/linux/trace.h | 5 +++++ kernel/trace/trace.c | 36 +++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/include/linux/trace.h b/include/linux/trace.h index 7fd86d3c691f..bc93063dda39 100644 --- a/include/linux/trace.h +++ b/include/linux/trace.h @@ -3,6 +3,9 @@ #define _LINUX_TRACE_H #ifdef CONFIG_TRACING + +#define TRACE_EXPORT_FUNCTION BIT(0) + /* * The trace export - an export of Ftrace output. The trace_export * can process traces and export them to a registered destination as @@ -15,10 +18,12 @@ * next - pointer to the next trace_export * write - copy traces which have been delt with ->commit() to * the destination + * flags - which ftrace to be exported */ struct trace_export { struct trace_export __rcu *next; void (*write)(struct trace_export *, const void *, unsigned int); + int flags; }; int register_ftrace_export(struct trace_export *export); diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index bb62269724d5..8f1e66831e9e 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -2747,33 +2747,37 @@ trace_buffer_unlock_commit_nostack(struct trace_buffer *buffer, static void trace_process_export(struct trace_export *export, - struct ring_buffer_event *event) + struct ring_buffer_event *event, int flag) { struct trace_entry *entry; unsigned int size = 0; - entry = ring_buffer_event_data(event); - size = ring_buffer_event_length(event); - export->write(export, entry, size); + if (export->flags & flag) { + entry = ring_buffer_event_data(event); + size = ring_buffer_event_length(event); + export->write(export, entry, size); + } } static DEFINE_MUTEX(ftrace_export_lock); static struct trace_export __rcu *ftrace_exports_list __read_mostly; -static DEFINE_STATIC_KEY_FALSE(ftrace_exports_enabled); +static DEFINE_STATIC_KEY_FALSE(trace_function_exports_enabled); -static inline void ftrace_exports_enable(void) +static inline void ftrace_exports_enable(struct trace_export *export) { - static_branch_enable(&ftrace_exports_enabled); + if (export->flags & TRACE_EXPORT_FUNCTION) + static_branch_inc(&trace_function_exports_enabled); } -static inline void ftrace_exports_disable(void) +static inline void ftrace_exports_disable(struct trace_export *export) { - static_branch_disable(&ftrace_exports_enabled); + if (export->flags & TRACE_EXPORT_FUNCTION) + static_branch_dec(&trace_function_exports_enabled); } -static void ftrace_exports(struct ring_buffer_event *event) +static void ftrace_exports(struct ring_buffer_event *event, int flag) { struct trace_export *export; @@ -2781,7 +2785,7 @@ static void ftrace_exports(struct ring_buffer_event *event) export = rcu_dereference_raw_check(ftrace_exports_list); while (export) { - trace_process_export(export, event); + trace_process_export(export, event, flag); export = rcu_dereference_raw_check(export->next); } @@ -2821,8 +2825,7 @@ rm_trace_export(struct trace_export **list, struct trace_export *export) static inline void add_ftrace_export(struct trace_export **list, struct trace_export *export) { - if (*list == NULL) - ftrace_exports_enable(); + ftrace_exports_enable(export); add_trace_export(list, export); } @@ -2833,8 +2836,7 @@ rm_ftrace_export(struct trace_export **list, struct trace_export *export) int ret; ret = rm_trace_export(list, export); - if (*list == NULL) - ftrace_exports_disable(); + ftrace_exports_disable(export); return ret; } @@ -2887,8 +2889,8 @@ trace_function(struct trace_array *tr, entry->parent_ip = parent_ip; if (!call_filter_check_discard(call, entry, buffer, event)) { - if (static_branch_unlikely(&ftrace_exports_enabled)) - ftrace_exports(event); + if (static_branch_unlikely(&trace_function_exports_enabled)) + ftrace_exports(event, TRACE_EXPORT_FUNCTION); __buffer_unlock_commit(buffer, event); } } -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project