Linux CXL
 help / color / mirror / Atom feed
From: Davidlohr Bueso <dave@stgolabs.net>
To: dan.j.williams@intel.com
Cc: dave.jiang@intel.com, alison.schofield@intel.com,
	vishal.l.verma@intel.com, Jonathan.Cameron@huawei.com,
	fan.ni@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net,
	linux-cxl@vger.kernel.org, peterz@infradead.org,
	mingo@redhat.com
Subject: [PATCH 1/3] rcuwait: Support timeouts
Date: Tue,  2 May 2023 10:18:39 -0700	[thread overview]
Message-ID: <20230502171841.21317-2-dave@stgolabs.net> (raw)
In-Reply-To: <20230502171841.21317-1-dave@stgolabs.net>

Introduce rcuwait_wait_event_timeout(), with semantics equivalent
to calls for the simple and regular waitqueue counterparts.

Cc: peterz@infradead.org
Cc: mingo@redhat.com
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
---
Only cc'ing sched folks this patch to avoid spamming. fyi the actual user
comes up in patch 3 (cxl/mbox: Add background cmd handling machinery),
but found a few other potential users in various drivers, so more could
be added.

 include/linux/rcuwait.h | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/include/linux/rcuwait.h b/include/linux/rcuwait.h
index 8052d34da782..27343424225c 100644
--- a/include/linux/rcuwait.h
+++ b/include/linux/rcuwait.h
@@ -49,9 +49,9 @@ static inline void prepare_to_rcuwait(struct rcuwait *w)
 
 extern void finish_rcuwait(struct rcuwait *w);
 
-#define rcuwait_wait_event(w, condition, state)				\
+#define ___rcuwait_wait_event(w, condition, state, ret, cmd)		\
 ({									\
-	int __ret = 0;							\
+	long __ret = ret;						\
 	prepare_to_rcuwait(w);						\
 	for (;;) {							\
 		/*							\
@@ -67,10 +67,27 @@ extern void finish_rcuwait(struct rcuwait *w);
 			break;						\
 		}							\
 									\
-		schedule();						\
+		cmd;							\
 	}								\
 	finish_rcuwait(w);						\
 	__ret;								\
 })
 
+#define rcuwait_wait_event(w, condition, state)				\
+	___rcuwait_wait_event(w, condition, state, 0, schedule())
+
+#define __rcuwait_wait_event_timeout(w, condition, state, timeout)	\
+	___rcuwait_wait_event(w, ___wait_cond_timeout(condition),	\
+			      state, timeout,				\
+			      __ret = schedule_timeout(__ret))
+
+#define rcuwait_wait_event_timeout(w, condition, state, timeout)	\
+({									\
+	long __ret = timeout;						\
+	if (!___wait_cond_timeout(condition))				\
+		__ret = __rcuwait_wait_event_timeout(w, condition,	\
+						     state, timeout);	\
+	__ret;								\
+})
+
 #endif /* _LINUX_RCUWAIT_H_ */
-- 
2.40.1


  reply	other threads:[~2023-05-02 17:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-02 17:18 [PATCH 0/3] cxl: Handle background commands Davidlohr Bueso
2023-05-02 17:18 ` Davidlohr Bueso [this message]
2023-05-19 21:38   ` [PATCH 1/3] rcuwait: Support timeouts Dan Williams
2023-05-19 22:55     ` Davidlohr Bueso
2023-05-20 11:03       ` Peter Zijlstra
2023-05-02 17:18 ` [PATCH 2/3] cxl/pci: Allocate irq vectors earlier in pci probe Davidlohr Bueso
2023-05-15 10:08   ` Jonathan Cameron
2023-05-02 17:18 ` [PATCH 3/3] cxl/mbox: Add background cmd handling machinery Davidlohr Bueso
2023-05-02 17:55   ` Davidlohr Bueso
2023-05-03 14:57   ` [PATCH v2] " Davidlohr Bueso
2023-05-15 10:30     ` Jonathan Cameron
2023-05-15 15:40       ` Davidlohr Bueso
2023-05-15 16:19         ` Jonathan Cameron
2023-05-16  7:58     ` Li, Ming
2023-05-16 17:02       ` Davidlohr Bueso
2023-05-19 23:13     ` Dan Williams
2023-05-22 16:58       ` Davidlohr Bueso
2023-05-22 18:19         ` Dan Williams
2023-05-22 18:57           ` Davidlohr Bueso
2023-05-22 20:16             ` Dan Williams
2023-05-22 20:28               ` Davidlohr Bueso
2023-05-22 21:21                 ` Dan Williams
2023-05-22 21:26                   ` Davidlohr Bueso
2023-05-22 22:48                     ` Dan Williams

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=20230502171841.21317-2-dave@stgolabs.net \
    --to=dave@stgolabs.net \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=a.manzanares@samsung.com \
    --cc=alison.schofield@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=fan.ni@samsung.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=vishal.l.verma@intel.com \
    /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