From owner-dev-commits-src-all@freebsd.org Thu Apr 1 14:32:11 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1357157936C; Thu, 1 Apr 2021 14:32:11 +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 4FB5HG70llz3stQ; Thu, 1 Apr 2021 14:32:10 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 E34EA6850; Thu, 1 Apr 2021 14:32:10 +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 131EWAZF093505; Thu, 1 Apr 2021 14:32:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 131EWA0Y093504; Thu, 1 Apr 2021 14:32:10 GMT (envelope-from git) Date: Thu, 1 Apr 2021 14:32:10 GMT Message-Id: <202104011432.131EWA0Y093504@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: cb5f8694a522 - main - powernv: Include NUMA locality information in the CPU topology MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cb5f8694a522ab9a80f9f0bd321d8f3ed818dd9b Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Apr 2021 14:32:11 -0000 The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=cb5f8694a522ab9a80f9f0bd321d8f3ed818dd9b commit cb5f8694a522ab9a80f9f0bd321d8f3ed818dd9b Author: Mark Johnston AuthorDate: 2021-04-01 14:25:57 +0000 Commit: Mark Johnston CommitDate: 2021-04-01 14:25:57 +0000 powernv: Include NUMA locality information in the CPU topology ULE uses this topology to try and preserve locality when migrating threads between CPUs and when performing work stealing. Ensure that on NUMA systems it will at least take the NUMA topology into account. Reviewed by: bdragon, jhibbits (previous version) Tested by: bdragon MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D28580 --- sys/powerpc/powernv/platform_powernv.c | 66 +++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 8 deletions(-) diff --git a/sys/powerpc/powernv/platform_powernv.c b/sys/powerpc/powernv/platform_powernv.c index d7acc544c2ed..8c7da5c257ee 100644 --- a/sys/powerpc/powernv/platform_powernv.c +++ b/sys/powerpc/powernv/platform_powernv.c @@ -480,22 +480,72 @@ powernv_smp_probe_threads(platform_t plat) mp_ncores = mp_ncpus / nthreads; } +static struct cpu_group * +cpu_group_init(struct cpu_group *group, struct cpu_group *parent, + const cpuset_t *cpus, int children, int level, int flags) +{ + struct cpu_group *child; + + child = children != 0 ? smp_topo_alloc(children) : NULL; + + group->cg_parent = parent; + group->cg_child = child; + CPU_COPY(cpus, &group->cg_mask); + group->cg_count = CPU_COUNT(cpus); + group->cg_children = children; + group->cg_level = level; + group->cg_flags = flags; + + return (child); +} + static struct cpu_group * powernv_smp_topo(platform_t plat) { + struct cpu_group *core, *dom, *root; + cpuset_t corecpus, domcpus; + int cpuid, i, j, k, ncores; + if (mp_ncpus % smp_threads_per_core != 0) { - printf("WARNING: Irregular SMP topology. Performance may be " - "suboptimal (%d threads, %d on first core)\n", - mp_ncpus, smp_threads_per_core); + printf("%s: irregular SMP topology (%d threads, %d per core)\n", + __func__, mp_ncpus, smp_threads_per_core); return (smp_topo_none()); } - /* Don't do anything fancier for non-threaded SMP */ - if (smp_threads_per_core == 1) - return (smp_topo_none()); + root = smp_topo_alloc(1); + dom = cpu_group_init(root, NULL, &all_cpus, vm_ndomains, CG_SHARE_NONE, + 0); + + /* + * Redundant layers will be collapsed by the caller so we don't need a + * special case for a single domain. + */ + for (i = 0; i < vm_ndomains; i++, dom++) { + CPU_COPY(&cpuset_domain[i], &domcpus); + ncores = CPU_COUNT(&domcpus) / smp_threads_per_core; + KASSERT(CPU_COUNT(&domcpus) % smp_threads_per_core == 0, + ("%s: domain %d core count not divisible by thread count", + __func__, i)); + + core = cpu_group_init(dom, root, &domcpus, ncores, CG_SHARE_L3, + 0); + for (j = 0; j < ncores; j++, core++) { + /* + * Assume that consecutive CPU IDs correspond to sibling + * threads. + */ + CPU_ZERO(&corecpus); + for (k = 0; k < smp_threads_per_core; k++) { + cpuid = CPU_FFS(&domcpus) - 1; + CPU_CLR(cpuid, &domcpus); + CPU_SET(cpuid, &corecpus); + } + (void)cpu_group_init(core, dom, &corecpus, 0, + CG_SHARE_L1, CG_FLAG_SMT); + } + } - return (smp_topo_1level(CG_SHARE_L1, smp_threads_per_core, - CG_FLAG_SMT)); + return (root); } #endif