From nobody Wed Jun 22 15:57:40 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id EB15287D4AA; Wed, 22 Jun 2022 15:57:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LSp1c5xFQz4d1m; Wed, 22 Jun 2022 15:57:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655913460; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2o2drubg83eWvEr0XOOIDGRV7Jdg6AzCNrsaKP4ier0=; b=H1f3n/srFD++euim6KyKr6yNVlJ8DcbDrBgqFNcgWje52Gi8e5GWlzsi8ARgkDGqJ2DJC2 bW6O7PDkm0t7P4RSGepgMH1+fJLKAp80bNGJ9qqq6nFv1Qwf1E6TYBZTMKc/Ewte49XzbU D0OMPXL1fM68ZLFGOIWIRKM9H/ePNaCO4Bwa/Z7qTnpGx/I6oS5mXIURL7xxOLBp5oeILE WoIjCOrAE4aBKOzbXFJTIecD8Evp0oJlghKxueV3f0Qg3+hWUU3OzG9tEFF9Za+XA7O76I w2bKadjIc/T8UtrO8kj7PH5MLIFVRgGfTPt69L1Q4Tw29Q4OA3F46ru7bJ5CZw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id ABF71EB8; Wed, 22 Jun 2022 15:57:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25MFve2Y066208; Wed, 22 Jun 2022 15:57:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25MFve8x066207; Wed, 22 Jun 2022 15:57:40 GMT (envelope-from git) Date: Wed, 22 Jun 2022 15:57:40 GMT Message-Id: <202206221557.25MFve8x066207@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Justin Hibbits Subject: git: c70276686572 - stable/12 - arm64: Print per-CPU cache summary List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhibbits X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: c70276686572fa4976babed8aa936ed3d3f2a52d Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655913460; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2o2drubg83eWvEr0XOOIDGRV7Jdg6AzCNrsaKP4ier0=; b=NR8Pr9znBeSV0nQT68BemHYlBe4JN1fkIccQWKiye7UjrzX1Kga+fIlcboRqtOf68iXFEg yDg6WUS12l0HBX73mHQnBvihGi/YIJsXNFtODynIRjM+KdSmH/CzMlpfQ+5feJ1TsoHtSj p+eG7ZfInKpu76vBJDxQSh7SIj0nm+QUNczcGDGmkN5OqbzoFo9tMzSKf/xrjbYmTMQyh0 HnKclAFC0RWt47x2nwyrt8h0nvvQhxrttbdfnWDopbcdlAY4ebyyIUOSA0oIrQ7AB0F1Om kF6qDzg4RlXDqvsiLmZBpXp6OEeftz+fDG3v8E8FEnTbpqLWeUGu8tleg5KzBw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655913460; a=rsa-sha256; cv=none; b=KxGZDaBd55i6rkFSYuAJ0dptm+mL87rtjeePWIbX5Kiin5VxRF3ydwS2ExK6kR4RMMvvfL Cpfa/EOatAvHD4TTQj2bwDWmbc9yX/o11wjycnm9C9vBb3ImVyXe4wtibSBzLYY+3KbYQF Mg2sRcQA8Z5tEJSvs+SzzKeP7tMEkr19TtXSyO4qCOUPme9JsU4TmG5wqf7MzoCaK2lNOw w2f8U6xNFSpdXQhVD1JWvfwhVvwWXwfeOOhumeSvH2i2h3VQEnHop019iq3vkhSRz/f1uy mQzt7Se4910mKGaH904JD9TWM8sBAfjrBHQEGq8IAu2Y5OeOTU2oeZ3qc1Sl5Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by jhibbits: URL: https://cgit.FreeBSD.org/src/commit/?id=c70276686572fa4976babed8aa936ed3d3f2a52d commit c70276686572fa4976babed8aa936ed3d3f2a52d Author: Justin Hibbits AuthorDate: 2022-05-31 15:40:20 +0000 Commit: Justin Hibbits CommitDate: 2022-06-22 15:46:40 +0000 arm64: Print per-CPU cache summary Summary: It can be useful to see a summary of CPU caches on bootup. This is done for most platforms already, so add this to arm64, in the form of (taken from Apple M1 pro test): L1 cache: 192KB (instruction), 128KB (data) L2 cache: 12288KB (unified) This is printed out per-CPU, only under bootverbose. Future refinements could instead determine if a cache level is shared with other cores (L2 is shared among cores on some SoCs, for instance), and perform a better calculation to the full true cache sizes. For instance, it's known that the M1 pro, on which this test was done, has 2 12MB L2 clusters, for a total of 24MB. Seeing each CPU with 12288KB L2 would make one think that there's 12MB * NCPUs, for possibly 120MB cache, which is incorrect. Sponsored by: Juniper Networks, Inc. Reviewed by: #arm64, andrew Differential Revision: https://reviews.freebsd.org/D35366 (cherry picked from commit 139ba152c9c91fad9b63ccd2382a80f753f217b9) --- sys/arm64/arm64/identcpu.c | 83 +++++++++++++++++++++++++++++++++++++++++++++- sys/arm64/include/armreg.h | 30 +++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) diff --git a/sys/arm64/arm64/identcpu.c b/sys/arm64/arm64/identcpu.c index 0b376cd02286..ed92cf412b33 100644 --- a/sys/arm64/arm64/identcpu.c +++ b/sys/arm64/arm64/identcpu.c @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$"); static int ident_lock; static void print_cpu_features(u_int cpu); static u_long parse_cpu_features_hwcap(u_int cpu); +static void print_cpu_caches(struct sbuf *sb, u_int); char machine[] = "arm64"; @@ -59,6 +60,8 @@ static char cpu_model[64]; SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD, cpu_model, sizeof(cpu_model), "Machine model"); +#define MAX_CACHES 8 /* Maximum number of caches supported + architecturally. */ /* * Per-CPU affinity as provided in MPIDR_EL1 * Indexed by CPU number in logical order selected by the system. @@ -92,6 +95,8 @@ struct cpu_desc { uint64_t id_aa64mmfr2; uint64_t id_aa64pfr0; uint64_t id_aa64pfr1; + uint64_t clidr; + uint32_t ccsidr[MAX_CACHES][2]; /* 2 possible types. */ }; struct cpu_desc cpu_desc[MAXCPU]; @@ -520,6 +525,62 @@ parse_cpu_features_hwcap(u_int cpu) return (hwcap); } +static void +print_cpu_cache(u_int cpu, struct sbuf *sb, uint64_t ccs, bool icache, + bool unified) +{ + size_t cache_size; + size_t line_size; + + /* LineSize is Log2(S) - 4. */ + line_size = 1 << ((ccs & CCSIDR_LineSize_MASK) + 4); + /* + * Calculate cache size (sets * ways * line size). There are different + * formats depending on the FEAT_CCIDX bit in ID_AA64MMFR2 feature + * register. + */ + if ((cpu_desc[cpu].id_aa64mmfr2 & ID_AA64MMFR2_CCIDX_64)) + cache_size = (CCSIDR_NSETS_64(ccs) + 1) * + (CCSIDR_ASSOC_64(ccs) + 1); + else + cache_size = (CCSIDR_NSETS(ccs) + 1) * (CCSIDR_ASSOC(ccs) + 1); + + cache_size *= line_size; + sbuf_printf(sb, "%zuKB (%s)", cache_size / 1024, + icache ? "instruction" : unified ? "unified" : "data"); +} + +static void +print_cpu_caches(struct sbuf *sb, u_int cpu) +{ + /* Print out each cache combination */ + uint64_t clidr; + int i = 1; + clidr = cpu_desc[cpu].clidr; + + for (i = 0; (clidr & CLIDR_CTYPE_MASK) != 0; i++, clidr >>= 3) { + int j = 0; + int ctype_m = (clidr & CLIDR_CTYPE_MASK); + + sbuf_printf(sb, " L%d cache: ", i + 1); + if ((clidr & CLIDR_CTYPE_IO)) { + print_cpu_cache(cpu, sb, cpu_desc[cpu].ccsidr[i][j++], + true, false); + /* If there's more, add to the line. */ + if ((ctype_m & ~CLIDR_CTYPE_IO) != 0) + sbuf_printf(sb, ", "); + } + if ((ctype_m & ~CLIDR_CTYPE_IO) != 0) { + print_cpu_cache(cpu, sb, cpu_desc[cpu].ccsidr[i][j], + false, (clidr & CLIDR_CTYPE_UNIFIED)); + } + sbuf_printf(sb, "\n"); + + } + sbuf_finish(sb); + printf("%s", sbuf_data(sb)); +} + static void print_cpu_features(u_int cpu) { @@ -1351,6 +1412,8 @@ print_cpu_features(u_int cpu) printf(" Auxiliary Features 1 = <%#lx>\n", cpu_desc[cpu].id_aa64afr1); } + if (bootverbose) + print_cpu_caches(sb, cpu); sbuf_delete(sb); sb = NULL; @@ -1360,6 +1423,7 @@ print_cpu_features(u_int cpu) void identify_cpu(void) { + uint64_t clidr; u_int midr; u_int impl_id; u_int part_id; @@ -1407,7 +1471,6 @@ identify_cpu(void) /* Save affinity for current CPU */ cpu_desc[cpu].mpidr = get_mpidr(); CPU_AFFINITY(cpu) = cpu_desc[cpu].mpidr & CPU_AFF_MASK; - cpu_desc[cpu].id_aa64dfr0 = READ_SPECIALREG(ID_AA64DFR0_EL1); cpu_desc[cpu].id_aa64dfr1 = READ_SPECIALREG(ID_AA64DFR1_EL1); cpu_desc[cpu].id_aa64isar0 = READ_SPECIALREG(ID_AA64ISAR0_EL1); @@ -1418,6 +1481,24 @@ identify_cpu(void) cpu_desc[cpu].id_aa64pfr0 = READ_SPECIALREG(ID_AA64PFR0_EL1); cpu_desc[cpu].id_aa64pfr1 = READ_SPECIALREG(ID_AA64PFR1_EL1); + cpu_desc[cpu].clidr = READ_SPECIALREG(clidr_el1); + + clidr = cpu_desc[cpu].clidr; + + for (int i = 0; (clidr & CLIDR_CTYPE_MASK) != 0; i++, clidr >>= 3) { + int j = 0; + if ((clidr & CLIDR_CTYPE_IO)) { + WRITE_SPECIALREG(CSSELR_EL1, + CSSELR_Level(i) | CSSELR_InD); + cpu_desc[cpu].ccsidr[i][j++] = + READ_SPECIALREG(CCSIDR_EL1); + } + if ((clidr & ~CLIDR_CTYPE_IO) == 0) + continue; + WRITE_SPECIALREG(CSSELR_EL1, CSSELR_Level(i)); + cpu_desc[cpu].ccsidr[i][j] = READ_SPECIALREG(CCSIDR_EL1); + } + if (cpu != 0) { /* * This code must run on one cpu at a time, but we are diff --git a/sys/arm64/include/armreg.h b/sys/arm64/include/armreg.h index d528f1af2377..c3fc7da46c6e 100644 --- a/sys/arm64/include/armreg.h +++ b/sys/arm64/include/armreg.h @@ -45,6 +45,32 @@ #define UL(x) UINT64_C(x) +/* CCSIDR_EL1 - Cache Size ID Register */ +#define CCSIDR_NumSets_MASK 0x0FFFE000 +#define CCSIDR_NumSets64_MASK 0x00FFFFFF00000000 +#define CCSIDR_NumSets_SHIFT 13 +#define CCSIDR_NumSets64_SHIFT 32 +#define CCSIDR_Assoc_MASK 0x00001FF8 +#define CCSIDR_Assoc64_MASK 0x0000000000FFFFF8 +#define CCSIDR_Assoc_SHIFT 3 +#define CCSIDR_Assoc64_SHIFT 3 +#define CCSIDR_LineSize_MASK 0x7 +#define CCSIDR_NSETS(idr) \ + (((idr) & CCSIDR_NumSets_MASK) >> CCSIDR_NumSets_SHIFT) +#define CCSIDR_ASSOC(idr) \ + (((idr) & CCSIDR_Assoc_MASK) >> CCSIDR_Assoc_SHIFT) +#define CCSIDR_NSETS_64(idr) \ + (((idr) & CCSIDR_NumSets64_MASK) >> CCSIDR_NumSets64_SHIFT) +#define CCSIDR_ASSOC_64(idr) \ + (((idr) & CCSIDR_Assoc64_MASK) >> CCSIDR_Assoc64_SHIFT) + +/* CLIDR_EL1 - Cache level ID register */ +#define CLIDR_CTYPE_MASK 0x7 /* Cache type mask bits */ +#define CLIDR_CTYPE_IO 0x1 /* Instruction only */ +#define CLIDR_CTYPE_DO 0x2 /* Data only */ +#define CLIDR_CTYPE_ID 0x3 /* Split instruction and data */ +#define CLIDR_CTYPE_UNIFIED 0x4 /* Unified */ + /* CNTHCTL_EL2 - Counter-timer Hypervisor Control register */ #define CNTHCTL_EVNTI_MASK (0xf << 4) /* Bit to trigger event stream */ #define CNTHCTL_EVNTDIR (1 << 3) /* Control transition trigger bit */ @@ -60,6 +86,10 @@ #define CPACR_FPEN_TRAP_NONE (0x3 << 20) /* No traps */ #define CPACR_TTA (0x1 << 28) +/* CSSELR_EL1 - Cache size selection register */ +#define CSSELR_Level(i) (i << 1) +#define CSSELR_InD 0x00000001 + /* CTR_EL0 - Cache Type Register */ #define CTR_DLINE_SHIFT 16 #define CTR_DLINE_MASK (0xf << CTR_DLINE_SHIFT)