From patchwork Mon Mar 7 08:53:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12771381 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B93C7C433FE for ; Mon, 7 Mar 2022 08:54:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236263AbiCGIy7 (ORCPT ); Mon, 7 Mar 2022 03:54:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236269AbiCGIyw (ORCPT ); Mon, 7 Mar 2022 03:54:52 -0500 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A23D31C124; Mon, 7 Mar 2022 00:53:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646643231; x=1678179231; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QpI2V/hfnUcmU3OAA7yk9HZ/2w/XcuWAii0cTKvKcMc=; b=hljjfpqwH0TXveHzyK4PxkZKkGCoc8Vlz0yWGJOMIejshRSqL2KpV/Cv 91cXrJRqjaTaXrgi3ClxTss2U2FCznkCnixXvOYTzCgbscr/y9mFclZYN 6Z8rJMbyWB4ZUwZWpRmOYrSodhW99u9QMnbVvSbo6cwjSbqR3CRRLgdCe yWw3TMS02Ej8JLTlDP4YEjIdFaQYPn2mCjpmYqTnLXHTCG2ClODPRZdcA 3+Yla5RwHvu6gYdG/k/bvnK/WhjOgcMOyFcPdumDBvTdZBBFQFJg3pgmY xyevB7R/b3sRtjIgMFeqfo2Gm3EuAY+BVPGOXvHc7+xNzhEcrO2dh12o0 A==; X-IronPort-AV: E=McAfee;i="6200,9189,10278"; a="241771870" X-IronPort-AV: E=Sophos;i="5.90,161,1643702400"; d="scan'208";a="241771870" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2022 00:53:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,161,1643702400"; d="scan'208";a="537033604" Received: from ahunter-desktop.fi.intel.com ([10.237.72.92]) by orsmga007.jf.intel.com with ESMTP; 07 Mar 2022 00:53:46 -0800 From: Adrian Hunter To: Peter Zijlstra Cc: Alexander Shishkin , Arnaldo Carvalho de Melo , Jiri Olsa , linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, kvm@vger.kernel.org, H Peter Anvin , Mathieu Poirier , Suzuki K Poulose , Leo Yan Subject: [PATCH V3 08/10] perf intel-pt: Add support for new clock IDs Date: Mon, 7 Mar 2022 10:53:10 +0200 Message-Id: <20220307085312.1814506-9-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307085312.1814506-1-adrian.hunter@intel.com> References: <20220307085312.1814506-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add support for new clock IDs CLOCK_PERF_HW_CLOCK and CLOCK_PERF_HW_CLOCK_NS. Mainly this means also keeping TSC conversion information for CLOCK_PERF_HW_CLOCK_NS when CLOCK_PERF_HW_CLOCK is being used, so that conversions from nanoseconds can still be done when the perf event clock is TSC. Signed-off-by: Adrian Hunter --- tools/perf/arch/x86/util/intel-pt.c | 37 ++++++++++++++++++++++++++--- tools/perf/util/intel-pt.c | 24 +++++++++++++++---- tools/perf/util/intel-pt.h | 2 +- 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c index 8c31578d6f4a..5bc05b8dd7f0 100644 --- a/tools/perf/arch/x86/util/intel-pt.c +++ b/tools/perf/arch/x86/util/intel-pt.c @@ -31,6 +31,7 @@ #include "../../../util/tsc.h" #include // page_size #include "../../../util/intel-pt.h" +#include "../../../util/clockid.h" #define KiB(x) ((x) * 1024) #define MiB(x) ((x) * 1024 * 1024) @@ -290,6 +291,20 @@ static const char *intel_pt_find_filter(struct evlist *evlist, return NULL; } +static bool intel_pt_clockid(struct evlist *evlist, struct perf_pmu *intel_pt_pmu, s32 clockid) +{ + struct evsel *evsel; + + evlist__for_each_entry(evlist, evsel) { + if (evsel->core.attr.type == intel_pt_pmu->type && + evsel->core.attr.use_clockid && + evsel->core.attr.clockid == clockid) + return true; + } + + return false; +} + static size_t intel_pt_filter_bytes(const char *filter) { size_t len = filter ? strlen(filter) : 0; @@ -304,9 +319,11 @@ intel_pt_info_priv_size(struct auxtrace_record *itr, struct evlist *evlist) container_of(itr, struct intel_pt_recording, itr); const char *filter = intel_pt_find_filter(evlist, ptr->intel_pt_pmu); - ptr->priv_size = (INTEL_PT_AUXTRACE_PRIV_MAX * sizeof(u64)) + + ptr->priv_size = (INTEL_PT_AUXTRACE_PRIV_FIXED * sizeof(u64)) + intel_pt_filter_bytes(filter); ptr->priv_size += sizeof(u64); /* Cap Event Trace */ + ptr->priv_size += sizeof(u64); /* ns Time Shift */ + ptr->priv_size += sizeof(u64); /* ns Time Multiplier */ return ptr->priv_size; } @@ -414,6 +431,18 @@ static int intel_pt_info_fill(struct auxtrace_record *itr, *info++ = event_trace; + if (intel_pt_clockid(session->evlist, ptr->intel_pt_pmu, CLOCK_PERF_HW_CLOCK)) { + struct perf_tsc_conversion ns_tc; + + if (perf_read_tsc_conv_for_clockid(CLOCK_PERF_HW_CLOCK_NS, &ns_tc)) + return -EINVAL; + *info++ = ns_tc.time_shift; + *info++ = ns_tc.time_mult; + } else { + *info++ = tc.time_shift; + *info++ = tc.time_mult; + } + return 0; } @@ -664,8 +693,10 @@ static int intel_pt_recording_options(struct auxtrace_record *itr, return -EINVAL; } - if (opts->use_clockid) { - pr_err("Cannot use clockid (-k option) with " INTEL_PT_PMU_NAME "\n"); + if (opts->use_clockid && opts->clockid != CLOCK_PERF_HW_CLOCK_NS && + opts->clockid != CLOCK_PERF_HW_CLOCK) { + pr_err("Cannot use clockid (-k option) with " INTEL_PT_PMU_NAME + " except CLOCK_PERF_HW_CLOCK_NS and CLOCK_PERF_HW_CLOCK\n"); return -EINVAL; } diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index ec43d364d0de..677ad0774464 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -89,6 +89,8 @@ struct intel_pt { struct perf_tsc_conversion tc; bool cap_user_time_zero; + u16 ns_time_shift; + u32 ns_time_mult; struct itrace_synth_opts synth_opts; @@ -1100,10 +1102,10 @@ static u64 intel_pt_ns_to_ticks(const struct intel_pt *pt, u64 ns) { u64 quot, rem; - quot = ns / pt->tc.time_mult; - rem = ns % pt->tc.time_mult; - return (quot << pt->tc.time_shift) + (rem << pt->tc.time_shift) / - pt->tc.time_mult; + quot = ns / pt->ns_time_mult; + rem = ns % pt->ns_time_mult; + return (quot << pt->ns_time_shift) + (rem << pt->ns_time_shift) / + pt->ns_time_mult; } static struct ip_callchain *intel_pt_alloc_chain(struct intel_pt *pt) @@ -3987,6 +3989,20 @@ int intel_pt_process_auxtrace_info(union perf_event *event, pt->cap_event_trace); } + if ((void *)info < info_end) { + pt->ns_time_shift = *info++; + pt->ns_time_mult = *info++; + if (dump_trace) { + fprintf(stdout, " ns Time Shift %d\n", pt->ns_time_shift); + fprintf(stdout, " ns Time Multiplier %d\n", pt->ns_time_mult); + } + } else { + pt->ns_time_shift = pt->tc.time_shift; + pt->ns_time_mult = pt->tc.time_mult; + } + if (!pt->ns_time_mult) + pt->ns_time_mult = 1; + pt->timeless_decoding = intel_pt_timeless_decoding(pt); if (pt->timeless_decoding && !pt->tc.time_mult) pt->tc.time_mult = 1; diff --git a/tools/perf/util/intel-pt.h b/tools/perf/util/intel-pt.h index c7d6068e3a6b..a2c4474641c0 100644 --- a/tools/perf/util/intel-pt.h +++ b/tools/perf/util/intel-pt.h @@ -27,7 +27,7 @@ enum { INTEL_PT_CYC_BIT, INTEL_PT_MAX_NONTURBO_RATIO, INTEL_PT_FILTER_STR_LEN, - INTEL_PT_AUXTRACE_PRIV_MAX, + INTEL_PT_AUXTRACE_PRIV_FIXED, }; struct auxtrace_record;