schedctl.c revision 47eb4d1eb88936d972e042f5583dcbec45d121a9
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/schedctl.h>
#include <sys/sysmacros.h>
/*
* Page handling structures. This is set up as a list of per-page
* control structures (sc_page_ctl), with p->p_pagep pointing to
* the first. The per-page structures point to the actual pages
* and contain pointers to the user address for each mapped page.
*
* All data is protected by p->p_sc_lock. Since this lock is
* held while waiting for memory, schedctl_shared_alloc() should
* not be called while holding p_lock.
*/
typedef struct sc_page_ctl {
struct sc_page_ctl *spc_next;
/* Context ops */
static void schedctl_save(sc_shared_t *);
static void schedctl_restore(sc_shared_t *);
/* Functions for handling shared pages */
/*
* System call interface to scheduler activations.
* This always operates on the current lwp.
*/
schedctl(void)
{
int error;
if (t->t_schedctl == NULL) {
/*
* Allocate and initialize the shared structure.
*/
thread_lock(t); /* protect against ts_tick and ts_update */
t->t_schedctl = ssp;
t->t_sc_uaddr = uaddr;
thread_unlock(t);
}
return ((caddr_t)t->t_sc_uaddr);
}
/*
* Clean up scheduler activations state associated with an exiting
* (or execing) lwp. t is always the current thread.
*/
void
{
thread_lock(t); /* protect against ts_tick and ts_update */
t->t_schedctl = NULL;
t->t_sc_uaddr = 0;
thread_unlock(t);
/*
* Remove the context op to avoid the final call to
* schedctl_save when switching away from this lwp.
*/
/*
* Do not unmap the shared page until the process exits.
* User-level library code relies on this for adaptive mutex locking.
*/
mutex_enter(&p->p_sc_lock);
mutex_exit(&p->p_sc_lock);
}
/*
* Cleanup the list of schedctl shared pages for the process.
* Called from exec() and exit() system calls.
*/
void
{
/*
* Since we are single-threaded, we don't have to hold p->p_sc_lock.
*/
/*
* Unmap the user space and free the mapping structure.
*/
}
}
/*
* Called by resume just before switching away from the current thread.
* Save new thread state.
*/
void
{
}
/*
* Called by resume after switching to the current thread.
* Save new thread state and CPU.
*/
void
{
}
/*
* On fork, remove inherited mappings from the child's address space.
* The child's threads must call schedctl() to get new shared mappings.
*/
void
{
/*
* Do this only once, whether we are doing fork1() or forkall().
* Don't do it at all if the child process is a child of vfork()
* because a child of vfork() borrows the parent's address space.
*/
return;
}
/*
* Returns non-zero if the specified thread shouldn't be preempted at this time.
* Called by ts_preempt, ts_tick, and ts_update.
*/
int
{
ASSERT(THREAD_LOCK_HELD(t));
}
/*
* Sets the value of the nopreempt field for the specified thread.
* Called by ts_preempt to clear the field on preemption.
*/
void
{
ASSERT(THREAD_LOCK_HELD(t));
}
/*
* Sets the value of the yield field for the specified thread. Called by
* ts_preempt and ts_tick to set the field, and ts_yield to clear it.
* The kernel never looks at this field so we don't need a schedctl_get_yield
* function.
*/
void
{
ASSERT(THREAD_LOCK_HELD(t));
}
/*
* Returns non-zero if the specified thread has requested that all
* signals be blocked. Called by signal-related code that tests
* the signal mask of a thread that may not be the current thread
* and where the process's p_lock cannot be acquired.
*/
int
{
return (tdp->sc_sigblock);
return (0);
}
/*
* If the sc_sigblock field is set for the specified thread, set
* its signal mask to block all maskable signals, then clear the
* sc_sigblock field. This finishes what user-level code requested
* to be done when it set tdp->sc_shared->sc_sigblock non-zero.
* Called by signal-related code that holds the process's p_lock.
*/
void
{
tdp->sc_sigblock = 0;
}
}
/*
* Return non-zero if the current thread has declared that
* it is calling into the kernel to park, else return zero.
*/
int
{
/*
* If we're here and there is no shared memory (how could
* that happen?) then just assume we really are here to park.
*/
return (1);
}
/*
* Declare thread is parking.
*
* libc will set "sc_park = 1" before calling lwpsys_park(0, tid) in order
* to declare that the thread is calling into the kernel to park.
*
* This interface exists ONLY to support older versions of libthread which
* are not aware of the sc_park flag.
*
* Older versions of libthread which are not aware of the sc_park flag need to
* be modified or emulated to call lwpsys_park(4, ...) instead of
* lwpsys_park(0, ...). This will invoke schedctl_set_park() before
* lwp_park() to declare that the thread is parking.
*/
void
{
}
/*
* Clear the shared sc_park flag on return from parking in the kernel.
*/
void
{
}
/*
* Page handling code.
*/
void
{
/*
* Amount of page that can hold sc_shared_t structures. If
* sizeof (sc_shared_t) is a power of 2, this should just be
* PAGESIZE.
*/
/*
* Allocation bitmap is one bit per struct on a page.
*/
}
int
{
int error;
mutex_enter(&p->p_sc_lock);
/*
* Try to find space for the new data in existing pages
* within the process's list of shared pages.
*/
break;
else {
/*
* No room, need to allocate a new page. Also set up
* a mapping to the kernel address space for the new
* page and lock it in memory.
*/
mutex_exit(&p->p_sc_lock);
return (error);
}
mutex_exit(&p->p_sc_lock);
return (error);
}
/*
* Allocate and initialize the page control structure.
*/
KM_SLEEP);
}
/*
* Got a page, now allocate space for the data. There should
* be space unless something's wrong.
*/
/*
* Get location with pointer arithmetic. spc_base is of type
* sc_shared_t *. Mark as allocated.
*/
mutex_exit(&p->p_sc_lock);
/*
* Return kernel and user addresses.
*/
return (0);
}
/*
* Find the page control structure corresponding to a kernel address.
*/
static sc_page_ctl_t *
{
return (pagep);
}
return (NULL); /* This "can't happen". Should we panic? */
}
/*
* This function is called when a page needs to be mapped into a
* process's address space. Allocate the user address space and
* set up the mapping to the page. Assumes the page has already
* been allocated and locked in memory via schedctl_getpage.
*/
static int
{
struct segvn_crargs vn_a;
int error;
/* pass address of kernel mapping as offset to avoid VAC conflicts */
return (ENOMEM);
}
/*
* Use segvn to set up the mapping to the page.
*/
if (error)
return (error);
return (0);
}
/*
* Allocate a new page from anonymous memory. Also, create a kernel
* mapping to the page and lock the page in memory.
*/
static int
{
/*
* Set up anonymous memory struct. No swap reservation is
* needed since the page will be locked into memory.
*/
/*
* Allocate the page.
*/
return (ENOMEM);
}
/*
* The page is left SE_SHARED locked so that it won't be
* paged out or relocated (KPD_LOCKED above).
*/
return (0);
}
/*
* Take the necessary steps to allow a page to be released.
* This is called when the process is doing exit() or exec().
* There should be no accesses to the page after this.
* The kernel mapping of the page is released and the page is unlocked.
*/
static void
{
/*
* Release the lock on the page and remove the kernel mapping.
*/
/*
* Decrement the refcnt so the anon_map structure will be freed.
*/
/*
* The current process no longer has the page mapped, so
* we have to free everything rather than letting as_free
* do the work.
*/
} else {
}
}