From nobody Thu Jan 29 18:12:35 2026 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 4f26gS2ywzz6PfNp for ; Thu, 29 Jan 2026 18:12:36 +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 "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4f26gS0HMrz3ZKj for ; Thu, 29 Jan 2026 18:12:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769710356; 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=6uAF9NJpfoapvURWn6SS4iEzWvnVvJ5tbQQfHj7Ry0U=; b=CV7qwez3wHe+jVH+aohQqI243GIe1T4/xmHUPfGGpPLHumVJCHguKiOULIp8aoZ+V2SRhF jGp8bKWwQJTpBGS60v6ynMLyLlSfq3bpwubOYT+UVh3YbV5+biwzm6sPn605RWg291X4Rr jAHLWR480Uxy6h5mVEkhukAGJLgI8es39MlE+aBNLRicMLp+t9zbQaaugmHogN2eeRDZ3Z 4QJBdxcxXo5ljApKB1/Ro8cUvPhxYrbq3ZtLbRbo+sODP4AfPkXV7qKo94fFaG01VmCv3f nzo+6JL7EkRCxdGYntCdMqNdEkUNtEuBnzNILc/9Ski0jFRLtK+Tx+u0VK+uMA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1769710356; a=rsa-sha256; cv=none; b=aJ4oaj8joT3SCRmKXDHkJIu8tQZYJoPuO2qYfrney5vmJgCEwN8u+elWOZAxKywvct6Svc NxTMRsnSaL4C3vaKziR/GGYqOuIHSLd8ATfa8odl2lG+/eMYzHZ/P6lrvRJNKDW8oLJfdM hg/MPGSLrJrysOqniTvmuQ0vQSmO2fPmWQc/iyGLO1y5jabLNphLwTyNDUaYyDEr3AM0ve +RasjfE3UAJJptZ70YXJ2d1QuSfdDF462MWcItC/y1XPy7ZFG9jdBgUjyvOCZ2DPg18Wuf 49TSS6bOlRVwfwVVXOeT9Xk9VEHR4UuFiFRUERphMw9JuHISvqB7UIL9AABTNQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769710356; 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=6uAF9NJpfoapvURWn6SS4iEzWvnVvJ5tbQQfHj7Ry0U=; b=k2TR7iCqJ4bT7xjJGxl8m/96/WVea929/f9qs0Kbf4s56jdPnxZ0RydojfyB1dBlGQNQ/5 7jGXgko4vtHriX9KE1fZBD+HipV8wADc9onQzPeY90JhcA2fsa0aWT/RJJ/tg+tlHLmZYy BET/byi9bH8x1bHj7s8XB5ydlSbnFG31F1kv2fCYlwYNUEjkKAA61e4GnnQP1j5azwftJl mvMTZYIwmzH3yGJLKr2+v8gisF4mvhyUDbFcVrhSk/AOeQ5td2dhWpSLHpIWXTAOaDMbOC bkRnqkRjeoCbhjOwEyKh13KsLho5b36kEkvyddBnmwIeD2dlGBudZeWd6OWvJA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4f26gR5xrfzq5q for ; Thu, 29 Jan 2026 18:12:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 964a by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 29 Jan 2026 18:12:35 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: b602ba1b5fd9 - main - net/iflib.c: move out scheduler-depended code into the hook 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b602ba1b5fd92bb226e32f5720885f856a5cb0bb Auto-Submitted: auto-generated Date: Thu, 29 Jan 2026 18:12:35 +0000 Message-Id: <697ba313.964a.4a1d91d1@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=b602ba1b5fd92bb226e32f5720885f856a5cb0bb commit b602ba1b5fd92bb226e32f5720885f856a5cb0bb Author: Konstantin Belousov AuthorDate: 2026-01-22 13:38:20 +0000 Commit: Konstantin Belousov CommitDate: 2026-01-29 18:11:56 +0000 net/iflib.c: move out scheduler-depended code into the hook Add sched_find_l2_neighbor(). This really should be not scheduler-depended, in does not have anything to do with scheduler at all. But for now keep the same code structure. Reviewed by: olce Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54831 --- sys/kern/sched_4bsd.c | 7 +++++ sys/kern/sched_shim.c | 1 + sys/kern/sched_ule.c | 68 ++++++++++++++++++++++++++++++++++++++++++ sys/net/iflib.c | 82 ++------------------------------------------------- sys/sys/sched.h | 8 +++++ 5 files changed, 87 insertions(+), 79 deletions(-) diff --git a/sys/kern/sched_4bsd.c b/sys/kern/sched_4bsd.c index 03e7b71d3fe6..11baf9d2bdfa 100644 --- a/sys/kern/sched_4bsd.c +++ b/sys/kern/sched_4bsd.c @@ -1854,6 +1854,12 @@ sched_4bsd_do_timer_accounting(void) #endif } +static int +sched_4bsd_find_l2_neighbor(int cpu) +{ + return (-1); +} + struct sched_instance sched_4bsd_instance = { #define SLOT(name) .name = sched_4bsd_##name SLOT(load), @@ -1897,6 +1903,7 @@ struct sched_instance sched_4bsd_instance = { SLOT(tdname), SLOT(clear_tdname), SLOT(do_timer_accounting), + SLOT(find_l2_neighbor), SLOT(init), SLOT(init_ap), SLOT(setup), diff --git a/sys/kern/sched_shim.c b/sys/kern/sched_shim.c index d2f0b5749752..816d0b44bb52 100644 --- a/sys/kern/sched_shim.c +++ b/sys/kern/sched_shim.c @@ -94,6 +94,7 @@ DEFINE_SHIM0(sizeof_thread, int, sched_sizeof_thread) DEFINE_SHIM1(tdname, char *, sched_tdname, struct thread *, td) DEFINE_SHIM1(clear_tdname, void, sched_clear_tdname, struct thread *, td) DEFINE_SHIM0(do_timer_accounting, bool, sched_do_timer_accounting) +DEFINE_SHIM1(find_l2_neighbor, int, sched_find_l2_neighbor, int, cpu) DEFINE_SHIM0(init_ap, void, schedinit_ap) static char sched_name[32] = "ULE"; diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c index 22257b2c0d7a..7a745619480d 100644 --- a/sys/kern/sched_ule.c +++ b/sys/kern/sched_ule.c @@ -3360,6 +3360,73 @@ sched_ule_do_timer_accounting(void) return (true); } +#ifdef SMP +static int +sched_ule_find_child_with_core(int cpu, struct cpu_group *grp) +{ + int i; + + if (grp->cg_children == 0) + return (-1); + + MPASS(grp->cg_child); + for (i = 0; i < grp->cg_children; i++) { + if (CPU_ISSET(cpu, &grp->cg_child[i].cg_mask)) + return (i); + } + + return (-1); +} + +static int +sched_ule_find_l2_neighbor(int cpu) +{ + struct cpu_group *grp; + int i; + + grp = cpu_top; + if (grp == NULL) + return (-1); + + /* + * Find the smallest CPU group that contains the given core. + */ + i = 0; + while ((i = sched_ule_find_child_with_core(cpu, grp)) != -1) { + /* + * If the smallest group containing the given CPU has less + * than two members, we conclude the given CPU has no + * L2 neighbor. + */ + if (grp->cg_child[i].cg_count <= 1) + return (-1); + grp = &grp->cg_child[i]; + } + + /* Must share L2. */ + if (grp->cg_level > CG_SHARE_L2 || grp->cg_level == CG_SHARE_NONE) + return (-1); + + /* + * Select the first member of the set that isn't the reference + * CPU, which at this point is guaranteed to exist. + */ + for (i = 0; i < CPU_SETSIZE; i++) { + if (CPU_ISSET(i, &grp->cg_mask) && i != cpu) + return (i); + } + + /* Should never be reached */ + return (-1); +} +#else +static int +sched_ule_find_l2_neighbor(int cpu) +{ + return (-1); +} +#endif + struct sched_instance sched_ule_instance = { #define SLOT(name) .name = sched_ule_##name SLOT(load), @@ -3403,6 +3470,7 @@ struct sched_instance sched_ule_instance = { SLOT(tdname), SLOT(clear_tdname), SLOT(do_timer_accounting), + SLOT(find_l2_neighbor), SLOT(init), SLOT(init_ap), SLOT(setup), diff --git a/sys/net/iflib.c b/sys/net/iflib.c index b0e4bb9470c9..8e2fd257ca74 100644 --- a/sys/net/iflib.c +++ b/sys/net/iflib.c @@ -29,7 +29,6 @@ #include "opt_inet.h" #include "opt_inet6.h" #include "opt_acpi.h" -#include "opt_sched.h" #include #include @@ -40,8 +39,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -4813,83 +4814,6 @@ cpuid_advance(if_ctx_t ctx, unsigned int cpuid, unsigned int n) return (cpuid); } -#if defined(SMP) && defined(SCHED_ULE) -extern struct cpu_group *cpu_top; /* CPU topology */ - -static int -find_child_with_core(int cpu, struct cpu_group *grp) -{ - int i; - - if (grp->cg_children == 0) - return (-1); - - MPASS(grp->cg_child); - for (i = 0; i < grp->cg_children; i++) { - if (CPU_ISSET(cpu, &grp->cg_child[i].cg_mask)) - return (i); - } - - return (-1); -} - - -/* - * Find an L2 neighbor of the given CPU or return -1 if none found. This - * does not distinguish among multiple L2 neighbors if the given CPU has - * more than one (it will always return the same result in that case). - */ -static int -find_l2_neighbor(int cpu) -{ - struct cpu_group *grp; - int i; - - grp = cpu_top; - if (grp == NULL) - return (-1); - - /* - * Find the smallest CPU group that contains the given core. - */ - i = 0; - while ((i = find_child_with_core(cpu, grp)) != -1) { - /* - * If the smallest group containing the given CPU has less - * than two members, we conclude the given CPU has no - * L2 neighbor. - */ - if (grp->cg_child[i].cg_count <= 1) - return (-1); - grp = &grp->cg_child[i]; - } - - /* Must share L2. */ - if (grp->cg_level > CG_SHARE_L2 || grp->cg_level == CG_SHARE_NONE) - return (-1); - - /* - * Select the first member of the set that isn't the reference - * CPU, which at this point is guaranteed to exist. - */ - for (i = 0; i < CPU_SETSIZE; i++) { - if (CPU_ISSET(i, &grp->cg_mask) && i != cpu) - return (i); - } - - /* Should never be reached */ - return (-1); -} - -#else -static int -find_l2_neighbor(int cpu) -{ - - return (-1); -} -#endif - /* * CPU mapping behaviors * --------------------- @@ -4942,7 +4866,7 @@ get_cpuid_for_queue(if_ctx_t ctx, unsigned int base_cpuid, unsigned int qid, unsigned int rx_cpuid; rx_cpuid = cpuid_advance(ctx, base_cpuid, qid); - l2_neighbor = find_l2_neighbor(rx_cpuid); + l2_neighbor = sched_find_l2_neighbor(rx_cpuid); if (l2_neighbor != -1) { return (l2_neighbor); } diff --git a/sys/sys/sched.h b/sys/sys/sched.h index 9c78452432b4..3ba40fb191d3 100644 --- a/sys/sys/sched.h +++ b/sys/sys/sched.h @@ -243,6 +243,13 @@ void schedinit_ap(void); bool sched_do_timer_accounting(void); +/* + * Find an L2 neighbor of the given CPU or return -1 if none found. This + * does not distinguish among multiple L2 neighbors if the given CPU has + * more than one (it will always return the same result in that case). + */ +int sched_find_l2_neighbor(int cpu); + struct sched_instance { int (*load)(void); int (*rr_interval)(void); @@ -285,6 +292,7 @@ struct sched_instance { char *(*tdname)(struct thread *td); void (*clear_tdname)(struct thread *td); bool (*do_timer_accounting)(void); + int (*find_l2_neighbor)(int cpuid); void (*init)(void); void (*init_ap)(void); void (*setup)(void);