From nobody Thu May 16 07:41:24 2024 X-Original-To: dev-commits-src-main@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 4Vg28h6BHgz5Kmy0; Thu, 16 May 2024 07:41: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 4Vg28h5l8dz4LwC; Thu, 16 May 2024 07:41:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715845284; 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=wv5nxC3PH2pGLMU38SRF4ypIwiBrBQzBMQ2wFskuuuc=; b=Jg963ThGviwus9ENrD2i/QDmXyvzmJ7cZyrZrMYfoOIdMtCJh4PM910Zqg5TzDD/3d18w/ QKIXNy9ZDLBtD4mPIrOBl1Rki9zSTtpd4EXvkA34Wq0H7OgKpBTWBBL2LEOR09dBRh6sMO FCTWBsPbScsA5Vh7QXB6r9RJpTrb8E0VowQ/mv636b8sLGHjkrDxJnTRr/gk2/OTdh4cwj JXUnShi0fR18+vtNZz8FvScev71pj7s92uyNTa0Vr/rd3fSQG1egbuhIEH/IlOVPZU0KKn 4QaR6VNiUrXC22Mhd7CFxpmbIiraU/s8IJkW/48Uu14T/zujqzslUD6CzzMkFQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715845284; a=rsa-sha256; cv=none; b=iT0Ilul0frL4bDCExdxOXJpAA0zKZGjDJFnIx/6byuhhgjvuZpaxAnav1op4um4a61wkDx JvAbnsT89rD/RM8mLmCSzzrLeg6qWzPW0Aj6JqcKCafsPsoBTSuX0zcmmlGa09vS5ijA2N IqVktVvpwrt4WGV56PaDMWtJfRWongydLwiMat/wrtqQWtRvJqOgzn8vBuerUTdhuXYnSg CSFPkFzhmwUF2jACU0Q09zBpL+XLapDjCSBG1XtwMTZAzIYcF4A45osv8KL93HV5aL8RL+ mH9/T1hqw0vSc5CXxJ0UrRBn+jYO1kc0/LqihhUgGf1DTI5fjDfkvJrPmnWnYg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715845284; 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=wv5nxC3PH2pGLMU38SRF4ypIwiBrBQzBMQ2wFskuuuc=; b=SkspH0SvBVIvDEKlqFvLAacHAwCkueHQ8ZyxmPve32DrC2J80OYTQpNUUGzKQhvP5dK8dq JUr9Rail+zes+YKclcusQqaxcpf5K7yfLqhNHj7rmSKQu6zESTHUUMe/8AA0wF+GlBzQHH zePewowfxpyn2fW2/kgKRoOPWt12O36L8McmzeTZqBLQQGFiH9PHiQ2DnToyYRkLnCYQaS 8cbZ5TrbETPxDrwuVXeEznsHQFvVYokKKLzeQESwaPiPcz6H06Z2CgdK39L+hYJLmCNTtC Di95NRShKzvvVdggVqt3yXC4/JA9ZLZjbS91FGXKkyHARG/bLQjISf8cyVhqLg== 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 4Vg28h5LsMzqG9; Thu, 16 May 2024 07:41:24 +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 44G7fO9v068027; Thu, 16 May 2024 07:41:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44G7fOPE068024; Thu, 16 May 2024 07:41:24 GMT (envelope-from git) Date: Thu, 16 May 2024 07:41:24 GMT Message-Id: <202405160741.44G7fOPE068024@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: ae38a1a1bfdf - main - linuxkpi: spinlock: Simplify code List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ae38a1a1bfdf320089c254e4dbffdf4769d89110 Auto-Submitted: auto-generated The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=ae38a1a1bfdf320089c254e4dbffdf4769d89110 commit ae38a1a1bfdf320089c254e4dbffdf4769d89110 Author: Emmanuel Vadot AuthorDate: 2024-05-15 09:00:04 +0000 Commit: Emmanuel Vadot CommitDate: 2024-05-16 07:39:36 +0000 linuxkpi: spinlock: Simplify code Just use a typedef for spinlock_t, no need to create a useless structure. Reviewed by: bz, emaste Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D45205 --- .../linuxkpi/common/include/linux/spinlock.h | 34 +++++++--------------- sys/compat/linuxkpi/common/include/linux/wait.h | 2 +- sys/compat/linuxkpi/common/src/linux_compat.c | 8 ++--- sys/compat/linuxkpi/common/src/linux_idr.c | 2 +- sys/dev/mlx4/mlx4_en/mlx4_en_tx.c | 8 ++--- 5 files changed, 20 insertions(+), 34 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/spinlock.h b/sys/compat/linuxkpi/common/include/linux/spinlock.h index 4bc1e2a2d431..3f6eb4bb70f6 100644 --- a/sys/compat/linuxkpi/common/include/linux/spinlock.h +++ b/sys/compat/linuxkpi/common/include/linux/spinlock.h @@ -41,9 +41,7 @@ #include #include -typedef struct { - struct mtx m; -} spinlock_t; +typedef struct mtx spinlock_t; /* * By defining CONFIG_SPIN_SKIP LinuxKPI spinlocks and asserts will be @@ -59,7 +57,7 @@ typedef struct { #define spin_lock(_l) do { \ if (SPIN_SKIP()) \ break; \ - mtx_lock(&(_l)->m); \ + mtx_lock(_l); \ local_bh_disable(); \ } while (0) @@ -76,7 +74,7 @@ typedef struct { if (SPIN_SKIP()) \ break; \ local_bh_enable(); \ - mtx_unlock(&(_l)->m); \ + mtx_unlock(_l); \ } while (0) #define spin_unlock_bh(_l) do { \ @@ -93,7 +91,7 @@ typedef struct { if (SPIN_SKIP()) { \ __ret = 1; \ } else { \ - __ret = mtx_trylock(&(_l)->m); \ + __ret = mtx_trylock(_l); \ if (likely(__ret != 0)) \ local_bh_disable(); \ } \ @@ -111,7 +109,7 @@ typedef struct { #define spin_lock_nested(_l, _n) do { \ if (SPIN_SKIP()) \ break; \ - mtx_lock_flags(&(_l)->m, MTX_DUPOK); \ + mtx_lock_flags(_l, MTX_DUPOK); \ local_bh_disable(); \ } while (0) @@ -141,31 +139,19 @@ typedef struct { #define _spin_lock_name(...) __spin_lock_name(__VA_ARGS__) #define spin_lock_name(name) _spin_lock_name(name, __FILE__, __LINE__) -#define spin_lock_init(lock) linux_spin_lock_init(lock, spin_lock_name("lnxspin")) +#define spin_lock_init(lock) mtx_init(lock, spin_lock_name("lnxspin"), \ + NULL, MTX_DEF | MTX_NOWITNESS) -static inline void -linux_spin_lock_init(spinlock_t *lock, const char *name) -{ - - memset(lock, 0, sizeof(*lock)); - mtx_init(&lock->m, name, NULL, MTX_DEF | MTX_NOWITNESS); -} - -static inline void -spin_lock_destroy(spinlock_t *lock) -{ - - mtx_destroy(&lock->m); -} +#define spin_lock_destroy(_l) mtx_destroy(_l) #define DEFINE_SPINLOCK(lock) \ spinlock_t lock; \ - MTX_SYSINIT(lock, &(lock).m, spin_lock_name("lnxspin"), MTX_DEF) + MTX_SYSINIT(lock, &lock, spin_lock_name("lnxspin"), MTX_DEF) #define assert_spin_locked(_l) do { \ if (SPIN_SKIP()) \ break; \ - mtx_assert(&(_l)->m, MA_OWNED); \ + mtx_assert(_l, MA_OWNED); \ } while (0) #define atomic_dec_and_lock_irqsave(cnt, lock, flags) \ diff --git a/sys/compat/linuxkpi/common/include/linux/wait.h b/sys/compat/linuxkpi/common/include/linux/wait.h index d50003d44955..b815050b6faa 100644 --- a/sys/compat/linuxkpi/common/include/linux/wait.h +++ b/sys/compat/linuxkpi/common/include/linux/wait.h @@ -113,7 +113,7 @@ extern wait_queue_func_t default_wake_function; MTX_SYSINIT(name, &(name).lock.m, spin_lock_name("wqhead"), MTX_DEF) #define init_waitqueue_head(wqh) do { \ - mtx_init(&(wqh)->lock.m, spin_lock_name("wqhead"), \ + mtx_init(&(wqh)->lock, spin_lock_name("wqhead"), \ NULL, MTX_DEF | MTX_NEW | MTX_NOWITNESS); \ INIT_LIST_HEAD(&(wqh)->task_list); \ } while (0) diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c index a6eb7bb17e16..4c639c1f8459 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c +++ b/sys/compat/linuxkpi/common/src/linux_compat.c @@ -382,9 +382,9 @@ linux_kq_assert_lock(void *arg, int what) spinlock_t *s = arg; if (what == LA_LOCKED) - mtx_assert(&s->m, MA_OWNED); + mtx_assert(s, MA_OWNED); else - mtx_assert(&s->m, MA_NOTOWNED); + mtx_assert(s, MA_NOTOWNED); #endif } @@ -1094,7 +1094,7 @@ linux_file_kqfilter_read_event(struct knote *kn, long hint) { struct linux_file *filp = kn->kn_hook; - mtx_assert(&filp->f_kqlock.m, MA_OWNED); + mtx_assert(&filp->f_kqlock, MA_OWNED); return ((filp->f_kqflags & LINUX_KQ_FLAG_NEED_READ) ? 1 : 0); } @@ -1104,7 +1104,7 @@ linux_file_kqfilter_write_event(struct knote *kn, long hint) { struct linux_file *filp = kn->kn_hook; - mtx_assert(&filp->f_kqlock.m, MA_OWNED); + mtx_assert(&filp->f_kqlock, MA_OWNED); return ((filp->f_kqflags & LINUX_KQ_FLAG_NEED_WRITE) ? 1 : 0); } diff --git a/sys/compat/linuxkpi/common/src/linux_idr.c b/sys/compat/linuxkpi/common/src/linux_idr.c index dc64da0d7cf5..583e2c237198 100644 --- a/sys/compat/linuxkpi/common/src/linux_idr.c +++ b/sys/compat/linuxkpi/common/src/linux_idr.c @@ -69,7 +69,7 @@ idr_preload_dequeue_locked(struct linux_idr_cache *lic) struct idr_layer *retval; /* check if wrong thread is trying to dequeue */ - if (mtx_owned(&lic->lock.m) == 0) + if (mtx_owned(&lic->lock) == 0) return (NULL); retval = lic->head; diff --git a/sys/dev/mlx4/mlx4_en/mlx4_en_tx.c b/sys/dev/mlx4/mlx4_en/mlx4_en_tx.c index ee8ed0da240d..9a73c7571fd7 100644 --- a/sys/dev/mlx4/mlx4_en/mlx4_en_tx.c +++ b/sys/dev/mlx4/mlx4_en/mlx4_en_tx.c @@ -91,8 +91,8 @@ int mlx4_en_create_tx_ring(struct mlx4_en_priv *priv, ring->size_mask = size - 1; ring->stride = stride; ring->inline_thold = MAX(MIN_PKT_LEN, MIN(priv->prof->inline_thold, MAX_INLINE)); - mtx_init(&ring->tx_lock.m, "mlx4 tx", NULL, MTX_DEF); - mtx_init(&ring->comp_lock.m, "mlx4 comp", NULL, MTX_DEF); + mtx_init(&ring->tx_lock, "mlx4 tx", NULL, MTX_DEF); + mtx_init(&ring->comp_lock, "mlx4 comp", NULL, MTX_DEF); tmp = size * sizeof(struct mlx4_en_tx_info); ring->tx_info = kzalloc_node(tmp, GFP_KERNEL, node); @@ -205,8 +205,8 @@ void mlx4_en_destroy_tx_ring(struct mlx4_en_priv *priv, for (x = 0; x != ring->size; x++) bus_dmamap_destroy(ring->dma_tag, ring->tx_info[x].dma_map); vfree(ring->tx_info); - mtx_destroy(&ring->tx_lock.m); - mtx_destroy(&ring->comp_lock.m); + mtx_destroy(&ring->tx_lock); + mtx_destroy(&ring->comp_lock); bus_dma_tag_destroy(ring->dma_tag); kfree(ring); *pring = NULL;