2008-01-07 14:41:29 +03:00
|
|
|
/* $NetBSD: kern_lwp.c,v 1.89 2008/01/07 11:41:29 yamt Exp $ */
|
2003-01-18 13:06:22 +03:00
|
|
|
|
|
|
|
/*-
|
2007-02-10 00:55:00 +03:00
|
|
|
* Copyright (c) 2001, 2006, 2007 The NetBSD Foundation, Inc.
|
2003-01-18 13:06:22 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2007-02-10 00:55:00 +03:00
|
|
|
* by Nathan J. Williams, and Andrew Doran.
|
2003-01-18 13:06:22 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Overview
|
|
|
|
*
|
2007-07-28 04:12:26 +04:00
|
|
|
* Lightweight processes (LWPs) are the basic unit or thread of
|
2007-02-10 00:55:00 +03:00
|
|
|
* execution within the kernel. The core state of an LWP is described
|
2007-07-28 04:12:26 +04:00
|
|
|
* by "struct lwp", also known as lwp_t.
|
2007-02-10 00:55:00 +03:00
|
|
|
*
|
|
|
|
* Each LWP is contained within a process (described by "struct proc"),
|
|
|
|
* Every process contains at least one LWP, but may contain more. The
|
|
|
|
* process describes attributes shared among all of its LWPs such as a
|
|
|
|
* private address space, global execution state (stopped, active,
|
|
|
|
* zombie, ...), signal disposition and so on. On a multiprocessor
|
2007-07-28 04:12:26 +04:00
|
|
|
* machine, multiple LWPs be executing concurrently in the kernel.
|
2007-02-10 00:55:00 +03:00
|
|
|
*
|
|
|
|
* Execution states
|
|
|
|
*
|
|
|
|
* At any given time, an LWP has overall state that is described by
|
|
|
|
* lwp::l_stat. The states are broken into two sets below. The first
|
|
|
|
* set is guaranteed to represent the absolute, current state of the
|
|
|
|
* LWP:
|
|
|
|
*
|
|
|
|
* LSONPROC
|
|
|
|
*
|
|
|
|
* On processor: the LWP is executing on a CPU, either in the
|
|
|
|
* kernel or in user space.
|
|
|
|
*
|
|
|
|
* LSRUN
|
|
|
|
*
|
|
|
|
* Runnable: the LWP is parked on a run queue, and may soon be
|
|
|
|
* chosen to run by a idle processor, or by a processor that
|
|
|
|
* has been asked to preempt a currently runnning but lower
|
|
|
|
* priority LWP. If the LWP is not swapped in (L_INMEM == 0)
|
|
|
|
* then the LWP is not on a run queue, but may be soon.
|
|
|
|
*
|
|
|
|
* LSIDL
|
|
|
|
*
|
2007-07-28 04:12:26 +04:00
|
|
|
* Idle: the LWP has been created but has not yet executed,
|
|
|
|
* or it has ceased executing a unit of work and is waiting
|
|
|
|
* to be started again.
|
2007-02-10 00:55:00 +03:00
|
|
|
*
|
|
|
|
* LSSUSPENDED:
|
|
|
|
*
|
|
|
|
* Suspended: the LWP has had its execution suspended by
|
|
|
|
* another LWP in the same process using the _lwp_suspend()
|
|
|
|
* system call. User-level LWPs also enter the suspended
|
|
|
|
* state when the system is shutting down.
|
|
|
|
*
|
|
|
|
* The second set represent a "statement of intent" on behalf of the
|
|
|
|
* LWP. The LWP may in fact be executing on a processor, may be
|
2007-07-28 04:12:26 +04:00
|
|
|
* sleeping or idle. It is expected to take the necessary action to
|
|
|
|
* stop executing or become "running" again within a short timeframe.
|
|
|
|
* The LW_RUNNING flag in lwp::l_flag indicates that an LWP is running.
|
|
|
|
* Importantly, in indicates that its state is tied to a CPU.
|
2007-02-10 00:55:00 +03:00
|
|
|
*
|
|
|
|
* LSZOMB:
|
|
|
|
*
|
2007-07-28 04:12:26 +04:00
|
|
|
* Dead or dying: the LWP has released most of its resources
|
|
|
|
* and is a) about to switch away into oblivion b) has already
|
|
|
|
* switched away. When it switches away, its few remaining
|
|
|
|
* resources can be collected.
|
2007-02-10 00:55:00 +03:00
|
|
|
*
|
|
|
|
* LSSLEEP:
|
|
|
|
*
|
|
|
|
* Sleeping: the LWP has entered itself onto a sleep queue, and
|
2007-07-28 04:12:26 +04:00
|
|
|
* has switched away or will switch away shortly to allow other
|
|
|
|
* LWPs to run on the CPU.
|
2007-02-10 00:55:00 +03:00
|
|
|
*
|
|
|
|
* LSSTOP:
|
|
|
|
*
|
|
|
|
* Stopped: the LWP has been stopped as a result of a job
|
|
|
|
* control signal, or as a result of the ptrace() interface.
|
2007-07-28 04:12:26 +04:00
|
|
|
*
|
2007-02-10 00:55:00 +03:00
|
|
|
* Stopped LWPs may run briefly within the kernel to handle
|
|
|
|
* signals that they receive, but will not return to user space
|
|
|
|
* until their process' state is changed away from stopped.
|
2007-07-28 04:12:26 +04:00
|
|
|
*
|
2007-02-10 00:55:00 +03:00
|
|
|
* Single LWPs within a process can not be set stopped
|
|
|
|
* selectively: all actions that can stop or continue LWPs
|
|
|
|
* occur at the process level.
|
|
|
|
*
|
|
|
|
* State transitions
|
|
|
|
*
|
2007-07-28 04:12:26 +04:00
|
|
|
* Note that the LSSTOP state may only be set when returning to
|
|
|
|
* user space in userret(), or when sleeping interruptably. The
|
|
|
|
* LSSUSPENDED state may only be set in userret(). Before setting
|
|
|
|
* those states, we try to ensure that the LWPs will release all
|
|
|
|
* locks that they hold, and at a minimum try to ensure that the
|
|
|
|
* LWP can be set runnable again by a signal.
|
2007-02-10 00:55:00 +03:00
|
|
|
*
|
|
|
|
* LWPs may transition states in the following ways:
|
|
|
|
*
|
|
|
|
* RUN -------> ONPROC ONPROC -----> RUN
|
|
|
|
* > STOPPED > SLEEP
|
|
|
|
* > SUSPENDED > STOPPED
|
|
|
|
* > SUSPENDED
|
|
|
|
* > ZOMB
|
|
|
|
*
|
|
|
|
* STOPPED ---> RUN SUSPENDED --> RUN
|
|
|
|
* > SLEEP > SLEEP
|
|
|
|
*
|
|
|
|
* SLEEP -----> ONPROC IDL --------> RUN
|
|
|
|
* > RUN > SUSPENDED
|
|
|
|
* > STOPPED > STOPPED
|
|
|
|
* > SUSPENDED
|
|
|
|
*
|
2007-07-28 04:12:26 +04:00
|
|
|
* Other state transitions are possible with kernel threads (eg
|
|
|
|
* ONPROC -> IDL), but only happen under tightly controlled
|
|
|
|
* circumstances the side effects are understood.
|
|
|
|
*
|
2007-02-10 00:55:00 +03:00
|
|
|
* Locking
|
|
|
|
*
|
|
|
|
* The majority of fields in 'struct lwp' are covered by a single,
|
2007-07-28 04:12:26 +04:00
|
|
|
* general spin lock pointed to by lwp::l_mutex. The locks covering
|
2007-02-10 00:55:00 +03:00
|
|
|
* each field are documented in sys/lwp.h.
|
|
|
|
*
|
2007-07-28 04:12:26 +04:00
|
|
|
* State transitions must be made with the LWP's general lock held,
|
|
|
|
* and may cause the LWP's lock pointer to change. Manipulation of
|
|
|
|
* the general lock is not performed directly, but through calls to
|
|
|
|
* lwp_lock(), lwp_relock() and similar.
|
2007-02-10 00:55:00 +03:00
|
|
|
*
|
|
|
|
* States and their associated locks:
|
|
|
|
*
|
2007-10-13 04:30:26 +04:00
|
|
|
* LSONPROC, LSZOMB:
|
2007-02-10 00:55:00 +03:00
|
|
|
*
|
2007-05-17 18:51:11 +04:00
|
|
|
* Always covered by spc_lwplock, which protects running LWPs.
|
|
|
|
* This is a per-CPU lock.
|
2007-02-10 00:55:00 +03:00
|
|
|
*
|
2007-10-13 04:30:26 +04:00
|
|
|
* LSIDL, LSRUN:
|
2007-02-10 00:55:00 +03:00
|
|
|
*
|
2007-05-17 18:51:11 +04:00
|
|
|
* Always covered by spc_mutex, which protects the run queues.
|
|
|
|
* This may be a per-CPU lock, depending on the scheduler.
|
2007-02-10 00:55:00 +03:00
|
|
|
*
|
|
|
|
* LSSLEEP:
|
|
|
|
*
|
2007-07-28 04:12:26 +04:00
|
|
|
* Covered by a lock associated with the sleep queue that the
|
2007-02-10 00:55:00 +03:00
|
|
|
* LWP resides on, indirectly referenced by l_sleepq->sq_mutex.
|
|
|
|
*
|
|
|
|
* LSSTOP, LSSUSPENDED:
|
|
|
|
*
|
|
|
|
* If the LWP was previously sleeping (l_wchan != NULL), then
|
2007-07-28 04:12:26 +04:00
|
|
|
* l_mutex references the sleep queue lock. If the LWP was
|
2007-02-10 00:55:00 +03:00
|
|
|
* runnable or on the CPU when halted, or has been removed from
|
2007-07-28 04:12:26 +04:00
|
|
|
* the sleep queue since halted, then the lock is spc_lwplock.
|
2007-02-10 00:55:00 +03:00
|
|
|
*
|
|
|
|
* The lock order is as follows:
|
|
|
|
*
|
2007-05-17 18:51:11 +04:00
|
|
|
* spc::spc_lwplock ->
|
|
|
|
* sleepq_t::sq_mutex ->
|
|
|
|
* tschain_t::tc_mutex ->
|
|
|
|
* spc::spc_mutex
|
2007-02-10 00:55:00 +03:00
|
|
|
*
|
2007-07-28 04:12:26 +04:00
|
|
|
* Each process has an scheduler state lock (proc::p_smutex), and a
|
2007-02-10 00:55:00 +03:00
|
|
|
* number of counters on LWPs and their states: p_nzlwps, p_nrlwps, and
|
|
|
|
* so on. When an LWP is to be entered into or removed from one of the
|
|
|
|
* following states, p_mutex must be held and the process wide counters
|
|
|
|
* adjusted:
|
|
|
|
*
|
|
|
|
* LSIDL, LSZOMB, LSSTOP, LSSUSPENDED
|
|
|
|
*
|
|
|
|
* Note that an LWP is considered running or likely to run soon if in
|
|
|
|
* one of the following states. This affects the value of p_nrlwps:
|
|
|
|
*
|
|
|
|
* LSRUN, LSONPROC, LSSLEEP
|
|
|
|
*
|
|
|
|
* p_smutex does not need to be held when transitioning among these
|
|
|
|
* three states.
|
|
|
|
*/
|
|
|
|
|
2003-07-14 18:59:01 +04:00
|
|
|
#include <sys/cdefs.h>
|
2008-01-07 14:41:29 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.89 2008/01/07 11:41:29 yamt Exp $");
|
2003-07-14 18:59:01 +04:00
|
|
|
|
2007-12-13 05:45:09 +03:00
|
|
|
#include "opt_ddb.h"
|
2003-06-23 15:00:59 +04:00
|
|
|
#include "opt_multiprocessor.h"
|
2007-02-10 00:55:00 +03:00
|
|
|
#include "opt_lockdebug.h"
|
2003-06-23 15:00:59 +04:00
|
|
|
|
2006-10-24 14:05:45 +04:00
|
|
|
#define _LWP_API_PRIVATE
|
|
|
|
|
2003-01-18 13:06:22 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2007-05-17 18:51:11 +04:00
|
|
|
#include <sys/cpu.h>
|
2003-01-18 13:06:22 +03:00
|
|
|
#include <sys/pool.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/syscallargs.h>
|
2007-02-18 19:58:15 +03:00
|
|
|
#include <sys/syscall_stats.h>
|
2006-07-20 01:11:37 +04:00
|
|
|
#include <sys/kauth.h>
|
2007-02-10 00:55:00 +03:00
|
|
|
#include <sys/sleepq.h>
|
2007-12-13 08:25:03 +03:00
|
|
|
#include <sys/user.h>
|
2007-02-10 00:55:00 +03:00
|
|
|
#include <sys/lockdebug.h>
|
|
|
|
#include <sys/kmem.h>
|
2007-11-06 03:42:39 +03:00
|
|
|
#include <sys/intr.h>
|
2007-11-13 02:11:58 +03:00
|
|
|
#include <sys/lwpctl.h>
|
2007-12-02 17:55:32 +03:00
|
|
|
#include <sys/atomic.h>
|
2003-01-18 13:06:22 +03:00
|
|
|
|
|
|
|
#include <uvm/uvm_extern.h>
|
2007-11-13 14:38:35 +03:00
|
|
|
#include <uvm/uvm_object.h>
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-11-12 02:22:23 +03:00
|
|
|
struct lwplist alllwp = LIST_HEAD_INITIALIZER(alllwp);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2006-10-08 08:28:44 +04:00
|
|
|
POOL_INIT(lwp_uc_pool, sizeof(ucontext_t), 0, 0, 0, "lwpucpl",
|
2007-03-12 21:18:22 +03:00
|
|
|
&pool_allocator_nointr, IPL_NONE);
|
2006-10-08 08:28:44 +04:00
|
|
|
|
2007-12-26 19:01:34 +03:00
|
|
|
static pool_cache_t lwp_cache;
|
2006-10-08 08:28:44 +04:00
|
|
|
static specificdata_domain_t lwp_specificdata_domain;
|
|
|
|
|
|
|
|
void
|
|
|
|
lwpinit(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
lwp_specificdata_domain = specificdata_domain_create();
|
|
|
|
KASSERT(lwp_specificdata_domain != NULL);
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_sys_init();
|
2007-12-26 19:01:34 +03:00
|
|
|
lwp_cache = pool_cache_init(sizeof(lwp_t), MIN_LWP_ALIGNMENT, 0, 0,
|
|
|
|
"lwppl", NULL, IPL_NONE, NULL, NULL, NULL);
|
2006-10-08 08:28:44 +04:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Set an suspended.
|
|
|
|
*
|
|
|
|
* Must be called with p_smutex held, and the LWP locked. Will unlock the
|
|
|
|
* LWP before return.
|
|
|
|
*/
|
2003-01-18 13:06:22 +03:00
|
|
|
int
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_suspend(struct lwp *curl, struct lwp *t)
|
2003-01-18 13:06:22 +03:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
int error;
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-03-21 21:25:59 +03:00
|
|
|
KASSERT(mutex_owned(&t->l_proc->p_smutex));
|
|
|
|
KASSERT(lwp_locked(t, NULL));
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
KASSERT(curl != t || curl->l_stat == LSONPROC);
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* If the current LWP has been told to exit, we must not suspend anyone
|
|
|
|
* else or deadlock could occur. We won't return to userspace.
|
2003-01-18 13:06:22 +03:00
|
|
|
*/
|
2007-02-18 01:31:36 +03:00
|
|
|
if ((curl->l_stat & (LW_WEXIT | LW_WCORE)) != 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_unlock(t);
|
|
|
|
return (EDEADLK);
|
2003-01-18 13:06:22 +03:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
error = 0;
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
switch (t->l_stat) {
|
|
|
|
case LSRUN:
|
|
|
|
case LSONPROC:
|
2007-02-18 01:31:36 +03:00
|
|
|
t->l_flag |= LW_WSUSPEND;
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_need_userret(t);
|
|
|
|
lwp_unlock(t);
|
|
|
|
break;
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
case LSSLEEP:
|
2007-02-18 01:31:36 +03:00
|
|
|
t->l_flag |= LW_WSUSPEND;
|
2003-01-18 13:06:22 +03:00
|
|
|
|
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* Kick the LWP and try to get it to the kernel boundary
|
|
|
|
* so that it will release any locks that it holds.
|
|
|
|
* setrunnable() will release the lock.
|
2003-01-18 13:06:22 +03:00
|
|
|
*/
|
2007-02-18 01:31:36 +03:00
|
|
|
if ((t->l_flag & LW_SINTR) != 0)
|
2007-02-10 00:55:00 +03:00
|
|
|
setrunnable(t);
|
|
|
|
else
|
|
|
|
lwp_unlock(t);
|
|
|
|
break;
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
case LSSUSPENDED:
|
|
|
|
lwp_unlock(t);
|
|
|
|
break;
|
2003-12-25 01:42:11 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
case LSSTOP:
|
2007-02-18 01:31:36 +03:00
|
|
|
t->l_flag |= LW_WSUSPEND;
|
2007-02-10 00:55:00 +03:00
|
|
|
setrunnable(t);
|
|
|
|
break;
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
case LSIDL:
|
|
|
|
case LSZOMB:
|
|
|
|
error = EINTR; /* It's what Solaris does..... */
|
|
|
|
lwp_unlock(t);
|
|
|
|
break;
|
2003-01-18 13:06:22 +03:00
|
|
|
}
|
|
|
|
|
2007-08-02 05:48:44 +04:00
|
|
|
return (error);
|
2003-01-18 13:06:22 +03:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Restart a suspended LWP.
|
|
|
|
*
|
|
|
|
* Must be called with p_smutex held, and the LWP locked. Will unlock the
|
|
|
|
* LWP before return.
|
|
|
|
*/
|
2003-01-18 13:06:22 +03:00
|
|
|
void
|
|
|
|
lwp_continue(struct lwp *l)
|
|
|
|
{
|
|
|
|
|
2007-03-21 21:25:59 +03:00
|
|
|
KASSERT(mutex_owned(&l->l_proc->p_smutex));
|
|
|
|
KASSERT(lwp_locked(l, NULL));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
/* If rebooting or not suspended, then just bail out. */
|
2007-02-18 01:31:36 +03:00
|
|
|
if ((l->l_flag & LW_WREBOOT) != 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_unlock(l);
|
2003-01-18 13:06:22 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-02-18 01:31:36 +03:00
|
|
|
l->l_flag &= ~LW_WSUSPEND;
|
2003-07-17 22:16:58 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
if (l->l_stat != LSSUSPENDED) {
|
|
|
|
lwp_unlock(l);
|
|
|
|
return;
|
2003-01-18 13:06:22 +03:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/* setrunnable() will release the lock. */
|
|
|
|
setrunnable(l);
|
2003-01-18 13:06:22 +03:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Wait for an LWP within the current process to exit. If 'lid' is
|
|
|
|
* non-zero, we are waiting for a specific LWP.
|
|
|
|
*
|
|
|
|
* Must be called with p->p_smutex held.
|
|
|
|
*/
|
2003-01-18 13:06:22 +03:00
|
|
|
int
|
|
|
|
lwp_wait1(struct lwp *l, lwpid_t lid, lwpid_t *departed, int flags)
|
|
|
|
{
|
|
|
|
struct proc *p = l->l_proc;
|
2007-02-10 00:55:00 +03:00
|
|
|
struct lwp *l2;
|
|
|
|
int nfound, error;
|
2007-03-21 21:25:59 +03:00
|
|
|
lwpid_t curlid;
|
|
|
|
bool exiting;
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-03-21 21:25:59 +03:00
|
|
|
KASSERT(mutex_owned(&p->p_smutex));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
p->p_nlwpwait++;
|
2007-03-21 21:25:59 +03:00
|
|
|
l->l_waitingfor = lid;
|
|
|
|
curlid = l->l_lid;
|
|
|
|
exiting = ((flags & LWPWAIT_EXITCONTROL) != 0);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
/*
|
|
|
|
* Avoid a race between exit1() and sigexit(): if the
|
|
|
|
* process is dumping core, then we need to bail out: call
|
|
|
|
* into lwp_userret() where we will be suspended until the
|
|
|
|
* deed is done.
|
|
|
|
*/
|
|
|
|
if ((p->p_sflag & PS_WCORE) != 0) {
|
|
|
|
mutex_exit(&p->p_smutex);
|
|
|
|
lwp_userret(l);
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
panic("lwp_wait1");
|
|
|
|
#endif
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First off, drain any detached LWP that is waiting to be
|
|
|
|
* reaped.
|
|
|
|
*/
|
|
|
|
while ((l2 = p->p_zomblwp) != NULL) {
|
|
|
|
p->p_zomblwp = NULL;
|
2007-03-21 21:25:59 +03:00
|
|
|
lwp_free(l2, false, false);/* releases proc mutex */
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&p->p_smutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now look for an LWP to collect. If the whole process is
|
|
|
|
* exiting, count detached LWPs as eligible to be collected,
|
|
|
|
* but don't drain them here.
|
|
|
|
*/
|
|
|
|
nfound = 0;
|
2007-03-21 21:25:59 +03:00
|
|
|
error = 0;
|
2007-02-10 00:55:00 +03:00
|
|
|
LIST_FOREACH(l2, &p->p_lwps, l_sibling) {
|
2007-03-21 21:25:59 +03:00
|
|
|
/*
|
|
|
|
* If a specific wait and the target is waiting on
|
|
|
|
* us, then avoid deadlock. This also traps LWPs
|
|
|
|
* that try to wait on themselves.
|
|
|
|
*
|
|
|
|
* Note that this does not handle more complicated
|
|
|
|
* cycles, like: t1 -> t2 -> t3 -> t1. The process
|
|
|
|
* can still be killed so it is not a major problem.
|
|
|
|
*/
|
|
|
|
if (l2->l_lid == lid && l2->l_waitingfor == curlid) {
|
|
|
|
error = EDEADLK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (l2 == l)
|
2007-02-10 00:55:00 +03:00
|
|
|
continue;
|
|
|
|
if ((l2->l_prflag & LPR_DETACHED) != 0) {
|
2007-03-21 21:25:59 +03:00
|
|
|
nfound += exiting;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (lid != 0) {
|
|
|
|
if (l2->l_lid != lid)
|
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
* Mark this LWP as the first waiter, if there
|
|
|
|
* is no other.
|
|
|
|
*/
|
|
|
|
if (l2->l_waiter == 0)
|
|
|
|
l2->l_waiter = curlid;
|
|
|
|
} else if (l2->l_waiter != 0) {
|
|
|
|
/*
|
|
|
|
* It already has a waiter - so don't
|
|
|
|
* collect it. If the waiter doesn't
|
|
|
|
* grab it we'll get another chance
|
|
|
|
* later.
|
|
|
|
*/
|
|
|
|
nfound++;
|
2007-02-10 00:55:00 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nfound++;
|
|
|
|
|
|
|
|
/* No need to lock the LWP in order to see LSZOMB. */
|
|
|
|
if (l2->l_stat != LSZOMB)
|
|
|
|
continue;
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-03-21 21:25:59 +03:00
|
|
|
/*
|
|
|
|
* We're no longer waiting. Reset the "first waiter"
|
|
|
|
* pointer on the target, in case it was us.
|
|
|
|
*/
|
|
|
|
l->l_waitingfor = 0;
|
|
|
|
l2->l_waiter = 0;
|
|
|
|
p->p_nlwpwait--;
|
2003-01-18 13:06:22 +03:00
|
|
|
if (departed)
|
|
|
|
*departed = l2->l_lid;
|
2007-11-06 03:42:39 +03:00
|
|
|
sched_lwp_collect(l2);
|
2007-03-21 21:25:59 +03:00
|
|
|
|
|
|
|
/* lwp_free() releases the proc lock. */
|
|
|
|
lwp_free(l2, false, false);
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&p->p_smutex);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-03-21 21:25:59 +03:00
|
|
|
if (error != 0)
|
|
|
|
break;
|
2007-02-10 00:55:00 +03:00
|
|
|
if (nfound == 0) {
|
|
|
|
error = ESRCH;
|
|
|
|
break;
|
|
|
|
}
|
2007-03-21 21:25:59 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The kernel is careful to ensure that it can not deadlock
|
|
|
|
* when exiting - just keep waiting.
|
|
|
|
*/
|
|
|
|
if (exiting) {
|
2007-02-10 00:55:00 +03:00
|
|
|
KASSERT(p->p_nlwps > 1);
|
|
|
|
cv_wait(&p->p_lwpcv, &p->p_smutex);
|
|
|
|
continue;
|
2003-01-18 13:06:22 +03:00
|
|
|
}
|
2007-03-21 21:25:59 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If all other LWPs are waiting for exits or suspends
|
|
|
|
* and the supply of zombies and potential zombies is
|
|
|
|
* exhausted, then we are about to deadlock.
|
|
|
|
*
|
|
|
|
* If the process is exiting (and this LWP is not the one
|
|
|
|
* that is coordinating the exit) then bail out now.
|
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if ((p->p_sflag & PS_WEXIT) != 0 ||
|
2007-03-21 21:25:59 +03:00
|
|
|
p->p_nrlwps + p->p_nzlwps - p->p_ndlwps <= p->p_nlwpwait) {
|
2007-02-10 00:55:00 +03:00
|
|
|
error = EDEADLK;
|
|
|
|
break;
|
|
|
|
}
|
2007-03-21 21:25:59 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sit around and wait for something to happen. We'll be
|
|
|
|
* awoken if any of the conditions examined change: if an
|
|
|
|
* LWP exits, is collected, or is detached.
|
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if ((error = cv_wait_sig(&p->p_lwpcv, &p->p_smutex)) != 0)
|
|
|
|
break;
|
2003-01-18 13:06:22 +03:00
|
|
|
}
|
|
|
|
|
2007-03-21 21:25:59 +03:00
|
|
|
/*
|
|
|
|
* We didn't find any LWPs to collect, we may have received a
|
|
|
|
* signal, or some other condition has caused us to bail out.
|
|
|
|
*
|
|
|
|
* If waiting on a specific LWP, clear the waiters marker: some
|
|
|
|
* other LWP may want it. Then, kick all the remaining waiters
|
|
|
|
* so that they can re-check for zombies and for deadlock.
|
|
|
|
*/
|
|
|
|
if (lid != 0) {
|
|
|
|
LIST_FOREACH(l2, &p->p_lwps, l_sibling) {
|
|
|
|
if (l2->l_lid == lid) {
|
|
|
|
if (l2->l_waiter == curlid)
|
|
|
|
l2->l_waiter = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
p->p_nlwpwait--;
|
2007-03-21 21:25:59 +03:00
|
|
|
l->l_waitingfor = 0;
|
|
|
|
cv_broadcast(&p->p_lwpcv);
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
return error;
|
2003-01-18 13:06:22 +03:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Create a new LWP within process 'p2', using LWP 'l1' as a template.
|
|
|
|
* The new LWP is created in state LSIDL and must be set running,
|
|
|
|
* suspended, or stopped by the caller.
|
|
|
|
*/
|
2003-01-18 13:06:22 +03:00
|
|
|
int
|
2007-11-06 03:42:39 +03:00
|
|
|
lwp_create(lwp_t *l1, proc_t *p2, vaddr_t uaddr, bool inmem, int flags,
|
|
|
|
void *stack, size_t stacksize, void (*func)(void *), void *arg,
|
|
|
|
lwp_t **rnewlwpp, int sclass)
|
2003-01-18 13:06:22 +03:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
struct lwp *l2, *isfree;
|
|
|
|
turnstile_t *ts;
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* First off, reap any detached LWP waiting to be collected.
|
|
|
|
* We can re-use its LWP structure and turnstile.
|
|
|
|
*/
|
|
|
|
isfree = NULL;
|
|
|
|
if (p2->p_zomblwp != NULL) {
|
|
|
|
mutex_enter(&p2->p_smutex);
|
|
|
|
if ((isfree = p2->p_zomblwp) != NULL) {
|
|
|
|
p2->p_zomblwp = NULL;
|
2007-03-21 21:25:59 +03:00
|
|
|
lwp_free(isfree, true, false);/* releases proc mutex */
|
2007-02-10 00:55:00 +03:00
|
|
|
} else
|
|
|
|
mutex_exit(&p2->p_smutex);
|
|
|
|
}
|
|
|
|
if (isfree == NULL) {
|
2007-12-26 19:01:34 +03:00
|
|
|
l2 = pool_cache_get(lwp_cache, PR_WAITOK);
|
2007-02-10 00:55:00 +03:00
|
|
|
memset(l2, 0, sizeof(*l2));
|
2007-11-07 03:23:13 +03:00
|
|
|
l2->l_ts = pool_cache_get(turnstile_cache, PR_WAITOK);
|
2007-02-26 12:20:52 +03:00
|
|
|
SLIST_INIT(&l2->l_pi_lenders);
|
2007-02-10 00:55:00 +03:00
|
|
|
} else {
|
|
|
|
l2 = isfree;
|
|
|
|
ts = l2->l_ts;
|
2007-11-06 03:42:39 +03:00
|
|
|
KASSERT(l2->l_inheritedprio == -1);
|
2007-02-26 12:20:52 +03:00
|
|
|
KASSERT(SLIST_EMPTY(&l2->l_pi_lenders));
|
2007-02-10 00:55:00 +03:00
|
|
|
memset(l2, 0, sizeof(*l2));
|
|
|
|
l2->l_ts = ts;
|
|
|
|
}
|
2003-01-18 13:06:22 +03:00
|
|
|
|
|
|
|
l2->l_stat = LSIDL;
|
|
|
|
l2->l_proc = p2;
|
2007-02-10 00:55:00 +03:00
|
|
|
l2->l_refcnt = 1;
|
2007-11-06 03:42:39 +03:00
|
|
|
l2->l_class = sclass;
|
|
|
|
l2->l_kpriority = l1->l_kpriority;
|
2007-12-03 20:14:59 +03:00
|
|
|
l2->l_kpribase = PRI_KERNEL;
|
2007-02-10 00:55:00 +03:00
|
|
|
l2->l_priority = l1->l_priority;
|
2007-11-06 03:42:39 +03:00
|
|
|
l2->l_inheritedprio = -1;
|
2007-05-17 18:51:11 +04:00
|
|
|
l2->l_mutex = l1->l_cpu->ci_schedstate.spc_mutex;
|
2003-01-18 13:06:22 +03:00
|
|
|
l2->l_cpu = l1->l_cpu;
|
2007-02-18 01:31:36 +03:00
|
|
|
l2->l_flag = inmem ? LW_INMEM : 0;
|
2008-01-02 14:48:20 +03:00
|
|
|
l2->l_pflag = LP_MPSAFE;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2007-02-18 01:31:36 +03:00
|
|
|
if (p2->p_flag & PK_SYSTEM) {
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Mark it as a system process and not a candidate for
|
|
|
|
* swapping.
|
|
|
|
*/
|
2007-02-18 01:31:36 +03:00
|
|
|
l2->l_flag |= LW_SYSTEM;
|
2007-10-09 23:00:13 +04:00
|
|
|
} else {
|
|
|
|
/* Look for a CPU to start */
|
|
|
|
l2->l_cpu = sched_takecpu(l2);
|
|
|
|
l2->l_mutex = l2->l_cpu->ci_schedstate.spc_mutex;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-10-09 23:00:13 +04:00
|
|
|
lwp_initspecific(l2);
|
2007-11-06 03:42:39 +03:00
|
|
|
sched_lwp_fork(l1, l2);
|
2006-07-20 01:11:37 +04:00
|
|
|
lwp_update_creds(l2);
|
2007-09-07 03:58:56 +04:00
|
|
|
callout_init(&l2->l_timeout_ch, CALLOUT_MPSAFE);
|
|
|
|
callout_setfunc(&l2->l_timeout_ch, sleepq_timeout, l2);
|
2007-07-10 00:51:58 +04:00
|
|
|
mutex_init(&l2->l_swaplock, MUTEX_DEFAULT, IPL_NONE);
|
2007-02-10 00:55:00 +03:00
|
|
|
cv_init(&l2->l_sigcv, "sigwait");
|
|
|
|
l2->l_syncobj = &sched_syncobj;
|
2003-01-18 13:06:22 +03:00
|
|
|
|
|
|
|
if (rnewlwpp != NULL)
|
|
|
|
*rnewlwpp = l2;
|
|
|
|
|
2006-05-22 17:43:54 +04:00
|
|
|
l2->l_addr = UAREA_TO_USER(uaddr);
|
2003-01-18 13:06:22 +03:00
|
|
|
uvm_lwp_fork(l1, l2, stack, stacksize, func,
|
|
|
|
(arg != NULL) ? arg : l2);
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&p2->p_smutex);
|
|
|
|
|
|
|
|
if ((flags & LWP_DETACHED) != 0) {
|
|
|
|
l2->l_prflag = LPR_DETACHED;
|
|
|
|
p2->p_ndlwps++;
|
|
|
|
} else
|
|
|
|
l2->l_prflag = 0;
|
|
|
|
|
|
|
|
l2->l_sigmask = l1->l_sigmask;
|
|
|
|
CIRCLEQ_INIT(&l2->l_sigpend.sp_info);
|
|
|
|
sigemptyset(&l2->l_sigpend.sp_set);
|
|
|
|
|
2007-02-15 18:08:42 +03:00
|
|
|
p2->p_nlwpid++;
|
|
|
|
if (p2->p_nlwpid == 0)
|
|
|
|
p2->p_nlwpid++;
|
|
|
|
l2->l_lid = p2->p_nlwpid;
|
2003-01-18 13:06:22 +03:00
|
|
|
LIST_INSERT_HEAD(&p2->p_lwps, l2, l_sibling);
|
|
|
|
p2->p_nlwps++;
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_exit(&p2->p_smutex);
|
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
mutex_enter(&proclist_lock);
|
2003-01-18 13:06:22 +03:00
|
|
|
LIST_INSERT_HEAD(&alllwp, l2, l_list);
|
2007-07-10 00:51:58 +04:00
|
|
|
mutex_exit(&proclist_lock);
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-02-18 19:58:15 +03:00
|
|
|
SYSCALL_TIME_LWP_INIT(l2);
|
|
|
|
|
2003-12-20 21:22:16 +03:00
|
|
|
if (p2->p_emul->e_lwp_fork)
|
|
|
|
(*p2->p_emul->e_lwp_fork)(l1, l2);
|
|
|
|
|
2003-01-18 13:06:22 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-05-17 18:51:11 +04:00
|
|
|
* Called by MD code when a new LWP begins execution. Must be called
|
|
|
|
* with the previous LWP locked (so at splsched), or if there is no
|
|
|
|
* previous LWP, at splsched.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lwp_startup(struct lwp *prev, struct lwp *new)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (prev != NULL) {
|
2007-12-02 17:55:32 +03:00
|
|
|
/*
|
|
|
|
* Normalize the count of the spin-mutexes, it was
|
|
|
|
* increased in mi_switch(). Unmark the state of
|
|
|
|
* context switch - it is finished for previous LWP.
|
|
|
|
*/
|
|
|
|
curcpu()->ci_mtx_count++;
|
|
|
|
membar_exit();
|
|
|
|
prev->l_ctxswtch = 0;
|
2007-05-17 18:51:11 +04:00
|
|
|
}
|
|
|
|
spl0();
|
|
|
|
pmap_activate(new);
|
|
|
|
LOCKDEBUG_BARRIER(NULL, 0);
|
2007-07-10 00:51:58 +04:00
|
|
|
if ((new->l_pflag & LP_MPSAFE) == 0) {
|
|
|
|
KERNEL_LOCK(1, new);
|
|
|
|
}
|
2007-05-17 18:51:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-07-10 00:51:58 +04:00
|
|
|
* Exit an LWP.
|
2003-01-18 13:06:22 +03:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
lwp_exit(struct lwp *l)
|
|
|
|
{
|
|
|
|
struct proc *p = l->l_proc;
|
2007-02-10 00:55:00 +03:00
|
|
|
struct lwp *l2;
|
2007-07-10 00:51:58 +04:00
|
|
|
bool current;
|
|
|
|
|
|
|
|
current = (l == curlwp);
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
KASSERT(current || l->l_stat == LSIDL);
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Verify that we hold no locks other than the kernel lock.
|
|
|
|
*/
|
|
|
|
#ifdef MULTIPROCESSOR
|
|
|
|
LOCKDEBUG_BARRIER(&kernel_lock, 0);
|
|
|
|
#else
|
|
|
|
LOCKDEBUG_BARRIER(NULL, 0);
|
|
|
|
#endif
|
2003-12-20 21:22:16 +03:00
|
|
|
|
2003-01-18 13:06:22 +03:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* If we are the last live LWP in a process, we need to exit the
|
|
|
|
* entire process. We do so with an exit status of zero, because
|
|
|
|
* it's a "controlled" exit, and because that's what Solaris does.
|
|
|
|
*
|
|
|
|
* We are not quite a zombie yet, but for accounting purposes we
|
|
|
|
* must increment the count of zombies here.
|
2006-10-11 08:51:06 +04:00
|
|
|
*
|
|
|
|
* Note: the last LWP's specificdata will be deleted here.
|
2003-01-18 13:06:22 +03:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&p->p_smutex);
|
|
|
|
if (p->p_nlwps - p->p_nzlwps == 1) {
|
2007-07-10 00:51:58 +04:00
|
|
|
KASSERT(current == true);
|
2008-01-02 14:48:20 +03:00
|
|
|
/* XXXSMP kernel_lock not held */
|
2003-01-18 13:06:22 +03:00
|
|
|
exit1(l, 0);
|
2004-01-04 14:33:29 +03:00
|
|
|
/* NOTREACHED */
|
2003-01-18 13:06:22 +03:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
p->p_nzlwps++;
|
|
|
|
mutex_exit(&p->p_smutex);
|
|
|
|
|
|
|
|
if (p->p_emul->e_lwp_exit)
|
|
|
|
(*p->p_emul->e_lwp_exit)(l);
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2006-10-11 08:51:06 +04:00
|
|
|
/* Delete the specificdata while it's still safe to sleep. */
|
|
|
|
specificdata_fini(lwp_specificdata_domain, &l->l_specdataref);
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Release our cached credentials.
|
|
|
|
*/
|
2006-07-20 01:11:37 +04:00
|
|
|
kauth_cred_free(l->l_cred);
|
2007-09-07 03:58:56 +04:00
|
|
|
callout_destroy(&l->l_timeout_ch);
|
2007-07-10 00:51:58 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* While we can still block, mark the LWP as unswappable to
|
|
|
|
* prevent conflicts with the with the swapper.
|
|
|
|
*/
|
|
|
|
if (current)
|
|
|
|
uvm_lwp_hold(l);
|
2006-07-20 01:11:37 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Remove the LWP from the global list.
|
|
|
|
*/
|
2007-07-10 00:51:58 +04:00
|
|
|
mutex_enter(&proclist_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&proclist_mutex);
|
|
|
|
LIST_REMOVE(l, l_list);
|
|
|
|
mutex_exit(&proclist_mutex);
|
2007-07-10 00:51:58 +04:00
|
|
|
mutex_exit(&proclist_lock);
|
2005-10-01 10:12:44 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Get rid of all references to the LWP that others (e.g. procfs)
|
|
|
|
* may have, and mark the LWP as a zombie. If the LWP is detached,
|
|
|
|
* mark it waiting for collection in the proc structure. Note that
|
|
|
|
* before we can do that, we need to free any other dead, deatched
|
|
|
|
* LWP waiting to meet its maker.
|
|
|
|
*
|
|
|
|
* XXXSMP disable preemption.
|
|
|
|
*/
|
|
|
|
mutex_enter(&p->p_smutex);
|
|
|
|
lwp_drainrefs(l);
|
|
|
|
|
|
|
|
if ((l->l_prflag & LPR_DETACHED) != 0) {
|
|
|
|
while ((l2 = p->p_zomblwp) != NULL) {
|
|
|
|
p->p_zomblwp = NULL;
|
2007-03-21 21:25:59 +03:00
|
|
|
lwp_free(l2, false, false);/* releases proc mutex */
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&p->p_smutex);
|
2007-10-08 22:11:11 +04:00
|
|
|
l->l_refcnt++;
|
|
|
|
lwp_drainrefs(l);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
p->p_zomblwp = l;
|
|
|
|
}
|
2005-10-01 10:12:44 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* If we find a pending signal for the process and we have been
|
|
|
|
* asked to check for signals, then we loose: arrange to have
|
|
|
|
* all other LWPs in the process check for signals.
|
|
|
|
*/
|
2007-02-18 01:31:36 +03:00
|
|
|
if ((l->l_flag & LW_PENDSIG) != 0 &&
|
2007-02-10 00:55:00 +03:00
|
|
|
firstsig(&p->p_sigpend.sp_set) != 0) {
|
|
|
|
LIST_FOREACH(l2, &p->p_lwps, l_sibling) {
|
|
|
|
lwp_lock(l2);
|
2007-02-18 01:31:36 +03:00
|
|
|
l2->l_flag |= LW_PENDSIG;
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_unlock(l2);
|
|
|
|
}
|
2005-10-01 10:12:44 +04:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_lock(l);
|
|
|
|
l->l_stat = LSZOMB;
|
|
|
|
lwp_unlock(l);
|
2003-01-18 13:06:22 +03:00
|
|
|
p->p_nrlwps--;
|
2007-02-10 00:55:00 +03:00
|
|
|
cv_broadcast(&p->p_lwpcv);
|
2007-11-13 02:11:58 +03:00
|
|
|
if (l->l_lwpctl != NULL)
|
|
|
|
l->l_lwpctl->lc_curcpu = LWPCTL_CPU_EXITED;
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_exit(&p->p_smutex);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can no longer block. At this point, lwp_free() may already
|
|
|
|
* be gunning for us. On a multi-CPU system, we may be off p_lwps.
|
|
|
|
*
|
|
|
|
* Free MD LWP resources.
|
|
|
|
*/
|
|
|
|
#ifndef __NO_CPU_LWP_FREE
|
|
|
|
cpu_lwp_free(l, 0);
|
|
|
|
#endif
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
if (current) {
|
|
|
|
pmap_deactivate(l);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release the kernel lock, and switch away into
|
|
|
|
* oblivion.
|
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
#ifdef notyet
|
2007-07-10 00:51:58 +04:00
|
|
|
/* XXXSMP hold in lwp_userret() */
|
|
|
|
KERNEL_UNLOCK_LAST(l);
|
2007-02-10 00:55:00 +03:00
|
|
|
#else
|
2007-07-10 00:51:58 +04:00
|
|
|
KERNEL_UNLOCK_ALL(l, NULL);
|
2007-02-10 00:55:00 +03:00
|
|
|
#endif
|
2007-07-10 00:51:58 +04:00
|
|
|
lwp_exit_switchaway(l);
|
|
|
|
}
|
2003-01-18 13:06:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-05-17 18:51:11 +04:00
|
|
|
lwp_exit_switchaway(struct lwp *l)
|
2003-01-18 13:06:22 +03:00
|
|
|
{
|
2007-05-17 18:51:11 +04:00
|
|
|
struct cpu_info *ci;
|
|
|
|
struct lwp *idlelwp;
|
|
|
|
|
|
|
|
/* Unlocked, but is for statistics only. */
|
|
|
|
uvmexp.swtch++;
|
|
|
|
|
|
|
|
(void)splsched();
|
|
|
|
l->l_flag &= ~LW_RUNNING;
|
|
|
|
ci = curcpu();
|
|
|
|
idlelwp = ci->ci_data.cpu_idlelwp;
|
|
|
|
idlelwp->l_stat = LSONPROC;
|
2007-11-06 03:42:39 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* cpu_onproc must be updated with the CPU locked, as
|
|
|
|
* aston() may try to set a AST pending on the LWP (and
|
|
|
|
* it does so with the CPU locked). Otherwise, the LWP
|
|
|
|
* may be destroyed before the AST can be set, leading
|
|
|
|
* to a user-after-free.
|
|
|
|
*/
|
|
|
|
spc_lock(ci);
|
|
|
|
ci->ci_data.cpu_onproc = idlelwp;
|
|
|
|
spc_unlock(ci);
|
|
|
|
cpu_switchto(NULL, idlelwp, false);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free a dead LWP's remaining resources.
|
|
|
|
*
|
|
|
|
* XXXLWP limits.
|
|
|
|
*/
|
|
|
|
void
|
2007-03-21 21:25:59 +03:00
|
|
|
lwp_free(struct lwp *l, bool recycle, bool last)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
ksiginfoq_t kq;
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2004-01-04 14:33:29 +03:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* If this was not the last LWP in the process, then adjust
|
|
|
|
* counters and unlock.
|
2004-01-04 14:33:29 +03:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if (!last) {
|
|
|
|
/*
|
|
|
|
* Add the LWP's run time to the process' base value.
|
|
|
|
* This needs to co-incide with coming off p_lwps.
|
|
|
|
*/
|
2007-12-22 04:14:53 +03:00
|
|
|
bintime_add(&p->p_rtime, &l->l_rtime);
|
2007-05-17 18:51:11 +04:00
|
|
|
p->p_pctcpu += l->l_pctcpu;
|
2007-02-10 00:55:00 +03:00
|
|
|
LIST_REMOVE(l, l_sibling);
|
|
|
|
p->p_nlwps--;
|
|
|
|
p->p_nzlwps--;
|
|
|
|
if ((l->l_prflag & LPR_DETACHED) != 0)
|
|
|
|
p->p_ndlwps--;
|
2004-01-04 14:33:29 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
2007-03-21 21:25:59 +03:00
|
|
|
* Have any LWPs sleeping in lwp_wait() recheck for
|
|
|
|
* deadlock.
|
2007-02-10 00:55:00 +03:00
|
|
|
*/
|
2007-03-21 21:25:59 +03:00
|
|
|
cv_broadcast(&p->p_lwpcv);
|
|
|
|
mutex_exit(&p->p_smutex);
|
2004-01-04 14:33:29 +03:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2007-03-21 21:25:59 +03:00
|
|
|
#ifdef MULTIPROCESSOR
|
|
|
|
/*
|
|
|
|
* In the unlikely event that the LWP is still on the CPU,
|
|
|
|
* then spin until it has switched away. We need to release
|
|
|
|
* all locks to avoid deadlock against interrupt handlers on
|
|
|
|
* the target CPU.
|
|
|
|
*/
|
2007-05-17 18:51:11 +04:00
|
|
|
if ((l->l_flag & LW_RUNNING) != 0 || l->l_cpu->ci_curlwp == l) {
|
2007-03-21 21:25:59 +03:00
|
|
|
int count;
|
2007-05-17 18:51:11 +04:00
|
|
|
(void)count; /* XXXgcc */
|
2007-03-21 21:25:59 +03:00
|
|
|
KERNEL_UNLOCK_ALL(curlwp, &count);
|
2007-05-17 18:51:11 +04:00
|
|
|
while ((l->l_flag & LW_RUNNING) != 0 ||
|
|
|
|
l->l_cpu->ci_curlwp == l)
|
2007-03-21 21:25:59 +03:00
|
|
|
SPINLOCK_BACKOFF_HOOK;
|
|
|
|
KERNEL_LOCK(count, curlwp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Destroy the LWP's remaining signal information.
|
|
|
|
*/
|
|
|
|
ksiginfo_queue_init(&kq);
|
|
|
|
sigclear(&l->l_sigpend, NULL, &kq);
|
|
|
|
ksiginfo_queue_drain(&kq);
|
|
|
|
cv_destroy(&l->l_sigcv);
|
2007-07-10 00:51:58 +04:00
|
|
|
mutex_destroy(&l->l_swaplock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Free the LWP's turnstile and the LWP structure itself unless the
|
2007-05-17 18:51:11 +04:00
|
|
|
* caller wants to recycle them. Also, free the scheduler specific data.
|
2007-02-10 00:55:00 +03:00
|
|
|
*
|
|
|
|
* We can't return turnstile0 to the pool (it didn't come from it),
|
|
|
|
* so if it comes up just drop it quietly and move on.
|
|
|
|
*
|
|
|
|
* We don't recycle the VM resources at this time.
|
|
|
|
*/
|
2007-11-13 02:11:58 +03:00
|
|
|
if (l->l_lwpctl != NULL)
|
|
|
|
lwp_ctl_free(l);
|
2007-05-17 18:51:11 +04:00
|
|
|
sched_lwp_exit(l);
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
if (!recycle && l->l_ts != &turnstile0)
|
2007-11-07 03:23:13 +03:00
|
|
|
pool_cache_put(turnstile_cache, l->l_ts);
|
2007-02-10 00:55:00 +03:00
|
|
|
#ifndef __NO_CPU_LWP_FREE
|
|
|
|
cpu_lwp_free2(l);
|
|
|
|
#endif
|
|
|
|
uvm_lwp_exit(l);
|
2007-02-26 12:20:52 +03:00
|
|
|
KASSERT(SLIST_EMPTY(&l->l_pi_lenders));
|
2007-11-06 03:42:39 +03:00
|
|
|
KASSERT(l->l_inheritedprio == -1);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (!recycle)
|
2007-12-26 19:01:34 +03:00
|
|
|
pool_cache_put(lwp_cache, l);
|
2003-01-18 13:06:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pick a LWP to represent the process for those operations which
|
|
|
|
* want information about a "process" that is actually associated
|
|
|
|
* with a LWP.
|
2007-02-10 00:55:00 +03:00
|
|
|
*
|
|
|
|
* If 'locking' is false, no locking or lock checks are performed.
|
|
|
|
* This is intended for use by DDB.
|
|
|
|
*
|
|
|
|
* We don't bother locking the LWP here, since code that uses this
|
|
|
|
* interface is broken by design and an exact match is not required.
|
2003-01-18 13:06:22 +03:00
|
|
|
*/
|
|
|
|
struct lwp *
|
2007-02-10 00:55:00 +03:00
|
|
|
proc_representative_lwp(struct proc *p, int *nrlwps, int locking)
|
2003-01-18 13:06:22 +03:00
|
|
|
{
|
|
|
|
struct lwp *l, *onproc, *running, *sleeping, *stopped, *suspended;
|
2004-05-13 01:10:09 +04:00
|
|
|
struct lwp *signalled;
|
2007-02-10 00:55:00 +03:00
|
|
|
int cnt;
|
|
|
|
|
|
|
|
if (locking) {
|
2007-03-21 21:25:59 +03:00
|
|
|
KASSERT(mutex_owned(&p->p_smutex));
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
2003-01-18 13:06:22 +03:00
|
|
|
|
|
|
|
/* Trivial case: only one LWP */
|
2007-02-10 00:55:00 +03:00
|
|
|
if (p->p_nlwps == 1) {
|
|
|
|
l = LIST_FIRST(&p->p_lwps);
|
|
|
|
if (nrlwps)
|
2007-07-31 13:56:31 +04:00
|
|
|
*nrlwps = (l->l_stat == LSONPROC || l->l_stat == LSRUN);
|
2007-02-10 00:55:00 +03:00
|
|
|
return l;
|
|
|
|
}
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
cnt = 0;
|
2003-01-18 13:06:22 +03:00
|
|
|
switch (p->p_stat) {
|
|
|
|
case SSTOP:
|
|
|
|
case SACTIVE:
|
|
|
|
/* Pick the most live LWP */
|
|
|
|
onproc = running = sleeping = stopped = suspended = NULL;
|
2004-05-13 01:10:09 +04:00
|
|
|
signalled = NULL;
|
2003-01-18 13:06:22 +03:00
|
|
|
LIST_FOREACH(l, &p->p_lwps, l_sibling) {
|
2007-05-17 18:51:11 +04:00
|
|
|
if ((l->l_flag & LW_IDLE) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2004-05-13 01:10:09 +04:00
|
|
|
if (l->l_lid == p->p_sigctx.ps_lwp)
|
|
|
|
signalled = l;
|
2003-01-18 13:06:22 +03:00
|
|
|
switch (l->l_stat) {
|
|
|
|
case LSONPROC:
|
|
|
|
onproc = l;
|
2007-02-10 00:55:00 +03:00
|
|
|
cnt++;
|
2003-01-18 13:06:22 +03:00
|
|
|
break;
|
|
|
|
case LSRUN:
|
|
|
|
running = l;
|
2007-02-10 00:55:00 +03:00
|
|
|
cnt++;
|
2003-01-18 13:06:22 +03:00
|
|
|
break;
|
|
|
|
case LSSLEEP:
|
|
|
|
sleeping = l;
|
|
|
|
break;
|
|
|
|
case LSSTOP:
|
|
|
|
stopped = l;
|
|
|
|
break;
|
|
|
|
case LSSUSPENDED:
|
|
|
|
suspended = l;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
if (nrlwps)
|
|
|
|
*nrlwps = cnt;
|
2004-05-13 01:10:09 +04:00
|
|
|
if (signalled)
|
2007-02-10 00:55:00 +03:00
|
|
|
l = signalled;
|
|
|
|
else if (onproc)
|
|
|
|
l = onproc;
|
|
|
|
else if (running)
|
|
|
|
l = running;
|
|
|
|
else if (sleeping)
|
|
|
|
l = sleeping;
|
|
|
|
else if (stopped)
|
|
|
|
l = stopped;
|
|
|
|
else if (suspended)
|
|
|
|
l = suspended;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
return l;
|
2003-01-18 13:06:22 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
case SIDL:
|
2007-02-10 00:55:00 +03:00
|
|
|
case SZOMB:
|
|
|
|
case SDYING:
|
|
|
|
case SDEAD:
|
|
|
|
if (locking)
|
|
|
|
mutex_exit(&p->p_smutex);
|
2003-01-18 13:06:22 +03:00
|
|
|
/* We have more than one LWP and we're in SIDL?
|
|
|
|
* How'd that happen?
|
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
panic("Too many LWPs in idle/dying process %d (%s) stat = %d",
|
|
|
|
p->p_pid, p->p_comm, p->p_stat);
|
|
|
|
break;
|
2003-01-18 13:06:22 +03:00
|
|
|
default:
|
2007-02-10 00:55:00 +03:00
|
|
|
if (locking)
|
|
|
|
mutex_exit(&p->p_smutex);
|
2003-01-18 13:06:22 +03:00
|
|
|
panic("Process %d (%s) in unknown state %d",
|
|
|
|
p->p_pid, p->p_comm, p->p_stat);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
if (locking)
|
|
|
|
mutex_exit(&p->p_smutex);
|
2003-01-18 13:06:22 +03:00
|
|
|
panic("proc_representative_lwp: couldn't find a lwp for process"
|
|
|
|
" %d (%s)", p->p_pid, p->p_comm);
|
|
|
|
/* NOTREACHED */
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-07-20 01:11:37 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Look up a live LWP within the speicifed process, and return it locked.
|
|
|
|
*
|
|
|
|
* Must be called with p->p_smutex held.
|
|
|
|
*/
|
|
|
|
struct lwp *
|
|
|
|
lwp_find(struct proc *p, int id)
|
|
|
|
{
|
|
|
|
struct lwp *l;
|
|
|
|
|
2007-03-21 21:25:59 +03:00
|
|
|
KASSERT(mutex_owned(&p->p_smutex));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
LIST_FOREACH(l, &p->p_lwps, l_sibling) {
|
|
|
|
if (l->l_lid == id)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No need to lock - all of these conditions will
|
|
|
|
* be visible with the process level mutex held.
|
|
|
|
*/
|
|
|
|
if (l != NULL && (l->l_stat == LSIDL || l->l_stat == LSZOMB))
|
|
|
|
l = NULL;
|
|
|
|
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2006-07-20 01:11:37 +04:00
|
|
|
/*
|
|
|
|
* Update an LWP's cached credentials to mirror the process' master copy.
|
|
|
|
*
|
|
|
|
* This happens early in the syscall path, on user trap, and on LWP
|
|
|
|
* creation. A long-running LWP can also voluntarily choose to update
|
|
|
|
* it's credentials by calling this routine. This may be called from
|
|
|
|
* LWP_CACHE_CREDS(), which checks l->l_cred != p->p_cred beforehand.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lwp_update_creds(struct lwp *l)
|
|
|
|
{
|
|
|
|
kauth_cred_t oc;
|
|
|
|
struct proc *p;
|
|
|
|
|
|
|
|
p = l->l_proc;
|
|
|
|
oc = l->l_cred;
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&p->p_mutex);
|
2006-07-20 01:11:37 +04:00
|
|
|
kauth_cred_hold(p->p_cred);
|
|
|
|
l->l_cred = p->p_cred;
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_exit(&p->p_mutex);
|
2008-01-02 14:48:20 +03:00
|
|
|
if (oc != NULL)
|
2006-07-20 01:11:37 +04:00
|
|
|
kauth_cred_free(oc);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify that an LWP is locked, and optionally verify that the lock matches
|
|
|
|
* one we specify.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
lwp_locked(struct lwp *l, kmutex_t *mtx)
|
|
|
|
{
|
|
|
|
kmutex_t *cur = l->l_mutex;
|
|
|
|
|
|
|
|
return mutex_owned(cur) && (mtx == cur || mtx == NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock an LWP.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lwp_lock_retry(struct lwp *l, kmutex_t *old)
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXXgcc ignoring kmutex_t * volatile on i386
|
|
|
|
*
|
|
|
|
* gcc version 4.1.2 20061021 prerelease (NetBSD nb1 20061021)
|
|
|
|
*/
|
|
|
|
#if 1
|
|
|
|
while (l->l_mutex != old) {
|
|
|
|
#else
|
|
|
|
for (;;) {
|
|
|
|
#endif
|
|
|
|
mutex_spin_exit(old);
|
|
|
|
old = l->l_mutex;
|
|
|
|
mutex_spin_enter(old);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mutex_enter() will have posted a read barrier. Re-test
|
|
|
|
* l->l_mutex. If it has changed, we need to try again.
|
|
|
|
*/
|
|
|
|
#if 1
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
} while (__predict_false(l->l_mutex != old));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lend a new mutex to an LWP. The old mutex must be held.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lwp_setlock(struct lwp *l, kmutex_t *new)
|
|
|
|
{
|
|
|
|
|
2007-03-21 21:25:59 +03:00
|
|
|
KASSERT(mutex_owned(l->l_mutex));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2007-12-02 17:55:32 +03:00
|
|
|
membar_producer();
|
2007-02-10 00:55:00 +03:00
|
|
|
l->l_mutex = new;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lend a new mutex to an LWP, and release the old mutex. The old mutex
|
|
|
|
* must be held.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lwp_unlock_to(struct lwp *l, kmutex_t *new)
|
|
|
|
{
|
|
|
|
kmutex_t *old;
|
|
|
|
|
2007-03-21 21:25:59 +03:00
|
|
|
KASSERT(mutex_owned(l->l_mutex));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
old = l->l_mutex;
|
2007-12-02 17:55:32 +03:00
|
|
|
membar_producer();
|
2007-02-10 00:55:00 +03:00
|
|
|
l->l_mutex = new;
|
|
|
|
mutex_spin_exit(old);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Acquire a new mutex, and donate it to an LWP. The LWP must already be
|
|
|
|
* locked.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lwp_relock(struct lwp *l, kmutex_t *new)
|
|
|
|
{
|
|
|
|
kmutex_t *old;
|
|
|
|
|
2007-03-21 21:25:59 +03:00
|
|
|
KASSERT(mutex_owned(l->l_mutex));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
old = l->l_mutex;
|
|
|
|
if (old != new) {
|
|
|
|
mutex_spin_enter(new);
|
|
|
|
l->l_mutex = new;
|
|
|
|
mutex_spin_exit(old);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-26 12:20:52 +03:00
|
|
|
int
|
|
|
|
lwp_trylock(struct lwp *l)
|
|
|
|
{
|
|
|
|
kmutex_t *old;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (!mutex_tryenter(old = l->l_mutex))
|
|
|
|
return 0;
|
|
|
|
if (__predict_true(l->l_mutex == old))
|
|
|
|
return 1;
|
|
|
|
mutex_spin_exit(old);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
2007-02-18 01:31:36 +03:00
|
|
|
* Handle exceptions for mi_userret(). Called if a member of LW_USERRET is
|
2007-02-10 00:55:00 +03:00
|
|
|
* set.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lwp_userret(struct lwp *l)
|
|
|
|
{
|
|
|
|
struct proc *p;
|
2007-02-15 18:13:10 +03:00
|
|
|
void (*hook)(void);
|
2007-02-10 00:55:00 +03:00
|
|
|
int sig;
|
|
|
|
|
|
|
|
p = l->l_proc;
|
|
|
|
|
2007-11-06 03:42:39 +03:00
|
|
|
#ifndef __HAVE_FAST_SOFTINTS
|
|
|
|
/* Run pending soft interrupts. */
|
|
|
|
if (l->l_cpu->ci_data.cpu_softints != 0)
|
|
|
|
softint_overlay();
|
|
|
|
#endif
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* It should be safe to do this read unlocked on a multiprocessor
|
|
|
|
* system..
|
|
|
|
*/
|
2007-02-18 01:31:36 +03:00
|
|
|
while ((l->l_flag & LW_USERRET) != 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Process pending signals first, unless the process
|
2007-03-04 23:59:00 +03:00
|
|
|
* is dumping core or exiting, where we will instead
|
|
|
|
* enter the L_WSUSPEND case below.
|
2007-02-10 00:55:00 +03:00
|
|
|
*/
|
2007-03-04 23:59:00 +03:00
|
|
|
if ((l->l_flag & (LW_PENDSIG | LW_WCORE | LW_WEXIT)) ==
|
|
|
|
LW_PENDSIG) {
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&p->p_smutex);
|
|
|
|
while ((sig = issignal(l)) != 0)
|
|
|
|
postsig(sig);
|
|
|
|
mutex_exit(&p->p_smutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Core-dump or suspend pending.
|
|
|
|
*
|
|
|
|
* In case of core dump, suspend ourselves, so that the
|
|
|
|
* kernel stack and therefore the userland registers saved
|
|
|
|
* in the trapframe are around for coredump() to write them
|
|
|
|
* out. We issue a wakeup on p->p_lwpcv so that sigexit()
|
|
|
|
* will write the core file out once all other LWPs are
|
|
|
|
* suspended.
|
|
|
|
*/
|
2007-02-18 01:31:36 +03:00
|
|
|
if ((l->l_flag & LW_WSUSPEND) != 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&p->p_smutex);
|
|
|
|
p->p_nrlwps--;
|
|
|
|
cv_broadcast(&p->p_lwpcv);
|
|
|
|
lwp_lock(l);
|
|
|
|
l->l_stat = LSSUSPENDED;
|
|
|
|
mutex_exit(&p->p_smutex);
|
2007-05-17 18:51:11 +04:00
|
|
|
mi_switch(l);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process is exiting. */
|
2007-02-18 01:31:36 +03:00
|
|
|
if ((l->l_flag & LW_WEXIT) != 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_exit(l);
|
|
|
|
KASSERT(0);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
2007-02-15 18:13:10 +03:00
|
|
|
|
|
|
|
/* Call userret hook; used by Linux emulation. */
|
2007-02-18 01:31:36 +03:00
|
|
|
if ((l->l_flag & LW_WUSERRET) != 0) {
|
2007-02-15 18:13:10 +03:00
|
|
|
lwp_lock(l);
|
2007-02-18 01:31:36 +03:00
|
|
|
l->l_flag &= ~LW_WUSERRET;
|
2007-02-15 18:13:10 +03:00
|
|
|
lwp_unlock(l);
|
|
|
|
hook = p->p_userret;
|
|
|
|
p->p_userret = NULL;
|
|
|
|
(*hook)();
|
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Force an LWP to enter the kernel, to take a trip through lwp_userret().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lwp_need_userret(struct lwp *l)
|
|
|
|
{
|
2007-03-21 21:25:59 +03:00
|
|
|
KASSERT(lwp_locked(l, NULL));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Since the tests in lwp_userret() are done unlocked, make sure
|
|
|
|
* that the condition will be seen before forcing the LWP to enter
|
|
|
|
* kernel mode.
|
|
|
|
*/
|
2007-12-02 17:55:32 +03:00
|
|
|
membar_producer();
|
2007-02-10 00:55:00 +03:00
|
|
|
cpu_signotify(l);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add one reference to an LWP. This will prevent the LWP from
|
|
|
|
* exiting, thus keep the lwp structure and PCB around to inspect.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lwp_addref(struct lwp *l)
|
|
|
|
{
|
|
|
|
|
2007-03-21 21:25:59 +03:00
|
|
|
KASSERT(mutex_owned(&l->l_proc->p_smutex));
|
2007-02-10 00:55:00 +03:00
|
|
|
KASSERT(l->l_stat != LSZOMB);
|
|
|
|
KASSERT(l->l_refcnt != 0);
|
|
|
|
|
|
|
|
l->l_refcnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove one reference to an LWP. If this is the last reference,
|
|
|
|
* then we must finalize the LWP's death.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lwp_delref(struct lwp *l)
|
|
|
|
{
|
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
|
|
|
|
mutex_enter(&p->p_smutex);
|
2007-10-08 22:11:11 +04:00
|
|
|
KASSERT(l->l_stat != LSZOMB);
|
|
|
|
KASSERT(l->l_refcnt > 0);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (--l->l_refcnt == 0)
|
2007-11-07 03:23:13 +03:00
|
|
|
cv_broadcast(&p->p_lwpcv);
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_exit(&p->p_smutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Drain all references to the current LWP.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lwp_drainrefs(struct lwp *l)
|
|
|
|
{
|
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
|
2007-03-21 21:25:59 +03:00
|
|
|
KASSERT(mutex_owned(&p->p_smutex));
|
2007-02-10 00:55:00 +03:00
|
|
|
KASSERT(l->l_refcnt != 0);
|
|
|
|
|
|
|
|
l->l_refcnt--;
|
|
|
|
while (l->l_refcnt != 0)
|
2007-11-07 03:23:13 +03:00
|
|
|
cv_wait(&p->p_lwpcv, &p->p_smutex);
|
2006-07-20 01:11:37 +04:00
|
|
|
}
|
2006-10-08 08:28:44 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* lwp_specific_key_create --
|
|
|
|
* Create a key for subsystem lwp-specific data.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
lwp_specific_key_create(specificdata_key_t *keyp, specificdata_dtor_t dtor)
|
|
|
|
{
|
|
|
|
|
2006-10-11 08:51:06 +04:00
|
|
|
return (specificdata_key_create(lwp_specificdata_domain, keyp, dtor));
|
2006-10-08 08:28:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* lwp_specific_key_delete --
|
|
|
|
* Delete a key for subsystem lwp-specific data.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lwp_specific_key_delete(specificdata_key_t key)
|
|
|
|
{
|
|
|
|
|
|
|
|
specificdata_key_delete(lwp_specificdata_domain, key);
|
|
|
|
}
|
|
|
|
|
2006-10-11 08:51:06 +04:00
|
|
|
/*
|
|
|
|
* lwp_initspecific --
|
|
|
|
* Initialize an LWP's specificdata container.
|
|
|
|
*/
|
2006-10-09 02:57:11 +04:00
|
|
|
void
|
|
|
|
lwp_initspecific(struct lwp *l)
|
|
|
|
{
|
|
|
|
int error;
|
2006-10-11 08:51:06 +04:00
|
|
|
|
2006-10-09 02:57:11 +04:00
|
|
|
error = specificdata_init(lwp_specificdata_domain, &l->l_specdataref);
|
|
|
|
KASSERT(error == 0);
|
|
|
|
}
|
|
|
|
|
2006-10-11 08:51:06 +04:00
|
|
|
/*
|
|
|
|
* lwp_finispecific --
|
|
|
|
* Finalize an LWP's specificdata container.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lwp_finispecific(struct lwp *l)
|
|
|
|
{
|
|
|
|
|
|
|
|
specificdata_fini(lwp_specificdata_domain, &l->l_specdataref);
|
|
|
|
}
|
|
|
|
|
2006-10-08 08:28:44 +04:00
|
|
|
/*
|
|
|
|
* lwp_getspecific --
|
|
|
|
* Return lwp-specific data corresponding to the specified key.
|
|
|
|
*
|
|
|
|
* Note: LWP specific data is NOT INTERLOCKED. An LWP should access
|
|
|
|
* only its OWN SPECIFIC DATA. If it is necessary to access another
|
|
|
|
* LWP's specifc data, care must be taken to ensure that doing so
|
|
|
|
* would not cause internal data structure inconsistency (i.e. caller
|
|
|
|
* can guarantee that the target LWP is not inside an lwp_getspecific()
|
|
|
|
* or lwp_setspecific() call).
|
|
|
|
*/
|
|
|
|
void *
|
2006-10-11 07:46:42 +04:00
|
|
|
lwp_getspecific(specificdata_key_t key)
|
2006-10-08 08:28:44 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (specificdata_getspecific_unlocked(lwp_specificdata_domain,
|
2006-10-11 07:46:42 +04:00
|
|
|
&curlwp->l_specdataref, key));
|
2006-10-08 08:28:44 +04:00
|
|
|
}
|
|
|
|
|
2006-10-24 14:05:45 +04:00
|
|
|
void *
|
|
|
|
_lwp_getspecific_by_lwp(struct lwp *l, specificdata_key_t key)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (specificdata_getspecific_unlocked(lwp_specificdata_domain,
|
|
|
|
&l->l_specdataref, key));
|
|
|
|
}
|
|
|
|
|
2006-10-08 08:28:44 +04:00
|
|
|
/*
|
|
|
|
* lwp_setspecific --
|
|
|
|
* Set lwp-specific data corresponding to the specified key.
|
|
|
|
*/
|
|
|
|
void
|
2006-10-11 08:51:06 +04:00
|
|
|
lwp_setspecific(specificdata_key_t key, void *data)
|
2006-10-08 08:28:44 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
specificdata_setspecific(lwp_specificdata_domain,
|
2006-10-11 07:46:42 +04:00
|
|
|
&curlwp->l_specdataref, key, data);
|
2006-10-08 08:28:44 +04:00
|
|
|
}
|
2007-11-13 02:11:58 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a new lwpctl structure for a user LWP.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
lwp_ctl_alloc(vaddr_t *uaddr)
|
|
|
|
{
|
|
|
|
lcproc_t *lp;
|
|
|
|
u_int bit, i, offset;
|
|
|
|
struct uvm_object *uao;
|
|
|
|
int error;
|
|
|
|
lcpage_t *lcp;
|
|
|
|
proc_t *p;
|
|
|
|
lwp_t *l;
|
|
|
|
|
|
|
|
l = curlwp;
|
|
|
|
p = l->l_proc;
|
|
|
|
|
2007-12-02 17:55:32 +03:00
|
|
|
if (l->l_lcpage != NULL) {
|
|
|
|
lcp = l->l_lcpage;
|
|
|
|
*uaddr = lcp->lcp_uaddr + (vaddr_t)l->l_lwpctl - lcp->lcp_kaddr;
|
2007-11-13 02:11:58 +03:00
|
|
|
return (EINVAL);
|
2007-12-02 17:55:32 +03:00
|
|
|
}
|
2007-11-13 02:11:58 +03:00
|
|
|
|
|
|
|
/* First time around, allocate header structure for the process. */
|
|
|
|
if ((lp = p->p_lwpctl) == NULL) {
|
|
|
|
lp = kmem_alloc(sizeof(*lp), KM_SLEEP);
|
|
|
|
mutex_init(&lp->lp_lock, MUTEX_DEFAULT, IPL_NONE);
|
|
|
|
lp->lp_uao = NULL;
|
|
|
|
TAILQ_INIT(&lp->lp_pages);
|
|
|
|
mutex_enter(&p->p_mutex);
|
|
|
|
if (p->p_lwpctl == NULL) {
|
|
|
|
p->p_lwpctl = lp;
|
|
|
|
mutex_exit(&p->p_mutex);
|
|
|
|
} else {
|
|
|
|
mutex_exit(&p->p_mutex);
|
|
|
|
mutex_destroy(&lp->lp_lock);
|
|
|
|
kmem_free(lp, sizeof(*lp));
|
|
|
|
lp = p->p_lwpctl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up an anonymous memory region to hold the shared pages.
|
|
|
|
* Map them into the process' address space. The user vmspace
|
|
|
|
* gets the first reference on the UAO.
|
|
|
|
*/
|
|
|
|
mutex_enter(&lp->lp_lock);
|
|
|
|
if (lp->lp_uao == NULL) {
|
|
|
|
lp->lp_uao = uao_create(LWPCTL_UAREA_SZ, 0);
|
|
|
|
lp->lp_cur = 0;
|
|
|
|
lp->lp_max = LWPCTL_UAREA_SZ;
|
|
|
|
lp->lp_uva = p->p_emul->e_vm_default_addr(p,
|
|
|
|
(vaddr_t)p->p_vmspace->vm_daddr, LWPCTL_UAREA_SZ);
|
|
|
|
error = uvm_map(&p->p_vmspace->vm_map, &lp->lp_uva,
|
|
|
|
LWPCTL_UAREA_SZ, lp->lp_uao, 0, 0, UVM_MAPFLAG(UVM_PROT_RW,
|
|
|
|
UVM_PROT_RW, UVM_INH_NONE, UVM_ADV_NORMAL, 0));
|
|
|
|
if (error != 0) {
|
|
|
|
uao_detach(lp->lp_uao);
|
|
|
|
lp->lp_uao = NULL;
|
|
|
|
mutex_exit(&lp->lp_lock);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get a free block and allocate for this LWP. */
|
|
|
|
TAILQ_FOREACH(lcp, &lp->lp_pages, lcp_chain) {
|
|
|
|
if (lcp->lcp_nfree != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (lcp == NULL) {
|
|
|
|
/* Nothing available - try to set up a free page. */
|
|
|
|
if (lp->lp_cur == lp->lp_max) {
|
|
|
|
mutex_exit(&lp->lp_lock);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
lcp = kmem_alloc(LWPCTL_LCPAGE_SZ, KM_SLEEP);
|
2007-11-13 11:38:06 +03:00
|
|
|
if (lcp == NULL) {
|
|
|
|
mutex_exit(&lp->lp_lock);
|
2007-11-13 02:11:58 +03:00
|
|
|
return ENOMEM;
|
2007-11-13 11:38:06 +03:00
|
|
|
}
|
2007-11-13 02:11:58 +03:00
|
|
|
/*
|
|
|
|
* Wire the next page down in kernel space. Since this
|
|
|
|
* is a new mapping, we must add a reference.
|
|
|
|
*/
|
|
|
|
uao = lp->lp_uao;
|
|
|
|
(*uao->pgops->pgo_reference)(uao);
|
|
|
|
error = uvm_map(kernel_map, &lcp->lcp_kaddr, PAGE_SIZE,
|
|
|
|
uao, lp->lp_cur, PAGE_SIZE,
|
|
|
|
UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_RW,
|
|
|
|
UVM_INH_NONE, UVM_ADV_RANDOM, 0));
|
|
|
|
if (error != 0) {
|
|
|
|
mutex_exit(&lp->lp_lock);
|
|
|
|
kmem_free(lcp, LWPCTL_LCPAGE_SZ);
|
|
|
|
(*uao->pgops->pgo_detach)(uao);
|
|
|
|
return error;
|
|
|
|
}
|
2008-01-07 14:41:29 +03:00
|
|
|
error = uvm_map_pageable(kernel_map, lcp->lcp_kaddr,
|
|
|
|
lcp->lcp_kaddr + PAGE_SIZE, FALSE, 0);
|
|
|
|
if (error != 0) {
|
|
|
|
mutex_exit(&lp->lp_lock);
|
|
|
|
uvm_unmap(kernel_map, lcp->lcp_kaddr,
|
|
|
|
lcp->lcp_kaddr + PAGE_SIZE);
|
|
|
|
kmem_free(lcp, LWPCTL_LCPAGE_SZ);
|
|
|
|
return error;
|
|
|
|
}
|
2007-11-13 02:11:58 +03:00
|
|
|
/* Prepare the page descriptor and link into the list. */
|
|
|
|
lcp->lcp_uaddr = lp->lp_uva + lp->lp_cur;
|
|
|
|
lp->lp_cur += PAGE_SIZE;
|
|
|
|
lcp->lcp_nfree = LWPCTL_PER_PAGE;
|
|
|
|
lcp->lcp_rotor = 0;
|
|
|
|
memset(lcp->lcp_bitmap, 0xff, LWPCTL_BITMAP_SZ);
|
|
|
|
TAILQ_INSERT_HEAD(&lp->lp_pages, lcp, lcp_chain);
|
|
|
|
}
|
|
|
|
for (i = lcp->lcp_rotor; lcp->lcp_bitmap[i] == 0;) {
|
|
|
|
if (++i >= LWPCTL_BITMAP_ENTRIES)
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
bit = ffs(lcp->lcp_bitmap[i]) - 1;
|
|
|
|
lcp->lcp_bitmap[i] ^= (1 << bit);
|
|
|
|
lcp->lcp_rotor = i;
|
|
|
|
lcp->lcp_nfree--;
|
|
|
|
l->l_lcpage = lcp;
|
|
|
|
offset = (i << 5) + bit;
|
|
|
|
l->l_lwpctl = (lwpctl_t *)lcp->lcp_kaddr + offset;
|
|
|
|
*uaddr = lcp->lcp_uaddr + offset * sizeof(lwpctl_t);
|
|
|
|
mutex_exit(&lp->lp_lock);
|
|
|
|
|
|
|
|
l->l_lwpctl->lc_curcpu = (short)curcpu()->ci_data.cpu_index;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free an lwpctl structure back to the per-process list.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lwp_ctl_free(lwp_t *l)
|
|
|
|
{
|
|
|
|
lcproc_t *lp;
|
|
|
|
lcpage_t *lcp;
|
|
|
|
u_int map, offset;
|
|
|
|
|
|
|
|
lp = l->l_proc->p_lwpctl;
|
|
|
|
KASSERT(lp != NULL);
|
|
|
|
|
|
|
|
lcp = l->l_lcpage;
|
|
|
|
offset = (u_int)((lwpctl_t *)l->l_lwpctl - (lwpctl_t *)lcp->lcp_kaddr);
|
|
|
|
KASSERT(offset < LWPCTL_PER_PAGE);
|
|
|
|
|
|
|
|
mutex_enter(&lp->lp_lock);
|
|
|
|
lcp->lcp_nfree++;
|
|
|
|
map = offset >> 5;
|
|
|
|
lcp->lcp_bitmap[map] |= (1 << (offset & 31));
|
|
|
|
if (lcp->lcp_bitmap[lcp->lcp_rotor] == 0)
|
|
|
|
lcp->lcp_rotor = map;
|
|
|
|
if (TAILQ_FIRST(&lp->lp_pages)->lcp_nfree == 0) {
|
|
|
|
TAILQ_REMOVE(&lp->lp_pages, lcp, lcp_chain);
|
|
|
|
TAILQ_INSERT_HEAD(&lp->lp_pages, lcp, lcp_chain);
|
|
|
|
}
|
|
|
|
mutex_exit(&lp->lp_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process is exiting; tear down lwpctl state. This can only be safely
|
|
|
|
* called by the last LWP in the process.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lwp_ctl_exit(void)
|
|
|
|
{
|
|
|
|
lcpage_t *lcp, *next;
|
|
|
|
lcproc_t *lp;
|
|
|
|
proc_t *p;
|
|
|
|
lwp_t *l;
|
|
|
|
|
|
|
|
l = curlwp;
|
|
|
|
l->l_lwpctl = NULL;
|
|
|
|
p = l->l_proc;
|
|
|
|
lp = p->p_lwpctl;
|
|
|
|
|
|
|
|
KASSERT(lp != NULL);
|
|
|
|
KASSERT(p->p_nlwps == 1);
|
|
|
|
|
|
|
|
for (lcp = TAILQ_FIRST(&lp->lp_pages); lcp != NULL; lcp = next) {
|
|
|
|
next = TAILQ_NEXT(lcp, lcp_chain);
|
|
|
|
uvm_unmap(kernel_map, lcp->lcp_kaddr,
|
|
|
|
lcp->lcp_kaddr + PAGE_SIZE);
|
|
|
|
kmem_free(lcp, LWPCTL_LCPAGE_SZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lp->lp_uao != NULL) {
|
|
|
|
uvm_unmap(&p->p_vmspace->vm_map, lp->lp_uva,
|
|
|
|
lp->lp_uva + LWPCTL_UAREA_SZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_destroy(&lp->lp_lock);
|
|
|
|
kmem_free(lp, sizeof(*lp));
|
|
|
|
p->p_lwpctl = NULL;
|
|
|
|
}
|
2007-12-13 05:45:09 +03:00
|
|
|
|
|
|
|
#if defined(DDB)
|
|
|
|
void
|
|
|
|
lwp_whatis(uintptr_t addr, void (*pr)(const char *, ...))
|
|
|
|
{
|
|
|
|
lwp_t *l;
|
|
|
|
|
|
|
|
LIST_FOREACH(l, &alllwp, l_list) {
|
|
|
|
uintptr_t stack = (uintptr_t)KSTACK_LOWEST_ADDR(l);
|
|
|
|
|
|
|
|
if (addr < stack || stack + KSTACK_SIZE <= addr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
(*pr)("%p is %p+%zu, LWP %p's stack\n",
|
|
|
|
(void *)addr, (void *)stack,
|
|
|
|
(size_t)(addr - stack), l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* defined(DDB) */
|