From nobody Tue Jun 27 11:56:55 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 4Qr3934bvWz4hf6w; Tue, 27 Jun 2023 11:56:55 +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 4Qr39348Jlz4LHS; Tue, 27 Jun 2023 11:56:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687867015; 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=4CxPlQhA1eVMtjRuffAdnq+ba1KkM8TOoUC2VkY5l8g=; b=xDVIarMDkMf3uc4pN/V/eRWo7Sw+CCiKZ562Pf9ihxA5Iuu253hInj/MyrElj+Hnwra/Bv XG+6xxZ5plzLUDlBV/Kmhm5QJEcgYItjAwBS2TBoKyQBIE1/aSKDWq4xVHsIZK7jS9mHD+ 8TC3xPb2PraNqe2pc0sqoRm8tF0pC1UhWmGKVBEzurFO4W5l/oF7CO5vQNlbK/lOyRBlqb 3pxl89K5DDxp9JrKQ1E7tMFCgvu9jW0UxcGSv9TygvbD1Qq++6ibrvMz/uPjdkByPIR+5A YcW1A7cyoM5YPhciXi9YjZGsP0WmHo8KyXU+S3ECYLnPoeTxVEimG0NKs4mL6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687867015; 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=4CxPlQhA1eVMtjRuffAdnq+ba1KkM8TOoUC2VkY5l8g=; b=eyQ4g3r2oQXxrjvRf/wRT6luPbJYlR1MkoxlA+mq9FO0BVicYQi28AkJFnrTqcWonSZvuD lt5AAN1NpoJKJFGVXywkch/9VTuqFXz9PBiYGyx7THWwqnO4JJYtKPHHPwq0ejyNdxbKy+ kuvvUmgRaTKhjmJjDf9eDJE0byMOESwRV2LsGSsGucJaMfjYiYK5TmgdQXG4YJiCOfEMiF Ff7sh7DzdiUOTPI9YuhTBLQwGMuu0U+SwRofggcK1p+OAfa0dIXvMyNN8yDskjMe2IWiXo /Gy0Azh9InqEN152NLIsMuDK3FE7wFjKjSV6+CrEPWTER4UjWMHSbYCENYcGEQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1687867015; a=rsa-sha256; cv=none; b=W8XdUYNfm1+qGHdU7ty16jgysCjWvriEV4KsJDL/yThbXQHMn6QALJXXDrcdpZBtRlK0zG qCk+bCSyajG1t1WdDaHgkFzEJ4Jblw6cyg7uLLHTTO5+X8e5Pb4SdE9EBSzUVzkG4cnLjm YTQvM05DWqBD7KahC/l3HdQdLABo1g3KS7VA2ghVYs9uq8tEOMpqN1oUWrjZWvjLIXqo3x 8VuYmZnIW89+w3rkOK5EDLMDHI6LT8h/xd2abKfvaad/lfGuR3Yv79xC8MjX29/aUn1r1b KA2eLbZz3hPJey3Cf12kWa1N2Ywx203QHt6ZRWNxSS3kySafMbnCv+yiWLVwng== 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 4Qr3933F6zzrTW; Tue, 27 Jun 2023 11:56:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 35RButuw071801; Tue, 27 Jun 2023 11:56:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35RButXO071800; Tue, 27 Jun 2023 11:56:55 GMT (envelope-from git) Date: Tue, 27 Jun 2023 11:56:55 GMT Message-Id: <202306271156.35RButXO071800@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: a6c0d801ca59 - main - libpthread: allocate rwlocks and spinlocks in dedicated cachelines 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: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a6c0d801ca5934bb9b9cca6870ea7406d5db0641 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=a6c0d801ca5934bb9b9cca6870ea7406d5db0641 commit a6c0d801ca5934bb9b9cca6870ea7406d5db0641 Author: Greg Becker AuthorDate: 2023-06-27 01:08:29 +0000 Commit: Mateusz Guzik CommitDate: 2023-06-27 11:56:44 +0000 libpthread: allocate rwlocks and spinlocks in dedicated cachelines Reduces severe performance degradation due to false-sharing. Note that this does not account for hardware which can perform adjacent cacheline prefetch. [mjg: massaged the commit message and the patch to use aligned_alloc instead of malloc] PR: 272238 MFC after: 1 week --- lib/libthr/thread/thr_pspinlock.c | 3 ++- lib/libthr/thread/thr_rwlock.c | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/libthr/thread/thr_pspinlock.c b/lib/libthr/thread/thr_pspinlock.c index 089416a18a07..374fe498034b 100644 --- a/lib/libthr/thread/thr_pspinlock.c +++ b/lib/libthr/thread/thr_pspinlock.c @@ -60,7 +60,8 @@ _pthread_spin_init(pthread_spinlock_t *lock, int pshared) if (lock == NULL) return (EINVAL); if (pshared == PTHREAD_PROCESS_PRIVATE) { - lck = malloc(sizeof(struct pthread_spinlock)); + lck = aligned_alloc(CACHE_LINE_SIZE, + roundup(sizeof(struct pthread_spinlock), CACHE_LINE_SIZE)); if (lck == NULL) return (ENOMEM); *lock = lck; diff --git a/lib/libthr/thread/thr_rwlock.c b/lib/libthr/thread/thr_rwlock.c index b7526376a9a3..3e8af974fa18 100644 --- a/lib/libthr/thread/thr_rwlock.c +++ b/lib/libthr/thread/thr_rwlock.c @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include "namespace.h" #include @@ -102,9 +103,11 @@ rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr) if (attr == NULL || *attr == NULL || (*attr)->pshared == PTHREAD_PROCESS_PRIVATE) { - prwlock = calloc(1, sizeof(struct pthread_rwlock)); + prwlock = aligned_alloc(CACHE_LINE_SIZE, + roundup(sizeof(struct pthread_rwlock), CACHE_LINE_SIZE)); if (prwlock == NULL) return (ENOMEM); + memset(prwlock, 0, sizeof(struct pthread_rwlock)); *rwlock = prwlock; } else { prwlock = __thr_pshared_offpage(rwlock, 1);