Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/sys/lwp.h,v rcsdiff: /ftp/cvs/cvsroot/src/sys/sys/lwp.h,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.89.2.7 retrieving revision 1.90 diff -u -p -r1.89.2.7 -r1.90 --- src/sys/sys/lwp.h 2010/10/09 03:32:45 1.89.2.7 +++ src/sys/sys/lwp.h 2008/04/28 15:36:01 1.90 @@ -1,8 +1,7 @@ -/* $NetBSD: lwp.h,v 1.89.2.7 2010/10/09 03:32:45 yamt Exp $ */ +/* $NetBSD: lwp.h,v 1.90 2008/04/28 15:36:01 ad Exp $ */ /*- - * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2010 - * The NetBSD Foundation, Inc. + * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -16,6 +15,13 @@ * 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 @@ -33,7 +39,6 @@ #ifndef _SYS_LWP_H_ #define _SYS_LWP_H_ -#include #include #include #include @@ -54,12 +59,13 @@ /* * Lightweight process. Field markings and the corresponding locks: * - * a: proclist_lock + * a: proclist_mutex * c: condition variable interlock, passed to cv_wait() * l: *l_mutex * p: l_proc->p_lock * s: spc_mutex, which may or may not be referenced by l_mutex - * S: l_selcluster->sc_lock + * t: l_proc->p_stmutex + * S: l_selcpu->sc_lock * (: unlocked, stable * !: unlocked, may only be reliably accessed by the LWP itself * ?: undecided @@ -67,32 +73,23 @@ * Fields are clustered together by usage (to increase the likelyhood * of cache hits) and by size (to reduce dead space in the structure). */ -struct lockdebug; -struct sadata_vp; -struct sysent; - struct lwp { /* Scheduling and overall state */ TAILQ_ENTRY(lwp) l_runq; /* s: run queue */ - union { - void * info; /* s: scheduler-specific structure */ - u_int timeslice; /* l: time-quantum for SCHED_M2 */ - } l_sched; + void *l_sched_info; /* s: Scheduler-specific structure */ struct cpu_info *volatile l_cpu;/* s: CPU we're on if LSONPROC */ kmutex_t * volatile l_mutex; /* l: ptr to mutex on sched state */ int l_ctxswtch; /* l: performing a context switch */ - struct user *l_addr; /* l: PCB address; use lwp_getpcb() */ + struct user *l_addr; /* l: KVA of u-area (PROC ONLY) */ struct mdlwp l_md; /* l: machine-dependent fields. */ int l_flag; /* l: misc flag values */ int l_stat; /* l: overall LWP status */ struct bintime l_rtime; /* l: real time */ struct bintime l_stime; /* l: start time (while ONPROC) */ u_int l_swtime; /* l: time swapped in or out */ - u_int _reserved1; + u_int l_holdcnt; /* l: if non-zero, don't swap */ u_int l_rticks; /* l: Saved start time of run */ u_int l_rticksum; /* l: Sum of ticks spent running */ - u_int l_slpticks; /* l: Saved start time of sleep */ - u_int l_slpticksum; /* l: Sum of ticks spent sleeping */ int l_biglocks; /* l: biglock count before sleep */ int l_class; /* l: scheduling class */ int l_kpriority; /* !: has kernel priority boost */ @@ -102,15 +99,15 @@ struct lwp { SLIST_HEAD(, turnstile) l_pi_lenders; /* l: ts lending us priority */ uint64_t l_ncsw; /* l: total context switches */ uint64_t l_nivcsw; /* l: involuntary context switches */ - u_int l_cpticks; /* (: Ticks of CPU time */ - fixpt_t l_pctcpu; /* p: %cpu during l_swtime */ + int l_cpticks; /* t: Ticks of CPU time */ + fixpt_t l_pctcpu; /* t: %cpu during l_swtime */ fixpt_t l_estcpu; /* l: cpu time for SCHED_4BSD */ psetid_t l_psid; /* l: assigned processor-set ID */ struct cpu_info *l_target_cpu; /* l: target CPU to migrate */ + kmutex_t l_swaplock; /* l: lock to prevent swapping */ struct lwpctl *l_lwpctl; /* p: lwpctl block kernel address */ struct lcpage *l_lcpage; /* p: lwpctl containing page */ - kcpuset_t *l_affinity; /* l: CPU set for affinity */ - struct sadata_vp *l_savp; /* p: SA "virtual processor" */ + cpuset_t l_affinity; /* l: CPU set for affinity */ /* Synchronisation */ struct turnstile *l_ts; /* l: current turnstile */ @@ -122,7 +119,6 @@ struct lwp { int l_sleeperr; /* !: error before unblock */ u_int l_slptime; /* l: time since last blocked */ callout_t l_timeout_ch; /* !: callout for tsleep */ - u_int l_emap_gen; /* !: emap generation number */ /* Process level and global state, misc. */ LIST_ENTRY(lwp) l_list; /* a: entry on list of all LWPs */ @@ -134,16 +130,10 @@ struct lwp { int l_prflag; /* p: process level flags */ u_int l_refcnt; /* p: reference count on this LWP */ lwpid_t l_lid; /* (: LWP identifier; local to proc */ - char *l_name; /* (: name, optional */ - - /* State of select() or poll() */ - int l_selflag; /* S: polling state flags */ + int l_selflag; /* S: select() flags */ SLIST_HEAD(,selinfo) l_selwait; /* S: descriptors waited on */ - int l_selret; /* S: return value of select/poll */ - uintptr_t l_selrec; /* (: argument for selrecord() */ - struct selcluster *l_selcluster;/* (: associated cluster data */ - void * l_selbits; /* (: select() bit-field */ - size_t l_selni; /* (: size of a single bit-field */ + struct selcpu *l_selcpu; /* !: associated per-CPU select data */ + char *l_name; /* (: name, optional */ /* Signals */ int l_sigrestore; /* p: need to restore old sig mask */ @@ -160,7 +150,10 @@ struct lwp { /* Private data */ specificdata_reference l_specdataref; /* !: subsystem lwp-specific data */ - struct timespec l_ktrcsw; /* !: for ktrace CSW trace XXX */ + union { + struct timeval tv; + struct timespec ts; + } l_ktrcsw; /* !: for ktrace CSW trace XXX */ void *l_private; /* !: svr4-style lwp-private data */ struct lwp *l_switchto; /* !: mi_switch: switch to this LWP */ struct kauth_cred *l_cred; /* !: cached credentials */ @@ -175,30 +168,16 @@ struct lwp { u_int l_dopreempt; /* s: kernel preemption pending */ int l_pflag; /* !: LWP private flags */ int l_dupfd; /* !: side return from cloning devs XXX */ - const struct sysent * volatile l_sysent;/* !: currently active syscall */ struct rusage l_ru; /* !: accounting information */ uint64_t l_pfailtime; /* !: for kernel preemption */ uintptr_t l_pfailaddr; /* !: for kernel preemption */ uintptr_t l_pfaillock; /* !: for kernel preemption */ - _TAILQ_HEAD(,struct lockdebug,volatile) l_ld_locks;/* !: locks held by LWP */ - int l_tcgen; /* !: for timecounter removal */ - int l_unused2; /* !: for future use */ /* These are only used by 'options SYSCALL_TIMES' */ uint32_t l_syscall_time; /* !: time epoch for current syscall */ uint64_t *l_syscall_counter; /* !: counter for current process */ - - struct kdtrace_thread *l_dtrace; /* ?: DTrace-specific data. */ }; -/* - * USER_TO_UAREA/UAREA_TO_USER: macros to convert between - * the lowest address of the uarea (UAREA) and lwp::l_addr (USER). - * - * the default is just a cast. MD code can modify it by defining - * either these macros or UAREA_USER_OFFSET in . - */ - #if !defined(USER_TO_UAREA) #if !defined(UAREA_USER_OFFSET) #define UAREA_USER_OFFSET 0 @@ -207,54 +186,43 @@ struct lwp { #define UAREA_TO_USER(uarea) ((struct user *)((uarea) + UAREA_USER_OFFSET)) #endif /* !defined(UAREA_TO_USER) */ -static __inline void * -lwp_getpcb(struct lwp *l) -{ - - return &l->l_addr->u_pcb; -} - LIST_HEAD(lwplist, lwp); /* a list of LWPs */ #ifdef _KERNEL +extern kmutex_t alllwp_mutex; /* Mutex on alllwp */ extern struct lwplist alllwp; /* List of all LWPs. */ + +extern struct pool lwp_uc_pool; /* memory pool for LWP startup args */ + extern lwp_t lwp0; /* LWP for proc0 */ #endif /* These flags are kept in l_flag. */ #define LW_IDLE 0x00000001 /* Idle lwp. */ +#define LW_INMEM 0x00000004 /* Loaded into memory. */ #define LW_SINTR 0x00000080 /* Sleep is interruptible. */ -#define LW_SA_SWITCHING 0x00000100 /* SA LWP in context switch */ #define LW_SYSTEM 0x00000200 /* Kernel thread */ -#define LW_SA 0x00000400 /* Scheduler activations LWP */ +#define LW_TIMEINTR 0x00010000 /* Time this soft interrupt */ #define LW_WSUSPEND 0x00020000 /* Suspend before return to user */ -#define LW_BATCH 0x00040000 /* LWP tends to hog CPU */ #define LW_WCORE 0x00080000 /* Stop for core dump on return to user */ #define LW_WEXIT 0x00100000 /* Exit before return to user */ #define LW_AFFINITY 0x00200000 /* Affinity is assigned to the thread */ -#define LW_SA_UPCALL 0x00400000 /* SA upcall is pending */ -#define LW_SA_BLOCKING 0x00800000 /* Blocking in tsleep() */ #define LW_PENDSIG 0x01000000 /* Pending signal for us */ #define LW_CANCELLED 0x02000000 /* tsleep should not sleep */ +#define LW_WUSERRET 0x04000000 /* Call proc::p_userret on return to user */ #define LW_WREBOOT 0x08000000 /* System is rebooting, please suspend */ #define LW_UNPARKED 0x10000000 /* Unpark op pending */ -#define LW_SA_YIELD 0x40000000 /* LWP on VP is yielding */ -#define LW_SA_IDLE 0x80000000 /* VP is idle */ -#define LW_RUMP_CLEAR LW_SA_IDLE /* clear curlwp in rump scheduler */ +#define LW_RUNNING 0x20000000 /* Active on a CPU (except if LSZOMB) */ /* The second set of flags is kept in l_pflag. */ #define LP_KTRACTIVE 0x00000001 /* Executing ktrace operation */ #define LP_KTRCSW 0x00000002 /* ktrace context switch marker */ #define LP_KTRCSWUSER 0x00000004 /* ktrace context switch marker */ -#define LP_PIDLID 0x00000008 /* free LID from PID space on exit */ +#define LP_UFSCOW 0x00000008 /* UFS: doing copy on write */ #define LP_OWEUPC 0x00000010 /* Owe user profiling tick */ #define LP_MPSAFE 0x00000020 /* Starts life without kernel_lock */ #define LP_INTR 0x00000040 /* Soft interrupt handler */ #define LP_SYSCTLWRITE 0x00000080 /* sysctl write lock held */ -#define LP_SA_PAGEFAULT 0x00000200 /* SA LWP in pagefault handler */ -#define LP_SA_NOBLOCK 0x00000400 /* SA don't upcall on block */ -#define LP_TIMEINTR 0x00010000 /* Time this soft interrupt */ -#define LP_RUNNING 0x20000000 /* Active on a CPU */ #define LP_BOUND 0x80000000 /* Bound to a CPU */ /* The third set is kept in l_prflag. */ @@ -266,7 +234,7 @@ extern lwp_t lwp0; /* LWP for proc0 */ * user. */ #define LW_USERRET (LW_WEXIT|LW_PENDSIG|LW_WREBOOT|LW_WSUSPEND|LW_WCORE|\ - LW_SA_BLOCKING|LW_SA_UPCALL) + LW_WUSERRET) /* * Status values. @@ -299,28 +267,24 @@ void lwp_startup(lwp_t *, lwp_t *); int lwp_locked(lwp_t *, kmutex_t *); void lwp_setlock(lwp_t *, kmutex_t *); void lwp_unlock_to(lwp_t *, kmutex_t *); -kmutex_t *lwp_lock_retry(lwp_t *, kmutex_t *); +void lwp_lock_retry(lwp_t *, kmutex_t *); void lwp_relock(lwp_t *, kmutex_t *); int lwp_trylock(lwp_t *); void lwp_addref(lwp_t *); void lwp_delref(lwp_t *); -void lwp_delref2(lwp_t *); void lwp_drainrefs(lwp_t *); -bool lwp_alive(lwp_t *); -lwp_t *lwp_find_first(proc_t *); /* Flags for _lwp_wait1 */ #define LWPWAIT_EXITCONTROL 0x00000001 void lwpinit(void); -void lwp0_init(void); int lwp_wait1(lwp_t *, lwpid_t, lwpid_t *, int); void lwp_continue(lwp_t *); -void lwp_unstop(lwp_t *); void cpu_setfunc(lwp_t *, void (*)(void *), void *); void startlwp(void *); void upcallret(lwp_t *); -void lwp_exit(lwp_t *); -void lwp_exit_switchaway(lwp_t *) __dead; +void lwp_exit(lwp_t *) __dead; +void lwp_exit_switchaway(lwp_t *); +lwp_t *proc_representative_lwp(struct proc *, int *, int); int lwp_suspend(lwp_t *, lwp_t *); int lwp_create1(lwp_t *, const void *, size_t, u_long, lwpid_t *); void lwp_update_creds(lwp_t *); @@ -331,11 +295,8 @@ void lwp_userret(lwp_t *); void lwp_need_userret(lwp_t *); void lwp_free(lwp_t *, bool, bool); void lwp_sys_init(void); -void lwp_unsleep(lwp_t *, bool); -uint64_t lwp_pctr(void); -int lwp_setprivate(lwp_t *, void *); +u_int lwp_unsleep(lwp_t *, bool); -void lwpinit_specificdata(void); int lwp_specific_key_create(specificdata_key_t *, specificdata_dtor_t); void lwp_specific_key_delete(specificdata_key_t); void lwp_initspecific(lwp_t *); @@ -355,11 +316,12 @@ void lwp_whatis(uintptr_t, void (*)(cons /* - * Lock an LWP. XXX _MODULE + * Lock an LWP. XXXLKM */ static inline void lwp_lock(lwp_t *l) { +#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG) kmutex_t *old; mutex_spin_enter(old = l->l_mutex); @@ -370,10 +332,13 @@ lwp_lock(lwp_t *l) */ if (__predict_false(l->l_mutex != old)) lwp_lock_retry(l, old); +#else + mutex_spin_enter(l->l_mutex); +#endif } /* - * Unlock an LWP. XXX _MODULE + * Unlock an LWP. XXXLKM */ static inline void lwp_unlock(lwp_t *l) @@ -411,12 +376,11 @@ lwp_eprio(lwp_t *l) return MAX(l->l_inheritedprio, pri); } -int lwp_create(lwp_t *, struct proc *, vaddr_t, int, +int lwp_create(lwp_t *, struct proc *, vaddr_t, bool, int, void *, size_t, void (*)(void *), void *, lwp_t **, int); /* - * XXX _MODULE - * We should provide real stubs for the below that modules can use. + * We should provide real stubs for the below that LKMs can use. */ static inline void @@ -447,30 +411,20 @@ spc_dlock(struct cpu_info *ci1, struct c } } -/* - * Allow machine-dependent code to override curlwp in for - * its own convenience. Otherwise, we declare it as appropriate. - */ -#if !defined(curlwp) -#if defined(MULTIPROCESSOR) -#define curlwp curcpu()->ci_curlwp /* Current running LWP */ -#else -extern struct lwp *curlwp; /* Current running LWP */ -#endif /* MULTIPROCESSOR */ -#endif /* ! curlwp */ -#define curproc (curlwp->l_proc) - -static inline bool -CURCPU_IDLE_P(void) +static inline void +spc_dunlock(struct cpu_info *ci1, struct cpu_info *ci2) { - struct cpu_info *ci = curcpu(); - return ci->ci_data.cpu_onproc == ci->ci_data.cpu_idlelwp; + struct schedstate_percpu *spc1 = &ci1->ci_schedstate; + struct schedstate_percpu *spc2 = &ci2->ci_schedstate; + + KASSERT(ci1 != ci2); + mutex_spin_exit(spc1->spc_mutex); + mutex_spin_exit(spc2->spc_mutex); } /* * Disable and re-enable preemption. Only for low-level kernel - * use. Device drivers and anything that could potentially be - * compiled as a module should use kpreempt_disable() and + * use. Code outside kern/ should use kpreempt_disable() and * kpreempt_enable(). */ static inline void @@ -504,11 +458,8 @@ KPREEMPT_ENABLE(lwp_t *l) #endif /* _KERNEL */ /* Flags for _lwp_create(), as per Solaris. */ + #define LWP_DETACHED 0x00000040 #define LWP_SUSPENDED 0x00000080 -/* Kernel-internal flags for LWP creation. */ -#define LWP_PIDLID 0x40000000 -#define LWP_VFORK 0x80000000 - #endif /* !_SYS_LWP_H_ */