From patchwork Mon Mar 15 06:18:21 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: 12138417 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 D0632C43333 for ; Mon, 15 Mar 2021 06:19:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ACCF964E64 for ; Mon, 15 Mar 2021 06:19:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229807AbhCOGS6 (ORCPT ); Mon, 15 Mar 2021 02:18:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229828AbhCOGSi (ORCPT ); Mon, 15 Mar 2021 02:18:38 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BCB1C061574 for ; Sun, 14 Mar 2021 23:18:38 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id e19so64291814ejt.3 for ; Sun, 14 Mar 2021 23:18:38 -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=jitJb1ehxF5eagaw5HDd3rowc0DPUw+8KZGkRm3aCAs=; b=ko+HN6zs+GsFxkVtJjtkqLvOJvF2Hr7kkzVuDTNSAYxweTzRYCPx2IYytWVBdw9QPz ZcMYWOvZxx/H6BfRhvlY9bB0RgtPbN0x4vSooa97PTiG5MdcSS6Ok8CAcZt9nSDkmQvv wMY6KhMjUsQDimmUHnrzW+1YT9yjg9rF5/ZoH29XCYaTpjXzK037c0hSbRCo11Qornic UXbJs45LbAfk4Oc7uYHO8baOC/LXHZmIfx+v/u37cjZwn34zXnRK6SfV0C36O0wu6Kqt U9qsh3nWIOeX6bkQPRf116FbNsC65DV+yLRltTyZ3nAO5ntTa88HKo4vC++CkwFTgwud 47KQ== 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=jitJb1ehxF5eagaw5HDd3rowc0DPUw+8KZGkRm3aCAs=; b=CYgDS9UYFI1/OzuD1TOwlB+Eo2fDbtzYFcRPWNp0PjQb71B/0vgBvm+EWmQVeewaHW s+u7XavqbtzruRYjwTlQHayewRQwCKHoDMmcVx1z4+PXrA6M7mQl53wNfw3PSoLN/AWj ldDFSUNnst0TnclCFZ5uuW0GuxbQiOA/NLaDoXQWIGXFnPZq5t6VjlGdXIcdpdN2fMd9 bz4nwNzGK1IsmA41dwP9QMD/VhtwumUZhslhfjQzHflXPQAghLThx3DyU3zEQfiwEnBd zw9yzn5QQYsrBxwcC6zzodQzbfvGXM5icFhzADq7QbHhPkF1MrVYaZow1PEHMsPuziub JK+g== X-Gm-Message-State: AOAM531Ai8GOSMUbWt23b6ZyPo7x5h165E0LmwPta7zWuvqxSfv8JjtY dpqQHAGkP7goJrriNcPAXJQ24C2OrzE16A== X-Google-Smtp-Source: ABdhPJxEZpMkzuG2GprB38+w4OY28jR+auOdmLDIxcQ3I1ZREHjjg5J9+6EjBts1OjgdMR+b0P7E7Q== X-Received: by 2002:a17:906:ca02:: with SMTP id jt2mr21744731ejb.312.1615789116898; Sun, 14 Mar 2021 23:18:36 -0700 (PDT) Received: from localhost.localdomain ([130.185.229.134]) by smtp.gmail.com with ESMTPSA id t6sm7468478edq.48.2021.03.14.23.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 23:18:36 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 01/12] trace-cmd: Add initial perf interface in trace-cmd library Date: Mon, 15 Mar 2021 08:18:21 +0200 Message-Id: <20210315061832.168495-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210315061832.168495-1-tz.stoyanov@gmail.com> References: <20210315061832.168495-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) --- lib/trace-cmd/Makefile | 1 + .../include/private/trace-cmd-private.h | 14 +++ lib/trace-cmd/trace-perf.c | 105 ++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 lib/trace-cmd/trace-perf.c diff --git a/lib/trace-cmd/Makefile b/lib/trace-cmd/Makefile index 2f553ed5..03d1a30c 100644 --- a/lib/trace-cmd/Makefile +++ b/lib/trace-cmd/Makefile @@ -17,6 +17,7 @@ OBJS += trace-util.o OBJS += trace-filter-hash.o OBJS += trace-msg.o OBJS += trace-plugin.o +OBJS += trace-perf.o 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 37c9a82a..27a96c12 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -8,6 +8,7 @@ #include /* for iovec */ #include +#include /* for perf types */ #include "traceevent/event-parse.h" #include "trace-cmd/trace-cmd.h" @@ -513,4 +514,17 @@ void *tracecmd_record_page(struct tracecmd_input *handle, void *tracecmd_record_offset(struct tracecmd_input *handle, struct tep_record *record); +/* 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 /* _TRACE_CMD_PRIVATE_H */ diff --git a/lib/trace-cmd/trace-perf.c b/lib/trace-cmd/trace-perf.c new file mode 100644 index 00000000..f3ee692d --- /dev/null +++ b/lib/trace-cmd/trace-perf.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: LGPL-2.1 +/* + * Copyright (C) 2021, VMware, Tzvetomir Stoyanov + * + */ +#include +#include +#include + +#include "trace-cmd-private.h" + +static void default_perf_init_pe(struct perf_event_attr *pe) +{ + pe->type = PERF_TYPE_SOFTWARE; + pe->sample_type = PERF_SAMPLE_CPU; + pe->size = sizeof(struct perf_event_attr); + pe->config = PERF_COUNT_HW_CPU_CYCLES; + pe->disabled = 1; + pe->exclude_kernel = 1; + pe->freq = 1; + pe->sample_freq = 1000; + pe->inherit = 1; + pe->mmap = 1; + pe->comm = 1; + pe->task = 1; + pe->precise_ip = 1; + pe->sample_id_all = 1; + pe->read_format = PERF_FORMAT_ID | + PERF_FORMAT_TOTAL_TIME_ENABLED | + PERF_FORMAT_TOTAL_TIME_RUNNING; +} + +/** + * trace_perf_init - Initialize perf context + * + * @perf: structure, representing perf context, that will be initialized. + * @pages: Number of perf memory mapped pages. + * @cpu: CPU number, associated with this perf context. + * @pid: PID, associated with this perf context. + * + * The perf context in initialized with default values. The caller can set + * custom perf parameters in perf->pe, before calling trace_perf_open() API. + * + * Returns 0 on success, or -1 in case of an error. + * + */ +int trace_perf_init(struct trace_perf *perf, int pages, int cpu, int pid) +{ + if (!perf) + return -1; + + memset(perf, 0, sizeof(struct trace_perf)); + default_perf_init_pe(&perf->pe); + perf->cpu = cpu; + perf->pages = pages; + perf->pid = pid; + perf->fd = -1; + + return 0; +} + +/** + * trace_perf_close - Close perf session + * + * @perf: structure, representing context of a running perf session, opened + * with trace_perf_open() + * + */ +void trace_perf_close(struct trace_perf *perf) +{ + if (perf->fd >= 0) + close(perf->fd); + perf->fd = -1; + if (perf->mmap) + munmap(perf->mmap, (perf->pages + 1) * getpagesize()); + perf->mmap = NULL; +} + +/** + * trace_perf_open - Open perf session + * + * @perf: structure, representing perf context that will be opened. It must be + * initialized with trace_perf_init(). + * + * Returns 0 on success, or -1 in case of an error. In case of success, the + * session must be closed with trace_perf_close() + */ +int trace_perf_open(struct trace_perf *perf) +{ + perf->fd = syscall(__NR_perf_event_open, &perf->pe, perf->pid, perf->cpu, -1, 0); + if (perf->fd < 0) + return -1; + fcntl(perf->fd, F_SETFL, O_NONBLOCK); + + perf->mmap = mmap(NULL, (perf->pages + 1) * getpagesize(), + PROT_READ | PROT_WRITE, MAP_SHARED, perf->fd, 0); + if (perf->mmap == MAP_FAILED) + goto error; + + return 0; + +error: + trace_perf_close(perf); + return -1; +} From patchwork Mon Mar 15 06:18:22 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: 12138399 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 16329C433DB for ; Mon, 15 Mar 2021 06:19:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D273264E4A for ; Mon, 15 Mar 2021 06:19:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229742AbhCOGS6 (ORCPT ); Mon, 15 Mar 2021 02:18:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229877AbhCOGSj (ORCPT ); Mon, 15 Mar 2021 02:18:39 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07568C061574 for ; Sun, 14 Mar 2021 23:18:39 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id si25so8489878ejb.1 for ; Sun, 14 Mar 2021 23:18:38 -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=fdjwE63HOvlmwb4iDR+pNauZbEE7zxvJz6kg+fL8rAM=; b=gBsVxsEEPHWlyHkth5bOmt3u1ZL7b+SVmcV1fHhLv/R/D5irYAetGZfwwdfk5l5ZCZ pHE4ZRANwn94shZFszYm4HFDrG0h3ClWQ91HtEb7KvdEeefuxNkgqf6xi1VKmuvIb34h rv+HUnxpYGwQLs/OtkYgpxWCAfQ4uqXxzbq6qRdDNEx7iUiZePqNxf3PWhw9duTaTK2v IAbtgPAPh4aoHpt8fB1aw3mcZx04kG9AJbijs7bp1vZCcbRMvHiuh73mkI4UZ90DuOAG weJiBSyvw/yH96BCSWGiFPUj5/6Iup10f/p7HOSk61mb74RzRXseg60M8N/BA5ys710J Wu3Q== 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=fdjwE63HOvlmwb4iDR+pNauZbEE7zxvJz6kg+fL8rAM=; b=XKWonQf9e92bRpxMeVqH95i1JFqJxYJEHqzPQfow9oAGOby+IrxO12xL1xottVGWkX y7qbOIyocebrypKiRYm01617XwQFwbtR742DYX36ymkYaz7bXHjOCgT+Yn/4XT4mEg3w grSGZA2deDdsCt+OwvN4TTE9QOtD1HzHIdUhxZiCK21Fn2p5mEYR67hlyHMMUkEsBrvs Gzzak8Il0BGWx3GalMfxlnb7E9XjNrrcHGvx+q3ko7D/hqG5BymDAmoxvjRdAH2E+5RB rFKv6tgqayC6GepPkCT24iglxQ/QfJYJ/JM5sW5+gOeTzA2iJWdXcckAHyo0nyVEK53L nqzA== X-Gm-Message-State: AOAM531MN75vzTxvF+IuJbjvaYEIAME1NUMkF//ySEbrkV/g5WH8KOjl kv1QuSvaw7Nb29VojvkBqOI= X-Google-Smtp-Source: ABdhPJw4oY+YCSHw1NJzbDk0mBCv3oQf/3bDOPCIQmITn8k64fPWFlgoLRVcVL9msL72KhmQH19NjQ== X-Received: by 2002:a17:906:414e:: with SMTP id l14mr21011556ejk.406.1615789117827; Sun, 14 Mar 2021 23:18:37 -0700 (PDT) Received: from localhost.localdomain ([130.185.229.134]) by smtp.gmail.com with ESMTPSA id t6sm7468478edq.48.2021.03.14.23.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 23:18:37 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 02/12] trace-cmd: Add logic for TSC to nanosecond conversion Date: Mon, 15 Mar 2021 08:18:22 +0200 Message-Id: <20210315061832.168495-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210315061832.168495-1-tz.stoyanov@gmail.com> References: <20210315061832.168495-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Added new logic to get multiplier and shift for converting TSC trace clock to nanoseconds, using perf kernel interface. The new logic is used only in host - guest tracing use case, when the user did not specify any tracing clock and KVM time sync plugin is available. Then the x86-tsc clock is auto selected for the current tracing session. There is one limitation - per CPU multiplier or shift is not supported. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/include/trace-local.h | 7 ++ tracecmd/trace-record.c | 124 ++++++++++++++++++++++++++------- 2 files changed, 107 insertions(+), 24 deletions(-) diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h index 6e39d27d..8a88ab9c 100644 --- a/tracecmd/include/trace-local.h +++ b/tracecmd/include/trace-local.h @@ -199,6 +199,12 @@ struct filter_pids { int exclude; }; +struct tsc_nsec { + int mult; + int shift; + int offset; +}; + struct buffer_instance { struct buffer_instance *next; char *name; @@ -234,6 +240,7 @@ struct buffer_instance { int get_procmap; const char *clock; + struct tsc_nsec tsc2nsec; unsigned int *client_ports; struct trace_seq *s_save; diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index a0eb0385..117e4f17 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -57,6 +57,7 @@ #define MAX_LATENCY "tracing_max_latency" #define STAMP "stamp" #define FUNC_STACK_TRACE "func_stack_trace" +#define TSC_CLOCK "x86-tsc" enum trace_type { TRACE_TYPE_RECORD = 1, @@ -4104,6 +4105,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) @@ -5676,6 +5678,100 @@ check_instance_die(struct buffer_instance *instance, char *param) tracefs_instance_get_name(instance->tracefs), param); } +static int get_tsc_nsec(int *shift, int *mult, int *offset) +{ + int cpus = tracecmd_count_cpus(); + int cpu_shift, cpu_mult, cpu_offset; + struct trace_perf perf; + int ret; + int i; + + ret = trace_perf_init(&perf, 1, 0, getpid()); + if (!ret) + ret = trace_perf_open(&perf); + if (ret) + return ret; + cpu_shift = perf.mmap->time_shift; + cpu_mult = perf.mmap->time_mult; + /* ToDo set the offset, should we use perf.mmap->time_offset ? */ + cpu_offset = 0; + for (i = 1; i < cpus; i++) { + trace_perf_close(&perf); + ret = trace_perf_init(&perf, 1, i, getpid()); + if (!ret) + ret = trace_perf_open(&perf); + if (ret) + 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; + + *shift = cpu_shift; + *mult = cpu_mult; + *offset = cpu_offset; + + return 0; +} + +static void set_vsync_clock(void) +{ + const char *clock = top_instance.clock; + struct buffer_instance *instance; + bool tsc2nsec = false; + int shift, mult, offset; + + /* + * If no clock is specified for the top trace instance AND + * KVM time sync protocol is available AND + * 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") && + !get_tsc_nsec(&shift, &mult, &offset) && mult) { + top_instance.clock = strdup(TSC_CLOCK); + if (!top_instance.clock) + die("Could not allocate top instance clock"); + clock = top_instance.clock; + top_instance.tsc2nsec.mult = mult; + top_instance.tsc2nsec.shift = shift; + top_instance.tsc2nsec.offset = offset; + tsc2nsec = true; + } + + if (!clock && !top_instance.tsync_loop_interval) + return; + for_all_instances(instance) { + if (clock) { + /* use the same clock in all tracing peers */ + 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"); + } + if (tsc2nsec) { + instance->tsc2nsec.mult = mult; + instance->tsc2nsec.shift = shift; + instance->tsc2nsec.offset = offset; + } + } + } + instance->tsync_loop_interval = top_instance.tsync_loop_interval; + } +} + static void parse_record_options(int argc, char **argv, enum trace_cmd curr_cmd, @@ -5691,7 +5787,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; @@ -5825,6 +5920,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': @@ -5872,8 +5968,6 @@ static void parse_record_options(int argc, check_instance_die(ctx->instance, "-C"); ctx->instance->clock = optarg; ctx->instance->flags |= BUFFER_FL_HAS_CLOCK; - if (is_top_instance(ctx->instance)) - guest_sync_set = true; break; case 'v': negative = 1; @@ -6118,7 +6212,6 @@ static void parse_record_options(int argc, case OPT_tsyncinterval: cmd_check_die(ctx, CMD_set, *(argv+1), "--tsync-interval"); top_instance.tsync_loop_interval = atoi(optarg); - guest_sync_set = true; break; case OPT_fork: if (!IS_START(ctx)) @@ -6145,26 +6238,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, @@ -6301,6 +6374,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_vsync_clock(); + make_instances(); /* Save the state of tracing_on before starting */ From patchwork Mon Mar 15 06:18:23 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: 12138421 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 C1FF5C43331 for ; Mon, 15 Mar 2021 06:19:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B54F64E4A for ; Mon, 15 Mar 2021 06:19:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229828AbhCOGS7 (ORCPT ); Mon, 15 Mar 2021 02:18:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbhCOGSk (ORCPT ); Mon, 15 Mar 2021 02:18:40 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05ED9C061574 for ; Sun, 14 Mar 2021 23:18:40 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id w18so15919447edc.0 for ; Sun, 14 Mar 2021 23:18: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=DUvx8Sw0GCOD8wA06mV/AFdvFVKBBzlJ2eua6c1F8UQ=; b=eeF6oBfbdI1IojJDz51HBEPs4pj/WLqt4exYtcgq5B4xlirOg4I55CNIDGDgBQYO31 ZjV/9hYVw6SQ1BAVBKmY9IciU9d5DDV+KfmUfSXt6aR744v4GW0R3wvhpSMrblYKTJpn jTRjP7hVASaqjmZ7aSIeRRQjQSTLS8O5BqRTblb8dlinmwED8l7Yq3omWPmypHe3Xshq WdqJfG0QPer622QJSdYFoUWdld8S6TMuxLSH2DGizB/6LedjISHTQ/515S5g0nV7CfZA VtH43IVf2qUTexAD5m07DQFLSTONlUwgatmOmU77THiGMOvoZNHO0kWtds44S208Si5K v8TA== 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=DUvx8Sw0GCOD8wA06mV/AFdvFVKBBzlJ2eua6c1F8UQ=; b=haiWwSXMsnyb+fscxjNpMY4hwkT3ApJK3nkwadP971x5+kBMQ0CHqw6OYWBfpPAaVr 49i/17YPZgXc+hLrYagEVMeja8Q8eLO3zva0PXodBGLlDmUb3JBRYDICJmnhzCbhy46P f2SYIj0OWTZbUIlFziXw8yyBmD16/RGCrGz1P8v0UMw12BMIzlfaC4qNU0QWkos1Kurx bo/gOvJfCpGYLVGEg6ME13ItndMbprixMD0s5xGa67i4aqkKIQ5JmtRuWWGiex1Bx7WM XL2tOrbb4Bq4qjUnbfJcvdmnmEpPo5FfgmKH2D/3gw0HZSjU72ktJwKtNmHpKTVAncje TEwA== X-Gm-Message-State: AOAM532QL9RxmCOkdK34Lg444pqVh1Q4KUVB5vEiPFyscxEZdqWu9P5p 9YiEYP2yVQoUy4UnpgAy/yYkKl28mBKA4w== X-Google-Smtp-Source: ABdhPJxuS1KniejwH+0VNW6hZ0cTKTmMCwEYB6L+9PajRSWD+EO+FG772yxUmh1Hzov7QBliEQErzw== X-Received: by 2002:a05:6402:1115:: with SMTP id u21mr28124645edv.383.1615789118825; Sun, 14 Mar 2021 23:18:38 -0700 (PDT) Received: from localhost.localdomain ([130.185.229.134]) by smtp.gmail.com with ESMTPSA id t6sm7468478edq.48.2021.03.14.23.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 23:18:38 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 03/12] trace-cmd: Append new options into guest trace file at the end of the tracing session Date: Mon, 15 Mar 2021 08:18:23 +0200 Message-Id: <20210315061832.168495-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210315061832.168495-1-tz.stoyanov@gmail.com> References: <20210315061832.168495-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 5995551e..85a57f23 100644 --- a/lib/trace-cmd/trace-timesync.c +++ b/lib/trace-cmd/trace-timesync.c @@ -840,7 +840,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 117e4f17..b064a1ff 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -681,6 +681,7 @@ static void host_tsync_complete(struct buffer_instance *instance) if (!handle) die("cannot create output handle"); tracecmd_write_guest_time_shift(handle, instance->tsync); + tracecmd_append_options(handle); tracecmd_output_close(handle); } From patchwork Mon Mar 15 06:18:24 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: 12138409 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 B1F23C4332E for ; Mon, 15 Mar 2021 06:19:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7FEDD60240 for ; Mon, 15 Mar 2021 06:19:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229877AbhCOGS7 (ORCPT ); Mon, 15 Mar 2021 02:18:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229899AbhCOGSl (ORCPT ); Mon, 15 Mar 2021 02:18:41 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 040DAC061574 for ; Sun, 14 Mar 2021 23:18:41 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id r17so64171977ejy.13 for ; Sun, 14 Mar 2021 23:18: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=BW3AIsyOrPEeGZPh0iFYitfuSlt6vel/Ntkp8lQyFpM=; b=WW00BQ+Gl+r/h38TwOzKlUR1j+Uq/NcxQMn/I2RJbmYRrOHpoLG/EpW3XaJuIlQg9r 98RSPrbvckfOaMRhj3/YKBG9W4I0S/pfySpeja3pcUTbMRBbVzuCcgAkqyPTxJIMMPfL g/hpR2uNgnACzqsInsSZBXpUkS1UVsYUFMrEj1k+cuS+WeLb/oc7HdiiWDzwsBxBAv9Z BVV5XpVEqMnNqgbMPBAghY5EcEhH27QQBpvZPQId2l//sEjVx7/VFvPFcVm7uBk7+yXM FRClohx40N/ksNy8MgKIPQXotiSVs1Rrjc16TNDy+LTCg9aSUjyaZcADGkuBxE2FDWwn wy9w== 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=BW3AIsyOrPEeGZPh0iFYitfuSlt6vel/Ntkp8lQyFpM=; b=d26wIqMCygRrUeL5oz5mTUu40Nyj+usVDOL35lVh7gpm7s+5YIZNOh99uEko6HwCS3 6X0JadmxJRxj/fQtPhUbJSA1YX93k8zPALPKcBDk5AnnEansMeiOsYxrHwgZ1CVeiKbQ R2KFNvJuLmW3S+lIZRcziuebwCwgPrlDzMrHiNlQCb6vTeUEF9+dLAK8coTO5al5veBA qPXC3zgnbhqiwbeU58YHHsDAAEo4/XXgs3v/z32SObI2Mx7v4/WPPmUcmjDVl5UC2h/V Qo7YYUXCA6IrUyweBWAWV5LlxvBPygSlrwdGA66d5A2gNIt1jA9D36Xxw+BPzbUedhXj FKww== X-Gm-Message-State: AOAM532fx8KmV85qMf7AH1A5Hva2fnKCpXn6p0vw2UlS2EPq1IhJIAnb /7ucGamRx1ZDX8hdkYbQhH4= X-Google-Smtp-Source: ABdhPJwjeGMXD2qOWPmJq8WQch2ngCY4X3xYppawZhhyvb4e2V+BuY9nlnccxWTxHKS86m5j5TaUiw== X-Received: by 2002:a17:906:2504:: with SMTP id i4mr22199782ejb.115.1615789119846; Sun, 14 Mar 2021 23:18:39 -0700 (PDT) Received: from localhost.localdomain ([130.185.229.134]) by smtp.gmail.com with ESMTPSA id t6sm7468478edq.48.2021.03.14.23.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 23:18:39 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 04/12] trace-cmd: Add a new option in trace file metadata for tsc2nsec conversion Date: Mon, 15 Mar 2021 08:18:24 +0200 Message-Id: <20210315061832.168495-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210315061832.168495-1-tz.stoyanov@gmail.com> References: <20210315061832.168495-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org A new option is added in the trace.dat file for holding the multiplier and shift, used for converting TSC trace clock to nanoseconds. Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 1 + tracecmd/trace-dump.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index 27a96c12..e2ea0dd0 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 6172231e..86524d0f 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -481,6 +481,21 @@ out: free(buf); } +void dump_option_tsc2nsec(int fd, int size) +{ + int mult, shift, 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, 4)) + die("cannot read tsc2nsec offset"); + do_print(OPTIONS, "%d %d %d [multiplier, shift, offset]\n", mult, shift, offset); +} + static void dump_options(int fd) { unsigned short option; @@ -540,6 +555,9 @@ static void dump_options(int fd) case TRACECMD_OPTION_GUEST: dump_option_guest(fd, size); break; + case TRACECMD_OPTION_TSC2NSEC: + dump_option_tsc2nsec(fd, size); + break; default: do_print(OPTIONS, " %d %d\t[Unknown option, size - skipping]\n", option, size); From patchwork Mon Mar 15 06:18:25 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: 12138407 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 80200C4332D for ; Mon, 15 Mar 2021 06:19:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6603C64E66 for ; Mon, 15 Mar 2021 06:19:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229884AbhCOGS7 (ORCPT ); Mon, 15 Mar 2021 02:18:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbhCOGSm (ORCPT ); Mon, 15 Mar 2021 02:18:42 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F030EC061574 for ; Sun, 14 Mar 2021 23:18:41 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id j3so15927328edp.11 for ; Sun, 14 Mar 2021 23:18: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=4bAXOBWqynurN7IbQYf4dThYpWPfY0J95xpkTl59hB8=; b=e94zhtHdmBg0FyULRzIf8eQYa6eomt7fsS4vM8L+R0jpvJxu4DkRut5h0EpbzDxUs2 VsDyzV8c4Rvf1VBulpNXLmr59MzrUx5G7XCRQl1AgHiPBfG2bOIw+MCDwD67CJSRyoMt xuD1HLdW5m2jdwaZOG3Qx+sljZQDmyrtLd6Qo/mTjGNtkzjgFq8V8f2uNccEJnOwZPxb lrk0dKasK1NOW/qX/Vp3M6alGj7ugVzOxSyeMgx+9xmhlYFjgnsKou8X7xneqqQt/rLj pE2XuZAkvQfYKqM3z73FGCoexmiQdMw4ocDhIEFatqJyCyM34zXvWdBHZahp7RgtW3Tj NP1w== 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=4bAXOBWqynurN7IbQYf4dThYpWPfY0J95xpkTl59hB8=; b=ri/ENYNX/+lY69pgmkb+v+ETIw0dNgJFgv5pwyPp+TDsf9apY++k4zdDhr6llA7lKJ ZDwf0XErZQX93R+RLAtCKOrw9fTkph/v1srL3F9aSGMXlgel1wBSM0Q/R42Z6WlDYQF4 8rYf6mc5kHD1R9bYl7HSk+0nyXSAdbcH5HrDo07taklvqdYSPej3l0khVfssqOiWGsrt LYIV4TPExR36zQbQV26zJbL7B7DQSCm/66wiNHy5BYsZF7n2x91VghhtkUEWNaAbfmXu obeqWjdvoOXj0MLN14kqcYXESXTphYTrBRQ11jJPz/JMvpS1AQLUX3VbmLmdfWGI1LmW gcZg== X-Gm-Message-State: AOAM533qyka2dz6Rl7I6Nhx622LoIQqP0Ot7Imoq1h+m7gsGmGkB8hHQ Pt84o9sx+mOa+PeEzbVDf1I= X-Google-Smtp-Source: ABdhPJxaD949Y3bnKqhQ5XBvuxagLmJEthxzXBxyRklXO37jXmoupvj7Cqf1nzwHB16ev588U4vfRA== X-Received: by 2002:a05:6402:17d6:: with SMTP id s22mr27815742edy.232.1615789120764; Sun, 14 Mar 2021 23:18:40 -0700 (PDT) Received: from localhost.localdomain ([130.185.229.134]) by smtp.gmail.com with ESMTPSA id t6sm7468478edq.48.2021.03.14.23.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 23:18:40 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 05/12] trace-cmd: Save information for tsc to nanoseconds conversion in trace file Date: Mon, 15 Mar 2021 08:18:25 +0200 Message-Id: <20210315061832.168495-6-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210315061832.168495-1-tz.stoyanov@gmail.com> References: <20210315061832.168495-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 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index b064a1ff..30d3ed89 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -666,6 +666,17 @@ static void delete_thread_data(void) } } +static void +add_tsc2nsec(struct tracecmd_output *handle, struct buffer_instance *instance) +{ + int array[] = { instance->tsc2nsec.mult, + instance->tsc2nsec.shift, + instance->tsc2nsec.offset}; + + tracecmd_add_option(handle, TRACECMD_OPTION_TSC2NSEC, + sizeof(array), array); +} + static void host_tsync_complete(struct buffer_instance *instance) { struct tracecmd_output *handle = NULL; @@ -680,6 +691,16 @@ static void host_tsync_complete(struct buffer_instance *instance) handle = tracecmd_get_output_handle_fd(fd); if (!handle) die("cannot create output handle"); + + /* + * If TSC is used as current trace clock and there is + * information for tsc to nanosecond conversion, store it + * in the trace file + */ + if (instance->tsc2nsec.mult && instance->clock && + !strncmp(top_instance.clock, TSC_CLOCK, strlen(TSC_CLOCK))) + add_tsc2nsec(handle, instance); + tracecmd_write_guest_time_shift(handle, instance->tsync); tracecmd_append_options(handle); tracecmd_output_close(handle); @@ -4269,6 +4290,15 @@ static void record_data(struct common_record_context *ctx) add_guest_info(handle, instance); } + /* + * If TSC is used as current trace clock and there is + * information for tsc to nanosecond conversion, store it + * in the trace file + */ + if (top_instance.tsc2nsec.mult && top_instance.clock && + !strncmp(top_instance.clock, TSC_CLOCK, strlen(TSC_CLOCK))) + add_tsc2nsec(handle, &top_instance); + if (tracecmd_write_cmdlines(handle)) die("Writing cmdlines"); From patchwork Mon Mar 15 06:18:26 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: 12138401 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 6A7DBC43381 for ; Mon, 15 Mar 2021 06:19:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4EB4D64E51 for ; Mon, 15 Mar 2021 06:19:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229899AbhCOGS7 (ORCPT ); Mon, 15 Mar 2021 02:18:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229914AbhCOGSn (ORCPT ); Mon, 15 Mar 2021 02:18:43 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED637C061574 for ; Sun, 14 Mar 2021 23:18:42 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id mj10so64193308ejb.5 for ; Sun, 14 Mar 2021 23:18: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=w6avxxa59CWKnEJJRYffo95ueCrWvVZMSAzBPlxpHUI=; b=leVek15DA1tfUVN6E0F/UPoJ+3pLD5Aq4Iss9tAZ5nTkoy9F85Fe7KlyMSpROUmquy xgMwia1QzfBR6QUjsDnGDOGU13oH6Sabwv8WM8Z3WLJ9Qw24KSP8+XFs+I3iWImj2GcZ Phf9fpRqFRXG1bQ19wXL0KnDK6Z5ceWgjRoO6n8qYQG5r9A0ywPd+jk3j3sA4a7rFxe/ G1dF+2+iuLXUXHFJM6VcTSHH+81yNkiQax0hrcakCHo0jSAJxib7i1A/kfW1YdJyBwYP MeOI2xE54oRfaYhsveRLF8cxQ/GntelR1mgz2MNVKn+GOqDCOku6pdUSOIjjocUaG6CX RUhQ== 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=w6avxxa59CWKnEJJRYffo95ueCrWvVZMSAzBPlxpHUI=; b=Mq63g3rWPjSnStxgIyyh/0bPUuZ9bZDtCko6l+YbRxadZhdVbbr6APViQG0xkATusJ zcuP31LPPwXRuqaD5GJagZ3vS++fMISflwsFp/rlnSfKvtguOumbqyRCZThwBxA43XP8 82ZHOJbol9GhkxgqjxL12Zoi7xM5Tr9b4dnmKbq2Z5mAshGG8Ya+fTL6du9dwPkEt6Kv wF7HAddghNDgsoWaRL+/4K2ncByQ6jgdsVDhw58WnjbbWl/FRVfWOvYjt6Hk7QsNTP9G 4eKJ2jrCLOmfFk0vz6pqYFVhFc6p36jFr2a5jthHKQLOgKjtelJ8TrMGsjxD9/uS6vxF 0+iA== X-Gm-Message-State: AOAM530F5rv7dyztPFIcin4SrxpsEb9wr1Mbex9c6NnRyRjBf+WKT7VN 9eDM3Jy59NmhDzfhqbd0bNo= X-Google-Smtp-Source: ABdhPJz96JAPSqqV7jI7BD9eUwQWtUcET2ZpE7q5kwC7P1G3dahoc3mE3jtrQT2nGh+2sB7bx8SQHg== X-Received: by 2002:a17:906:18aa:: with SMTP id c10mr21768763ejf.248.1615789121759; Sun, 14 Mar 2021 23:18:41 -0700 (PDT) Received: from localhost.localdomain ([130.185.229.134]) by smtp.gmail.com with ESMTPSA id t6sm7468478edq.48.2021.03.14.23.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 23:18:41 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 06/12] trace-cmd: Read information for tsc to nanoseconds conversion from trace file Date: Mon, 15 Mar 2021 08:18:26 +0200 Message-Id: <20210315061832.168495-7-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210315061832.168495-1-tz.stoyanov@gmail.com> References: <20210315061832.168495-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..1e925f45 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; + int 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 != 12) + 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, 4); + break; default: warning("unknown option %d", option); break; From patchwork Mon Mar 15 06:18:27 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: 12138423 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 36E21C43619 for ; Mon, 15 Mar 2021 06:19:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16DCF60240 for ; Mon, 15 Mar 2021 06:19:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229905AbhCOGS7 (ORCPT ); Mon, 15 Mar 2021 02:18:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229920AbhCOGSo (ORCPT ); Mon, 15 Mar 2021 02:18:44 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15C45C061574 for ; Sun, 14 Mar 2021 23:18:44 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id e19so64292063ejt.3 for ; Sun, 14 Mar 2021 23:18: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=gUyvPCagh4Vt6i8rfn0r1Yh65oM97Xk+G2v/+Ya9ufY=; b=D6oYyM+VChofY+LYwfSa1frjjW63bm/v3KgJvNnnvTYIe7yCm0zkAHl2GI+BR/daDm aME57wPx90HDu2EbrJNHpss5hy0rJoiOnwZBgscdf/cyaaRiUTIN8sly0BX5hPg05cyB nFFkAS4AI4xCbjJ9c7CueCNpYtybbS8R76yEyYJdQgY6A0t9ON9uzSLbyM0wbAYyRzPo ubwRi5/TskLuNuT7HsTP9uVP8Lfu3ThOE/IWOvJpG8Re5f3DMjcRwmqw9UaIJLh3H4qB h08IxPslvicMdPx1xN12eyHKM+SUqCXwM4ucWW2q7RECumhT/guBLer2eI9DkWqwhmdu fZ4w== 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=gUyvPCagh4Vt6i8rfn0r1Yh65oM97Xk+G2v/+Ya9ufY=; b=UaUkbTi05mgqFSnsxBh2ehKgzxVqD5ILQ7SqIsumhQOrKS6OdRql8f3IfOKrqlLZct 1cDX9fu4r9vsHK1FZ03cbVgV6Mzecdvl2NhhYAkVz6pksMl7Xqs8knfa5lrf7FirT4OU 2+NpZn3BIWjr6Mu2NO93h/Iwi9LzQaonbPOXhhS2TDb6t0v4muIG3qFJOBx+KLddDx0n SN6uviQ3xj/pESosRtbsGGV2RXWljotZDU1vlrrzir0LhR/FJCHgQjNWmRcaJ/VAA/ma 2f8P0TRS82mnJy9WRTBdMxGaFleg1brA6vjP9/kB0zmviFEp4yXUa71kvR5qxTdEwPnl Z8ug== X-Gm-Message-State: AOAM533ir/ade386lhPFXtnnom57lCm3CLfE4de3J7In/lW2UwpVdfXq QxxM7Bi3hP6lMKNjv5JQZvM= X-Google-Smtp-Source: ABdhPJwGmhC2jvmFV9ITZ29Us5WYIKEy7xYsnLkJpmLvYDx9ozNuiwdNPWet8OynPVAEtsRkarX8Qg== X-Received: by 2002:a17:906:ad4:: with SMTP id z20mr21234376ejf.496.1615789122924; Sun, 14 Mar 2021 23:18:42 -0700 (PDT) Received: from localhost.localdomain ([130.185.229.134]) by smtp.gmail.com with ESMTPSA id t6sm7468478edq.48.2021.03.14.23.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 23:18:42 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 07/12] trace-cmd: Remove unneeded multiply in events timestamp reading Date: Mon, 15 Mar 2021 08:18:27 +0200 Message-Id: <20210315061832.168495-8-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210315061832.168495-1-tz.stoyanov@gmail.com> References: <20210315061832.168495-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 1e925f45..5384ad90 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -1932,10 +1932,8 @@ read_again: handle->cpu_data[cpu].timestamp = timestamp_correct(ts, handle); - if (handle->ts2secs) { + if (handle->ts2secs) handle->cpu_data[cpu].timestamp *= handle->ts2secs; - ts *= handle->ts2secs; - } index = kbuffer_curr_offset(kbuf); From patchwork Mon Mar 15 06:18:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12138427 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 2CE58C43603 for ; Mon, 15 Mar 2021 06:19:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 03DA664E12 for ; Mon, 15 Mar 2021 06:19:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229914AbhCOGTA (ORCPT ); Mon, 15 Mar 2021 02:19:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229925AbhCOGSp (ORCPT ); Mon, 15 Mar 2021 02:18:45 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18EA6C061574 for ; Sun, 14 Mar 2021 23:18:45 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id b16so3134441eds.7 for ; Sun, 14 Mar 2021 23:18:45 -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=wNC9H0hPHXoToxr/gseEnC9/9164KvhD0GLDaTKzSog=; b=lPCSfkinGkKmKGIUWLl3duDDN0EQ6jRXhcDWaY+K870F4RA6B8lWQitXuEa1IfjzcF unR4M88SWkyVz0mCe9JoyHZ0CKdmNxx2YZet5tooc6U958oXmmJ94SugwCrTx/8bMmh1 GoGUUvw/kK15nHFj0FtPEfUDxzeL5ZKhVM2Eq/uJNb6miXzMScPJoIsxz+uHQltB5dzO KPTh/Cj4Ypi7xi2VSa3Ay0W+EUk0JJJsayM3ZB5xiLUEd0SUg5mK58jhtE/ppeKcOmP2 f7ANj3tTFhb6wzsb51gHz0PQs98eDUJv4HoIP3or/U4ENBpOwgAz3a78gsNphubSGG2a 4xCg== 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=wNC9H0hPHXoToxr/gseEnC9/9164KvhD0GLDaTKzSog=; b=bs85KmX5vVCENwSQ5JeXG9LbhJ2cAGM3iR0OgE/6kE9aIuWor44Ltp+xaLnAlC3rA6 oDY+O7QCVOa8JhzZUYBkQZdEkSD4GYRi9Aj+j7gKz5MzqGjSGCDf+ex7NTqXXREamkBY TOw7eT6Xp0chQksOUQp3RLtEYy6dDEq01W1fhNL0jWBuYutPCnYUPcbf50Iu9uxSUHB5 4XX/b/Cad9oGX8+5QRqgyewwukkpDH5OMMFl7Tx8v97SP1m+5fLSdQ6kp9MuLeLZT87b r3cqlJ89U/pLqN4SY2HKWsp9kv0woYa8//s3T8pTRVMDjwxTX/0O3YpFwlqBptc/aUsO K1ng== X-Gm-Message-State: AOAM531Vb2j+bRAmV1sQ70kaKQ/xevpaM2a8dNDp8QYIwjcK578L3Xvf eX92g95RZLmSzHSysLtrnpQ= X-Google-Smtp-Source: ABdhPJw7sy1MAt7WCkO8DPiC5TKZgbhOwzj5+YiHgJE2rGSD498PuJUs5gXEqbR3sBkA1/r0k9YplQ== X-Received: by 2002:a50:d71e:: with SMTP id t30mr27805350edi.58.1615789123922; Sun, 14 Mar 2021 23:18:43 -0700 (PDT) Received: from localhost.localdomain ([130.185.229.134]) by smtp.gmail.com with ESMTPSA id t6sm7468478edq.48.2021.03.14.23.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 23:18:43 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 08/12] trace-cmd: Perform all timestamp corrections in a single function Date: Mon, 15 Mar 2021 08:18:28 +0200 Message-Id: <20210315061832.168495-9-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210315061832.168495-1-tz.stoyanov@gmail.com> References: <20210315061832.168495-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org When reading event timestamps from a trace file, there could be various corrections depending on the metadata information from the file. Move all logic that performs timestamp calculations in a single function. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 5384ad90..65081007 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -1276,6 +1276,19 @@ static unsigned long long timestamp_correct(unsigned long long ts, &host->ts_samples[mid+1]); } +static unsigned long long timestamp_calc(unsigned long long ts, + struct tracecmd_input *handle) +{ + unsigned long long tstamp; + + tstamp = timestamp_correct(ts, handle); + + if (handle->ts2secs) + tstamp *= handle->ts2secs; + + return tstamp; +} + /* * Page is mapped, now read in the page header info. */ @@ -1297,10 +1310,8 @@ static int update_page_info(struct tracecmd_input *handle, int cpu) kbuffer_subbuffer_size(kbuf)); return -1; } - handle->cpu_data[cpu].timestamp = timestamp_correct(kbuffer_timestamp(kbuf), handle); - - if (handle->ts2secs) - handle->cpu_data[cpu].timestamp *= handle->ts2secs; + handle->cpu_data[cpu].timestamp = timestamp_calc(kbuffer_timestamp(kbuf), + handle); return 0; } @@ -1930,10 +1941,7 @@ read_again: goto read_again; } - handle->cpu_data[cpu].timestamp = timestamp_correct(ts, handle); - - if (handle->ts2secs) - handle->cpu_data[cpu].timestamp *= handle->ts2secs; + handle->cpu_data[cpu].timestamp = timestamp_calc(ts, handle); index = kbuffer_curr_offset(kbuf); From patchwork Mon Mar 15 06:18:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12138415 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 041A7C4321A for ; Mon, 15 Mar 2021 06:19:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E696560240 for ; Mon, 15 Mar 2021 06:19:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbhCOGTA (ORCPT ); Mon, 15 Mar 2021 02:19:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229594AbhCOGSq (ORCPT ); Mon, 15 Mar 2021 02:18:46 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1611FC061574 for ; Sun, 14 Mar 2021 23:18:46 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id ox4so48578691ejb.11 for ; Sun, 14 Mar 2021 23:18: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=5QrahDd61JCNCC55JMJ2nPOG9SHith/bj5jUizrYN8U=; b=ru4RV9HbpeUuVASknsC4VZIC371/tr+BIwexbCZGkrnx0JX3Xomn4dXN2iBW34D4oJ Q36aa6bH6Ykw/zY2vzq1NPGcgANhdUnjt27kkqmuLueOdc8TGFrw8frImc+5HAJNsXvY e3gUfneIqPwORi7688htvP2s9+TJbYFwd+pziQoBv8XbY2QhgCXAUviNRTj0ult8vqV+ k0+nRx9Bybr7eV2DVgIWtWTRSEaBjVMv8jVkFbFnNgnItE8tdukhsdyzmoUFKhLLbuQ7 g3rzcbaOAM8LcFvmcp55uWykIbaXoylZSPWqrUeF8qxlXlT8XRrSMaDXIcEcWaerbJjM eZvw== 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=5QrahDd61JCNCC55JMJ2nPOG9SHith/bj5jUizrYN8U=; b=fBhagNLsPnA6sVaWiWPQ5ZaCHixRdGpYEwYCwytrrnuXbenf9PyFlwQY6sDV5xmDUN tl95r+AKpXMSZpHe6BHvM0h4hRXKV/RMT5sWIGnJEEvTYe3nDLolGaBKoPpvDDmdBrfx Y4LhC3etWqKh3yVNkFnKgEqRMrwFu1Bb9bY5hlDOADixdLsgD0DjeU38Mkmd000oiQEL MEQP9/FhAj2XIYPqCk8/3OzSmprXcdZIQMS4zUtwmQUyPtSdbk9NU+bppXKbIAVEL+IE GykycxxavdFzxz8uJc2IwoAtrmpyVKo0Bg7vtQerd4T/PTOKLDY8a3sfr3N6JpYCE6da V/mw== X-Gm-Message-State: AOAM5339NAK054Y4Uus2xll2sg0r6Yqgq5oYw4D7w7Sq8THRNHsp/mxz VL/zhRg5XEFIbflmoxMAkHM= X-Google-Smtp-Source: ABdhPJxrJoOueqxei/25Jeko4h6CMJXERhBJgL4c+YjFOos2ggqAdS0RKwXTqQri+HGte2yQOt/Luw== X-Received: by 2002:a17:906:30d9:: with SMTP id b25mr21609137ejb.348.1615789124917; Sun, 14 Mar 2021 23:18:44 -0700 (PDT) Received: from localhost.localdomain ([130.185.229.134]) by smtp.gmail.com with ESMTPSA id t6sm7468478edq.48.2021.03.14.23.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 23:18:44 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 09/12] trace-cmd: Convert tsc timestamps to nanosecods when reading trace data from a file Date: Mon, 15 Mar 2021 08:18:29 +0200 Message-Id: <20210315061832.168495-10-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210315061832.168495-1-tz.stoyanov@gmail.com> References: <20210315061832.168495-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 | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 65081007..dc9ac1d3 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -1276,17 +1276,37 @@ static unsigned long long timestamp_correct(unsigned long long ts, &host->ts_samples[mid+1]); } +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 unsigned long long timestamp_calc(unsigned long long ts, struct tracecmd_input *handle) { - unsigned long long tstamp; + unsigned long long t; - tstamp = timestamp_correct(ts, handle); + t = timestamp_correct(ts, handle); if (handle->ts2secs) - tstamp *= handle->ts2secs; + t *= handle->ts2secs; + else if (handle->tsc_calc.mult) { + t = mul_u64_u32_shr(t, handle->tsc_calc.mult, handle->tsc_calc.shift); + t += handle->tsc_calc.offset; + } - return tstamp; + return t; } /* From patchwork Mon Mar 15 06:18:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12138419 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 E6AF2C43332 for ; Mon, 15 Mar 2021 06:19:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D6A0064E12 for ; Mon, 15 Mar 2021 06:19:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229594AbhCOGTA (ORCPT ); Mon, 15 Mar 2021 02:19:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229933AbhCOGSr (ORCPT ); Mon, 15 Mar 2021 02:18:47 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19B12C061574 for ; Sun, 14 Mar 2021 23:18:47 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id h13so15894751eds.5 for ; Sun, 14 Mar 2021 23:18:47 -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=KkCYKVW+cBMkK0d6ssPH66zOJhQ5u7wM4k6hR5nJgpE=; b=eXL4klNAWEybYutEMIAhLbhabWzJ6aob9CNAhtKyCSHoc/ANrcBW27qXDgigJ0wBHy aPRaOGpyqAMYQyhqtxDlzpr5WwW/1TqsSig0Tuo27Q5CGbkebxMDD1tguMAmrP2Nw1Yx qsfwMjS75ZDFTof/mCdIj/PeABjlMlnn5/z6wig3r1UeIgom/iNCFLWh77BaL+PTcrjS ElHcDfJw9e1v/e3WmhO6tE1jP6+hxpDzxUaI3YDYLTM5BBlFQrAUkHLv4iPpdjZr7vjx VKrR0jq4uW4ifOJROZMQ6NsgtOcM7U2NPDV0XtLp44W51BIpNxABp1Z7NbOwrk/k96PR 9FJg== 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=KkCYKVW+cBMkK0d6ssPH66zOJhQ5u7wM4k6hR5nJgpE=; b=qkwzoL6UfT1HA8HAdvm+bJU/wxdxp3Vq2UB28V5nzJV+gyGcxfdLGi9cBVnVnJpF+T +EKDx7gIE0TsC/cjigwP4eFdp6AaC5t6l3kr5oeBTB2rjGp4KYaUPnnxBHLUdzlNC59x 2J+kE8cUYw1Q9TBRYRqKvYcAe/Hc9wVD++E4tqQ8rdpdzMSitYw0J1U8H4BGrbA/1xlH tKoSMQz6ZQKUk1o09Al504LUcDXRUaGHhwTmPwnp/NzIeC8j2U9CVkYZfP+UG+9xyeh4 mrQsAy7I/DWILxdDHJt+dTT+0CISPe/xZzslPFcrxkdM440ADKZkcLuCVYiW4Lstk/2V 9EiA== X-Gm-Message-State: AOAM532KLIMAf1j6E2v9fEHRY1K3iQvR53hvAcU8Jl0Q2EmI/bjpCNY7 E0bmOYeAOFJKD20s7Ia/tzQ= X-Google-Smtp-Source: ABdhPJzdB3Dya3C3ZSPKRMvYeZMZKEeKi/5/TZK5ZuDwGKAGwoyvYBzitwLazXfFtmDiw2hm7Xon1g== X-Received: by 2002:a05:6402:181a:: with SMTP id g26mr28055341edy.225.1615789125865; Sun, 14 Mar 2021 23:18:45 -0700 (PDT) Received: from localhost.localdomain ([130.185.229.134]) by smtp.gmail.com with ESMTPSA id t6sm7468478edq.48.2021.03.14.23.18.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 23:18:45 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 10/12] trace-cmd: Set order and priorities when applying timestamp corrections Date: Mon, 15 Mar 2021 08:18:30 +0200 Message-Id: <20210315061832.168495-11-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210315061832.168495-1-tz.stoyanov@gmail.com> References: <20210315061832.168495-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org There are multiple options that affect the event's timestamps while recording trace or displaying the trace file. Some of these options can be used together and the order and priorities for all of them should be strictly defined: trace-cmd record --date , --ts-offset - only one of these can be used trace-cmd record host-guest trace - guest timestamps are auto synchronized with host time stamps. If no trace clock is set by the user and "kvm" synch plugin is available, then "x86-tsc" trace clock is used and tsc timestamps are converted to nanoseconds in both host and guest trace events. trace-cmd report --ts-offset, --ts2secs, --nodate Event timestamps corrections are applied in this order, when the trace file is opened for reading: 1. If it is a guest trace file and there is information for synchronization with the host events and is this synchronization is enabled: synchronize guest events with host events. 2. If the user has specified --ts2secs, apply it. 3. If the user has not specified --ts2secs and there is information in the trace file metadata for tsc to nanosecond conversion, apply it. 4. If the user has specified --ts-offset or --date, apply it. The offsets specified by "report" command have higher priority that the offsets specified by "record" command. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index dc9ac1d3..1cffa0f5 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -1224,21 +1224,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; @@ -1295,17 +1286,26 @@ static unsigned long long mul_u64_u32_shr(unsigned long long a, static unsigned long long timestamp_calc(unsigned long long ts, struct tracecmd_input *handle) { - unsigned long long t; + unsigned long long t = ts; - t = timestamp_correct(ts, handle); - if (handle->ts2secs) + /* Guest trace file, sync with host timestamps */ + if (handle->host.sync_enable) + t = timestamp_host_sync(ts, handle); + + if (handle->ts2secs) { + /* user specified clock frequency */ t *= handle->ts2secs; - else if (handle->tsc_calc.mult) { + } else if (handle->tsc_calc.mult) { + /* auto calculated TSC clock frequency */ t = mul_u64_u32_shr(t, handle->tsc_calc.mult, handle->tsc_calc.shift); t += handle->tsc_calc.offset; } + /* User specified time offset with --ts-offset or --date options */ + if (handle->ts_offset) + t += handle->ts_offset; + return t; } From patchwork Mon Mar 15 06:18:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12138413 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 D61DEC432C3 for ; Mon, 15 Mar 2021 06:19:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C14CA60240 for ; Mon, 15 Mar 2021 06:19:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229924AbhCOGTA (ORCPT ); Mon, 15 Mar 2021 02:19:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229939AbhCOGSs (ORCPT ); Mon, 15 Mar 2021 02:18:48 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50275C061574 for ; Sun, 14 Mar 2021 23:18:48 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id j3so15927565edp.11 for ; Sun, 14 Mar 2021 23:18: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=t+DImzHaNRqeHyfPwgtYfwWhK2kk5rujc12vxD101mY=; b=RfLLRMkr8SluD+zk2QyBW28v5qvdfHPqS0+xCFhurTWTPkRxCHl6nZO7NF85Ito1mo L6Vmqha8Cq8m4YN25NEgyVYcyyqE/v5NC9p5qGawVeRRScmBSYi9/8cS9DVn6byoB7f9 zzxU6ZjZ2MoMWIR6mR63m3TC5viPe/YUAAUO9JuJ5V9GNr4QfvL4dP8NmMUasCSufZxN Kr9nAu5j/9DnIJSdziQpAgwX8UP/jM/MdpqCnooh963ZoN6KNDp/rDHIN2aLk+gGFvHS fdQ2V2ivsfkGiB0Tnq1WGzDOphi4yX1CmGe8CrkkEbTvXKR0LarurqTqOyqzNPy+KA9l SgOQ== 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=t+DImzHaNRqeHyfPwgtYfwWhK2kk5rujc12vxD101mY=; b=Mst/K4oSxRf80kPMNWiMCoMvIOq92hVlzaj1aWwnBYU+g7818jNcXIkdOvK3RWOHx1 HVjye95hMvhkHVTTTOlCX5ITGfaqdxfJztdQaeQsR0iFlKb3Kgat3Di8Ilr58nrNmxQ6 1YQWGx0bZ9mjSBMYE81yyCooUFwl8r6Kux/cPIbzo3FpNSp5wDh3bqsZ8GueX0BgbRIf qom32WaeZXd2q2jWwSJRTeno6n59iiv8Yl2FykoIViKeHE5L5T2o9PErbNxoTlqfTvUB IWTl6Rl+xD0by3sKidai4R2v76KaN/SOiaTTLd/yKfR+8N+Mp2Mp0HWVpA8bho4AU0B8 wtHg== X-Gm-Message-State: AOAM533tAEMhApEeCED9YcT/AOk3jOjhp82w7aTSTxy1E9+MpCcTUp7r F5wm4cQ/E7BJtlZ9LtDmND0= X-Google-Smtp-Source: ABdhPJxJjpl63DB07G5ZBMB+Yf3e5ZwF9FsMdiIgCLYf/6w4T+ajV2/PtQOt7e81HNa80+rN3KcJpQ== X-Received: by 2002:a05:6402:5203:: with SMTP id s3mr28410316edd.79.1615789127024; Sun, 14 Mar 2021 23:18:47 -0700 (PDT) Received: from localhost.localdomain ([130.185.229.134]) by smtp.gmail.com with ESMTPSA id t6sm7468478edq.48.2021.03.14.23.18.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 23:18:46 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 11/12] trace-cmd: Add a new flag to disable any timestamp corrections Date: Mon, 15 Mar 2021 08:18:31 +0200 Message-Id: <20210315061832.168495-12-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210315061832.168495-1-tz.stoyanov@gmail.com> References: <20210315061832.168495-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org A new flag is added in the trace-cmd library for controlling events timestamp corrections while reading a trace file. If the flag is set, all timestamps are displayed as-is from the trace file. TRACECMD_FL_RAW_TS The flag can be modified with these APIs: tracecmd_set_flag() tracecmd_clear_flag() Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/include/private/trace-cmd-private.h | 1 + lib/trace-cmd/trace-input.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index e2ea0dd0..98616c76 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -132,6 +132,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 1cffa0f5..b53c1932 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -1288,6 +1288,9 @@ static unsigned long long timestamp_calc(unsigned long long ts, { unsigned long long t = ts; + /* do not modify raw timestamps */ + if (handle->flags & TRACECMD_FL_RAW_TS) + return ts; /* Guest trace file, sync with host timestamps */ if (handle->host.sync_enable) @@ -2603,7 +2606,8 @@ static int handle_options(struct tracecmd_input *handle) * gtod. It is stored as ASCII with '0x' * appended. */ - if (handle->flags & TRACECMD_FL_IGNORE_DATE) + if ((handle->flags & TRACECMD_FL_IGNORE_DATE) || + (handle->flags & TRACECMD_FL_RAW_TS)) break; offset = strtoll(buf, NULL, 0); /* Convert from micro to nano */ @@ -2615,7 +2619,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; @@ -2630,7 +2634,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); @@ -2709,7 +2713,7 @@ static int handle_options(struct tracecmd_input *handle) trace_guest_load(handle, buf, size); break; case TRACECMD_OPTION_TSC2NSEC: - if (size != 12) + if (size != 12 || (handle->flags & TRACECMD_FL_RAW_TS)) break; handle->tsc_calc.mult = tep_read_number(handle->pevent, buf, 4); From patchwork Mon Mar 15 06:18:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12138425 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 55919C4360C for ; Mon, 15 Mar 2021 06:19:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2595864E27 for ; Mon, 15 Mar 2021 06:19:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229925AbhCOGTA (ORCPT ); Mon, 15 Mar 2021 02:19:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229942AbhCOGSt (ORCPT ); Mon, 15 Mar 2021 02:18:49 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78ED3C061574 for ; Sun, 14 Mar 2021 23:18:49 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id e7so15888191edu.10 for ; Sun, 14 Mar 2021 23:18:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iJwVXhushZOIYhjD0e/V5i9CQUcf9y1pG40t0rxZTQY=; b=cgHvWqMbqb7WPmXB6CT37+8bY08TKjJ7qk0pRlQ/IPPvQfIDITV/Ha02H1YQH4xTPC 9EyWknhTiwW9bFW2vjNJ/byYAf/BrgdczSq+Pvxcs2gNKPz8SYLH5gBY7lDkPW39QroL HZI7QBCxWF6Vl5AxqfWeBMf4GeoCDotAhliQKzL4CG5XdXJHPZr6d5eSckz10HeM0vNb ZzPxXtL+mEtsRfLAiUnvEl7j+nwvovLhxieDxHnOQYONF9KhC8TL0RZzDs8ajziVLZZM TIN7JhB5Qpq6HiFHbSa32/gAebf81LLPgtKH8Z11zQZfsCrj7JBa9DjHVnAtsaUlhK1O GEDA== 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=iJwVXhushZOIYhjD0e/V5i9CQUcf9y1pG40t0rxZTQY=; b=sJ8+d1waSHfHOYi4ou+3s/7HQPbUJX93ygO+F++HJtD7LxtHOobStAMUNO5mwuQY0X bmb4bse9GwHvhIXnFZ+UjBrv8h3L/1ak/0zHjczhQgZzsLKTyQYghTVDaiuzMH0bOzVs B/M9Xtam5ChP467SCi8asQIviiA9Uw1QfB3+8+AUoGKI+InghO6IYQVmnxcxCIF54jp+ EVT4NDw+2KFQu5w86BFQAQ3R+CBjrmHiuMRCMZZUn5HUDaGDKjO0kwc6FJuorvBR7L4l vDy6wWxEfsMN8FkAqyTS6HFYHsLzARRJ17V1XMl+3tAGu2tO3XCXX7b51PAFckjcNXEF RIaQ== X-Gm-Message-State: AOAM533N3HX0gmikv4vcSrbFm+8H3Bap3qiH0IaViBK9nvklsO2L2Hwi 9DnihlkQCvsxBoRbEVO97Y4WBWVFm3yNVw== X-Google-Smtp-Source: ABdhPJw7srT0EOjhdk/RdtuB24/Q70R03wiGibwrzzaprWGiC8gCTRz2GDbdjMWcIR+ImnC6IMoflw== X-Received: by 2002:aa7:c456:: with SMTP id n22mr27728167edr.277.1615789128294; Sun, 14 Mar 2021 23:18:48 -0700 (PDT) Received: from localhost.localdomain ([130.185.229.134]) by smtp.gmail.com with ESMTPSA id t6sm7468478edq.48.2021.03.14.23.18.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 23:18:47 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 12/12] trace-cmd: Add new parameter "--raw-ts" to "trace-cmd report" command Date: Mon, 15 Mar 2021 08:18:32 +0200 Message-Id: <20210315061832.168495-13-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210315061832.168495-1-tz.stoyanov@gmail.com> References: <20210315061832.168495-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) --- tracecmd/trace-read.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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) {