From nobody Fri Nov 01 17:55:48 2024 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 4Xg7nc58GNz5cC0M; Fri, 01 Nov 2024 17:55:48 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Xg7nc4Dyqz4FPM; Fri, 1 Nov 2024 17:55:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730483748; 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=j74uT77FyMeg1waybl2o5e0gARio30Iv1V4qoj66Fog=; b=tYHngvhmfBh5xyWoHKu8UKbU8w/T2SoczdouqBz2t0bo2/RwJ+BnwG0LkUPleNtcbodpbo yNVTHFiMw4/3EL5jA/SVcHEdX4HscZBH59qqlAatoYzfAksT3IT5sWCUVScJw0d99g3Tdj 7/0IvJjzPT/zCVnYB88KIabkltByEK4pm8FkDLQDf+5GvHe2S4uwWXIDTuaJl8+BdSU1l1 h+oJXP4YWriN+7MJtgRFK5c2SYpE1MCrGvVJPEg4obw8Rxv2J7yI/loxoBnGq2YjKVcNOq yEOjsgKnlf4xtwfQxdJrWhKjLt00q9oWaKeF0kU+eVja2GhUVebdnvx2bbw5ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730483748; 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=j74uT77FyMeg1waybl2o5e0gARio30Iv1V4qoj66Fog=; b=LTwXXje+h0sM8TJTPhvWbnLeELD/wwfjXidFt2mNGbSgLaC9tXszm38ABvw0e+BBzLdfei UUHUX1hGJEUPSi18TlNvvl6bFx8X5sxI2XIMxhTbq6Sirmm6/Evf4jjvuPLkRnKe6SdV9v Zh/XaEww4UtN3uN1nofQ+72yXoxwS/E0lXP2LbUuqSwjqhhhMpQvE8INbLNjUOGQoiBrEe IVPTrjiPXufm5M3ZT2QldClbGGs0Oo0KHPHfGOyklTfB/dqmWzhYZw6dC15qsesdc7W6Jw dbCSxohJ7uZ3EjS3SHZ/mOQY1FOvYptKC5ape2VOvQVHNGwJkOYxXvUdyV1YAg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730483748; a=rsa-sha256; cv=none; b=qu0+4t4aheLZU3ANkJf0jwXi6rjvBcj1CZ7+izU1MWQO/aKoCyOeKPi35n9kYuF06bjg8C lOmT4qCr+j1QCCI8PDjeDYX+BdFPMpjYfm4gBV1tF6wGzafi1oaLmBaTBiaFPY5e+1MKMs zNrpz3gBCiHVwdTNhOJy/+Kp9gNACK0fpiK6A2OwNeVbR6/z329aze9k4RZqjB77a3w9zY nYq0Zl5U2UJb+oWYThMJ28JPQzt0JjhQ8FRwPmoynwzVkGkcKovVtt5aEWw/klAeuyn3qv JiT/tR5upcOYsqbo/4LFDWbxyN1PlUFm3VfO+fC+eItqNZVLIGYZxDMXrLjAFw== 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 4Xg7nc3rVdzW09; Fri, 1 Nov 2024 17:55:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4A1HtmL5072483; Fri, 1 Nov 2024 17:55:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A1HtmtH072479; Fri, 1 Nov 2024 17:55:48 GMT (envelope-from git) Date: Fri, 1 Nov 2024 17:55:48 GMT Message-Id: <202411011755.4A1HtmtH072479@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: f3d3c63442ff - main - newbus: Simplify reallocation of devices 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: 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: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f3d3c63442fff813d4941e0c73b7260834642422 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=f3d3c63442fff813d4941e0c73b7260834642422 commit f3d3c63442fff813d4941e0c73b7260834642422 Author: Warner Losh AuthorDate: 2024-10-31 22:50:42 +0000 Commit: Warner Losh CommitDate: 2024-11-01 17:56:20 +0000 newbus: Simplify reallocation of devices array Simplify the complex expression down to what it is on 64-bit systems. 32-bit kernels would allocate 2 at a time. Replace all that with reallocf which will eliminate a bunch of copies. This should be faster and simpler on both types of kernels. In addition, transition to M_WAITOK since this is a sleepable context. Suggested by: jhb Sponsored by: Netflix Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D47362 --- sys/kern/subr_bus.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 8fec2b3de139..cd5f97cc72fe 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -1229,28 +1229,18 @@ devclass_alloc_unit(devclass_t dc, device_t dev, int *unitp) } /* - * We've selected a unit beyond the length of the table, so let's - * extend the table to make room for all units up to and including - * this one. + * We've selected a unit beyond the length of the table, so let's extend + * the table to make room for all units up to and including this one. */ if (unit >= dc->maxunit) { - device_t *newlist, *oldlist; int newsize; - oldlist = dc->devices; - newsize = roundup((unit + 1), - MAX(1, MINALLOCSIZE / sizeof(device_t))); - newlist = malloc(sizeof(device_t) * newsize, M_BUS, M_NOWAIT); - if (!newlist) - return (ENOMEM); - if (oldlist != NULL) - bcopy(oldlist, newlist, sizeof(device_t) * dc->maxunit); - bzero(newlist + dc->maxunit, + newsize = unit + 1; + dc->devices = reallocf(dc->devices, + newsize * sizeof(*dc->devices), M_BUS, M_WAITOK); + memset(dc->devices + dc->maxunit, 0, sizeof(device_t) * (newsize - dc->maxunit)); - dc->devices = newlist; dc->maxunit = newsize; - if (oldlist != NULL) - free(oldlist, M_BUS); } PDEBUG(("now: unit %d in devclass %s", unit, DEVCLANAME(dc)));