9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright (c) 2012 by Delphix. All rights reserved.
29 */
30
31 #include <sys/thread.h>
32 #include <sys/proc.h>
33 #include <sys/debug.h>
34 #include <sys/cmn_err.h>
35 #include <sys/systm.h>
36 #include <sys/sobject.h>
37 #include <sys/sleepq.h>
38 #include <sys/cpuvar.h>
39 #include <sys/condvar.h>
40 #include <sys/condvar_impl.h>
41 #include <sys/schedctl.h>
42 #include <sys/procfs.h>
43 #include <sys/sdt.h>
44 #include <sys/callo.h>
45
46 /*
47 * CV_MAX_WAITERS is the maximum number of waiters we track; once
48 * the number becomes higher than that, we look at the sleepq to
535 int signalled = 0;
536
537 if (panicstr)
538 return (rval);
539
540 /*
541 * Threads in system processes don't process signals. This is
542 * true both for standard threads of system processes and for
543 * interrupt threads which have borrowed their pinned thread's LWP.
544 */
545 if (lwp == NULL || (p->p_flag & SSYS)) {
546 cv_wait(cvp, mp);
547 return (rval);
548 }
549 ASSERT(t->t_intr == NULL);
550
551 cancel_pending = schedctl_cancel_pending();
552 lwp->lwp_asleep = 1;
553 lwp->lwp_sysabort = 0;
554 thread_lock(t);
555 t->t_kpri_req = 0; /* don't need kernel priority */
556 cv_block_sig(t, (condvar_impl_t *)cvp);
557 /* I can be swapped now */
558 curthread->t_schedflag &= ~TS_DONT_SWAP;
559 thread_unlock_nopreempt(t);
560 mutex_exit(mp);
561 if (ISSIG(t, JUSTLOOKING) || MUSTRETURN(p, t) || cancel_pending)
562 setrun(t);
563 /* ASSERT(no locks are held) */
564 swtch();
565 signalled = (t->t_schedflag & TS_SIGNALLED);
566 t->t_flag &= ~T_WAKEABLE;
567 /* TS_DONT_SWAP set by disp() */
568 ASSERT(curthread->t_schedflag & TS_DONT_SWAP);
569 mutex_enter(mp);
570 if (ISSIG_PENDING(t, lwp, p)) {
571 mutex_exit(mp);
572 if (issig(FORREAL))
573 rval = 0;
574 mutex_enter(mp);
575 }
746 * If 'when' is a NULL pointer, no timeout will occur.
747 * Returns:
748 * Function result in order of precedence:
749 * 0 if a signal was received
750 * -1 if timeout occured
751 * >0 if awakened via cv_signal() or cv_broadcast()
752 * or by a spurious wakeup.
753 * (might return time remaining)
754 * As a special test, if someone abruptly resets the system time
755 * (but not through adjtime(2); drifting of the clock is allowed and
756 * expected [see timespectohz_adj()]), then we force a return of -1
757 * so the caller can return a premature timeout to the calling process
758 * so it can reevaluate the situation in light of the new system time.
759 * (The system clock has been reset if timecheck != timechanged.)
760 *
761 * Generally, cv_timedwait_sig_hrtime() should be used instead of this
762 * routine. It waits based on hrtime rather than wall-clock time and therefore
763 * does not need to deal with the time changing.
764 */
765 int
766 cv_waituntil_sig(kcondvar_t *cvp, kmutex_t *mp,
767 timestruc_t *when, int timecheck)
768 {
769 timestruc_t now;
770 timestruc_t delta;
771 hrtime_t interval;
772 int rval;
773
774 if (when == NULL)
775 return (cv_wait_sig_swap(cvp, mp));
776
777 gethrestime(&now);
778 delta = *when;
779 timespecsub(&delta, &now);
780 if (delta.tv_sec < 0 || (delta.tv_sec == 0 && delta.tv_nsec == 0)) {
781 /*
782 * We have already reached the absolute future time.
783 * Call cv_timedwait_sig() just to check for signals.
784 * We will return immediately with either 0 or -1.
785 */
786 rval = cv_timedwait_sig_hires(cvp, mp, 0, 1, 0);
787 } else {
|
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright (c) 2012 by Delphix. All rights reserved.
29 * Copyright 2019 Joyent, Inc.
30 */
31
32 #include <sys/thread.h>
33 #include <sys/proc.h>
34 #include <sys/debug.h>
35 #include <sys/cmn_err.h>
36 #include <sys/systm.h>
37 #include <sys/sobject.h>
38 #include <sys/sleepq.h>
39 #include <sys/cpuvar.h>
40 #include <sys/condvar.h>
41 #include <sys/condvar_impl.h>
42 #include <sys/schedctl.h>
43 #include <sys/procfs.h>
44 #include <sys/sdt.h>
45 #include <sys/callo.h>
46
47 /*
48 * CV_MAX_WAITERS is the maximum number of waiters we track; once
49 * the number becomes higher than that, we look at the sleepq to
536 int signalled = 0;
537
538 if (panicstr)
539 return (rval);
540
541 /*
542 * Threads in system processes don't process signals. This is
543 * true both for standard threads of system processes and for
544 * interrupt threads which have borrowed their pinned thread's LWP.
545 */
546 if (lwp == NULL || (p->p_flag & SSYS)) {
547 cv_wait(cvp, mp);
548 return (rval);
549 }
550 ASSERT(t->t_intr == NULL);
551
552 cancel_pending = schedctl_cancel_pending();
553 lwp->lwp_asleep = 1;
554 lwp->lwp_sysabort = 0;
555 thread_lock(t);
556 cv_block_sig(t, (condvar_impl_t *)cvp);
557 /* I can be swapped now */
558 curthread->t_schedflag &= ~TS_DONT_SWAP;
559 thread_unlock_nopreempt(t);
560 mutex_exit(mp);
561 if (ISSIG(t, JUSTLOOKING) || MUSTRETURN(p, t) || cancel_pending)
562 setrun(t);
563 /* ASSERT(no locks are held) */
564 swtch();
565 signalled = (t->t_schedflag & TS_SIGNALLED);
566 t->t_flag &= ~T_WAKEABLE;
567 /* TS_DONT_SWAP set by disp() */
568 ASSERT(curthread->t_schedflag & TS_DONT_SWAP);
569 mutex_enter(mp);
570 if (ISSIG_PENDING(t, lwp, p)) {
571 mutex_exit(mp);
572 if (issig(FORREAL))
573 rval = 0;
574 mutex_enter(mp);
575 }
746 * If 'when' is a NULL pointer, no timeout will occur.
747 * Returns:
748 * Function result in order of precedence:
749 * 0 if a signal was received
750 * -1 if timeout occured
751 * >0 if awakened via cv_signal() or cv_broadcast()
752 * or by a spurious wakeup.
753 * (might return time remaining)
754 * As a special test, if someone abruptly resets the system time
755 * (but not through adjtime(2); drifting of the clock is allowed and
756 * expected [see timespectohz_adj()]), then we force a return of -1
757 * so the caller can return a premature timeout to the calling process
758 * so it can reevaluate the situation in light of the new system time.
759 * (The system clock has been reset if timecheck != timechanged.)
760 *
761 * Generally, cv_timedwait_sig_hrtime() should be used instead of this
762 * routine. It waits based on hrtime rather than wall-clock time and therefore
763 * does not need to deal with the time changing.
764 */
765 int
766 cv_waituntil_sig(kcondvar_t *cvp, kmutex_t *mp, timestruc_t *when,
767 int timecheck)
768 {
769 timestruc_t now;
770 timestruc_t delta;
771 hrtime_t interval;
772 int rval;
773
774 if (when == NULL)
775 return (cv_wait_sig_swap(cvp, mp));
776
777 gethrestime(&now);
778 delta = *when;
779 timespecsub(&delta, &now);
780 if (delta.tv_sec < 0 || (delta.tv_sec == 0 && delta.tv_nsec == 0)) {
781 /*
782 * We have already reached the absolute future time.
783 * Call cv_timedwait_sig() just to check for signals.
784 * We will return immediately with either 0 or -1.
785 */
786 rval = cv_timedwait_sig_hires(cvp, mp, 0, 1, 0);
787 } else {
|