#include <sys/types.h>
#include <sys/proc.h>
#include <sys/thread.h>
#include <sys/class.h>
#include <sys/debug.h>
#include <sys/sobject.h>
#include <sys/cpuvar.h>
#include <sys/schedctl.h>
#include <sys/sdt.h>
static disp_lock_t shuttle_lock;
static void
shuttle_unsleep(kthread_t *t)
{
ASSERT(THREAD_LOCK_HELD(t));
ASSERT(t->t_wchan0 == (caddr_t)1 && t->t_wchan == NULL);
t->t_flag &= ~T_WAKEABLE;
t->t_wchan0 = NULL;
t->t_sobj_ops = NULL;
THREAD_TRANSITION(t);
CL_SETRUN(t);
}
static kthread_t *
shuttle_owner()
{
return (NULL);
}
static void
shuttle_change_pri(kthread_t *t, pri_t p, pri_t *t_prip)
{
ASSERT(THREAD_LOCK_HELD(t));
*t_prip = p;
}
static sobj_ops_t shuttle_sobj_ops = {
SOBJ_SHUTTLE, shuttle_owner, shuttle_unsleep, shuttle_change_pri
};
void
shuttle_resume(kthread_t *t, kmutex_t *l)
{
klwp_t *lwp = ttolwp(curthread);
cpu_t *cp;
disp_lock_t *oldtlp;
thread_lock(curthread);
disp_lock_enter_high(&shuttle_lock);
if (lwp != NULL) {
lwp->lwp_asleep = 1;
lwp->lwp_sysabort = 0;
lwp->lwp_ru.nvcsw++;
}
curthread->t_flag |= T_WAKEABLE;
curthread->t_sobj_ops = &shuttle_sobj_ops;
cp = CPU;
cp->cpu_dispthread = t;
cp->cpu_dispatch_pri = DISP_PRIO(t);
curthread->t_wchan0 = (caddr_t)1;
CL_INACTIVE(curthread);
DTRACE_SCHED1(wakeup, kthread_t *, t);
DTRACE_SCHED(sleep);
THREAD_SLEEP(curthread, &shuttle_lock);
disp_lock_exit_high(&shuttle_lock);
(void) new_mstate(curthread, LMS_SLEEP);
thread_lock_high(t);
oldtlp = t->t_lockp;
t->t_flag &= ~T_WAKEABLE;
t->t_wchan0 = NULL;
t->t_sobj_ops = NULL;
if (t->t_bound_cpu != NULL || t->t_cpupart != cp->cpu_part) {
aston(t);
cp->cpu_runrun = 1;
}
if (t->t_disp_queue != cp->cpu_disp) {
t->t_disp_queue = cp->cpu_disp;
thread_onproc(t, cp);
}
disp_lock_exit_high(oldtlp);
mutex_exit(l);
if (lwp && (ISSIG(curthread, JUSTLOOKING) ||
MUSTRETURN(curproc, curthread) || schedctl_cancel_pending()))
setrun(curthread);
swtch_to(t);
}
void
shuttle_swtch(kmutex_t *l)
{
klwp_t *lwp = ttolwp(curthread);
thread_lock(curthread);
disp_lock_enter_high(&shuttle_lock);
lwp->lwp_asleep = 1;
lwp->lwp_sysabort = 0;
lwp->lwp_ru.nvcsw++;
curthread->t_flag |= T_WAKEABLE;
curthread->t_sobj_ops = &shuttle_sobj_ops;
curthread->t_wchan0 = (caddr_t)1;
CL_INACTIVE(curthread);
DTRACE_SCHED(sleep);
THREAD_SLEEP(curthread, &shuttle_lock);
(void) new_mstate(curthread, LMS_SLEEP);
disp_lock_exit_high(&shuttle_lock);
mutex_exit(l);
if (ISSIG(curthread, JUSTLOOKING) ||
MUSTRETURN(curproc, curthread) || schedctl_cancel_pending())
setrun(curthread);
swtch();
}
void
shuttle_sleep(kthread_t *t)
{
klwp_t *lwp = ttolwp(t);
proc_t *p = ttoproc(t);
thread_lock(t);
disp_lock_enter_high(&shuttle_lock);
if (lwp != NULL) {
lwp->lwp_asleep = 1;
lwp->lwp_sysabort = 0;
lwp->lwp_ru.nvcsw++;
}
t->t_flag |= T_WAKEABLE;
t->t_sobj_ops = &shuttle_sobj_ops;
t->t_wchan0 = (caddr_t)1;
CL_INACTIVE(t);
ASSERT(t->t_mstate == LMS_SLEEP);
THREAD_SLEEP(t, &shuttle_lock);
disp_lock_exit_high(&shuttle_lock);
if (lwp && (ISSIG(t, JUSTLOOKING) || MUSTRETURN(p, t)))
setrun(t);
}