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);