From patchwork Wed Mar 24 13:03:56 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: 12161089 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 14CDDC433DB for ; Wed, 24 Mar 2021 13:05:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4B4961A0C for ; Wed, 24 Mar 2021 13:05:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232501AbhCXNEa (ORCPT ); Wed, 24 Mar 2021 09:04:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233395AbhCXNEX (ORCPT ); Wed, 24 Mar 2021 09:04:23 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C8D3C061763 for ; Wed, 24 Mar 2021 06:04:22 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id v11so24356412wro.7 for ; Wed, 24 Mar 2021 06:04:22 -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=mrWql2bkv1L+P0BBKY7vCuX2NHh8WUzf7IFlE+FdBVE=; b=iFaoa6Iu5CGQfJ5sQdQqaTv2VfMI9i9u7eR27t5XLOvt9zBLusDsvx2BTHdGRqytyz Y2iN1xO/+No98756T6dou2CNht8dA2fTSAw3Lew/8Z6C+vcat6/33qoboBkszQjRchZl Swp9x6qCsIVo0s9ST63oLCOVkZvC4BlG4STcD2V+cvQho22ZGks7YgjaAIkUC4RU79Lm FVui9zpRTxuacWh2vjSXlV8V8dcR09k2YV8CY3ESvATD1/3/trHg2bLl6lISPma9b9Gu 6Lonf1iWuFl8qBwlmXUQ/8m/YDG2zyoO/rYoVRZ6dkfsxSjerZ4L2tdemp8N19j4LCPU HqJQ== 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=mrWql2bkv1L+P0BBKY7vCuX2NHh8WUzf7IFlE+FdBVE=; b=mGD5txIQHtBEQyh5STRYdqHtGmbS6UKEnRl7R6D+OLNt/4fx/ZYHeDzlHV7De3663l rIT+ZvIexHMFfEjXlhxAiONB16Kch27KBCxVHCx/fiiY3wbKbmElHmM0aQwpQUFU2uIh Ayvmy7wo85514oRcX9WJ9hAjLDyJp21PF+MVTekoNtQ9h1AaxPRVSFpO6aKdgoUhXGu6 CC/npSktRt7cpH+vv5uPdN9r5OrgIwfMmd+YPYaCliembbP/f93Q1YpaXmj9r9lB773+ Euk+qkHvCGJM6vBq3k8mTNzYyJl4goyFHTaEFeUGOuve8G0Ih5uQspfmr8zIm+tuSoQE Hl8Q== X-Gm-Message-State: AOAM5337gpm2ITqS7AL/wQCLO0VUsDS71EQgx+ZG3USrcLBP9RM6l+zP ld8BTrhRbTiChw7mPBmeqT0= X-Google-Smtp-Source: ABdhPJxpisnOL2Rpw9xzZg+CVnRx7wl5oH3SGnYXgU370o3xxJ7RHmRlmW+uKPNEINFeZfiJN85WAA== X-Received: by 2002:a5d:6cd2:: with SMTP id c18mr3428594wrc.330.1616591061268; Wed, 24 Mar 2021 06:04:21 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:20 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 01/23] trace-cmd: Add initial perf interface in trace-cmd library Date: Wed, 24 Mar 2021 15:03:56 +0200 Message-Id: <20210324130418.436206-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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..2a24a244 --- /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 && perf->mmap != MAP_FAILED) + 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 Wed Mar 24 13:03:57 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: 12161085 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 3D430C433E1 for ; Wed, 24 Mar 2021 13:05:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 133C461A13 for ; Wed, 24 Mar 2021 13:05:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233395AbhCXNEc (ORCPT ); Wed, 24 Mar 2021 09:04:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233906AbhCXNEY (ORCPT ); Wed, 24 Mar 2021 09:04:24 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01B8AC061763 for ; Wed, 24 Mar 2021 06:04:24 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id u5-20020a7bcb050000b029010e9316b9d5so1143396wmj.2 for ; Wed, 24 Mar 2021 06:04:23 -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=YLSZRHJ15BgheYH12K6bf4mztvdaLm+ZIUhTTetY+g0qprYkP7rMfstUN7AIWosHGW e8yGEGTxgWSPuOhj+k0gdKTeJsIW6bfS38tAz0Ca6U7mzXlczXrKl48gx0vaRy9Yfbj+ 4Rkb5mDqYR9axgCJrDxtkpEfoKZaxFekeRShvlr8R6NM7JIp+6JFgRUtxHJLsGtd+O5E bDPPzsyUjq0ebqMHUvkwjbQGaxOsp3X6JIoowuCxl3hU0oF7aISpi6pKhHShEbYGQ1/6 gEG8Pn776DBVTPZaNHmZTyDvgT1Gto501cRI6HLmHxL3/MzKenCUAbW3lKvw5sNFicdL 94IA== 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=anfSSgmmqj8eoLy+5BhARu7cN0m7on9x4YNp5rp10VbaQTcJw0MUWZ7IWETnrtIBFv okgMTdwS9CMh7P3F9hlhw2hNS0sOLZaBVVYrxmGwovvd8bRs00M6KCM+TDY4ArfaoeKI xSWjULAZTbMLGWKlLeR2NKOs9jVSPGqMsOOI3UtVtu5KvQpwcONPjHdM6F89NnuKbnfB 3shH/ZPNbtfZwdMb++y0YINO5BZiG/lUk2fPPML65BXvIw6o53I39dvA/6Lu8MunFSKR fNn27JlBxKJ6SrGMBBph9/ET4ldhhPNCboyUJA8E2sLnPjFHbKaShV2guDmlys8ApEY9 HjGw== X-Gm-Message-State: AOAM531utuo982hBDoQ2Yr8aKEfIchOVRJANq260fvcodLgTu8jrYyaM ng+y/+h9hKGsy8wdX5GvnLIiXldxysgbxw== X-Google-Smtp-Source: ABdhPJwwLu0YlfC+lVAR505BWHsdSBDdCtM6gDmZ4T9Q4KOzTKXtz/5utGWfMguZeYfIQREOWpptMg== X-Received: by 2002:a05:600c:210a:: with SMTP id u10mr2872671wml.147.1616591062265; Wed, 24 Mar 2021 06:04:22 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:21 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 02/23] trace-cmd: Extend trace-cmd dump subcommand to display the clock Date: Wed, 24 Mar 2021 15:03:57 +0200 Message-Id: <20210324130418.436206-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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 Wed Mar 24 13:03:58 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: 12161091 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 5EC5AC433E2 for ; Wed, 24 Mar 2021 13:05:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3919E619F2 for ; Wed, 24 Mar 2021 13:05:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233906AbhCXNEd (ORCPT ); Wed, 24 Mar 2021 09:04:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234058AbhCXNEZ (ORCPT ); Wed, 24 Mar 2021 09:04:25 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06496C061763 for ; Wed, 24 Mar 2021 06:04:25 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id x13so24357921wrs.9 for ; Wed, 24 Mar 2021 06:04:24 -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=FFmQ1fq57eAKEn7JoyEsw9BLI1uipnb77OWdbcAaJ1mOtwLv3dN08oPIl6Tq+Udxum apgSXxhbVEoFGhqGxhrrr5A+iFlxBASJqlczpvBGiaJHqAQaVnolrZ2sKJS/B7yDR65E sQwCzY28FT0l9gACn5JXHN2Ad83481lj7f2F24cMJv8Ta/wYcZTFCkscz8poMJ9bvieY TOxrpWUgGAWyQOmeTiq6+Ip4XX8S793yuvN1srDy1qsYhDkh7K8tmpcbRilbBtumYZBF WH7PFou3mvKqQhSCM/OzfsayL7j7G12PQU550kXtE2ynPbWwlaUHvYkJxy81nejrrgVo EhPg== 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=S2ZgYYyWAHUT5SJTnRM0p4FCXUpTSHpRe6cJ5JmVfVV3vTVOzLYQK4Hz++k7iNDTlY Qmgu/jIMkCdIm2Vy4KlnfBMSERMLF2ZJCIp7t7vz3YUDOueYO0jRz5BY0XOGSJV1hIf1 ZostGXp+TtN0NH6gMBJAbrUrPiSgi+y5yOHed5TGsKsfqGut6Pv1RLAPauuJXtdKyxFx ISQpsk2xVlWMPyVdPxLKS5ZkJ8TtbMOX2suMUPgbY5eMblZh8g60pxhxQqYcZiYlaalF I1VAfavJ8tAJGbQIBhl1QyaqzUR9HL3UO29W48Cp0KapAZBDLJ382B6x5WRRSRb7z39D AH4Q== X-Gm-Message-State: AOAM532O/3eOiXFDdOl6AsCpsbRwXQL6go9W5sWmDmMsYFO46gRdDSr3 EV3hpPQFkrqC76kJVIp5HyewbLuzG6AhUw== X-Google-Smtp-Source: ABdhPJzuB6bHx5+w34dxxaPNdQWW6c8/Y9kv0nePzTHbKAFdri//ysV4eXh213voV114atQhVvDmDw== X-Received: by 2002:adf:fe8d:: with SMTP id l13mr3313194wrr.81.1616591063797; Wed, 24 Mar 2021 06:04:23 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:22 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 03/23] trace-cmd: Save only the selected clock in the trace.dat file Date: Wed, 24 Mar 2021 15:03:58 +0200 Message-Id: <20210324130418.436206-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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 Wed Mar 24 13:03:59 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: 12161083 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 48B89C433E3 for ; Wed, 24 Mar 2021 13:05:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 25608619E5 for ; Wed, 24 Mar 2021 13:05:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233182AbhCXNEd (ORCPT ); Wed, 24 Mar 2021 09:04:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234065AbhCXNE0 (ORCPT ); Wed, 24 Mar 2021 09:04:26 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EF44C061763 for ; Wed, 24 Mar 2021 06:04:26 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id k128so10462525wmk.4 for ; Wed, 24 Mar 2021 06:04:26 -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=WDq4JxpNtg/mIRxKEMjeZkSbCUogjXW4ab8x4Wk8n5Q=; b=HqlE7zQJA+kWp+ILpbIMGQ1xFJYhZmheDV34zy9FNuxF+t1R37uEKH0F4ZKXh6TGGM TZNv7K85k/f01rcvEv7FUdK4a1rMQ1p/9r9xH1gmg5P1+y59R38BoQlfnmRAdtYqorbr Ku5l5f8nRU6sn0SKkVZEvQShh+P7SIc4oK1cLZjP34Jf/AsEuIy1H8xAYeoxjmogmete OMsWuYItVFIAmGWEBX9WvsuO9HOrqLzsk4kdYylrjRX2l/Bt0ApZRqmfmwiDYQYxhLFK nhIsaMd4lB5eJrfDKdxujE/7SH0rs2p2cHVPuXjBJxHYT/HWR3IZaHFAFb3dBYOyjmhg 3M5Q== 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=WDq4JxpNtg/mIRxKEMjeZkSbCUogjXW4ab8x4Wk8n5Q=; b=UTUfNqAFdRqxN1EC04dcnoJVGYKnp8D3LS00Fj3m/ZFdKwDH2DoSwrYw/z5XLr+7Iq bPvAzkbTX1LdHEU9N5dq8sVjVi9WC/i9aDjLWvpCdD/QlZXwv+HeJurxgf2m8vpoi5Ci QUfhEamcSEM2ExhJP+BfhNXV3xC0Bfbts/sr/tS4GoWt8qKSmQoMgBcZwv2EhOvxIzrR omDoCN6/78pK8X3vM8WGfMHH9aC0/Cnk7bbFcccmTY5Bt10vaP50I+w2gYkWcp9m3eVP FK93lsCQVtBoXFDJfvnUquSvXgnWI+RIKX1nAgHw0MJXAOCy1wBbzR2RiMYXDbuMK7kh AldA== X-Gm-Message-State: AOAM533y2hE/C/W+Fdn/f0bggaAiqLrPDWV8Gk/1zF92mcRfp/9txVTe K2EmANFpTn4vyDMLhY67hhPz8WLEjPAtCg== X-Google-Smtp-Source: ABdhPJzBRGy0qXDGY0ANpfm98k4ZVAT7btIQ+Pz73CThsNxVswUUEssfGEPObl/BW3/E4GtM5ycHkA== X-Received: by 2002:a1c:400b:: with SMTP id n11mr2792264wma.167.1616591064696; Wed, 24 Mar 2021 06:04:24 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:24 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 04/23] trace-cmd: Internal refactoring, move logic for local tep handler in its own function Date: Wed, 24 Mar 2021 15:03:59 +0200 Message-Id: <20210324130418.436206-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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 initializing a tep handler for ftrace events from get_date_to_ts() to its own local funciotn, get_ftrace_tep(). That way the code can be reused in the scope of trace-record.c file. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-record.c | 53 +++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index a0eb0385..635897e1 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -4459,52 +4459,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; From patchwork Wed Mar 24 13:04:00 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: 12161087 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 730C1C433E5 for ; Wed, 24 Mar 2021 13:05:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E8CC61A0A for ; Wed, 24 Mar 2021 13:05:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234058AbhCXNEe (ORCPT ); Wed, 24 Mar 2021 09:04:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234152AbhCXNE1 (ORCPT ); Wed, 24 Mar 2021 09:04:27 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61B63C061763 for ; Wed, 24 Mar 2021 06:04:27 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id j4-20020a05600c4104b029010c62bc1e20so1148331wmi.3 for ; Wed, 24 Mar 2021 06:04:27 -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=XWEGLIRdj+57c4CPY7xbrjfzkALdluV2F+0dWMm/4Z8=; b=Xx5DLFViugfqpBRQGlScs5Q3eblS0B/NOMpobWYbjF8xldqI5JyGSmKAZ7KcmWLr7a Pq8765z/9W7qvhnEbv+2LMDF8rkIwB7wzyFwXt+xDJ/uZi94nDrGdYWdkzZhfC5+z77S iULdVjz+zmfascAEh6rdcUsy3OqEMwvjo+J7J9PITYBXqlC+YzqTzgrJcDMptAiKXSG2 kzd7Ozu7MLf8PjXA7TD6Vz+IQp3kfBC5Ddc8XoGCFDr2LAqiMuB6R5eXXPDEWpyM0j1X YdH8WMznirmegODtrWpHxFp/04Da2r3NDRf0GzFAKFYKuOD7AoqvVfnu80Q2v+1ZjiTP Y4IQ== 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=XWEGLIRdj+57c4CPY7xbrjfzkALdluV2F+0dWMm/4Z8=; b=RthpZ1moxoBe/iHT54kNlhGyEwnkGXGtwOrfMaKDRvhI8bJ3P6hf3p5jn+fGAiToC0 7/643jUgot3JAwdoRC4Qp1S9rnu5HTeaZKuSwfIYxT37rmu5yVBPad3D6CC6zwoxhGk5 oxb7BNU5SbLqhKVNqhpbyYxZ/QcL9HHcBnT86HRLqi76HCZZrAk9Vg+ECKGeJ1ElHFQu VKA/VQv1yjNLAzXjQPpdKA3xm32qYcTVJcBEgTXpsykumz/qicVIEBQMSoXLKppWTbj9 J8bnFaKIqvVL7dsBlNLWNmuEtA/P0R8smKa3diphfTrEesx5gzWufBj8QV4eqSqzYnRg z6sQ== X-Gm-Message-State: AOAM532vIRH7TcJCp6V4Z+6rc9C+BXyh8Aw8lM9HEpzqgWZrSWduEiX5 6ZZWzw2YXd4Pe1AyXQsGGGE= X-Google-Smtp-Source: ABdhPJx8GI7VRPbXcCgwcgv0x+n6Qj1q6cgwWoP6gYQcCVxm9gZv/8emkfTkUgFo/QYMfzCRrFWgeg== X-Received: by 2002:a7b:c2f7:: with SMTP id e23mr2947573wmk.30.1616591066021; Wed, 24 Mar 2021 06:04:26 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:25 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 05/23] trace-cmd: Add new local function to check if a trace clock is supported Date: Wed, 24 Mar 2021 15:04:00 +0200 Message-Id: <20210324130418.436206-6-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org A new local function is added to check if a given trace clock is supported by the ftrace: clock_is_supported() This function is used by the other patches from the set. The logic should be part of the tracefs library, when a tracefs API is implemeneted, this local funciton will be removed. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-record.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 635897e1..5f7f5b3d 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -5683,6 +5683,33 @@ 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); + if (ret && (ret == all_clocks || ret[-1] == ' ' || ret[-1] == '[')) { + switch (ret[strlen(clock)]) { + case ' ': + case '\0': + case ']': + break; + default: + ret = NULL; + } + } else { + ret = NULL; + } + free(all_clocks); + + return ret != NULL; +} + static void parse_record_options(int argc, char **argv, enum trace_cmd curr_cmd, From patchwork Wed Mar 24 13:04:01 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: 12161093 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 85D87C433E4 for ; Wed, 24 Mar 2021 13:05:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 675CE619E5 for ; Wed, 24 Mar 2021 13:05:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234152AbhCXNEf (ORCPT ); Wed, 24 Mar 2021 09:04:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234190AbhCXNE3 (ORCPT ); Wed, 24 Mar 2021 09:04:29 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4C79C061763 for ; Wed, 24 Mar 2021 06:04:28 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id x16so24366051wrn.4 for ; Wed, 24 Mar 2021 06:04:28 -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=K2T4uniV500/F11/PZ5OwvG4e2YWyyjPFFVXLLHfb4s=; b=L9jH6AKzc/4dAQnN0vInu2Z5yJfjm4FSJTzeQuGGOiWWDHicmr+fxgnKcRgFSob05D 4eIEKm5RehM5qSbI5SzHkD6JSvkqLwInRocGCcQXEFr2O/FDfnu+HhfWGWlPFfZZgo4o DD0C979d8BdkvEPFHjORtRkQ1ym03Ot55VMC//RpVETIj3YqTAU0pIcc7/Adzwp5YvDF zfLm8kgXuC5R6rCQTpcRu7+W9IdM2OMFWuUbhxQXWebzLRdGtMXkFUZ+yv8ZkHEqkae3 DzgPc0LksABCCHWpG9SnWImLWU+Rrq389EnJVvNIrCaE0vJVcloUNtpnxKHgZx4zJ9Mx UhlA== 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=K2T4uniV500/F11/PZ5OwvG4e2YWyyjPFFVXLLHfb4s=; b=pKLw8Cm4tfbuWb+3YiNnX5Q1L1ePMLACBkaQgClfRYcl1RQWSwiuSQNRRzM25YtCCJ 0rCXI36TjvXctwNxp4bXT/9L1ogG0Q46fTZzdk01y0YP1ZMvkGWcR7QaX8AF06Du6cIG 15Xu0QqPvttlp4XxfJ0qIgZPp8ry8b3iya7oOczpgP08Sj8yCMcDU/3oUbaWwGt2/Mly S3xaS3g5uaO1LV9B6qerKoopKOFCTSjcYH0rYXVBLicMYfFOsOpoHKXsO/s8hjghzsjp eBBteu4VUhQVHuzI5OurxaKlVAX5IVQiM6HB7OrTc9V7hd6+xuNk8Bxxjdt6C9eJPqy/ oOQA== X-Gm-Message-State: AOAM532GJOhsO+q41kKMFb/teiRuQpXBiuwg62/Kzo/2ZTWsuPApFJQP ciN1q9+O5JzqiBBmkPqJyKg= X-Google-Smtp-Source: ABdhPJwjNSgXngV2NJyi6Ys6nI3UZJAchxe5RjN57ILflAQ8qx8HjjsLHPI9KBdphwjCtqZD8l+e8w== X-Received: by 2002:adf:e5c8:: with SMTP id a8mr3459303wrn.352.1616591067262; Wed, 24 Mar 2021 06:04:27 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:26 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 06/23] trace-cmd: Add new trace-cmd clock tsc2nsec Date: Wed, 24 Mar 2021 15:04:01 +0200 Message-Id: <20210324130418.436206-7-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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 | 146 ++++++++++++++++++++++++++++++++- 2 files changed, 149 insertions(+), 4 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 5f7f5b3d..2a594736 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; @@ -4527,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; @@ -5388,6 +5392,7 @@ void init_top_instance(void) } enum { + OPT_tsc2nsec = 240, OPT_fork = 241, OPT_tsyncinterval = 242, OPT_user = 243, @@ -5710,6 +5715,61 @@ static bool clock_is_supported(struct tracefs_instance *instance, char *clock) return ret != NULL; } +#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, @@ -5759,6 +5819,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} }; @@ -5904,7 +5965,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; @@ -6159,6 +6228,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; @@ -6306,6 +6382,65 @@ 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; + 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); + close(tfd); + +out: + 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. @@ -6364,6 +6499,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 Wed Mar 24 13:04:02 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: 12161103 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 0632CC433E0 for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A3E3B61A0C for ; Wed, 24 Mar 2021 13:05:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234620AbhCXNFG (ORCPT ); Wed, 24 Mar 2021 09:05:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234065AbhCXNEf (ORCPT ); Wed, 24 Mar 2021 09:04:35 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97F1AC061763 for ; Wed, 24 Mar 2021 06:04:34 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id z2so24393242wrl.5 for ; Wed, 24 Mar 2021 06:04:34 -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=4UIs+hZLDi5iAqomvDA/upvdNqsH5erDUfGFvSxCEPs=; b=p1hrHgRLxskV4iQ+rUXcxbS1MN73sbmsf91mTitXHGGZUPIcinQX6JoyyxxivwYN2o b4v52rPdDNOPJNLztBWzblkkw+vebf0NDZkwKl9k/VsUR9MqRRfe/vLBxyFOmbQt6yRm 0DLI5HXgWyBDtROgwc5C4SOh7+tGEvxq2LZ4hDUUOFbnh3bBKgHkCrLmbtlh400+/XCh +fY9C3WYbZ9JW8YxLDjwbT+Oz/cB7F4q8MWBCsviFTTgQY5DUPbx/WBKG/D8kYhbwg4q eRFc6fWAPb+ls0ZLPP1JAKS13fK1uS3AglZsPqE226SHyG0K104Nm4H6cEtQzbFjFA02 Ad2g== 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=4UIs+hZLDi5iAqomvDA/upvdNqsH5erDUfGFvSxCEPs=; b=pIwu1gROMvdzkv+WIm4SgnxLQQeMGKjDqzcKki+Jk8WJUA6Iz+3pRDSVi35mkAfu8e IV/4CJOxpoyw2m7uarRaWcrv9TPJx7ztmPzmFz4/AITxuqH2Wu96Y7B0PaE781E3qXyh 9ts9gse5YbyklUiXmILlNaJvVzCtDUOUzHA2j/JSKX7ZntS7ycmKEeKlBUN5zYfxJTuv cT9joSAeuANxwIMvT+b5J+APTH0pOw7/mqNnt0fGXfnpKY2cK2vC89etgbM9AzySRAMh 3hj/DMoRnBpCAfH28ZJqZEK4aoDsvLstXvBS7vJ7nu3kkrS7m25g4m96QU1uzuBAWIu0 5nKg== X-Gm-Message-State: AOAM531SqBzkP3FL3VSzeiRG33B/bjuhCBpJ2WVMv3Rfq+aoav2ZU5ie efUfRWOeNeDFc0o+UhU+41g= X-Google-Smtp-Source: ABdhPJxecjv39P+KHSXFZ8mUFVT1oqG4appD8TT776jsDA0zrEOPIJfhSw87xASAfcB6SkJbnmoccQ== X-Received: by 2002:adf:e38a:: with SMTP id e10mr3418328wrm.37.1616591073322; Wed, 24 Mar 2021 06:04:33 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:27 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 07/23] trace-cmd: Define a new option for tsc2nsec conversion Date: Wed, 24 Mar 2021 15:04:02 +0200 Message-Id: <20210324130418.436206-8-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Added a define for a new trace.dat file option for tsc2nsec conversion. Added logic in "trace-cmd dump" for parsig the option and printing its content. 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 Wed Mar 24 13:04:03 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: 12161097 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 94AAEC433DB for ; Wed, 24 Mar 2021 13:05:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C530619F2 for ; Wed, 24 Mar 2021 13:05:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234593AbhCXNFF (ORCPT ); Wed, 24 Mar 2021 09:05:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234190AbhCXNEg (ORCPT ); Wed, 24 Mar 2021 09:04:36 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8381C0613DE for ; Wed, 24 Mar 2021 06:04:35 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id o16so24392203wrn.0 for ; Wed, 24 Mar 2021 06:04:35 -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=qshlzDiqvkw9WgYjrZrIZ2GCvYgKoctVCVPSsN0HRY0=; b=fOFdCivTqUQJliJXKRxUQYTF8paOEQTIeJFafyqp/SQu4KXvznwLTblZV0edaJH92l Bp+6AxXwxGfuyj5uwtTFd3qBQwwJxU8wwZPJ/Hnb6wixIDG2TO5pVA/cKMlbqW1/mqM2 o0JeqHp8BIyC/akwQgxQ1P0dHjdfLXB02qzjYV5pCPWZt/MWf3qwAkQAusovFUbydIEd VPFrzOJQgB0/wUKtHAvVPC8TJob7WR1S+TZA/lO6WnaivFphQOiDGSoHWfNSot9UmVA5 v5ovSJLIwcoJiml0QHNSWkaX1RvJQMtPEr9CgLX4NEC9kZOvy0IpFHxnsXIIdSWbgGOV n2cQ== 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=qshlzDiqvkw9WgYjrZrIZ2GCvYgKoctVCVPSsN0HRY0=; b=EPt/RPu3G/Son3ni8j8hRrjcESbRYalFinvu4Mraw+V418WFsJMmbO6gqI+Pi+Mt+l viDOPbIBM1ppmNk7XOeCxCXczXXReowiZv8GljiFEstUWsRF5e4T81a7gYfwlxD9vwg+ 1Mypw1L/dr0wJbiryIIAx0lXTlwzbANLgj0K48qXNy0bRgPASR8gyUU9CT6ixh2NfTbK /1vRSCRAzpFbpHJrtu239UDPpm4D/0lb4UtU1m7kewbGCNvhAoh7jCUEfly98psfxOU0 yjEwsJQPXc5OPvpkLW9IvJ8OYlOuUrh8j2eRQBQrNXomS3fZjsgz8rQzidyqz+K698mD WReQ== X-Gm-Message-State: AOAM532WBso1kLu0jG8JGFLywnynCSCg/8WbGjNm2AlQRHibdWAuopJ+ dqbFfBaOxCUq6XQCiXTfnvQ= X-Google-Smtp-Source: ABdhPJzzyrFjHg6f3tA2cPUsha9KDyDkb9cMNFtAtsCBr+TYL10FRPW52aAfHPV7qknUMhH3qrZOfA== X-Received: by 2002:a5d:6587:: with SMTP id q7mr3389667wru.282.1616591074449; Wed, 24 Mar 2021 06:04:34 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:33 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 08/23] trace-cmd: Save information for tsc to nanoseconds conversion in trace file Date: Wed, 24 Mar 2021 15:04:03 +0200 Message-Id: <20210324130418.436206-9-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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 2a594736..9b652c64 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"); @@ -6582,7 +6606,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 Wed Mar 24 13:04:04 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: 12161095 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 C31C6C433C1 for ; Wed, 24 Mar 2021 13:05:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 856CB619FB for ; Wed, 24 Mar 2021 13:05:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234689AbhCXNF0 (ORCPT ); Wed, 24 Mar 2021 09:05:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234381AbhCXNEh (ORCPT ); Wed, 24 Mar 2021 09:04:37 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BED08C061763 for ; Wed, 24 Mar 2021 06:04:36 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id x16so24366512wrn.4 for ; Wed, 24 Mar 2021 06:04:36 -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=IEhy4zzTk7ONYG4cCIGVfQ4y1qKY9DkAY8EBW0HAlQq8y7ZHr4tN/UI+WlxyERQIyP Tt2Z3x58eLcgCmCN5U4gsYQcns9oXB0kTFp9z1Bd4l8D3jiqnykKQd7lHCZOJBLJTig+ Fol9w+XWqunsFtCzUI85dsy1mMXVzfby1iK4YOpBMy4dnmabvXeULdJd8M0aqUL1vwaP jUIuiPEJq3HSt1T4mIINzisu+qR6B2Q6jPes/G4gVF30hfWlpFsS+3Nmv7CCkT1DXc2K X21vURmMRJIxy5Jf5kbYfhKb2Lwsh4Xh75+ci+u7ci/n41G5bdTMuo/QK9MMXcmGfV7S A6Ew== 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=W0FlGZ0Ovj9VORECsXkdZ2BAvADmfO2pF185OLPZvMry0hr8YtGCp9CgzAyOFXHMhr 7LgOzkwRg8gyJhaN2OKCfyC4tx8GkdD4zpGIGCCPu/NqBwRXgc+uOIOqH/oqzRVCeu3Q GtanOKuajEy+mP2zgyPzXzg96pLyMlTc0udiQxIkrCsx7Rxpnul7r+poGch0UC4mb5g3 57AZJNJrEmz+WOZpEMiVRkozmM27VcF2Klyk2oRcWgaf/nsw2s+5uUEXd+klzYzRT+1t CLacC0iuDOO+s8SI5zArUC9BN4ZCLVEvGKhgIdpoWXhSVF8/N1RxRrrobUIofBdHkWIv 8kUQ== X-Gm-Message-State: AOAM530cqhJWCyPKQyH51QUskpeBJZ/J81RTUnFNbnphZmatCE3u5np+ 2lvzGZF/SkF2FMUY83M+I8KOVw7Xw7uN4Q== X-Google-Smtp-Source: ABdhPJz7xu6CSUQcawZfaRGAV0QKdWfruDLk/2+LkVTm9ez6wNYuSXHIN0i8rCbIP0md4yecP6jbdQ== X-Received: by 2002:a5d:6ccb:: with SMTP id c11mr3468458wrc.122.1616591075525; Wed, 24 Mar 2021 06:04:35 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:35 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 09/23] trace-cmd: Read information for tsc to nanoseconds conversion from trace file Date: Wed, 24 Mar 2021 15:04:04 +0200 Message-Id: <20210324130418.436206-10-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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 Wed Mar 24 13:04:05 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: 12161105 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 405DDC433E2 for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0BD87619FB for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234381AbhCXNF0 (ORCPT ); Wed, 24 Mar 2021 09:05:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234393AbhCXNEi (ORCPT ); Wed, 24 Mar 2021 09:04:38 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2E80C0613DE for ; Wed, 24 Mar 2021 06:04:37 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id c8so11466335wrq.11 for ; Wed, 24 Mar 2021 06:04:37 -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=IADVNGrRtbQctJbk3TpTPaQERBg+o+o6wvAZztJ3F14=; b=bfdNEE6HqOiHBB25NM7eQTcG2HyWQUX42/K7xqvfLkRnpmncMaQntnkvH8PSYEt4By SPBoLUH+gbXCHbL3ct/VYw0CCSVDjIr/gl099MwSw5o4epw+zr/tvXXcdTiAfJ3IniuJ v3cT2PSF1au7XsGWBFMVj3bFAygFTuc4flNfr/MoLou8WC5Qf+cAFZkLHucXAkfKF+Kd Uj+6bRxn186sMVBgWi1/OjZdHhyDcWD0iwNQtCbo3A5mB8bCDBOAVR+0CYL7a4Tai8aJ 05LYDfuPCLldr8et+jiGXI3i6QqyELvbyEMwe2y0AFeye9ryh9Fm3pEavJS/SIiYyEMV 0+4Q== 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=IADVNGrRtbQctJbk3TpTPaQERBg+o+o6wvAZztJ3F14=; b=JKoCymc/dOKZ4q5PnaaGnGSD6lQU7AKLBhCjqmG8DDLSoaJxBiH5ut6NRjNNYY4mEM IUFyl86zWVEQ36yXH029GXaYMS41286T2qxc2DMXawekgZScc1uugPh7wQXyiIr8k4RK iD4LYPK30l0OfsvlihGYmMTkxmpaPeRV4HkwuXR9Rx05a7pMIHfkSlznkAhGd1EvovtS DjhAEbUfZ68cp91qRhugghipsbS+kWFYWIULICEkNAuV5O0+BSw4MI/aMK4VjSoEfFyD 93SmxfdLHPH8JLVB+A6daIreFzsmyj64ZSRU0XnbXGXDnEkMlAaeeVcjxpHSUHcsf0jQ ao1Q== X-Gm-Message-State: AOAM531PXDMm0+tCkgBJZiFMmx6JMAbIbT6Pz2xugzQBOik2Bg8Tqk0r lNLaCUu5s1rfSe1uKH0fx+SgJU8nXSYjTQ== X-Google-Smtp-Source: ABdhPJxXa7f07+6eGasrwxpxip+m4nsPQOITdlx34M9lIMY0mJv9Zo/1H6F5fBORbPfH+23MSJn6zw== X-Received: by 2002:adf:f186:: with SMTP id h6mr3450847wro.290.1616591076391; Wed, 24 Mar 2021 06:04:36 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:35 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 10/23] trace-cmd: Save tsc2nsec clock in trace.dat file Date: Wed, 24 Mar 2021 15:04:05 +0200 Message-Id: <20210324130418.436206-11-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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 9b652c64..7d2a8013 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 Wed Mar 24 13:04:06 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: 12161101 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 2E562C433E3 for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E7D1061A0F for ; Wed, 24 Mar 2021 13:05:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234393AbhCXNF1 (ORCPT ); Wed, 24 Mar 2021 09:05:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234412AbhCXNEj (ORCPT ); Wed, 24 Mar 2021 09:04:39 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E226C061763 for ; Wed, 24 Mar 2021 06:04:39 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id m20-20020a7bcb940000b029010cab7e5a9fso1140002wmi.3 for ; Wed, 24 Mar 2021 06:04:39 -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=uSi3uEcmkaXEuP6Q3gKY3I92rv2pVd6xu8pIP2dyV4I=; b=NPkgRpXNGmyOkIU/ECi//KX/u9Z6p6lqgWcTKlA+S0VlQ61T17Y9gH6OYCCdKadlwz x78tdWUjI8OwgeiKW+jotmnq22NGlOOIGOXVu1dmMafgKZGKCFAGbRTHjLpt2GcioqJQ OX4PCrHEPG9Nt/fG6yQxR2pkjnsSXRxHLkWdEsdLFW4RsZspkvuiBW2kx6vYZLdAiEPY /nEEMyk662Q6jQoDUn9ny3RNgNVt28f2jaGswr9grNIHqiqOzuWQ0gsJqio6PkPs/3m3 6Y9bYXlZtgDCzhX58AfGn1b3w4j7Xf1A1I27E3vWOrX7fPXQ65eOf8j4zhV4dzSJmhTp NPvw== 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=uSi3uEcmkaXEuP6Q3gKY3I92rv2pVd6xu8pIP2dyV4I=; b=oQB6xARY9nFYJ/EP+JhprtXQO8xtUdeoN7nDdjJ3nCySYuzrBB6RS4a7OH5u2DuxVy Rmy7R7K7E9/s0YoQ/7s9+wW2+VZa063WlZMdSQY5X7YEFgxkuSruwJpg3NsZietDTgSY BTyf5NxJTVOHasi6oNo7PYYuarwGUhQe7FhT+vzerw1NDhK+dD+O8crH9mWpM1OuNVQA tyCA2Hti+Vv9jkTTF+1ydJ2S6pbXdU3Eer7rHe+ALsce3arC01zAceK+UPvV6wlJPrtm yp1X9MEYIw0S9LnBhATKPDTn3XsyWOutynIHznM3zKQME0+SP2SRzzB4ouN+6wgtr6g/ EjvA== X-Gm-Message-State: AOAM5339f2EK01vzHeEARWclsF/2yBBDTdmuCAASyUuoEWfG4oQRWiva ynShJZ6KVumVrug6On/LKVOvqSFapsTTig== X-Google-Smtp-Source: ABdhPJyupAZbF0Dsed5erl26iSTeQvDtGTrJD9lCmBby+Xf8C8XlrRJjdPrescZmek/mj7X3IqLWjw== X-Received: by 2002:a05:600c:4f8e:: with SMTP id n14mr2937200wmq.34.1616591077536; Wed, 24 Mar 2021 06:04:37 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:36 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 11/23] trace-cmd: Append new options into guest trace file at the end of the tracing session Date: Wed, 24 Mar 2021 15:04:06 +0200 Message-Id: <20210324130418.436206-12-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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 7d2a8013..00fd4a1d 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 Wed Mar 24 13:04:07 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: 12161099 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 15F3BC433E1 for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF43061A0A for ; Wed, 24 Mar 2021 13:05:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234412AbhCXNF1 (ORCPT ); Wed, 24 Mar 2021 09:05:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234420AbhCXNEk (ORCPT ); Wed, 24 Mar 2021 09:04:40 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E946C061763 for ; Wed, 24 Mar 2021 06:04:40 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id k8so24363747wrc.3 for ; Wed, 24 Mar 2021 06:04:40 -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=VKMeFHYFMaEtsmgBPRExQOvHMfmJ6uZ2bd1VsuOKfnfcOEztlF1qBAoQVEFsfYCsXQ FwULvld9dhnEdQvhEV0cggdkZFqrM2d7wWzX/nmx0lFNVtm9ZwjyXdYzDoRj+YkBT8nx ruJJ8uRTW3ZlsPxu/7c+dAhgN5wuSVcLpA1v6SIH7tUHhN3GEmJeXbbtglGapSRV5HVs joVuR0Nxwf0zabKqyKp0tv8hEmS62oLIDJ+dP0EOLyFkvDXxgm042+MZlbwn65vXRO7a fhj4r2QYevecbl/mSRENZc1uupIKPvURzoJHgdzQ1m9ISxjHFiXc3zNy8sQpwsFBBDce +fNA== 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=OWz6sZWmIb8J35Hn8mOGgP6XhWAMInpccoLiz03OAtmYL8zXsoVzjacaH4vc8h9lOU n9iDDBvjaYs5YWECX22d+uEz4JD9twXk6w0caTtGsyuceNqDhFNcqY4YRUDNbrrMMDsF qkGXEyiXC+9ktb/xKUTve6SJYH+VVFEpn8fypjWkWshF1Kq/4AnGG1GjeUuHB/67YcCD tNb9/TAqo+OZ7qAsIRRTShEVH0HTBD/aJBZNb5DvcMT4GMQH2Efdx0pYuF6azvHtjS9p ONMcvfJfjQCrGRlYBqT4UX8MIq8ax2zl/pn93+cFQWWpQQfjAb2B9bqMjY9D2LzjNHtK tmyQ== X-Gm-Message-State: AOAM531e2QITR2asoai0VP7iYbXj/w/4E8Ca3h+HtV0wbppyay3BSzDL TzgWQRit3WuBvIjM/PooEEw= X-Google-Smtp-Source: ABdhPJwi34ZjU0zH+0LdEjHx9uzj/1OvZmc6r0LfEDCFq1X9NfngS+1uYp7WvMulK63EavCwxQRA9Q== X-Received: by 2002:adf:ed49:: with SMTP id u9mr3394167wro.337.1616591078883; Wed, 24 Mar 2021 06:04:38 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:37 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 12/23] trace-cmd: Remove unneeded multiply in events timestamp reading Date: Wed, 24 Mar 2021 15:04:07 +0200 Message-Id: <20210324130418.436206-13-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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 Wed Mar 24 13:04:08 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: 12161107 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 775C0C433E4 for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B97B61A14 for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234228AbhCXNF1 (ORCPT ); Wed, 24 Mar 2021 09:05:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234461AbhCXNEm (ORCPT ); Wed, 24 Mar 2021 09:04:42 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECEADC061763 for ; Wed, 24 Mar 2021 06:04:41 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id n11-20020a05600c4f8bb029010e5cf86347so2664235wmq.1 for ; Wed, 24 Mar 2021 06:04:41 -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=HqCDMS6/zKiTKr+JmBzugazZXnt0+q8DIKy+t/24CuM=; b=hHibC0QPbQr0dbeOi5EqOv0n7Pjokd8qVLyzWDAYGF3CnPsHR8ootuA9LqisWGg27a iDD2FojO2LkGwCW0Rmak2ALGbXpQjUy+JkLSB7wOnaSWwHSb4dBXK4N3F+xJHyWH747R ppxilxN2vMDEuwfRTP42fZrhVn9lSv0hYgqkfBCELb77n6hoHhjXkpS4szcpT8qSRE0d Xn8YhWIEBba6Utf5fB3+ZNdhbHPGqjfrw98q60IZgwwGW86prRD0ZGd/iUXq9RIhr9fL 8SQp29eueE27D780Oo2QBqqQjZqVOmz9xIclEh36EftCe0nWoTEZhmDGV5/7O86pGwP/ IbjA== 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=HqCDMS6/zKiTKr+JmBzugazZXnt0+q8DIKy+t/24CuM=; b=fUQN1i9x5wGuY/lsM3c4XhoeF/D0+hKXIqlfWDTKl9iTfIkhmw1y7Avx/WBiYzz4GQ RRUW8qDPggwllKH8fzFbPvUwkFw1eG/meCCU7LfrW5DlV9UNmmNRnCMbVeCk1gBlyltt l8Kvp6eah71w6it784M97ONRYrstr4JYl7tY/IucWvDE7o6x+WJmzAcBedrvLPCvSFud 9m96yip+0Bz2LQm8wAOnOge9rEHmEStfJZ8tzIOe0VcKJVWe9BPANe/7yrRIW5qAv5yf DcJIi5ev7Ct6U4vxx0KlqmjovxLl34zMjLQ9nrIBh50H63XZQgfj72HAgu7EeiSFIlSb skdQ== X-Gm-Message-State: AOAM533kfr/75oAqky8deJM2FjJGEKwd6/I39CGZsQLJJjYWeEHVm8em 0JdEe4XlqQDqYEd6zUQLbf2mmgnwcwI0eA== X-Google-Smtp-Source: ABdhPJzU61nt8oZcLszrecNOUlq2N4GljbLuyFKv7ffaFVrCRwEQN/gHSAAFx5NeMjDc9mZlJmkd5Q== X-Received: by 2002:a05:600c:2947:: with SMTP id n7mr2913179wmd.61.1616591080251; Wed, 24 Mar 2021 06:04:40 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:39 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 13/23] trace-cmd: Perform all timestamp corrections in a single function Date: Wed, 24 Mar 2021 15:04:08 +0200 Message-Id: <20210324130418.436206-14-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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 | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index be8a7919..e1842cce 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -1276,6 +1276,17 @@ 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) +{ + ts = timestamp_correct(ts, handle); + + if (handle->ts2secs) + ts *= handle->ts2secs; + + return ts; +} + /* * Page is mapped, now read in the page header info. */ @@ -1297,10 +1308,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 +1939,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 Wed Mar 24 13:04:09 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: 12161109 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 8E57EC433E6 for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67C9561A0E for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234420AbhCXNF2 (ORCPT ); Wed, 24 Mar 2021 09:05:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234474AbhCXNEm (ORCPT ); Wed, 24 Mar 2021 09:04:42 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54FACC0613DE for ; Wed, 24 Mar 2021 06:04:42 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id b9so24387053wrt.8 for ; Wed, 24 Mar 2021 06:04:42 -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=qvFUgy6miIeRLIu13Cf1pJ72y5BXBpHZC3n7LJ9dlbg=; b=Tnk7OlgaplGvlZ+CyTB/cwoyKRk6hZNFoMa8rEVYThDJ+87SvFUu7UbbbFLZDa1UQr CppjLrXgxteYRJAsx5RjmoRJTWPYlLblT6bU5GcimTl78FIA+K8GyEAKrO+dGxvlJMFb ebuKN/7hmrtUFyxU/CAWUepR3JyF+NimYiuJqH2n2u2F0g1VUYcQ9v0Y4SyhkLC1VI/N 7nmwICuEdIrrXbj6bJzUAvWvFv4ZHrkbzhX7gbExBpiSXn1NBuHzKJfwsfs1olnc666R dwziE5/WeAr4ccRdSuYibs7RD5Xt4QQbfVXR/i/t5u9A7NUuvDO1fXMGCGIXXep5evdn stqw== 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=qvFUgy6miIeRLIu13Cf1pJ72y5BXBpHZC3n7LJ9dlbg=; b=pcfBBilynjt+YhW8mJf/vocbsbE1RfX0HuAvxDc+hl7A+Y2XVRpIp886MhSpnTGPIr +0FkqvBddLIlv/kN0AlV2s1SiEVshDDtvoW4wmgy6fPh8ZXAaExM12D0uWnnlkm0T7Ls Eb58Zu+eIduVQ+T3U0mvtiiA8xPw02OVrwfzQX1hy34jCL13fHUcOm7aDgHyxRT0ntDp Vn9N+Tw8eogaRcSzIQFx5xoylPdF6Rfp80H+EzmqIN6RTa6xgpd6on1bILIzWq8/1fux Jy9N/PSYFzYLkFYtv2/U97Ky1oh7+KZg9NKagyPns19OKwrcXCuKlTs6sajaplnBahlo DPpg== X-Gm-Message-State: AOAM531Ff1kk3wjMrCH7AQhVArGVKjSdDpstd7984RtipD6/UJCwGZbs UK+ksdIBbsVJYZGj80vS3Z5Yy3SZD43BTw== X-Google-Smtp-Source: ABdhPJxZ6jA0OLqjKBO1F8XtTxsFihowAcHUXTmTjpQpUOWCoLenEyQVGLK6EM2Ec8sLU6E+u+qcDA== X-Received: by 2002:adf:84e6:: with SMTP id 93mr3246461wrg.376.1616591081133; Wed, 24 Mar 2021 06:04:41 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:40 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 14/23] trace-cmd: Convert tsc timestamps to nanosecods when reading trace data from a file Date: Wed, 24 Mar 2021 15:04:09 +0200 Message-Id: <20210324130418.436206-15-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index e1842cce..266b0b0c 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, @@ -1283,6 +1300,10 @@ static unsigned long long timestamp_calc(unsigned long long ts, if (handle->ts2secs) ts *= handle->ts2secs; + else if (handle->tsc_calc.mult) { + ts -= handle->tsc_calc.offset; + ts = mul_u64_u32_shr(ts, handle->tsc_calc.mult, handle->tsc_calc.shift); + } return ts; } From patchwork Wed Mar 24 13:04:10 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: 12161117 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 E72EEC433EC for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C7A2961A0D for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232800AbhCXNFa (ORCPT ); Wed, 24 Mar 2021 09:05:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234485AbhCXNEo (ORCPT ); Wed, 24 Mar 2021 09:04:44 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31213C061763 for ; Wed, 24 Mar 2021 06:04:44 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id j4-20020a05600c4104b029010c62bc1e20so1148909wmi.3 for ; Wed, 24 Mar 2021 06:04:44 -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=MpH8LyKwbje/aQPtMTItjN3p/dZCO7Xx1rGgpNhlQyU=; b=uL9vb5RJz5JNsGcv5SpbERaLpWH8BZKW8/x0HC5RKevlWPAdlV3VX6vkxnosB+oML0 LFgsql7xImO+MKIgTmdgVotwzQu4SztnvPRbJerh42XvKeZvOxl5AAjXz5CF9w74l9ep hYTZRJnWxUXwQ5P3lpsTaLWwP5c0BmIvDUl3p4F2QJn7ch/3xjuGf4JSkPMszf36fCD0 zel7uiWpjkDvrQrNW3Yxd/l6cU8qfQs1GLyXtMhN4mQK7UaXbtYwifRl+xsXwikgYw99 gK/iogkDYPO+qjjMIdW6Pp33oVFC7toInqmkWAnroRL2/3zR1f3D016cfc11QEUWQDh/ +muw== 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=MpH8LyKwbje/aQPtMTItjN3p/dZCO7Xx1rGgpNhlQyU=; b=demZL9kYSJQcy+PH/6Cq/P8bGhmdoL0r+OMuklbwA0AMSeERBrIamu8uIA6gkRAe2I bARJBa6WjQiHOmhN/AH4y40hQdpRtYSmIxIQLtDmMzIhP9iGoAkJN7g3PCcT0Fb+BFCJ KN8ahvVXh9SCuhvRyE1aFmiGnZ/+LbI3gbqXWxGVk/+uwvnHRdAUFj4yKdQHthKRlHyz 2bstInMidixeEPWR5t75SN6zE8BcaOOuOZ53ktnHTSoRGlKk1YzBxol8rgtIUiUoXqhg m9dHG8FW2ukHsiwn8/XmLMSGLo7S7HoscJxEGqp0NWOETCL2cRbsIpOoOzWg4g8NYfqS RULA== X-Gm-Message-State: AOAM531b5vFpCj+NKj7PdNqYtMWIe+fQv1z1XS8qmvzU7tO2whmkj4fn r+pyHek1J4inzuLsaLNQQEMNHbmObmZavQ== X-Google-Smtp-Source: ABdhPJx8OeWNF4nWi1ps1M2J6o/Hcdt8IOvmYi+XX1SS/oxMJtBOccMPfEZEYQ6h29DoyJvpQRoGiQ== X-Received: by 2002:a1c:bd55:: with SMTP id n82mr2823370wmf.3.1616591082439; Wed, 24 Mar 2021 06:04:42 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:41 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 15/23] trace-cmd: Set order and priorities when applying timestamp corrections Date: Wed, 24 Mar 2021 15:04:10 +0200 Message-Id: <20210324130418.436206-16-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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 | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 266b0b0c..696e7bd8 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,15 +1287,23 @@ static unsigned long long timestamp_correct(unsigned long long ts, static unsigned long long timestamp_calc(unsigned long long ts, struct tracecmd_input *handle) { - ts = timestamp_correct(ts, handle); + /* Guest trace file, sync with host timestamps */ + if (handle->host.sync_enable) + ts = timestamp_host_sync(ts, handle); - if (handle->ts2secs) + if (handle->ts2secs) { + /* user specified clock frequency */ ts *= handle->ts2secs; - else if (handle->tsc_calc.mult) { + } else if (handle->tsc_calc.mult) { + /* auto calculated TSC clock frequency */ ts -= handle->tsc_calc.offset; ts = mul_u64_u32_shr(ts, handle->tsc_calc.mult, handle->tsc_calc.shift); } + /* User specified time offset with --ts-offset or --date options */ + if (handle->ts_offset) + ts += handle->ts_offset; + return ts; } From patchwork Wed Mar 24 13:04:11 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: 12161111 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 9EDA4C433E8 for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7EF6761A0C for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234426AbhCXNF2 (ORCPT ); Wed, 24 Mar 2021 09:05:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234494AbhCXNEp (ORCPT ); Wed, 24 Mar 2021 09:04:45 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02B23C061763 for ; Wed, 24 Mar 2021 06:04:45 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id t5-20020a1c77050000b029010e62cea9deso1167209wmi.0 for ; Wed, 24 Mar 2021 06:04:44 -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=U72XNlXWEBux9XBC/JbsI6dAOYW3hOLN+0Rgtgi1614=; b=AoRouU2XtI0nObD6PGRMvKfJU7lQctMelDkLVI+2nxOzKvpvUJPiWyt8BQ4G7NyzFQ YiifiPZXSzOBmmbDwgM65J8jnMxqWlc501VqOth6EYZuQz/zY9qO/iPaAydWbN0r5zr5 9F7Gor/cFEkgyG2hhvAaf40EB2w9+xgXtNKJTo8TWzo9WWxWgXCI3z0p/7genp5AWUvw 1RMZXN94KsPmydbgcihsF/7q8BNWB8nX00PUE1z6+JDu1a0yopKjtOyaqGkjTxKzBhYG 3T6TcfBAKwJGZHaArZn0nfNt3Q6VXlstzf5mZmpgQTn4osiQumxmBGDwRkIlMNN/fRXm jIjQ== 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=U72XNlXWEBux9XBC/JbsI6dAOYW3hOLN+0Rgtgi1614=; b=N5C34hegZHkYWqnFCMqzM3ntsvouVPEYJ4XXUB0fA/rFVaC0oZHsBwntzCPqTyclTE XtP9F3ZLr6K/DSuxozgvrhd9kbJ0jXjh+Nl19KzPRDvmrUIDI5UDNTFsMaD3QyWlnHzg qvPDAOAEkNC+PF3cbjwjaBLQj2UBk7OonzOy2xk65yoFbltTmlNguMaNAFb2w7B9fOTR H4b21554L6giGhnUCaWYl/DEfJdLnfdJDMzKaYofSNXOtZbVh5j0k4aGnFlWlJJf5lUy 6HrxIZ+fXaZRh0rnnN844R9mAxIOixrA5u8Oto/FUlbAO4gTEWo21Bi4I8/Jq4bAN0ry 7pHQ== X-Gm-Message-State: AOAM533djHHNxhDMM3ufuw0tNCb6sGIuykSPwrnYaPO3odVjh8fQqSLf OIXr64CXWdnIXDn9BaGSOjBrKUdm2B5avg== X-Google-Smtp-Source: ABdhPJwb+ahhtoTfYqiMFE4uMrEeztoTvjJZt4u6XFlx6Fbm/s+kxR53c7zKhwiGj+Q0h7lHVQrCRA== X-Received: by 2002:a1c:7e82:: with SMTP id z124mr2895016wmc.51.1616591083350; Wed, 24 Mar 2021 06:04:43 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:42 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 16/23] trace-cmd: Add a new flag to disable any timestamp corrections Date: Wed, 24 Mar 2021 15:04:11 +0200 Message-Id: <20210324130418.436206-17-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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 | 9 +++++++-- 2 files changed, 8 insertions(+), 2 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 696e7bd8..27ddd8eb 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -1287,6 +1287,10 @@ static unsigned long long timestamp_host_sync(unsigned long long ts, static unsigned long long timestamp_calc(unsigned long long ts, struct tracecmd_input *handle) { + /* 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) ts = timestamp_host_sync(ts, handle); @@ -2601,7 +2605,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 || TRACECMD_FL_RAW_TS)) break; offset = strtoll(buf, NULL, 0); /* Convert from micro to nano */ @@ -2707,7 +2712,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 Wed Mar 24 13:04:12 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: 12161113 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 CF4DCC433E9 for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AFB5361A1B for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233699AbhCXNFd (ORCPT ); Wed, 24 Mar 2021 09:05:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234499AbhCXNEq (ORCPT ); Wed, 24 Mar 2021 09:04:46 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E919C061763 for ; Wed, 24 Mar 2021 06:04:46 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id e18so24382347wrt.6 for ; Wed, 24 Mar 2021 06:04:46 -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=nokKjdGn8oLDWt+O4i6e2PcrVh0FAmGZtYgsKS/GGHI=; b=hSRdNrPWWFI3PwXjXIcPGOqLvxSNmB2OVHnWUJQqxn59wTVJh7LUnJp7uns6vw9Kct 0Kx14mRmNn9HT2ijSRYrW7dDoxL7X+ll8z0KdxOml08TTb8nsxaSMuwI2TPqpsbN0wZa joFGe8llY2KV3zWoHrcqosSVemPTsq2PuPbpuxnsoCw/AxHejGdmvskWSXmzooXRupC0 1mjxDZfdf2nZjpa4tb7+oyLBugptWC45+Mi1LidRiLnfux5NzJeW6ohwCAwkHm+jgObD arDkVF7NMWfJa3qnC3OKTVBI/bhEjUZt6CfS6x5XOLXoCaetK1Wtp2vKZLbocIfTL+Sh +KgA== 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=nokKjdGn8oLDWt+O4i6e2PcrVh0FAmGZtYgsKS/GGHI=; b=Xalehk40RQeoYGrSLkVmY98+1n7JfiySVNlrPIRNgxOHQn2vU5bQ4D1ePE4POAbRkT D9tDATZTwfGplGW2QkbQBJxhqY6SPIB4GXklwXJLS5LqP47ewTTNi2V9q0BKq0feUR2X 9v8wHkM4rq4ENNNqmmtFP2E29doA0c0NlMxKjuZIRg/Kx0YGlMF301Yh+WnmwckPgEZr hU8uKiUWRj6eLJU4deJsaCnaiLBKTcn9yfKd5mAw7293RKKTxDQVT5HkbZHou4WRmi0z WCkaJDwLL0MnxA3O+NYSCYL1BfCYnbybQD4RMjYqBZyenCLipA83fSpVQK7yvxB8xQiT 3IOQ== X-Gm-Message-State: AOAM531g0iokXtNAxoLpDwcH6jIhhu0Bit6A6AzkZHV+jBRLXtMTZZeJ GtUd5tbMcXtnxgKtDfnMRIM= X-Google-Smtp-Source: ABdhPJwsYComIB4ehC531sHwOxYwErXuaiH8dQu+YNC6+KVISUg479kkDodVE6OGMR0X/fARwdmzIA== X-Received: by 2002:adf:bc46:: with SMTP id a6mr3388836wrh.418.1616591084653; Wed, 24 Mar 2021 06:04:44 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:43 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 17/23] trace-cmd: Change "--nodate" option to affect "--date" option only Date: Wed, 24 Mar 2021 15:04:12 +0200 Message-Id: <20210324130418.436206-18-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org When displaying a trace.dat file, the option "--nodate" disables all corrections on the events timestamps. It was originally designed to suppress the "timestamp to date" translation, triggered by the "--date" record option. When more timestamp corrections have been implemented, the same option "--nodate" was used for all of them. Now there is a new flag RAW_TS and new option "--raw-ts", that is used to show raw event timestamps, without any correction. The "--nodate" is changed to suppress the "--date" option only, and the new "--raw-ts" affects all timestamps corrections. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 27ddd8eb..9b4f8cca 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -2618,7 +2618,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; @@ -2633,7 +2633,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); From patchwork Wed Mar 24 13:04:13 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: 12161125 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 B4946C433EA for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 95B6861A1D for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234474AbhCXNFd (ORCPT ); Wed, 24 Mar 2021 09:05:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234500AbhCXNEr (ORCPT ); Wed, 24 Mar 2021 09:04:47 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFA0EC061763 for ; Wed, 24 Mar 2021 06:04:46 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id v11so24357867wro.7 for ; Wed, 24 Mar 2021 06:04:46 -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=JV7AAIqGr1HS87/CTo6xLRmr6EAxMQRsqqk5ekMFjWs=; b=fIBZ+gsa0LWtFR1mzkPfq54wBOehzwwg8/OBepxPeXD5GXQjscA2RMpRrefSLEKTcd vXp6I4i5p5fzpCjE1pVB9CDjm6e0ptXcg6YCmpKxvyAI7AqX8/wm3wZuPxqqIgwxpT1M EkRMDqOCcLA422d8Kcbcu/F8Tsi+64sD37v1v+xqMDk7iwfkq1OmR+X3UMl3BexqsZzf 7dooEsb5biHvyM6/F+ph2BqBpzJgnM1G0leiAlANd62xV5r6jda883tcAIDU2Av+a+vx WZgTSHOpC4c6tG26dbYfBf3t0H11TEOOkM6rteF4O7W8gQFfDZysNHM4m9eW/DlWn2BB dHpA== 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=JV7AAIqGr1HS87/CTo6xLRmr6EAxMQRsqqk5ekMFjWs=; b=JuT6yn1GdgbSqVa5zgxYK6iItLmcLYshiOOF0kuLAjgNTUswsfb/PQN9MYYep6AQb+ uvQqpGnmdQuiyfrOv5NSQW1dZrnUbiVDBNLikw6ie/UTE3igNEyO/vmrjLJYo4OZR/v7 6oiimQJabC/uupGXxlNeOuu47Hqzcat2lMMS2L1eeRqB7YWrfjxSTW51e8GsUQUaxymC iPjwWK+SMm0GXNCaN9J6hNIX3RP1Yf5YD/thaapS63DDYFDF4iBXVA6CNLo+Ep6ffebA 2knZ4yfFLuKRUZQKr6Ro5okDvNymVxP90+GcfHgaa7lIcXcAGvO4VsPDLFKa0C6cyDmA LTmQ== X-Gm-Message-State: AOAM530qY+Z/MtUrId68LjGKf2W2ntV6kOiuAe1XaqxvL6Oy6Qkc4ZkN 92FbwZUeoSlb141hbk6+eOK3WalRpuoXZA== X-Google-Smtp-Source: ABdhPJwPqMIcybxaLhZQWmrnN2G4r21M4C83cZM/CHqU/HnCrZCRCEmz6BDhV1d6cSMyLtzzcAZuIQ== X-Received: by 2002:adf:c587:: with SMTP id m7mr3331250wrg.369.1616591085713; Wed, 24 Mar 2021 06:04:45 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:45 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 18/23] trace-cmd: Add new parameter "--raw-ts" to "trace-cmd report" command Date: Wed, 24 Mar 2021 15:04:13 +0200 Message-Id: <20210324130418.436206-19-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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 9b4f8cca..0f5ed684 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -2932,6 +2932,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 Wed Mar 24 13:04:14 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: 12161119 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 855B9C433F2 for ; Wed, 24 Mar 2021 13:05:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 403C161992 for ; Wed, 24 Mar 2021 13:05:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234485AbhCXNFd (ORCPT ); Wed, 24 Mar 2021 09:05:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234513AbhCXNEt (ORCPT ); Wed, 24 Mar 2021 09:04:49 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 903D7C061763 for ; Wed, 24 Mar 2021 06:04:48 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id g20so12861153wmk.3 for ; Wed, 24 Mar 2021 06:04:48 -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=bc6ZTBPKEplfNLPmuSlmIx3WFs+yru7dg+7w/QzOlSNU/QvjkH9BfGvexeuuhRMv8k WHCyRJpoKJmNL7e6meFaADVfLzIfudGlk8zgBOCPMIWome8BiCvU0DwZ51hdYbI0cO9x A1iZwDXLwyzOWsLck3p8yLTYlAdT+JCX+NNRY/RZEfhuO70u4v+1WupCaN2+jxTVCQdd kfYEd26wFoQz4gF/hYBZmzYw0Xj/hbiQ4CrkN4yD4i3y2f8kE3/QY/TiUE4uwP0tYVOS k8a65IQMljQjtCGLVopprmOKzCqJ9/mQ+TNhQ2ADSBDL+xCjuhrDrpCKHgQGbF4WQIrZ MmsA== 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=IElAF0hB+qFg0NZNMQ8Y/M9z7lD2iNFCLYWXPgeAhXdVTnOw57XXndyLpupdagvEKb izPnjBX80xnwQDH2OWrL4KUkeflwTCJokPkB8EKvs/6RgqViJt1ASvOQviNgADSCEVnf dGNcHC998BfiSxj/piKnhJA523QwZPizsaTwhXSc2RKFRj5/x0P3AM1UyT9BH3ati4d3 NCNHZ0rFVaYFJWfO/aE1BPlfSWKDu31PZL7R+DwoS9I/5sQOPjWhP6xunDPe+ByvmmfE LleLSQVAYHUgpdcXESbIg4a38eOceO2C4hLmf/QFzqz291NVNnjHQiNPHRTfJ6LaTE3y r5Uw== X-Gm-Message-State: AOAM530KqJjkSqyXPykn4V2pBqMqvRFg5JVlAkYMJ9yrVaqwAzWMSde5 6LnEqzoRJ5VLxLzYfhGxkLmYq/o6gt1G1g== X-Google-Smtp-Source: ABdhPJzq4hKNC0lTYKOaR6G/qeYjcNLAzmkmNnUP7GinaPMQYkBWzJNhGqJEt1KWfaU1Kp3Y8+S0mA== X-Received: by 2002:a1c:f614:: with SMTP id w20mr2814735wmc.70.1616591086763; Wed, 24 Mar 2021 06:04:46 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:46 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 19/23] trace-cmd: Print times in TimeShift options as unsigned in trace-cmd dump Date: Wed, 24 Mar 2021 15:04:14 +0200 Message-Id: <20210324130418.436206-20-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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 Wed Mar 24 13:04:15 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: 12161127 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 433B1C433ED for ; Wed, 24 Mar 2021 13:05:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 26AED61A0F for ; Wed, 24 Mar 2021 13:05:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234494AbhCXNFe (ORCPT ); Wed, 24 Mar 2021 09:05:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234574AbhCXNEt (ORCPT ); Wed, 24 Mar 2021 09:04:49 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09305C0613DE for ; Wed, 24 Mar 2021 06:04:49 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id x13so24359353wrs.9 for ; Wed, 24 Mar 2021 06:04:48 -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=0TgkhQR/si8LpboHmBV6OZDJCOZs/LOloLhndbHX8HA=; b=nWvOaSKP+GBpb7b7BShZknJaH59yDCPQ9fpQA5KOktyUROcc1Za4Dx6gtHCZ9eRESd fygp4/aimYtV7n4rysEKFyamfdheL69YhrkKmFtJU4x9UzuUkSFOTP8eZpa7FNz+7m51 0/arBhwgznKfNxg9/CysmVuvE9bKrqdNNSzoiDFuelV2C97tCenV9VTxOyp6SZAHv+Ni ORH28gABjxZCs1MsgOy9chAKrQu2HcGgZ0lZKuvYPuUA4WZwXk5XNKpJS/qbKDLojNHx hzKx/p/jPJyK05Eh7JGLYJzaV4h3qhT5T8MsAea69d5DSvN8upWCX8BFMR5BbLoYkADD 6XdA== 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=0TgkhQR/si8LpboHmBV6OZDJCOZs/LOloLhndbHX8HA=; b=s+woAg8qhKVdStOeMpaq683WkzTi1Mw7PoT0061+ISJ94R4Ww/V7y4zrbGyezbPei+ xCGGvUmfUIPudcs+7P8zbRmFiLGSNkjmfcRnjiA/85El28+izEqehazuYmtEfd+Nb0Yi wFEeBaBOk2E7M1BBF7OMlgAB6RrU2vhguqHezDMDWqrIa4P1LHAoaqyhLtDVtXZQV9Ap XavKNDCcCRiIELMKxV9okknfUQo0um5RO1XL1qmkMlMgiMGl5aThrlOlfrns0QGbrpIh FTTWLyUnFUOQkP20nnSCTckhA3g2Hvmj5dwPa1lXv5vLMnJZ5y9b+vjKdgvp00MKV/Wc N06Q== X-Gm-Message-State: AOAM533YjIsHTD/PppRf6vsX/l3Bso8zh84G7TKEQdEKKx2jeBNeLpki B5/okV64fpAW53JD/2jkS7E= X-Google-Smtp-Source: ABdhPJwNRribhoTDvRWt9TTmYt28IQhrmImQrkycBxxzbiP1txNXP3doBdUocDk746sbclCZYJFrXg== X-Received: by 2002:a5d:6c6a:: with SMTP id r10mr3466266wrz.42.1616591087717; Wed, 24 Mar 2021 06:04:47 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:47 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 20/23] trace-cmd: Use tsc clock for host-guest tracing, if available Date: Wed, 24 Mar 2021 15:04:15 +0200 Message-Id: <20210324130418.436206-21-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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 00fd4a1d..f90fdbe4 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) @@ -5811,7 +5816,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; @@ -5946,6 +5950,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': @@ -5998,11 +6003,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; @@ -6246,8 +6253,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)) @@ -6281,26 +6287,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, @@ -6467,6 +6453,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. @@ -6496,6 +6532,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 Wed Mar 24 13:04:16 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: 12161115 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 1161CC433EB for ; Wed, 24 Mar 2021 13:05:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4AF261A11 for ; Wed, 24 Mar 2021 13:05:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234500AbhCXNFe (ORCPT ); Wed, 24 Mar 2021 09:05:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234586AbhCXNEv (ORCPT ); Wed, 24 Mar 2021 09:04:51 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B896C061763 for ; Wed, 24 Mar 2021 06:04:50 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id c8so11467213wrq.11 for ; Wed, 24 Mar 2021 06:04: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=yzsSYk49mVd/1rqHdSfH2WsUIqsYGxDwkah8P2Avg9c=; b=cq58uxhbu2U8dP/4k8uQXJ5ZWrYRObEWCqIvQqzebMpp5uvXz+9HpjVibxk8qZD2JZ UlrFdHsTURdN4OzpD3uHkqULcZVQUEyOQ69Vcc8AagoUq9kNRYX2driMW7m6Yjvk5QvL zn2VsWm5QCWRM65EUr0AMhkHxtVt0IaY7d0Rr9KvhYFnV3olaBh3SBjZ8gHTPP1MVxxF eJM5uZm+kcjz207FckeS7qUGsd9nCi1HmTJ/K2XWNkSzOsbSe7KhSHD6+EA6cibk94Pk ZDbCjtZea1mIx502Q4eqDEmfuUsclXFtAcEaw6TWFcYxuEEoU0777UpskpMXv+TU6TNX 4HDg== 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=yzsSYk49mVd/1rqHdSfH2WsUIqsYGxDwkah8P2Avg9c=; b=XJpncsmy5hSpTVpMJKiI9A0FdAqbqTGbFaUvXUOYB1ZjIf+Lfso/kgvLoHbWBW3wkv FdR+2WZWf96IZCh7gnE4mDAYDgTgY+4tm9DfhZF2Jo6BZKgeWSQE7iqnV8RP5xmo6wMb WxOIQIAE/OePG+Nx0UZfLOl+1lgX50Uycv32+tGHaj51fbmQwHbnllKse+GBzUmSQMgQ w1Bki64SqTYTOVU0Cqvdak+1v+kUbCEhyUYFTJek8rawsxmvknKkgZSUJQ2A1i3ievWK jsNM+V/RcEFgl4ESmnucuTLkvSQmeYq5vUTXz8r3xs1Whz3jdGWtmvAI2wB8hC7GycFs adLA== X-Gm-Message-State: AOAM532ZqKGTqNtoQC3RtP6UY1Hndr7eK2wAQNioLgBVVG1jW96vGwM5 M+q7Aj04Bd5B82Td4L/9FJA= X-Google-Smtp-Source: ABdhPJzBiEp9f7NWElYpiRFfO44YBBEEIti9ynFy6cWgZJXJW64C/boPSNlMQCGpmzTwIgz8bmLLdw== X-Received: by 2002:adf:e38f:: with SMTP id e15mr3256483wrm.321.1616591089426; Wed, 24 Mar 2021 06:04:49 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:48 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 21/23] trace-cmd: Get current clock for host-guest tracing session Date: Wed, 24 Mar 2021 15:04:16 +0200 Message-Id: <20210324130418.436206-22-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-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 f90fdbe4..2fc6723a 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -6455,11 +6455,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 && @@ -6468,18 +6469,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 */ @@ -6501,6 +6519,8 @@ static void set_tsync_params(struct common_record_context *ctx) } instance->tsync_loop_interval = ctx->tsync_loop_interval; } +out: + free(clock); } /* From patchwork Wed Mar 24 13:04:17 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: 12161121 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 2A648C433F1 for ; Wed, 24 Mar 2021 13:05:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0FBD861A19 for ; Wed, 24 Mar 2021 13:05:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234499AbhCXNFe (ORCPT ); Wed, 24 Mar 2021 09:05:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234591AbhCXNEw (ORCPT ); Wed, 24 Mar 2021 09:04:52 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7A37C0613DE for ; Wed, 24 Mar 2021 06:04:51 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id d191so12850912wmd.2 for ; Wed, 24 Mar 2021 06:04: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=msOfs+6fUUPf4h8RyhdwB8/EjZwtgK5XFO+5ApYFmuY=; b=rtxCMiI8IG1dfZCSKfma1bcwEAMzNxI64w00UtBU58Lh1eeOZFhRDPFyTgPkcyibW6 lkR9W4Su1P4N1v8VOxOKtHzeaW2SLXvp7THIWyNINIKE9dQnnxms7r8sO/msnxzAU+Io G1c3MFJRy0izk6Hkyx/QfEwARq1Aw9A25MPeOUcSQANf8YqCzd6DeKMmU1vkii30Cq/X PPm79i/lhsRFak8FKzBpA8amWFS83u7z+DvX1jAOuyyIOnYU3Gw3eDiBgoUYNOdRO2GL U6HKwRWicae15pzYB3W0E/OEAkcTCzsxAwVHFx08SwMpro4yckxnovM1X0+SIwXJu3zD Th9A== 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=msOfs+6fUUPf4h8RyhdwB8/EjZwtgK5XFO+5ApYFmuY=; b=YKBVPWEpbRk/HRkqTiqGOv3c00Vbb7NYJ8VaO8uV5yd/N9X3eQkVanxFD30aPDXOi9 ifL/OR1nqLsm4SVgdz5Fhcmeslwwe71wed+EAIlQiCaIK9d8s0LN5GiRtP7bWmZcc6SY ZIoWRoFZ4PE00Lm+HIdlRVOluaz84s583zArcFLO3YIZaLYGbhlgXGOG4E7G1lKrq/wC 3um8RNN0oL9HmIpjPxclsh7kysXFKKIgs12z+s6M4gRWv7C3rCRqVqC8ynl1YIwUzu2O lNIh3Ml40JzWIX+F/0R4SEcuQIro8KWxDhB1w5INVHHxSrUcbm3pD0YiiJxuJGspn42N SJrg== X-Gm-Message-State: AOAM531tlcZbBvA66R3XGj39iXvIyKLnuXJG1MPK2ir1wWIpiEWMJ7Sq qOJoOneZ8B3omCrpLGKW6RXTL19AxSLRLQ== X-Google-Smtp-Source: ABdhPJxlk0pNc6IOZRcAYaJmFpFGuN5yPemR3J0Z5iQw6FH/j/5HJx/c9caSLtJq5KlX0rfLGh1Zug== X-Received: by 2002:a05:600c:289:: with SMTP id 9mr2887636wmk.135.1616591090506; Wed, 24 Mar 2021 06:04:50 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:49 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 22/23] trace-cmd: Save the trace clocks in TRACECLOCK option Date: Wed, 24 Mar 2021 15:04:17 +0200 Message-Id: <20210324130418.436206-23-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Save the content of the trace_clock file in the TRACECLOCK option in the trace.dat file. The clocks can be printed with "trace-cmd dump --options" command. These clocks were saved right before the tracing data in the file, but this patch set changed that logic. Now only the selected clock is saved in the file before the tracing data. Having all supported trace clocks in the file is useful for debug purposes. Adding clocks in the existing TRACECLOCK option is save and will not break the older versions of trace-cmd. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-record.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 2fc6723a..f4c27ef1 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -4138,6 +4138,7 @@ enum { static void add_options(struct tracecmd_output *handle, struct common_record_context *ctx) { int type = 0; + char *clocks; if (ctx->date2ts) { if (ctx->data_flags & DATA_FL_DATE) @@ -4149,12 +4150,15 @@ static void add_options(struct tracecmd_output *handle, struct common_record_con if (type) tracecmd_add_option(handle, type, strlen(ctx->date2ts)+1, ctx->date2ts); - tracecmd_add_option(handle, TRACECMD_OPTION_TRACECLOCK, 0, NULL); + clocks = tracefs_instance_file_read(NULL, "trace_clock", NULL); + tracecmd_add_option(handle, TRACECMD_OPTION_TRACECLOCK, + clocks ? strlen(clocks)+1 : 0, clocks); add_option_hooks(handle); add_uname(handle); add_version(handle); if (!no_top_instance()) add_trace_id(handle, &top_instance); + free(clocks); } static void write_guest_file(struct buffer_instance *instance) From patchwork Wed Mar 24 13:04:18 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: 12161123 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 A116DC433F7 for ; Wed, 24 Mar 2021 13:05:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64BDB61A0D for ; Wed, 24 Mar 2021 13:05:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234513AbhCXNFe (ORCPT ); Wed, 24 Mar 2021 09:05:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234506AbhCXNEy (ORCPT ); Wed, 24 Mar 2021 09:04:54 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCAAFC061763 for ; Wed, 24 Mar 2021 06:04:53 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id b2-20020a7bc2420000b029010be1081172so1146750wmj.1 for ; Wed, 24 Mar 2021 06:04: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=W3unDQUXPtkGXHvMUpsn8lod8Lwq/jv3Y3fL2UtAX0g=; b=AxUGtiXynHBxmqnzE61cZGoVD+9KyYUzwqplXB1Syb9cUtiE1SZOL7vPruUSVXFja2 MEkCQj9x8HYFHV3PeVzucGAE9s4nQHUHFQHlTQQm648BxxEqSE6b3Ih+64uXBvSAhEiH rZ6R/vUC3hCUCKDBp0IU1/El7pW8c1xKbnRkYPvKWgvof0TR6+ESIUe8yv4W0FDaYnPM DypEdssTGqQrPbVgKeIx8qU6CcDGFmjEO1z54TCoaQMOYyG0joEtmQR6n6/g9NK/GQqT J6QdQSk3W4u48hzALHCRfNuK9NY1SowKF3M2tG4rPsi9inO5u5zcoPTm5nojZe7HMBkv EMqg== 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=W3unDQUXPtkGXHvMUpsn8lod8Lwq/jv3Y3fL2UtAX0g=; b=bxygqqXDqvx9n81NCCu0YsehP+rgBnYRnoZ2okCGkzXiD8h7OhvSpD+WIs/ziLJ6w/ LZ71YUNKqy/cZljjBdx2HAzgRTLriJ/da1bAi5aWZ5QBdnkQ59DCI1o0CprqdUJXK9HV 2SaWso31EVoJrh05/40l09sFB/DfjM28KxDn0w2JpEHLUE8S8XKpmeLqgaNaiEuDTsCR tJmkKbwHrGOa8PEo28gEQatM07JlcaL9wzx8rNw0DrlNA9Y3329ztgiQanFvRL9xs4e3 MXrWkKs3WVn+MKnGvrSUelNAmjLLIW8FaIc0/EdnW2UrfgJmrviiHJjWB3zZUmHp4S/B sc/g== X-Gm-Message-State: AOAM533+689+Tg9YIulDsOd2vTw3zfmucogKgZWK+g03V3M6eW3K/x0r dAzC3pAj+kGbv8w/tGVsdtcno7QVInkWqg== X-Google-Smtp-Source: ABdhPJyk6WxlBUWJ2s32BvPxkE+nQLUjwLfpSHie3WOZGxnolvAxY4qA08c2/JybKtPmxia3rCY48g== X-Received: by 2002:a05:600c:224e:: with SMTP id a14mr2838942wmm.57.1616591092389; Wed, 24 Mar 2021 06:04:52 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w11sm3034919wrv.88.2021.03.24.06.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 06:04:50 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 23/23] trace-cmd: Read at least 8 bytes trace-id option Date: Wed, 24 Mar 2021 15:04:18 +0200 Message-Id: <20210324130418.436206-24-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324130418.436206-1-tz.stoyanov@gmail.com> References: <20210324130418.436206-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org When reading the trace-id option from trace.dat file, check if the size is at least 8 bytes. If the size is greater, use the first 8 bytes only and ignore the rest. That way we can safely extend this option in the future, without breaking the legacy logic. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 0f5ed684..5ec12ed9 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -2703,7 +2703,7 @@ static int handle_options(struct tracecmd_input *handle) trace_pid_map_load(handle, buf); break; case TRACECMD_OPTION_TRACEID: - if (size != 8) + if (size < 8) break; handle->trace_id = tep_read_number(handle->pevent, buf, 8);