From nobody Thu Nov 16 20:54:48 2023 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 4SWXN86k2Hz515Nn; Thu, 16 Nov 2023 20:54: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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SWXN866kHz4HWQ; Thu, 16 Nov 2023 20:54:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700168088; 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=DqTdFHTzU/OpV2MK0MilK3l5JuOyPEO1oLJz29hyZnQ=; b=IAxqGlwNl6KZxPZ7/sh4sTyeh3o590XwWy1niIuI35MTzpR4ZvWBANVMUVNg7deTOz2Out CvdN9Zp8f3JtpsFcgfkyXidzZFKSVIj93I3pLwsOJDU47bS2TufPBszIfDYkf0Kr32rxTM qf7oNwfcvJsa2cReU4C1YV6tOm1PjA/qL0Hpz8N2TlMHMBybUbhy0HsBg8qooDZj+jDhVw xMj7XsoCkVx3OVYfGNx6g9IOe0i93sS1ZCXMvnnFwAavLITQlzcqYWi46SW3liyhpEQP3g yUvX3xe/kbcyEAT74kmHuwnR3FIE+iJtEaMyuAFx7wr5DSaSqOBRqj073OWIEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700168088; 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=DqTdFHTzU/OpV2MK0MilK3l5JuOyPEO1oLJz29hyZnQ=; b=KvkrQWUAkAKFqe+2I58bWIT/TMfEQbgS6FNsbg2+z0JPleGzwt7SyXSc70wEnPA1iZ9rh7 /l1OtdqpimT3SkuV4njMrTRPUzchjhvAM255fZU3/wCkwW7atoIPewNsygFoh6GF66UJn9 up1KwUYOe1qoeGNSOPumP9qVBxQH5RGhrNF0WpnygC1nnqi6/vPdm+N6hQadAbJTQKph/o E5v+cE8uKL6ne2eE+3WZr+2q3cpwZE2ikA2GzGtapcjgpyV80lmfwSBhwCp2SI4MJiF/pp HpYxmT8IpGDgD3iVtpEqhceC0qFdGGO1wEBS+Vbcdxv6CJIzdqW/okstBmZyIw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1700168088; a=rsa-sha256; cv=none; b=rRnIbt9P2Erig5H/ht0FJa+fvIGDuZi+FsVhOGaTO5htAznnYcrUJ+sVIuRbXLkoYh6xoT rNdSdTqLGHTb5tbrBB60Njx/uzKAPDmy1AxoXwpTldkrsk3NU5QxzJfVludj7ebddY1hTs lfYQXiOOp5Q04EQA6TUFhdJeGJoutY+JelJI/osoiiseRYZIMTLkdOA/JSwA0EsWmmvgus fCutiFHad6uhQi9l5TRWJRKkyRMjfr0te7NtzBsJ/nyAw+HITEgSzNUENpw+HpSQTaD27e IApyhU2wZ0v5ysFI7635n2UxMPmwNhaTv3x4tOplci43yUUGGR9+kGdeo9pAlA== 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 4SWXN85C4pzrT; Thu, 16 Nov 2023 20:54:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3AGKsmBA054057; Thu, 16 Nov 2023 20:54:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3AGKsm9v054054; Thu, 16 Nov 2023 20:54:48 GMT (envelope-from git) Date: Thu, 16 Nov 2023 20:54:48 GMT Message-Id: <202311162054.3AGKsm9v054054@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: e191c0283e86 - stable/14 - Ensure 'struct thread' is aligned to a cache line 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org 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/stable/14 X-Git-Reftype: branch X-Git-Commit: e191c0283e8640d46ed6b725e3311d0f37f3620c Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=e191c0283e8640d46ed6b725e3311d0f37f3620c commit e191c0283e8640d46ed6b725e3311d0f37f3620c Author: Olivier Certner AuthorDate: 2023-10-13 08:52:31 +0000 Commit: Mark Johnston CommitDate: 2023-11-16 15:07:30 +0000 Ensure 'struct thread' is aligned to a cache line Using the new UMA_ALIGN_CACHE_AND_MASK() facility, which allows to simultaneously guarantee a minimum of 32 bytes of alignment (the 5 lower bits are always 0). For the record, to this day, here's a (possibly non-exhaustive) list of synchronization primitives using lower bits to store flags in pointers to thread structures: - lockmgr, rwlock and sx all use the 5 bits directly. - rmlock indirectly relies on sx, so can use the 5 bits. - mtx (non-spin) relies on the 3 lower bits. Reviewed by: markj, kib MFC after: 2 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D42266 (cherry picked from commit 7d1469e555bdce32b3dfc898478ae5564d5072b1) --- sys/kern/kern_thread.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c index 4175d1594af4..d8ba94925fec 100644 --- a/sys/kern/kern_thread.c +++ b/sys/kern/kern_thread.c @@ -568,9 +568,15 @@ threadinit(void) if (tid0 != THREAD0_TID) panic("tid0 %d != %d\n", tid0, THREAD0_TID); + /* + * Thread structures are specially aligned so that (at least) the + * 5 lower bits of a pointer to 'struct thead' must be 0. These bits + * are used by synchronization primitives to store flags in pointers to + * such structures. + */ thread_zone = uma_zcreate("THREAD", sched_sizeof_thread(), thread_ctor, thread_dtor, thread_init, thread_fini, - 32 - 1, UMA_ZONE_NOFREE); + UMA_ALIGN_CACHE_AND_MASK(32 - 1), UMA_ZONE_NOFREE); tidhashtbl = hashinit(maxproc / 2, M_TIDHASH, &tidhash); tidhashlock = (tidhash + 1) / 64; if (tidhashlock > 0)