From 4805dbd892082958e0e871108dfe639d05fcd6ad Mon Sep 17 00:00:00 2001 From: Nexoniarz Date: Fri, 23 Oct 2026 13:54:37 +0200 Subject: [PATCH] limits: 256 PCI functions, 128 sockets and devices, 64 USB interfaces The fixed tables that a bigger machine than the one they were written on reaches first, each raised to where it costs little: NPCI 64 -> 256 a desktop with cards and Thunderbolt passes 64, and the devices past it -- often the disk or NIC last in bus order -- were ignored; 44 KB NSOCK 32 -> 128 Unix sockets, which a desktop session uses by the dozen; 4.9 KB each, 470 KB in all NDEVICE 32 -> 128 120 bytes each NIFDEV 16 -> 64 one dock is a hub, Ethernet, audio and a card reader at two or three interfaces apiece NETIF_MAX 4 -> 8 Device names took one digit and clamped there, so the tenth device of a kind and every one after it was named "...9". Two digits now. Checked under QEMU with two bridges of test devices: 68 functions, all in lspci, /proc/pci and /sys/bus/pci. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01S1giNvrHTrPMPw7V6x1kQ4 --- include/device.h | 2 +- include/param.h | 5 +++-- include/pci.h | 5 ++++- include/socket.h | 2 +- kernel/dev/device.c | 10 ++++++---- kernel/drivers/usb/core/usb.c | 7 ++++--- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/device.h b/include/device.h index 6d90493..de7d3e1 100644 --- a/include/device.h +++ b/include/device.h @@ -67,7 +67,7 @@ struct device { int in_use; }; -#define NDEVICE 32 +#define NDEVICE 128 // Register a device. Returns it, or 0 if the table is full. The name is made // unique by appending an index, so a caller passes "vga" and gets "vga0". diff --git a/include/param.h b/include/param.h index ad5f545..fc7abe2 100644 --- a/include/param.h +++ b/include/param.h @@ -67,5 +67,6 @@ // Network interfaces the stack will attach. Two is already an ordinary machine // -- a laptop with Ethernet plus a virtual adapter -- and each one costs a // struct netif, so the limit is about keeping a fixed array honest rather than -// about memory. -#define NETIF_MAX 4 +// about memory. Eight, since a dock's Ethernet and a phone tethered over USB +// sit beside the built-in ones. +#define NETIF_MAX 8 diff --git a/include/pci.h b/include/pci.h index d3fa02a..f919ffb 100644 --- a/include/pci.h +++ b/include/pci.h @@ -53,7 +53,10 @@ #define PCI_ANY 0xFFFF // wildcard in a match table -#define NPCI 64 // devices we will remember +// Devices we will remember. A laptop has 30 to 60 functions, a desktop with +// a couple of cards and Thunderbolt more than 64, and every one past the limit +// was ignored -- including whatever disk or NIC came last in bus order. +#define NPCI 256 struct pci_bar { uint64 base; // already masked; 0 means "no BAR here" diff --git a/include/socket.h b/include/socket.h index d12eb26..54af05e 100644 --- a/include/socket.h +++ b/include/socket.h @@ -260,7 +260,7 @@ struct rtattr { #ifdef _KERNEL_SOCKET_INTERNALS -#define NSOCK 32 // sockets in the system +#define NSOCK 128 // sockets in the system, 4.9 KB each #define SOCKBUF 4096 // receive buffer per connected socket #define NBACKLOG 8 diff --git a/kernel/dev/device.c b/kernel/dev/device.c index 53a7b45..7831fe6 100644 --- a/kernel/dev/device.c +++ b/kernel/dev/device.c @@ -93,11 +93,13 @@ device_add(const char *base, enum dev_bus bus, enum dev_class class, d->name[n] = base[n]; n++; } - // Single digit is enough for NDEVICE of 32 per base name, and a two-digit - // path that is never taken is a two-digit path that is never tested. + // Two digits once there are ten of a kind. This clamped at 9, so the tenth + // and every later disk or interface of one kind were all called "...9". + if (idx > 99) + idx = 99; if (idx > 9) - idx = 9; - d->name[n++] = (char)('0' + idx); + d->name[n++] = (char)('0' + idx / 10); + d->name[n++] = (char)('0' + idx % 10); d->name[n] = '\0'; return d; diff --git a/kernel/drivers/usb/core/usb.c b/kernel/drivers/usb/core/usb.c index 37780e4..17c9aca 100644 --- a/kernel/drivers/usb/core/usb.c +++ b/kernel/drivers/usb/core/usb.c @@ -130,9 +130,10 @@ parse_config(struct usb_dev *dev, int nth) } // One usb_dev for every interface after the first. See `base` in -// include/usb.h. A fixed pool, like everything else here: sixteen is more -// interfaces than a desk of keyboards, mice and receivers adds up to. -#define NIFDEV 16 +// include/usb.h. A fixed pool, like everything else here. It was sixteen, +// which a dock -- hub, Ethernet, audio, card reader, each two or three +// interfaces -- and a couple of receivers already reach. 672 bytes each. +#define NIFDEV 64 static struct usb_dev ifdevs[NIFDEV]; // ---------------------------------------------------------------------------