From patchwork Fri Feb 22 14:28:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzvetomir Stoyanov X-Patchwork-Id: 10826161 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 86E2815AC for ; Fri, 22 Feb 2019 14:28:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75F5D303F5 for ; Fri, 22 Feb 2019 14:28:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A375327D9; Fri, 22 Feb 2019 14:28:42 +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 E5FE4303F5 for ; Fri, 22 Feb 2019 14:28:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726331AbfBVO2l (ORCPT ); Fri, 22 Feb 2019 09:28:41 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41674 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726214AbfBVO2l (ORCPT ); Fri, 22 Feb 2019 09:28:41 -0500 Received: by mail-wr1-f65.google.com with SMTP id n2so2576789wrw.8 for ; Fri, 22 Feb 2019 06:28:39 -0800 (PST) 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=iGC7rh6ccnovJ9Vj2x/cclblPNlik72qrfXGJ/5N6b4=; b=fjX+vXLbrEGNkXFW4lS4M9GhaEkh37ovpDg8QXLj8U13lDGyQL89Ub4VO/1DBt1KJw +ZSct1jMLdgfycfsXcV3AMcp7jJWjrOj5UJdZdQqmEYJtgnvsoKQdfAGvRGw3i3M2u5v Z0UNLLFEkSY9porlrEs0VG812DDVEzlwJIeYb/7peqsrzbpzVKv5IljRwHGxlPjhj24p lQNEtRLvfH6fKUPt+lh9mz/k3sQmV2BnsZdmN3BMq3tKenCQJ9oP24CMXA6lKtW6/6Du puPMKS3Svxn7cPzcFrKvQ0GhbBoNSpLrv089rTGec30XEsQPh5DAyAOR1Gj/wNTeOzwE IBPw== X-Gm-Message-State: AHQUAuZXv4laVwPMfF0PgqVeyFMfXeWfFtMO/fWHBgy60R+eaoIv/Sqp DYsnJElb9+TZsIAK9e+/9qTPHA+k X-Google-Smtp-Source: AHgI3IZTQzyhiT24CUwKTU+JWvT8n1/CW6kGjtgQKhtoxurQ4SRGSBrQBl/f+cF+7xZvcfTFAVb4ww== X-Received: by 2002:a5d:604d:: with SMTP id j13mr3269045wrt.194.1550845719071; Fri, 22 Feb 2019 06:28:39 -0800 (PST) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id q9sm848987wrv.26.2019.02.22.06.28.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Feb 2019 06:28:38 -0800 (PST) From: Tzvetomir Stoyanov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 1/7] trace-cmd: Implemented new lib API: tracecmd_local_events_system() Date: Fri, 22 Feb 2019 16:28:30 +0200 Message-Id: <20190222142836.12596-2-tstoyanov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190222142836.12596-1-tstoyanov@vmware.com> References: <20190222142836.12596-1-tstoyanov@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 The new tracecmd lib API tracecmd_local_events_system() creates a tep handler and initializes it with the events of the specified subsystems. Signed-off-by: Tzvetomir Stoyanov --- include/trace-cmd/trace-cmd.h | 2 + lib/trace-cmd/trace-util.c | 99 +++++++++++++++++++++++------------ 2 files changed, 68 insertions(+), 33 deletions(-) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index 27ba89d..0067882 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -32,6 +32,8 @@ void tracecmd_unload_plugins(struct tep_plugin_list *list, struct tep_handle *pe char **tracecmd_event_systems(const char *tracing_dir); char **tracecmd_system_events(const char *tracing_dir, const char *system); struct tep_handle *tracecmd_local_events(const char *tracing_dir); +struct tep_handle *tracecmd_local_events_system(const char *tracing_dir, + char **sys_names); int tracecmd_fill_local_events(const char *tracing_dir, struct tep_handle *pevent); char **tracecmd_local_plugins(const char *tracing_dir); diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c index b5aea39..0e925ed 100644 --- a/lib/trace-cmd/trace-util.c +++ b/lib/trace-cmd/trace-util.c @@ -1119,43 +1119,15 @@ static int read_header(struct tep_handle *pevent, const char *events_dir) return ret; } -/** - * tracecmd_local_events - create a pevent from the events on system - * @tracing_dir: The directory that contains the events. - * - * Returns a pevent structure that contains the pevents local to - * the system. - */ -struct tep_handle *tracecmd_local_events(const char *tracing_dir) -{ - struct tep_handle *pevent = NULL; - - pevent = tep_alloc(); - if (!pevent) - return NULL; - - if (tracecmd_fill_local_events(tracing_dir, pevent)) { - tep_free(pevent); - pevent = NULL; - } - - return pevent; -} - -/** - * tracecmd_fill_local_events - Fill a pevent with the events on system - * @tracing_dir: The directory that contains the events. - * @pevent: Allocated pevent which will be filled - * - * Returns whether the operation succeeded - */ -int tracecmd_fill_local_events(const char *tracing_dir, struct tep_handle *pevent) +static int tracecmd_fill_local_events_system(const char *tracing_dir, + struct tep_handle *pevent, + char **sys_names) { + int ret, i, failure = 0; struct dirent *dent; char *events_dir; struct stat st; DIR *dir; - int ret, failure = 0; if (!tracing_dir) return -1; @@ -1189,7 +1161,16 @@ int tracecmd_fill_local_events(const char *tracing_dir, struct tep_handle *peven if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) continue; - + if (sys_names) { + i = 0; + while (sys_names[i]) { + if (strcmp(name, sys_names[i]) == 0) + break; + i++; + } + if (sys_names[i] == NULL) + continue; + } sys = append_file(events_dir, name); ret = stat(sys, &st); if (ret < 0 || !S_ISDIR(st.st_mode)) { @@ -1217,6 +1198,58 @@ int tracecmd_fill_local_events(const char *tracing_dir, struct tep_handle *peven return ret; } +/** + * tracecmd_local_events_system - create a tep from the events of the specified subsystem. + * + * @tracing_dir: The directory that contains the events. + * @sys_name: Array of system names, to load the events from. + * The last element from the array must be NULL + * + * Returns a tep structure that contains the tep local to + * the system. + */ +struct tep_handle *tracecmd_local_events_system(const char *tracing_dir, + char **sys_names) +{ + struct tep_handle *tep = NULL; + + tep = tep_alloc(); + if (!tep) + return NULL; + + if (tracecmd_fill_local_events_system(tracing_dir, tep, sys_names)) { + tep_free(tep); + tep = NULL; + } + + return tep; +} + +/** + * tracecmd_local_events - create a pevent from the events on system + * @tracing_dir: The directory that contains the events. + * + * Returns a pevent structure that contains the pevents local to + * the system. + */ +struct tep_handle *tracecmd_local_events(const char *tracing_dir) +{ + return tracecmd_local_events_system(tracing_dir, NULL); +} + +/** + * tracecmd_fill_local_events - Fill a pevent with the events on system + * @tracing_dir: The directory that contains the events. + * @pevent: Allocated pevent which will be filled + * + * Returns whether the operation succeeded + */ +int tracecmd_fill_local_events(const char *tracing_dir, + struct tep_handle *pevent) +{ + return tracecmd_fill_local_events_system(tracing_dir, pevent, NULL); +} + /** * tracecmd_local_plugins - returns an array of available tracer plugins * @tracing_dir: The directory that contains the tracing directory From patchwork Fri Feb 22 14:28:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzvetomir Stoyanov X-Patchwork-Id: 10826163 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 610C615AC for ; Fri, 22 Feb 2019 14:28:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51A7A327D5 for ; Fri, 22 Feb 2019 14:28:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4615C327D9; Fri, 22 Feb 2019 14:28:43 +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 14B7C327D5 for ; Fri, 22 Feb 2019 14:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726352AbfBVO2l (ORCPT ); Fri, 22 Feb 2019 09:28:41 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:33959 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725942AbfBVO2l (ORCPT ); Fri, 22 Feb 2019 09:28:41 -0500 Received: by mail-wm1-f68.google.com with SMTP id y185so9026384wmd.1 for ; Fri, 22 Feb 2019 06:28:40 -0800 (PST) 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=0Akwbj/kBryCNHRJuSYOiQOEQ7urlKUyQpryXh2sI2c=; b=iIAfwHu56mNHhJLybwhj6hK06l6LTdIJWLHclo4F5ItKU0zK22WjfSygbpUeS5xOa6 EVEXb8gRu5mZVAfxp58OPmAyQc0OnPMWbIv1G61Aiija9ZTwotpXbn5gzLPe0IaYeqNE VmrA7wqMQekGJvk6XExw1c6XUW7unAcG9Z/OGUmDkzzZyKJufz0k8xmeRsqHLUPGNnlR yWaUB+Dhu23TQVcG+g/0oq3yOhYmaRcQeHO6xWU+Uj5/VF0ExCoojQirJLG1ySz+W7Rs v3FqpzCOTwHIZEccs92226ATFkpSqlZOuc71TtLEBfheL8UHQ8IQSbxDqnKx+LO6O7G9 TYeA== X-Gm-Message-State: AHQUAubM7fOBq8mweGeq0rCj/c8baSjTNeYKdh20E2u+oE+v9lYlbI7M FHe8a5l2eMWG2Cj7y2uFViL3jX7D X-Google-Smtp-Source: AHgI3IZRkbrYatZv5uXexipEn3AtEgONjT+FVEhaN6Uh6JTVKLeXHbBnzMobmKsSakQKeJ/YNNzbkg== X-Received: by 2002:a1c:7008:: with SMTP id l8mr2604110wmc.63.1550845719970; Fri, 22 Feb 2019 06:28:39 -0800 (PST) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id q9sm848987wrv.26.2019.02.22.06.28.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Feb 2019 06:28:39 -0800 (PST) From: Tzvetomir Stoyanov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 2/7] trace-cmd: Added support for negative time offsets in trace.dat file Date: Fri, 22 Feb 2019 16:28:31 +0200 Message-Id: <20190222142836.12596-3-tstoyanov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190222142836.12596-1-tstoyanov@vmware.com> References: <20190222142836.12596-1-tstoyanov@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 When synchronizing timestamps between different machines, there are cases when the time offset is negative. This patch changes the way time offset is written and read from trace.dat file - as signed decimal, instead of hex. Signed-off-by: Tzvetomir Stoyanov --- include/trace-cmd/trace-cmd.h | 2 +- lib/trace-cmd/trace-input.c | 6 +++--- tracecmd/trace-read.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index 0067882..3f0ab4f 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -126,7 +126,7 @@ int tracecmd_is_buffer_instance(struct tracecmd_input *handle); void tracecmd_create_top_instance(char *name); void tracecmd_remove_instances(void); -void tracecmd_set_ts_offset(struct tracecmd_input *handle, unsigned long long offset); +void tracecmd_set_ts_offset(struct tracecmd_input *handle, long long offset); void tracecmd_set_ts2secs(struct tracecmd_input *handle, unsigned long long hz); void tracecmd_print_events(struct tracecmd_input *handle, const char *regex); diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 34a8301..be6720c 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -91,7 +91,7 @@ struct tracecmd_input { bool read_page; bool use_pipe; struct cpu_data *cpu_data; - unsigned long long ts_offset; + long long ts_offset; double ts2secs; char * cpustats; char * uname; @@ -2082,7 +2082,7 @@ static int init_cpu(struct tracecmd_input *handle, int cpu) } void tracecmd_set_ts_offset(struct tracecmd_input *handle, - unsigned long long offset) + long long offset) { handle->ts_offset = offset; } @@ -2099,7 +2099,7 @@ void tracecmd_set_ts2secs(struct tracecmd_input *handle, static int handle_options(struct tracecmd_input *handle) { - unsigned long long offset; + long long offset; unsigned short option; unsigned int size; char *cpustats = NULL; diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c index 804022a..e309672 100644 --- a/tracecmd/trace-read.c +++ b/tracecmd/trace-read.c @@ -58,7 +58,7 @@ static struct list_head handle_list; struct input_files { struct list_head list; const char *file; - unsigned long long tsoffset; + long long tsoffset; unsigned long long ts2secs; }; static struct list_head input_files; @@ -1413,7 +1413,7 @@ void trace_report (int argc, char **argv) struct input_files *inputs; struct handle_list *handles; enum output_type otype; - unsigned long long tsoffset = 0; + long long tsoffset = 0; unsigned long long ts2secs = 0; unsigned long long ts2sc; int show_stat = 0; From patchwork Fri Feb 22 14:28:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzvetomir Stoyanov X-Patchwork-Id: 10826165 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 8A3341399 for ; Fri, 22 Feb 2019 14:28:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7892B303F5 for ; Fri, 22 Feb 2019 14:28:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D0EA327D6; Fri, 22 Feb 2019 14:28:43 +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 223F4303F5 for ; Fri, 22 Feb 2019 14:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726356AbfBVO2n (ORCPT ); Fri, 22 Feb 2019 09:28:43 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:50926 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726214AbfBVO2m (ORCPT ); Fri, 22 Feb 2019 09:28:42 -0500 Received: by mail-wm1-f66.google.com with SMTP id x7so2147046wmj.0 for ; Fri, 22 Feb 2019 06:28:41 -0800 (PST) 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=uk3prq7PM5NWRxFeku/sMfCiWVMc5DcibNxNMdyfE4M=; b=HnuS1SZce2e8Vt/K0vAcYwiqXI05JrMdLulLQvdq6bF0kTywCAH3YKHEiEM25+C3Go WPrRkqrkoSfYBNQhHJoPl976b2jZr1Iwikr1DCZSPjNlnAhFzvorUdt0mYWlUP/3iIYo QbQA+BaNNNMryutKmfSffouFUAC0yYdx/nYHEUgC03jsqUevhtgybKZhy7F93z355p2W 2TNWAhSXyr2KaxU+bAaqwT4XCcNsGrW+qo2tpHgbl1jwFn+JcFrLeUR8bTWlVUEN9gVt dQlLi/8fUAyss5v+MbKrrFCFZHs3xUigli+HxrF4wGuk8ZrrvtGFcukRW04i/sE2Oo5u CTzg== X-Gm-Message-State: AHQUAuYcF4cbcUr3r7a5XLFU1gHRwhOta5v6tOfh8jl6KUiZMVl3IKMg 8bY4RRG7UvjibvI4zpzTX0g= X-Google-Smtp-Source: AHgI3IZ8MG7uey6n/EPR7G2Kg8jIayhMEbgwB9c5XTjxlHrxpHwwAb6t/WOTH92WX7GOi731Kp7QLw== X-Received: by 2002:a1c:a9d0:: with SMTP id s199mr2642048wme.142.1550845720993; Fri, 22 Feb 2019 06:28:40 -0800 (PST) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id q9sm848987wrv.26.2019.02.22.06.28.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Feb 2019 06:28:40 -0800 (PST) From: Tzvetomir Stoyanov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 3/7] trace-cmd: Fix tracecmd_read_page_record() to read more than one event Date: Fri, 22 Feb 2019 16:28:32 +0200 Message-Id: <20190222142836.12596-4-tstoyanov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190222142836.12596-1-tstoyanov@vmware.com> References: <20190222142836.12596-1-tstoyanov@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 The kbuffer_next_event() will return the next event on the sub buffer. If we pass in the last_record to tracecmd_read_page_record(), it initializes the sub buffer, and by calling kbuffer_next_event() (instead of kbuffer_read_event()), the second event on the sub buffer is returned. This causes the match of the last_record not to match if the last_record happens to be the first event on the sub buffer. Signed-off-by: Tzvetomir Stoyanov --- lib/trace-cmd/trace-input.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index be6720c..0a6e820 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -1679,18 +1679,22 @@ tracecmd_read_page_record(struct tep_handle *pevent, void *page, int size, goto out_free; } - do { + ptr = kbuffer_read_event(kbuf, &ts); + while (ptr < last_record->data) { ptr = kbuffer_next_event(kbuf, NULL); if (!ptr) break; - } while (ptr < last_record->data); + if (ptr == last_record->data) + break; + } if (ptr != last_record->data) { warning("tracecmd_read_page_record: could not find last_record"); goto out_free; } - } + ptr = kbuffer_next_event(kbuf, &ts); + } else + ptr = kbuffer_read_event(kbuf, &ts); - ptr = kbuffer_read_event(kbuf, &ts); if (!ptr) goto out_free; From patchwork Fri Feb 22 14:28:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzvetomir Stoyanov X-Patchwork-Id: 10826167 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 24C6A15AC for ; Fri, 22 Feb 2019 14:28:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14082303F5 for ; Fri, 22 Feb 2019 14:28:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 085FE327D6; Fri, 22 Feb 2019 14:28:46 +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 B73B4303F5 for ; Fri, 22 Feb 2019 14:28:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726560AbfBVO2n (ORCPT ); Fri, 22 Feb 2019 09:28:43 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:56044 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725942AbfBVO2n (ORCPT ); Fri, 22 Feb 2019 09:28:43 -0500 Received: by mail-wm1-f68.google.com with SMTP id q187so2144317wme.5 for ; Fri, 22 Feb 2019 06:28:42 -0800 (PST) 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=KZrqIpIWaDsmqIPJyX90jfu7nox1DuIvSLjj1esD/k8=; b=aXqe2kQskkavPK3Pi2xhIZm9vIyluxC8oeW3il+nIULgJ5vXl8xCn29XjpUX5Tw9oT R45EFawtvwa+nL/wf91eM3J4EeE7AC1c0XFfVpo6QRnpow5uYvDU2vTlm4Xx9BBjLZZv a9XpdZypXO6vXVmq9ysTUq0oWqq6ZeZcUZDiNnY23lb8/vTGZZU490bpD+4biySBWi0E s2Naust7Witf1zEwV5+2sMzrxYLiKg2+b0/xD4jIDuWPgUKmaf6EXBAbI90zFf1tb/ae 2CBLNLWiwXNFr8u0crcMGrAdsPJ0lDN8eci0LgNrMWDaRK2qMM6Fetr3hRrth1+9OZ3M oifA== X-Gm-Message-State: AHQUAuZTND5a+ArkEQlqm5x7HiJWs54rKYfCnsoJKrrBXWcvhpL+1ZzL oWWnu1yqrVSfDH9ajaBPtVJmCACq X-Google-Smtp-Source: AHgI3IafLAfiiH494oWFoN1esJp5MM9p27Kmw6HND6CKaajcxD//3Ue6jOVxpB+ouQovQkZ1TPW99Q== X-Received: by 2002:a1c:5fd7:: with SMTP id t206mr2686687wmb.73.1550845721737; Fri, 22 Feb 2019 06:28:41 -0800 (PST) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id q9sm848987wrv.26.2019.02.22.06.28.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Feb 2019 06:28:41 -0800 (PST) From: Tzvetomir Stoyanov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 4/7] trace-cmd: Added implementation of htonll() and ntohll() Date: Fri, 22 Feb 2019 16:28:33 +0200 Message-Id: <20190222142836.12596-5-tstoyanov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190222142836.12596-1-tstoyanov@vmware.com> References: <20190222142836.12596-1-tstoyanov@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 Added implementation of htonll() and ntohll() as macros, if they are not already defined. Signed-off-by: Tzvetomir Stoyanov --- tracecmd/include/trace-msg.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tracecmd/include/trace-msg.h b/tracecmd/include/trace-msg.h index b7fe10b..445f799 100644 --- a/tracecmd/include/trace-msg.h +++ b/tracecmd/include/trace-msg.h @@ -15,4 +15,14 @@ extern unsigned int page_size; void plog(const char *fmt, ...); void pdie(const char *fmt, ...); +#ifndef htonll +# if __BYTE_ORDER == __LITTLE_ENDIAN +#define htonll(x) __bswap_64(x) +#define ntohll(x) __bswap_64(x) +#else +#define htonll(x) (x) +#define ntohll(x) (x) +#endif +#endif + #endif /* _TRACE_MSG_H_ */ From patchwork Fri Feb 22 14:28:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzvetomir Stoyanov X-Patchwork-Id: 10826169 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 13BA515AC for ; Fri, 22 Feb 2019 14:28:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02B83303F5 for ; Fri, 22 Feb 2019 14:28:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB255327D6; Fri, 22 Feb 2019 14:28:46 +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 930A6303F5 for ; Fri, 22 Feb 2019 14:28:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726574AbfBVO2q (ORCPT ); Fri, 22 Feb 2019 09:28:46 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:34978 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726325AbfBVO2p (ORCPT ); Fri, 22 Feb 2019 09:28:45 -0500 Received: by mail-wm1-f68.google.com with SMTP id y15so2166519wma.0 for ; Fri, 22 Feb 2019 06:28:43 -0800 (PST) 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=Mb1yPU2Gft4CefjzzqFAfr3+pf5vHg6DCvfBVtFI6IM=; b=iyLyrk0EFzQQHocxTF4cb96RwlzyLX3qLcmDrE78Rc+O57+ZwamPTeCzl//Vtp6ENA WMHQkIo1fPXstCEjDyOsmU+5/Wn/BIzb8dKx6JnWkEYOZsnfK7iMmt4BhWOp0MSKE7/E PRyFWBNnKpaSN4fXiWl0Al1YxJssSTlDF/zd5QoUoOQCSyspf37iczGPEeW8UIGnc6mR PjBie7rb3ES+qPa5pvQTUYFPoQP/ODHODxiggBxThVeG2k6EnF1efJQmo6sKXuQT7Qtc e4BcaKyD11h9k9Lo/Lo3WMo4akq8ekuI+4PWqmZSJcMHiJYLqFR0chmkcYUu7He5nI1J ykAQ== X-Gm-Message-State: AHQUAuZAtnkSBdjjkSoQNtYWAAMgGXx6pg/TBbkUvuGUwsIHxTIBftji do5dv0vlO31ga56Xxxd3Jio= X-Google-Smtp-Source: AHgI3IZj2l74nBxPbpKGtI6rfYMl7i/S2mYBhy78Xoq85A2pgDEUdwy6YGKVsCTbLZur8+umbBYrMA== X-Received: by 2002:a1c:5546:: with SMTP id j67mr2564980wmb.95.1550845722487; Fri, 22 Feb 2019 06:28:42 -0800 (PST) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id q9sm848987wrv.26.2019.02.22.06.28.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Feb 2019 06:28:41 -0800 (PST) From: Tzvetomir Stoyanov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 5/7] trace-cmd: Refactored make_instances() and tracecmd_remove_instances() Date: Fri, 22 Feb 2019 16:28:34 +0200 Message-Id: <20190222142836.12596-6-tstoyanov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190222142836.12596-1-tstoyanov@vmware.com> References: <20190222142836.12596-1-tstoyanov@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 In order to reuse the code which creates / deletes tracing instances, these two functions are refactotred. A new ones are implemented: make_instance() and tracecmd_remove_instance(). Signed-off-by: Tzvetomir Stoyanov --- tracecmd/trace-record.c | 54 +++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index ef6319f..c57ed6b 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -4316,49 +4316,57 @@ static void clear_func_filters(void) } } -static void make_instances(void) +static void make_instance(struct buffer_instance *instance) { - struct buffer_instance *instance; struct stat st; char *path; int ret; + path = get_instance_dir(instance); + ret = stat(path, &st); + if (ret < 0) { + ret = mkdir(path, 0777); + if (ret < 0) + die("mkdir %s", path); + } else + /* Don't delete instances that already exist */ + instance->flags |= BUFFER_FL_KEEP; + tracecmd_put_tracing_file(path); + +} + +static void make_instances(void) +{ + struct buffer_instance *instance; + for_each_instance(instance) { if (is_guest(instance)) continue; + make_instance(instance); + } +} - path = get_instance_dir(instance); - ret = stat(path, &st); - if (ret < 0) { - ret = mkdir(path, 0777); - if (ret < 0) - die("mkdir %s", path); - } else - /* Don't delete instances that already exist */ - instance->flags |= BUFFER_FL_KEEP; - tracecmd_put_tracing_file(path); +static void tracecmd_remove_instance(struct buffer_instance *instance) +{ + char *path; + + if (instance->tracing_on_fd > 0) { + close(instance->tracing_on_fd); + instance->tracing_on_fd = 0; } + path = get_instance_dir(instance); + tracecmd_put_tracing_file(path); } void tracecmd_remove_instances(void) { struct buffer_instance *instance; - char *path; - int ret; for_each_instance(instance) { /* Only delete what we created */ if (is_guest(instance) || (instance->flags & BUFFER_FL_KEEP)) continue; - if (instance->tracing_on_fd > 0) { - close(instance->tracing_on_fd); - instance->tracing_on_fd = 0; - } - path = get_instance_dir(instance); - ret = rmdir(path); - if (ret < 0) - die("rmdir %s", path); - tracecmd_put_tracing_file(path); + tracecmd_remove_instance(instance); } } From patchwork Fri Feb 22 14:28:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzvetomir Stoyanov X-Patchwork-Id: 10826171 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 DEB811399 for ; Fri, 22 Feb 2019 14:28:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB304303F5 for ; Fri, 22 Feb 2019 14:28:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF7AE327D6; Fri, 22 Feb 2019 14:28:47 +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 592C9303F5 for ; Fri, 22 Feb 2019 14:28:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726325AbfBVO2q (ORCPT ); Fri, 22 Feb 2019 09:28:46 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38477 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725942AbfBVO2q (ORCPT ); Fri, 22 Feb 2019 09:28:46 -0500 Received: by mail-wm1-f67.google.com with SMTP id v26so2150041wmh.3 for ; Fri, 22 Feb 2019 06:28:44 -0800 (PST) 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=IIFyUucP7K4v0qLKAqa28gYnIzAYgIFIORZpsMA9ufo=; b=HmtU3i+dUowiUsXhDs48yIQ6OWCJD8m1fQ7gJWgn+vQXWqv9QkBXWqquKWoYRQXHGV VY9glTToF6bGGWVxaY3NCZ92CAWatAEvfkcAx1+LbTT0H3o/GC2MwcIoS+918z8rObao xHLwMpygA7PyEgmvGNInxf5Jcp2A+FD5lTyNoVOTG+V5IqFHP1WzuVeNaMR6mTuQ+oT7 QPk/5ShfFgwZHkSmAfMJOHTbQ99QBxb6sARYAYJkA+BBfL/M7SPHJZkFevXr4mJ1sNuX Ybeut0fwm5YctvW/f51MVvy6hWOin1DsY/HhS0FLIVCkAvXAig3TSAPicnhBgRpSMcr2 L//A== X-Gm-Message-State: AHQUAua2OTkkK7JFfPopPEFGjugb+TKPbQcF9C5YAU6bSm3kXaOuuufY UhDBAwXKmBHKvbCxTkWgbOWe9QaO X-Google-Smtp-Source: AHgI3Ia//COswqvEvqtbuj7/yOFEMSCx47NQo7NxAGKFeQpTk3+D2aMNXcJahMu6+gQPifY33WEt9Q== X-Received: by 2002:a7b:c0c3:: with SMTP id s3mr2555800wmh.141.1550845723457; Fri, 22 Feb 2019 06:28:43 -0800 (PST) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id q9sm848987wrv.26.2019.02.22.06.28.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Feb 2019 06:28:42 -0800 (PST) From: Tzvetomir Stoyanov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 6/7] trace-cmd: Find and store pids of tasks, which run virtual CPUs of given VM Date: Fri, 22 Feb 2019 16:28:35 +0200 Message-Id: <20190222142836.12596-7-tstoyanov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190222142836.12596-1-tstoyanov@vmware.com> References: <20190222142836.12596-1-tstoyanov@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 In order to match host and guest events, a mapping between guest VCPU and the host task, running this VCPU is needed. Extended existing struct guest to hold such mapping and added logic in read_qemu_guests() function to initialize it. Implemented a new internal API, get_guest_vcpu_pids(), to retrieve VCPU-task mapping for given VM. Signed-off-by: Tzvetomir Stoyanov --- tracecmd/include/trace-local.h | 3 ++ tracecmd/trace-record.c | 57 +++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h index d7bdb1f..ef6848f 100644 --- a/tracecmd/include/trace-local.h +++ b/tracecmd/include/trace-local.h @@ -236,6 +236,9 @@ void show_instance_file(struct buffer_instance *instance, const char *name); int count_cpus(void); +#define VCPUS_MAX 256 +int *get_guest_vcpu_pids(int cid); + /* No longer in event-utils.h */ void __noreturn die(const char *fmt, ...); /* Can be overriden */ void *malloc_or_die(unsigned int size); /* Can be overridden */ diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index c57ed6b..59f0197 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -2752,6 +2752,7 @@ struct guest { char *name; int cid; int pid; + int cpu_pid[VCPUS_MAX]; }; static struct guest *guests; @@ -2772,9 +2773,10 @@ static char *get_qemu_guest_name(char *arg) static void read_qemu_guests(void) { static bool initialized; + struct dirent *entry_t; struct dirent *entry; char path[PATH_MAX]; - DIR *dir; + DIR *dir, *dir_t; if (initialized) return; @@ -2830,6 +2832,49 @@ static void read_qemu_guests(void) if (!is_qemu) goto next; + snprintf(path, sizeof(path), "/proc/%s/task", entry->d_name); + dir_t = opendir(path); + if (dir_t) { + unsigned int vcpu; + char *buf = NULL; + char *cpu_str; + FILE *ft; + size_t n; + int j; + + for (entry_t = readdir(dir_t); entry_t; entry_t = readdir(dir_t)) { + if (!(entry_t->d_type == DT_DIR && + is_digits(entry_t->d_name))) + continue; + snprintf(path, sizeof(path), + "/proc/%s/task/%s/comm", + entry->d_name, entry_t->d_name); + ft = fopen(path, "r"); + if (!ft) + continue; + getline(&buf, &n, ft); + if (buf && strncmp(buf, "CPU ", 4) == 0) { + cpu_str = buf; + while (*cpu_str != '\0' && + isdigit(*cpu_str) == 0) + cpu_str++; + if (*cpu_str != '\0') { + j = 0; + while (cpu_str[j] != '\0' && + isdigit(cpu_str[j]) != 0) + j++; + cpu_str[j] = '\0'; + vcpu = atoi(cpu_str); + if (vcpu < VCPUS_MAX) + guest.cpu_pid[vcpu] = atoi(entry_t->d_name); + } + } + free(buf); + fclose(ft); + buf = NULL; + } + } + guests = realloc(guests, (guests_len + 1) * sizeof(*guests)); if (!guests) die("Can not allocate guest buffer"); @@ -2875,6 +2920,16 @@ static char *parse_guest_name(char *guest, int *cid, int *port) return guest; } +int *get_guest_vcpu_pids(int cid) +{ + int i; + + for (i = 0; i < guests_len; i++) + if (cid == guests[i].cid) + return guests[i].cpu_pid; + return NULL; +} + static void set_prio(int prio) { struct sched_param sp; From patchwork Fri Feb 22 14:28:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzvetomir Stoyanov X-Patchwork-Id: 10826173 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 BA0F91399 for ; Fri, 22 Feb 2019 14:28:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7450303F5 for ; Fri, 22 Feb 2019 14:28:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B601327D6; Fri, 22 Feb 2019 14:28:49 +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 3916F303F5 for ; Fri, 22 Feb 2019 14:28:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725942AbfBVO2s (ORCPT ); Fri, 22 Feb 2019 09:28:48 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:38430 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726563AbfBVO2r (ORCPT ); Fri, 22 Feb 2019 09:28:47 -0500 Received: by mail-wr1-f67.google.com with SMTP id v13so2603663wrw.5 for ; Fri, 22 Feb 2019 06:28:45 -0800 (PST) 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=FpmFn+eSKyDCh89HNlwUJFpBfqqHYHWj1ZJ8cKffFu8=; b=QUSEngevR69CEmC+B3jxcl6DGif5D+KKR8SPpM60c+bAtkTiC/tzfx2/2NCSSva97n ydy9x3w8u//HT4K05T4JqSCO8/Y3muwF29hvc+rTebIVXkeJH+I0RGdZqYV7K7XfQkrc khr6333CBo37J8ziv/y5fD69Ap1611R2wRWSpO17OzD47R8NhpO3+TBvMSggnqnwA3YP CtlP8lFS682VrDA++znoyHcCkgwI2gaX1BGeZn9viVgtMRECLOSAh/G/JppSKjrqzRvp SwiBpENW6uRNLzCgImo9aexzVEChIR4VT0Cjzp+yv2U3n5+wFq+IpxBv2dQM9ZqeUfuX HH8w== X-Gm-Message-State: AHQUAuYKtFEkqqQOxDQdLc3Uy8ND4nvWjpYMurwZX6UNAZazrGCvqydJ sJeW/cg0HxXYYCktVr+Byg4= X-Google-Smtp-Source: AHgI3IaJ0vuPInTYDxJGpviyMZ1VyuGCTnNyoSiXvV1YHP6cwrTyd9RwChxjn1Eq9zlTMBcGkuOoJw== X-Received: by 2002:a5d:500e:: with SMTP id e14mr3034824wrt.219.1550845724575; Fri, 22 Feb 2019 06:28:44 -0800 (PST) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id q9sm848987wrv.26.2019.02.22.06.28.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Feb 2019 06:28:43 -0800 (PST) From: Tzvetomir Stoyanov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 7/7] trace-cmd [POC]: Implemented timestamps synch algorithm, using vsock events. Date: Fri, 22 Feb 2019 16:28:36 +0200 Message-Id: <20190222142836.12596-8-tstoyanov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190222142836.12596-1-tstoyanov@vmware.com> References: <20190222142836.12596-1-tstoyanov@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 This is a POC patch, implementing an algorithm for syncing timestamps between host and guest machines, using vsock trace events to catch the host / guest time. Signed-off-by: Tzvetomir Stoyanov --- include/trace-cmd/trace-cmd.h | 4 + tracecmd/include/trace-local.h | 13 + tracecmd/trace-listen.c | 3 + tracecmd/trace-msg.c | 477 ++++++++++++++++++++++++++++++++- tracecmd/trace-record.c | 156 ++++++++++- 5 files changed, 634 insertions(+), 19 deletions(-) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index 3f0ab4f..5469dee 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -346,6 +346,10 @@ int tracecmd_msg_recv_trace_resp(struct tracecmd_msg_handle *msg_handle, int *nr_cpus, int *page_size, unsigned int **ports, bool *use_fifos); +int tracecmd_msg_rcv_time_sync(struct tracecmd_msg_handle *msg_handle); +int tracecmd_msg_snd_time_sync(struct tracecmd_msg_handle *msg_handle, + char *clock_str, long long *toffset); + /* --- Plugin handling --- */ extern struct tep_plugin_option trace_ftrace_options[]; diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h index ef6848f..948cb06 100644 --- a/tracecmd/include/trace-local.h +++ b/tracecmd/include/trace-local.h @@ -236,6 +236,19 @@ void show_instance_file(struct buffer_instance *instance, const char *name); int count_cpus(void); +struct clock_synch_event_descr { + char *file; + char *set; + char *reset; +}; +struct buffer_instance *clock_synch_enable(char *clock, unsigned int cid, + struct clock_synch_event_descr *events); +void clock_synch_disable(struct buffer_instance *instance, + struct clock_synch_event_descr *events); +struct tep_handle *clock_synch_get_tep(struct buffer_instance *instance, + char **systems); +void get_vsocket_params(int fd, unsigned int *lcid, unsigned int *lport, + unsigned int *rcid, unsigned int *rport); #define VCPUS_MAX 256 int *get_guest_vcpu_pids(int cid); diff --git a/tracecmd/trace-listen.c b/tracecmd/trace-listen.c index 8bd7bad..7103a88 100644 --- a/tracecmd/trace-listen.c +++ b/tracecmd/trace-listen.c @@ -404,6 +404,9 @@ static int communicate_with_client(struct tracecmd_msg_handle *msg_handle) msg_handle->version = V3_PROTOCOL; + /* time sync with the v3 client */ + tracecmd_msg_rcv_time_sync(msg_handle); + /* read the CPU count, the page size, and options */ if ((pagesize = tracecmd_msg_initial_setting(msg_handle)) < 0) goto out; diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c index 065a01e..fddd327 100644 --- a/tracecmd/trace-msg.c +++ b/tracecmd/trace-msg.c @@ -18,16 +18,22 @@ #include #include #include +#include #include #include #include +#include #include "trace-cmd-local.h" #include "trace-local.h" #include "trace-msg.h" +typedef __u16 u16; +typedef __s16 s16; typedef __u32 u32; typedef __be32 be32; +typedef __u64 u64; +typedef __s64 s64; static inline void dprint(const char *fmt, ...) { @@ -50,6 +56,16 @@ static inline void dprint(const char *fmt, ...) unsigned int page_size; +/* Try a few times to get an accurate time sync */ +#define TSYNC_TRIES 300 + +struct clock_synch_event { + int id; + int cpu; + int pid; + unsigned long long ts; +}; + struct tracecmd_msg_opt { be32 size; be32 opt_cmd; @@ -76,6 +92,15 @@ struct tracecmd_msg_trace_resp { be32 page_size; } __attribute__((packed)); +struct tracecmd_msg_time_sync_init { + char clock[32]; +} __attribute__((packed)); + +struct tracecmd_msg_time_sync { + u64 tlocal_ts; + u16 tlocal_cpu; +} __attribute__((packed)); + struct tracecmd_msg_header { be32 size; be32 cmd; @@ -83,14 +108,16 @@ struct tracecmd_msg_header { } __attribute__((packed)); #define MSG_MAP \ - C(CLOSE, 0, 0), \ - C(TINIT, 1, sizeof(struct tracecmd_msg_tinit)), \ - C(RINIT, 2, sizeof(struct tracecmd_msg_rinit)), \ - C(SEND_DATA, 3, 0), \ - C(FIN_DATA, 4, 0), \ - C(NOT_SUPP, 5, 0), \ - C(TRACE_REQ, 6, sizeof(struct tracecmd_msg_trace_req)), \ - C(TRACE_RESP, 7, sizeof(struct tracecmd_msg_trace_resp)), + C(CLOSE, 0, 0), \ + C(TINIT, 1, sizeof(struct tracecmd_msg_tinit)), \ + C(RINIT, 2, sizeof(struct tracecmd_msg_rinit)), \ + C(SEND_DATA, 3, 0), \ + C(FIN_DATA, 4, 0), \ + C(NOT_SUPP, 5, 0), \ + C(TRACE_REQ, 6, sizeof(struct tracecmd_msg_trace_req)), \ + C(TRACE_RESP, 7, sizeof(struct tracecmd_msg_trace_resp)),\ + C(TIME_SYNC_INIT, 8, sizeof(struct tracecmd_msg_time_sync_init)),\ + C(TIME_SYNC, 9, sizeof(struct tracecmd_msg_time_sync)), #undef C #define C(a,b,c) MSG_##a = b @@ -120,10 +147,12 @@ static const char *cmd_to_name(int cmd) struct tracecmd_msg { struct tracecmd_msg_header hdr; union { - struct tracecmd_msg_tinit tinit; - struct tracecmd_msg_rinit rinit; - struct tracecmd_msg_trace_req trace_req; - struct tracecmd_msg_trace_resp trace_resp; + struct tracecmd_msg_tinit tinit; + struct tracecmd_msg_rinit rinit; + struct tracecmd_msg_trace_req trace_req; + struct tracecmd_msg_trace_resp trace_resp; + struct tracecmd_msg_time_sync_init time_sync_init; + struct tracecmd_msg_time_sync time_sync; }; union { struct tracecmd_msg_opt *opt; @@ -859,6 +888,430 @@ out: return ret; } +#define EVENTS_CHUNK 10 +static int +get_events_in_page(struct tep_handle *tep, void *page, + int size, int cpu, struct clock_synch_event **events, + int *events_count, int *events_size) +{ + struct clock_synch_event *events_array = NULL; + struct tep_record *last_record = NULL; + struct tep_event *event = NULL; + struct tep_record *record; + int id, cnt = 0; + + if (size <= 0) + return 0; + + if (*events == NULL) { + *events = malloc(EVENTS_CHUNK*sizeof(struct clock_synch_event)); + *events_size = EVENTS_CHUNK; + *events_count = 0; + } + + while (true) { + event = NULL; + record = tracecmd_read_page_record(tep, page, size, + last_record); + if (!record) + break; + free_record(last_record); + id = tep_data_type(tep, record); + event = tep_data_event_from_type(tep, id); + if (event) { + if (*events_count >= *events_size) { + events_array = realloc(*events, + (*events_size + EVENTS_CHUNK)*sizeof(struct clock_synch_event)); + if (events_array) { + *events = events_array; + (*events_size) += EVENTS_CHUNK; + } + } + + if (*events_count < *events_size) { + (*events)[*events_count].ts = record->ts; + (*events)[*events_count].cpu = cpu; + (*events)[*events_count].id = id; + (*events)[*events_count].pid = tep_data_pid(tep, record); + (*events_count)++; + } + } + last_record = record; + } + free_record(last_record); + + return cnt; +} + +static int +find_sync_events(struct tep_handle *pevent, struct clock_synch_event *recorded, + int rsize, struct clock_synch_event *events) +{ + int i = 0, j = 0; + + while (i < rsize) { + if (!events[j].ts && events[j].id == recorded[i].id && + (!events[j].pid || events[j].pid == recorded[i].pid)) { + events[j].cpu = recorded[i].cpu; + events[j].ts = recorded[i].ts; + j++; + } else if (j > 0 && events[j-1].id == recorded[i].id && + (!events[j-1].pid || events[j-1].pid == recorded[i].pid)) { + events[j-1].cpu = recorded[i].cpu; + events[j-1].ts = recorded[i].ts; + } + i++; + } + return j; +} + +static int sync_events_cmp(const void *a, const void *b) +{ + const struct clock_synch_event *ea = (const struct clock_synch_event *)a; + const struct clock_synch_event *eb = (const struct clock_synch_event *)b; + + if (ea->ts > eb->ts) + return 1; + if (ea->ts < eb->ts) + return -1; + return 0; +} + +static int clock_synch_find_events(struct tep_handle *tep, + struct buffer_instance *instance, + struct clock_synch_event *events) +{ + struct clock_synch_event *events_array = NULL; + int events_count = 0; + int events_size = 0; + struct dirent *dent; + int ts = 0; + void *page; + char *path; + char *file; + DIR *dir; + int cpu; + int len; + int fd; + int r; + + page_size = getpagesize(); +#ifdef TSYNC_RBUFFER_DEBUG + file = get_instance_file(instance, "trace"); + if (!file) + return ts; + { + char *buf = NULL; + FILE *fp; + size_t n; + int r; + + printf("Events:\n\r"); + fp = fopen(file, "r"); + while ((r = getline(&buf, &n, fp)) >= 0) { + + if (buf[0] != '#') + printf("%s", buf); + + free(buf); + buf = NULL; + } + fclose(fp); + } + tracecmd_put_tracing_file(file); +#endif /* TSYNC_RBUFFER_DEBUG */ + path = get_instance_file(instance, "per_cpu"); + if (!path) + return ts; + + dir = opendir(path); + if (!dir) + goto out; + + len = strlen(path); + file = malloc(len + strlen("trace_pipe_raw") + 32); + page = malloc(page_size); + if (!file || !page) + die("Failed to allocate time_stamp info"); + + while ((dent = readdir(dir))) { + + const char *name = dent->d_name; + + if (strncmp(name, "cpu", 3) != 0) + continue; + cpu = atoi(&name[3]); + sprintf(file, "%s/%s/trace_pipe_raw", path, name); + fd = open(file, O_RDONLY | O_NONBLOCK); + if (fd < 0) + continue; + do { + r = read(fd, page, page_size); + if (r > 0) { + get_events_in_page(tep, page, r, cpu, + &events_array, &events_count, + &events_size); + } + } while (r > 0); + close(fd); + } + qsort(events_array, events_count, sizeof(*events_array), sync_events_cmp); + r = find_sync_events(tep, events_array, events_count, events); +#ifdef TSYNC_RBUFFER_DEBUG + len = 0; + while (events[len].id) { + printf("Found %d @ cpu %d: %lld\n\r", + events[len].id, events[len].cpu, events[len].ts); + len++; + } +#endif + free(events_array); + free(file); + free(page); + closedir(dir); + + out: + tracecmd_put_tracing_file(path); + return r; +} + +int tracecmd_msg_rcv_time_sync(struct tracecmd_msg_handle *msg_handle) +{ + unsigned int lcid, lport, rcid, rport; + struct clock_synch_event events[3]; + struct buffer_instance *vinst; + char vsock_rx_filter[255]; + struct tep_event *event; + struct tracecmd_msg msg; + struct tep_handle *tep; + int *cpu_pid = NULL; + int ret, cpu; + char *clock; + char *systems[] = {"vsock", "kvm", NULL}; + struct clock_synch_event_descr events_descr[] = { + {"events/kvm/kvm_exit/enable", "1", "0"}, + {"events/vsock/virtio_transport_recv_pkt/enable", "1", "0"}, + {"events/vsock/virtio_transport_recv_pkt/filter", vsock_rx_filter, "\0"}, + {NULL, NULL, NULL} + }; + + ret = tracecmd_msg_recv(msg_handle->fd, &msg); + if (ret < 0 || ntohl(msg.hdr.cmd) != MSG_TIME_SYNC_INIT) + return 0; + if (!msg.time_sync_init.clock[0]) + return 0; + clock = strdup(msg.time_sync_init.clock); + memset(events, 0, sizeof(struct clock_synch_event)*3); + + rcid = 0; + get_vsocket_params(msg_handle->fd, &lcid, &lport, &rcid, &rport); + if (rcid) + cpu_pid = get_guest_vcpu_pids(rcid); + snprintf(vsock_rx_filter, 255, + "src_cid==%u && src_port==%u && dst_cid==%u && dst_port==%u && len!=0", + rcid, rport, lcid, lport); + + vinst = clock_synch_enable(clock, rcid, events_descr); + tep = clock_synch_get_tep(vinst, systems); + event = tep_find_event_by_name(tep, "kvm", "kvm_exit"); + if (event) + events[0].id = event->id; + event = tep_find_event_by_name(tep, "vsock", "virtio_transport_recv_pkt"); + if (event) + events[1].id = event->id; + tracecmd_msg_init(MSG_TIME_SYNC_INIT, &msg); + tracecmd_msg_send(msg_handle->fd, &msg); + + do { + events[0].ts = 0; /* kvm exit ts */ + events[0].pid = 0; + events[1].ts = 0; /* vsock receive ts */ + ret = tracecmd_msg_recv(msg_handle->fd, &msg); + if (ret < 0 || ntohl(msg.hdr.cmd) != MSG_TIME_SYNC) + break; + ret = tracecmd_msg_recv(msg_handle->fd, &msg); + if (ret < 0 || ntohl(msg.hdr.cmd) != MSG_TIME_SYNC) + break; + /* Get kvm_exit events related to the corresponding VCPU */ + cpu = ntohs(msg.time_sync.tlocal_cpu); + if (cpu_pid && cpu < VCPUS_MAX) + events[0].pid = cpu_pid[cpu]; + ret = clock_synch_find_events(tep, vinst, events); + tracecmd_msg_init(MSG_TIME_SYNC, &msg); + msg.time_sync.tlocal_ts = htonll(events[0].ts); + tracecmd_msg_send(msg_handle->fd, &msg); + } while (true); + clock_synch_disable(vinst, events_descr); + msg_free(&msg); + tep_free(tep); + free(clock); + return 0; +} + +int tracecmd_msg_snd_time_sync(struct tracecmd_msg_handle *msg_handle, + char *clock_str, long long *toffset) +{ + static struct buffer_instance *vinst; + struct clock_synch_event events_s[3]; + struct tracecmd_msg msg_resp; + struct tracecmd_msg msg_req; + int sync_loop = TSYNC_TRIES; + long long min = 0, max = 0; + long long offset_av = 0; + struct tep_event *event; + struct tep_handle *tep; + int k = 0, n, ret = 0; + long long tresch = 0; + long long offset = 0; + long long m_t1 = 0; + long long s_t2 = 0; + long long *offsets; + int probes = 0; + char *clock; + char vsock_tx_filter[255]; + unsigned int lcid, lport, rcid, rport; + char *systems[] = {"vsock", "ftrace", NULL}; + struct clock_synch_event_descr events_descr[] = { + {"set_ftrace_filter", "vp_notify", "\0"}, + {"current_tracer", "function", "nop"}, + {"events/vsock/virtio_transport_alloc_pkt/enable", "1", "0"}, + {"events/vsock/virtio_transport_alloc_pkt/filter", vsock_tx_filter, "\0"}, + {NULL, NULL, NULL} + }; +#ifdef TSYNC_DEBUG +/* Write all ts in a file, used to analyze the raw data */ + struct timespec tsStart, tsEnd; + int zm = 0, zs = 0; + long long duration; + char buff[256]; + int iFd; +#endif + + clock = clock_str; + if (!clock) + clock = "local"; + + tracecmd_msg_init(MSG_TIME_SYNC_INIT, &msg_req); + if (toffset == NULL) { + msg_req.time_sync_init.clock[0] = 0; + tracecmd_msg_send(msg_handle->fd, &msg_req); + return 0; + } + offsets = calloc(sizeof(long long), TSYNC_TRIES); + if (!offsets) + return 0; + + strncpy(msg_req.time_sync_init.clock, clock, 32); + tracecmd_msg_send(msg_handle->fd, &msg_req); + ret = tracecmd_msg_recv(msg_handle->fd, &msg_resp); + if (ret < 0 || ntohl(msg_resp.hdr.cmd) != MSG_TIME_SYNC_INIT) { + free(offsets); + return 0; + } + get_vsocket_params(msg_handle->fd, &lcid, &lport, &rcid, &rport); + snprintf(vsock_tx_filter, 255, + "src_cid==%u && src_port==%u && dst_cid==%u && dst_port==%u && len!=0", + lcid, lport, rcid, rport); + + memset(events_s, 0, sizeof(struct clock_synch_event)*3); + vinst = clock_synch_enable(clock_str, rcid, events_descr); + tep = clock_synch_get_tep(vinst, systems); + event = tep_find_event_by_name(tep, "vsock", "virtio_transport_alloc_pkt"); + if (event) + events_s[0].id = event->id; + event = tep_find_event_by_name(tep, "ftrace", "function"); + if (event) + events_s[1].id = event->id; + + *toffset = 0; +#ifdef TSYNC_DEBUG + sprintf(buff, "s-%s.txt", clock); + iFd = open(buff, O_CREAT|O_WRONLY|O_TRUNC, 0644); + clock_gettime(CLOCK_MONOTONIC, &tsStart); +#endif + do { + memset(&msg_resp, 0, sizeof(msg_resp)); + events_s[0].ts = 0; /* vsock send ts */ + events_s[0].cpu = 0; + events_s[1].ts = 0; /* vp_notify ts */ + events_s[1].cpu = 0; + tracecmd_msg_init(MSG_TIME_SYNC, &msg_req); + tracecmd_msg_send(msg_handle->fd, &msg_req); + /* Get the ts and CPU of the sent event */ + clock_synch_find_events(tep, vinst, events_s); + tracecmd_msg_init(MSG_TIME_SYNC, &msg_req); + msg_req.time_sync.tlocal_ts = htonll(events_s[0].ts); + msg_req.time_sync.tlocal_cpu = htons(events_s[0].cpu); + tracecmd_msg_send(msg_handle->fd, &msg_req); + ret = tracecmd_msg_recv(msg_handle->fd, &msg_resp); + if (ret < 0 || ntohl(msg_resp.hdr.cmd) != MSG_TIME_SYNC) + break; + m_t1 = events_s[1].ts; + s_t2 = htonll(msg_resp.time_sync.tlocal_ts); /* Client kvm exit ts */ +#ifdef TSYNC_DEBUG + if (!s_t2) + zs++; + if (!m_t1) + zm++; +#endif + if (!s_t2 || !m_t1) + continue; + offsets[probes] = s_t2 - m_t1; + offset_av += offsets[probes]; + if (!min || min > llabs(offsets[probes])) + min = llabs(offsets[probes]); + if (!max || max < llabs(offsets[probes])) + max = llabs(offsets[probes]); + probes++; +#ifdef TSYNC_DEBUG + sprintf(buff, "%lld %lld\n", m_t1, s_t2); + write(iFd, buff, strlen(buff)); +#endif + } while (--sync_loop); + +#ifdef TSYNC_DEBUG + clock_gettime(CLOCK_MONOTONIC, &tsEnd); + close(iFd); +#endif + clock_synch_disable(vinst, events_descr); + if (probes) + offset_av /= (long long)probes; + tresch = (long long)((max - min)/10); + for (n = 0; n < TSYNC_TRIES; n++) { + /* filter the offsets with deviation up to 10% */ + if (offsets[n] && + llabs(offsets[n] - offset_av) < tresch) { + offset += offsets[n]; + k++; + } + } + if (k) + offset /= (long long)k; + + tracecmd_msg_init(MSG_TIME_SYNC_INIT, &msg_req); + msg_req.time_sync_init.clock[0] = 0; + tracecmd_msg_send(msg_handle->fd, &msg_req); + + msg_free(&msg_req); + msg_free(&msg_resp); + free(offsets); + + *toffset = offset; + +#ifdef TSYNC_DEBUG + duration = tsEnd.tv_sec * 1000000000LL; + duration += tsEnd.tv_nsec; + duration -= (tsStart.tv_sec * 1000000000LL); + duration -= tsStart.tv_nsec; + + printf("\n selected: %lld (in %lld ns), used %s clock, %d probes\n\r", + *toffset, duration, clock, probes); + printf("\t good probes: %d / %d, threshold %lld, Zm %d, Zs %d\n\r", + k, TSYNC_TRIES, tresch, zm, zs); +#endif + return 0; +} + static int make_trace_resp(struct tracecmd_msg *msg, int page_size, int nr_cpus, unsigned int *ports, bool use_fifos) { diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 59f0197..21be253 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -224,6 +224,12 @@ struct common_record_context { int run_command; }; +enum { + DATA_FL_NONE = 0, + DATA_FL_DATE = 1, + DATA_FL_OFFSET = 2, +}; + static void add_reset_file(const char *file, const char *val, int prio) { struct reset_file *reset; @@ -3215,6 +3221,39 @@ static void check_protocol_version(struct tracecmd_msg_handle *msg_handle) } } +static void sync_time_with_listener_v3(struct tracecmd_msg_handle *msg_handle, + struct common_record_context *ctx) +{ + struct buffer_instance *instance; + long long toffset = 0; + char *clock = NULL; + + instance = ctx->instance; + while (instance) { + clock = instance->clock; + if (clock) + break; + instance = instance->next; + } + + if (ctx->data_flags & DATA_FL_DATE || + ctx->data_flags & DATA_FL_OFFSET) { + tracecmd_msg_snd_time_sync(msg_handle, clock, NULL); + return; + } + + tracecmd_msg_snd_time_sync(msg_handle, clock, &toffset); + + free(ctx->date2ts); + /* 21 digits + \0 */ + ctx->date2ts = malloc(22); + if (ctx->date2ts) { + snprintf(ctx->date2ts, 22, "%lld", toffset); + ctx->data_flags |= DATA_FL_OFFSET; + } + +} + static struct tracecmd_msg_handle *setup_network(struct buffer_instance *instance) { struct tracecmd_msg_handle *msg_handle = NULL; @@ -3406,6 +3445,8 @@ static void connect_to_agent(struct buffer_instance *instance) /* the msg_handle now points to the guest fd */ instance->msg_handle = msg_handle; + + tracecmd_msg_rcv_time_sync(msg_handle); } static void setup_guest(struct buffer_instance *instance) @@ -3430,10 +3471,13 @@ static void setup_guest(struct buffer_instance *instance) close(fd); } -static void setup_agent(struct buffer_instance *instance, struct common_record_context *ctx) +static void setup_agent(struct buffer_instance *instance, + struct common_record_context *ctx) { struct tracecmd_output *network_handle; + sync_time_with_listener_v3(instance->msg_handle, ctx); + network_handle = tracecmd_create_init_fd_msg(instance->msg_handle, listed_events); add_options(network_handle, ctx); @@ -3620,12 +3664,6 @@ static void print_stat(struct buffer_instance *instance) trace_seq_do_printf(&instance->s_print[cpu]); } -enum { - DATA_FL_NONE = 0, - DATA_FL_DATE = 1, - DATA_FL_OFFSET = 2, -}; - static void add_options(struct tracecmd_output *handle, struct common_record_context *ctx) { int type = 0; @@ -5895,3 +5933,107 @@ int trace_record_agent(struct tracecmd_msg_handle *msg_handle, free(argv_plus); return 0; } + +void get_vsocket_params(int fd, unsigned int *lcid, unsigned int *lport, + unsigned int *rcid, unsigned int *rport) +{ + struct sockaddr_vm addr; + socklen_t addr_len = sizeof(addr); + + if (lcid || lport) { + memset(&addr, 0, sizeof(addr)); + if (getsockname(fd, (struct sockaddr *)&addr, &addr_len)) + return; + if (addr.svm_family != AF_VSOCK) + return; + if (lport) + *lport = addr.svm_port; + if (lcid) + *lcid = addr.svm_cid; + } + + if (rcid || rport) { + memset(&addr, 0, sizeof(addr)); + addr_len = sizeof(addr); + if (getpeername(fd, (struct sockaddr *)&addr, &addr_len)) + return; + if (addr.svm_family != AF_VSOCK) + return; + + if (rport) + *rport = addr.svm_port; + if (rcid) + *rcid = addr.svm_cid; + } +} + +static void set_clock_synch_events(struct buffer_instance *instance, + struct clock_synch_event_descr *events, + bool enable) +{ + int i = 0; + + if (!enable) + write_tracing_on(instance, 0); + + while (events[i].file) { + if (enable && events[i].set) + write_instance_file(instance, events[i].file, + events[i].set, NULL); + if (!enable && events[i].reset) + write_instance_file(instance, events[i].file, + events[i].reset, NULL); + i++; + } + + if (enable) + write_tracing_on(instance, 1); +} + +static void vsock_trace_reset(struct buffer_instance *vinst) +{ + write_instance_file(vinst, "trace", "\0", NULL); +} + +struct tep_handle *clock_synch_get_tep(struct buffer_instance *instance, char **systems) +{ + struct tep_handle *tep = NULL; + char *path; + + path = get_instance_dir(instance); + tep = tracecmd_local_events_system(path, systems); + tracecmd_put_tracing_file(path); + + tep_set_file_bigendian(tep, tracecmd_host_bigendian()); + tep_set_host_bigendian(tep, tracecmd_host_bigendian()); + + return tep; +} + +struct buffer_instance *clock_synch_enable(char *clock, unsigned int cid, + struct clock_synch_event_descr *events) +{ + struct buffer_instance *vinst; + char inst_name[256]; + + snprintf(inst_name, 256, "clock_synch-%d", cid); + + vinst = create_instance(strdup(inst_name)); + init_instance(vinst); + vinst->cpu_count = local_cpu_count; + make_instance(vinst); + vsock_trace_reset(vinst); + if (clock) + vinst->clock = strdup(clock); + set_clock(vinst); + set_clock_synch_events(vinst, events, true); + return vinst; +} + +void clock_synch_disable(struct buffer_instance *instance, + struct clock_synch_event_descr *events) +{ + set_clock_synch_events(instance, events, false); + tracecmd_remove_instance(instance); + /* todo: clean up the instance */ +}