Deleted Added
full compact
thr_kern.c (117706) thr_kern.c (117715)
1/*
2 * Copyright (C) 2003 Daniel M. Eischen <deischen@freebsd.org>
3 * Copyright (C) 2002 Jonathon Mini <mini@freebsd.org>
4 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 19 unchanged lines hidden (view full) ---

28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 */
35#include <sys/cdefs.h>
1/*
2 * Copyright (C) 2003 Daniel M. Eischen <deischen@freebsd.org>
3 * Copyright (C) 2002 Jonathon Mini <mini@freebsd.org>
4 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 19 unchanged lines hidden (view full) ---

28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 */
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD: head/lib/libkse/thread/thr_kern.c 117706 2003-07-17 23:02:30Z davidxu $");
36__FBSDID("$FreeBSD: head/lib/libkse/thread/thr_kern.c 117715 2003-07-18 02:46:55Z deischen $");
37
38#include <sys/types.h>
39#include <sys/kse.h>
40#include <sys/signalvar.h>
41#include <sys/queue.h>
42#include <machine/atomic.h>
43#include <machine/sigframe.h>
44

--- 102 unchanged lines hidden (view full) ---

147static void thr_link(struct pthread *thread);
148static void thr_resume_wrapper(int sig, siginfo_t *, ucontext_t *);
149static void thr_resume_check(struct pthread *curthread, ucontext_t *ucp,
150 struct pthread_sigframe *psf);
151static int thr_timedout(struct pthread *thread, struct timespec *curtime);
152static void thr_unlink(struct pthread *thread);
153
154
37
38#include <sys/types.h>
39#include <sys/kse.h>
40#include <sys/signalvar.h>
41#include <sys/queue.h>
42#include <machine/atomic.h>
43#include <machine/sigframe.h>
44

--- 102 unchanged lines hidden (view full) ---

147static void thr_link(struct pthread *thread);
148static void thr_resume_wrapper(int sig, siginfo_t *, ucontext_t *);
149static void thr_resume_check(struct pthread *curthread, ucontext_t *ucp,
150 struct pthread_sigframe *psf);
151static int thr_timedout(struct pthread *thread, struct timespec *curtime);
152static void thr_unlink(struct pthread *thread);
153
154
155static void __inline
156thr_accounting(struct pthread *thread)
157{
158 if ((thread->slice_usec != -1) &&
159 (thread->slice_usec <= TIMESLICE_USEC) &&
160 (thread->attr.sched_policy != SCHED_FIFO)) {
161 thread->slice_usec += (thread->tmbx.tm_uticks
162 + thread->tmbx.tm_sticks) * _clock_res_usec;
163 /* Check for time quantum exceeded: */
164 if (thread->slice_usec > TIMESLICE_USEC)
165 thread->slice_usec = -1;
166 }
167 thread->tmbx.tm_uticks = 0;
168 thread->tmbx.tm_sticks = 0;
169}
170
155/*
156 * This is called after a fork().
157 * No locks need to be taken here since we are guaranteed to be
158 * single threaded.
159 *
160 * XXX
161 * POSIX says for threaded process, fork() function is used
162 * only to run new programs, and the effects of calling functions

--- 413 unchanged lines hidden (view full) ---

576 volatile int resume_once = 0;
577 ucontext_t uc;
578
579 /* We're in the scheduler, 5 by 5: */
580 curkse = _get_curkse();
581
582 curthread->need_switchout = 1; /* The thread yielded on its own. */
583 curthread->critical_yield = 0; /* No need to yield anymore. */
171/*
172 * This is called after a fork().
173 * No locks need to be taken here since we are guaranteed to be
174 * single threaded.
175 *
176 * XXX
177 * POSIX says for threaded process, fork() function is used
178 * only to run new programs, and the effects of calling functions

--- 413 unchanged lines hidden (view full) ---

592 volatile int resume_once = 0;
593 ucontext_t uc;
594
595 /* We're in the scheduler, 5 by 5: */
596 curkse = _get_curkse();
597
598 curthread->need_switchout = 1; /* The thread yielded on its own. */
599 curthread->critical_yield = 0; /* No need to yield anymore. */
584 curthread->slice_usec = -1; /* Restart the time slice. */
600 thr_accounting(curthread);
585
601
602
586 /* Thread can unlock the scheduler lock. */
587 curthread->lock_switch = 1;
588
589 /*
590 * The signal frame is allocated off the stack because
591 * a thread can be interrupted by other signals while
592 * it is running down pending signals.
593 */

