svn commit: r238453 - in projects/calloutng/sys: kern sys

Davide Italiano davide at FreeBSD.org
Sat Jul 14 19:39:54 UTC 2012


Author: davide
Date: Sat Jul 14 19:39:53 2012
New Revision: 238453
URL: http://svn.freebsd.org/changeset/base/238453

Log:
  Change the sleepqueue(9) and condvar(9) KPI so that functions which take
  a timeout as argument have variants that take an additional 'flags'
  argument that can be used to specify precision interval.
  
  Modify a couple of comments that aren't valid anymore after changes.
  
  Now sleepq_set_timeout_bt() and cv_timedwait_bt_sig() takes as time
  argument a pointer to struct bintime rather than a struct bintime.
  
  Reviewed by:		mav

Modified:
  projects/calloutng/sys/kern/kern_condvar.c
  projects/calloutng/sys/kern/kern_synch.c
  projects/calloutng/sys/kern/kern_time.c
  projects/calloutng/sys/kern/subr_sleepqueue.c
  projects/calloutng/sys/kern/sys_generic.c
  projects/calloutng/sys/sys/condvar.h
  projects/calloutng/sys/sys/mutex.h
  projects/calloutng/sys/sys/sleepqueue.h
  projects/calloutng/sys/sys/sx.h
  projects/calloutng/sys/sys/systm.h

Modified: projects/calloutng/sys/kern/kern_condvar.c
==============================================================================
--- projects/calloutng/sys/kern/kern_condvar.c	Sat Jul 14 18:10:44 2012	(r238452)
+++ projects/calloutng/sys/kern/kern_condvar.c	Sat Jul 14 19:39:53 2012	(r238453)
@@ -270,12 +270,12 @@ _cv_wait_sig(struct cv *cvp, struct lock
 }
 
 /*
- * Wait on a condition variable for at most timo/hz seconds.  Returns 0 if the
- * process was resumed by cv_signal or cv_broadcast, EWOULDBLOCK if the timeout
- * expires.
+ * Wait on a condition variable.  Returns 0 if the process was resumed by
+ * cv_signal or cv_broadcast, EWOULDBLOCK if the timeout expires.
  */
 int
-_cv_timedwait(struct cv *cvp, struct lock_object *lock, int timo)
+_cv_timedwait(struct cv *cvp, struct lock_object *lock, struct bintime *bt, 
+    int timo, int flags)
 {
 	WITNESS_SAVE_DECL(lock_witness);
 	struct lock_class *class;
@@ -311,7 +311,10 @@ _cv_timedwait(struct cv *cvp, struct loc
 	DROP_GIANT();
 
 	sleepq_add(cvp, lock, cvp->cv_description, SLEEPQ_CONDVAR, 0);
-	sleepq_set_timeout(cvp, timo);
+	if (bt == NULL) 
+		sleepq_set_timeout_flags(cvp, timo, flags);
+	else
+		sleepq_set_timeout_bt(cvp, bt, flags);	
 	if (lock != &Giant.lock_object) {
 		if (class->lc_flags & LC_SLEEPABLE)
 			sleepq_release(cvp);
@@ -336,14 +339,14 @@ _cv_timedwait(struct cv *cvp, struct loc
 }
 
 /*
- * Wait on a condition variable for at most timo/hz seconds, allowing
- * interruption by signals.  Returns 0 if the thread was resumed by cv_signal
- * or cv_broadcast, EWOULDBLOCK if the timeout expires, and EINTR or ERESTART if
- * a signal was caught.
+ * Wait on a condition variable allowing interruption by signals.
+ * Returns 0 if the thread was resumed by cv_signal or cv_broadcast, 
+ * or cv_broadcast, EWOULDBLOCK if the timeout expires, and EINTR 
+ * or ERESTART if a signal was caught.
  */
 int
 _cv_timedwait_sig(struct cv *cvp, struct lock_object *lock, 
-    struct bintime *bt, int timo) 
+    struct bintime *bt, int timo, int flags) 
 {
 	WITNESS_SAVE_DECL(lock_witness);
 	struct lock_class *class;
@@ -381,9 +384,9 @@ _cv_timedwait_sig(struct cv *cvp, struct
 	sleepq_add(cvp, lock, cvp->cv_description, SLEEPQ_CONDVAR |
 	    SLEEPQ_INTERRUPTIBLE, 0);
 	if (bt == NULL)	
-		sleepq_set_timeout(cvp, timo);
+		sleepq_set_timeout_flags(cvp, timo, flags);
 	else
-		sleepq_set_timeout_bt(cvp, *bt);
+		sleepq_set_timeout_bt(cvp, bt, flags);
 	if (lock != &Giant.lock_object) {
 		if (class->lc_flags & LC_SLEEPABLE)
 			sleepq_release(cvp);

Modified: projects/calloutng/sys/kern/kern_synch.c
==============================================================================
--- projects/calloutng/sys/kern/kern_synch.c	Sat Jul 14 18:10:44 2012	(r238452)
+++ projects/calloutng/sys/kern/kern_synch.c	Sat Jul 14 19:39:53 2012	(r238453)
@@ -146,12 +146,12 @@ sleepinit(void)
  */
 int
 _sleep(void *ident, struct lock_object *lock, int priority,
-    const char *wmesg, int timo)
+    const char *wmesg, int timo, struct bintime *bt, int flags)
 {
 	struct thread *td;
 	struct proc *p;
 	struct lock_class *class;
-	int catch, flags, lock_state, pri, rval;
+	int catch, sleepq_flags, lock_state, pri, rval;
 	WITNESS_SAVE_DECL(lock_witness);
 
 	td = curthread;
@@ -199,13 +199,13 @@ _sleep(void *ident, struct lock_object *
 		sleepq_remove(td, td->td_wchan);
 
 	if (ident == &pause_wchan)
-		flags = SLEEPQ_PAUSE;
+		sleepq_flags = SLEEPQ_PAUSE;
 	else
-		flags = SLEEPQ_SLEEP;
+		sleepq_flags = SLEEPQ_SLEEP;
 	if (catch)
-		flags |= SLEEPQ_INTERRUPTIBLE;
+		sleepq_flags |= SLEEPQ_INTERRUPTIBLE;
 	if (priority & PBDRY)
-		flags |= SLEEPQ_STOP_ON_BDRY;
+		sleepq_flags |= SLEEPQ_STOP_ON_BDRY;
 
 	sleepq_lock(ident);
 	CTR5(KTR_PROC, "sleep: thread %ld (pid %ld, %s) on %s (%p)",
@@ -231,18 +231,20 @@ _sleep(void *ident, struct lock_object *
 	 * stopped, then td will no longer be on a sleep queue upon
 	 * return from cursig().
 	 */
-	sleepq_add(ident, lock, wmesg, flags, 0);
-	if (timo)
-		sleepq_set_timeout(ident, timo);
+	sleepq_add(ident, lock, wmesg, sleepq_flags, 0);
+	if (bt) 
+		sleepq_set_timeout_bt(ident, bt, flags);
+	else if (timo)
+		sleepq_set_timeout_flags(ident, timo, flags);
 	if (lock != NULL && class->lc_flags & LC_SLEEPABLE) {
 		sleepq_release(ident);
 		WITNESS_SAVE(lock, lock_witness);
 		lock_state = class->lc_unlock(lock);
 		sleepq_lock(ident);
 	}
-	if (timo && catch)
+	if ((timo || bt) && catch)
 		rval = sleepq_timedwait_sig(ident, pri);
-	else if (timo)
+	else if (timo || bt)
 		rval = sleepq_timedwait(ident, pri);
 	else if (catch)
 		rval = sleepq_wait_sig(ident, pri);

Modified: projects/calloutng/sys/kern/kern_time.c
==============================================================================
--- projects/calloutng/sys/kern/kern_time.c	Sat Jul 14 18:10:44 2012	(r238452)
+++ projects/calloutng/sys/kern/kern_time.c	Sat Jul 14 19:39:53 2012	(r238453)
@@ -367,7 +367,7 @@ kern_nanosleep(struct thread *td, struct
 	for (;;) {
 		sleepq_lock(&nanowait);	
 		sleepq_add(&nanowait, NULL, "nanslp", PWAIT | PCATCH, 0);
-		sleepq_set_timeout_bt(&nanowait,bt);
+		sleepq_set_timeout_bt(&nanowait, &bt, 0);
 		error = sleepq_timedwait_sig(&nanowait, PWAIT | PCATCH);
 		binuptime(&bt2);
 		if (error != EWOULDBLOCK) {

Modified: projects/calloutng/sys/kern/subr_sleepqueue.c
==============================================================================
--- projects/calloutng/sys/kern/subr_sleepqueue.c	Sat Jul 14 18:10:44 2012	(r238452)
+++ projects/calloutng/sys/kern/subr_sleepqueue.c	Sat Jul 14 19:39:53 2012	(r238453)
@@ -362,7 +362,7 @@ sleepq_add(void *wchan, struct lock_obje
  * sleep queue after timo ticks if the thread has not already been awakened.
  */
 void 
-_sleepq_set_timeout(void *wchan, struct bintime *bt, int timo)
+_sleepq_set_timeout(void *wchan, struct bintime *bt, int timo, int flags)
 {
 
 	struct sleepqueue_chain *sc;
@@ -375,11 +375,11 @@ _sleepq_set_timeout(void *wchan, struct 
 	MPASS(td->td_sleepqueue == NULL);
 	MPASS(wchan != NULL);
 	if (bt == NULL) 
-		callout_reset_curcpu(&td->td_slpcallout, timo, 
-		    sleepq_timeout, td);
+		callout_reset_flags_on(&td->td_slpcallout, timo, 
+		    sleepq_timeout, td, PCPU_GET(cpuid), flags);
 	else
 		callout_reset_bt_on(&td->td_slpcallout, bt, 
-		    sleepq_timeout, td, PCPU_GET(cpuid), 0); 
+		    sleepq_timeout, td, PCPU_GET(cpuid), flags); 
 }
 
 /*

Modified: projects/calloutng/sys/kern/sys_generic.c
==============================================================================
--- projects/calloutng/sys/kern/sys_generic.c	Sat Jul 14 18:10:44 2012	(r238452)
+++ projects/calloutng/sys/kern/sys_generic.c	Sat Jul 14 19:39:53 2012	(r238453)
@@ -1722,7 +1722,8 @@ seltdwait(struct thread *td, struct bint
 	if (bt == NULL && timo > 0) 
 		error = cv_timedwait_sig(&stp->st_wait, &stp->st_mtx, timo);
 	else if (bt != NULL)
-		error = cv_timedwait_bt_sig(&stp->st_wait, &stp->st_mtx, *bt);
+		error = cv_timedwait_bt_sig(&stp->st_wait, &stp->st_mtx, 
+		    bt, 0);
 	else	
 		error = cv_wait_sig(&stp->st_wait, &stp->st_mtx);
 	mtx_unlock(&stp->st_mtx);

Modified: projects/calloutng/sys/sys/condvar.h
==============================================================================
--- projects/calloutng/sys/sys/condvar.h	Sat Jul 14 18:10:44 2012	(r238452)
+++ projects/calloutng/sys/sys/condvar.h	Sat Jul 14 19:39:53 2012	(r238453)
@@ -55,9 +55,10 @@ void	cv_destroy(struct cv *cvp);
 void	_cv_wait(struct cv *cvp, struct lock_object *lock);
 void	_cv_wait_unlock(struct cv *cvp, struct lock_object *lock);
 int	_cv_wait_sig(struct cv *cvp, struct lock_object *lock);
-int	_cv_timedwait(struct cv *cvp, struct lock_object *lock, int timo);
+int	_cv_timedwait(struct cv *cvp, struct lock_object *lock,  
+	    struct bintime *bt, int timo, int flags);
 int	_cv_timedwait_sig(struct cv *cvp, struct lock_object *lock,
-	    struct bintime *bt, int timo);
+	    struct bintime *bt, int timo, int flags);
 
 void	cv_signal(struct cv *cvp);
 void	cv_broadcastpri(struct cv *cvp, int pri);
@@ -69,11 +70,20 @@ void	cv_broadcastpri(struct cv *cvp, int
 #define	cv_wait_sig(cvp, lock)						\
 	_cv_wait_sig((cvp), &(lock)->lock_object)
 #define	cv_timedwait(cvp, lock, timo)					\
-	_cv_timedwait((cvp), &(lock)->lock_object, (timo))
+	_cv_timedwait((cvp), &(lock)->lock_object, NULL, (timo), 0)	
+#define	cv_timedwait_bt(cvp, lock, bt, flags)				\
+	_cv_timedwait_sig((cvp), &(lock)->lock_object, (bt), 0, 0)
+#define	cv_timedwait_bt_sig(cvp, lock, bt, flags)			\
+	_cv_timedwait_sig((cvp), &(lock)->lock_object, (bt), 0, 	\
+	    (flags))
+#define	cv_timedwait_flags(cvp, lock, timo, flags)			\
+	_cv_timedwait((cvp), &(lock)->lock_object, NULL, (timo), 	\
+	    (flags)) 
 #define	cv_timedwait_sig(cvp, lock, timo)				\
-	_cv_timedwait_sig((cvp), &(lock)->lock_object, (NULL), (timo))
-#define cv_timedwait_bt_sig(cvp, lock, bt)				\
-	_cv_timedwait_sig((cvp), &(lock)->lock_object, (&bt), (0))
+	_cv_timedwait_sig((cvp), &(lock)->lock_object, NULL, (timo), 0)
+#define	cv_timedwait_sig_flags(cvp, lock, timo, flags)			\
+	_cv_timedwait_sig((cvp), &(lock)->lock_object, NULL, (timo),	\
+	    (flags))
 
 #define cv_broadcast(cvp)	cv_broadcastpri(cvp, 0)
 

Modified: projects/calloutng/sys/sys/mutex.h
==============================================================================
--- projects/calloutng/sys/sys/mutex.h	Sat Jul 14 18:10:44 2012	(r238452)
+++ projects/calloutng/sys/sys/mutex.h	Sat Jul 14 19:39:53 2012	(r238453)
@@ -339,7 +339,8 @@ extern struct mtx_pool *mtxpool_sleep;
 	mtx_assert_((m), (what), __FILE__, __LINE__)
 
 #define	mtx_sleep(chan, mtx, pri, wmesg, timo)				\
-	_sleep((chan), &(mtx)->lock_object, (pri), (wmesg), (timo))
+	_sleep((chan), &(mtx)->lock_object, (pri), (wmesg), (timo),	\
+	   NULL, 0)	
 
 #define	mtx_initialized(m)	lock_initalized(&(m)->lock_object)
 

Modified: projects/calloutng/sys/sys/sleepqueue.h
==============================================================================
--- projects/calloutng/sys/sys/sleepqueue.h	Sat Jul 14 18:10:44 2012	(r238452)
+++ projects/calloutng/sys/sys/sleepqueue.h	Sat Jul 14 19:39:53 2012	(r238453)
@@ -108,11 +108,14 @@ struct sleepqueue *sleepq_lookup(void *w
 void	sleepq_release(void *wchan);
 void	sleepq_remove(struct thread *td, void *wchan);
 int	sleepq_signal(void *wchan, int flags, int pri, int queue);
-void	_sleepq_set_timeout(void *wchan, struct bintime *bt, int timo);
+void	_sleepq_set_timeout(void *wchan, struct bintime *bt, int timo, 
+	    int flags);
 #define	sleepq_set_timeout(wchan, timo)					\
-    _sleepq_set_timeout((wchan), (NULL), (timo))
-#define	sleepq_set_timeout_bt(wchan, bt)				\
-    _sleepq_set_timeout((wchan), (&bt), (0))
+    _sleepq_set_timeout((wchan), NULL, (timo), 0)
+#define	sleepq_set_timeout_flags(wchan, timo, flags)			\
+    _sleepq_set_timeout((wchan), NULL, (timo), (flags))
+#define	sleepq_set_timeout_bt(wchan, bt, flags)				\
+    _sleepq_set_timeout((wchan), (bt), 0, (flags))
 u_int	sleepq_sleepcnt(void *wchan, int queue);
 int	sleepq_timedwait(void *wchan, int pri);
 int	sleepq_timedwait_sig(void *wchan, int pri);

Modified: projects/calloutng/sys/sys/sx.h
==============================================================================
--- projects/calloutng/sys/sys/sx.h	Sat Jul 14 18:10:44 2012	(r238452)
+++ projects/calloutng/sys/sys/sx.h	Sat Jul 14 19:39:53 2012	(r238453)
@@ -275,8 +275,9 @@ __sx_sunlock(struct sx *sx, const char *
 #define	sx_unlock(sx)	sx_unlock_((sx), LOCK_FILE, LOCK_LINE)
 
 #define	sx_sleep(chan, sx, pri, wmesg, timo)				\
-	_sleep((chan), &(sx)->lock_object, (pri), (wmesg), (timo))
-
+	_sleep((chan), &(sx)->lock_object, (pri), (wmesg), (timo),	\
+	    NULL, 0)
+	
 /*
  * Options passed to sx_init_flags().
  */

Modified: projects/calloutng/sys/sys/systm.h
==============================================================================
--- projects/calloutng/sys/sys/systm.h	Sat Jul 14 18:10:44 2012	(r238452)
+++ projects/calloutng/sys/sys/systm.h	Sat Jul 14 19:39:53 2012	(r238453)
@@ -341,14 +341,21 @@ static __inline void		splx(intrmask_t ip
  * less often.
  */
 int	_sleep(void *chan, struct lock_object *lock, int pri, const char *wmesg,
-	    int timo) __nonnull(1);
+	    int timo, struct bintime *bt, int flags) __nonnull(1);
 #define	msleep(chan, mtx, pri, wmesg, timo)				\
-	_sleep((chan), &(mtx)->lock_object, (pri), (wmesg), (timo))
+	_sleep((chan), &(mtx)->lock_object, (pri), (wmesg), (timo),	\
+	    NULL, 0) 
+#define	msleep_flags(chan, mtx, pri, wmesg, timo, flags)		\
+	_sleep((chan), &(mtx)->lock_object, (pri), (wmesg), (timo), 	\
+	    NULL, (flags)) 
+#define	msleep_bt(chan, mtx, pri, wmesg, bt, flags)			\
+	_sleep((chan), &(mtx)->lock_object, (pri), (wmesg) 0, (bt),	\
+	    (flags))
 int	msleep_spin(void *chan, struct mtx *mtx, const char *wmesg, int timo)
 	    __nonnull(1);
 int	pause(const char *wmesg, int timo);
 #define	tsleep(chan, pri, wmesg, timo)					\
-	_sleep((chan), NULL, (pri), (wmesg), (timo))
+	_sleep((chan), NULL, (pri), (wmesg), (timo), NULL, 0)
 void	wakeup(void *chan) __nonnull(1);
 void	wakeup_one(void *chan) __nonnull(1);
 


More information about the svn-src-projects mailing list