From 3a3649ec3ffd27009deb0cf85c206f448cb6432f Mon Sep 17 00:00:00 2001 From: quackerd Date: Mon, 21 Nov 2022 14:35:29 +0100 Subject: [PATCH] tmpfs round robin page allocation & finer grained iflib affinity ctrl --- sys/fs/tmpfs/tmpfs_subr.c | 1 + sys/net/iflib.c | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/sys/fs/tmpfs/tmpfs_subr.c b/sys/fs/tmpfs/tmpfs_subr.c index 2aa8891f907d..ffd809a431f7 100644 --- a/sys/fs/tmpfs/tmpfs_subr.c +++ b/sys/fs/tmpfs/tmpfs_subr.c @@ -96,6 +96,7 @@ tmpfs_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot, vm_object_deallocate(object); object = NULL; } + object->domain.dr_policy = DOMAINSET_RR(); return (object); } diff --git a/sys/net/iflib.c b/sys/net/iflib.c index 423cdecd86b4..f447065b0057 100644 --- a/sys/net/iflib.c +++ b/sys/net/iflib.c @@ -594,7 +594,14 @@ SYSCTL_INT(_net_iflib, OID_AUTO, timer_default, CTLFLAG_RW, #define IFLIB_CPU_OVERRIDE_MAX_SIZE (256) static char iflib_override_cpu_bdfs[IFLIB_CPU_OVERRIDE_MAX_SIZE] = ""; SYSCTL_STRING(_net_iflib, OID_AUTO, override_cpu_bdfs, CTLFLAG_RWTUN, - iflib_override_cpu_bdfs, sizeof(iflib_override_cpu_bdfs), "a device's bdfs identifier to affinitze to all cpus"); + iflib_override_cpu_bdfs, sizeof(iflib_override_cpu_bdfs), "a device's bdfs identifier to affinitze to a subset of cores"); +#define IFLIB_CPU_LIST_MAX_SIZE (256) +static int iflib_override_cpu_base = 0; +SYSCTL_INT(_net_iflib, OID_AUTO, override_cpu_base, CTLFLAG_RWTUN, + &iflib_override_cpu_base, 0, "the base cpu for the the subset of cores"); +static int iflib_override_cpu_stride = 2; +SYSCTL_INT(_net_iflib, OID_AUTO, override_cpu_stride, CTLFLAG_RWTUN, + &iflib_override_cpu_stride, 0, "the stride for the the subset of cores"); #if IFLIB_DEBUG_COUNTERS @@ -5015,6 +5022,7 @@ iflib_device_register(device_t dev, void *sc, if_shared_ctx_t sctx, if_ctx_t *ct kobj_method_t *kobj_method; int err, msix, rid; int num_txd, num_rxd; + int cpu_count; unsigned int bus = pci_get_bus(dev); unsigned int device = pci_get_slot(dev); unsigned int function = pci_get_function(dev); @@ -5116,15 +5124,18 @@ iflib_device_register(device_t dev, void *sc, if_shared_ctx_t sctx, if_ctx_t *ct NULL, NULL, "admin"); if (strcmp(iflib_override_cpu_bdfs, bdf_str) == 0) { - cpuset_t cset; - device_printf(dev, "override cpu to all cpus\n"); - CPU_COPY(&all_cpus, &ctx->ifc_cpus); - CPU_ZERO(&cset); - for (int i = 0; i < 32; i++) { - CPU_SET(i*2, &cset); + CPU_ZERO(&ctx->ifc_cpus); + cpu_count = CPU_COUNT(&all_cpus); + if (iflib_override_cpu_stride <= 0) { + device_printf(dev, "invalid cpu stride %d detected, resetting to 2\n", iflib_override_cpu_stride); + iflib_override_cpu_stride = 2; } - CPU_AND(&ctx->ifc_cpus, &ctx->ifc_cpus, &cset); - ctx->ifc_cpus_are_physical_cores = true; + device_printf(dev, "overriding core affinty to base %d, stride %d, total cores %d\n", iflib_override_cpu_base, iflib_override_cpu_stride, cpu_count); + for (int i = iflib_override_cpu_base; i < cpu_count; i+= iflib_override_cpu_stride) { + device_printf(dev, "setting affinty to core %d\n", i); + CPU_SET(i, &ctx->ifc_cpus); + } + ctx->ifc_cpus_are_physical_cores = false; } /* Set up cpu set. If it fails, use the set of all CPUs. */ else if (bus_get_cpus(dev, INTR_CPUS, sizeof(ctx->ifc_cpus), &ctx->ifc_cpus) != 0) {