--- 39 unchanged lines hidden (view full) ---

633
634 /*
635 * Make sure the current thread's kse points to
636 * this kse.
637 */
638 td->kse = curkse;
639
640 /*
603 /* Thread can unlock the scheduler lock. */
604 curthread->lock_switch = 1;
605
606 /*
607 * The signal frame is allocated off the stack because
608 * a thread can be interrupted by other signals while
609 * it is running down pending signals.
610 */

--- 39 unchanged lines hidden (view full) ---

650
651 /*
652 * Make sure the current thread's kse points to
653 * this kse.
654 */
655 td->kse = curkse;
656
657 /*
641 * Reset accounting.
642 */
643 td->tmbx.tm_uticks = 0;
644 td->tmbx.tm_sticks = 0;
645
646 /*
647 * Reset the time slice if this thread is running
648 * for the first time or running again after using
649 * its full time slice allocation.
650 */
651 if (td->slice_usec == -1)
652 td->slice_usec = 0;
653
654 /* Mark the thread active. */

--- 368 unchanged lines hidden (view full) ---

1023 curkse->k_curthread = curthread;
1024
1025 /*
1026 * Make sure the current thread's kse points to this kse.
1027 */
1028 curthread->kse = curkse;
1029
1030 /*
658 * Reset the time slice if this thread is running
659 * for the first time or running again after using
660 * its full time slice allocation.
661 */
662 if (td->slice_usec == -1)
663 td->slice_usec = 0;
664
665 /* Mark the thread active. */

--- 368 unchanged lines hidden (view full) ---

1034 curkse->k_curthread = curthread;
1035
1036 /*
1037 * Make sure the current thread's kse points to this kse.
1038 */
1039 curthread->kse = curkse;
1040
1041 /*
1031 * Reset accounting.
1032 */
1033 curthread->tmbx.tm_uticks = 0;
1034 curthread->tmbx.tm_sticks = 0;
1035
1036 /*
1037 * Reset the time slice if this thread is running for the first
1038 * time or running again after using its full time slice allocation.
1039 */
1040 if (curthread->slice_usec == -1)
1041 curthread->slice_usec = 0;
1042
1043 /* Mark the thread active. */
1044 curthread->active = 1;

--- 366 unchanged lines hidden (view full) ---

