From nobody Thu Jun 8 16:11:17 2023 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 4QcTjL1x6vz4bvWN; Thu, 8 Jun 2023 16:11:18 +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 4QcTjL0qTlz4bDb; Thu, 8 Jun 2023 16:11:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686240678; 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=hW/KwPs498Af/8L2qenlCx/UqRx1JFdo5EGTwZ4DQQU=; b=wHdexyvK+FsoEfScOJo916WaTJtzpJNqQ6YoimSFk5JjWO70RARbna7IWePuvmWR6YUBHm CmGb/rB4uZOkdSlisWWfi0cBi6nn+WNGptJsMGJr85AEepPmkAJ+xbFCp080ADcusBN5fJ 8m/52wfZnENHXUz4Vk8+AW46AMKneewf+OCQtFRwTLaXG2vYv8ayzFCHfP1fV9JYtV4i+Y e+GJvXtHp+gtxul3N+B/6dYb9vgmkG0w/EgqVbSkAMqNj3u1ZDmtqLAovQSKVAmZCQMgTP mJh/B+yIv5gHpwHGw22PQKE1QzB6ylvVoJqL3KLvidhirBeMpJ3+8dyx938Ctg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686240678; 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=hW/KwPs498Af/8L2qenlCx/UqRx1JFdo5EGTwZ4DQQU=; b=ukYGOjrvClN6L2Pa7mgYqsugyUWg5T9OCHIFPp54u365CUdEiFbm5HtvzI2WMRG+fcZP+q OdSNI9SmSaJOQnTnU0I/2lN8P3qZ6yoYZQisAskRdBoMqZrh5tg04/XbTpONgpAhsG1UPe WLVLsexN8b475aFhlB9AVsewjCEr0d1ffE5extgHiCwogCj3guVFpPCCHwmYZ2QPb8LQQo Cxo2X7gzlMK66UQtRbnetn46lSeHWGlkR7PEOOdK2ZUwys0uMgDaNKSlihq9aPM7yZz7y6 /KqChGY/CYvZN9MmWxn4PPmaxKCeGN7QFRe+IXXihU4oyEksWYYW7CZVVjO35Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1686240678; a=rsa-sha256; cv=none; b=MkohdULVUh4JX1eXcgZqjvqeaFjpeij5ViPEArct7fjgC92wXPqPdd9YQNgqDgwfW0h0Bw 184Z7SY5J6X5mtIsDYmfJu2fVQO1yNvIwB7U542AzX9PKJ8X19vQQ8UjTVTXxS0txVQoKN PR8HeIn4Wc6vWOBe+0hq3FjBuSjrpVcQ0d7GQnH7FV7gJm2CCUJNMPZJi6wX6sd8P0nzPL 3V3Yr4madR/cQisSgqJqRIGtNEGyJpnlboXjYoo2V/9BQ4WCPOO6r1ZXjVyBAh4CVu0ZkE FZ1wQYMRrveXfFcZwaVcT6vIb75TOOesQrH2PxVYnakUUauXEL3omzAauk6HIw== 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 4QcTjK6vKBz11CV; Thu, 8 Jun 2023 16:11:17 +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 358GBHCK027061; Thu, 8 Jun 2023 16:11:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 358GBHbw027060; Thu, 8 Jun 2023 16:11:17 GMT (envelope-from git) Date: Thu, 8 Jun 2023 16:11:17 GMT Message-Id: <202306081611.358GBHbw027060@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: d057b7aac8ae - main - arm64: Malloc the cpu_desc array 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: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d057b7aac8aedd353f2cb047cb0069f6a4db7a83 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=d057b7aac8aedd353f2cb047cb0069f6a4db7a83 commit d057b7aac8aedd353f2cb047cb0069f6a4db7a83 Author: Andrew Turner AuthorDate: 2023-06-02 16:12:24 +0000 Commit: Andrew Turner CommitDate: 2023-06-08 16:10:10 +0000 arm64: Malloc the cpu_desc array We only need this during boot. Allocate the array before starting CPUs to reduce the memory usage. Reviewed by: Zach Leaf Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D40433 --- sys/arm64/arm64/identcpu.c | 43 ++++++++++++++++++++++++++++++++++++++----- sys/arm64/arm64/mp_machdep.c | 2 ++ sys/arm64/include/cpu.h | 2 ++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/sys/arm64/arm64/identcpu.c b/sys/arm64/arm64/identcpu.c index fb1c4537f216..86b669ea2f56 100644 --- a/sys/arm64/arm64/identcpu.c +++ b/sys/arm64/arm64/identcpu.c @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -47,6 +48,8 @@ __FBSDID("$FreeBSD$"); #include #include +static MALLOC_DEFINE(M_IDENTCPU, "CPU ID", "arm64 CPU identification memory"); + struct cpu_desc; static void print_cpu_midr(struct sbuf *sb, u_int cpu); @@ -150,10 +153,22 @@ struct cpu_desc { bool have_sve; }; -static struct cpu_desc cpu_desc[MAXCPU]; +static struct cpu_desc cpu_desc0; +static struct cpu_desc *cpu_desc; static struct cpu_desc kern_cpu_desc; static struct cpu_desc user_cpu_desc; +static struct cpu_desc * +get_cpu_desc(u_int cpu) +{ + /* The cpu_desc for CPU 0 is used before the allocator is ready. */ + if (cpu == 0) + return (&cpu_desc0); + + MPASS(cpu_desc != NULL); + return (&cpu_desc[cpu - 1]); +} + struct cpu_parts { u_int part_id; const char *part_name; @@ -1803,7 +1818,7 @@ update_special_regs(u_int cpu) user_cpu_desc.id_aa64dfr0 = ID_AA64DFR0_DebugVer_8; } - desc = &cpu_desc[cpu]; + desc = get_cpu_desc(cpu); for (i = 0; i < nitems(user_regs); i++) { value = CPU_DESC_FIELD(*desc, i); if (cpu == 0) { @@ -1839,6 +1854,22 @@ update_special_regs(u_int cpu) } } +void +cpu_desc_init(void) +{ + if (mp_ncpus == 1) + return; + + /* + * Allocate memory for the non-boot CPUs to store their registers. + * As this is indexed by CPU ID we need to allocate space for CPUs + * 1 to mp_maxid. Because of this mp_maxid is already the correct + * number of elements. + */ + cpu_desc = mallocarray(mp_maxid, sizeof(*cpu_desc), M_IDENTCPU, + M_ZERO | M_WAITOK); +} + /* HWCAP */ bool __read_frequently lse_supported = false; @@ -1896,7 +1927,7 @@ identify_cpu_sysinit(void *dummy __unused) prev_desc = NULL; CPU_FOREACH(cpu) { - desc = &cpu_desc[cpu]; + desc = get_cpu_desc(cpu); if (cpu != 0) { check_cpu_regs(cpu, desc, prev_desc); update_special_regs(cpu); @@ -1950,7 +1981,7 @@ cpu_features_sysinit(void *dummy __unused) prev_desc = NULL; CPU_FOREACH(cpu) { - desc = &cpu_desc[cpu]; + desc = get_cpu_desc(cpu); print_cpu_features(cpu, desc, prev_desc); prev_desc = desc; } @@ -1961,6 +1992,8 @@ cpu_features_sysinit(void *dummy __unused) sbuf_finish(&sb); sbuf_delete(&sb); + + free(cpu_desc, M_IDENTCPU); } /* Log features before APs are released and start printing to the dmesg. */ SYSINIT(cpu_features, SI_SUB_SMP - 1, SI_ORDER_ANY, cpu_features_sysinit, NULL); @@ -2390,7 +2423,7 @@ identify_cpu(u_int cpu) struct cpu_desc *desc; uint64_t clidr; - desc = &cpu_desc[cpu]; + desc = get_cpu_desc(cpu); /* Save affinity for current CPU */ desc->mpidr = get_mpidr(); CPU_AFFINITY(cpu) = desc->mpidr & CPU_AFF_MASK; diff --git a/sys/arm64/arm64/mp_machdep.c b/sys/arm64/arm64/mp_machdep.c index 9dd1182e5721..babeee331be0 100644 --- a/sys/arm64/arm64/mp_machdep.c +++ b/sys/arm64/arm64/mp_machdep.c @@ -779,6 +779,8 @@ cpu_mp_start(void) mpidr = READ_SPECIALREG(mpidr_el1) & CPU_AFF_MASK; cpuid_to_pcpu[0]->pc_mpidr = mpidr; + cpu_desc_init(); + switch(arm64_bus_method) { #ifdef DEV_ACPI case ARM64_BUS_ACPI: diff --git a/sys/arm64/include/cpu.h b/sys/arm64/include/cpu.h index 88a9ac18080b..1ea497756698 100644 --- a/sys/arm64/include/cpu.h +++ b/sys/arm64/include/cpu.h @@ -214,6 +214,8 @@ void update_special_regs(u_int); bool extract_user_id_field(u_int, u_int, uint8_t *); bool get_kernel_reg(u_int, uint64_t *); +void cpu_desc_init(void); + #define CPU_AFFINITY(cpu) __cpu_affinity[(cpu)] #define CPU_CURRENT_SOCKET \ (CPU_AFF2(CPU_AFFINITY(PCPU_GET(cpuid))))