From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB96CC10F14 for ; Tue, 8 Oct 2019 08:15:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9660220679 for ; Tue, 8 Oct 2019 08:15:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730594AbfJHIP4 (ORCPT ); Tue, 8 Oct 2019 04:15:56 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38829 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730292AbfJHIPw (ORCPT ); Tue, 8 Oct 2019 04:15:52 -0400 Received: by mail-wm1-f67.google.com with SMTP id 3so2086609wmi.3 for ; Tue, 08 Oct 2019 01:15:49 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=m5OV5cFlKr7e7axf/197zDk8zOm3sSU44C7NlBnG75w=; b=mstZWdH9n/htOxUedKzhNo7l++cRp74/YPyeRj5+BqOMd9k8LLybHmDD2NnOd+P7f4 IdjsStWMyduc9pXm0wL26lNSmnlF25LSQ25o39JYa23SmiRw0DdHMxbE06rusGP57x3y 4m4gqSp4Z1GETaifa5Awo+ckJgSZectiw5lPeraSGlVxpu8mXNqTXNiJHgheqQxuleqF p51eNqHxldHLudzU50n4AjavEdPW78byDakNTyJiTvrydk/RUMCVBWLV3AJiacbf+dEh iQvP4B1OX2dOYSmaps4AII6CE6x6j5QlOGHNzUDQ/pCxojD2FSGOoLX07Kmt7ZJZSbWC nsZg== X-Gm-Message-State: APjAAAUnM/NGAp3p+EOkwGORFEgjLSzDSQvYgqb8CAQRCQYP1g+v2dvB bFWpyTmwg9b3K0XjESTGqQ== X-Google-Smtp-Source: APXvYqwaHu7uLl9vkNCWcvmPpBg/AYkuXCGv5NlfUMI6HloYOn30Nixne2Mf8WFtqKf7kKdIRz1O3A== X-Received: by 2002:a7b:cf28:: with SMTP id m8mr2911654wmg.161.1570522549022; Tue, 08 Oct 2019 01:15:49 -0700 (PDT) Received: from box.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id f13sm2201440wmj.17.2019.10.08.01.15.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 01:15:48 -0700 (PDT) From: Slavomir Kaslev To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v15 05/13] trace-cmd: Add buffer instance flags for tracing in guest and agent context Date: Tue, 8 Oct 2019 11:15:29 +0300 Message-Id: <20191008081537.11536-6-kaslevs@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191008081537.11536-1-kaslevs@vmware.com> References: <20191008081537.11536-1-kaslevs@vmware.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Add BUFFER_FL_GUEST and BUFFER_FL_AGENT flags to differentiate when trace-record.c is being called to trace guest or the VM tracing agent. Also disable functions talking to the local tracefs when called in recording guest instances context. Signed-off-by: Slavomir Kaslev --- tracecmd/include/trace-local.h | 5 +++ tracecmd/trace-record.c | 58 ++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h index 05760d8..24fad8d 100644 --- a/tracecmd/include/trace-local.h +++ b/tracecmd/include/trace-local.h @@ -146,6 +146,8 @@ char *strstrip(char *str); enum buffer_instance_flags { BUFFER_FL_KEEP = 1 << 0, BUFFER_FL_PROFILE = 1 << 1, + BUFFER_FL_GUEST = 1 << 2, + BUFFER_FL_AGENT = 1 << 3, }; struct func_list { @@ -207,6 +209,9 @@ extern struct buffer_instance *first_instance; #define for_all_instances(i) for (i = first_instance; i; \ i = i == &top_instance ? buffer_instances : (i)->next) +#define is_agent(instance) ((instance)->flags & BUFFER_FL_AGENT) +#define is_guest(instance) ((instance)->flags & BUFFER_FL_GUEST) + struct buffer_instance *create_instance(const char *name); void add_instance(struct buffer_instance *instance, int cpu_count); char *get_instance_file(struct buffer_instance *instance, const char *file); diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 69de82a..5f0e8d3 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -828,6 +828,9 @@ static void __clear_trace(struct buffer_instance *instance) FILE *fp; char *path; + if (is_guest(instance)) + return; + /* reset the trace */ path = get_instance_file(instance, "trace"); fp = fopen(path, "w"); @@ -1536,6 +1539,9 @@ set_plugin_instance(struct buffer_instance *instance, const char *name) char *path; char zero = '0'; + if (is_guest(instance)) + return; + path = get_instance_file(instance, "current_tracer"); fp = fopen(path, "w"); if (!fp) { @@ -1632,6 +1638,9 @@ static void disable_func_stack_trace_instance(struct buffer_instance *instance) int size; int ret; + if (is_guest(instance)) + return; + path = get_instance_file(instance, "current_tracer"); ret = stat(path, &st); tracecmd_put_tracing_file(path); @@ -1825,6 +1834,9 @@ reset_events_instance(struct buffer_instance *instance) int i; int ret; + if (is_guest(instance)) + return; + if (use_old_event_method()) { /* old way only had top instance */ if (!is_top_instance(instance)) @@ -2137,6 +2149,9 @@ static void write_tracing_on(struct buffer_instance *instance, int on) int ret; int fd; + if (is_guest(instance)) + return; + fd = open_tracing_on(instance); if (fd < 0) return; @@ -2156,6 +2171,9 @@ static int read_tracing_on(struct buffer_instance *instance) char buf[10]; int ret; + if (is_guest(instance)) + return -1; + fd = open_tracing_on(instance); if (fd < 0) return fd; @@ -2302,6 +2320,9 @@ static void update_pid_filters(struct buffer_instance *instance) int ret; int fd; + if (is_guest(instance)) + return; + fd = open_instance_fd(instance, "set_event_pid", O_WRONLY | O_CLOEXEC | O_TRUNC); if (fd < 0) @@ -2397,6 +2418,9 @@ static void set_mask(struct buffer_instance *instance) int fd; int ret; + if (is_guest(instance)) + return; + if (!instance->cpumask) return; @@ -2428,6 +2452,9 @@ static void enable_events(struct buffer_instance *instance) { struct event_list *event; + if (is_guest(instance)) + return; + for (event = instance->events; event; event = event->next) { if (!event->neg) update_event(event, event->filter, 0, '1'); @@ -2451,6 +2478,9 @@ static void set_clock(struct buffer_instance *instance) char *content; char *str; + if (is_guest(instance)) + return; + if (!instance->clock) return; @@ -2480,6 +2510,9 @@ static void set_max_graph_depth(struct buffer_instance *instance, char *max_grap char *path; int ret; + if (is_guest(instance)) + return; + path = get_instance_file(instance, "max_graph_depth"); reset_save_file(path, RESET_DEFAULT_PRIO); tracecmd_put_tracing_file(path); @@ -2705,6 +2738,9 @@ static void expand_event_instance(struct buffer_instance *instance) struct event_list *compressed_list = instance->events; struct event_list *event; + if (is_guest(instance)) + return; + reset_event_list(instance); while (compressed_list) { @@ -3631,6 +3667,9 @@ static void set_funcs(struct buffer_instance *instance) int set_notrace = 0; int ret; + if (is_guest(instance)) + return; + ret = write_func_file(instance, "set_ftrace_filter", &instance->filter_funcs); if (ret < 0) die("set_ftrace_filter does not exist. Can not filter functions"); @@ -3927,6 +3966,9 @@ static void set_buffer_size_instance(struct buffer_instance *instance) int ret; int fd; + if (is_guest(instance)) + return; + if (!buffer_size) return; @@ -4137,6 +4179,9 @@ static void make_instances(void) int ret; for_each_instance(instance) { + if (is_guest(instance)) + continue; + path = get_instance_dir(instance); ret = stat(path, &st); if (ret < 0) { @@ -4158,7 +4203,7 @@ void tracecmd_remove_instances(void) for_each_instance(instance) { /* Only delete what we created */ - if (instance->flags & BUFFER_FL_KEEP) + if (is_guest(instance) || (instance->flags & BUFFER_FL_KEEP)) continue; if (instance->tracing_on_fd > 0) { close(instance->tracing_on_fd); @@ -4240,7 +4285,7 @@ static void check_function_plugin(void) static int __check_doing_something(struct buffer_instance *instance) { - return (instance->flags & BUFFER_FL_PROFILE) || + return is_guest(instance) || (instance->flags & BUFFER_FL_PROFILE) || instance->plugin || instance->events; } @@ -4262,6 +4307,9 @@ update_plugin_instance(struct buffer_instance *instance, { const char *plugin = instance->plugin; + if (is_guest(instance)) + return; + if (!plugin) return; @@ -4361,6 +4409,9 @@ static void record_stats(void) int cpu; for_all_instances(instance) { + if (is_guest(instance)) + continue; + s_save = instance->s_save; s_print = instance->s_print; for (cpu = 0; cpu < instance->cpu_count; cpu++) { @@ -4387,6 +4438,9 @@ static void destroy_stats(void) int cpu; for_all_instances(instance) { + if (is_guest(instance)) + continue; + for (cpu = 0; cpu < instance->cpu_count; cpu++) { trace_seq_destroy(&instance->s_save[cpu]); trace_seq_destroy(&instance->s_print[cpu]); -- 2.20.1