Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp821904rdb; Sun, 20 Aug 2023 04:41:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCVvKXfXYFEl+p9MpKsdK/965DHW6fMGxFbox+TSBHNqDvCfVk2lzpivC8nF8ji2t1teiv X-Received: by 2002:a05:6a00:24d2:b0:687:5c3f:d834 with SMTP id d18-20020a056a0024d200b006875c3fd834mr6036948pfv.11.1692531683287; Sun, 20 Aug 2023 04:41:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692531683; cv=none; d=google.com; s=arc-20160816; b=g2p3Uh9oEaYg9fDSzQcGgicMishVeyG2+0wFq6Q8IL/fqsRi+s1+PygUrDi93Scvwy J+0PXKptbPD5gNJnp1POyG0qzOlZTsbjFuu5BkuF1t36nC8s55W/ubpxTQMV2/QRwNrw lgc8VCQj8/CLau8o8Ut34phZmEUKjLmIDDbVAKJMjEDTgm5T8lpcz3U9XcHDOpfyorni XMutXuCcAKN/8xgYihxjRb9RHkI1bYp9S5vgY3iHf3hdl6IaWRbqWy94u1v/g2b5lZlS e49QdvRUpIoF3yzPT0F3MyA4IBOUjDF5sLpaYVf36uvlp8LueJVG1dn+bAxubsov3wCv FpBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=H/9I4ECExHGIMvUzChhAly7ACMhvJxlwZ0Rv7wF62YA=; fh=XvqEulEdhZUpg3m4NWM4DmjybBTvE+66GxJg5iuyww8=; b=NwtAsNwRYGjY0mHH0sYka1y7tHA20xHNFdUSkEXxsD1Dhlhj0ypxl9/tK6nRyfUeKX s0KhtlHEI+6EX/tfS/XtPYyfPw4C68kCU5sG8SqZ9Ao7RDfMzXkPrsi8UWl2jyuPSsM1 h1ghzmoI4fzWTAh1BlbHbFlyTK1KCsSORgYxPH9VE7s6tqawZH+k1iRLxlfrFc4QTL5b N8amQ/cIHnlpYOTh0cSd4qHgX74hKWTiMpWjHOAEyRUrAV3Lw2z2iJhx9+GygPMYZKNk 2d3RUHFPTPPHpvjmMFk9CP+hLOhWsKpbjFEupZkh+MBLetjqDsROE/Jt9kuZaUEbwRx7 AHBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u3-20020a056a00158300b00682d2ab09dbsi5497604pfk.306.2023.08.20.04.41.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 04:41:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D3D1F307DAD; Sat, 19 Aug 2023 11:56:40 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244788AbjHPLud (ORCPT + 99 others); Wed, 16 Aug 2023 07:50:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244779AbjHPLuC (ORCPT ); Wed, 16 Aug 2023 07:50:02 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A5F96AB; Wed, 16 Aug 2023 04:50:00 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 91CD01063; Wed, 16 Aug 2023 04:50:41 -0700 (PDT) Received: from e127643.arm.com (unknown [10.57.4.137]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C85F43F64C; Wed, 16 Aug 2023 04:49:56 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, irogers@google.com, john.g.garry@oracle.com, renyu.zj@linux.alibaba.com, acme@kernel.org Cc: James Clark , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Haixin Yu , Nick Forrington , Kajol Jain , Andrii Nakryiko , Eduard Zingerman , Sohom Datta , Rob Herring , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v6 1/6] perf arm64: Allow version comparisons of CPU IDs Date: Wed, 16 Aug 2023 12:47:43 +0100 Message-Id: <20230816114841.1679234-2-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230816114841.1679234-1-james.clark@arm.com> References: <20230816114841.1679234-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently variant and revision fields are masked out of the MIDR so it's not possible to compare different versions of the same CPU. In a later commit a workaround will be removed just for N2 r0p3, so enable comparisons on version. This has the side effect of changing the MIDR stored in the header of the perf.data file to no longer have masked version fields. It also affects the lookups in mapfile.csv, but as that currently only has zeroed version fields, it has no actual effect. The mapfile.csv documentation also states to zero the version fields, so unless this isn't done it will continue to have no effect. There is an existing weak default strcmp_cpuid_str() function, and an x86 version. This adds another version for arm64. Signed-off-by: James Clark --- tools/perf/arch/arm64/util/header.c | 67 ++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/tools/perf/arch/arm64/util/header.c b/tools/perf/arch/arm64/util/header.c index 80b9f6287fe2..a2eef9ec5491 100644 --- a/tools/perf/arch/arm64/util/header.c +++ b/tools/perf/arch/arm64/util/header.c @@ -1,3 +1,6 @@ +#include +#include +#include #include #include #include @@ -10,15 +13,14 @@ #define MIDR "/regs/identification/midr_el1" #define MIDR_SIZE 19 -#define MIDR_REVISION_MASK 0xf -#define MIDR_VARIANT_SHIFT 20 -#define MIDR_VARIANT_MASK (0xf << MIDR_VARIANT_SHIFT) +#define MIDR_REVISION_MASK GENMASK(3, 0) +#define MIDR_VARIANT_MASK GENMASK(23, 20) static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus) { const char *sysfs = sysfs__mountpoint(); - u64 midr = 0; int cpu; + int ret = EINVAL; if (!sysfs || sz < MIDR_SIZE) return EINVAL; @@ -44,22 +46,13 @@ static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus) } fclose(file); - /* Ignore/clear Variant[23:20] and - * Revision[3:0] of MIDR - */ - midr = strtoul(buf, NULL, 16); - midr &= (~(MIDR_VARIANT_MASK | MIDR_REVISION_MASK)); - scnprintf(buf, MIDR_SIZE, "0x%016lx", midr); /* got midr break loop */ + ret = 0; break; } perf_cpu_map__put(cpus); - - if (!midr) - return EINVAL; - - return 0; + return ret; } int get_cpuid(char *buf, size_t sz) @@ -99,3 +92,47 @@ char *get_cpuid_str(struct perf_pmu *pmu) return buf; } + +/* + * Return 0 if idstr is a higher or equal to version of the same part as + * mapcpuid. Therefore, if mapcpuid has 0 for revision and variant then any + * version of idstr will match as long as it's the same CPU type. + * + * Return 1 if the CPU type is different or the version of idstr is lower. + */ +int strcmp_cpuid_str(const char *mapcpuid, const char *idstr) +{ + u64 map_id = strtoull(mapcpuid, NULL, 16); + char map_id_variant = FIELD_GET(MIDR_VARIANT_MASK, map_id); + char map_id_revision = FIELD_GET(MIDR_REVISION_MASK, map_id); + u64 id = strtoull(idstr, NULL, 16); + char id_variant = FIELD_GET(MIDR_VARIANT_MASK, id); + char id_revision = FIELD_GET(MIDR_REVISION_MASK, id); + u64 id_fields = ~(MIDR_VARIANT_MASK | MIDR_REVISION_MASK); + + /* Compare without version first */ + if ((map_id & id_fields) != (id & id_fields)) + return 1; + + /* + * ID matches, now compare version. + * + * Arm revisions (like r0p0) are compared here like two digit semver + * values eg. 1.3 < 2.0 < 2.1 < 2.2. + * + * r = high value = 'Variant' field in MIDR + * p = low value = 'Revision' field in MIDR + * + */ + if (id_variant > map_id_variant) + return 0; + + if (id_variant == map_id_variant && id_revision >= map_id_revision) + return 0; + + /* + * variant is less than mapfile variant or variants are the same but + * the revision doesn't match. Return no match. + */ + return 1; +} -- 2.34.1