From mboxrd@z Thu Jan 1 00:00:00 1970 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 0A3B3C433F5 for ; Wed, 9 Feb 2022 08:52:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236821AbiBIIww (ORCPT ); Wed, 9 Feb 2022 03:52:52 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:42576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236979AbiBIIwk (ORCPT ); Wed, 9 Feb 2022 03:52:40 -0500 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AD80C02B647; Wed, 9 Feb 2022 00:52:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644396755; x=1675932755; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=N2F7TIMJv5p51QRiR0PjjnEjpwG2HqCv0tEcgH5DpDc=; b=XmQZnbI9NCnkero63LeDNizVfBy+u4vP/Cs2j3IAWhrzuxDf9tKoVW6l F6qBPBtkx/ypZAk6y85orFrBZyP0Nm5VdsyouB0iyEYVZAm4wj5Nv0Diq v6jpuRy2QoLPWnM+VGjEBdjSWg6x7LApS50caYUc8xCc5UDLwmyGeVAeI mr7rw3l7RCZZfqjm2yqKxRDdIHhQ1b9PJBKLSS59zaNzrdLMa6AsrQ0+z yy90tlsxeewCqFXVyRvhhWvgPHaEGpJu1y8EJ1BNBPJEJTiA4l27Bmtyr e7INHxXzmc7XWMlisTvxgGib15KEtFwxdsK0Ii4HYiOl476mzWwdeyhNW g==; X-IronPort-AV: E=McAfee;i="6200,9189,10252"; a="309903005" X-IronPort-AV: E=Sophos;i="5.88,355,1635231600"; d="scan'208";a="309903005" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2022 00:50:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,355,1635231600"; d="scan'208";a="568169270" Received: from ahunter-desktop.fi.intel.com ([10.237.72.92]) by orsmga001.jf.intel.com with ESMTP; 09 Feb 2022 00:49:56 -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 06/11] perf tools: Add new clock IDs to "perf time to TSC" test Date: Wed, 9 Feb 2022 10:49:24 +0200 Message-Id: <20220209084929.54331-7-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220209084929.54331-1-adrian.hunter@intel.com> References: <20220209084929.54331-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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The same "Convert perf time to TSC" test can be used with new clock IDs CLOCK_PERF_HW_CLOCK and CLOCK_PERF_HW_CLOCK_NS. Signed-off-by: Adrian Hunter --- tools/perf/tests/perf-time-to-tsc.c | 41 ++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/tools/perf/tests/perf-time-to-tsc.c b/tools/perf/tests/perf-time-to-tsc.c index d12d0ad81801..1044bc4acacb 100644 --- a/tools/perf/tests/perf-time-to-tsc.c +++ b/tools/perf/tests/perf-time-to-tsc.c @@ -22,6 +22,7 @@ #include "tests.h" #include "pmu.h" #include "pmu-hybrid.h" +#include "perf_api_probe.h" /* * Except x86_64/i386 and Arm64, other archs don't support TSC in perf. Just @@ -47,15 +48,7 @@ } \ } -/** - * test__perf_time_to_tsc - test converting perf time to TSC. - * - * This function implements a test that checks that the conversion of perf time - * to and from TSC is consistent with the order of events. If the test passes - * %0 is returned, otherwise %-1 is returned. If TSC conversion is not - * supported then then the test passes but " (not supported)" is printed. - */ -static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int subtest __maybe_unused) +static int perf_time_to_tsc_test(bool use_clockid, s32 clockid) { struct record_opts opts = { .mmap_pages = UINT_MAX, @@ -104,6 +97,8 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su evsel->core.attr.comm = 1; evsel->core.attr.disabled = 1; evsel->core.attr.enable_on_exec = 0; + evsel->core.attr.use_clockid = use_clockid; + evsel->core.attr.clockid = clockid; /* * For hybrid "cycles:u", it creates two events. @@ -200,4 +195,32 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su return err; } +/** + * test__perf_time_to_tsc - test converting perf time to TSC. + * + * This function implements a test that checks that the conversion of perf time + * to and from TSC is consistent with the order of events. If the test passes + * %0 is returned, otherwise %-1 is returned. If TSC conversion is not + * supported then the test passes but " (not supported)" is printed. + */ +static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, + int subtest __maybe_unused) +{ + int err; + + err = perf_time_to_tsc_test(false, 0); + + if (!err && perf_can_perf_clock_hw_clock()) { + pr_debug("Testing CLOCK_PERF_HW_CLOCK\n"); + err = perf_time_to_tsc_test(true, CLOCK_PERF_HW_CLOCK); + } + + if (!err && perf_can_perf_clock_hw_clock_ns()) { + pr_debug("Testing CLOCK_PERF_HW_CLOCK_NS\n"); + err = perf_time_to_tsc_test(true, CLOCK_PERF_HW_CLOCK_NS); + } + + return err; +} + DEFINE_SUITE("Convert perf time to TSC", perf_time_to_tsc); -- 2.25.1