From patchwork Mon Mar 22 09:59:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154259 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 0D917C433E3 for ; Mon, 22 Mar 2021 10:00:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BDBC461969 for ; Mon, 22 Mar 2021 10:00:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229760AbhCVJ74 (ORCPT ); Mon, 22 Mar 2021 05:59:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229984AbhCVJ7v (ORCPT ); Mon, 22 Mar 2021 05:59:51 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC886C061756 for ; Mon, 22 Mar 2021 02:59:49 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id ce10so20170022ejb.6 for ; Mon, 22 Mar 2021 02:59:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=09RpGejqRrze5SeuipDniSUDcgkfl3OwifqJlL8SHX4=; b=oUWtQVGD6jGu5sNReRTsdZTkLOCAL+oOASj5aogtr/T2LC+0iVKqIslnlg51xrugNZ gzQzKkoLFbOvPKXH4VygcMgkJ+9NZSBE9epm7OgfDQAwIB7xyUE8HF39qw9Fr3VsWBd4 Yx8x8+Jcdt1hYvkBrAtLYw4EV5TZTsdg1Q3nJf8xFQ6qsIFKEJBXkQMqM+uD8Yl0aG4C LaODm7zWKjhu9q4mIjn1dGynAwUVz7aHyhqegy9sM58Ixo8/yUCp+5Ns3FXM7pmX4TlK exnYkC0NXbEx/0bUDI/6TuMS5TykFE78bgSthqiMw44PTDl0+zNCljLy2b8Rru+FBetK Fi4w== 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=09RpGejqRrze5SeuipDniSUDcgkfl3OwifqJlL8SHX4=; b=ZpzjSpVBTBMAs7rRA1HU8W8eLPCOwQS6MW3AXw7VjkpMTczbVqiwylt15gJAX3n7MW eUl2jTKwgZz+H8ufoEygGfFwQ1W4RwwceQOHDYRRIWAIrFZ+Ni9T0UXUgkaFzizj/x6Z s8X1Cu8aOVVbdyj8B8mdPrP6Wf/d38oNpSK5omg3MBYWwKJKdp3tEvPYQPY3ZNQirj29 Fa4l2FrHoZfpIgunhqlxY4lufsxjuCl0ymGAB8uZpXArKxKsRGV7quLFeCfdv+YhjIwR fMaSNt5voEHyUhqqmh1qzSN9vlApxrr0/RAF7EwqErJKSykqOdM2AL8kCtXo29ln9SIx mULA== X-Gm-Message-State: AOAM532Xnl5jcCUH388h1P1bsGgJNODj6o02lNd6cYEix2jJ41b5rdaS lkP+9DOZ5F2E4FUGzmhBHW4= X-Google-Smtp-Source: ABdhPJyeL6ITNvxAR2nSOwurmIm1+Z49c1b6N+9BP2lbdelKPEfafRaEG8TovdJXSEodsLSRAQy4vA== X-Received: by 2002:a17:907:9862:: with SMTP id ko2mr17992322ejc.222.1616407188467; Mon, 22 Mar 2021 02:59:48 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.02.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 02:59:47 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 01/18] trace-cmd: Add initial perf interface in trace-cmd library Date: Mon, 22 Mar 2021 11:59:28 +0200 Message-Id: <20210322095945.259300-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Add new trace-cmd library internal APIs for working with perf. These initial APIs offer only basic functionality - init, open and close a perf session: trace_perf_init(); trace_perf_close(); trace_perf_open(); Signed-off-by: Tzvetomir Stoyanov (VMware) --- Makefile | 6 + lib/trace-cmd/Makefile | 3 + .../include/private/trace-cmd-private.h | 17 +++ lib/trace-cmd/trace-perf.c | 105 ++++++++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 lib/trace-cmd/trace-perf.c diff --git a/Makefile b/Makefile index fae43ff8..1c684af8 100644 --- a/Makefile +++ b/Makefile @@ -298,6 +298,12 @@ ifeq ($(VSOCK_DEFINED), 1) CFLAGS += -DVSOCK endif +PERF_DEFINED := $(shell if (echo "$(pound)include " | $(CC) -E - >/dev/null 2>&1) ; then echo 1; else echo 0 ; fi) +export PERF_DEFINED +ifeq ($(PERF_DEFINED), 1) +CFLAGS += -DPERF +endif + CUNIT_INSTALLED := $(shell if (printf "$(pound)include \n void main(){CU_initialize_registry();}" | $(CC) -o /dev/null -x c - -lcunit >/dev/null 2>&1) ; then echo 1; else echo 0 ; fi) export CUNIT_INSTALLED diff --git a/lib/trace-cmd/Makefile b/lib/trace-cmd/Makefile index 2f553ed5..aa92c8c0 100644 --- a/lib/trace-cmd/Makefile +++ b/lib/trace-cmd/Makefile @@ -17,6 +17,9 @@ OBJS += trace-util.o OBJS += trace-filter-hash.o OBJS += trace-msg.o OBJS += trace-plugin.o +ifeq ($(PERF_DEFINED), 1) +OBJS += trace-perf.o +endif OBJS += trace-timesync.o # Additional util objects diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index 6b32ce58..27f4c9c3 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -512,5 +512,22 @@ void *tracecmd_record_page(struct tracecmd_input *handle, struct tep_record *record); void *tracecmd_record_offset(struct tracecmd_input *handle, struct tep_record *record); +#ifdef PERF + +#include + +/* trace-cmd Perf */ +struct trace_perf { + int fd; + int cpu; + int pid; + int pages; + struct perf_event_attr pe; + struct perf_event_mmap_page *mmap; +}; +int trace_perf_init(struct trace_perf *perf, int pages, int cpu, int pid); +int trace_perf_open(struct trace_perf *perf); +void trace_perf_close(struct trace_perf *perf); +#endif #endif /* _TRACE_CMD_PRIVATE_H */ diff --git a/lib/trace-cmd/trace-perf.c b/lib/trace-cmd/trace-perf.c new file mode 100644 index 00000000..f3ee692d --- /dev/null +++ b/lib/trace-cmd/trace-perf.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: LGPL-2.1 +/* + * Copyright (C) 2021, VMware, Tzvetomir Stoyanov + * + */ +#include +#include +#include + +#include "trace-cmd-private.h" + +static void default_perf_init_pe(struct perf_event_attr *pe) +{ + pe->type = PERF_TYPE_SOFTWARE; + pe->sample_type = PERF_SAMPLE_CPU; + pe->size = sizeof(struct perf_event_attr); + pe->config = PERF_COUNT_HW_CPU_CYCLES; + pe->disabled = 1; + pe->exclude_kernel = 1; + pe->freq = 1; + pe->sample_freq = 1000; + pe->inherit = 1; + pe->mmap = 1; + pe->comm = 1; + pe->task = 1; + pe->precise_ip = 1; + pe->sample_id_all = 1; + pe->read_format = PERF_FORMAT_ID | + PERF_FORMAT_TOTAL_TIME_ENABLED | + PERF_FORMAT_TOTAL_TIME_RUNNING; +} + +/** + * trace_perf_init - Initialize perf context + * + * @perf: structure, representing perf context, that will be initialized. + * @pages: Number of perf memory mapped pages. + * @cpu: CPU number, associated with this perf context. + * @pid: PID, associated with this perf context. + * + * The perf context in initialized with default values. The caller can set + * custom perf parameters in perf->pe, before calling trace_perf_open() API. + * + * Returns 0 on success, or -1 in case of an error. + * + */ +int trace_perf_init(struct trace_perf *perf, int pages, int cpu, int pid) +{ + if (!perf) + return -1; + + memset(perf, 0, sizeof(struct trace_perf)); + default_perf_init_pe(&perf->pe); + perf->cpu = cpu; + perf->pages = pages; + perf->pid = pid; + perf->fd = -1; + + return 0; +} + +/** + * trace_perf_close - Close perf session + * + * @perf: structure, representing context of a running perf session, opened + * with trace_perf_open() + * + */ +void trace_perf_close(struct trace_perf *perf) +{ + if (perf->fd >= 0) + close(perf->fd); + perf->fd = -1; + if (perf->mmap) + munmap(perf->mmap, (perf->pages + 1) * getpagesize()); + perf->mmap = NULL; +} + +/** + * trace_perf_open - Open perf session + * + * @perf: structure, representing perf context that will be opened. It must be + * initialized with trace_perf_init(). + * + * Returns 0 on success, or -1 in case of an error. In case of success, the + * session must be closed with trace_perf_close() + */ +int trace_perf_open(struct trace_perf *perf) +{ + perf->fd = syscall(__NR_perf_event_open, &perf->pe, perf->pid, perf->cpu, -1, 0); + if (perf->fd < 0) + return -1; + fcntl(perf->fd, F_SETFL, O_NONBLOCK); + + perf->mmap = mmap(NULL, (perf->pages + 1) * getpagesize(), + PROT_READ | PROT_WRITE, MAP_SHARED, perf->fd, 0); + if (perf->mmap == MAP_FAILED) + goto error; + + return 0; + +error: + trace_perf_close(perf); + return -1; +} From patchwork Mon Mar 22 09:59:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154253 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 347A0C433E0 for ; Mon, 22 Mar 2021 10:00:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E9E726192A for ; Mon, 22 Mar 2021 10:00:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229548AbhCVJ74 (ORCPT ); Mon, 22 Mar 2021 05:59:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230012AbhCVJ7v (ORCPT ); Mon, 22 Mar 2021 05:59:51 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2F0EC061762 for ; Mon, 22 Mar 2021 02:59:50 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id jy13so20164591ejc.2 for ; Mon, 22 Mar 2021 02:59:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bkMemzN07X64imp97CYxdrPc7SsdcDc77EC0gds/d2Q=; b=ITEFWlq2VgLg9NoCVNsSe704Kmivs6i79hruJm4ksMZAoMAnBbTHPgaJ0S2poW68i3 N5Sdz+c32tMFGTYqlXKBNTbvseD+IV8qyDKcpP9PYKgtvJO2cmnd5wx8IDj3LRoPRLcS F9CZ7vXv2zc5ZA6IatcqChcigusWnqyGQ0kT5L14DjOQn57OgFZdZo8Lfl1KzWRr0/uT VxBJ3aabrA4zReqbjwP170QBWe45Z1lllTFIdHNm0etLOtad98n5xnpHZa7ZS6AoKPK6 KyycGu7sZdzWkxPnE0cMvfhnc1LDUSmD9AAk8f45jab4taEa6eu4nAew/Fo63MAwNWC2 yq0w== 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=bkMemzN07X64imp97CYxdrPc7SsdcDc77EC0gds/d2Q=; b=WPGCn9ODlTYIJW0ARws3SRLttAdtzdNtSmO9VPhK9vEHyG45ejSxTqIxrladEHlJQT R0NXsxlNgH6UdVRA+oO33O2WP37OY/dWgKwHPb/FKBEHcmnI5qlyE36tSUHFhzCorskK njVxPvW0FaKFJmSrLectenwdg82vYu80fqY0b5PgF5mDpHCd6BRoulqEt+/2zM549wIP Bd8S8gfZuOvWefs7vxwiVKM9QBiD4Qe35krV/Z7IvLs5Hqt/7WK00tES4l9flkRQquI2 ZgPvkpHc2XuMemWZm9LcZdeNGNO51k/VIRRa/W8vn62vOAdMkn8x9ZRs5RZB51SYgoIj rdqg== X-Gm-Message-State: AOAM531sWWOTETixI/8anPMr7TtaY8QnqpzXHhHqD3RGpRTPqVLGmvHq TO08qJRSh6fGZr4LSj7GwdA= X-Google-Smtp-Source: ABdhPJyMVLSKglqstxAwJKJ/gaW1sYuDiuLh9rJa9jyYxvOYF7LJLQY6tCKp8qfO7Gc9iN/Wz9xjHw== X-Received: by 2002:a17:906:7102:: with SMTP id x2mr18579527ejj.355.1616407189306; Mon, 22 Mar 2021 02:59:49 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.02.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 02:59:48 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 02/18] trace-cmd: Extend trace-cmd dump subcommand to display the clock Date: Mon, 22 Mar 2021 11:59:29 +0200 Message-Id: <20210322095945.259300-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Trace clock, used to record the tracing data is saved in the trace.dat file. As "trace-cmd dump" command shows the metadata content of the file, it should display the trace clock also. Added a new parameter "trace-cmd dump --clock" which shows the clock saved in the file. The clock can be displayed also with "trace-cmd dump --all" Signed-off-by: Tzvetomir Stoyanov (VMware) --- Documentation/trace-cmd/trace-cmd-dump.1.txt | 2 ++ tracecmd/trace-dump.c | 34 +++++++++++++++++++- tracecmd/trace-usage.c | 1 + 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Documentation/trace-cmd/trace-cmd-dump.1.txt b/Documentation/trace-cmd/trace-cmd-dump.1.txt index 71b8e655..0f8626fa 100644 --- a/Documentation/trace-cmd/trace-cmd-dump.1.txt +++ b/Documentation/trace-cmd/trace-cmd-dump.1.txt @@ -46,6 +46,8 @@ OPTIONS Print all options, stored in the file. *--flyrecord*:: Print the offset and the size of tracing data per each CPU. +*--clock*:: + Print the trace clock, used for timestamp of the tracing events, stored in the file. *--all*:: Print all meta data from the file. *--help*:: diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 6172231e..4bdfd53f 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -24,6 +24,7 @@ static struct tep_handle *tep; static unsigned int trace_cpus; +static int has_clock; enum dump_items { SUMMARY = (1 << 0), @@ -37,6 +38,7 @@ enum dump_items { CMDLINES = (1 << 8), OPTIONS = (1 << 9), FLYRECORD = (1 << 10), + CLOCK = (1 << 11), }; enum dump_items verbosity; @@ -496,7 +498,7 @@ static void dump_options(int fd) die("cannot read the option size"); count++; - if (!DUMP_CHECK(OPTIONS)) { + if (!DUMP_CHECK(OPTIONS) && !DUMP_CHECK(CLOCK)) { lseek64(fd, size, SEEK_CUR); continue; } @@ -512,6 +514,7 @@ static void dump_options(int fd) break; case TRACECMD_OPTION_TRACECLOCK: dump_option_string(fd, size, "TRACECLOCK"); + has_clock = 1; break; case TRACECMD_OPTION_UNAME: dump_option_string(fd, size, "UNAME"); @@ -556,6 +559,29 @@ static void dump_latency(int fd) do_print(SUMMARY, "\t[Latency tracing data]\n"); } +static void dump_clock(int fd) +{ + long long size; + char *clock; + + do_print((SUMMARY | CLOCK), "\t[Tracing clock]\n"); + if (!has_clock) { + do_print((SUMMARY | CLOCK), "\t\t No tracing clock saved in the file\n"); + return; + } + if (read_file_number(fd, &size, 8)) + die("cannot read clock size"); + clock = calloc(1, size); + if (!clock) + die("cannot allocate clock %d bytes", size); + + if (read_file_bytes(fd, clock, size)) + die("cannot read clock %d bytes", size); + clock[size] = 0; + do_print((SUMMARY | CLOCK), "\t\t%s\n", clock); + free(clock); +} + static void dump_flyrecord(int fd) { long long cpu_offset; @@ -572,6 +598,7 @@ static void dump_flyrecord(int fd) do_print(FLYRECORD, "\t\t %lld %lld\t[offset, size of cpu %d]\n", cpu_offset, cpu_size, i); } + dump_clock(fd); } static void dump_therest(int fd) @@ -626,6 +653,7 @@ static void dump_file(const char *file) } enum { + OPT_clock = 243, OPT_all = 244, OPT_summary = 245, OPT_flyrecord = 246, @@ -666,6 +694,7 @@ void trace_dump(int argc, char **argv) {"cmd-lines", no_argument, NULL, OPT_cmd_lines}, {"options", no_argument, NULL, OPT_options}, {"flyrecord", no_argument, NULL, OPT_flyrecord}, + {"clock", no_argument, NULL, OPT_clock}, {"validate", no_argument, NULL, 'v'}, {"help", no_argument, NULL, '?'}, {NULL, 0, NULL, 0} @@ -721,6 +750,9 @@ void trace_dump(int argc, char **argv) case OPT_head_page: verbosity |= HEAD_PAGE; break; + case OPT_clock: + verbosity |= CLOCK; + break; default: usage(argv); } diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c index 1a7abd58..22537d20 100644 --- a/tracecmd/trace-usage.c +++ b/tracecmd/trace-usage.c @@ -377,6 +377,7 @@ static struct usage_help usage_help[] = { " --cmd-lines print information mapping a PID to a process name\n" " --options print options\n" " --flyrecord information of offset and count of recorded events per CPU\n" + " --clock trace clock, saved in the file\n" " -h, --help show usage information\n" }, { From patchwork Mon Mar 22 09:59:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154257 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 A1942C433E1 for ; Mon, 22 Mar 2021 10:00:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 794BD61969 for ; Mon, 22 Mar 2021 10:00:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229508AbhCVJ7z (ORCPT ); Mon, 22 Mar 2021 05:59:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230016AbhCVJ7v (ORCPT ); Mon, 22 Mar 2021 05:59:51 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F8B2C061763 for ; Mon, 22 Mar 2021 02:59:51 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id kt15so10700148ejb.12 for ; Mon, 22 Mar 2021 02:59:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+xeRlthL1+GIubmgF5iUWUn30iJC7ShY382hQ6L4NE4=; b=K/HFWzsmTrZRbzoLuG/g1L0avaOamWdw77cp59xccB98vCGjSnjT4QFwUZ8mgWEiPa +x8Z38jE2W+5xrG/LTbjULP9KKPQdTv+QxmQpDDtfXdmMTtWnSFJh6ue3kI2YAnoshAK wbKBxmeDZCwiL4x4DYh1BONowyrd5BiWauVp3LqVii1qPESN8/8sWiGORDnevsxczASs g/3ZQci121gM0sxBWhhRsIqyHakuLtvPQzFrjPxhd2SGuNo400kMFs7+m8Enrw1gMapp XGglA+ni8HueUjUvtgNhKznFmRKk9UVV/U8BDCJTt49GUxRgXc4q/MFfH+/Wt4pR8MuL 9SGw== 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=+xeRlthL1+GIubmgF5iUWUn30iJC7ShY382hQ6L4NE4=; b=H1zjX+uooJlbL2yZ5t+/ltLDRoD5JydMaRmejLNwYD/jGSjga/az4KDJQSSLFm+qbj vFIHOnQE/FB50XqDcLdHxC6GlRetgwPXA7aEgAPqF769eBoH7bKdkyezve2YHCtUO6/h Hp50fFNyFmvBUUIw+h+DLo28Z2iDC97rY/WeAo5bw+37dhxarthgkdMJ0wke/ucai2LQ KmNbC4sEMMkBc1IAGMJrHosewpTXjq/O5ogOzLjJyIY/CkIb6DM7qWjbLOZqtn4eO8b8 QnzJIAz2PRUbFF+ZxgKfjCEMYE12n/3GJT7F1ykZK48rZo59hqQnt5QfDl0lBizhCJ5E RVmg== X-Gm-Message-State: AOAM530iA8nGL5+YDdoI1SiNjlAqXz0aPq7XdiAqJSTQExN3Pr21SOqX 3i4o3XpT05G/f0WNzqyDyEtXwhOiZWx8mg== X-Google-Smtp-Source: ABdhPJxkbRUqvVy1de59bRVgllHJhG6P42XfdBFDHpbW7FDWnopX2wkgCzinKUh2Tz9Y7zPMASm1NQ== X-Received: by 2002:a17:906:1f93:: with SMTP id t19mr18750743ejr.443.1616407190224; Mon, 22 Mar 2021 02:59:50 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.02.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 02:59:49 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 03/18] trace-cmd: Save only the selected clock in the trace.dat file Date: Mon, 22 Mar 2021 11:59:30 +0200 Message-Id: <20210322095945.259300-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Trace clock, used for curent trace sessions is saved in the trace.dat file. This information is used when displaying timestamps of the events. However, only the selected clock is needed. A new API is added: tracecmd_set_out_clock(); that can be used to set the trace clock on the output handle. Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 1 + lib/trace-cmd/trace-output.c | 65 +++++++++++++++---- 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index 27f4c9c3..a4637046 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -83,6 +83,7 @@ tracecmd_plugin_context_output(struct trace_plugin_context *trace_context); void tracecmd_set_quiet(struct tracecmd_output *handle, bool set_quiet); bool tracecmd_get_quiet(struct tracecmd_output *handle); +void tracecmd_set_out_clock(struct tracecmd_output *handle, char *clock); static inline int tracecmd_host_bigendian(void) { diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 54ddcb54..5b6bef28 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -59,6 +59,7 @@ struct tracecmd_output { unsigned long file_state; struct list_head options; struct tracecmd_msg_handle *msg_handle; + char *trace_clock; }; struct list_event { @@ -118,6 +119,12 @@ void tracecmd_set_quiet(struct tracecmd_output *handle, bool set_quiet) handle->quiet = set_quiet; } +void tracecmd_set_out_clock(struct tracecmd_output *handle, char *clock) +{ + if (handle && clock) + handle->trace_clock = strdup(clock); +} + /** * tracecmd_get_quiet - Get if to print output to the screen * Returns non zero, if no output to the screen should be printed @@ -150,7 +157,7 @@ void tracecmd_output_free(struct tracecmd_output *handle) free(option->data); free(option); } - + free(handle->trace_clock); free(handle); } @@ -1359,6 +1366,45 @@ out_free: return NULL; } +static int save_clock(struct tracecmd_output *handle, char *clock) +{ + unsigned long long endian8; + char *str = NULL; + int ret; + + ret = asprintf(&str, "[%s]", clock); + if (ret < 0) + return -1; + + endian8 = convert_endian_8(handle, strlen(str)); + ret = do_write_check(handle, &endian8, 8); + if (ret) + goto out; + ret = do_write_check(handle, str, strlen(str)); + +out: + free(str); + return ret; +} + +static char *get_clock(struct tracecmd_output *handle) +{ + struct tracefs_instance *inst; + + if (handle->trace_clock) + return handle->trace_clock; + + /* If no clock is set on this handle, get the trace clock of + * the top instance in the handle's tracing dir + * */ + inst = tracefs_instance_alloc(handle->tracing_dir, NULL); + if (!inst) + return NULL; + handle->trace_clock = tracefs_get_clock(inst); + tracefs_instance_free(inst); + return handle->trace_clock; +} + int tracecmd_write_cpu_data(struct tracecmd_output *handle, int cpus, char * const *cpu_data_files) { @@ -1366,6 +1412,7 @@ int tracecmd_write_cpu_data(struct tracecmd_output *handle, unsigned long long *sizes = NULL; off64_t offset; unsigned long long endian8; + char *clock = NULL; off64_t check_size; char *file; struct stat st; @@ -1403,18 +1450,14 @@ int tracecmd_write_cpu_data(struct tracecmd_output *handle, * we need to find the size of it before we define the final * offsets. */ - file = get_tracing_file(handle, "trace_clock"); - if (!file) + clock = get_clock(handle); + if (!clock) goto out_free; - /* Save room for storing the size */ offset += 8; - - ret = stat(file, &st); - if (ret >= 0) - offset += get_size(file); - - put_tracing_file(file); + offset += strlen(clock); + /* 2 bytes for [] around the clock */ + offset += 2; /* Page align offset */ offset = (offset + (handle->page_size - 1)) & ~(handle->page_size - 1); @@ -1439,7 +1482,7 @@ int tracecmd_write_cpu_data(struct tracecmd_output *handle, goto out_free; } - if (save_tracing_file_data(handle, "trace_clock") < 0) + if (save_clock(handle, clock)) goto out_free; for (i = 0; i < cpus; i++) { From patchwork Mon Mar 22 09:59:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154261 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 EE49FC433DB for ; Mon, 22 Mar 2021 10:00:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E6EA61974 for ; Mon, 22 Mar 2021 10:00:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229900AbhCVJ75 (ORCPT ); Mon, 22 Mar 2021 05:59:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230027AbhCVJ7w (ORCPT ); Mon, 22 Mar 2021 05:59:52 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7164DC061574 for ; Mon, 22 Mar 2021 02:59:52 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id kt15so10700202ejb.12 for ; Mon, 22 Mar 2021 02:59:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jXq6CuA445tJvG+aV9fh8vmPxfC4nEbNk5861K8zwck=; b=FLpubd8aedv6Ud0v6AVY/oQeMCsGb613KUjDxazRMmyh8e2j2cs+6LGlkGI9picF/M rLA8y1UMZEUTHyXsHHMZlZi84SHw412DhY0nmaASDKjUKZTDDlv5vWTjGC1wbOyZmNq6 q5SHiAnOaYBjJDrhCV2qmJbokPt41WfDufLSY2wz2AW1k+hP2WoSVFJDruyTUb2YvzI6 sTggMuRHFxX4fV3eeshCIR+BvoY8/C0ctE7v4ZKPFDbhGvU2f+mj/Yz73CsJxe+s6p7F 8uPh26HcYXzGScW/wdRN7ujCyZTSh4mG+MFShMSl81l2d+JpLjgAN29JbEiyJkHSNFxv mK1w== 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=jXq6CuA445tJvG+aV9fh8vmPxfC4nEbNk5861K8zwck=; b=LfeyZODT13GGDFP9YqMmyUnLFZb0dAn7BQDCoQl+aPQuZNrRu7w/gXh1nABVWpY8wy ZVq620HQ/TeoL9Fw9NsqF3JaRJzmU+gGhnXqlMcvbK/WqfmdvzENzgkAs/Usmb73x94f ntTMyD/pwLhDSrS0MNtNWe/QwnqgnnNSPEjQmUrIVw2cQ1OGxMbawA5P8vzNAjldCPu/ eHbSG3yjHw7D8l/9EDynkQvjZVqjeAwHmUQliRipjQJ05zY7YCflQhNXOaeiD3ON+1Ej wTkjVxq1Gq0TTaJEZx1a7hCl74SIa2541rY0lqt89yQ8ZWB1mx4mO6ccQ0G9GFD6XDnk +5Yw== X-Gm-Message-State: AOAM532TQYCtQNhkQu4O38TGHDXsLJvYjc+I9awITfjDRsq1RnNKHS2A Jmdep/0wXHhh/IX7HHHXhos= X-Google-Smtp-Source: ABdhPJyoYyUTPakyME0xTttim4kjsojRuQAjvi3iniS1uq2y4WhoIB29K/yob82Wsxj1hS4+OZtmIA== X-Received: by 2002:a17:906:2551:: with SMTP id j17mr18441992ejb.441.1616407191186; Mon, 22 Mar 2021 02:59:51 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.02.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 02:59:50 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 04/18] trace-cmd: Add new trace-cmd clock tsc2nsec Date: Mon, 22 Mar 2021 11:59:31 +0200 Message-Id: <20210322095945.259300-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org A new clock is added to "trace-cmd record" command: trace-cmd record -C tsc2nsec ... which uses x86-tsc ftrace clock and converts the timestamps from tsc to nanoseconds, using data from perf kernel interface. A new options is added also: trace-cmd record --tsc2nsec ... which does not change the current trace clock, just convert whatever it is to nanoseconds, using the same data from perf kernel interface. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/include/trace-local.h | 7 ++ tracecmd/trace-record.c | 217 +++++++++++++++++++++++++++++---- 2 files changed, 197 insertions(+), 27 deletions(-) diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h index 6e39d27d..7773e9fc 100644 --- a/tracecmd/include/trace-local.h +++ b/tracecmd/include/trace-local.h @@ -172,6 +172,7 @@ enum buffer_instance_flags { BUFFER_FL_GUEST = 1 << 2, BUFFER_FL_AGENT = 1 << 3, BUFFER_FL_HAS_CLOCK = 1 << 4, + BUFFER_FL_TSC2NSEC = 1 << 5, }; struct func_list { @@ -199,6 +200,12 @@ struct filter_pids { int exclude; }; +struct tsc_nsec { + int mult; + int shift; + unsigned long long offset; +}; + struct buffer_instance { struct buffer_instance *next; char *name; diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index a0eb0385..38edea2c 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -57,6 +57,8 @@ #define MAX_LATENCY "tracing_max_latency" #define STAMP "stamp" #define FUNC_STACK_TRACE "func_stack_trace" +#define TSC_CLOCK "x86-tsc" +#define TSCNSEC_CLOCK "tsc2nsec" enum trace_type { TRACE_TYPE_RECORD = 1, @@ -198,6 +200,7 @@ struct common_record_context { char *date2ts; char *user; int data_flags; + struct tsc_nsec tsc2nsec; int record_all; int total_disable; @@ -4443,11 +4446,12 @@ static int find_ts(struct tep_event *event, struct tep_record *record, return 0; } -static unsigned long long find_time_stamp(struct tep_handle *tep) +static unsigned long long find_time_stamp(struct tep_handle *tep, + struct tracefs_instance *instance) { unsigned long long ts = 0; - if (!tracefs_iterate_raw_events(tep, NULL, NULL, 0, find_ts, &ts)) + if (!tracefs_iterate_raw_events(tep, instance, NULL, 0, find_ts, &ts)) return ts; return 0; @@ -4459,52 +4463,59 @@ static char *read_top_file(char *file, int *psize) return tracefs_instance_file_read(top_instance.tracefs, file, psize); } +static struct tep_handle *get_ftrace_tep(void) +{ + const char *systems[] = {"ftrace", NULL}; + struct tep_handle *tep; + char *buf; + int size; + int ret; + + tep = tracefs_local_events_system(NULL, systems); + if (!tep) + return NULL; + tep_set_file_bigendian(tep, tracecmd_host_bigendian()); + buf = read_top_file("events/header_page", &size); + if (!buf) + goto error; + ret = tep_parse_header_page(tep, buf, size, sizeof(unsigned long)); + free(buf); + if (ret < 0) + goto error; + + return tep; + +error: + tep_free(tep); + return NULL; +} + /* * Try to write the date into the ftrace buffer and then * read it back, mapping the timestamp to the date. */ static char *get_date_to_ts(void) { - const char *systems[] = {"ftrace", NULL}; + struct tep_handle *tep; unsigned long long min = -1ULL; unsigned long long diff; unsigned long long stamp; unsigned long long min_stamp; unsigned long long min_ts; unsigned long long ts; - struct tep_handle *tep; struct timespec start; struct timespec end; char *date2ts = NULL; - char *path; - char *buf; - int size; int tfd; - int ret; int i; /* Set up a tep to read the raw format */ - tep = tracefs_local_events_system(NULL, systems); + tep = get_ftrace_tep(); if (!tep) { warning("failed to alloc tep, --date ignored"); return NULL; } - - tep_set_file_bigendian(tep, tracecmd_host_bigendian()); - - buf = read_top_file("events/header_page", &size); - if (!buf) - goto out_pevent; - ret = tep_parse_header_page(tep, buf, size, sizeof(unsigned long)); - free(buf); - if (ret < 0) { - warning("Can't parse header page, --date ignored"); - goto out_pevent; - } - - path = tracefs_get_tracing_file("trace_marker"); - tfd = open(path, O_WRONLY); - tracefs_put_tracing_file(path); + tfd = tracefs_instance_file_open(NULL, "trace_marker", O_WRONLY); if (tfd < 0) { warning("Can not open 'trace_marker', --date ignored"); goto out_pevent; @@ -4520,7 +4531,7 @@ static char *get_date_to_ts(void) clock_gettime(CLOCK_REALTIME, &end); tracecmd_disable_tracing(); - ts = find_time_stamp(tep); + ts = find_time_stamp(tep, NULL); if (!ts) continue; @@ -5381,6 +5392,7 @@ void init_top_instance(void) } enum { + OPT_tsc2nsec = 240, OPT_fork = 241, OPT_tsyncinterval = 242, OPT_user = 243, @@ -5676,6 +5688,78 @@ check_instance_die(struct buffer_instance *instance, char *param) tracefs_instance_get_name(instance->tracefs), param); } +static bool clock_is_supported(struct tracefs_instance *instance, char *clock) +{ + char *all_clocks = NULL; + char *ret = NULL; + + all_clocks = tracefs_instance_file_read(instance, "trace_clock", NULL); + if (!all_clocks) + return false; + + ret = strstr(all_clocks, clock); + free(all_clocks); + + if (ret) + return true; + return false; +} + +#ifdef PERF +static int get_tsc_nsec(int *shift, int *mult) +{ + static int cpu_shift, cpu_mult; + static int supported; + int cpus = tracecmd_count_cpus(); + struct trace_perf perf; + int i; + + if (supported) + goto out; + + supported = -1; + if (trace_perf_init(&perf, 1, 0, getpid())) + return -1; + if (trace_perf_open(&perf)) + return -1; + cpu_shift = perf.mmap->time_shift; + cpu_mult = perf.mmap->time_mult; + for (i = 1; i < cpus; i++) { + trace_perf_close(&perf); + if (trace_perf_init(&perf, 1, i, getpid())) + break; + if (trace_perf_open(&perf)) + break; + if (perf.mmap->time_shift != cpu_shift || + perf.mmap->time_mult != cpu_mult) { + warning("Found different TSC multiplier and shift for CPU %d: %d;%d instead of %d;%d", + i, perf.mmap->time_mult, perf.mmap->time_shift, cpu_mult, cpu_shift); + break; + } + } + trace_perf_close(&perf); + if (i < cpus) + return -1; + + supported = 1; +out: + if (supported < 0) + return -1; + + if (shift) + *shift = cpu_shift; + if (mult) + *mult = cpu_mult; + + return 0; +} +#else +static int get_tsc_nsec(int *shift, int *mult) +{ + return -1; +} +#endif + static void parse_record_options(int argc, char **argv, enum trace_cmd curr_cmd, @@ -5725,6 +5809,7 @@ static void parse_record_options(int argc, {"module", required_argument, NULL, OPT_module}, {"tsync-interval", required_argument, NULL, OPT_tsyncinterval}, {"fork", no_argument, NULL, OPT_fork}, + {"tsc2nsec", no_argument, NULL, OPT_tsc2nsec}, {NULL, 0, NULL, 0} }; @@ -5870,7 +5955,15 @@ static void parse_record_options(int argc, break; case 'C': check_instance_die(ctx->instance, "-C"); - ctx->instance->clock = optarg; + if (!strncmp(optarg, TSCNSEC_CLOCK, strlen(TSCNSEC_CLOCK))) { + ret = get_tsc_nsec(&ctx->tsc2nsec.shift, + &ctx->tsc2nsec.mult); + if (ret || !clock_is_supported(NULL, TSC_CLOCK)) + die("Clock %s is not supported", optarg); + ctx->instance->flags |= BUFFER_FL_TSC2NSEC; + ctx->instance->clock = strdup(TSC_CLOCK); + } else + ctx->instance->clock = optarg; ctx->instance->flags |= BUFFER_FL_HAS_CLOCK; if (is_top_instance(ctx->instance)) guest_sync_set = true; @@ -6125,6 +6218,13 @@ static void parse_record_options(int argc, die("--fork option used for 'start' command only"); fork_process = true; break; + case OPT_tsc2nsec: + ret = get_tsc_nsec(&ctx->tsc2nsec.shift, + &ctx->tsc2nsec.mult); + if (ret) + die("TSC to nanosecond is not supported"); + ctx->instance->flags |= BUFFER_FL_TSC2NSEC; + break; case OPT_quiet: case 'q': quiet = true; @@ -6272,6 +6372,66 @@ static bool has_local_instances(void) return false; } +/* + * Get the current clock value + */ +#define CLOCK_INST_NAME "_clock_instance_" +static unsigned long long get_clock_now(const char *clock) +{ + struct tracefs_instance *ts_instance = NULL; + unsigned long long ts = 0; + struct tep_handle *tep; + int tfd = -1; + int ret; + + /* Set up a tep to read the raw format */ + tep = get_ftrace_tep(); + if (!tep) + return 0; + ts_instance = tracefs_instance_create(CLOCK_INST_NAME); + if (!ts_instance) + goto out; + if (clock) { + ret = tracefs_instance_file_write(ts_instance, "trace_clock", clock); + if (ret < strlen(clock)) + goto out; + } + tfd = tracefs_instance_file_open(ts_instance, "trace_marker", O_WRONLY); + if (tfd < 0) + goto out; + tracefs_trace_on(ts_instance); + ret = write(tfd, STAMP, 5); + tracefs_trace_off(ts_instance); + ts = find_time_stamp(tep, ts_instance); + +out: + if (tfd >= 0) + close(tfd); + if (ts_instance) { + if (tracefs_instance_is_new(ts_instance)) + tracefs_instance_destroy(ts_instance); + tracefs_instance_free(ts_instance); + } + tep_free(tep); + + return ts; +} + +static void get_tsc_offset(struct common_record_context *ctx) +{ + struct buffer_instance *instance; + + for_all_instances(instance) { + if (is_guest(instance) || !instance->clock) + return; + + ctx->tsc2nsec.offset = get_clock_now(instance->clock); + return; + } + + ctx->tsc2nsec.offset = get_clock_now(NULL); +} + /* * This function contains common code for the following commands: * record, start, stream, profile. @@ -6330,6 +6490,9 @@ static void record_trace(int argc, char **argv, for_all_instances(instance) set_clock(instance); + if (ctx->tsc2nsec.mult) + get_tsc_offset(ctx); + /* Record records the date first */ if (ctx->date && ((IS_RECORD(ctx) && has_local_instances()) || IS_RECORD_AGENT(ctx))) From patchwork Mon Mar 22 09:59:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154255 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 B94F9C433E2 for ; Mon, 22 Mar 2021 10:00:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 88CFB6192A for ; Mon, 22 Mar 2021 10:00:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229913AbhCVJ75 (ORCPT ); Mon, 22 Mar 2021 05:59:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230040AbhCVJ7x (ORCPT ); Mon, 22 Mar 2021 05:59:53 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 424FBC061574 for ; Mon, 22 Mar 2021 02:59:53 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id jy13so20164752ejc.2 for ; Mon, 22 Mar 2021 02:59:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qum7V/CX9vs6Frbtqh58iT4ZdrrYTiakqaue6dbnQtw=; b=encznjyLHc0JOV7wpvlUoLkG4dC2SuLNEzzBBok03Lr6Gubs0xhcRaCqizQVP6nYJq f4JSEA2OdFlrXFWLcBWVzuxJEfwEKH06YW+1qEtuGLrIuAOVR0nxFRrN6paf+kvWg8L0 fQeT1UUnSwvAZn7GXDKu///lZGOeq17w+7X/P33aDt4dO4Y4cO6fmaArFdtHk+mcT1+8 5TbcW0TdsavapadMzhg2Ljy+fCV+w2t1OZJPqDjHe0FQDQiG3l7jJ+pDXyz2PUto/Uvo DJ6LpoEndkOvpk9twUIlfX0e4N5pLPNIOP7xbWrrj2yEVKqf1VnMJjNnuSNsLedP9jI0 OuVA== 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=Qum7V/CX9vs6Frbtqh58iT4ZdrrYTiakqaue6dbnQtw=; b=mGKH5UKNBnYiWLXiKnf9708LX4DilueRUvwEaTusraop6ePgBKz5n7o2XKIAAJf/x/ TEU2bA/sH2YJxF6dpJBM/Snqi7VEC8unUDhClsqYocBtUnSgWpqhma3Qnn1VdYg7WaOY /nrkhCJHLJTWtcajM40qoS+CtY1Xz0FXODsgjMXvZ8+ugRHE61FQnQShdF41qWghOAAy pc8YeakoAnRXQeMAss8Rj8bBv+UZ8i2M7BxA5VpCgN+/aYNAptiMDuaCFf8M3mX0lTai c216Z1AJD+vtXm7oGrmca+xtZqT0YnU/ZHfrmnS1uo1ZFDGgEAZYAUDBOZL4z17rq1a0 30mA== X-Gm-Message-State: AOAM5335EmhsJUAe4riQ2Xp8hxYbBTsdCE5rUQEjZpBAXmzudT1sY9QT 4l/wQ8VWMyj/tDecLI/9LKb2jij2tERcEg== X-Google-Smtp-Source: ABdhPJxvPNmjwYBpBDW59IxlX37AzkbbqBKIqB3oUuHJ+fF+SDvOWuliVf7ocSjNsI9EE57DV3S1Qw== X-Received: by 2002:a17:906:a049:: with SMTP id bg9mr18378491ejb.186.1616407192026; Mon, 22 Mar 2021 02:59:52 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.02.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 02:59:51 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 05/18] trace-cmd: Add a new option in trace file metadata for tsc2nsec conversion Date: Mon, 22 Mar 2021 11:59:32 +0200 Message-Id: <20210322095945.259300-6-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org A new option is added in the trace.dat file for holding the multiplier and shift, used for converting TSC trace clock to nanoseconds. Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 1 + tracecmd/trace-dump.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index a4637046..ce3d8dc0 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -125,6 +125,7 @@ enum { TRACECMD_OPTION_TRACEID, TRACECMD_OPTION_TIME_SHIFT, TRACECMD_OPTION_GUEST, + TRACECMD_OPTION_TSC2NSEC, }; enum { diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 4bdfd53f..31b9d201 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -483,6 +483,22 @@ out: free(buf); } +void dump_option_tsc2nsec(int fd, int size) +{ + int mult, shift; + unsigned long long offset; + + do_print(OPTIONS, "\n\t\t[Option TSC2NSEC, %d bytes]\n", size); + + if (read_file_number(fd, &mult, 4)) + die("cannot read tsc2nsec multiplier"); + if (read_file_number(fd, &shift, 4)) + die("cannot read tsc2nsec shift"); + if (read_file_number(fd, &offset, 8)) + die("cannot read tsc2nsec offset"); + do_print(OPTIONS, "%d %d %llu [multiplier, shift, offset]\n", mult, shift, offset); +} + static void dump_options(int fd) { unsigned short option; @@ -543,6 +559,9 @@ static void dump_options(int fd) case TRACECMD_OPTION_GUEST: dump_option_guest(fd, size); break; + case TRACECMD_OPTION_TSC2NSEC: + dump_option_tsc2nsec(fd, size); + break; default: do_print(OPTIONS, " %d %d\t[Unknown option, size - skipping]\n", option, size); From patchwork Mon Mar 22 09:59:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154265 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 A3E5BC433E0 for ; Mon, 22 Mar 2021 10:01:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 65DA361983 for ; Mon, 22 Mar 2021 10:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbhCVKA1 (ORCPT ); Mon, 22 Mar 2021 06:00:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbhCVJ7y (ORCPT ); Mon, 22 Mar 2021 05:59:54 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39FFFC061756 for ; Mon, 22 Mar 2021 02:59:54 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id u21so2229001ejo.13 for ; Mon, 22 Mar 2021 02:59:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zu2CdEmARU5Bf83z5GHyL4PVeIbHQU4VjDX8CrNvZp4=; b=mUZTKKm3e0ywIqgutieguviKenURheOE5T7y1cBpTL9r434256Zke1Fg9esvHPk9SO ZIX1P9BeixS8AiwIUDeombPKrd+sKBDm74HYVX2eede9zPU8E384LIPzBO28I+BuQa44 yxRu+g5QyUVvq5O/cH3KsZaq77O08M9rwB34u7SSN/32A2b41dpKxQCim2l4L2GjU3dW 6wL1VVGimdw5hPgwT+Q9QsDvw8cl7KPTSM1UViszog7AP05aL+Yg1WdUDj+B2EIgsc8A vMdTGxh+hLRXgxcUi8kDPS/9M5mEATtnNJ4DoiXscKq+njWnRsBt5vSkzjhWA/pJB+FF O2Xg== 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=zu2CdEmARU5Bf83z5GHyL4PVeIbHQU4VjDX8CrNvZp4=; b=gp9HoeK+t6BYQmBQuO4u58cLyEqHPjXmQMLm9EI3WbrVNnVJjLNzMQyNU6uGG4uSxh yfoaXp7PujEdlMo5wEwvxksytsyA3Nv23/dIHakR+7/ZNI6pX3Ks1Zb4YfCnHy0LVnyW s1UyBp2y5NQCZR6Bm65VoeSKOAbZS/ksYqisNX+yzRZ66COl/Z85IfuujlPMwY43DDRX IWcZxTA/cnb+eFQL3/eNa6nDROzvGh03JStPsF5ZKQvM3Gqaa7AeGCJZgzyMwsZ+uY53 9d+f2aFyFFKM+FrLasLpvG7gonZB124CCf/dB42Uz9ZHmN0lIelKUQD8tnvBkraS/kz+ ykfg== X-Gm-Message-State: AOAM530100bAqEtKzm+yiv0qfkOfgcsamy5X//3nhsUpMPHKTneIfKHr 3zWmDcMksQGu3lMsQNCKBdieenBpE2e0ww== X-Google-Smtp-Source: ABdhPJxG59iENbFurECRqkCyD/00wF854FjbDysq+tAeexvmXgAytaani0uEIBUPKWAvsrO4Z3gGbQ== X-Received: by 2002:a17:906:75a:: with SMTP id z26mr18349900ejb.22.1616407193020; Mon, 22 Mar 2021 02:59:53 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.02.59.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 02:59:52 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 06/18] trace-cmd: Save information for tsc to nanoseconds conversion in trace file Date: Mon, 22 Mar 2021 11:59:33 +0200 Message-Id: <20210322095945.259300-7-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Store multiplier and shift, required for TSC clock to nanosecond conversion in the metadata of the trace file. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-record.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 38edea2c..37a0f486 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -668,7 +668,24 @@ static void delete_thread_data(void) } } -static void host_tsync_complete(struct buffer_instance *instance) +static void +add_tsc2nsec(struct tracecmd_output *handle, struct tsc_nsec *tsc2nsec) +{ + /* multiplier, shift, offset */ + struct iovec vector[3]; + + vector[0].iov_len = 4; + vector[0].iov_base = &tsc2nsec->mult; + vector[1].iov_len = 4; + vector[1].iov_base = &tsc2nsec->shift; + vector[2].iov_len = 8; + vector[2].iov_base = &tsc2nsec->offset; + + tracecmd_add_option_v(handle, TRACECMD_OPTION_TSC2NSEC, vector, 3); +} + +static void host_tsync_complete(struct common_record_context *ctx, + struct buffer_instance *instance) { struct tracecmd_output *handle = NULL; int fd = -1; @@ -682,6 +699,10 @@ static void host_tsync_complete(struct buffer_instance *instance) handle = tracecmd_get_output_handle_fd(fd); if (!handle) die("cannot create output handle"); + + if (ctx->tsc2nsec.mult) + add_tsc2nsec(handle, &ctx->tsc2nsec); + tracecmd_write_guest_time_shift(handle, instance->tsync); tracecmd_output_close(handle); } @@ -690,7 +711,7 @@ static void host_tsync_complete(struct buffer_instance *instance) instance->tsync = NULL; } -static void tell_guests_to_stop(void) +static void tell_guests_to_stop(struct common_record_context *ctx) { struct buffer_instance *instance; @@ -702,7 +723,7 @@ static void tell_guests_to_stop(void) for_all_instances(instance) { if (is_guest(instance)) - host_tsync_complete(instance); + host_tsync_complete(ctx, instance); } /* Wait for guests to acknowledge */ @@ -4269,6 +4290,9 @@ static void record_data(struct common_record_context *ctx) add_guest_info(handle, instance); } + if (ctx->tsc2nsec.mult) + add_tsc2nsec(handle, &ctx->tsc2nsec); + if (tracecmd_write_cmdlines(handle)) die("Writing cmdlines"); @@ -6573,7 +6597,7 @@ static void record_trace(int argc, char **argv, trace_or_sleep(type, pwait); } - tell_guests_to_stop(); + tell_guests_to_stop(ctx); tracecmd_disable_tracing(); if (!latency) stop_threads(type); From patchwork Mon Mar 22 09:59:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154267 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 AF6B2C433E2 for ; Mon, 22 Mar 2021 10:01:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7941561927 for ; Mon, 22 Mar 2021 10:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229870AbhCVKA2 (ORCPT ); Mon, 22 Mar 2021 06:00:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229591AbhCVJ74 (ORCPT ); Mon, 22 Mar 2021 05:59:56 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30D32C061574 for ; Mon, 22 Mar 2021 02:59:55 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id z1so18544879edb.8 for ; Mon, 22 Mar 2021 02:59:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dTJIMZfw6bNHyKfjvlkzUKuOnQwAl+BaNIF7uNwURYE=; b=BhgDKhxtkaKy+cvhL4l8eElMllUwd+2dtJcUqxGhsW/KMo8ovIPa6HezEpan8MqSmW e+sFPxGyAK+yLYvNnxHTOK+XcNj4YXGeOUvXyGHgTKHFJ7v4tTCIgFSSZK8EGwOEm2t3 vP5VisRE9L640MAtsKRmBPuH7rRMta2VsQmzJsUMjpOubFyk2czukIg2yWH81Fw6Ciwh /4MSpO4bXrcwJpnhQBv/McOp7gZqX7NyggtK072WmH4STEmDn8yfnPsA7hmGfdln+No3 wLYxjRvmISJjLGs+3czjwPQP3YVAX4m3r9EpzDaY/b4YBP6m11Lca1IMzBVoSCKQnCa3 YzHQ== 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=dTJIMZfw6bNHyKfjvlkzUKuOnQwAl+BaNIF7uNwURYE=; b=Nf3Bw5Y4ND6SCXWsXaIHYz3RNnC7V1OmHsooNUlM4JvMMDyD4eUOF1waoAicKA9y5H 6BlRJNxIS4LDyXm5iZ7w8K3eVRGYThjRjSGh+jlrCQE2TPyC1C8dm6yXKnL+w5uqoIsL Bdew/WLmCVUY2lbA5U6aYTRCsVPfdD6GBWQzNSeJzryBk9RnFbNyduM/gYInRuOV0fyM IX5hh4PtwJjSwR6Y3An+KZs/i++6ANyToS3qKYGdemWBYhqk3JjyWrkv2BKWM022PLdW Dj4m5rulV318EpGAAb6ZCSg44VjOTYLtSTFPduh/B8X7Q6N5RipZCiF6suoHW8aJYUaa UkuQ== X-Gm-Message-State: AOAM5316ogUVMGVqmyk0hwK3OzAnqdiNo5Q9OnR+2FNG4/FDkTIpRi3R Knavy+zk3uaoVU3ZPwb1iMZHTz6RrJvOpQ== X-Google-Smtp-Source: ABdhPJynAC7SnvSDgpnd49RkLGFmThc5d7prVL7NSt2cjGG5KGDHUxOltKvawm1G0R8eN4CJBW+xzw== X-Received: by 2002:a05:6402:42c9:: with SMTP id i9mr24803447edc.35.1616407194019; Mon, 22 Mar 2021 02:59:54 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.02.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 02:59:53 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 07/18] trace-cmd: Read information for tsc to nanoseconds conversion from trace file Date: Mon, 22 Mar 2021 11:59:34 +0200 Message-Id: <20210322095945.259300-8-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Read multiplier and shift, required for TSC clock to nanosecond conversion from the metadata of the trace file and save them in the tracecmd input file handler. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 2093a3dc..ebc28f7b 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -99,6 +99,12 @@ struct host_trace_info { struct ts_offset_sample *ts_samples; }; +struct tsc2nsec { + int mult; + int shift; + unsigned long long offset; +}; + struct tracecmd_input { struct tep_handle *pevent; unsigned long file_state; @@ -118,6 +124,8 @@ struct tracecmd_input { bool use_pipe; struct cpu_data *cpu_data; long long ts_offset; + struct tsc2nsec tsc_calc; + struct host_trace_info host; double ts2secs; char * cpustats; @@ -2674,6 +2682,16 @@ static int handle_options(struct tracecmd_input *handle) case TRACECMD_OPTION_GUEST: trace_guest_load(handle, buf, size); break; + case TRACECMD_OPTION_TSC2NSEC: + if (size < 16) + break; + handle->tsc_calc.mult = tep_read_number(handle->pevent, + buf, 4); + handle->tsc_calc.shift = tep_read_number(handle->pevent, + buf + 4, 4); + handle->tsc_calc.offset = tep_read_number(handle->pevent, + buf + 8, 8); + break; default: warning("unknown option %d", option); break; From patchwork Mon Mar 22 09:59:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154263 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=-12.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, 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 6CF58C433C1 for ; Mon, 22 Mar 2021 10:01:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 41BDB61927 for ; Mon, 22 Mar 2021 10:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229482AbhCVKA2 (ORCPT ); Mon, 22 Mar 2021 06:00:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229870AbhCVJ74 (ORCPT ); Mon, 22 Mar 2021 05:59:56 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CE94C061756 for ; Mon, 22 Mar 2021 02:59:56 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id bf3so18534976edb.6 for ; Mon, 22 Mar 2021 02:59:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kOJH3HXZvkfc6Wmych7kH3mxO/LHuz9jlLGyUgMKjN4=; b=cLoa+aw13LQcwVj7mfmq/bY9Px96CBFDeYAJcLZ+IKLzDdgcnXrgtTfbZ03klSouek 1cdMPm5BWbA87sHnzUrz84VbKahN/S+RBNfE282lAPM5Tt7Yvv3ptTYB/flSjgfWC3pq 07gQ/L8k7lgICoBQppQ2P6sCH6oDh2kLsPzGqQbbNimbXcr4bhGTOHt8hQVW2+IbcbqJ c3yXXJodSW2rCCWOmCowS6RUV/nqHryo3jUHHqcfp70MG6Qqzcu4OzFbQ3IjTS5pdDUx xhFKYbfdgmy0HRXgbMcKeNfLgcmTbsicZ/Q0KSXjY1blB3pKPjbUxDhi4RMVML2xqU0n G3mA== 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=kOJH3HXZvkfc6Wmych7kH3mxO/LHuz9jlLGyUgMKjN4=; b=N/QvDEpEVAgUDSrmvEa0sMlAQ7UHsRyI26M7gA7K2+Flf6xBjIvvXIu3rOBSrKVYdw fh8RtFW0MDyaelZ8tcXj9TxLficOFNdRdoQoOL2+5NKXWa4LXPMTysS4Vd1+yaSZTzhn VTzsz3paBERkKAky2qwO5dECiPsxDCxQmU7/afT2SrlR8Tz0URaW4hAWismwBuxLn59I YCFDgRbbuPhI81Dnbo53SWD6WbluEGUNTMEKaX3wRkG4+e/2R4vNWrzkPBnuqldvLY+A gFgpJ4yHUrJOmgI7TO634C2l8+q9onrEFo5Qz50IjpN6NuVhaLkcf9IATmFdHGa5kP8w 7xmw== X-Gm-Message-State: AOAM53253XiA4xJuuiVSjgYFIvNwTHK5B4Em1PD6PPjBf70uA6sQgyrN QEfX99gUZM18fAzZOhdWTUn1DAasHNAIww== X-Google-Smtp-Source: ABdhPJyP/GsR/OyddRN2+30/yUGBihvSOGz+ZJWxlTmRDm9ZNJ35Ty0DKqBp+I1LUpiVNwJFJc/zjQ== X-Received: by 2002:a05:6402:b41:: with SMTP id bx1mr24824200edb.69.1616407194934; Mon, 22 Mar 2021 02:59:54 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.02.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 02:59:54 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 08/18] trace-cmd: Save tsc2nsec clock in trace.dat file Date: Mon, 22 Mar 2021 11:59:35 +0200 Message-Id: <20210322095945.259300-9-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org When tsc2nsec clock is used, save it as selected clock in the trace.dat file. When reading the file, in case of tsc2nsec clock show timestamps in usec / nsec. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/include/private/trace-cmd-private.h | 2 ++ lib/trace-cmd/trace-input.c | 2 +- tracecmd/trace-record.c | 9 +++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index ce3d8dc0..c33d067a 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -22,6 +22,8 @@ #define TRACECMD_ERROR(ret) ((void *)((unsigned long)(ret) | TRACECMD_ERR_MSK)) #define TRACECMD_PTR2ERR(ptr) ((unisgned long)(ptr) & ~TRACECMD_ERR_MSK) +#define TSCNSEC_CLOCK "tsc2nsec" + void tracecmd_parse_cmdlines(struct tep_handle *pevent, char *file, int size); void tracecmd_parse_proc_kallsyms(struct tep_handle *pevent, char *file, unsigned int size); void tracecmd_parse_ftrace_printk(struct tep_handle *pevent, char *file, unsigned int size); diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index ebc28f7b..67915f25 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -2906,7 +2906,7 @@ static void extract_trace_clock(struct tracecmd_input *handle, char *line) /* Clear usecs if not one of the specified clocks */ if (strcmp(clock, "local") && strcmp(clock, "global") && strcmp(clock, "uptime") && strcmp(clock, "perf") && - strncmp(clock, "mono", 4)) + strncmp(clock, "mono", 4) && strcmp(clock, TSCNSEC_CLOCK)) handle->flags &= ~TRACECMD_FL_IN_USECS; } diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 37a0f486..9ae6e032 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -58,7 +58,6 @@ #define STAMP "stamp" #define FUNC_STACK_TRACE "func_stack_trace" #define TSC_CLOCK "x86-tsc" -#define TSCNSEC_CLOCK "tsc2nsec" enum trace_type { TRACE_TYPE_RECORD = 1, @@ -4168,7 +4167,8 @@ static void write_guest_file(struct buffer_instance *instance) handle = tracecmd_get_output_handle_fd(fd); if (!handle) die("error writing to %s", file); - + if (instance->flags & BUFFER_FL_TSC2NSEC) + tracecmd_set_out_clock(handle, TSCNSEC_CLOCK); temp_files = malloc(sizeof(*temp_files) * cpu_count); if (!temp_files) die("failed to allocate temp_files for %d cpus", @@ -4290,9 +4290,10 @@ static void record_data(struct common_record_context *ctx) add_guest_info(handle, instance); } - if (ctx->tsc2nsec.mult) + if (ctx->tsc2nsec.mult) { add_tsc2nsec(handle, &ctx->tsc2nsec); - + tracecmd_set_out_clock(handle, TSCNSEC_CLOCK); + } if (tracecmd_write_cmdlines(handle)) die("Writing cmdlines"); From patchwork Mon Mar 22 09:59:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154269 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 BDB5AC433E1 for ; Mon, 22 Mar 2021 10:01:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DC726198D for ; Mon, 22 Mar 2021 10:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229875AbhCVKAa (ORCPT ); Mon, 22 Mar 2021 06:00:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229953AbhCVJ75 (ORCPT ); Mon, 22 Mar 2021 05:59:57 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 056CCC061574 for ; Mon, 22 Mar 2021 02:59:57 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id dm8so18544107edb.2 for ; Mon, 22 Mar 2021 02:59:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gLmHgyv83IrgZDXtaFwHHBDrIsd/4q/WIVuAKAx5xNM=; b=MI95kiZmX4Hn0hHH6sTuqj+VZE7UcOZvlMEM3DEam7latx+Ul17q94dGCHKmbsjucl rJAuQbyKqa9mCSVbefUiRgsQ9L/932JWZsY6lKTw1j/YikhZLV4ItXcbO0NqE5V/nNq3 VdmHM36xl5G4+YU0pco50Ss4bPP6Mef6Q9WB4qBP0KhwQeH0NqHUIfFF7PGCcWpO/IUq TeQ1FLo3feCzQxRzdjykMFZPPk3bDkK1ohc1jGxda3Xn0unMdukI1v1G3cJfNJnVxPFZ soKgxzxO3Zm+ueRMiV7BNN8C1j12ZLSmwgTwvjBwVxUUKEpWqQxE796Xx/7PWadX8qeM K7kw== 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=gLmHgyv83IrgZDXtaFwHHBDrIsd/4q/WIVuAKAx5xNM=; b=KaWhMUVqf83mvoISaYZcREo/ValhDQmcZWhiRE4V7Gj5n0rsDDj753zMQ/8USnKH8u v6xcjQO6xgPgQaNBygvgR9bBnEN6L2b1KAJ682d/sGX9H2xyWRpo3rlETtFq5DicCtfL cK+whKNTxLi00DlFkbWXHMpBtCLeiPnPR0B+E9pl3bdeGws4EntZgGuYZyzYZktAcdDC tl7Mg71hpa7sezshDmFCAt8QTyEuNjR+skyVQ4TeUlXdCJJ1DYdV6EAzC4WNes7ZqJ+E Tem6AN4Z2rp/kiRrB9ymsI6WaZty4LCPyNOaGTtPlk2wCCyDlpEDsFGegtuRbfdrjopk wN7A== X-Gm-Message-State: AOAM531LbSpKc3to1n9ck4KTe1FKsmeEiNGtGGaJkji+Oz0pYqP1YhDa HaJ553itPK6+Oys/sRsRyhIUZCvAut75iw== X-Google-Smtp-Source: ABdhPJzI84JGIh0noChQNlx8DaXJ2A+KZCrievK/RVo7YTJfBrPrXghub4T8ZYNLWRkxVV3waQnQxA== X-Received: by 2002:aa7:d0c2:: with SMTP id u2mr24513464edo.158.1616407195849; Mon, 22 Mar 2021 02:59:55 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.02.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 02:59:55 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 09/18] trace-cmd: Append new options into guest trace file at the end of the tracing session Date: Mon, 22 Mar 2021 11:59:36 +0200 Message-Id: <20210322095945.259300-10-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Moved the logic for appending new options into guest trace file from tracecmd_write_guest_time_shift() to host_tsync_complete() context. The guest time shift may not be the only option to append, the right place for this logic is when the tracing session is completed. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-timesync.c | 1 - tracecmd/trace-record.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/trace-cmd/trace-timesync.c b/lib/trace-cmd/trace-timesync.c index 4c03052d..0097ce15 100644 --- a/lib/trace-cmd/trace-timesync.c +++ b/lib/trace-cmd/trace-timesync.c @@ -834,7 +834,6 @@ int tracecmd_write_guest_time_shift(struct tracecmd_output *handle, vector[5].iov_len = 8 * count; vector[5].iov_base = scalings; tracecmd_add_option_v(handle, TRACECMD_OPTION_TIME_SHIFT, vector, 6); - tracecmd_append_options(handle); #ifdef TSYNC_DEBUG if (count > 1) printf("Got %d timestamp synch samples in %lld ns trace\n\r", diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 9ae6e032..54e4b6de 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -703,6 +703,7 @@ static void host_tsync_complete(struct common_record_context *ctx, add_tsc2nsec(handle, &ctx->tsc2nsec); tracecmd_write_guest_time_shift(handle, instance->tsync); + tracecmd_append_options(handle); tracecmd_output_close(handle); } From patchwork Mon Mar 22 09:59:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154281 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 C5EC2C433E4 for ; Mon, 22 Mar 2021 10:01:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F99E6198E for ; Mon, 22 Mar 2021 10:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229591AbhCVKA3 (ORCPT ); Mon, 22 Mar 2021 06:00:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229972AbhCVJ76 (ORCPT ); Mon, 22 Mar 2021 05:59:58 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1EFEC061574 for ; Mon, 22 Mar 2021 02:59:57 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id w18so18568246edc.0 for ; Mon, 22 Mar 2021 02:59:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oMjD439qNlAB7PqKNkhqf7Z0VI4YUDEnQeZeV/0WHzA=; b=b8PH62CyLIIr2Udgg2r/QsoREOO4sXdJcORlgEmC3QyduMBlYXJH8z39oMm7TgS6Rg CDzJjE/b5z0MPnG+bxDJBLuZLY0wRI/KS0+WtBsM33zphFqJ63FVrqHfhGlJCC4v/j49 tn5TrS28Oc1kJsts4Cv7SdU1HkLkfdwKtRsbJR5SDIxbe4iDg+STv10BBmjuYJevcnVF jQeReaiNMVoZ8vXaXra+owGZga2Ipvcdb3H0Qgt6MrKek01DvLhSE4RK5QP34eCenuVo c4pE7fe1EYEYYdx3sz/1Zzhu6UvzY1aO1Zz5OR8uS/BQ0DwxHfEdipLnmjfIkjopPfk2 dkgQ== 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=oMjD439qNlAB7PqKNkhqf7Z0VI4YUDEnQeZeV/0WHzA=; b=mQe/mM/0msMw9efCc/ZLYstLsxZeEYQFevIicWgCPDbfAT9fguPnJK9pBhP7EpwTbl h9gguXqLCgXhtPEi4HHWJftoguHOiIXXWSf0Wd4avHFLuS4Cl/5oVEO3n6X6Zqh6ncc/ tVGDuaFcwJ3yllKklUW3CIQvsAM5cwuigI8+lBhE57ZQYahW5N9vhfwM5QsHm85tdk4n Fad4wYLV0LeU6Tmj/1mGVFZbKe4BK2Y+HCQW1VSKAkc/d0EKJTnUTV4D3KhCjVuqAgvi hE0Qfhxqyyo0F5ewRaPPAum4EB4rZPOtUmbSaMWPS1quAN0EPIqFFF/8vMlh1fxT/EnA o4ZA== X-Gm-Message-State: AOAM5321oY45es4k9JFtFKMWc6nKMT82g77WrWLWzPk0Sghtn5jZYo08 OI2tdKHEfzlfE1uQHGtNQd/1EUlI/BDGrA== X-Google-Smtp-Source: ABdhPJw5TNPZHvfT4SGWcbZTPk0/dbhZ2Kekdtw0NP/7nI3Vffeu61jpnHWxwv8GL+7HR/bvhsVYYw== X-Received: by 2002:aa7:c907:: with SMTP id b7mr25000180edt.37.1616407196743; Mon, 22 Mar 2021 02:59:56 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.02.59.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 02:59:56 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 10/18] trace-cmd: Remove unneeded multiply in events timestamp reading Date: Mon, 22 Mar 2021 11:59:37 +0200 Message-Id: <20210322095945.259300-11-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org When the event timestamp is converted to seconds, the local variable that holds this timestamp is converted to seconds also. As this variable is not used in the function later, this conversion in not needed. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 67915f25..be8a7919 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -1932,10 +1932,8 @@ read_again: handle->cpu_data[cpu].timestamp = timestamp_correct(ts, handle); - if (handle->ts2secs) { + if (handle->ts2secs) handle->cpu_data[cpu].timestamp *= handle->ts2secs; - ts *= handle->ts2secs; - } index = kbuffer_curr_offset(kbuf); From patchwork Mon Mar 22 09:59:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154271 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 E6A36C433E3 for ; Mon, 22 Mar 2021 10:01:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2AD061974 for ; Mon, 22 Mar 2021 10:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229904AbhCVKAa (ORCPT ); Mon, 22 Mar 2021 06:00:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229574AbhCVJ77 (ORCPT ); Mon, 22 Mar 2021 05:59:59 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1D2CC061574 for ; Mon, 22 Mar 2021 02:59:58 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id w18so18568298edc.0 for ; Mon, 22 Mar 2021 02:59:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VQlKcKO67KfSyJNyl/8Q71K1fUi/rYirm77sz0vwbx4=; b=TRgXPqPJPfYOB+ReP3Xahi81DAeq28Lrf3uup2Gc+nx96f4Cb1VEhxpcQMgPPNjWfa CTm6Nb/pjFD8OI1ClfypHxcpZNWMw5ycBKZG8UIhYz2LBPpR3XI9RHDgWy89ljuhVtuH rEVIEOQ5T1gew68Qyrd8LGSKlJhUBVm1OroFDeHkOrL9+MPBWHpbWooXE6ht62q/Le5l zpehlPkBdwrF72q/1LE2hQAYZegyiSH1nKpZ1m7MFrBpjJpegj2y28A0cRxZMVVPqzmZ tLwJgdCyKc57nJyc8WiAEAbEGyTZiP7ELLTHdlUAQq1qnRHcWNCEjGVx4Vb9wl7OfGRj bbzQ== 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=VQlKcKO67KfSyJNyl/8Q71K1fUi/rYirm77sz0vwbx4=; b=jlQf28piXkg2czRMWIO2/paiehtC7Ukx0wV5kpjHU0jGAxgfHaMVZGnPaJYOq1NWRj CBGhljhTgtER74BOMEwtEZfJxX8w56dtGDPImf8VqrasC5ykLV685THBEUAcLNje/3hx /ZcGntuhoRfML9e6W2tgmWo1iT5fTCz2HiCjWUObiEOrv3vLQbrFpsjiUIBgJ8A3jryP /d/x4KaCtr2nAMS3xj8x8oU9IgJnGnrQACJa8Hrm56GNnMzUBXlWvZjvFA+eMUKdtcCa 3P9j3WxzAOLf3utb/Y0YcOcXv7gQXwYB4vMAMwjv9fOsLhpvVxYq604sx4vgMl0ARX4N 7vmQ== X-Gm-Message-State: AOAM531DWEPTWlYcO7SZtZ2bPnyltlKmXnlVZklFRzdbPkTLNxC4J0Tt nWUlMtAEgbtLDP7iKuZ3zN3H9JBSuMmTag== X-Google-Smtp-Source: ABdhPJwAQb1W22X+Inbrbr8ari0ZKS1LHo7Ak4DH+mnqclOXs8VzCgmkz3T5ysgQ/xqnG4qppxFJgA== X-Received: by 2002:aa7:c7c5:: with SMTP id o5mr24536324eds.31.1616407197587; Mon, 22 Mar 2021 02:59:57 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.02.59.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 02:59:57 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 11/18] trace-cmd: Perform all timestamp corrections in a single function Date: Mon, 22 Mar 2021 11:59:38 +0200 Message-Id: <20210322095945.259300-12-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org When reading event timestamps from a trace file, there could be various corrections depending on the metadata information from the file. Move all logic that performs timestamp calculations in a single function. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index be8a7919..dfbe4af6 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -1276,6 +1276,19 @@ static unsigned long long timestamp_correct(unsigned long long ts, &host->ts_samples[mid+1]); } +static unsigned long long timestamp_calc(unsigned long long ts, + struct tracecmd_input *handle) +{ + unsigned long long tstamp; + + tstamp = timestamp_correct(ts, handle); + + if (handle->ts2secs) + tstamp *= handle->ts2secs; + + return tstamp; +} + /* * Page is mapped, now read in the page header info. */ @@ -1297,10 +1310,8 @@ static int update_page_info(struct tracecmd_input *handle, int cpu) kbuffer_subbuffer_size(kbuf)); return -1; } - handle->cpu_data[cpu].timestamp = timestamp_correct(kbuffer_timestamp(kbuf), handle); - - if (handle->ts2secs) - handle->cpu_data[cpu].timestamp *= handle->ts2secs; + handle->cpu_data[cpu].timestamp = timestamp_calc(kbuffer_timestamp(kbuf), + handle); return 0; } @@ -1930,10 +1941,7 @@ read_again: goto read_again; } - handle->cpu_data[cpu].timestamp = timestamp_correct(ts, handle); - - if (handle->ts2secs) - handle->cpu_data[cpu].timestamp *= handle->ts2secs; + handle->cpu_data[cpu].timestamp = timestamp_calc(ts, handle); index = kbuffer_curr_offset(kbuf); From patchwork Mon Mar 22 09:59:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154273 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 1DD80C433E8 for ; Mon, 22 Mar 2021 10:01:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EDBBC61969 for ; Mon, 22 Mar 2021 10:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229879AbhCVKAc (ORCPT ); Mon, 22 Mar 2021 06:00:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229984AbhCVKAB (ORCPT ); Mon, 22 Mar 2021 06:00:01 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD37CC061574 for ; Mon, 22 Mar 2021 02:59:59 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id a7so20181533ejs.3 for ; Mon, 22 Mar 2021 02:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nbgnKU8GP1yKd2NkXfeHddUmXNX+593CNhTW2h6Pyng=; b=PWc8XJGgHbMh/XW4Lxt6s+KrGnnlwJK+zlf0d98l9sCYKZNu2+UHjLLKGWUGQQkXag aFAqaV96muvxcyBeimFGjO/k8+kufI2cEfdtIE1ZaQ/MLM3OypuTrLidEC4BRnMH9epa rLASM9ZLSM56oLSkf+PMD5cM7DtrD5vHDJXOdYOp3ntQ96Z6QHfIBx/u55e4Zt2grcIu dx2V1svlbd6DeGA0w5JOfik6TstgkgmIQOXNYFVAuS7Z8TBToP0P3pFt3p584wR6hTXP tDiT229CQZjXzFbAPt81E0SaYIzuE5YXoBEMdlIA/f0hAYqkElBwG5KqOHvHbXR2U3uE iDxA== 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=nbgnKU8GP1yKd2NkXfeHddUmXNX+593CNhTW2h6Pyng=; b=CT7T27c1OuklU727NufpZF80Ir60dyW/yZeqkG5J+T1OZh7JQJPVeeQfHDvxBp70nB Gzdvjl7PmS/a1qA+CzdB7Iu6DngpSC0bI3ITKyfxLMCfJqiMT7JJkZzk2qsDyhJBBzNV XhAgIYbV4XrDDE1v3kEpq04SYsKMpPX/bOODI7SsLI3nmTQZHgQ0oUB6iavHxF6OZs8u XIGyQr9GpWs4ez6Xh5m0PmOkXzGRsbSry+d0v6vx4q7PvhPFOE299kt88fMVc8XkbB/R mlxyeAlzhMAT4gIojY0Yl+qpx1TuRK7PW2C+lbGgiusdjF43Qz5LHtt1h+/ri9J+bTCI ji1w== X-Gm-Message-State: AOAM531F7/RdnxA0uRDQwF1ozKrQUzInCrNP9cAnHcEA3zwq20efNJv/ 5M1kUMdjSBfFvAngIWSMWNHSmZgzOtAVYw== X-Google-Smtp-Source: ABdhPJzHQAG5D2SdaRF2pbvY8j0Eq9O4ZkM7jGSBb/7lSGaYkR7C5bw966JA3+aa2DgBTriwxew6vA== X-Received: by 2002:a17:906:33d9:: with SMTP id w25mr19186073eja.413.1616407198538; Mon, 22 Mar 2021 02:59:58 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.02.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 02:59:58 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 12/18] trace-cmd: Convert tsc timestamps to nanosecods when reading trace data from a file Date: Mon, 22 Mar 2021 11:59:39 +0200 Message-Id: <20210322095945.259300-13-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org If there is information for TSC to nanoseconds conversion in the trace file metadata, use it to recalculate the timestamps of all events. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index dfbe4af6..7ac81809 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -1196,6 +1196,23 @@ static void free_next(struct tracecmd_input *handle, int cpu) tracecmd_free_record(record); } +/* This functions was taken from the Linux kernel */ +static unsigned long long mul_u64_u32_shr(unsigned long long a, + unsigned long long mul, unsigned int shift) +{ + unsigned int ah, al; + unsigned long long ret; + + al = a; + ah = a >> 32; + + ret = (al * mul) >> shift; + if (ah) + ret += (ah * mul) << (32 - shift); + + return ret; +} + static inline unsigned long long timestamp_correction_calc(unsigned long long ts, unsigned int flags, struct ts_offset_sample *min, @@ -1279,14 +1296,18 @@ static unsigned long long timestamp_correct(unsigned long long ts, static unsigned long long timestamp_calc(unsigned long long ts, struct tracecmd_input *handle) { - unsigned long long tstamp; + unsigned long long t; - tstamp = timestamp_correct(ts, handle); + t = timestamp_correct(ts, handle); if (handle->ts2secs) - tstamp *= handle->ts2secs; + t *= handle->ts2secs; + else if (handle->tsc_calc.mult) { + t -= handle->tsc_calc.offset; + t = mul_u64_u32_shr(t, handle->tsc_calc.mult, handle->tsc_calc.shift); + } - return tstamp; + return t; } /* From patchwork Mon Mar 22 09:59:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154275 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 0397CC433E5 for ; Mon, 22 Mar 2021 10:01:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D32F76198B for ; Mon, 22 Mar 2021 10:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229574AbhCVKAb (ORCPT ); Mon, 22 Mar 2021 06:00:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229991AbhCVKAB (ORCPT ); Mon, 22 Mar 2021 06:00:01 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4669C061756 for ; Mon, 22 Mar 2021 03:00:00 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id kt15so10700825ejb.12 for ; Mon, 22 Mar 2021 03:00:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LerKyBc2du7sy0mCV9M4yVUHN1I0Ty2UesA34CkaMYo=; b=k8MEObFKur+6j0xpS1uDDVYqXhMXU8iJyAvmx9/WXVxTkYDtQW9/6mCIFGc34Untk5 +t33gIrMATDulWpxSkYpJ0MYPgT4XhUV3yyKazv0kTuI93yHpWntWCnlvPomIZgipkqy q0B7uTfg4c6Q/LhyXdKPxd1FK17utHPExMKf81x4S3/lT5SFV7J6xG+UyTcfMiYJxn0C pt9ntKcAF9yvBkRmtGBzVqLzZzLu+Klr6YVrJGp/YKgW5XON+CRAmiTGhyQGCiXZkbyZ zeLpyNpA7+J98pZYWDKZOcjK704JBrYBQ5mpjPbZisRRzSbJesU7734HW3nBIjeLy0j5 a2hA== 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=LerKyBc2du7sy0mCV9M4yVUHN1I0Ty2UesA34CkaMYo=; b=pS5X1Ck6UIeEFtMRD2YGrlINrQo5aOt2Y+Y3ROe0+IU23mqC4V7Ll+w2AYQIsY2pkf bgLqFXdgDG85khEIhjOpZqogcAivbBs+GgrlBgkWD8rSZHc75AfyGoP+ZtQiu44jawMJ 0HfxvPKSwuYHRFidqUUvBjH2u43uhR92dNbkju/xxTIwsMRHeGOSaLjpcfruqjSloBxf TCHvnzKjvS1k/oTCngQnozNc5L44NZfpEkGTr1b2BZdqyyPd1vgwVMxQ4OJr6NyS7Xcx DxiIDoL5sU8w6Fnt8cs7XQAr0GFuJ3MbliByi4wUC4sT5yuvy1XHdW0AOJWpl0DE8YPu qFhA== X-Gm-Message-State: AOAM530GpPs9DtXiki9STC1BvNtcni54fBLqLon4BpbviOw1XlGdy7Yl 0eDpI8T48fgkrIImfSM24MM= X-Google-Smtp-Source: ABdhPJyUAfx9uynEsdu61E8YoBelNbdW5PVTBp/SuNW/SnhuBDwLJfsryZICvuOIWwe68bZ0l9awRg== X-Received: by 2002:a17:906:cb0a:: with SMTP id lk10mr18179156ejb.479.1616407199496; Mon, 22 Mar 2021 02:59:59 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.02.59.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 02:59:59 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 13/18] trace-cmd: Set order and priorities when applying timestamp corrections Date: Mon, 22 Mar 2021 11:59:40 +0200 Message-Id: <20210322095945.259300-14-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org There are multiple options that affect the event's timestamps while recording trace or displaying the trace file. Some of these options can be used together and the order and priorities for all of them should be strictly defined: trace-cmd record --date , --ts-offset - only one of these can be used trace-cmd record host-guest trace - guest timestamps are auto synchronized with host time stamps. If no trace clock is set by the user and "kvm" synch plugin is available, then "x86-tsc" trace clock is used and tsc timestamps are converted to nanoseconds in both host and guest trace events. trace-cmd report --ts-offset, --ts2secs, --nodate Event timestamps corrections are applied in this order, when the trace file is opened for reading: 1. If it is a guest trace file and there is information for synchronization with the host events and is this synchronization is enabled: synchronize guest events with host events. 2. If the user has specified --ts2secs, apply it. 3. If the user has not specified --ts2secs and there is information in the trace file metadata for tsc to nanosecond conversion, apply it. 4. If the user has specified --ts-offset or --date, apply it. The offsets specified by "report" command have higher priority that the offsets specified by "record" command. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 7ac81809..5d03cd00 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -1241,21 +1241,12 @@ timestamp_correction_calc(unsigned long long ts, unsigned int flags, return ts + tscor; } -static unsigned long long timestamp_correct(unsigned long long ts, - struct tracecmd_input *handle) +static unsigned long long timestamp_host_sync(unsigned long long ts, + struct tracecmd_input *handle) { struct host_trace_info *host = &handle->host; int min, mid, max; - if (handle->flags & TRACECMD_FL_IGNORE_DATE) - return ts; - - if (handle->ts_offset) - return ts + handle->ts_offset; - - if (!host->sync_enable) - return ts; - /* We have one sample, nothing to calc here */ if (host->ts_samples_count == 1) return ts + host->ts_samples[0].offset; @@ -1296,17 +1287,26 @@ static unsigned long long timestamp_correct(unsigned long long ts, static unsigned long long timestamp_calc(unsigned long long ts, struct tracecmd_input *handle) { - unsigned long long t; + unsigned long long t = ts; - t = timestamp_correct(ts, handle); - if (handle->ts2secs) + /* Guest trace file, sync with host timestamps */ + if (handle->host.sync_enable) + t = timestamp_host_sync(ts, handle); + + if (handle->ts2secs) { + /* user specified clock frequency */ t *= handle->ts2secs; - else if (handle->tsc_calc.mult) { + } else if (handle->tsc_calc.mult) { + /* auto calculated TSC clock frequency */ t -= handle->tsc_calc.offset; t = mul_u64_u32_shr(t, handle->tsc_calc.mult, handle->tsc_calc.shift); } + /* User specified time offset with --ts-offset or --date options */ + if (handle->ts_offset) + t += handle->ts_offset; + return t; } From patchwork Mon Mar 22 09:59:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154279 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 559B3C433E6 for ; Mon, 22 Mar 2021 10:01:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1636D6198D for ; Mon, 22 Mar 2021 10:01:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229984AbhCVKAd (ORCPT ); Mon, 22 Mar 2021 06:00:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230012AbhCVKAC (ORCPT ); Mon, 22 Mar 2021 06:00:02 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACF12C061574 for ; Mon, 22 Mar 2021 03:00:01 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id ce10so20170910ejb.6 for ; Mon, 22 Mar 2021 03:00:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a4BiW5YoUz5ufk3n1fjMIzWlYK86+qzPaMiKwA8JOn0=; b=VDCfZjrKxhUFWnWHJwTb9Yz6td7d3pxYIvl/CUoAsNSoNwu4yQ2w/pV+caDyYSbHga 0otVYh+jLFG5gcPx4czwJmumeAQRQSPgnGKii6LEph4Xrf9ZxCuzymGIrAnMhbE1syUB pUrQbBKMptAZlZNdH1CVxdqMjyqJ1s1K9sIESd/2cUnGN19P9yzR0xf0hRdD/bBoQOdi vFXwA4POyaKB+toPkrT5dvJxur6kcs+5H4sCZTEfybPMsDOg9OAbN8tw7WGxcs1euVTh JB9Ugh8KJZwJvNO43x1CuCa2aaCe6Jn5Zopr6cZjZJVtBEm5aUeuNUmdZA3edOEMQF+w RD1g== 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=a4BiW5YoUz5ufk3n1fjMIzWlYK86+qzPaMiKwA8JOn0=; b=dIQJHwJkmZ0Y7Yv+a02Tgm7njexpi5Q8Js3VBZVDPrtYYTyYiKoIM6vt85B1T8lVNt SQF25qoz0AEQVLvabMLBsNmEQXBcIxGtvCIDci+uLcvSqYwHhc9RGw+ZBDF7SpVbC5MA A9FySABVd7PXbkqvsfedm6AbUETGhiHkyzSTrX354n7g2l7Oax3iMilUQgVKeyzjcN16 g3EDq2llxxYDhL9A6yn741k6OnxkK2TooLUu7548V8xcBAijQpDAt8ohYGUECb2aT9Lm bUNVJfeiePbXy9LYNJSHOQtp5g6fQj+/fSBZ5/fRdpGUzRkWMA2yVc2oVcl0aGhuE/bS XtXg== X-Gm-Message-State: AOAM530bQNRMzQ64xoLIr6EZrjFxYT+5/giy1tf99pBaThB+intndUFb ZoldFl9Q/sWKqtGlBOJsEZ6jFe7A5Lx1Sg== X-Google-Smtp-Source: ABdhPJwqJEGwRksaetqiqeuxZHqeSOPQ4MTAsLBRmLzVkxeuPv0YnffODIt1YSmJAfBzUOJxwXqjew== X-Received: by 2002:a17:906:c143:: with SMTP id dp3mr16556435ejc.499.1616407200460; Mon, 22 Mar 2021 03:00:00 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.02.59.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 03:00:00 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 14/18] trace-cmd: Add a new flag to disable any timestamp corrections Date: Mon, 22 Mar 2021 11:59:41 +0200 Message-Id: <20210322095945.259300-15-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org A new flag is added in the trace-cmd library for controlling events timestamp corrections while reading a trace file. If the flag is set, all timestamps are displayed as-is from the trace file. TRACECMD_FL_RAW_TS The flag can be modified with these APIs: tracecmd_set_flag() tracecmd_clear_flag() Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/include/private/trace-cmd-private.h | 1 + lib/trace-cmd/trace-input.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index c33d067a..fdca7494 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -134,6 +134,7 @@ enum { TRACECMD_FL_IGNORE_DATE = (1 << 0), TRACECMD_FL_BUFFER_INSTANCE = (1 << 1), TRACECMD_FL_IN_USECS = (1 << 2), + TRACECMD_FL_RAW_TS = (1 << 3), }; struct tracecmd_ftrace { diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 5d03cd00..88007cde 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -1289,6 +1289,9 @@ static unsigned long long timestamp_calc(unsigned long long ts, { unsigned long long t = ts; + /* do not modify raw timestamps */ + if (handle->flags & TRACECMD_FL_RAW_TS) + return ts; /* Guest trace file, sync with host timestamps */ if (handle->host.sync_enable) @@ -2604,7 +2607,8 @@ static int handle_options(struct tracecmd_input *handle) * gtod. It is stored as ASCII with '0x' * appended. */ - if (handle->flags & TRACECMD_FL_IGNORE_DATE) + if ((handle->flags & TRACECMD_FL_IGNORE_DATE) || + (handle->flags & TRACECMD_FL_RAW_TS)) break; offset = strtoll(buf, NULL, 0); /* Convert from micro to nano */ @@ -2616,7 +2620,7 @@ static int handle_options(struct tracecmd_input *handle) * Similar to date option, but just adds an * offset to the timestamp. */ - if (handle->flags & TRACECMD_FL_IGNORE_DATE) + if (handle->flags & TRACECMD_FL_RAW_TS) break; offset = strtoll(buf, NULL, 0); handle->ts_offset += offset; @@ -2631,7 +2635,7 @@ static int handle_options(struct tracecmd_input *handle) * long long array of size [count] of timestamp offsets. * long long array of size [count] of timestamp scaling ratios.* */ - if (size < 16 || handle->flags & TRACECMD_FL_IGNORE_DATE) + if (size < 16 || (handle->flags & TRACECMD_FL_RAW_TS)) break; handle->host.peer_trace_id = tep_read_number(handle->pevent, buf, 8); @@ -2710,7 +2714,7 @@ static int handle_options(struct tracecmd_input *handle) trace_guest_load(handle, buf, size); break; case TRACECMD_OPTION_TSC2NSEC: - if (size < 16) + if (size < 16 || (handle->flags & TRACECMD_FL_RAW_TS)) break; handle->tsc_calc.mult = tep_read_number(handle->pevent, buf, 4); From patchwork Mon Mar 22 09:59:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154283 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 7DF48C433EB for ; Mon, 22 Mar 2021 10:01:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B45E61972 for ; Mon, 22 Mar 2021 10:01:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229912AbhCVKAe (ORCPT ); Mon, 22 Mar 2021 06:00:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230016AbhCVKAD (ORCPT ); Mon, 22 Mar 2021 06:00:03 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1190C061756 for ; Mon, 22 Mar 2021 03:00:02 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id u9so20180787ejj.7 for ; Mon, 22 Mar 2021 03:00:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wc2CNDZfCEfTInFqm/4fuSskdmNZbg2Y7JHAZmXVQWo=; b=YJBepcmpuoSbFcSuwcwhTzEH5c7154a73Me5Nqy2si5cIr5SVqMnRBdJaeX4raSlvv NzHGytJkfJlGHi4X79OscVaTnqlRR8JSvbTFZktvnMld8Ddr1j/AI8LMkcR9TJ/QmEnf 2Fywwh0voh+g4KWxjyWkY7d3PAfM/m4N0sLkVoFW25MX6xRGBBkxKLkkY6Pe5eqX9Uwz x9Hp5kjAKZl1MbhTv48MQJ9EukAScWskdt2tWWgUczuIwJvrYECtZwgds/v9Sgjfxetp 7du2MzpChAD3k5wPqd00PTq2YVi6Fdcxp+To1UAttTGYblfWggQVvRihw7xSXWkHkXEE C/Rg== 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=wc2CNDZfCEfTInFqm/4fuSskdmNZbg2Y7JHAZmXVQWo=; b=t+wsyvy5nXQA8X3gUax6j5J/APHs78g6wJXmyA7B7bI5u0eBZFUdr7eILj2KbwBQoc fTM+T7T0KPq1nhmR8BZApbb5ju8no2xjnC//Vb0Rh6s/lvA6eGQISP5Y+qnjCJtXmPEB vgPakgKILOYNZt7PVH5+iODCSa6uSGM2TA/GA8aDLLEpJPxcJg4o2B8ZorEVLqBHP9/N zIZelIIt+IKKXd7fiz3NfCUtBu2k5v2g6QBiR1lqjYdt+owYsIeJ1kCatYOZ8UbuDKmI 1T1Tj4Go3/1lcBJpgiBfaCMIWNI4HDi/Qcz1iqFkYKBPP/f7lE0wgPMIruzODCMtV+8n /iag== X-Gm-Message-State: AOAM532lB9/Ycv298LaQLB6pjNo0vpCB6GCo+SYgihgo89d8KI7eQOmd 5V/M1dtwysmu5zwUPg3JK5492qODmf65uw== X-Google-Smtp-Source: ABdhPJz/sg73/MAYRP4ARNOSS4M2uxfUwGSInPAodaSlZwVyE/N3BwGe5rNoLMlRswULDiliz4J0fw== X-Received: by 2002:a17:907:9862:: with SMTP id ko2mr17993018ejc.222.1616407201544; Mon, 22 Mar 2021 03:00:01 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.03.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 03:00:01 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 15/18] trace-cmd: Add new parameter "--raw-ts" to "trace-cmd report" command Date: Mon, 22 Mar 2021 11:59:42 +0200 Message-Id: <20210322095945.259300-16-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org "trace-cmd report --raw-ts" disables all corrections of event timestamps from the trace file. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 4 ++++ tracecmd/trace-read.c | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 88007cde..256431f0 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -2934,6 +2934,10 @@ static void extract_trace_clock(struct tracecmd_input *handle, char *line) if (!clock) return; + /* Clear usecs if raw timestamps are requested */ + if (handle->flags & TRACECMD_FL_RAW_TS) + handle->flags &= ~TRACECMD_FL_IN_USECS; + /* Clear usecs if not one of the specified clocks */ if (strcmp(clock, "local") && strcmp(clock, "global") && strcmp(clock, "uptime") && strcmp(clock, "perf") && diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c index 22e8635c..1b99db1d 100644 --- a/tracecmd/trace-read.c +++ b/tracecmd/trace-read.c @@ -1484,6 +1484,7 @@ static void add_hook(const char *arg) } enum { + OPT_raw_ts = 236, OPT_version = 237, OPT_tscheck = 238, OPT_tsdiff = 239, @@ -1533,6 +1534,7 @@ void trace_report (int argc, char **argv) int print_events = 0; int nanosec = 0; int no_date = 0; + int raw_ts = 0; int global = 0; int neg = 0; int ret = 0; @@ -1574,6 +1576,7 @@ void trace_report (int argc, char **argv) {"ts2secs", required_argument, NULL, OPT_ts2secs}, {"ts-diff", no_argument, NULL, OPT_tsdiff}, {"ts-check", no_argument, NULL, OPT_tscheck}, + {"raw-ts", no_argument, NULL, OPT_raw_ts}, {"help", no_argument, NULL, '?'}, {NULL, 0, NULL, 0} }; @@ -1746,6 +1749,9 @@ void trace_report (int argc, char **argv) case OPT_tscheck: tscheck = 1; break; + case OPT_raw_ts: + raw_ts = 1; + break; default: usage(argv); } @@ -1777,7 +1783,8 @@ void trace_report (int argc, char **argv) if (no_date) tracecmd_set_flag(handle, TRACECMD_FL_IGNORE_DATE); - + if (raw_ts) + tracecmd_set_flag(handle, TRACECMD_FL_RAW_TS); page_size = tracecmd_page_size(handle); if (show_page_size) { From patchwork Mon Mar 22 09:59:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154277 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 5CD4CC433EA for ; Mon, 22 Mar 2021 10:01:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34C8B61974 for ; Mon, 22 Mar 2021 10:01:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229962AbhCVKAf (ORCPT ); Mon, 22 Mar 2021 06:00:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230027AbhCVKAE (ORCPT ); Mon, 22 Mar 2021 06:00:04 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0441C061574 for ; Mon, 22 Mar 2021 03:00:03 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id hq27so20177838ejc.9 for ; Mon, 22 Mar 2021 03:00:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zm+BFXucsZyphQSVHYTcZQBOKWvv5kzSkT5G321QS7Y=; b=tiGIfjWy8tTyHlOd/C0y1nWORKF4B6Ld+pnPltLLXSrlJDqhm0PLJjf31oT5s2pshp iEWuK9cp2hjqssvjiKO4VAICB9l9Ups+wIsjbmeNCvEoNuMsbWa1iGLEDl7mAFYBEr99 V/TSBguQlNQb9xRQImVx8PhWT07j04OEY7bePO+ztYJm3Oa5VjH+CrgKNVgzeIoRcfSF ubOVkW+9AbAf43pnfzwVZZscLOTmY9zgIxCz6YORTWq8kF9cijUC5qY89lfgA9OrFelZ nEcBAl9bWs0bJQryvhKLCtyQ4QGxdsV2uqpIlO00Te3wmCDbhbumutdnppIlSQj48pHc vOoQ== 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=zm+BFXucsZyphQSVHYTcZQBOKWvv5kzSkT5G321QS7Y=; b=dRLI722K38hLRU5xnOx3VjE10rjW3uf64qbUkicpx1DEw9olSKxbTNAH5g1rWpFSqw +swxVN8GeqgFekGzcJOx2B30xAmntBcDsV988LxQw0GQEnF9VGVnbV4wszfeoI9PP2xH 9neFwNebPNATKKNQEbDgk5N5OsP4T1ZqqnRAmXOYzj2K1VBvlEnp+2YXNMfKBMx/TOPX muYmg21s6tTdqvm/KJVFcH9uGLPn1qsZc1XnI6WfVyazbAfFJtozOcljYBLCzrrAi6Gf nU97/umb+OwkwywPpGVohBxbUpPIcLfbZoU8pmy8+5b5IwoV9snb2zGioX/7s0dlTxvG fpfg== X-Gm-Message-State: AOAM530ZabQLR/0GIgjTc26sgd77kS74Dqig+dTqu+0if5LOlJKyhADs /gej4mcKqM6wjItPulXSmy6u172s+VbWDA== X-Google-Smtp-Source: ABdhPJw1yUTHczAF1/7zjwri7OIk5ij7JCgRlMlIM9jayWC2eXMbPBhh/oXtd6LSVWZcy9h0acvQTg== X-Received: by 2002:a17:907:2112:: with SMTP id qn18mr17925081ejb.220.1616407202434; Mon, 22 Mar 2021 03:00:02 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.03.00.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 03:00:02 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 16/18] trace-cmd: Print times in TimeShift options as unsigned in trace-cmd dump Date: Mon, 22 Mar 2021 11:59:43 +0200 Message-Id: <20210322095945.259300-17-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Fixed "trace-cmd dump" subcommand to print unsigned times from Time Shift option in a trace.dat file. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-dump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 31b9d201..f5b864f7 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -373,7 +373,7 @@ static void dump_option_timeshift(int fd, int size) { long long *scalings = NULL; long long *offsets = NULL; - long long *times = NULL; + unsigned long long *times = NULL; long long trace_id; unsigned int count; unsigned int flags; From patchwork Mon Mar 22 09:59:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154285 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 938ADC433E9 for ; Mon, 22 Mar 2021 10:01:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74F1D6198E for ; Mon, 22 Mar 2021 10:01:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230012AbhCVKAg (ORCPT ); Mon, 22 Mar 2021 06:00:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230040AbhCVKAF (ORCPT ); Mon, 22 Mar 2021 06:00:05 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 872BFC061574 for ; Mon, 22 Mar 2021 03:00:04 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id bx7so18500237edb.12 for ; Mon, 22 Mar 2021 03:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=25JkKQ8wLMwBM8dZG9fHs+5yC1Hbru9Q1NYWZJjuefo=; b=VmhRAtLcEce2aGOwcmHymL+fcVb6/S8ZvTs+LU9Chu1rABKfyHbj7odSrlNC/eul1A InjyN4onI9VBbtQp5XrMptyacWmBwygmFk94Yv3KnDWlzaXDWkz2BNs2hpDPLtSpzaT1 SnJ9pLqNWTMQWHvGYmjFfxeklnfI4Sg5XMv/KAVHiZpC6zDLt8fenleUh8fTodGXV/hZ 7+solRgJGP3LvjpAQqhC+nICuSqPo6ITtTevqyC+9DtQyfpXAsyumgjsco4dzISc1oHn N3a/prYUjfRjHEJHAqw0ckVlkt2We60hCTrKB9kTZ762r8n+bvQONnimh8GQDAbd8Tfy rrlw== 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=25JkKQ8wLMwBM8dZG9fHs+5yC1Hbru9Q1NYWZJjuefo=; b=R/UiTAY4i/oB6qelTWH4caMS+3rSduKG5doD0L5GXe66FGFuI6z12zqpN83yHy3nmN pQ9iPPcQolYKwQSwIH3XQ3M2fD35h3IarLGi4TjbZ9ndNWpa9v7B2g8RI07yfGQukYlJ 01npJ2g3L8BWuerUVlBj13y6JMP3iXMRpMuEYdKPpExOW36m1MtjzwOMHZ2ZlQEvqwMw ENY5z34bKUol3ApcPrvwlUTbMMGbDHxfdRN2ZgwwzTuOvzGCH5uIKqmlCTFe5UO6NNIS ggTjHVY7tXRUAtCsZ2vnFmThMfFwh7+pwjeTMmgWTHIJI/sZyDB0ru6WIWBmm8K5SzwI klwQ== X-Gm-Message-State: AOAM531y57RPMJk2MmrBA+MBptoSUaCeeCm9xpzXDVX1woCE805I+GLP QBEcD0zCHMlUrSvL6bUIQ4MM3yvu10dvqw== X-Google-Smtp-Source: ABdhPJyRxzHomJu4pL2gacjdfzRRxRmDszrxYlvBaLFrUtznOITf7mUgWNsjD+E7OsL5IqJiGn5gBg== X-Received: by 2002:a05:6402:34c8:: with SMTP id w8mr25530990edc.235.1616407203339; Mon, 22 Mar 2021 03:00:03 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.03.00.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 03:00:02 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 17/18] trace-cmd: Use tsc clock for host-guest tracing, if available Date: Mon, 22 Mar 2021 11:59:44 +0200 Message-Id: <20210322095945.259300-18-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org In a host-guest tracing session, if there is no user configured tracing clock, use TSC by default if following conditions are met: - tsc-x86 trace clock is available on the host - params for tsc to nanosecond conversion can be retrieved using perf interface of the Liunx kernel - miltiplier and shift Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-record.c | 99 ++++++++++++++++++++++++++++------------- 1 file changed, 69 insertions(+), 30 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 54e4b6de..552be914 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -198,8 +198,10 @@ struct common_record_context { const char *output; char *date2ts; char *user; + const char *clock; int data_flags; struct tsc_nsec tsc2nsec; + int tsync_loop_interval; int record_all; int total_disable; @@ -3708,7 +3710,8 @@ static int open_guest_fifos(const char *guest, int **fds) return i; } -static int host_tsync(struct buffer_instance *instance, +static int host_tsync(struct common_record_context *ctx, + struct buffer_instance *instance, unsigned int tsync_port, char *proto) { struct trace_guest *guest; @@ -3723,14 +3726,15 @@ static int host_tsync(struct buffer_instance *instance, instance->tsync_loop_interval, instance->cid, tsync_port, guest->pid, guest->cpu_max, - proto, top_instance.clock); + proto, ctx->clock); if (!instance->tsync) return -1; return 0; } -static void connect_to_agent(struct buffer_instance *instance) +static void connect_to_agent(struct common_record_context *ctx, + struct buffer_instance *instance) { struct tracecmd_tsync_protos *protos = NULL; int sd, ret, nr_fifos, nr_cpus, page_size; @@ -3783,7 +3787,7 @@ static void connect_to_agent(struct buffer_instance *instance) printf("Negotiated %s time sync protocol with guest %s\n", tsync_protos_reply, instance->name); - host_tsync(instance, tsync_port, tsync_protos_reply); + host_tsync(ctx, instance, tsync_port, tsync_protos_reply); } else warning("Failed to negotiate timestamps synchronization with the guest"); } @@ -3862,7 +3866,7 @@ void start_threads(enum trace_type type, struct common_record_context *ctx) for_all_instances(instance) { /* Start the connection now to find out how many CPUs we need */ if (is_guest(instance)) - connect_to_agent(instance); + connect_to_agent(ctx, instance); total_cpu_count += instance->cpu_count; } @@ -4128,6 +4132,7 @@ enum { DATA_FL_NONE = 0, DATA_FL_DATE = 1, DATA_FL_OFFSET = 2, + DATA_FL_GUEST = 4, }; static void add_options(struct tracecmd_output *handle, struct common_record_context *ctx) @@ -5801,7 +5806,6 @@ static void parse_record_options(int argc, int name_counter = 0; int negative = 0; struct buffer_instance *instance, *del_list = NULL; - bool guest_sync_set = false; int do_children = 0; int fpids_count = 0; @@ -5936,6 +5940,7 @@ static void parse_record_options(int argc, ctx->instance->port = port; ctx->instance->name = name; add_instance(ctx->instance, 0); + ctx->data_flags |= DATA_FL_GUEST; break; } case 'F': @@ -5988,11 +5993,13 @@ static void parse_record_options(int argc, die("Clock %s is not supported", optarg); ctx->instance->flags |= BUFFER_FL_TSC2NSEC; ctx->instance->clock = strdup(TSC_CLOCK); + if (!ctx->instance->clock) + die("Cannot allocate instance clock"); } else ctx->instance->clock = optarg; ctx->instance->flags |= BUFFER_FL_HAS_CLOCK; - if (is_top_instance(ctx->instance)) - guest_sync_set = true; + if (!ctx->clock && !is_guest(ctx->instance)) + ctx->clock = ctx->instance->clock; break; case 'v': negative = 1; @@ -6236,8 +6243,7 @@ static void parse_record_options(int argc, break; case OPT_tsyncinterval: cmd_check_die(ctx, CMD_set, *(argv+1), "--tsync-interval"); - top_instance.tsync_loop_interval = atoi(optarg); - guest_sync_set = true; + ctx->tsync_loop_interval = atoi(optarg); break; case OPT_fork: if (!IS_START(ctx)) @@ -6271,26 +6277,6 @@ static void parse_record_options(int argc, add_argv(instance, "--date", true); } } - if (guest_sync_set) { - /* If -C is specified, prepend clock to all guest VM flags */ - for_all_instances(instance) { - if (top_instance.clock) { - if (is_guest(instance) && - !(instance->flags & BUFFER_FL_HAS_CLOCK)) { - add_argv(instance, - (char *)top_instance.clock, - true); - add_argv(instance, "-C", true); - if (!instance->clock) { - instance->clock = strdup((char *)top_instance.clock); - if (!instance->clock) - die("Could not allocate instance clock"); - } - } - } - instance->tsync_loop_interval = top_instance.tsync_loop_interval; - } - } if (!ctx->filtered && ctx->instance->filter_mod) add_func(&ctx->instance->filter_funcs, @@ -6458,6 +6444,56 @@ static void get_tsc_offset(struct common_record_context *ctx) ctx->tsc2nsec.offset = get_clock_now(NULL); } +static void set_tsync_params(struct common_record_context *ctx) +{ + const char *clock = ctx->clock; + struct buffer_instance *instance; + int shift, mult; + bool force_tsc = false; + + /* + * If no clock is configured && + * KVM time sync protocol is available && + * tsc-x86 clock is supported && + * TSC to nsec multiplier and shift are available: + * force using the x86-tsc clock for this host-guest tracing session + * and store TSC to nsec multiplier and shift. + */ + if (!clock && tsync_proto_is_supported("kvm") && + clock_is_supported(NULL, TSC_CLOCK) && + !get_tsc_nsec(&shift, &mult) && mult) { + clock = TSC_CLOCK; + ctx->tsc2nsec.mult = mult; + ctx->tsc2nsec.shift = shift; + ctx->tsc2nsec.offset = get_clock_now(TSC_CLOCK); + force_tsc = true; + } + + if (!clock && !ctx->tsync_loop_interval) + return; + for_all_instances(instance) { + if (clock && !(instance->flags & BUFFER_FL_HAS_CLOCK)) { + /* use the same clock in all tracing peers */ + if (is_guest(instance)) { + if (!instance->clock) { + instance->clock = strdup(clock); + if (!instance->clock) + die("Can not allocate instance clock"); + } + add_argv(instance, (char *)instance->clock, true); + add_argv(instance, "-C", true); + if (ctx->tsc2nsec.mult) + instance->flags |= BUFFER_FL_TSC2NSEC; + } else if (force_tsc && !instance->clock) { + instance->clock = strdup(clock); + if (!instance->clock) + die("Can not allocate instance clock"); + } + } + instance->tsync_loop_interval = ctx->tsync_loop_interval; + } +} + /* * This function contains common code for the following commands: * record, start, stream, profile. @@ -6487,6 +6523,9 @@ static void record_trace(int argc, char **argv, if (!ctx->output) ctx->output = DEFAULT_INPUT_FILE; + if (ctx->data_flags & DATA_FL_GUEST) + set_tsync_params(ctx); + make_instances(); /* Save the state of tracing_on before starting */ From patchwork Mon Mar 22 09:59:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12154287 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 AB8D2C433ED for ; Mon, 22 Mar 2021 10:01:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8C5C86197F for ; Mon, 22 Mar 2021 10:01:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229995AbhCVKAg (ORCPT ); Mon, 22 Mar 2021 06:00:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230048AbhCVKAF (ORCPT ); Mon, 22 Mar 2021 06:00:05 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 498C4C061762 for ; Mon, 22 Mar 2021 03:00:05 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id a7so20182021ejs.3 for ; Mon, 22 Mar 2021 03:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xp2ym0L+FMQ86HK5AO6GT6GFNdJ0XuaFnuA6AnGsXcg=; b=YtpMf22XGkcREi8WGifVsx4rvdLdEJZfOl1Bpuy6fGq2kbPIgE2vzSLFQUlgrZ8WUo I7SPXEsjvxucytT0gQi1QIz7PVJCArquVMWAgcu8AWpHxsZcrqvVXZ43ZrDnGXsKkazD 8yZ68Qe4LlXtY6KY6E/WI9mVzWWJpFDcGRDfar3oG6kF/W1x6Dv2Lp6AAkUJPXEyWAOK xmsCmFKm1ec4sXHxHfDm76R3OqPvCVgpNsjwgcJLKv28AmtLuQnYwN4omqtblhlGhOGg t5jtZD4LlTkNdUwfNo9z85AMyA8HJOUDv+QwM4GvOGkL3/8mfy0QvImtJ11aA9zVVwVi KXHA== 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=xp2ym0L+FMQ86HK5AO6GT6GFNdJ0XuaFnuA6AnGsXcg=; b=SL5oHzmWjXbqTokF63SQMUEjx9yblQJJMSYWmosd2/wuNjbYeNjZ6OgwliPpwYeII6 HebGDJvY5/BA+5l2bbjoh6mH97uFtRjDLNtJQyGdXex+THIYCeJWTdtTSqv4Y8AI/JWy PMk0/1pNInHWWcZUTvAHC6+ckjo64k2b8F9KacT4T6hZxoQFZRc9XOC9YkiUKYkl1La+ MJklClhujP54NGTVapO8vC5gsFjYZ7B/KYy70gKZnPwNn/uuvc1K9Z3qjATIw3Vo5v1v jzHie+AiGL1EhpRUAvEdR3o7Xx+BgtOj82h6X7fmWAj+Gd7o7568Fv1iJ0pl6waWSidN Y+ng== X-Gm-Message-State: AOAM531K/cnejVKJ1R0TwA6k9lYUxrAIr4+RLurlKNhvhCIT1LxyHFc/ kHO8q2IV/HfIqlLeAElLHUueOefZLt8K1A== X-Google-Smtp-Source: ABdhPJzoSn1zfGyrCIUku06hKdDY1Jr4DSrG5SUDp0v2A4OG/QY8ry93bjGBZSkmSjJBxLalBnoaQQ== X-Received: by 2002:a17:907:1693:: with SMTP id hc19mr18150834ejc.28.1616407204095; Mon, 22 Mar 2021 03:00:04 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id g26sm9288424ejz.70.2021.03.22.03.00.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 03:00:03 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 18/18] trace-cmd: Get current clock for host-guest tracing session Date: Mon, 22 Mar 2021 11:59:45 +0200 Message-Id: <20210322095945.259300-19-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322095945.259300-1-tz.stoyanov@gmail.com> References: <20210322095945.259300-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org In host-guest tracing session, all peers should use the same tracing clock. If there is no user configured trace clock, the current logic assumes "local" clock for the session. This could be wrong, as other clock than "local" could be already configured on the host, before running trace-cmd. The default clock for host-guest tracing session should be rertieved from the host's "trace_clock" file. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-record.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 552be914..d0591e26 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -6446,11 +6446,12 @@ static void get_tsc_offset(struct common_record_context *ctx) static void set_tsync_params(struct common_record_context *ctx) { - const char *clock = ctx->clock; struct buffer_instance *instance; int shift, mult; bool force_tsc = false; + char *clock = NULL; + if (!ctx->clock) { /* * If no clock is configured && * KVM time sync protocol is available && @@ -6459,18 +6460,35 @@ static void set_tsync_params(struct common_record_context *ctx) * force using the x86-tsc clock for this host-guest tracing session * and store TSC to nsec multiplier and shift. */ - if (!clock && tsync_proto_is_supported("kvm") && - clock_is_supported(NULL, TSC_CLOCK) && - !get_tsc_nsec(&shift, &mult) && mult) { - clock = TSC_CLOCK; - ctx->tsc2nsec.mult = mult; - ctx->tsc2nsec.shift = shift; - ctx->tsc2nsec.offset = get_clock_now(TSC_CLOCK); - force_tsc = true; + if (tsync_proto_is_supported("kvm") && + clock_is_supported(NULL, TSC_CLOCK) && + !get_tsc_nsec(&shift, &mult) && mult) { + clock = strdup(TSC_CLOCK); + if (!clock) + die("Cannot not allocate clock"); + ctx->tsc2nsec.mult = mult; + ctx->tsc2nsec.shift = shift; + ctx->tsc2nsec.offset = get_clock_now(TSC_CLOCK); + force_tsc = true; + } else { + /* + * Else, use the current clock of the first host instance + */ + for_all_instances(instance) { + if (is_guest(instance)) + continue; + clock = tracefs_get_clock(instance->tracefs); + break; + } + } + } else { + clock = strdup(ctx->clock); + if (!clock) + die("Cannot not allocate clock"); } if (!clock && !ctx->tsync_loop_interval) - return; + goto out; for_all_instances(instance) { if (clock && !(instance->flags & BUFFER_FL_HAS_CLOCK)) { /* use the same clock in all tracing peers */ @@ -6492,6 +6510,8 @@ static void set_tsync_params(struct common_record_context *ctx) } instance->tsync_loop_interval = ctx->tsync_loop_interval; } +out: + free(clock); } /*