Deleted Added
sdiff udiff text old ( 134586 ) new ( 134591 )
full compact
1/*-
2 * Copyright (c) 1982, 1986, 1990, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 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/sys/kern/sched_4bsd.c 134586 2004-09-01 02:11:28Z julian $");
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/kernel.h>
41#include <sys/ktr.h>
42#include <sys/lock.h>
43#include <sys/kthread.h>
44#include <sys/mutex.h>

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

693 kg->kg_slptime = 0;
694 setrunqueue(td, SRQ_BORING);
695}
696
697void
698sched_add(struct thread *td, int flags)
699{
700 struct kse *ke;
701
702 ke = td->td_kse;
703 mtx_assert(&sched_lock, MA_OWNED);
704 KASSERT((ke->ke_thread != NULL), ("sched_add: No thread on KSE"));
705 KASSERT((ke->ke_thread->td_kse != NULL),
706 ("sched_add: No KSE on thread"));
707 KASSERT(ke->ke_state != KES_ONRUNQ,
708 ("sched_add: kse %p (%s) already in run queue", ke,
709 ke->ke_proc->p_comm));
710 KASSERT(ke->ke_proc->p_sflag & PS_INMEM,
711 ("sched_add: process swapped out"));
712
713#ifdef SMP
714 /*
715 * Only try to preempt if the thread is unpinned or pinned to the
716 * current CPU.
717 */
718 if (KSE_CAN_MIGRATE(ke) || ke->ke_runq == &runq_pcpu[PCPU_GET(cpuid)])
719#endif
720 /*
721 * Don't try preempt if we are already switching.
722 * all hell might break loose.
723 */
724 if ((flags & SRQ_YIELDING) == 0)
725 if (maybe_preempt(td))
726 return;
727
728#ifdef SMP
729 if (KSE_CAN_MIGRATE(ke)) {
730 CTR2(KTR_RUNQ, "sched_add: adding kse:%p (td:%p) to gbl runq", ke, td);
731 ke->ke_runq = &runq;
732 } else {
733 CTR2(KTR_RUNQ, "sched_add: adding kse:%p (td:%p)to pcpu runq", ke, td);
734 if (!SKE_RUNQ_PCPU(ke))
735 ke->ke_runq = &runq_pcpu[PCPU_GET(cpuid)];
736 }
737#else
738 CTR2(KTR_RUNQ, "sched_add: adding kse:%p (td:%p) to runq", ke, td);
739 ke->ke_runq = &runq;
740#endif
741 if ((td->td_proc->p_flag & P_NOLOAD) == 0)
742 sched_tdcnt++;
743 runq_add(ke->ke_runq, ke);
744 ke->ke_ksegrp->kg_runq_kses++;
745 ke->ke_state = KES_ONRUNQ;
746 maybe_resched(td);
747}
748

--- 155 unchanged lines hidden ---