cpr_uthread.c revision 2df1fe9ca32bb227b9158c67f5c00b54c20b10fd
/*
* 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"
extern void utstop_init(void);
extern void add_one_utstop(void);
extern void utstop_timedwait(long ticks);
static void cpr_stop_user(int);
static int cpr_check_user_threads(void);
/*
* CPR user thread related support routines
*/
void
cpr_signal_user(int sig)
{
/*
* The signal SIGTHAW and SIGFREEZE cannot be sent to every thread yet
* since openwin is catching every signal and default action is to exit.
* We also need to implement the true SIGFREEZE and SIGTHAW to stop threads.
*/
struct proc *p;
/* only user threads */
continue;
mutex_enter(&p->p_lock);
mutex_exit(&p->p_lock);
}
}
/* max wait time for user thread stop */
#define CPR_UTSTOP_WAIT hz
#define CPR_UTSTOP_RETRY 4
static int count;
int
{
utstop_init();
count = 0;
do {
if (++count > CPR_UTSTOP_RETRY)
return (ESRCH);
} while (cpr_check_user_threads() &&
return (0);
}
/*
* This routine tries to stop all user threads before we get rid of all
* its pages.It goes through allthreads list and set the TP_CHKPT flag
* for all user threads and make them runnable. If all of the threads
* can be stopped within the max wait time, CPR will proceed. Otherwise
* CPR is aborted after a few of similiar retries.
*/
static void
cpr_stop_user(int wait)
{
proc_t *p;
/* The whole loop below needs to be atomic */
/* faster this way */
do {
/* kernel threads will be handled later */
continue;
/*
* If the thread is stopped (by CPR) already, do nothing;
* if running, mark TP_CHKPT;
* if sleeping normally, mark TP_CHKPT and setrun;
* if sleeping non-interruptable, mark TP_CHKPT only for now;
* if sleeping with t_wchan0 != 0 etc, virtually stopped,
* do nothing.
*/
/* p_lock is needed for modifying t_proc_flag */
mutex_enter(&p->p_lock);
/*
* if already stopped by other reasons, add this new
* reason to it.
*/
} else {
mutex_exit(&p->p_lock);
mutex_enter(&p->p_lock);
}
}
/*
* force the thread into the kernel if it is not already there.
*/
mutex_exit(&p->p_lock);
}
/*
* Checks and makes sure all user threads are stopped
*/
static int
{
int rc = 0;
do {
continue;
/*
* make sure that we are off all the queues and in a stopped
* state.
*/
if (!CPR_ISTOPPED(tp)) {
if (count == CPR_UTSTOP_RETRY) {
"cannot stop uthread\n");
"process %s (%p:%x).",
" network request, please try again.");
}
tp->t_schedflag);
return (1);
}
return (0);
}
/*
* start all threads that were stopped for checkpoint.
*/
void
{
proc_t *p;
do {
/*
* kernel threads are callback'ed rather than setrun.
*/
/*
* t_proc_flag should have been cleared. Just to make sure here
*/
mutex_enter(&p->p_lock);
mutex_exit(&p->p_lock);
if (CPR_ISTOPPED(tp)) {
/*
* put it back on the runq
*/
}
/*
* DEBUG - Keep track of current and next thread pointer.
*/
}
/*
*/
void
cpr_start_kernel_threads(void)
{
/* see table lock below */
}
/*
* Stop kernel threads by using the callback mechanism. If any thread
* cannot be stopped, return failure.
*/
int
cpr_stop_kernel_threads(void)
{
callb_lock_table(); /* Note: we unlock the table in resume. */
"Could not stop \"%s\" kernel thread. "
"Please try again later.", name);
return (EBUSY);
}
return (0);
}
/*
* Check to see that kernel threads are stopped.
* This should be called while CPU's are paused, and the caller is
* effectively running single user, or else we are virtually guaranteed
* to fail. The routine should not ASSERT on the paused state or spl
* level, as there may be a use for this to verify that things are running
* again.
*/
int
cpr_threads_are_stopped(void)
{
proc_t *p;
/*
* We think we stopped all the kernel threads. Just in case
* someone is not playing by the rules, take a spin through
* the threadlist and see if we can account for everybody.
*/
do {
continue;
continue;
"\"%s\" kernel thread not stopped.", name);
return (EBUSY);
}
return (0);
}