1411 kse->k_mbx.km_completed = NULL;
1412 while (completed != NULL) {
1413 thread = completed->tm_udata;
1414 DBG_MSG("Found completed thread %p, name %s\n",
1415 thread,
1416 (thread->name == NULL) ? "none" : thread->name);
1417 thread->blocked = 0;
1418 if (thread != kse->k_curthread) {
1042 * Reset the time slice if this thread is running for the first
1043 * time or running again after using its full time slice allocation.
1044 */
1045 if (curthread->slice_usec == -1)
1046 curthread->slice_usec = 0;
1047
1048 /* Mark the thread active. */
1049 curthread->active = 1;

--- 366 unchanged lines hidden (view full) ---

1416 kse->k_mbx.km_completed = NULL;
1417 while (completed != NULL) {
1418 thread = completed->tm_udata;
1419 DBG_MSG("Found completed thread %p, name %s\n",
1420 thread,
1421 (thread->name == NULL) ? "none" : thread->name);
1422 thread->blocked = 0;
1423 if (thread != kse->k_curthread) {
1424 thr_accounting(thread);
1419 if ((thread->flags & THR_FLAGS_SUSPENDED) != 0)
1420 THR_SET_STATE(thread, PS_SUSPENDED);
1421 else
1422 KSE_RUNQ_INSERT_TAIL(kse, thread);
1423 if ((thread->kse != kse) &&
1424 (thread->kse->k_curthread == thread)) {
1425 thread->kse->k_curthread = NULL;
1426 thread->active = 0;

--- 113 unchanged lines hidden (view full) ---

1540 */
1541 DBG_MSG("Switching out thread %p, state %d\n", thread, thread->state);
1542
1543 THR_DEACTIVATE_LAST_LOCK(thread);
1544 if (thread->blocked != 0) {
1545 thread->active = 0;
1546 thread->need_switchout = 0;
1547 /* This thread must have blocked in the kernel. */
1425 if ((thread->flags & THR_FLAGS_SUSPENDED) != 0)
1426 THR_SET_STATE(thread, PS_SUSPENDED);
1427 else
1428 KSE_RUNQ_INSERT_TAIL(kse, thread);
1429 if ((thread->kse != kse) &&
1430 (thread->kse->k_curthread == thread)) {
1431 thread->kse->k_curthread = NULL;
1432 thread->active = 0;

--- 113 unchanged lines hidden (view full) ---

1546 */
1547 DBG_MSG("Switching out thread %p, state %d\n", thread, thread->state);
1548
1549 THR_DEACTIVATE_LAST_LOCK(thread);
1550 if (thread->blocked != 0) {
1551 thread->active = 0;
1552 thread->need_switchout = 0;
1553 /* This thread must have blocked in the kernel. */
1548 /* thread->slice_usec = -1;*/ /* restart timeslice */
1549 if ((thread->slice_usec != -1) &&
1550 (thread->attr.sched_policy != SCHED_FIFO))
1551 thread->slice_usec += (thread->tmbx.tm_uticks
1552 + thread->tmbx.tm_sticks) * _clock_res_usec;
1553 /*
1554 * Check for pending signals for this thread to
1555 * see if we need to interrupt it in the kernel.
1556 */
1557 if (thread->check_pending != 0) {
1558 for (i = 1; i <= _SIG_MAXSIG; ++i) {
1559 if (SIGISMEMBER(thread->sigpend, i) &&
1560 !SIGISMEMBER(thread->sigmask, i)) {

--- 57 unchanged lines hidden (view full) ---

1618 */
1619 thread->wakeup_time.tv_sec = -1;
1620 thread->wakeup_time.tv_nsec = -1;
1621
1622 /* Insert into the waiting queue: */
1623 KSE_WAITQ_INSERT(kse, thread);
1624 break;
1625 }
1554 /*
1555 * Check for pending signals for this thread to
1556 * see if we need to interrupt it in the kernel.
1557 */
1558 if (thread->check_pending != 0) {
1559 for (i = 1; i <= _SIG_MAXSIG; ++i) {
1560 if (SIGISMEMBER(thread->sigpend, i) &&
1561 !SIGISMEMBER(thread->sigmask, i)) {

--- 57 unchanged lines hidden (view full) ---

1619 */
1620 thread->wakeup_time.tv_sec = -1;
1621 thread->wakeup_time.tv_nsec = -1;
1622
1623 /* Insert into the waiting queue: */
1624 KSE_WAITQ_INSERT(kse, thread);
1625 break;
1626 }
1626 if (thread->state != PS_RUNNING) {
1627 /* Restart the time slice: */
1628 thread->slice_usec = -1;
1629 } else {
1630 if (thread->need_switchout != 0)
1631 /*
1632 * The thread yielded on its own;
1633 * restart the timeslice.
1634 */
1635 thread->slice_usec = -1;
1636 else if ((thread->slice_usec != -1) &&
1637 (thread->attr.sched_policy != SCHED_FIFO)) {
1638 thread->slice_usec += (thread->tmbx.tm_uticks
1639 + thread->tmbx.tm_sticks) * _clock_res_usec;
1640 /* Check for time quantum exceeded: */
1641 if (thread->slice_usec > TIMESLICE_USEC)
1642 thread->slice_usec = -1;
1643 }
1627 thr_accounting(thread);
1628 if (thread->state == PS_RUNNING) {
1644 if (thread->slice_usec == -1) {
1645 /*
1646 * The thread exceeded its time quantum or
1647 * it yielded the CPU; place it at the tail
1648 * of the queue for its priority.
1649 */
1650 KSE_RUNQ_INSERT_TAIL(kse, thread);
1651 } else {

--- 713 unchanged lines hidden ---
1629 if (thread->slice_usec == -1) {
1630 /*
1631 * The thread exceeded its time quantum or
1632 * it yielded the CPU; place it at the tail
1633 * of the queue for its priority.
1634 */
1635 KSE_RUNQ_INSERT_TAIL(kse, thread);
1636 } else {

--- 713 unchanged lines hidden ---