From: NeilBrown <neilb@suse.de>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH 2/9] Introduce atomic_dec_and_wake_up_var().
Date: Mon, 19 Aug 2024 15:20:36 +1000 [thread overview]
Message-ID: <20240819053605.11706-3-neilb@suse.de> (raw)
In-Reply-To: <20240819053605.11706-1-neilb@suse.de>
There is a common pattern of atomic_dec_and_test() being followed by
wake_up_var().
So provide atomic_dec_and_wake_up_var() to do both.
A future patch will change the default barrier used by wake_up_var().
Doing this first will reduce the size of that patch.
Signed-off-by: NeilBrown <neilb@suse.de>
---
drivers/dma-buf/st-dma-fence-chain.c | 3 +--
drivers/gpu/drm/display/drm_dp_aux_dev.c | 6 ++----
drivers/gpu/drm/i915/selftests/i915_request.c | 7 +------
drivers/media/platform/qcom/venus/hfi.c | 3 +--
fs/afs/cell.c | 3 +--
fs/afs/internal.h | 3 +--
fs/afs/rxrpc.c | 4 +---
fs/btrfs/block-group.c | 6 ++----
fs/netfs/objects.c | 3 +--
fs/nfs/pagelist.c | 3 +--
fs/nfs/write.c | 6 +-----
fs/nfsd/nfs4callback.c | 4 +---
fs/reiserfs/journal.c | 3 +--
include/linux/wait_bit.h | 8 ++++++++
mm/shmem.c | 3 +--
net/rxrpc/call_accept.c | 3 +--
net/rxrpc/call_object.c | 3 +--
net/rxrpc/conn_object.c | 3 +--
net/sunrpc/xprt.c | 3 +--
19 files changed, 28 insertions(+), 49 deletions(-)
diff --git a/drivers/dma-buf/st-dma-fence-chain.c b/drivers/dma-buf/st-dma-fence-chain.c
index ed4b323886e4..36466ae588e8 100644
--- a/drivers/dma-buf/st-dma-fence-chain.c
+++ b/drivers/dma-buf/st-dma-fence-chain.c
@@ -434,8 +434,7 @@ static int __find_race(void *arg)
cond_resched();
}
- if (atomic_dec_and_test(&data->children))
- wake_up_var(&data->children);
+ atomic_dec_and_wake_up_var(&data->children);
return err;
}
diff --git a/drivers/gpu/drm/display/drm_dp_aux_dev.c b/drivers/gpu/drm/display/drm_dp_aux_dev.c
index 29555b9f03c8..bb03f1dff840 100644
--- a/drivers/gpu/drm/display/drm_dp_aux_dev.c
+++ b/drivers/gpu/drm/display/drm_dp_aux_dev.c
@@ -180,8 +180,7 @@ static ssize_t auxdev_read_iter(struct kiocb *iocb, struct iov_iter *to)
res = pos - iocb->ki_pos;
iocb->ki_pos = pos;
- if (atomic_dec_and_test(&aux_dev->usecount))
- wake_up_var(&aux_dev->usecount);
+ atomic_dec_and_wake_up_var(&aux_dev->usecount);
return res;
}
@@ -223,8 +222,7 @@ static ssize_t auxdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
res = pos - iocb->ki_pos;
iocb->ki_pos = pos;
- if (atomic_dec_and_test(&aux_dev->usecount))
- wake_up_var(&aux_dev->usecount);
+ atomic_dec_and_wake_up_var(&aux_dev->usecount);
return res;
}
diff --git a/drivers/gpu/drm/i915/selftests/i915_request.c b/drivers/gpu/drm/i915/selftests/i915_request.c
index acae30a04a94..8a45f79f10a0 100644
--- a/drivers/gpu/drm/i915/selftests/i915_request.c
+++ b/drivers/gpu/drm/i915/selftests/i915_request.c
@@ -1530,12 +1530,7 @@ static void __live_parallel_engineN(struct kthread_work *work)
static bool wake_all(struct drm_i915_private *i915)
{
- if (atomic_dec_and_test(&i915->selftest.counter)) {
- wake_up_var(&i915->selftest.counter);
- return true;
- }
-
- return false;
+ return atomic_dec_and_wakeup_var(&i915->selftest.counter);
}
static int wait_for_all(struct drm_i915_private *i915)
diff --git a/drivers/media/platform/qcom/venus/hfi.c b/drivers/media/platform/qcom/venus/hfi.c
index e00aedb41d16..4c75b827a341 100644
--- a/drivers/media/platform/qcom/venus/hfi.c
+++ b/drivers/media/platform/qcom/venus/hfi.c
@@ -255,8 +255,7 @@ void hfi_session_destroy(struct venus_inst *inst)
mutex_lock(&core->lock);
list_del_init(&inst->list);
- if (atomic_dec_and_test(&core->insts_count))
- wake_up_var(&core->insts_count);
+ atomic_dec_and_wake_up_var(&core->insts_count);
mutex_unlock(&core->lock);
}
EXPORT_SYMBOL_GPL(hfi_session_destroy);
diff --git a/fs/afs/cell.c b/fs/afs/cell.c
index caa09875f520..422bcc26becc 100644
--- a/fs/afs/cell.c
+++ b/fs/afs/cell.c
@@ -25,8 +25,7 @@ static void afs_manage_cell_work(struct work_struct *);
static void afs_dec_cells_outstanding(struct afs_net *net)
{
- if (atomic_dec_and_test(&net->cells_outstanding))
- wake_up_var(&net->cells_outstanding);
+ atomic_dec_and_wake_up_var(&net->cells_outstanding);
}
/*
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 6e1d3c4daf72..d19db6c00cae 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -1484,8 +1484,7 @@ static inline void afs_inc_servers_outstanding(struct afs_net *net)
static inline void afs_dec_servers_outstanding(struct afs_net *net)
{
- if (atomic_dec_and_test(&net->servers_outstanding))
- wake_up_var(&net->servers_outstanding);
+ atomic_dec_and_wake_up_var(&net->servers_outstanding);
}
static inline bool afs_is_probing_server(struct afs_server *server)
diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c
index c453428f3c8b..36e61b20f937 100644
--- a/fs/afs/rxrpc.c
+++ b/fs/afs/rxrpc.c
@@ -195,9 +195,7 @@ void afs_put_call(struct afs_call *call)
__builtin_return_address(0));
kfree(call);
- o = atomic_dec_return(&net->nr_outstanding_calls);
- if (o == 0)
- wake_up_var(&net->nr_outstanding_calls);
+ atomic_dec_and_wake_up_var(&net->nr_outstanding_calls);
}
}
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 2e49d978f504..d26e176fa531 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -352,8 +352,7 @@ struct btrfs_block_group *btrfs_inc_nocow_writers(struct btrfs_fs_info *fs_info,
*/
void btrfs_dec_nocow_writers(struct btrfs_block_group *bg)
{
- if (atomic_dec_and_test(&bg->nocow_writers))
- wake_up_var(&bg->nocow_writers);
+ atomic_dec_and_wake_up_var(&bg->nocow_writers);
/* For the lookup done by a previous call to btrfs_inc_nocow_writers(). */
btrfs_put_block_group(bg);
@@ -371,8 +370,7 @@ void btrfs_dec_block_group_reservations(struct btrfs_fs_info *fs_info,
bg = btrfs_lookup_block_group(fs_info, start);
ASSERT(bg);
- if (atomic_dec_and_test(&bg->reservations))
- wake_up_var(&bg->reservations);
+ atomic_dec_and_wake_up_var(&bg->reservations);
btrfs_put_block_group(bg);
}
diff --git a/fs/netfs/objects.c b/fs/netfs/objects.c
index f4a642727479..39e3ab3d0042 100644
--- a/fs/netfs/objects.c
+++ b/fs/netfs/objects.c
@@ -145,8 +145,7 @@ static void netfs_free_request(struct work_struct *work)
kvfree(rreq->direct_bv);
}
- if (atomic_dec_and_test(&ictx->io_count))
- wake_up_var(&ictx->io_count);
+ atomic_dec_and_wake_up_var(&ictx->io_count);
call_rcu(&rreq->rcu, netfs_free_request_rcu);
}
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index 04124f226665..8ae767578cd9 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -559,8 +559,7 @@ static void nfs_clear_request(struct nfs_page *req)
req->wb_page = NULL;
}
if (l_ctx != NULL) {
- if (atomic_dec_and_test(&l_ctx->io_count)) {
- wake_up_var(&l_ctx->io_count);
+ if (atomic_dec_and_wake_up_var(&l_ctx->io_count)) {
ctx = l_ctx->open_context;
if (test_bit(NFS_CONTEXT_UNLOCK, &ctx->flags))
rpc_wake_up(&NFS_SERVER(d_inode(ctx->dentry))->uoc_rpcwaitq);
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index d074d0ceb4f0..7d9d6ba5c71c 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -1646,11 +1646,7 @@ void nfs_commit_begin(struct nfs_mds_commit_info *cinfo)
bool nfs_commit_end(struct nfs_mds_commit_info *cinfo)
{
- if (atomic_dec_and_test(&cinfo->rpcs_out)) {
- wake_up_var(&cinfo->rpcs_out);
- return true;
- }
- return false;
+ return atomic_dec_and_wake_up_var(&cinfo->rpcs_out);
}
void nfs_commitdata_release(struct nfs_commit_data *data)
diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
index d756f443fc44..cef65be34525 100644
--- a/fs/nfsd/nfs4callback.c
+++ b/fs/nfsd/nfs4callback.c
@@ -993,9 +993,7 @@ static void nfsd41_cb_inflight_begin(struct nfs4_client *clp)
static void nfsd41_cb_inflight_end(struct nfs4_client *clp)
{
-
- if (atomic_dec_and_test(&clp->cl_cb_inflight))
- wake_up_var(&clp->cl_cb_inflight);
+ atomic_dec_and_wake_up_var(&clp->cl_cb_inflight);
}
static void nfsd41_cb_inflight_wait_complete(struct nfs4_client *clp)
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index e477ee0ff35d..f3da240e486b 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -1059,8 +1059,7 @@ static int flush_commit_list(struct super_block *s,
put_bh(tbh) ;
}
}
- if (atomic_dec_and_test(&journal->j_async_throttle))
- wake_up_var(&journal->j_async_throttle);
+ atomic_dec_and_wake_up_var(&journal->j_async_throttle);
for (i = 0; i < (jl->j_len + 1); i++) {
bn = SB_ONDISK_JOURNAL_1st_BLOCK(s) +
diff --git a/include/linux/wait_bit.h b/include/linux/wait_bit.h
index 7725b7579b78..178ed8bed91c 100644
--- a/include/linux/wait_bit.h
+++ b/include/linux/wait_bit.h
@@ -335,4 +335,12 @@ static inline void clear_and_wake_up_bit(int bit, void *word)
wake_up_bit(word, bit);
}
+static inline bool atomic_dec_and_wake_up_var(atomic_t *var)
+{
+ if (!atomic_dec_and_test(var))
+ return false;
+ wake_up_var(var);
+ return true;
+}
+
#endif /* _LINUX_WAIT_BIT_H */
diff --git a/mm/shmem.c b/mm/shmem.c
index 5a77acf6ac6a..414c69d7596f 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1421,8 +1421,7 @@ int shmem_unuse(unsigned int type)
next = list_next_entry(info, swaplist);
if (!info->swapped)
list_del_init(&info->swaplist);
- if (atomic_dec_and_test(&info->stop_eviction))
- wake_up_var(&info->stop_eviction);
+ atomic_dec_and_wake_up_var(&info->stop_eviction);
if (error)
break;
}
diff --git a/net/rxrpc/call_accept.c b/net/rxrpc/call_accept.c
index 0f5a1d77b890..ece4137bb464 100644
--- a/net/rxrpc/call_accept.c
+++ b/net/rxrpc/call_accept.c
@@ -209,8 +209,7 @@ void rxrpc_discard_prealloc(struct rxrpc_sock *rx)
list_del(&conn->proc_link);
write_unlock(&rxnet->conn_lock);
kfree(conn);
- if (atomic_dec_and_test(&rxnet->nr_conns))
- wake_up_var(&rxnet->nr_conns);
+ atomic_dec_and_wake_up_var(&rxnet->nr_conns);
tail = (tail + 1) & (size - 1);
}
diff --git a/net/rxrpc/call_object.c b/net/rxrpc/call_object.c
index f9e983a12c14..b25f6ed4bcc0 100644
--- a/net/rxrpc/call_object.c
+++ b/net/rxrpc/call_object.c
@@ -661,8 +661,7 @@ static void rxrpc_rcu_free_call(struct rcu_head *rcu)
struct rxrpc_net *rxnet = READ_ONCE(call->rxnet);
kmem_cache_free(rxrpc_call_jar, call);
- if (atomic_dec_and_test(&rxnet->nr_calls))
- wake_up_var(&rxnet->nr_calls);
+ atomic_dec_and_wake_up_var(&rxnet->nr_calls);
}
/*
diff --git a/net/rxrpc/conn_object.c b/net/rxrpc/conn_object.c
index 1539d315afe7..738663251188 100644
--- a/net/rxrpc/conn_object.c
+++ b/net/rxrpc/conn_object.c
@@ -294,8 +294,7 @@ static void rxrpc_rcu_free_connection(struct rcu_head *rcu)
rxrpc_conn_free);
kfree(conn);
- if (atomic_dec_and_test(&rxnet->nr_conns))
- wake_up_var(&rxnet->nr_conns);
+ atomic_dec_and_wake_up_var(&rxnet->nr_conns);
}
/*
diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
index 09f245cda526..1a801a08671f 100644
--- a/net/sunrpc/xprt.c
+++ b/net/sunrpc/xprt.c
@@ -1113,8 +1113,7 @@ void xprt_unpin_rqst(struct rpc_rqst *req)
atomic_dec(&req->rq_pin);
return;
}
- if (atomic_dec_and_test(&req->rq_pin))
- wake_up_var(&req->rq_pin);
+ atomic_dec_and_wake_up_var(&req->rq_pin);
}
EXPORT_SYMBOL_GPL(xprt_unpin_rqst);
--
2.44.0
next prev parent reply other threads:[~2024-08-19 5:36 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-19 5:20 [PATCH 0/9 RFC] Make wake_up_{bit,var} less fragile NeilBrown
2024-08-19 5:20 ` [PATCH 1/9] i915: remove wake_up on I915_RESET_MODESET NeilBrown
2024-08-19 5:20 ` NeilBrown [this message]
2024-08-20 5:47 ` [PATCH 2/9] Introduce atomic_dec_and_wake_up_var() kernel test robot
2024-08-21 5:23 ` kernel test robot
2024-08-19 5:20 ` [PATCH 3/9] XFS: use wait_var_event() when waiting of i_pincount NeilBrown
2024-08-19 5:20 ` [PATCH 4/9] Use wait_var_event() instead of I_DIO_WAKEUP NeilBrown
2024-08-20 7:22 ` Christian Brauner
2024-08-20 19:12 ` Christian Brauner
2024-08-19 5:20 ` [PATCH 5/9] Block: switch bd_prepare_to_claim to use ___wait_var_event() NeilBrown
2024-08-20 4:18 ` Dave Chinner
2024-08-20 21:52 ` NeilBrown
2024-08-28 1:22 ` Dave Chinner
2024-08-28 5:20 ` NeilBrown
2024-08-21 7:10 ` kernel test robot
2024-08-19 5:20 ` [PATCH 6/9] block/pktdvd: switch congestion waiting to ___wait_var_event() NeilBrown
2024-08-19 5:20 ` [PATCH 7/9] Improve and expand wake_up_bit() interface NeilBrown
2024-08-19 5:20 ` [PATCH 8/9] Improve and extend wake_up_var() interface NeilBrown
2024-08-19 5:20 ` [PATCH 9/9] Use clear_and_wake_up_bit() where appropriate NeilBrown
2024-08-19 6:13 ` [PATCH 0/9 RFC] Make wake_up_{bit,var} less fragile Linus Torvalds
2024-08-20 21:47 ` NeilBrown
2024-08-20 21:58 ` Linus Torvalds
2024-08-20 22:15 ` NeilBrown
2024-08-20 22:24 ` Linus Torvalds
2024-08-19 8:16 ` Christian Brauner
2024-08-19 17:45 ` Linus Torvalds
2024-08-19 20:52 ` NeilBrown
2024-08-19 21:12 ` Linus Torvalds
2024-08-20 16:06 ` [PATCH RFC 0/5] inode: turn i_state into u32 Christian Brauner
2024-08-20 16:06 ` [PATCH RFC 1/5] fs: add i_state helpers Christian Brauner
2024-08-20 17:10 ` Linus Torvalds
2024-08-20 17:19 ` Linus Torvalds
2024-08-20 19:10 ` Christian Brauner
2024-08-20 19:08 ` Christian Brauner
2024-08-20 16:06 ` [PATCH RFC 2/5] writeback: port __I_SYNC to var event Christian Brauner
2024-08-20 16:06 ` [PATCH RFC 3/5] inode: port __I_NEW " Christian Brauner
2024-08-20 16:06 ` [PATCH RFC 4/5] inode: port __I_LRU_ISOLATING " Christian Brauner
2024-08-20 16:06 ` [PATCH RFC 5/5] inode: make i_state a u32 Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240819053605.11706-3-neilb@suse.de \
--to=neilb@suse.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox