Author: hselasky
Date: Tue Mar 13 16:14:52 2018
New Revision: 330850
URL: https://svnweb.freebsd.org/changeset/base/330850

Log:
  MFC r330349 and r330362:
  Allow pause_sbt() to catch signals during sleep by passing C_CATCH flag.
  Define pause_sig() function macro helper similarly to other kernel functions
  which catch signals. Update outdated function description.
  
  Document pause_sig(9) and update prototypes for existing pause(9) and
  pause_sbt(9) functions.
  
  Discussed with:       kib@
  Suggested by: cem@
  Sponsored by: Mellanox Technologies

Modified:
  stable/11/share/man/man9/Makefile
  stable/11/share/man/man9/sleep.9
  stable/11/sys/kern/kern_synch.c
  stable/11/sys/sys/callout.h
  stable/11/sys/sys/systm.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/share/man/man9/Makefile
==============================================================================
--- stable/11/share/man/man9/Makefile   Tue Mar 13 16:10:11 2018        
(r330849)
+++ stable/11/share/man/man9/Makefile   Tue Mar 13 16:14:52 2018        
(r330850)
@@ -1597,6 +1597,7 @@ MLINKS+=sleep.9 msleep.9 \
        sleep.9 msleep_spin.9 \
        sleep.9 msleep_spin_sbt.9 \
        sleep.9 pause.9 \
+       sleep.9 pause_sig.9 \
        sleep.9 pause_sbt.9 \
        sleep.9 tsleep.9 \
        sleep.9 tsleep_sbt.9 \

Modified: stable/11/share/man/man9/sleep.9
==============================================================================
--- stable/11/share/man/man9/sleep.9    Tue Mar 13 16:10:11 2018        
(r330849)
+++ stable/11/share/man/man9/sleep.9    Tue Mar 13 16:14:52 2018        
(r330850)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd May 24, 2015
+.Dd March 4, 2018
 .Dt SLEEP 9
 .Os
 .Sh NAME
@@ -34,6 +34,7 @@
 .Nm msleep_spin ,
 .Nm msleep_spin_sbt ,
 .Nm pause ,
+.Nm pause_sig ,
 .Nm pause_sbt ,
 .Nm tsleep ,
 .Nm tsleep_sbt ,
@@ -53,9 +54,11 @@
 .Ft int
 .Fn msleep_spin_sbt "void *chan" "struct mtx *mtx" "const char *wmesg" \
 "sbintime_t sbt" "sbintime_t pr" "int flags"
-.Ft void
+.Ft int
 .Fn pause "const char *wmesg" "int timo"
-.Ft void
+.Ft int
+.Fn pause_sig "const char *wmesg" "int timo"
+.Ft int
 .Fn pause_sbt "const char *wmesg" "sbintime_t sbt" "sbintime_t pr" \
  "int flags"
 .Ft int
@@ -73,6 +76,8 @@ The functions
 .Fn msleep ,
 .Fn msleep_spin ,
 .Fn pause ,
+.Fn pause_sig ,
+.Fn pause_sbt ,
 .Fn wakeup ,
 and
 .Fn wakeup_one
@@ -82,8 +87,10 @@ external event, it is put to sleep by
 .Fn tsleep ,
 .Fn msleep ,
 .Fn msleep_spin ,
+.Fn pause ,
+.Fn pause_sig ,
 or
-.Fn pause .
+.Fn pause_sbt .
 Threads may also wait using one of the locking primitive sleep routines
 .Xr mtx_sleep 9 ,
 .Xr rw_sleep 9 ,
@@ -248,6 +255,11 @@ The thread can not be awakened early by signals or cal
 .Fn wakeup
 or
 .Fn wakeup_one .
+The
+.Fn pause_sig
+function is a variant of
+.Fn pause
+which can be awakened early by signals.
 .Pp
 The
 .Fn wakeup_one
@@ -385,6 +397,10 @@ The
 .Fn pause
 function appeared in
 .Fx 7.0 .
+The
+.Fn pause_sig
+function appeared in
+.Fx 12.0 .
 .Sh AUTHORS
 .An -nosplit
 This manual page was written by

Modified: stable/11/sys/kern/kern_synch.c
==============================================================================
--- stable/11/sys/kern/kern_synch.c     Tue Mar 13 16:10:11 2018        
(r330849)
+++ stable/11/sys/kern/kern_synch.c     Tue Mar 13 16:14:52 2018        
(r330850)
@@ -299,16 +299,16 @@ msleep_spin_sbt(void *ident, struct mtx *mtx, const ch
 }
 
 /*
- * pause() delays the calling thread by the given number of system ticks.
- * During cold bootup, pause() uses the DELAY() function instead of
- * the tsleep() function to do the waiting. The "timo" argument must be
- * greater than or equal to zero. A "timo" value of zero is equivalent
- * to a "timo" value of one.
+ * pause_sbt() delays the calling thread by the given signed binary
+ * time. During cold bootup, pause_sbt() uses the DELAY() function
+ * instead of the _sleep() function to do the waiting. The "sbt"
+ * argument must be greater than or equal to zero. A "sbt" value of
+ * zero is equivalent to a "sbt" value of one tick.
  */
 int
 pause_sbt(const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags)
 {
-       KASSERT(sbt >= 0, ("pause: timeout must be >= 0"));
+       KASSERT(sbt >= 0, ("pause_sbt: timeout must be >= 0"));
 
        /* silently convert invalid timeouts */
        if (sbt == 0)
@@ -330,7 +330,8 @@ pause_sbt(const char *wmesg, sbintime_t sbt, sbintime_
                        DELAY(sbt);
                return (0);
        }
-       return (_sleep(&pause_wchan[curcpu], NULL, 0, wmesg, sbt, pr, flags));
+       return (_sleep(&pause_wchan[curcpu], NULL,
+           (flags & C_CATCH) ? PCATCH : 0, wmesg, sbt, pr, flags));
 }
 
 /*

Modified: stable/11/sys/sys/callout.h
==============================================================================
--- stable/11/sys/sys/callout.h Tue Mar 13 16:10:11 2018        (r330849)
+++ stable/11/sys/sys/callout.h Tue Mar 13 16:14:52 2018        (r330850)
@@ -58,6 +58,7 @@
 #define        C_HARDCLOCK             0x0100 /* align to hardclock() calls */
 #define        C_ABSOLUTE              0x0200 /* event time is absolute. */
 #define        C_PRECALC               0x0400 /* event time is pre-calculated. 
*/
+#define        C_CATCH                 0x0800 /* catch signals, used by 
pause_sbt(9) */
 
 struct callout_handle {
        struct callout *callout;

Modified: stable/11/sys/sys/systm.h
==============================================================================
--- stable/11/sys/sys/systm.h   Tue Mar 13 16:10:11 2018        (r330849)
+++ stable/11/sys/sys/systm.h   Tue Mar 13 16:14:52 2018        (r330850)
@@ -407,6 +407,8 @@ int pause_sbt(const char *wmesg, sbintime_t sbt, sbint
            int flags);
 #define        pause(wmesg, timo)                                              
\
        pause_sbt((wmesg), tick_sbt * (timo), 0, C_HARDCLOCK)
+#define        pause_sig(wmesg, timo)                                          
\
+       pause_sbt((wmesg), tick_sbt * (timo), 0, C_HARDCLOCK | C_CATCH)
 #define        tsleep(chan, pri, wmesg, timo)                                  
\
        _sleep((chan), NULL, (pri), (wmesg), tick_sbt * (timo),         \
            0, C_HARDCLOCK)
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to