Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp873164ybl; Fri, 10 Jan 2020 08:08:24 -0800 (PST) X-Google-Smtp-Source: APXvYqxBNh2f2nkn/RLWvUBoPUEGMNLsc3ciBvPN61iLuWwv71ThMDiw/Vt7ycOAEq8k87xK4141 X-Received: by 2002:a9d:4e92:: with SMTP id v18mr3004576otk.47.1578672502362; Fri, 10 Jan 2020 08:08:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578672502; cv=none; d=google.com; s=arc-20160816; b=Mx+Nq+p6aIwBvNgK45HDpl34I22VC42r44T0zlKNJEg3GU3WHWBYnJFXnT4D7vdTf+ rMERE+sKT42IjlwnIZ05Q+9b6r2HULGqopjWAUgqbeBoW23RBcfnaKuXNBy70QBnqg6n Ukh5jPfYTmUYCE4F46N+SibVOTSVSbNBp7Cvn4ALkf4Chyx67aW0xU+kjATDdcRFUftt KcLYlv1iGbDFc132u/YefLgcdXOHemDzMCw60yYuuM4+3QMIprEWFZuhB3CVd9puaDA0 ZymlPco5upLtzAC65Yd7VfEdJFd8hJxgE5ckDQmTU4HL1oQTOBzQzGYkPaLIoNtXz7ce DncQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=heHAmzBl37uWdYH+iP4BBu/dLe46ygAhkk7fCC1Plek=; b=yLa0ogkqKhbwbTUGuSOA86sfSfbXfGOYQJEcnCyXUkSVvo1C+i+lsz6dJQTohayhJ2 5fXWkw3BTVuVzAIHL+Eqa0nDdb9fVXIkx/vkNrR1KQDkQsL+nyAW+rYqj7rMju/Qu+88 vKNU201JDlM8qPioisJnFUJ/oCiZ+iw0ancrSLtQTZkwsJutUrKH1C4FVmrnEdtv+He0 96Ha16az/wBMysCmjlsvyBZvVkAPFxiSt/Ee634twz4o0lkjsDquz30JCRMKTDdrGiYn vTq5uravpHhw8qJTImtJb7baTlVetSYIl5s6MjMJCblhWX+pZIzPlvPo/iSTe7YI33fd fF8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pLZQ3fX4; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si1556507otj.115.2020.01.10.08.08.07; Fri, 10 Jan 2020 08:08:22 -0800 (PST) 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=@kernel.org header.s=default header.b=pLZQ3fX4; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728877AbgAJQG7 (ORCPT + 99 others); Fri, 10 Jan 2020 11:06:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:55404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728475AbgAJQG7 (ORCPT ); Fri, 10 Jan 2020 11:06:59 -0500 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C547D20673; Fri, 10 Jan 2020 16:06:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578672418; bh=jKmMpOy9enGmw++ycvlhCyFLkxvaeOxGWeTY1lvYWgw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pLZQ3fX4dLTapiF6Ft2nki6ebIivlHTmyY3oXnDFoySc/Q7VwP3wcTfi8TKyDMyqb iDsSCkSolIeC8ewwoXXfF8+s17ktayuroX3oDyzQj6leBCWke5q64GYpjyMrbKJfeo iq99Q3xwPSSAhDS+c2EUxpmvg+7cgxRykVG4UxrQ= From: Masami Hiramatsu To: Steven Rostedt Cc: Ingo Molnar , Frank Rowand , Randy Dunlap , Namhyung Kim , Tim Bird , Jiri Olsa , Arnaldo Carvalho de Melo , Tom Zanussi , Rob Herring , Andrew Morton , Thomas Gleixner , Greg Kroah-Hartman , Alexey Dobriyan , Jonathan Corbet , Linus Torvalds , linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 18/22] tracing/boot: Add synthetic event support Date: Sat, 11 Jan 2020 01:06:52 +0900 Message-Id: <157867241236.17873.12411615143321557709.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <157867220019.17873.13377985653744804396.stgit@devnote2> References: <157867220019.17873.13377985653744804396.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add synthetic event node support to boot time tracing. The synthetic event is a kind of event node, but the group name is "synthetic". - ftrace.event.synthetic.EVENT.fields = FIELD[, FIELD2...] Defines new synthetic event with FIELDs. Each field should be "type varname". The synthetic node requires "fields" string arraies, which defines the fields as same as tracing/synth_events interface. Signed-off-by: Masami Hiramatsu --- kernel/trace/trace_boot.c | 47 ++++++++++++++++++++++++++++++++++++++ kernel/trace/trace_events_hist.c | 5 ++++ 2 files changed, 52 insertions(+) diff --git a/kernel/trace/trace_boot.c b/kernel/trace/trace_boot.c index a11dc60299fb..3054921b0877 100644 --- a/kernel/trace/trace_boot.c +++ b/kernel/trace/trace_boot.c @@ -118,6 +118,50 @@ trace_boot_add_kprobe_event(struct xbc_node *node, const char *event) } #endif +#ifdef CONFIG_HIST_TRIGGERS +extern int synth_event_run_command(const char *command); + +static int __init +trace_boot_add_synth_event(struct xbc_node *node, const char *event) +{ + struct xbc_node *anode; + char buf[MAX_BUF_LEN], *q; + const char *p; + int len, delta, ret; + + len = ARRAY_SIZE(buf); + delta = snprintf(buf, len, "%s", event); + if (delta >= len) { + pr_err("Event name is too long: %s\n", event); + return -E2BIG; + } + len -= delta; q = buf + delta; + + xbc_node_for_each_array_value(node, "fields", anode, p) { + delta = snprintf(q, len, " %s;", p); + if (delta >= len) { + pr_err("fields string is too long: %s\n", p); + return -E2BIG; + } + len -= delta; q += delta; + } + + ret = synth_event_run_command(buf); + if (ret < 0) + pr_err("Failed to add synthetic event: %s\n", buf); + + + return ret; +} +#else +static inline int __init +trace_boot_add_synth_event(struct xbc_node *node, const char *event) +{ + pr_err("Synthetic event is not supported.\n"); + return -ENOTSUPP; +} +#endif + static void __init trace_boot_init_one_event(struct trace_array *tr, struct xbc_node *gnode, struct xbc_node *enode) @@ -133,6 +177,9 @@ trace_boot_init_one_event(struct trace_array *tr, struct xbc_node *gnode, if (!strcmp(group, "kprobes")) if (trace_boot_add_kprobe_event(enode, event) < 0) return; + if (!strcmp(group, "synthetic")) + if (trace_boot_add_synth_event(enode, event) < 0) + return; mutex_lock(&event_mutex); file = find_event_file(tr, group, event); diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 137fc50f2b35..3f26c4ed212a 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -1384,6 +1384,11 @@ static int create_or_delete_synth_event(int argc, char **argv) return ret == -ECANCELED ? -EINVAL : ret; } +int synth_event_run_command(const char *command) +{ + return trace_run_command(command, create_or_delete_synth_event); +} + static int synth_event_create(int argc, const char **argv) { const char *name = argv[0];