/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Wait queue implementation.
*/
void
{
}
void
{
}
/*
* Operations on waitq_t structures.
*
* A wait queue is a singly linked NULL-terminated list with doubly
* linked circular sublists. The singly linked list is in descending
* priority order and FIFO for threads of the same priority. It links
* through the t_link field of the thread structure. The doubly linked
* sublists link threads of the same priority. They use the t_priforw
* and t_priback fields of the thread structure.
*
* Graphically (with priorities in parens):
*
* ________________ _______ _______
* / \ / \ / \
* | | | | | |
* v v v v v v
* t1(60)-->t2(60)-->t3(60)-->t4(50)-->t5(50)-->t6(30)-->t7(0)-->t8(0)
* ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
* | | | | | | | | | |
* \______/ \______/ \_______/ \__/ \_______/
*
* There are three interesting operations on a waitq list: inserting
* a thread into the proper position according to priority; removing a
* thread given a pointer to it; and walking the list, possibly
* removing threads along the way. This design allows all three
* operations to be performed efficiently and easily.
*
* To insert a thread, traverse the list looking for the sublist of
* the same priority as the thread (or one of a lower priority,
* meaning there are no other threads in the list of the same
* priority). This can be done without touching all threads in the
* list by following the links between the first threads in each
* sublist. Given a thread t that is the head of a sublist (the first
* thread of that priority found when following the t_link pointers),
* t->t_priback->t_link points to the head of the next sublist. It's
* important to do this since a waitq may contain thousands of
* threads.
*
* Removing a thread from the list is also efficient. First, the
* t_waitq field contains a pointer to the waitq on which a thread
* is waiting (or NULL if it's not on a waitq). This is used to
* determine if the given thread is on the given waitq without
* searching the list. Assuming it is, if it's not the head of a
* sublist, just remove it from the sublist and use the t_priback
* pointer to find the thread that points to it with t_link. If it is
* the head of a sublist, search for it by walking the sublist heads,
* similar to searching for a given priority level when inserting a
* thread.
*
* To walk the list, simply follow the t_link pointers. Removing
* threads along the way can be done easily if the code maintains a
* pointer to the t_link field that pointed to the thread being
* removed.
*/
static void
{
break;
}
*tpp = t;
/* last_tp points to the last thread of this priority */
} else {
}
}
static void
{
ASSERT(THREAD_LOCK_HELD(t));
/*
* Is it the head of a priority sublist? If so, need to walk
* the priorities to find the t_link pointer that points to it.
*/
if (*ptl != t) {
/*
* Find the right priority level.
*/
}
/*
* Remove thread from the t_link list.
*/
/*
* Take it off the priority sublist if there's more than one
* thread there.
*/
if (t->t_priforw != t) {
}
}
/*
* Put specified thread to specified wait queue without dropping thread's lock.
* Returns 1 if thread was successfully placed on project's wait queue, or
* 0 if wait queue is blocked.
*/
int
{
ASSERT(THREAD_LOCK_HELD(t));
/*
* Can't enqueue anything on a blocked wait queue
*/
if (wq->wq_blocked) {
return (0);
}
/*
* Mark the time when thread is placed on wait queue. The microstate
* accounting code uses this timestamp to determine wait times.
*/
t->t_waitrq = gethrtime_unscaled();
/*
* Mark thread as not swappable. If necessary, it will get
* swapped out when it returns to the userland.
*/
t->t_schedflag |= TS_DONT_SWAP;
waitq_link(wq, t);
return (1);
}
/*
* Change thread's priority while on the wait queue.
* Dequeue and equeue it again so that it gets placed in the right place.
*/
void
{
ASSERT(THREAD_LOCK_HELD(t));
waitq_unlink(wq, t);
waitq_link(wq, t);
}
static void
{
ASSERT(THREAD_LOCK_HELD(t));
waitq_unlink(wq, t);
/*
* Change thread to transition state and drop the wait queue lock. The
* thread will remain locked since its t_lockp points to the
* transition_lock.
*/
}
/*
* Return True iff there are any threads on the specified wait queue.
* The check is done **without holding any locks**.
*/
{
}
/*
* Take thread off its wait queue and make it runnable.
* Returns with thread lock held.
*/
void
{
ASSERT(THREAD_LOCK_HELD(t));
panic("waitq_setrun: thread %p is not on waitq", (void *)t);
waitq_dequeue(wq, t);
CL_SETRUN(t);
}
/*
* Take the first thread off the wait queue and return pointer to it.
*/
static kthread_t *
{
kthread_t *t;
/*
* waitq_dequeue drops wait queue lock but leaves the CPU at high PIL.
*/
else
return (t);
}
/*
* Take the first thread off the wait queue and make it runnable.
* Return the pointer to the thread or NULL if waitq is empty
*/
static kthread_t *
{
kthread_t *t;
t = waitq_takeone(wq);
if (t != NULL) {
/*
* t should have transition lock held.
* CL_SETRUN() will replace it with dispq lock and keep it held.
* thread_unlock() will drop dispq lock and restore PIL.
*/
ASSERT(THREAD_LOCK_HELD(t));
CL_SETRUN(t);
thread_unlock(t);
}
return (t);
}
/*
* Take the first thread off the wait queue and make it runnable.
*/
void
{
(void) waitq_runfirst(wq);
}
/*
* Take all threads off the wait queue and make them runnable.
*/
static void
{
;
}
/*
* Prevent any new threads from entering wait queue and make all threads
* currently on the wait queue runnable. After waitq_block() completion, no
* threads should ever appear on the wait queue untill it is unblocked.
*/
void
{
}
/*
* Allow threads to be placed on the wait queue.
*/
void
{
}