From patchwork Thu Mar 25 06:40:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12163085 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 37324C433E0 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 128B461A21 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229617AbhCYGlc (ORCPT ); Thu, 25 Mar 2021 02:41:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229963AbhCYGlA (ORCPT ); Thu, 25 Mar 2021 02:41:00 -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 A68A5C06174A for ; Wed, 24 Mar 2021 23:40:59 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id v4so1067690wrp.13 for ; Wed, 24 Mar 2021 23:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mrWql2bkv1L+P0BBKY7vCuX2NHh8WUzf7IFlE+FdBVE=; b=ZgJoOTOfR2lWLqg6MG6+/z+aGPOZ3tRjx1tIKW10PHSXA4n+urJ4nlUSRWndTQeXRn ZyYbtP8NUsXvQxwfXl3M3Z90T+eUId3wV16N6VRY84RTW3lQPgTSSCNa5j5FZVcfCbQD rOKwxVWlMHonFnQrgGuHOdblNxbmvZFDvL2ilJJyZXVl7FI90w9G/+qAISYPMaSxTzo5 z1AZCTNXUtefHUMbQ9JWu/UKZukym+tIMGO+aUGKFaXDERkrnUvNqv19Fy1kAi3ExbCe TYQNKXwlgYiNZhQe4hCeBTg3lVS6MET8sAXjuMVNyR2H2wfmXT2296LjMsehvHmhxAeD 26sg== 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=sXoYpei3z/OGlA4NoV+FlZoNywdjlBJ9wIHSooXpM9bX7t9CzORVaDvCwao7uUugdt qKa0MmSBVB1Lv1I2jp1KkN3SODLBCmt0IXR3th3tvtk7ltlpQ8Ayh4ymEXEABNi5jDQI 9vGc9bGVhFfVx77CiSnuhCy5pqeTr7MzQhxFIoJK1FiUIcdS0WrK17qf/BFa0uoGLZ6P 7qhE7X2Bp1YmMwxmIj+0kkcwdPI4cv99YiAhknO2sFFEuyFb20KPLMnMb12LD08Hdunb ygD5RKfKKCcv7M9E836tpRvqdZtvMe7uW/pS2tRHbqsJLeObVVy2PEtF71q1lJ0oeSU2 I2qg== X-Gm-Message-State: AOAM533cYI0F1H1trYCqhJsJRMV6XpkbPGOE4pm7dwA0bBA67WruDlrA 2h3OEPJxKbKeetaOZDiVToF3b7h6mI31dg== X-Google-Smtp-Source: ABdhPJwG4MirmsYYscDN2a7NZwau9K9pFkhAvQ2CV85i1UuNO85TwCW5LyvU/pXaeXPQlaOQMXttSA== X-Received: by 2002:a05:6000:1acd:: with SMTP id i13mr7057201wry.48.1616654458342; Wed, 24 Mar 2021 23:40:58 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.40.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:40:57 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 01/23] trace-cmd: Add initial perf interface in trace-cmd library Date: Thu, 25 Mar 2021 08:40:33 +0200 Message-Id: <20210325064055.539554-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 Thu Mar 25 06:40:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12163083 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 49962C433E1 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 20E2F61A25 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229642AbhCYGld (ORCPT ); Thu, 25 Mar 2021 02:41:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229533AbhCYGlB (ORCPT ); Thu, 25 Mar 2021 02:41:01 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF152C06174A for ; Wed, 24 Mar 2021 23:41:00 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id p19so528161wmq.1 for ; Wed, 24 Mar 2021 23:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U+Rurdt3TLvNbFd+pb3BnO5RroijQkjhTL6sPJpY6XE=; b=uGPKYN30B6hOJNEIB5o2CJEq7Gb45vq66numMHs11jvHt8d+zOv2ru2Pi4dBk9kQiY oTjp3FH0ZeCjqtgVTspeOQHDI8cP2a2C2+/mTkIXueSWwcEEjsjj7Ci2AeKyPFhaow5Z Zrq9tnS7QTEN/ct5mGHPVv/VfJK4NZpororytW/V6xeAeQh164ho9GDJRdGTt00iu+SX WkLDr8WmEgO0nZl2Yj7H7J62oiCSUVZuaBjIothtRXmCT/lN4grUPJ0rU3rlRH7gps/M CviogicIuuAkFc8ZDK6tK/y7jDx5SI3B9v7va3+fkJkA8uaGpGQiFH/d8hbCcJpj2i/M 6YCA== 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=U+Rurdt3TLvNbFd+pb3BnO5RroijQkjhTL6sPJpY6XE=; b=QUtPd1VPze/lt8k5xROqzkr3QBArWrdW7GUdTG5LxAefmR4lnLe6CBNxF14XdHnp/g 16iFRl3z1m2lJkI4nFucbhq1kbD9NuZs06yGYd/0Y4hnmea97Pjw1PI3/Lp9nR9kQjRN 9/XM4JGjvo5bqRHvzON+gz+My07ioxbza8gdUoQeVXRYljcP0X1+kDFSUSSPhRVHQxj0 nCl3fiJZ1xjgd0+KDyda+Fsn46X3pwbdYBMyrVq8KVC682ns8EEqazdziwt1NYVUIavW 93SY7KYPukEcf4T9L/1qFlGxQbxHjTsz+pheFZaEWFWa3hXffi1ITcBTkUrHQF82m1XL rpyg== X-Gm-Message-State: AOAM533lcP4iizzp2r+WvUiwLjZ57uozBx/T0LY8VT1c8zMzKZkB4IZo Z0YAqVfwiRUSL+1+mohQTMos1fJfneg+UA== X-Google-Smtp-Source: ABdhPJz1SU2BWM9atDOzDr4cO6MxmeNWl0JON+DVORW3YB+f/rdk7SKsunI+n1uEHq4I/HuKF3atwQ== X-Received: by 2002:a05:600c:4292:: with SMTP id v18mr6147206wmc.23.1616654459606; Wed, 24 Mar 2021 23:40:59 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:40:59 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 02/23] trace-cmd: Extend trace-cmd dump subcommand to display the clock Date: Thu, 25 Mar 2021 08:40:34 +0200 Message-Id: <20210325064055.539554-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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..5db1ecfa 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) && !DUMP_CHECK(SUMMARY)) { 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 Thu Mar 25 06:40:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12163079 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 28761C433DB for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 014B661A10 for ; Thu, 25 Mar 2021 06:42:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229662AbhCYGld (ORCPT ); Thu, 25 Mar 2021 02:41:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229979AbhCYGlC (ORCPT ); Thu, 25 Mar 2021 02:41:02 -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 A9024C06174A for ; Wed, 24 Mar 2021 23:41:01 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id x7so1083099wrw.10 for ; Wed, 24 Mar 2021 23:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BydiSnOJRjDENmt5NRZCJV7x/+M3vHm+ubCEz8/g42c=; b=lp+2ub1s9mDf2UTsp0KBB/RHkocM9chOeTAtNUaIXvSWRNTdqVr5pTm1LcPRSyz17L D1QG9jS9mX7MO0DnzHX8XNKfyQ6W5JkYBqEoB/dBeMqBfDw4Cr+1+9+6jZhRbOddEIpn dBeMZz8kZIsEDLQafZljB0bbQYhuvDrw2Po1w3kHV3vX1/wtt4F6C+MPHVO1bVh/sTp0 rUWs5k73KXx1jhULiwxNfAprmJYWK0Kto2dRLBDChmiYT4ci+/IrqVwW9xo/VfyUYxWS v84gtS6Q1UkFaok7mnfnG4TAuZJ0ycLB7pD7YBrSa1v2wFYEz/6fFW6pOLrVZBowOQk7 Ipvw== 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=BydiSnOJRjDENmt5NRZCJV7x/+M3vHm+ubCEz8/g42c=; b=r9IpSwG2GD//OkyuOGfL0Wsh/vg9snO2FOCOvq2EtglMUdh/a6OWdQ9TWJCzpH7ub3 9BTXDK9n6I15b+nHduf/S6CUQzsw8siFayrD+NiuVYVFLpSnRaGkkZwZ6SZ1bKtNkZl7 lWd/aAfKFIldJ6FiqP1htCLPtzzi9KFp5i0Z42YQfhNE5B5R3mMz3ghijDNAGdiTbnFw wdasoJ9ihXMvuI4BVy8yU7JeRLvK7gopxD1y2xqQF5IpkyTOUNcQPTZYpvkh6rBoTij+ bUsQJUN5C+g8jvpM63zHxiddc5DDzwSnyQRHoL9cKnlW0yxu4ODVWw+4NdWX6atxDWg7 hBjw== X-Gm-Message-State: AOAM530mvHCP0chW+7Uhh6HRQuDI4E9QDdfyRrC/fHnVVoNQ7WPXKIg5 kXsFOXEoM68QpMP4EnLnwjRzyMvn+hBgDg== X-Google-Smtp-Source: ABdhPJxhNQqx9SJh8OZhVB0/ZHtOemqy0MyirzZSQMtq3Rze6VSYDobZF7rEGZOse1L3B/QJ1gihJA== X-Received: by 2002:a5d:46d1:: with SMTP id g17mr7070485wrs.342.1616654460453; Wed, 24 Mar 2021 23:41:00 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:00 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 03/23] trace-cmd: Save only the selected clock in the trace.dat file Date: Thu, 25 Mar 2021 08:40:35 +0200 Message-Id: <20210325064055.539554-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 | 66 +++++++++++++++---- 2 files changed, 56 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..ea6d1ba3 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,46 @@ 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 +1413,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 +1451,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 +1483,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 Thu Mar 25 06:40:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12163081 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 5B785C433E2 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3109F61A23 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229533AbhCYGle (ORCPT ); Thu, 25 Mar 2021 02:41:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229981AbhCYGlC (ORCPT ); Thu, 25 Mar 2021 02:41:02 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8769BC06174A for ; Wed, 24 Mar 2021 23:41:02 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id k8so1121472wrc.3 for ; Wed, 24 Mar 2021 23:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WDq4JxpNtg/mIRxKEMjeZkSbCUogjXW4ab8x4Wk8n5Q=; b=biTOBMeduNszFl/Z5VoxmfO9qkPNRQe9hTCwyioMgFdQmrlTH0+cKaTu6JvO0J1/oW Rrz96JBdirD8LObGWIuM7V7JMXSQoq3PUGbxqUZtQyIel7FcEgBHayrE4a/Vs8kCu+y4 PkXE3K7x5eWFRR3HNMjaJHRLWbO2QCd8l4AW5sKn52p81wOBqSWeHeBlAyRTvJn1EXiD 0ZvNFDZkWQ01UwBmeSPvnvpg8DkAkwBVfmPLxTu2EAXw6R2IzLqxMEhRKkrhao6V1qeJ 4V1FogrqMzXXnX+JNb7M+FaGtnDs/hAKppahVntMDcrqToWNwcdibM4TCkPIS/c/Ssrh Gtcw== 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=AuYyRcpOBn6d88fb8m4CX/YY1IV7z7Dw7l7ZqgARFH8hUQMJzTDMgZEZOaAQ+zkjST NwUVWBBY3Mq73FTCqG0YqUooOrrTIQbMXCq+PQ7CjyNiFZM88Tm5ZoyCRRZm9xnaGZCU 8HntPjv1Dw5GBDLkJoKRNsYZUcIuGKkzOQFFpgOpOH1ZJhDJXMz2kMYXUi/taSLxQC7/ ZyM42SGJSRGuUd4z1s1kET0ttA7r7pReSjuJRo2sPr0rdnZvKx/os0VhoxoHLGWTh2LQ F394yRgi0eRGap4qXxltuaTKpqU+4t59y7Z6HqbjkzX+iuDpE30cQloxd7NDxpFB0VVc n73g== X-Gm-Message-State: AOAM530H8kyiMvd9cY9kShQ0BAmWNZzLwKIKqG92X6MToQS/RpvDf62d IMaqMhYAlgd0zoqVLfbVd9fKObNAp7ThIQ== X-Google-Smtp-Source: ABdhPJxHYAuXj3nWmsxffq6u3qzSMMepNisVTCb2TQMdXirrGD4xgkvwyn4QVmVEjxs7ZoNJc6HRoA== X-Received: by 2002:adf:de91:: with SMTP id w17mr7209370wrl.268.1616654461305; Wed, 24 Mar 2021 23:41:01 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:00 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 04/23] trace-cmd: Internal refactoring, move logic for local tep handler in its own function Date: Thu, 25 Mar 2021 08:40:36 +0200 Message-Id: <20210325064055.539554-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 Thu Mar 25 06:40:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12163087 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 7AB6EC433E6 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5586861A10 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229664AbhCYGle (ORCPT ); Thu, 25 Mar 2021 02:41:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229984AbhCYGlD (ORCPT ); Thu, 25 Mar 2021 02:41:03 -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 8AED1C06174A for ; Wed, 24 Mar 2021 23:41:03 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id o16so1158380wrn.0 for ; Wed, 24 Mar 2021 23:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dyWukcMW7GmZiqYJEO7XCZFR0f+MugJSuQK6wQtLAAk=; b=mwv5ZodNmtXWD52VP1bNxJ+kGD/uZzYdhPSiPYrjF6SBOW7wFACvPHDSOwIzxyTpnX raXzwPKkmiOR+8Y1G1JH7Y6zhi/dDT6rAUrn1MxzBZiBAQfd7+4BabIwnAdYpw44jJTJ CweZ87x/WUv2SSThKcBtIyJqCpJcReIUoMe6qH4dct9t65feSFvMEXg4UOazXzf9yiDL PA/1XS/I7IjiwQrCrDcajKextro5R2+5WC5b38COeWEe1WxAhIPxHBQsrV9ckPNMNmrg XkgLBtEjzSugxAl0APKa5ilkQw8OJpev0HRhi4GLTESfyMcvOrNdVxGduNu5Fd+/M7Xv L6rw== 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=dyWukcMW7GmZiqYJEO7XCZFR0f+MugJSuQK6wQtLAAk=; b=Zt3ra7VFN25DJ8nC50R0RLNnC2OrWr9Ayx26GWa57y9mRuUK5ohrmR1NUMaS4z167j 9igX2OG+ArVuLqfDUe8xXXUraRm/zLRiaLcxewEqLKbYzWKh84ln2G0amIUk/2TCdFRW 2i78V6/0g+i/Sed1CaSHYxzGXjCysr9y/PzQ5RQ01mFwaHjmuk7s3uzr4I3qehjZMCR5 WuJftMHYtj9XfaJeLGlztpkr6q7wE9H1nIetoIA4neZTRPh63PZqgk4VEHV0zhc67N/p dpzFQX2gWAcXQEVDfjpSpYu4e0Ik0h/Lb6zw5hhzFb7RgBqen5TwWbN7ilB/cpTkUKe0 o2bQ== X-Gm-Message-State: AOAM531+FcRfTLUorM3mTwgDCN2h9mbpDWAx3D2gJVV6VukqMHZi9zWn C+5aNrBsRVikoLwHkQJqOuU= X-Google-Smtp-Source: ABdhPJyze9/yTb7Rb8i88eI1osLBmmLMvyAhYj5NfgiW5gAzhz+hvuQ9LHhXZwCxKIKBVUJTRqYMEw== X-Received: by 2002:a5d:6a86:: with SMTP id s6mr7275925wru.307.1616654462388; Wed, 24 Mar 2021 23:41:02 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:01 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 05/23] trace-cmd: Add new local function to check if a trace clock is supported Date: Thu, 25 Mar 2021 08:40:37 +0200 Message-Id: <20210325064055.539554-6-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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) Signed-off-by: Tzvetomir Stoyanov (VMware) Signed-off-by: Steven Rostedt (VMware) --- tracecmd/trace-record.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 635897e1..c7197ba0 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -5683,6 +5683,34 @@ 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, const 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 ']': + case '\n': + 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 Thu Mar 25 06:40:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12163093 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 79BDEC433E3 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6721761A2D for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229981AbhCYGlg (ORCPT ); Thu, 25 Mar 2021 02:41:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229986AbhCYGlE (ORCPT ); Thu, 25 Mar 2021 02:41:04 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8522BC06174A for ; Wed, 24 Mar 2021 23:41:04 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id b9so1087963wrt.8 for ; Wed, 24 Mar 2021 23:41:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oQOA0gjf35WeJ2NhvqG2ZfoRPZU5Ku7HjPjiQZ6qxMk=; b=ev38YBL4Wgr69/uGpDshi9F1ibZ810yNFjQnluuQRCA8XXh7XOFc4AEtzqBj8lw+3c 2bOy9xq8PbK8URkMvxKkSRdTkEgl1tbLlrkN+ws1DuUxhn8ZYMdOo3v+ASPn91dfZwbT BU/5t9DsOiIo7FICh7NGIHJ+OaZDj38P0OHGDC554pp/+UPzww51Q2uDRyXLtghC1jz+ O5gNeuNZQEP53u0+z3WOY8jWifTQ1y3XYbiTc0CV08JDv4gtgcgdEbhphfoR6/VS0PWl w1oK2gR/fcpP2FIECC0c9bXgPTGzEYSQovv6Jq7r/3U9qwv3daD4VcVfsqUNIAHCh7QA zHnQ== 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=oQOA0gjf35WeJ2NhvqG2ZfoRPZU5Ku7HjPjiQZ6qxMk=; b=flxMYAtDek2YKgtB73c3YjkUMrd05qrmsOefjgUy6zCN6LO95WXMteYnQhzMqyWjDP i/5RUQUS9m0I97VppYYdT470B70x9qcmOBszFd1XH06Vd2Wz7Jj+EFFuYNrwqDT3Eo3p /JDoA7p9TnJmvs7l9wByBfZi3YTJ9rWghyUm5or5b2icwOWgR7Xomrp607FlfMoGQUc3 1ah8IFa6MjdxtLCFZWsZT3wH8cx86LwhVqTJ8D1wGKWutBsuWnq2bNInzBcj+aAadPNA Noouf89oaFPQHPmmtZ2e31Y9SrimjyQnL56aTZ6sA9L1cUqa+rBiIrbFQ4p6oWGmk8xV Ju+w== X-Gm-Message-State: AOAM533ktlMVkYGRpDEZ/QcdGiy51eTAPWVFNLsGe+yCFlPN8mHEqNqM aN6J6YpEtjDf2Dh9cJaobrRIbJhv3y6R3A== X-Google-Smtp-Source: ABdhPJzdABES/T34lnHezvX0fKTBzCy/pPtevKwDzOlhkeM7Bvnf8T6wGD5TV5vj0dLs38/RwQlKyg== X-Received: by 2002:adf:e7c2:: with SMTP id e2mr7427377wrn.338.1616654463317; Wed, 24 Mar 2021 23:41:03 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:02 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 06/23] trace-cmd: Add new trace-cmd clock tsc2nsec Date: Thu, 25 Mar 2021 08:40:38 +0200 Message-Id: <20210325064055.539554-7-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 | 152 ++++++++++++++++++++++++++++++++- 2 files changed, 155 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 c7197ba0..49fa46d9 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, @@ -197,6 +199,7 @@ struct common_record_context { const char *output; char *date2ts; char *user; + struct tsc_nsec tsc2nsec; int data_flags; int record_all; @@ -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, @@ -5711,6 +5716,61 @@ static bool clock_is_supported(struct tracefs_instance *instance, const char *cl 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, @@ -5760,6 +5820,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} }; @@ -5905,7 +5966,21 @@ static void parse_record_options(int argc, break; case 'C': check_instance_die(ctx->instance, "-C"); - ctx->instance->clock = optarg; + if (strcmp(optarg, TSCNSEC_CLOCK) == 0) { + 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; + ctx->instance->clock = TSC_CLOCK; + } else { + ctx->instance->clock = optarg; + } + if (!clock_is_supported(NULL, ctx->instance->clock)) + die("Clock %s is not supported", ctx->instance->clock); + ctx->instance->clock = strdup(ctx->instance->clock); + if (!ctx->instance->clock) + die("Failed allocation"); ctx->instance->flags |= BUFFER_FL_HAS_CLOCK; if (is_top_instance(ctx->instance)) guest_sync_set = true; @@ -6160,6 +6235,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; @@ -6307,6 +6389,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) + continue; + + 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. @@ -6365,6 +6506,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 Thu Mar 25 06:40:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12163089 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 6981CC433E4 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 414E961A21 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229833AbhCYGlf (ORCPT ); Thu, 25 Mar 2021 02:41:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229988AbhCYGlF (ORCPT ); Thu, 25 Mar 2021 02:41:05 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A0A2C06174A for ; Wed, 24 Mar 2021 23:41:05 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id c8so1078259wrq.11 for ; Wed, 24 Mar 2021 23:41:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Uv/CogdT8ceOEw3qj2CE7HWQcP8kkyyYvyFfuCggMho=; b=fp2QmcsqpniWGcu1XMtxrepCDRbti84E6lq/JSmAYMjA3gocfEbh1pJWhmeCCT1SoA koRe4vvds8hGUh7g2dwOn/oku1EPlfwio4ejGozNNjtcusMJmMLw61GXQFUVyB8fCtED PEVnbXFQV/8KZmHsyuVDVPLvxQmIr3Mokw06z3p5sH77G2bw+qhbG9kEJ0+0kTF3Rx+q Z4Z0luzX4e1+G0b3DcjOqGR8geh/Sd2Ii0umcSPP/xyO3UETNFYNrgGxgsXZe8Zxt7yA rHjBY4LSF4ONkvfQFneBEqo1NkU0ebqkPgaVoaTjsxUEySQIi7N2wuIPTktieb+gWqon Qx4g== 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=Uv/CogdT8ceOEw3qj2CE7HWQcP8kkyyYvyFfuCggMho=; b=QH3MLM+zAlLgRwq7cict7lHEdYMFnd3eJIhbZE0Y8rWrJB4RBu8ZPX3Vg8otQRnCYK Axn+t7lNJxTZaowv4e469tGQqx1yued0OLyEzKczOlmnhpqGqis7Ty+z9ic3KBi89oqk Op7IWoNmJFamQQVvgoFoLaaOVLu0y6Hg7J0juZzZShMW1Jc97vQBezFrRb6OimRFNoHe gqkI7LBtGJpKHTe6UUsJkFPQOg2nm24MaQS2NFBD/7wazM3PEcAP9RdyALiIuK0NPARd VTnMOWuJkHnbuRIG37qyYvnZi/IWNoDfTTlvI1HE+ffCRUwHMCiNuFi3WIWTPAnXWBLb ZXIQ== X-Gm-Message-State: AOAM531CXlpQO0s0320HWpc5/KtwlzunjiDa4eShe5JoKhPs63uexVXZ ZbPXszm3zte56aQabuof0yV0EmRX0Gg6Og== X-Google-Smtp-Source: ABdhPJyYHEk6+ZsMLJinUVWDjaaK+BYEu/qtVoy8t/HA5DjKJ/lUb76eVoMDjoKp4bqnXDrcbFYHyg== X-Received: by 2002:adf:f005:: with SMTP id j5mr6919179wro.423.1616654464119; Wed, 24 Mar 2021 23:41:04 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:03 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 07/23] trace-cmd: Define a new option for tsc2nsec conversion Date: Thu, 25 Mar 2021 08:40:39 +0200 Message-Id: <20210325064055.539554-8-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 5db1ecfa..24ec9695 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 Thu Mar 25 06:40:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12163115 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 E78E0C433EC for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4BD361A10 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230001AbhCYGlh (ORCPT ); Thu, 25 Mar 2021 02:41:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229991AbhCYGlG (ORCPT ); Thu, 25 Mar 2021 02:41:06 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D285C06174A for ; Wed, 24 Mar 2021 23:41:06 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id x16so1108946wrn.4 for ; Wed, 24 Mar 2021 23:41:06 -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=fvmmPxOjkja9jyejZt6YMZ6zzu/myY++7FFg2p/Kgvs=; b=WtGKG03up6cnOG2n5lkpvsTCMjP8HekfepOtlGycySiDTG4YUr8vkjMmUnlcKhmfbe 7cruVgQuPPwa4+Jjx/GMbA6yRIMJ8hLdeljYQbR9Ln5kwMj596dh5TWwktiPxB83yJzh gd5kPZaFWMp5UsBgAwQtxb5H6rVJ7IquropGluJiN6v1X+50OjkCvY2p6Fuf+o0JKi5n pBrs0HJ/tk0qat8WIt6Pcu9XOd4ALKp6AutNG7i7Fv4gLxpQlMS4uCeQii6i6SxZ5Z6k w55wobWRKi55LL16cr53rqlXThC4CPtVPXHna3oqHKxwLyn1vaLWUGAGtlNpfwUm1S0Z MmsQ== 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=fvmmPxOjkja9jyejZt6YMZ6zzu/myY++7FFg2p/Kgvs=; b=tgylcKelA3PnccqCj7kztJ8uBpmO658UolAO/QKt+srQ9ETzweCCjRtf45O3RtFEDf iQis4840F1f0Sg+72sUxFvbCoWCJ4tqzcZ0LHzXtYbDQojEoZoOGrL33AcemPcquLzy0 14AzHlKb5uuDuqqHjd5uqi2im65egKU70NfhYj4j8ZB5BPXmQXfBSTDkTfYG0guiGA28 2+BPUaSS99gXXYvD/9PzTxx3KRM0hC2xcUNbulJL3425UADI6ouc1X6Fb5Tv1pQ51Y5z vnFdCg9o9y103KXA5iKSkutcPFKkKQu2VBv8of4kJN8CFllOrRsuEZqc0++Nz0H1mGpn 22tw== X-Gm-Message-State: AOAM532h8bKBphzDKmxZn9RdIpbWaiCQ4HJPVtpBbn/3qwLMtb4LmqFh yKMuIuUvueYpj2+jJTDR64kYlKGKl9MtoQ== X-Google-Smtp-Source: ABdhPJxqi8PP/Ek4XaPCzzvw9ClQJB15tHULy0iAIFgsf/vDG3puTuG/qZvXVXGi7gLo8Zn8argYBA== X-Received: by 2002:a5d:5270:: with SMTP id l16mr2438452wrc.317.1616654465193; Wed, 24 Mar 2021 23:41:05 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:04 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 08/23] trace-cmd: Save information for tsc to nanoseconds conversion in trace file Date: Thu, 25 Mar 2021 08:40:40 +0200 Message-Id: <20210325064055.539554-9-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 49fa46d9..9f8c4943 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"); @@ -6589,7 +6613,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 Thu Mar 25 06:40:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12163103 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 D8F3CC433EB for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B37F561A23 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229991AbhCYGlh (ORCPT ); Thu, 25 Mar 2021 02:41:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229989AbhCYGlI (ORCPT ); Thu, 25 Mar 2021 02:41:08 -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 497A7C06174A for ; Wed, 24 Mar 2021 23:41:07 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id z6-20020a1c4c060000b029010f13694ba2so502375wmf.5 for ; Wed, 24 Mar 2021 23:41:07 -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=jEmUk0KbtzZg53n38VEzA24UZEh2PdPVvLHOaJVW48GA23dvHoVpZkaqvHwYwEKsQE 7xzx3o8QlBqazY5MmbpLgtcaXkS2udlj/vwTFTlWJANSRWMChaB+pt7WX+kwu3OTJVJf o4PIXq9dQ/sDRvWRHty+EVYYY0azmmnzGd8Z+5rWkbun0DtTJuLv5/MAtJt2sRYCRuNI COMTYdz0+IKdJ2t3OUn+EKq159kNJVupyP89Jj7EbJoCIhiEsc5ZZd+By1bwQByfCl+l BRZY7JIUuTndPemtDcG3WeebarUpYUR5awVnykfOBeLiw6+U3JGIp3gi9okNCjZeMPgu N/oA== 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=L0q5LJP0CFdJVmuuygVUvNAAnmhaYycH/JIMK+Sbrz1QX1xwnSJjWoB6p7OZl3G54a ObfnpnyXwjN14fTrTBTewdUkMbm0wFC5mq9j3yX5MUA8O3VjWlQMLBGXA2GR6mdjnw+3 vSQVfzpqXNZLPKIlIF3NnH+HsV23jf2Cwq6Gwg4hfUtjJKCVPROskTFKEoBUr+SV5E64 G/88UU0VBVVnYCVGnNcJ8ktKdXjG5Fx1psH2ET8Hj7ttKYsYVKHfmFEHLkRXfJU13bU/ RWk3ywuHTmKaKECd9urDzKoJhXSu6Eb0bDjqlSh7FUI6BZCkV/g3l5mTOUievaVYWoHI Quuw== X-Gm-Message-State: AOAM532x7W6HjCQQgE7vmzneFeJL9Ki87e5JSh8ut4n2moJ+mhaHnPQG +1hQBdEaojR9lgDTbSSVOhr3wm4XNOy3/Q== X-Google-Smtp-Source: ABdhPJwqivHPPyzcP3+ArhVRLgog3TW5iy6G++LM1AUPATAKMPzhKx/ieGOcaEhxn9x57s3jbSgd6Q== X-Received: by 2002:a1c:e389:: with SMTP id a131mr6314450wmh.78.1616654466057; Wed, 24 Mar 2021 23:41:06 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:05 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 09/23] trace-cmd: Read information for tsc to nanoseconds conversion from trace file Date: Thu, 25 Mar 2021 08:40:41 +0200 Message-Id: <20210325064055.539554-10-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 Thu Mar 25 06:40:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12163097 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2C6DC433E8 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 87B3561A23 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229994AbhCYGli (ORCPT ); Thu, 25 Mar 2021 02:41:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229993AbhCYGlI (ORCPT ); Thu, 25 Mar 2021 02:41:08 -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 7622DC06174A for ; Wed, 24 Mar 2021 23:41:08 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id o16so1158535wrn.0 for ; Wed, 24 Mar 2021 23:41:08 -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=maircGKBgsmJQJ6smWACwE9U5aIc3Gre0Jp/o7zMKlQ=; b=Kp2jnLu+klOulH2H1TRsVmH/xeQjKpt0OZdLVhyiVUrYTem16uqDnN9gyJb9d24Qoh 7pR8K6PnvqRCU/g1FIKUEOM78XP1m1BSCE7NGy+Gng8I/rQTMRluvhkDleLgy2D4ZU6t o69At4sfm8uetOa5bk4VihbuvEbapqrx6ddr4KNrNRyRjJCqRpdd5dJT4w20yv3MATFO tgnl4reYNA+JoiIsrRcov8ZQ4/dN+1mhe01YyH2erSyUB8TNjUr/LI+kdJS5tVGyH1Ib TE5Qn0lPbbm0hKjknQH8asA/T+h3qEz7cs87z6cGLfJg+A1p4dZU3KDrsT+sfHQXGTNl TVSg== 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=maircGKBgsmJQJ6smWACwE9U5aIc3Gre0Jp/o7zMKlQ=; b=bDstvaeguxXF4gCb3Hc/IBmWfrJSFPsGeHj6tZCYSnd2pbXvdq8KyJ+154Jzso+yzH zqa7heUQYKbff2mcvq/zhmXV0XqNokkr5QpOuuzyJ4TzHpNOhSExJCWJZi8+ZEttaWNz gluV6qqtsCCLaYIZriRs9HpiBsCfVSvtSeqHVmPpy40Z1OdFjp/4lkngbiJHOGDF8cFG tfmiDh+mKHsYig418hjZY5VHwUIxee9lSrLdoFsyWNJu1IaWf+2/pWTIZD9lja4oF9S0 KTC8cA57JzLhZnvjKRe3+n11h8wtL3dp84HWwrh0n79Z/be9eh2ZLGJq7/pwNXXuuEJJ v4LA== X-Gm-Message-State: AOAM532/hdZQOUVFImbBVQXE3Jdmt5CY7Gp4uvQrt0rcFPhIN/DHmrNV O4ytMcWYuqt8yXu35lyyJ8fWh/QI/86HQg== X-Google-Smtp-Source: ABdhPJy1tp7+P02txI3d17DqGCcTOuOp7UE3s2aG0ForXqRRh2EfO7CUitk6U7D2/bkeOV8gX/J/rw== X-Received: by 2002:a5d:4884:: with SMTP id g4mr7047730wrq.191.1616654467158; Wed, 24 Mar 2021 23:41:07 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:06 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 10/23] trace-cmd: Save tsc2nsec clock in trace.dat file Date: Thu, 25 Mar 2021 08:40:42 +0200 Message-Id: <20210325064055.539554-11-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 9f8c4943..b7f6f438 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 Thu Mar 25 06:40:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12163091 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 AB1A7C433EA for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9A8A761A10 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229989AbhCYGli (ORCPT ); Thu, 25 Mar 2021 02:41:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229994AbhCYGlJ (ORCPT ); Thu, 25 Mar 2021 02:41:09 -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 4F70EC06174A for ; Wed, 24 Mar 2021 23:41:09 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id c8so1078377wrq.11 for ; Wed, 24 Mar 2021 23:41:09 -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=bNPGgh/lMzmMxbBchjr7g7nlX6is0KgzagoVUlvw+ig=; b=ZVhc2LD02eIdGseukPJfJW3/gUBRkZcxnzWUWjyEf2U+8mLWzK9SKk7U//JzWnYCWC Vc7H0TjLRx14reZpfRvTEdlB+W3vkhkq6DQjU7PZpnGMGuZw7Lee1Up/RMxzIa4L6Wrt jx2N38rNCdPpVSZdf0nsvVy9Gfgee6MSnDbCHZyYj5herzeJECCcTr/l+0QJrzMMTNIP Xhb6xbA11IhvEuGRGD7NecdJq48af4Z21SQz9sfMOEzRaHzD7zi5/4kzLU1FmYJipQi2 S/1T7CO3nFi+z501Zz1yJQoPBThNC5qBKxUxpiNdIOwj7zyAceTiGrtzWqg6fFJAVxuX SzCw== 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=bNPGgh/lMzmMxbBchjr7g7nlX6is0KgzagoVUlvw+ig=; b=dLkFoilvwZV8N6B7tjli4O3zjoi7kJ6ie5FDtpRa9lD4tBFW6/0ySt6rajM5sntLwf ECAglxi6FZEtPjMzkzcCRwwpCXvCFaGWs+nNiTZDUWoS/4Zdl9GEANbs+XAsdPRWhP3Q N+zj7VCDteMFw0Oa52pW04DIbC8VJe6IBlBYIL3YOAVGH27+iJveEztA6CGcovjEFlg2 FPJ9BFl58HEMP18j56w1xLU07XiSvIzlBldtpAD1rt0eXQB4wrl/ONN6Xr/ly8MPIWU1 tn/LAfgdTcgbJ2VExKppwq68PYwdz476uaufshW645ekCk+XiW68TuI/1OC+KrnzF6gi Xkxg== X-Gm-Message-State: AOAM531FnsO7Hpee+cJTWCN9JxaFtyO446WOS6dN/yneklsSGrIDW5b/ qvUtI7pccoXLabElV3BOXww= X-Google-Smtp-Source: ABdhPJzShYOBd7wpTwbM3xR3PawD3U/HFxNU87Til+hMUaG1XfZRvQgAh+6gH7hyWU5iAx0lp0rfPg== X-Received: by 2002:a5d:526b:: with SMTP id l11mr6981849wrc.385.1616654468087; Wed, 24 Mar 2021 23:41:08 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:07 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 11/23] trace-cmd: Append new options into guest trace file at the end of the tracing session Date: Thu, 25 Mar 2021 08:40:43 +0200 Message-Id: <20210325064055.539554-12-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 b7f6f438..4e4ad127 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 Thu Mar 25 06:40:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12163119 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 5CAD7C433FB for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3FD0961A23 for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230005AbhCYGli (ORCPT ); Thu, 25 Mar 2021 02:41:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230003AbhCYGlK (ORCPT ); Thu, 25 Mar 2021 02:41:10 -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 4B644C06174A for ; Wed, 24 Mar 2021 23:41:10 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id x16so1109077wrn.4 for ; Wed, 24 Mar 2021 23:41:10 -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=AJbGqIIMjLeG7JzlqR2aRE6fUziKOUtAP5E2nmdJS+RyoQ9t/c22WJguMEfGgaCW6J 2HUy5XcxWgTH2UdBGIPmTKaVCaimndjg9Vp03Kgw6C9Eai7LjVUKVxI9vm03IVff3CP5 t5xeWVOooXVKK0uxzkW8HAfGtJMJ3hPfF/kadpsDtyObCUZfoMCvNbrKuYlnfzvpg23p ksKCy0Hbs5GHueV2Gm44+ASkD25Pn4U6zsBP2VhVSLyhb4R9ycXwKlLcmWg5i69/snDD GgKFGSXiZtTz3YHh0B5aHfJp3uy2HXPKmGqMfPZ7OsIodpmDXlMiqxzRj1WStGZ4k33l d3hg== 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=j12uVynwgxu3gLdLdUmpd7clygFSpJOT5Cp1VAUDQ4i29vMom+O5yNiP47bDOAekt7 g6MDCk5IJcXl5k1j2bO9fe8I683ZN33sVysOjyDujyAeLi1AuvEW0Zs6+Irg+6mfYfRC qfDFVJqrl3KvFyGLsKtNZECUHArr/P8aOtRneQk0Y3bvEMylTyZFEwqtTChmdnOeniGp OkARs+nrCXUuYhijmjrTfQqrYg46UL4F4oa8fhcV4pJLmaaLPLEuy9PuY4m20oClSnx8 nyXvdaR+uFIrDUH3V40R8roM39gQUYs8CfllXHtcFuA8/cXQgx600pLsmyjBt3OnOG86 GtPw== X-Gm-Message-State: AOAM531wkH45oCMuYNgn91/nf/q78QE05apWMAvGcu2YJQdf4Oey4wLe JDCmMqCnSXE1302ehuC85oY= X-Google-Smtp-Source: ABdhPJx1C0s8TRQXAvL5nV9yCZcORRT8/YjnIMxwv8crYSIQD0h/7mQFG9WUa6F9+NlTrLgILWDMaw== X-Received: by 2002:a5d:6cab:: with SMTP id a11mr7143401wra.419.1616654469069; Wed, 24 Mar 2021 23:41:09 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:08 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 12/23] trace-cmd: Remove unneeded multiply in events timestamp reading Date: Thu, 25 Mar 2021 08:40:44 +0200 Message-Id: <20210325064055.539554-13-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 Thu Mar 25 06:40:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12163095 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 89E3EC433E5 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7760761A12 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229993AbhCYGli (ORCPT ); Thu, 25 Mar 2021 02:41:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230007AbhCYGlL (ORCPT ); Thu, 25 Mar 2021 02:41:11 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 599BBC06174A for ; Wed, 24 Mar 2021 23:41:11 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 12so511683wmf.5 for ; Wed, 24 Mar 2021 23:41:11 -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=qgQgasx3+yLGnWdgsbHSU8V/acy9bP5cJ3m/0xMfeprvU/3XNAzUT3jfq4T5KY9GnK RxiUbq47Bv372CagFxDKbQoZ7Du1p5OE2GwGIzCRFlSLVLFOuLZT6XiPxvqKNyWWb/PT ddLh0o7mHzKEph/dsr9mNZDeWJoD3TBEnthvj5aZix6A5iOr847BkR8s0hoU2JUi8+q9 MT9jt00BoO+O8rZk/3FUNYn5WxmUAgAAlD/h+HcP2gx9YzFaiFuoOEyOp/bR6NdYEuej 9n3ui0be5gI26XFa+7kEleyaEc0b0DvFZ42PCPu4hGdWYGNIrjFki91XddMDMWoXG1RB gLqQ== 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=jhHzyWHi1RIEbh+SWSFwJ/9YFCiKxU0XIy6eUFvmPcdL1gHW7Ep0DQRhsdgb3BbSmm dxi9DyOv0lkM30P0joL7DxQCOvYUfF/Dbdnx4u+o6Umt2DmCTDDW5PPP87ach5PBtp7q ey3oaTHfG77mhbLhCS9kcSxcqsGuS0/zNCjqFvLBf4/dpNx5Iow73d5yykcwS79Z9EYW 1Y4Y7WHe1Y/Ln46RMMPUNMrrojb8vJwsxQT2Z5WUF7NIUWaQNkABRx7O8ur1sRhroE1O lZWwX6XEncS3SKVdCm9+L1egjQZZlvI8yxR/wvmqBoJFMxy1Qn2MWDGbWU/5CgJ02Mf1 9tHQ== X-Gm-Message-State: AOAM531e941EutXdS9yVOkHSYqtsMQLn0MD+M/Yydl+/hbWz+HtSFGPl BjLpv8zNpkJ/+On3Y4q2X6A= X-Google-Smtp-Source: ABdhPJxDhl9Z5r27d54lZv3O1xIaHySSp1gGcILjyzsFpGEtC4Jbgx7jnUHyBd2isUClmHXW3XdulQ== X-Received: by 2002:a05:600c:252:: with SMTP id 18mr6058097wmj.67.1616654470150; Wed, 24 Mar 2021 23:41:10 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:09 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 13/23] trace-cmd: Perform all timestamp corrections in a single function Date: Thu, 25 Mar 2021 08:40:45 +0200 Message-Id: <20210325064055.539554-14-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 Thu Mar 25 06:40:46 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: 12163105 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 4ED7DC433F4 for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2946A61A21 for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230003AbhCYGlj (ORCPT ); Thu, 25 Mar 2021 02:41:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230008AbhCYGlM (ORCPT ); Thu, 25 Mar 2021 02:41:12 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BE73C06174A for ; Wed, 24 Mar 2021 23:41:12 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id v11so1096803wro.7 for ; Wed, 24 Mar 2021 23:41:12 -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=BbDExBI/aURsRLooEoItQSzTVlccqQHix6NIQKDxhEh/Z4U1oqDmsNwhvyCO5rYk/A osa2Kf3dbEshHTwZCpAsoyHh223EXBlprcuuxiAN9eOFWzf6k0w+XqRrz/+GSEg0qjs6 4RkCUzuQUeWBxIvQhs8ME/b40t5b8b+oLsbs976lzOI/WvuFX0h7MSph6Yafp23xu4VQ c2w+ih/eRM5IC2cv1DUOnjntnFJF8knd6tnPrnzO8ZNzG7oUygT+5IRg/IqZhu7GWZ0h slAUwo/yGxnIs0gyQVcIicpoftfvxupVv+W+YBRO40ZaNtcmWjqE2B6pn2DDGXihwULg ccTw== 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=jolE7790QdFoFjgmBxzfa8gzBwLTdNkaYTo+7ZiAeMJKakKOT+vLbUvwA8FPCpj3p3 tob8VxORJ8vjY/QV1QRqKCS3oo+cYuhrQQhlIkTAfMryvYFYSycuDppFU2q9ckI6KXMo 57PzL7n+WFvUalNto1juDTNMk3AhFBkBgo+UtlBRO9//EhULu1mCnNrsHCBctPYJqw9u 3ufT9tj/jvOpyFFLL3hjuNFbc+WbfPhvTCbh5m/6akYJnjzMGbVcceqT3ARLXTM7Iyx2 tlKm4JvDC9C1vausMX5Lj83FdG2EmMWOLlTGEDIKHQFcHzw6RrQSlurTIb1a5GJBKKoH Xdsw== X-Gm-Message-State: AOAM5333QJqg33Y8TVkzTQvTbN6FgRuVPIrjMLQSYMBryYxpv/nwCijl yDF5e3uAUXMKbk/GlP6r6lI= X-Google-Smtp-Source: ABdhPJwIaZSX2abtpOkDf8vUlNWAEHTYVe5XEqQfVuqzm7VfYz9NUmaPdGrb43WIK5OREHsj1sF62Q== X-Received: by 2002:a05:6000:181b:: with SMTP id m27mr7204916wrh.363.1616654470952; Wed, 24 Mar 2021 23:41:10 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:10 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 14/23] trace-cmd: Convert tsc timestamps to nanosecods when reading trace data from a file Date: Thu, 25 Mar 2021 08:40:46 +0200 Message-Id: <20210325064055.539554-15-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 Thu Mar 25 06:40:47 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: 12163101 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 25D46C433F2 for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1633A61A12 for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230006AbhCYGlj (ORCPT ); Thu, 25 Mar 2021 02:41:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230009AbhCYGlN (ORCPT ); Thu, 25 Mar 2021 02:41:13 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31D1CC06174A for ; Wed, 24 Mar 2021 23:41:13 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id e18so1103060wrt.6 for ; Wed, 24 Mar 2021 23:41:13 -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=Y7Y9cR9ikE45WYrgCBcAkPvQjVtBQog9dES8chXckiOOPSK5Y9Sfft2ZrQcZ1sKTWJ Pw7fyZKNH14wzB1jQEptn36SJas0inajqYO2pu3H5vxfgdmEthcMCYh9h5eRmtx/KFEc MgF7FjzTl7DVwgMGRDjHEkxuXv2jr2cGcE5spmVFLCXaOMOUs8ir+Lc4LPpDHyzegZij HnzPkMVqa5G0ojg5pdoq929GcijbShPJRfvj9XDlzxMmjfg27HuLN92ml3rrJCiMCVlF WF/fST1faf5sVIXTp01dA4KOASrkH+SUSSSp0iBpOu4MsxLyLSMHmAaw9BR8JNUa6Hs/ hpvg== 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=OfBhhx37L5F794YYBC8JHpk4yDjWlC/oHB1NbUAMhXHTVtgbonicVOdIL+655h2NCa 8ewuYbwI9YRN2WLmJxE64akk1bEE1LpR9bUBeCG0L+EhsyzvYnxkKFDWFq6+ei0LRj8q ta2807PdQXTZo5pgcpyezAro2i9cAwpzXGMzue0T0KL7LZk22Q0zzoB5J1YgxxtUjh9E FJyJLPPkuuchg5F2YRnDd86Vycwff5dn73KCEkugcpX9vlBip2cNiMA0LynWIk6qxjdZ 4Cha+YKaUxF422gjuVpkWWKDRe0pAlmX3B+1mea7gWJQJmMuHtL7YvDCgwY9+/bYKz2I M8Ng== X-Gm-Message-State: AOAM5305AUEJlsjE4SFEejfNpXvJxAdd2f0k6/VYKZwLhZct3FexA+LJ HlWBzAC4LXx6d/uXofDerN5XKNtxuSQYmA== X-Google-Smtp-Source: ABdhPJxePsU4gY3FREiDsij9KNDADY6mgEIqIcFAa62ezXOMY/YFDe1e+O0JD2697I8c7Dxv/5KQrA== X-Received: by 2002:a05:6000:1789:: with SMTP id e9mr7185428wrg.237.1616654471949; Wed, 24 Mar 2021 23:41:11 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:11 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 15/23] trace-cmd: Set order and priorities when applying timestamp corrections Date: Thu, 25 Mar 2021 08:40:47 +0200 Message-Id: <20210325064055.539554-16-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 Thu Mar 25 06:40:48 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: 12163099 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 049B4C433F1 for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E649961A13 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230008AbhCYGlj (ORCPT ); Thu, 25 Mar 2021 02:41:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230011AbhCYGlO (ORCPT ); Thu, 25 Mar 2021 02:41:14 -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 1BCF4C06174A for ; Wed, 24 Mar 2021 23:41:14 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id d191so526113wmd.2 for ; Wed, 24 Mar 2021 23:41:14 -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=RSmGXWfU+slAXusEwQl0TevAthvkl1itTESgTOaoVz8=; b=CiK4S/DO6RalkcAXaXMjqIl8w74ByjgZ7K15YvcviOnhc/pX3cM39x1IVL9NTGjANM ju4UY3ngBFocdmp0E15aEwoEaxYVsf4ITgVbQ+B10Vx5U03xLXRjYfbmuHr5zCyL1qOm JIGbtnqPZlVyp30jHNuzOjSWljPPCxdY9BrZYtpWW40AQprDThvid/LgD4dz/bNEo0ZI YYwnGHDhd+wvEomfzFWE5oXMyR+vsZEr8v7UmlKHcpCRwCTtdym/Bea7867VPO/Rw7Pc DsmfTo/Q9MzPd1ZZ7N7eUpI0WVoTBwZGQSLltFBexL2k9BrYAYxTRBIwMZ5iIk+1xTym tSRA== 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=RSmGXWfU+slAXusEwQl0TevAthvkl1itTESgTOaoVz8=; b=ErZ4qhiPvNWluQ6m9oDVf6rHazlEcnDmKWYYr3SSRqHJWquJvW8TAXWwkJ+EeaZ7rp pmtzvDif3ARU1WBUZWKcdMdcmOe0Tkt+Fi6m7Xz7dmdlHSOPh9SN1rE6AJqzEJ1U/K9N jyMbgHhGMJ4J3AarsGCQxNmkZ/W+geDbTTLh1nmvVIEfw7taAHSVGHctgQ+JGvmzAgIZ 9yHuCxrowaocLAf48amq1il4JeovP/zfMKVgYXWVDReS5dT8NWuITnVsSg237/Hmv+HN EnMRmvjG7NSdCue1IAnbW4Uuh2Et6fYmBjA4Nca8yac5LtrvjYTDBdeOiSJoIC6vS3f7 1LPw== X-Gm-Message-State: AOAM533ua6hZ9Sdo+wcOFa1ENMhdeGTheZMFSepa5+QmloOaCK+QJzyy OOyIFItrh3taIjKD/GpHCLo= X-Google-Smtp-Source: ABdhPJzkA2V4LAFZlYZqlCSwnsK/pZU1qppdj5M6MEsA+CjBNVMAFeiUpOGThyyP17FnSgo0Z8uwTw== X-Received: by 2002:a1c:a745:: with SMTP id q66mr6254698wme.21.1616654472837; Wed, 24 Mar 2021 23:41:12 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:12 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 16/23] trace-cmd: Add a new flag to disable any timestamp corrections Date: Thu, 25 Mar 2021 08:40:48 +0200 Message-Id: <20210325064055.539554-17-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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..ef2f9678 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 Thu Mar 25 06:40:49 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: 12163113 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 141EFC433ED for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 00E5461A10 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230007AbhCYGlj (ORCPT ); Thu, 25 Mar 2021 02:41:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230012AbhCYGlP (ORCPT ); Thu, 25 Mar 2021 02:41:15 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2109DC06174A for ; Wed, 24 Mar 2021 23:41:15 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id w203-20020a1c49d40000b029010c706d0642so3768282wma.0 for ; Wed, 24 Mar 2021 23:41:15 -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=hI0EV2GPDxR7VVKXt4QZMSRqrlxjlh1hduRz4xlbz8g=; b=cWmIBqtUD6np9ONFF2hgQEp8fYZQh7G1LM2jortfBmTn0ccWJveNyAi7I6bty7Gg0T OPfwKxmk4bh4NgXJDJqaM6RAqcA9B4/uK+qdCqkZ+XWSakHrl9geKhmCiyN1qE1bQmrn amVlrvKnEneRHrSDiBup5L3w+e2c2DY0bPujR8BPg2LsdUiubEOy/VvXC1hBLBI8pjGX 8TrMgB3WZGHls2+8wSpDHRcNaVkiGeYpZniJWl5PeElhb9qACFYgiJZhmaY7lK9dAW3B c/w8K1a7+YuCd7bW0vv5wFL336Uj+esZ5LI/0dtsercyqcIcV8Nfk8Dmvkpp0k+hvtJ9 eeAg== 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=hI0EV2GPDxR7VVKXt4QZMSRqrlxjlh1hduRz4xlbz8g=; b=D+Xor0qENslMtVR0P5TU4/vi8ZF7HRLwnwECEOFHtCpsRwyFEZxfoF/cC03AkQsWsK 7W8bWlQECqUsEN+NXIaxwS6RzQq08MRLNk8XQQFwRoxVAR6hYRnHQnz9Rx/9XQ5UgIYl /MXy6KYa7bZylcw1WNhCyowGGk0T3sHhnlMuoA0ZUQ8zQCrPMK4WYcZNba0iYmpzjUU9 QqLBSAxlFUcrwfwAR4DJbQMBHnxfaBwSTyCsNRKgNEBDjYClXOiEpK/+Xo9Bu5PZCvIz TWFU2sJtjl1rl9oQArZQP1dXlilJmo4Rs+0voXFgX5Z4ppyak2nz9Hx+LNZe/D/Zi+bZ S60w== X-Gm-Message-State: AOAM533Zyt1vYkqKLizSO1rIONZB+Jyb3r3AC5LQHYIIXsWzlrIABep2 TtiNJ7xrzgkxiv04WPtscJ8= X-Google-Smtp-Source: ABdhPJzYF9lpHdAduyhsaQVwaFV4P7BwvikSETi7nQo2lnln1LRV7z6UA6TIxzMfC+POYh52jFnUkQ== X-Received: by 2002:a1c:4b11:: with SMTP id y17mr6040333wma.171.1616654473890; Wed, 24 Mar 2021 23:41:13 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:13 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 17/23] trace-cmd: Change "--nodate" option to affect "--date" option only Date: Thu, 25 Mar 2021 08:40:49 +0200 Message-Id: <20210325064055.539554-18-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 ef2f9678..d9a2b6df 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 Thu Mar 25 06:40:50 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: 12163107 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 01057C433E9 for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4F2561A28 for ; Thu, 25 Mar 2021 06:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230011AbhCYGlj (ORCPT ); Thu, 25 Mar 2021 02:41:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230013AbhCYGlQ (ORCPT ); Thu, 25 Mar 2021 02:41:16 -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 F0612C06174A for ; Wed, 24 Mar 2021 23:41:15 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id d191so526135wmd.2 for ; Wed, 24 Mar 2021 23:41:15 -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=uREccLdW/J8Jqi6p5cDdjIJ4wcHvy833wlG3mk+0/HU=; b=UUBzMWwHvVPXEhrlzrGc6/DdWriZ1DGMvF4cGd48Q40sUDxUS8BPxyCSLOnRxOWwJd zWJMmk3bL2gxmSybSYk58ZoaiXbyLu1Qu7347eQIdbVzPvq5UbEsP7qIehi1cROK7x3m dPwy8GAvphk6Bnmovv1V0/a7SEtfj0tbpAz7wojibuwgxgPcm5K3vqH9Z3yfWSLt8DWp 093VkD+A3Zwoa7zXtBKUDB8YWdT7lCQ9tGI3/ZNMRY0ZJ3/5pwYvdJ3RtxbCzImFlcpX +WGUmppnb7Q8+fonjbnIDp1GrB/CO3jCxmNoie6PpmLpMZ1EN5p7EaHRZaIPYUcJPi9j loFg== 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=uREccLdW/J8Jqi6p5cDdjIJ4wcHvy833wlG3mk+0/HU=; b=Mh/rJHhlNEcfCkDdbnjUZBQOdl+XZx9SgPKHfKjY5uButEa56oiY20hholuBEJQgF0 h5SGJxw+kf5dgJori6ZuXz8jrIoJmz0dEkWpzhQw6elDV7ezY+EsnY7rti6kwNnBMeHA rRBUXo9m+rhkrJJfPrlLaeTGu3xS1tBxQd9YnGpuwCqnVvcdNmNJtfBYmD0jf4hQZVUf 7LfDm46Ff+Jf+U1Ke/3u2ySKiLZ0ZuRNUrgfXpxBFwObO0ZprHXg6xkcCM59ujCIA9Kc /cmdF5vIJidmVyWDsAq2sG7dUzn2hdc8ueTatEzDfc1QOwGwgw+psAncne8w6modrron NS9g== X-Gm-Message-State: AOAM5329XBIl9lxDNWg7YweVwTUl5Amw8kvdbQ0AL0xZoA9G1x5nLsv2 slZ7ps0txaXVZQytASHq8Kg= X-Google-Smtp-Source: ABdhPJwNOr4OfYcB3msA20YmlKkKvxvKeeYesEqIKifXlco539GcGBQ10c2Z5QZuhEAYtmv3z9nj4g== X-Received: by 2002:a1c:dd43:: with SMTP id u64mr6185252wmg.160.1616654474711; Wed, 24 Mar 2021 23:41:14 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:14 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 18/23] trace-cmd: Add new parameter "--raw-ts" to "trace-cmd report" command Date: Thu, 25 Mar 2021 08:40:50 +0200 Message-Id: <20210325064055.539554-19-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 d9a2b6df..513f6cc3 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 Thu Mar 25 06:40:51 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: 12163109 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 800F7C43445 for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 70E0A61A1F for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230012AbhCYGlk (ORCPT ); Thu, 25 Mar 2021 02:41:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230016AbhCYGlR (ORCPT ); Thu, 25 Mar 2021 02:41:17 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE3B6C06174A for ; Wed, 24 Mar 2021 23:41:16 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 12so511762wmf.5 for ; Wed, 24 Mar 2021 23:41:16 -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=kHjWAydcKu8G0F9+C84JyWVJgYi15YLDKcGQ3tSKtOg=; b=uBP0o5mLSyLH7vCkL4nEVU5+wxnJW1btRQMF1Nfa4JVd/K6bHPgtmtFpF9mBqCPKRI +7pfjWCpjiBzllMJ59DDmuE9yYdjbqNnb9uBxTgiBdCrQhv9VlEPHDkOk0hYPWmYbX3/ BbgIrnGeJAUnp9scByxwnN2cfwR4WbhJ15wto8L9e04c/PC3p2Qsh4mKm0ERCdE/Qv05 w6H70Xp2ur+POuIGhi4q3SNEeEpDW0LJcCMoCsIL0Qz6jsXhyChAlNU6QEswERJFyct9 GOgf5zVAqOPgxkGWPE7Ruv0RKIQ2p8d746aPpwHZUKUWAFXRBdqvBarHfaOI9VehBNBL /gkA== 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=kHjWAydcKu8G0F9+C84JyWVJgYi15YLDKcGQ3tSKtOg=; b=FsOfMIs2IBOtwgDQ6/m7Sbl1EHXUlKNBNR1JQHqYzmgpqhAx2+UsTar34NeZmbjkbg WArTWQ0QtIep5I5oOw6Njkcn3sZZdudCrRqJ8pasI8dwnGlL/Ctwai7bwq2doXwqn6BC 4pevV/P9TxSe7fq2G/CuoMWFmfZjLl6Jj+InrXlUEwdoSqn5njtcx+CTUKPYj4lRoMlH ggRxTraHFJHhbCl8m7bCYgjJa3/irjJ49CF4cOLOf5riLPRYfWpIAqCy1h1SmDFGd13T y1No59qeclBqgCmZaiKWGcEd+Yxe7x6Q8uAc60jY8JH5cgKgILAvWffzZvwGMrKWpVKy +2tg== X-Gm-Message-State: AOAM53026CybLawRihSANUVjY/4RaalYf+KGAk+4B+lA1cZilwWt3x/i Ghn8fRh0f4Z6q/Nrvi1ueW0= X-Google-Smtp-Source: ABdhPJxXT68He0kyTfzKiNxOaeBtK9hSJBLYOiasR2VpfZ2ejUffRD1ylKqtO7Pbz3eu52Qd4AaSmw== X-Received: by 2002:a1c:2155:: with SMTP id h82mr6351230wmh.169.1616654475651; Wed, 24 Mar 2021 23:41:15 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:15 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 19/23] trace-cmd: Print times in TimeShift options as unsigned in trace-cmd dump Date: Thu, 25 Mar 2021 08:40:51 +0200 Message-Id: <20210325064055.539554-20-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 24ec9695..b6ae5638 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; @@ -415,7 +415,7 @@ static void dump_option_timeshift(int fd, int size) read_file_number(fd, scalings + i, 8); for (i = 0; i < count; i++) - do_print(OPTIONS, "\t%lld * %lld %lld [offset * scaling @ time]\n", + do_print(OPTIONS, "\t%lld * %lld %llu [offset * scaling @ time]\n", offsets[i], scalings[1], times[i]); out: From patchwork Thu Mar 25 06:40:52 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: 12163123 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 79F18C433FC for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6069A61A28 for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230016AbhCYGlk (ORCPT ); Thu, 25 Mar 2021 02:41:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230018AbhCYGlS (ORCPT ); Thu, 25 Mar 2021 02:41:18 -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 C33DEC06174A for ; Wed, 24 Mar 2021 23:41:17 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id j18so1125532wra.2 for ; Wed, 24 Mar 2021 23:41:17 -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=nNSwgCWuMgOgj9roqKuvWrIb08sQVoQ8atUL8Pp8HDc=; b=TSNMacAN8ynwBgGKK2Er7DmzqnFBoCMA9M9BfiN52rYPa7zi20YgrPs/cRiCdIrin5 yfoUpjps6SAkinBfNBYxP+vVv6t6vPMsXXPqCwQ7SxoJJ07mNgMnFhtwLn2IEbJ8rqGy tGFKXiNu+IZfL1X0J4VHaUI2/H7ra39dfQ5zZIgn4MCxywfMJ1YFyhEkwyu3szXDbAgg MP9zVE/A1esHxKD65gW4d3S8DZ1h1wcHGvzExPGPU+SYV/wPM8kCBU+Srjk/BhP2hX8u 6QvJrRXjBmAHgoFjlquTdR71w9WgBjj+dGjCJrN95I/Vzpf88EKBjGw43vexLX8pvt0k fCAA== 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=nNSwgCWuMgOgj9roqKuvWrIb08sQVoQ8atUL8Pp8HDc=; b=fGMTVmR7NLXQc39YEMiazeBVpL7Pyjeyvl/OdJ81+wP65rRkRjOlqD5IrtesG8MgmI p8dKTHzdS6BaViwbDZ6qp40ZiuPujrbnXKQnrK/JPfCF+0Zw9N0ddW/9JScYO/Z1/vaK B8yEVjP7XsEx+yUIL3d5TmtFEJ1kIvtcFqD5eVYYiLoHYdlzJtiz3tF9li99btxQ/r/x HlBoWwinRxowVVLb1xjTYSwZNufIUSyXQ2iMfjbYx+OHjYAw/u1EsXWCD2KG9/ZMmoEO mzr+Ei2xcUw3c98CGXVmixR7n9zX9mBjVd7HoPbwi7YWpwi+KuUxMIxbrXT6rXO3KIQk 8iZw== X-Gm-Message-State: AOAM532xkA2Az4IgR/fGS2PxBBpHsojqaOkssCnVdV32g0GxPZ7DbsFH 6LzZPH/czJVjc8f4gWpc/Ao= X-Google-Smtp-Source: ABdhPJztsV6dGtRMY3yIEBcSMQke6fnijKyrITU2bdhiKKYmSGkg7Y1qiVynWTLEBEvKtExBUj5a5w== X-Received: by 2002:adf:edc3:: with SMTP id v3mr6870442wro.79.1616654476585; Wed, 24 Mar 2021 23:41:16 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:16 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 20/23] trace-cmd: Use tsc clock for host-guest tracing, if available Date: Thu, 25 Mar 2021 08:40:52 +0200 Message-Id: <20210325064055.539554-21-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 | 97 ++++++++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 30 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 4e4ad127..d794f1af 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; struct tsc_nsec tsc2nsec; int data_flags; + 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) @@ -5812,7 +5817,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; @@ -5947,6 +5951,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': @@ -6008,8 +6013,8 @@ static void parse_record_options(int argc, if (!ctx->instance->clock) die("Failed allocation"); 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; @@ -6253,8 +6258,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)) @@ -6288,26 +6292,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, @@ -6474,6 +6458,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. @@ -6503,6 +6537,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 Thu Mar 25 06:40:53 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: 12163117 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 7380EC433F8 for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5050461A27 for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230018AbhCYGlk (ORCPT ); Thu, 25 Mar 2021 02:41:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230022AbhCYGlT (ORCPT ); Thu, 25 Mar 2021 02:41:19 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A12E4C06174A for ; Wed, 24 Mar 2021 23:41:18 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id d191so526199wmd.2 for ; Wed, 24 Mar 2021 23:41:18 -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=xDsomzgCbP0yJx9Jw3t5GvX1UHU45XtloLwQV6bcNQs=; b=oq0mhN9Ciz5Xb0GvBoozEXLk4c7QkzZVOEw83cQdF5UHlD68YR1A/Wxe/CJq73qkb9 vQUijcDTLTLOZFs8ylej3wGeK/XxMkcXdnUDoS+jVXi6xr7j/ZP1AzXKbIvEBqqrrKer uwzjHsW8u3yxEcQUtq0V9uo1uRfxpxwFf2BOHlerpMKlAyONfPAhyG5QKl1Hma7Os4yE P29xKQx6lnvFRO9evSfizABH5CZ+uiYCgFRtpYdLPU1lZZcfv6Zws9E2FMFZLkAeDYgM ezoemEs55wPnxUuKy5R2xYLVjRnEvMEffegefHmyycGHizy0Fuj4lI2f+QpEJTsPK+ae Bk6g== 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=xDsomzgCbP0yJx9Jw3t5GvX1UHU45XtloLwQV6bcNQs=; b=BRFiYO8wCEwJc1+oB5BUwYjgm+u1dAPcAKUBPj/y8IkL6ZSrm79nKQeTNf7nveTNo5 x3/gLqo2sCUg/Ypo/faMOxX6lf7rL7cGjH+YA9xfUs7MSA7lb0SlgJSWOwkgPQ0KHn1/ lptjKWVxalqaqrZmZmNej3tBAuJ2xGMV9V/b8lDhw6i3a3Wd4BsipsUqvWDCF5er9FXi DYjsmb11oAjHAdDulq1+7gRk5PrVXvp+PtIjAKlNajsUV1U9bjqEioLycopCG9h/BJfd ZtEXXPeDsWR10f54qj6y9snxlIgUt+oVi4mE7mQX6nUiHKnbWQT1MqhkI9jyh7nBF83c NOig== X-Gm-Message-State: AOAM532hZoIbIqggEXA20WeyMuJN1c+mR2vuse9eeW3EqFxGAuqJ2zl5 0ZUabTp7pc7qFdkFgVuHt7367ap9OfcBUw== X-Google-Smtp-Source: ABdhPJwMKjaw3Mpqd1RYYsOBiS3+RpCJ1dykk1H1hJVRwp/FR99pqLGcllt9lpsO+fRvde9IhBBvLQ== X-Received: by 2002:a7b:cb89:: with SMTP id m9mr6253233wmi.27.1616654477436; Wed, 24 Mar 2021 23:41:17 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:17 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 21/23] trace-cmd: Get current clock for host-guest tracing session Date: Thu, 25 Mar 2021 08:40:53 +0200 Message-Id: <20210325064055.539554-22-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 "trace_clock" file of the first host trace instance, used in the tracing session. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-record.c | 49 ++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index d794f1af..4f412e8d 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -4128,6 +4128,23 @@ static void print_stat(struct buffer_instance *instance) trace_seq_do_printf(&instance->s_print[cpu]); } +static char *get_trace_clock(bool selected) +{ + struct buffer_instance *instance; + + for_all_instances(instance) { + if (is_guest(instance)) + continue; + break; + } + + if (selected) + return tracefs_get_clock(instance ? instance->tracefs : NULL); + else + return tracefs_instance_file_read(instance ? instance->tracefs : NULL, + "trace_clock", NULL); +} + enum { DATA_FL_NONE = 0, DATA_FL_DATE = 1, @@ -6460,11 +6477,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 && @@ -6473,18 +6491,27 @@ 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 { /* Use the current clock of the first host instance */ + clock = get_trace_clock(true); + } + } 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 */ @@ -6506,6 +6533,8 @@ static void set_tsync_params(struct common_record_context *ctx) } instance->tsync_loop_interval = ctx->tsync_loop_interval; } +out: + free(clock); } /* From patchwork Thu Mar 25 06:40:54 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: 12163111 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 9007DC43381 for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F7D561A10 for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230026AbhCYGll (ORCPT ); Thu, 25 Mar 2021 02:41:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230023AbhCYGlU (ORCPT ); Thu, 25 Mar 2021 02:41:20 -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 86D9CC06174A for ; Wed, 24 Mar 2021 23:41:19 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id z6-20020a1c4c060000b029010f13694ba2so502592wmf.5 for ; Wed, 24 Mar 2021 23:41:19 -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=whyMnEDznYysm82m8ir4n1/f3ymUXiDPfvuizjj6J5M=; b=L5zWUy/8nY8fq8B8uhVZENNCz1EA6e4VBclhMEIFcPzB5uwE4KkMJDa69okegsvWTN JZ3HcjqiWSp7NOMOq+TKZGzJjWYSrNvsnUyZhc54pE/p2SCGO8kgA0FhcD7HuAgqS09A S0hMO37rlE1r2WgPTkV2gVS85WvMLaVmdHs7E0c0hU6ArogTTohiBdwZz6DVEmBOKByG XTj1/MSPqbNjTopVo1pHAptnK9tIMwSAfFPIY4HaBPkzG/DmN9mZMFEH4k1yT3eetDta DzsrzHplzHheqZvFfj/nUcL+puGh+m8Htb5K/F0yScj6IraltJSm1ZnDf+PcCB+wDctD u4qw== 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=whyMnEDznYysm82m8ir4n1/f3ymUXiDPfvuizjj6J5M=; b=gUrvTjd+bKB3aLIh8ly5rJ+ZbsyCcJkWxrIjXDW/ATAcO1kNI8fiNWWnyWX5WvLo6D 9KQ0NcsN/miywFLWjKPPbXOjIoLBYWHirtBq/kC4fgcOZNChjqw4zG0xm2xJY1mj9QUO OGz+8SQXSftx7qPpuVPQTne2+E+W206SHB0LKp3pT1W2MK7WMJ3w8t5bxl3h5Lzsttsn QAiWaKkcQfmw3xw7cdeVAs8pCtNIJuKhWlPSDoWtrB2fAAeLQZKL5iYjOV+A1LqCVO6T s8RU9o9kXsLwIxy3/z2dye1Hh927kqDjmHxDJPckhDNle7DwzLejn9+HADql3zLut5Bm SfrA== X-Gm-Message-State: AOAM532SFN0NPvLx0Qw5sD4MXA5/fUuEY4TMWk0VuNiqQkXEzhwAjP14 mGYE6MSxJEkzMdZlf0f3pHA= X-Google-Smtp-Source: ABdhPJz/G34xyqLoOPyZnDD5zViTfCOzDP3wYABMXuoGKstYowdqr+ZFOian3kgv5gqYhzjLNrPkXg== X-Received: by 2002:a7b:ce19:: with SMTP id m25mr6295821wmc.74.1616654478334; Wed, 24 Mar 2021 23:41:18 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:17 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 22/23] trace-cmd: Save the trace clocks in TRACECLOCK option Date: Thu, 25 Mar 2021 08:40:54 +0200 Message-Id: <20210325064055.539554-23-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 4f412e8d..946bcb4d 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -4155,6 +4155,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) @@ -4166,12 +4167,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 = get_trace_clock(false); + 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 Thu Mar 25 06:40:55 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: 12163121 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 9B885C433C1 for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DED961A13 for ; Thu, 25 Mar 2021 06:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230022AbhCYGlk (ORCPT ); Thu, 25 Mar 2021 02:41:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230026AbhCYGlU (ORCPT ); Thu, 25 Mar 2021 02:41:20 -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 63B69C06175F for ; Wed, 24 Mar 2021 23:41:20 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id c8so1078669wrq.11 for ; Wed, 24 Mar 2021 23:41:20 -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=A4LvwnxyzRE/EtAFtpTGnD7SDW9+pNTORWFgylvctSQ=; b=GlDFFaFSRQ1NgoA2pG4JU38rhkFB8rILYihmfE4JIF93r75iLbQfGSG6bTsBa8d8zP jBonS2ptUyfKefpKokVAw9nkocBLAatRL7FpYaIcYMj4WHHMZLL73dK+pDQq7o2XBCXv tWpYGO2hdEcoC9jGxiOQ4xznmMVif0oKUdZvYEH3lyZvpKqLRakfbQXbiCtnRpK+zkJZ kJtWSp1KFJWzlUjyDojIiDIQJ2axBLvBlTEKla1F87B4aWB0lrUH3ToHiOn69qT8N5mn 0+DEoJ6S1H0LsgA8GBtclYkOZOV1jbd9xWz+V52HW2IEZ+QccvOJXJxUz0bp98kvyZb2 7YRg== 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=A4LvwnxyzRE/EtAFtpTGnD7SDW9+pNTORWFgylvctSQ=; b=SSyym+QxLEqHS/akXEm1FXTr7SKPu5enu2+M3FanQSuRiUVfjOIGotadR8bnktahqx Lzv+PM4DfL5T/W4lJUvT5ipX/ba+jYtg85PRNxII6lJGbc2u6mQ5F9gUfSU3frzCrWP4 gEsoDaBkNSDM+cwEJviLt/7nBGyLF8WfjHryTxdMLF3Kwz1qb/NWDZi/nC3XqNX2vBMl PNi+I13YI8JH2JgBYxMNLBeeui1+Br4qTrrXXR7iTN6oiOMTwHbiOuZ8RrF7orLiWyUK syCS4LyrH2VG4YGFYHek5gF5HrRmfoDGIJSrQmPErmG5GqVGCobkuwcSeGr0G15FCdZk KRkA== X-Gm-Message-State: AOAM532/3vaKnJ/LdMMpX0on98y8R+IA6OP9SmW9ORUIh/8ZYwndoM+9 NPhZF4+3aTSWLnMUN9kDd/JGvRaq4bxuxQ== X-Google-Smtp-Source: ABdhPJxdmanJyUKyPGqtFNQvUhMXgmj9bDZZ6svavawghkZPzRqskEYBL6PO1gjMloGOaXxKqAHuPA== X-Received: by 2002:adf:dc4e:: with SMTP id m14mr7353862wrj.248.1616654479172; Wed, 24 Mar 2021 23:41:19 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e17sm6403259wra.65.2021.03.24.23.41.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 23:41:18 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 23/23] trace-cmd: Read at least 8 bytes trace-id option Date: Thu, 25 Mar 2021 08:40:55 +0200 Message-Id: <20210325064055.539554-24-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325064055.539554-1-tz.stoyanov@gmail.com> References: <20210325064055.539554-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 513f6cc3..c0b47345 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);