From nobody Thu Nov 2 13:40:12 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 4SLlP92y97z50Lq1; Thu, 2 Nov 2023 13:40:13 +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 4SLlP86yqNz4Pdk; Thu, 2 Nov 2023 13:40:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698932413; 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=zUqe3flrzxUUwm7S/XCrR6dtN3v84BTEmJurxGAiKl0=; b=yOBmcCKRp3EEXHrO/zFpP0qXCAFHkfAJl/jnIPH8RCyn95sUQ5UW5eo9CdTXUu+XRYit7H 2JYmKMqTuTnqLZlwP4NzjRyZvIxns4HP+D//qi1IqqdzoieqJMxkFXkxqmXmwZRovXotM6 OTyWboWzzLkHT0UomooSomcRZ3doKixjxTz3G9EbIz3dlf4dKze9YOkC8+zBtzZly+JbwS 2VqQ7w0aAKGWrP+aAfg8WByQBUJjZY9qCLfmgG0Pgl8TxEsynoRcskZuGmKCvZcXeClkwR ERzXrD6qJY3dtFMVc8Q8w1Ziz97J6XLvrT8pXHxkB8gFCWFTuZFqDwE+rTcwGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698932413; 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=zUqe3flrzxUUwm7S/XCrR6dtN3v84BTEmJurxGAiKl0=; b=Ui1Pes7+tpF5wHqtEffi1Tp0jft7ffX4Ykp3Fu0XLYOn9ZMhuskGWAPg4MPL6kfBP73t5H RhqK0TRUqJmoKz612d/Aznr3ystJsG1ads+w06ndkwGDGqgDAlmFRh/c9BLe93OcMX5m7A wGc1u1xXMFRSarULj9lAWdywyQh8zaqPyTMwCQ5Gv6RFiQJI2uGaJ0734LIDTOZRk0wN1l aewazHN2GsAcPZzuVqsUu7f6YgBF7J3Po7tS0VzgtnP2K6SnnwJszX2hSe9XLf+jXvDIwQ qFc8ygQNXysu94PJsRmUOzgaFvnxsesmDJzeziPl6NMCHm6jHpmF3dHvSKvV4g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1698932413; a=rsa-sha256; cv=none; b=X+FElF/xu0Gl7ox7jBKsYg62cf1wM2iggNqJiDEvzMRNWc8zGEuO/OmpRFYfhNUnPbBleg tEi6p/u/7AHaScadZb4ZQjLIXbJ/WAZbDTMxHTSr4/Mm2B2lYRg/Uu5M8JvDjbc2wG+7SW fZ7sMPKl6WG9rHseZmOzCv1TOFeszfbCyCaH/7UMTRPxqv5RHneLji1zsVOLtwUc0MbF2w cs3YMu1cDFczFDpTBewtxT3GumKwYguTkjOl03hD2zRN6hEqDgoDid6q09Xf0fmoujV3yu hscafwSCXrWa8uH7TdPV2LwOsv5f/yB308mXUAxL//KZmixur4jhNeS/yXfw2Q== 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 4SLlP862FQzWjl; Thu, 2 Nov 2023 13:40:12 +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 3A2DeCYI031195; Thu, 2 Nov 2023 13:40:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3A2DeCcx031188; Thu, 2 Nov 2023 13:40:12 GMT (envelope-from git) Date: Thu, 2 Nov 2023 13:40:12 GMT Message-Id: <202311021340.3A2DeCcx031188@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 7d1469e555bd - main - 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/main X-Git-Reftype: branch X-Git-Commit: 7d1469e555bdce32b3dfc898478ae5564d5072b1 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=7d1469e555bdce32b3dfc898478ae5564d5072b1 commit 7d1469e555bdce32b3dfc898478ae5564d5072b1 Author: Olivier Certner AuthorDate: 2023-10-13 08:52:31 +0000 Commit: Mark Johnston CommitDate: 2023-11-02 13:30:03 +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 --- 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 3bc8546db594..d948665392d4 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)