From nobody Tue Dec 13 09:25:23 2022 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 4NWY4h2fN4z4kcv3; Tue, 13 Dec 2022 09:25:24 +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 4NWY4h263Qz4XvC; Tue, 13 Dec 2022 09:25:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670923524; 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=lEzpZlhSXW5Kv6+HTv1+YvTnnZeQL946GTPWzCxNygk=; b=M7HZaaggJD4eVznsFSKh4EOLqfiwG0z8gebVFs5EGuRkOwKlFFvdz3jfPGOc3gCD6ruXim mqpYwQe/hR36iJWDbPU61m5h6RGw2zjPlFyAZWb0k0N8ChsF26+9OwVLe+kfG3SiKp2WeA wKwQjvdtfnUD2NVoZR83fJvuDT9TOGJkzXsMzqi/fxi3Krr9u1dxokeDp8nx5SN6Wybrv4 iakFpvpGyFhj0Qkgin3iO9qpyklZeyuBZ0T0h7Fegs+/LZRZjVPaeRQFKS9nlYNEJUCnc4 OmxHC0x9h1/iEtvchhKT5UFBNqyhRTo3pm5P7Z5pZDg00an+5OWokzCzoVCyXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670923524; 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=lEzpZlhSXW5Kv6+HTv1+YvTnnZeQL946GTPWzCxNygk=; b=Yz2x+YYRwXRzcSBAPTvCrDgbIazJWsePERdVhbik60E7CTXZeuReFwXVVAL8+pHoHJyJrK kY0w4AdT+7irfnJiQH4pIAnsivaDd4ePOVxTgvryM2861RCaCsA4gBQ89N8sTbONI5WHXP p8v0TcTbVtJi4QeatVSUD5ShJdoBNvoSm4t1s5FfSJobS74VKe3Yu/TS8EOLhl+075UnXu qTi7iZexJBnj3u9WRSqz4dEeXHN0CewMFZClmGWmkopANLgCrlwLBzZy0bPJzSUhWRkYwN axV238UGkMClnyKvPf0MROxTVN0qiLPz8fgAVItb3L6cM1kzIp+W2gjOs34PHQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670923524; a=rsa-sha256; cv=none; b=uE+WB86yBsdxnKSnoHqwKPK/FckW6J9nEBcUw0AOIsUDJ0avr4NpDyGQSkTgtk3nrmHVV0 Z1oTLGy21hS0e10+rBxY8bgf/8TZASvfd9hUYRI2xWv1OFHVwJ8iqXNzyO3/lzwEJs6B4/ XEPXUiItP2Vl1XkXMc/nMk44dsoZ3UTe7Yttx5AFoIL5YJ92uC0CGjGi04WC1EE/ovDuZL /+jKzcY2QQTaU5WffiJalEv/kSFi0HjlzTCuusbUNspb5hp4/afstxuIIeRVA2m+S83rtc NSh5k0L6mnDpKPuBgX7/2aXpp9rPJEGEBQvLQfNOKC4OssWM0a28UixaG4gxOA== 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 4NWY4h0gRXz17qD; Tue, 13 Dec 2022 09:25:24 +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 2BD9PNcd090003; Tue, 13 Dec 2022 09:25:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BD9PNWE090002; Tue, 13 Dec 2022 09:25:23 GMT (envelope-from git) Date: Tue, 13 Dec 2022 09:25:23 GMT Message-Id: <202212130925.2BD9PNWE090002@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: 67e628b7a643 - main - kref: replace hand-rolled atomic ops with refcount API 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: 67e628b7a6432c1ab296b0c936dffc42df357d82 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=67e628b7a6432c1ab296b0c936dffc42df357d82 commit 67e628b7a6432c1ab296b0c936dffc42df357d82 Author: Mateusz Guzik AuthorDate: 2022-12-05 17:38:45 +0000 Commit: Mateusz Guzik CommitDate: 2022-12-13 09:24:57 +0000 kref: replace hand-rolled atomic ops with refcount API Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D37608 --- sys/compat/linuxkpi/common/include/linux/kref.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/kref.h b/sys/compat/linuxkpi/common/include/linux/kref.h index 3b5645bf139b..9a6814175223 100644 --- a/sys/compat/linuxkpi/common/include/linux/kref.h +++ b/sys/compat/linuxkpi/common/include/linux/kref.h @@ -44,35 +44,35 @@ struct kref { /* XXX In Linux this is a refcount_t */ - atomic_t refcount; + volatile u_int32_t refcount; }; static inline void kref_init(struct kref *kref) { - refcount_init(&kref->refcount.counter, 1); + refcount_init(&kref->refcount, 1); } static inline unsigned int -kref_read(const struct kref *kref) +kref_read(struct kref *kref) { - return (atomic_read(&kref->refcount)); + return (refcount_load(&kref->refcount)); } static inline void kref_get(struct kref *kref) { - refcount_acquire(&kref->refcount.counter); + refcount_acquire(&kref->refcount); } static inline int kref_put(struct kref *kref, void (*rel)(struct kref *kref)) { - if (refcount_release(&kref->refcount.counter)) { + if (refcount_release(&kref->refcount)) { rel(kref); return 1; } @@ -84,7 +84,7 @@ kref_put_lock(struct kref *kref, void (*rel)(struct kref *kref), spinlock_t *lock) { - if (refcount_release(&kref->refcount.counter)) { + if (refcount_release(&kref->refcount)) { spin_lock(lock); rel(kref); return (1); @@ -98,7 +98,7 @@ kref_sub(struct kref *kref, unsigned int count, { while (count--) { - if (refcount_release(&kref->refcount.counter)) { + if (refcount_release(&kref->refcount)) { rel(kref); return 1; } @@ -110,16 +110,16 @@ static inline int __must_check kref_get_unless_zero(struct kref *kref) { - return atomic_add_unless(&kref->refcount, 1, 0); + return refcount_acquire_if_not_zero(&kref->refcount); } static inline int kref_put_mutex(struct kref *kref, void (*release)(struct kref *kref), struct mutex *lock) { WARN_ON(release == NULL); - if (unlikely(!atomic_add_unless(&kref->refcount, -1, 1))) { + if (unlikely(!refcount_release_if_not_last(&kref->refcount))) { mutex_lock(lock); - if (unlikely(!atomic_dec_and_test(&kref->refcount))) { + if (unlikely(!refcount_release(&kref->refcount))) { mutex_unlock(lock); return 0; }