From nobody Sat Apr 18 04:20:20 2026 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 B0056C433EF for ; Mon, 18 Jul 2022 16:43:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235667AbiGRQn0 (ORCPT ); Mon, 18 Jul 2022 12:43:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235619AbiGRQnW (ORCPT ); Mon, 18 Jul 2022 12:43:22 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91E992983B for ; Mon, 18 Jul 2022 09:43:20 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id r16-20020a257610000000b0066f5239588eso9063274ybc.12 for ; Mon, 18 Jul 2022 09:43:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ZrBjT07dxIxrj4xoTKfpB0Ct6tpCXJxcmpau/yJexmM=; b=S6zHrx6t+ZkJpKmrvIJhWRpogS8H62QCsoKZ0hAUqXZsejr12rXHvEF1MonOtNg8VC Vjo81NGOQPl5UQSDtPau54CUtopvPA2WDke1UO3K3zjA+R3oiVONmJO77SPJNmip/crl sfbd+eYL6KQqY2xPNJUvSFGYIHT+Kc/QHSEeGJ8hnR65spWMpga/l+fJdbdTlFfCoMhd 9OqXE3Aedb6LxuGLGE5dtLGIctTSDw6hRKgNSbCCcPrXfh+2MFrTTNNZtOB0ixUK7NGm i8nTnKx819GhPtgxxW9GIrV2WGahtpGnOIbpPmaqajif6VFVxbqp785k9+4HvmxMps+K ATFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ZrBjT07dxIxrj4xoTKfpB0Ct6tpCXJxcmpau/yJexmM=; b=34sxketUUqQiTvFdUJXubJAQSaJmeg+90eKFQR32CU4D8ayUTzyoneNkwjLrJRhNxk cdDUNUP0D6aqyyUS+6R8vEqZgqxbramnOE4rV3sVNS32tB1mplury5vWTew7liZfWHLz xrmN2DDxtP47rGyykCi57Vuj0m+3Q6rirInNleIauXtFtN8my7CwS7P2E6uFi8gYkNv3 ITWqwiMc08HRsG4v6cPobb7AUB5utg8YwuRy5tg4nF3yfMHmRD84I0MZH7YLMJwj/9PF Gp/zWl7nKRCbgkUftYChgc045Bt1WpmP+NCJ1GIGobA7Y3EBE6DinqEgdDMfAFVtd9nm 5LAg== X-Gm-Message-State: AJIora8xnSoqVvVRq0p85zcqefn0c3SUSBxA5cGJX66x6fgDPcX4BYO0 1g+R0U3HbzH/v4tbNFjA5ip3j4L9gWpE X-Google-Smtp-Source: AGRyM1uxrBpupOE8dccxuc9QlExJA45WmzxrSVukJNRZwiiOaKgZ7ZscrIWsx4Gf/Z+6d5SxcWfQDnTvDe1o X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:922:90e9:167f:1ccd]) (user=irogers job=sendgmr) by 2002:a05:6902:4d0:b0:66e:4fef:cc3f with SMTP id v16-20020a05690204d000b0066e4fefcc3fmr26060990ybs.20.1658162599830; Mon, 18 Jul 2022 09:43:19 -0700 (PDT) Date: Mon, 18 Jul 2022 09:43:10 -0700 In-Reply-To: <20220718164312.3994191-1-irogers@google.com> Message-Id: <20220718164312.3994191-2-irogers@google.com> Mime-Version: 1.0 References: <20220718164312.3994191-1-irogers@google.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog Subject: [PATCH v4 1/3] perf tsc: Add arch TSC frequency information From: Ian Rogers To: perry.taylor@intel.com, caleb.biggers@intel.com, kshipra.bopardikar@intel.com, Kan Liang , Zhengjun Xing , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Maxime Coquelin , Alexandre Torgue , Andi Kleen , James Clark , John Garry , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kan Liang The TSC frequency information is required for the event metrics with the literal, system_tsc_freq. For the newer Intel platform, the TSC frequency information can be retrieved from the CPUID leaf 0x15. If the TSC frequency information isn't present the /proc/cpuinfo approach is used. Refactor cpuid for this use. Note, the previous stack pushing/popping approach was broken on x86-64 that has stack red zones that would be clobbered. Signed-off-by: Kan Liang Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/arch/x86/util/cpuid.h | 34 +++++++++++++++++++++++++++++++ tools/perf/arch/x86/util/header.c | 27 ++++++++++-------------- tools/perf/arch/x86/util/tsc.c | 33 ++++++++++++++++++++++++++++++ tools/perf/util/expr.c | 13 ++++++++++++ tools/perf/util/tsc.h | 1 + 5 files changed, 92 insertions(+), 16 deletions(-) create mode 100644 tools/perf/arch/x86/util/cpuid.h diff --git a/tools/perf/arch/x86/util/cpuid.h b/tools/perf/arch/x86/util/cp= uid.h new file mode 100644 index 000000000000..0a3ae0ace7e9 --- /dev/null +++ b/tools/perf/arch/x86/util/cpuid.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef PERF_CPUID_H +#define PERF_CPUID_H 1 + + +static inline void +cpuid(unsigned int op, unsigned int op2, unsigned int *a, unsigned int *b, + unsigned int *c, unsigned int *d) +{ + /* + * Preserve %ebx/%rbx register by either placing it in %rdi or saving it + * on the stack - x86-64 needs to avoid the stack red zone. In PIC + * compilations %ebx contains the address of the global offset + * table. %rbx is occasionally used to address stack variables in + * presence of dynamic allocas. + */ + asm( +#if defined(__x86_64__) + "mov %%rbx, %%rdi\n" + "cpuid\n" + "xchg %%rdi, %%rbx\n" +#else + "pushl %%ebx\n" + "cpuid\n" + "movl %%ebx, %%edi\n" + "popl %%ebx\n" +#endif + : "=3Da"(*a), "=3DD"(*b), "=3Dc"(*c), "=3Dd"(*d) + : "a"(op), "2"(op2)); +} + +void get_cpuid_0(char *vendor, unsigned int *lvl); + +#endif diff --git a/tools/perf/arch/x86/util/header.c b/tools/perf/arch/x86/util/h= eader.c index 578c8c568ffd..a51444a77a5f 100644 --- a/tools/perf/arch/x86/util/header.c +++ b/tools/perf/arch/x86/util/header.c @@ -9,18 +9,17 @@ =20 #include "../../../util/debug.h" #include "../../../util/header.h" +#include "cpuid.h" =20 -static inline void -cpuid(unsigned int op, unsigned int *a, unsigned int *b, unsigned int *c, - unsigned int *d) +void get_cpuid_0(char *vendor, unsigned int *lvl) { - __asm__ __volatile__ (".byte 0x53\n\tcpuid\n\t" - "movl %%ebx, %%esi\n\t.byte 0x5b" - : "=3Da" (*a), - "=3DS" (*b), - "=3Dc" (*c), - "=3Dd" (*d) - : "a" (op)); + unsigned int b, c, d; + + cpuid(0, 0, lvl, &b, &c, &d); + strncpy(&vendor[0], (char *)(&b), 4); + strncpy(&vendor[4], (char *)(&d), 4); + strncpy(&vendor[8], (char *)(&c), 4); + vendor[12] =3D '\0'; } =20 static int @@ -31,14 +30,10 @@ __get_cpuid(char *buffer, size_t sz, const char *fmt) int nb; char vendor[16]; =20 - cpuid(0, &lvl, &b, &c, &d); - strncpy(&vendor[0], (char *)(&b), 4); - strncpy(&vendor[4], (char *)(&d), 4); - strncpy(&vendor[8], (char *)(&c), 4); - vendor[12] =3D '\0'; + get_cpuid_0(vendor, &lvl); =20 if (lvl >=3D 1) { - cpuid(1, &a, &b, &c, &d); + cpuid(1, 0, &a, &b, &c, &d); =20 family =3D (a >> 8) & 0xf; /* bits 11 - 8 */ model =3D (a >> 4) & 0xf; /* Bits 7 - 4 */ diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c index 559365f8fe52..b69144f22489 100644 --- a/tools/perf/arch/x86/util/tsc.c +++ b/tools/perf/arch/x86/util/tsc.c @@ -1,7 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include =20 #include "../../../util/tsc.h" +#include "cpuid.h" =20 u64 rdtsc(void) { @@ -11,3 +13,34 @@ u64 rdtsc(void) =20 return low | ((u64)high) << 32; } + +double arch_get_tsc_freq(void) +{ + unsigned int a, b, c, d, lvl; + static bool cached; + static double tsc; + char vendor[16]; + + if (cached) + return tsc; + + cached =3D true; + get_cpuid_0(vendor, &lvl); + if (!strstr(vendor, "Intel")) + return 0; + + /* + * Don't support Time Stamp Counter and + * Nominal Core Crystal Clock Information Leaf. + */ + if (lvl < 0x15) + return 0; + + cpuid(0x15, 0, &a, &b, &c, &d); + /* TSC frequency is not enumerated */ + if (!a || !b || !c) + return 0; + + tsc =3D (double)c * (double)b / (double)a; + return tsc; +} diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c index 675f318ce7c1..c15a9852fa41 100644 --- a/tools/perf/util/expr.c +++ b/tools/perf/util/expr.c @@ -12,6 +12,7 @@ #include "expr-bison.h" #include "expr-flex.h" #include "smt.h" +#include "tsc.h" #include #include #include @@ -402,6 +403,13 @@ double expr_id_data__source_count(const struct expr_id= _data *data) return data->val.source_count; } =20 +#if !defined(__i386__) && !defined(__x86_64__) +double arch_get_tsc_freq(void) +{ + return 0.0; +} +#endif + double expr__get_literal(const char *literal) { static struct cpu_topology *topology; @@ -417,6 +425,11 @@ double expr__get_literal(const char *literal) goto out; } =20 + if (!strcasecmp("#system_tsc_freq", literal)) { + result =3D arch_get_tsc_freq(); + goto out; + } + /* * Assume that topology strings are consistent, such as CPUs "0-1" * wouldn't be listed as "0,1", and so after deduplication the number of diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h index 7d83a31732a7..88fd1c4c1cb8 100644 --- a/tools/perf/util/tsc.h +++ b/tools/perf/util/tsc.h @@ -25,6 +25,7 @@ int perf_read_tsc_conversion(const struct perf_event_mmap= _page *pc, u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc); u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc); u64 rdtsc(void); +double arch_get_tsc_freq(void); =20 size_t perf_event__fprintf_time_conv(union perf_event *event, FILE *fp); =20 --=20 2.37.0.170.g444d1eabd0-goog From nobody Sat Apr 18 04:20:20 2026 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 71FE8C43334 for ; Mon, 18 Jul 2022 16:43:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235760AbiGRQnb (ORCPT ); Mon, 18 Jul 2022 12:43:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235627AbiGRQnX (ORCPT ); Mon, 18 Jul 2022 12:43:23 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B99C9F5BA for ; Mon, 18 Jul 2022 09:43:22 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id r16-20020a257610000000b0066f5239588eso9063331ybc.12 for ; Mon, 18 Jul 2022 09:43:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=6ZhNslhhLNsgEg+FWq588BvRg4wz6Du1TOlV29T7frs=; b=AE1a2A8ktkCPoEaOl2Bjua2K9ctpZygOcIGgjIb7OmzO0HuCrX2VEssYRD0CzVzqeR Ghlv7ypWETR0HVub9zaNjlknRCHKRpKfsYR1BUSFSfqeQZXooaiVnhEhTJBpdQsg2Bxl U6GKtHZEJqRqnMJNabLeTsR/5QyZqCo6PKOaAWXBD5LXHAQGZPxkumXimRjuUvVNtP9N JezohPy9CWfP+fEHCTA8Pr62SmxfKloy1ghz2bLq3C0sAbTyeE+uaotJwS42xWh3rqiY zy/i+8uK7viWEa72tNyQra3m2thf0WpJQerzhr9FXsRjMXQYX84lYmXm/wtiQ4tAZpsw GdXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=6ZhNslhhLNsgEg+FWq588BvRg4wz6Du1TOlV29T7frs=; b=zXNUnaiS9n+D79q10EPjYtKGup4gnRWJgmjxWTvZwmwAUk/oobfKqAN4vlG5CR3KRs lFcOjd7bWz+hycGXTuOZUO+O4saCxKurWrNYPmiloli5Ra1P/lbWa0Fq0vn3OKsyHYTv faGFfYA5VIbVs3LtiXWTPbJd1n8/OhR7OJ45XDbbE/fKuHnkn1/YVssK2kW56YJ8x7AW rmBiYlkZfbMwtGPLuqahtnukpRYGyg7LcV/lJCLAAXoBNLgjqyW2YYm4yfJ9ULgk9xVA TZqwzeRqluLBtEP+w7BqUonr6drbQWicS2TAWHUZhW0UvBSdzuqmIls8v1ghYQ7tIPfb D4Ng== X-Gm-Message-State: AJIora+wlAxMz7I1vDcY7IAE8hcqjtl8VCt5FgByVAoSM1k0c3OXQLhD uAJ8mc3EnkbPPCviPiUvJe43ySvWUkIU X-Google-Smtp-Source: AGRyM1vo+bqIlRAK/lQLOqnS2Cls5RI2liOXTblRr6VUX+Jdqlp2anG254SCKfSoUx+7XbTL01bcVQGdocpW X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:922:90e9:167f:1ccd]) (user=irogers job=sendgmr) by 2002:a0d:e895:0:b0:31c:85a6:1444 with SMTP id r143-20020a0de895000000b0031c85a61444mr31886874ywe.493.1658162602493; Mon, 18 Jul 2022 09:43:22 -0700 (PDT) Date: Mon, 18 Jul 2022 09:43:11 -0700 In-Reply-To: <20220718164312.3994191-1-irogers@google.com> Message-Id: <20220718164312.3994191-3-irogers@google.com> Mime-Version: 1.0 References: <20220718164312.3994191-1-irogers@google.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog Subject: [PATCH v4 2/3] perf tsc: Add cpuinfo fall back for arch_get_tsc_freq From: Ian Rogers To: perry.taylor@intel.com, caleb.biggers@intel.com, kshipra.bopardikar@intel.com, Kan Liang , Zhengjun Xing , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Maxime Coquelin , Alexandre Torgue , Andi Kleen , James Clark , John Garry , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The CPUID method of arch_get_tsc_freq fails for older Intel processors, such as Skylake. Compute using /proc/cpuinfo. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/arch/x86/util/tsc.c | 52 +++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c index b69144f22489..eb2b5195bd02 100644 --- a/tools/perf/arch/x86/util/tsc.c +++ b/tools/perf/arch/x86/util/tsc.c @@ -1,7 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include =20 +#include "../../../util/debug.h" #include "../../../util/tsc.h" #include "cpuid.h" =20 @@ -14,6 +16,44 @@ u64 rdtsc(void) return low | ((u64)high) << 32; } =20 +/* + * Derive the TSC frequency in Hz from the /proc/cpuinfo, for example: + * ... + * model name : Intel(R) Xeon(R) Gold 6154 CPU @ 3.00GHz + * ... + * will return 3000000000. + */ +static double cpuinfo_tsc_freq(void) +{ + double result =3D 0; + FILE *cpuinfo; + char *line =3D NULL; + size_t len =3D 0; + + cpuinfo =3D fopen("/proc/cpuinfo", "r"); + if (!cpuinfo) { + pr_err("Failed to read /proc/cpuinfo for TSC frequency"); + return NAN; + } + while (getline(&line, &len, cpuinfo) > 0) { + if (!strncmp(line, "model name", 10)) { + char *pos =3D strstr(line + 11, " @ "); + + if (pos && sscanf(pos, " @ %lfGHz", &result) =3D=3D 1) { + result *=3D 1000000000; + goto out; + } + } + } +out: + if (fpclassify(result) =3D=3D FP_ZERO) + pr_err("Failed to find TSC frequency in /proc/cpuinfo"); + + free(line); + fclose(cpuinfo); + return result; +} + double arch_get_tsc_freq(void) { unsigned int a, b, c, d, lvl; @@ -33,13 +73,17 @@ double arch_get_tsc_freq(void) * Don't support Time Stamp Counter and * Nominal Core Crystal Clock Information Leaf. */ - if (lvl < 0x15) - return 0; + if (lvl < 0x15) { + tsc =3D cpuinfo_tsc_freq(); + return tsc; + } =20 cpuid(0x15, 0, &a, &b, &c, &d); /* TSC frequency is not enumerated */ - if (!a || !b || !c) - return 0; + if (!a || !b || !c) { + tsc =3D cpuinfo_tsc_freq(); + return tsc; + } =20 tsc =3D (double)c * (double)b / (double)a; return tsc; --=20 2.37.0.170.g444d1eabd0-goog From nobody Sat Apr 18 04:20:20 2026 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 CCB31C433EF for ; Mon, 18 Jul 2022 16:43:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235808AbiGRQng (ORCPT ); Mon, 18 Jul 2022 12:43:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235687AbiGRQn1 (ORCPT ); Mon, 18 Jul 2022 12:43:27 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1B5C2B1AC for ; Mon, 18 Jul 2022 09:43:25 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id v1-20020a259d81000000b0066ec7dff8feso9079616ybp.18 for ; Mon, 18 Jul 2022 09:43:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=MeQFhDWhw6uJhVAf4SRwsMvd39/eawx4leroeGONoc8=; b=odOfFuywMBJ86ClpGLOJnyTs1vkUPpoBT8uT+btgbpCrf06texWEMIb+CtOWroV+0W jyVmCoiMbUMEmOEpds+6GymsbBdkAoIc7IzGTr/dQQRUSNppsMn47MIJFXEzYGV3KyAj l8eghn2P4ZbzTQKxBavlZnwAQtb1jf+09PnQ8HgLzETmk3+PwvrQGshHwopIbQJZh/Af 1aV6H1eiwFxXulYwGJYQkcyO24NMMjsFQaTxgcCy70uCcQGLa1YFdb7TxEkRJeqiM/Pw xHq1F5Xd/KHxqxY5D+ywSeT/FVtNgJ39xHZjmMgsB8botISnbTGGfR8IwQJNMjIcB7wk veaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=MeQFhDWhw6uJhVAf4SRwsMvd39/eawx4leroeGONoc8=; b=SLtE2Yf6ZaMTnowzkN74sAcf+0GX1hOk7E+RKQ2F9OgeK9QEG0NEwqqyrO5KXCllnc Tl6gtIwWgalOZmmPR68/yoh3MaOnMDhOOWKq9xlFf2ETjV0rh/I+eu7imAnCZ5E80pRB 5bLnTGX8AuL8XAR6ti8/GlZqJWB60/RxE1Yw5FgGrz1HT67fLo88ylvoEUFvUcUBKXqQ TvgGTuL7umSAfsSBgLtKkOh4Hq/zD0DMD3sK2biL4+0R2mqUFc0yDiQQBYiGpdXJSz2L 19MYxjdCmm/SX/ksOuZrixCfQg1mJQW5GSaNK0od1wqmtKcPPcNFhHQZde8mrLvnhIFc XL1Q== X-Gm-Message-State: AJIora+4jUOco+5KPmd5+i1cbvtnTeXYbgpzlBxsS62gLX/O+IPRdz4l Ktdzzuz3txRjBPRUgKQkEQiWruMYYFPB X-Google-Smtp-Source: AGRyM1sCFaSaN+OYXwJis87SDXFstBd+j8/M7CzZr1dKfE5Bl/b3JDSsZHKBzslDVbqZbE4BRCTv1jxJVvaJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:922:90e9:167f:1ccd]) (user=irogers job=sendgmr) by 2002:a25:d00b:0:b0:66e:e393:aa68 with SMTP id h11-20020a25d00b000000b0066ee393aa68mr27218620ybg.65.1658162604988; Mon, 18 Jul 2022 09:43:24 -0700 (PDT) Date: Mon, 18 Jul 2022 09:43:12 -0700 In-Reply-To: <20220718164312.3994191-1-irogers@google.com> Message-Id: <20220718164312.3994191-4-irogers@google.com> Mime-Version: 1.0 References: <20220718164312.3994191-1-irogers@google.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog Subject: [PATCH v4 3/3] perf test: Add test for #system_tsc_freq in metrics From: Ian Rogers To: perry.taylor@intel.com, caleb.biggers@intel.com, kshipra.bopardikar@intel.com, Kan Liang , Zhengjun Xing , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Maxime Coquelin , Alexandre Torgue , Andi Kleen , James Clark , John Garry , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The value should be non-zero on Intel while zero on everything else. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/tests/expr.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c index 5c0032fe93ae..2efe9e3a63b8 100644 --- a/tools/perf/tests/expr.c +++ b/tools/perf/tests/expr.c @@ -1,8 +1,10 @@ // SPDX-License-Identifier: GPL-2.0 #include "util/debug.h" #include "util/expr.h" +#include "util/header.h" #include "util/smt.h" #include "tests.h" +#include #include #include #include @@ -69,6 +71,11 @@ static int test__expr(struct test_suite *t __maybe_unuse= d, int subtest __maybe_u double val, num_cpus, num_cores, num_dies, num_packages; int ret; struct expr_parse_ctx *ctx; + bool is_intel =3D false; + char buf[128]; + + if (!get_cpuid(buf, sizeof(buf))) + is_intel =3D strstr(buf, "Intel") !=3D NULL; =20 TEST_ASSERT_EQUAL("ids_union", test_ids_union(), 0); =20 @@ -175,6 +182,12 @@ static int test__expr(struct test_suite *t __maybe_unu= sed, int subtest __maybe_u if (num_dies) // Some platforms do not have CPU die support, for example = s390 TEST_ASSERT_VAL("#num_dies >=3D #num_packages", num_dies >=3D num_packag= es); =20 + TEST_ASSERT_VAL("#system_tsc_freq", expr__parse(&val, ctx, "#system_tsc_f= req") =3D=3D 0); + if (is_intel) + TEST_ASSERT_VAL("#system_tsc_freq > 0", val > 0); + else + TEST_ASSERT_VAL("#system_tsc_freq =3D=3D 0", fpclassify(val) =3D=3D FP_Z= ERO); + /* * Source count returns the number of events aggregating in a leader * event including the leader. Check parsing yields an id. --=20 2.37.0.170.g444d1eabd0-goog