From patchwork Mon Apr 22 14:55:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slavomir Kaslev X-Patchwork-Id: 10911127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8DF0F161F for ; Mon, 22 Apr 2019 14:55:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 806B428535 for ; Mon, 22 Apr 2019 14:55:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 726072859A; Mon, 22 Apr 2019 14:55:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E05E528535 for ; Mon, 22 Apr 2019 14:55:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727765AbfDVOzc (ORCPT ); Mon, 22 Apr 2019 10:55:32 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:56169 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726132AbfDVOzc (ORCPT ); Mon, 22 Apr 2019 10:55:32 -0400 Received: by mail-wm1-f68.google.com with SMTP id o25so14738449wmf.5 for ; Mon, 22 Apr 2019 07:55:30 -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=NRdRlpQx22MU6DHOTYD9ZlKGcpoMmfuVzREyj+Vdzno=; b=QgZKGYaMOg/yZ0aNVQgBQkydRoLAw9lhe4MbRmyPuNXHMHGQZzvU/GbzseheQ4qelo 507cuc5Vm+5nKJdtQRW1u7o2ZC1O+X92nSZ1gbhGnAK7yxKdzo8xl04tsAxa2p752eGj XtifgkJh2C1Tm3272Zm6h01ITbuvYDQ24RIuwzwmmlKBtA3vEdDhGsqMeFmQKBW/HCV3 LhD8SjbtbYTtrKCBBFypXmurQCklOKu/uzYW2++V6v9bnmwpF+YwLfPFvfnnqcU7sDK5 1z/NTAsp/cKrQtwrm5KdN+9bgz7fp6LwNFrfgITCkQYyhvHrYOI1FezlWI8Rn3BRvvAx EBrg== X-Gm-Message-State: APjAAAXB/9EKHpx5YG7mTKVipiAsbmL59EdoH5xfQytIqLCfvWJfKnVj j/NB1qaoV1W39Zug2SOWrg== X-Google-Smtp-Source: APXvYqw+iZPxX6H2SEVJ87u+ZBE9AUL5kAXadp8h0BJbLKcZX3kUdp+nvRLkAZJRatPj7yZm0Rxb8Q== X-Received: by 2002:a1c:9691:: with SMTP id y139mr11624976wmd.64.1555944930131; Mon, 22 Apr 2019 07:55:30 -0700 (PDT) Received: from box.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id f128sm17321087wme.28.2019.04.22.07.55.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Apr 2019 07:55:29 -0700 (PDT) From: Slavomir Kaslev To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v10 05/12] trace-cmd: Add buffer instance flags for tracing in guest and agent context Date: Mon, 22 Apr 2019 17:55:12 +0300 Message-Id: <20190422145519.16146-6-kaslevs@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422145519.16146-1-kaslevs@vmware.com> References: <20190422145519.16146-1-kaslevs@vmware.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 55 ++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h index a1a06e9..f43c9d8 100644 --- a/tracecmd/include/trace-local.h +++ b/tracecmd/include/trace-local.h @@ -149,6 +149,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 { @@ -198,6 +200,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 4523128..933667e 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -821,6 +821,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"); @@ -1338,6 +1341,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) { @@ -1434,6 +1440,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); @@ -1627,6 +1636,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)) @@ -1939,6 +1951,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; @@ -1958,6 +1973,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; @@ -2199,6 +2217,9 @@ static void set_mask(struct buffer_instance *instance) int fd; int ret; + if (is_guest(instance)) + return; + if (!instance->cpumask) return; @@ -2229,6 +2250,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'); @@ -2252,6 +2276,9 @@ static void set_clock(struct buffer_instance *instance) char *content; char *str; + if (is_guest(instance)) + return; + if (!instance->clock) return; @@ -2281,6 +2308,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); @@ -2506,6 +2536,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) { @@ -3380,6 +3413,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"); @@ -3676,6 +3712,9 @@ static void set_buffer_size_instance(struct buffer_instance *instance) int ret; int fd; + if (is_guest(instance)) + return; + if (!buffer_size) return; @@ -3886,6 +3925,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) { @@ -3907,7 +3949,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); @@ -3989,7 +4031,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; } @@ -4011,6 +4053,9 @@ update_plugin_instance(struct buffer_instance *instance, { const char *plugin = instance->plugin; + if (is_guest(instance)) + return; + if (!plugin) return; @@ -4110,6 +4155,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++) { @@ -4136,6 +4184,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]);