Home | History | Annotate | Download | only in kern
History log of /src/sys/kern/sys_lwp.c
RevisionDateAuthorComments
 1.89  15-Oct-2023  riastradh kern_lwp.c: Sort includes. No functional change intended.
 1.88  15-Oct-2023  riastradh sys/lwp.h: Nix sys/syncobj.h dependency.

Remove it in ddb/db_syncobj.h too.

New sys/wchan.h defines wchan_t so that users need not pull in
sys/syncobj.h to get it.

Sprinkle #include <sys/syncobj.h> in .c files where it is now needed.
 1.87  08-Oct-2023  ad Ensure that an LWP that has taken a legitimate wakeup never produces an
error code from sleepq_block(). Then, it's possible to make cv_signal()
work as expected and only ever wake a singular LWP.
 1.86  04-Oct-2023  ad Eliminate l->l_biglocks. Originally I think it had a use but these days a
local variable will do.
 1.85  23-Sep-2023  ad - Simplify how priority boost for blocking in kernel is handled. Rather
than setting it up at each site where we block, make it a property of
syncobj_t. Then, do not hang onto the priority boost until userret(),
drop it as soon as the LWP is out of the run queue and onto a CPU.
Holding onto it longer is of questionable benefit.

- This allows two members of lwp_t to be deleted, and mi_userret() to be
simplified a lot (next step: trim it down to a single conditional).

- While here, constify syncobj_t and de-inline a bunch of small functions
like lwp_lock() which turn out not to be small after all (I don't know
why, but atomic_*_relaxed() seem to provoke a compiler shitfit above and
beyond what volatile does).
 1.84  17-Jul-2023  riastradh kern: New struct syncobj::sobj_name member for diagnostics.

XXX potential kernel ABI change -- not sure any modules actually use
struct syncobj but it's hard to rule that out because sys/syncobj.h
leaks into sys/lwp.h
 1.83  29-Jun-2022  riastradh sleepq(9): Pass syncobj through to sleepq_block.

Previously the usage pattern was:

sleepq_enter(sq, l, lock); // locks l
...
sleepq_enqueue(sq, ..., sobj, ...); // assumes l locked, sets l_syncobj
... (*)
sleepq_block(...); // unlocks l

As long as l remains locked from sleepq_enter to sleepq_block,
l_syncobj is stable, and sleepq_block uses it via ktrcsw to determine
whether the sleep is on a mutex in order to avoid creating ktrace
context-switch records (which involves allocation which is forbidden
in softint context, while taking and even sleeping for a mutex is
allowed).

However, in turnstile_block, the logic at (*) also involves
turnstile_lendpri, which sometimes unlocks and relocks l. At that
point, another thread can swoop in and sleepq_remove l, which sets
l_syncobj to sched_syncobj. If that happens, ktrcsw does what is
forbidden -- tries to allocate a ktrace record for the context
switch.

As an optimization, sleepq_block or turnstile_block could stop early
if it detects that l_syncobj doesn't match -- we've already been
requested to wake up at this point so there's no need to mi_switch.
(And then it would be unnecessary to pass the syncobj through
sleepq_block, because l_syncobj would remain stable.) But I'll leave
that to another change.

Reported-by: syzbot+8b9d7b066c32dbcdc63b@syzkaller.appspotmail.com
 1.82  23-May-2020  ad Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.
 1.81  23-May-2020  ad - Replace pid_table_lock with a lockless lookup covered by pserialize, with
the "writer" side being pid_table expansion. The basic idea is that when
doing an LWP lookup there is usually already a lock held (p->p_lock), or a
spin mutex that needs to be taken (l->l_mutex), and either can be used to
get the found LWP stable and confidently determine that all is correct.

- For user processes LSLARVAL implies the same thing as LSIDL ("not visible
by ID"), and lookup by ID in proc0 doesn't really happen. In-tree the new
state should be understood by top(1), the tty subsystem and so on, and
would attract the attention of 3rd party kernel grovellers in time, so
remove it and just rely on LSIDL.
 1.80  05-May-2020  ad lwp_unpark(): no need to acquire LWP refs or drop the proc lock.

On the hacky benchmarks I have, held over from the transition to 1:1
threading, this restores pthread_cond_signal() perf to radixtree/sleepq
levels, and semes much better than either with pthread_cond_broadcast() and
10 threads. It would be interesting to see what might be achieved with a
lockless lookup, which is within grasp now thanks to pid_table being used
for lookup.
 1.79  24-Apr-2020  thorpej Overhaul the way LWP IDs are allocated. Instead of each LWP having it's
own LWP ID space, LWP IDs came from the same number space as PIDs. The
lead LWP of a process gets the PID as its LID. If a multi-LWP process's
lead LWP exits, the PID persists for the process.

In addition to providing system-wide unique thread IDs, this also lets us
eliminate the per-process LWP radix tree, and some associated locks.

Remove the separate "global thread ID" map added previously; it is no longer
needed to provide this functionality.

Nudged in this direction by ad@ and chs@.
 1.78  22-Apr-2020  thorpej Remove _lwp_gettid(2) system call. This problem is going to be solved
another way. (Note: this call was never exposed in libc, so we can just
recycle the syscall number.)
 1.77  19-Apr-2020  ad Set LW_SINTR earlier so it doesn't pose a problem for doing interruptable
waits with turnstiles (not currently done).
 1.76  04-Apr-2020  thorpej branches: 1.76.2;
Add support for lazily generating a "global thread ID" for a LWP. This
identifier uniquely identifies an LWP across the entire system, and will
be used in future improvements in user-space synchronization primitives.

(Test disabled and libc stub not included intentionally so as to avoid
multiple libc version bumps.)
 1.75  30-Jan-2020  ad Update comments
 1.74  29-Jan-2020  ad - Track LWPs in a per-process radixtree. It uses no extra memory in the
single threaded case. Replace scans of p->p_lwps with lookups in the
tree. Find free LIDs for new LWPs in the tree. Replace the hashed sleep
queues for park/unpark with lookups in the tree under cover of a RW lock.

- lwp_wait(): if waiting on a specific LWP, find the LWP via tree lookup and
return EINVAL if it's detached, not ESRCH.

- Group the locks in struct proc at the end of the struct in their own cache
line.

- Add some comments.
 1.73  26-Jan-2020  ad Correction to previous: don't leak newuc if copyout() fails.
 1.72  25-Jan-2020  ad - Fix a race between the kernel and libpthread, where a new thread can start
life without its self->pt_lid being filled in.

- Fix an error path in _lwp_create(). If the new LID can't be copied out,
then get rid of the new LWP (i.e. either succeed or fail, not both).

- Mark l_dopreempt and l_nopreempt volatile in struct lwp.
 1.71  23-Nov-2019  ad branches: 1.71.2;
Minor scheduler cleanup:

- Adapt to cpu_need_resched() changes. Avoid lost & duplicate IPIs and ASTs.
sched_resched_cpu() and sched_resched_lwp() contain the logic for this.
- Changes for LSIDL to make the locking scheme match the intended design.
- Reduce lock contention and false sharing further.
- Numerous small bugfixes, including some corrections for SCHED_FIFO/RT.
- Use setrunnable() in more places, and merge cut & pasted code.
 1.70  30-Sep-2019  kamil Move TRAP_CHLD/TRAP_LWP ptrace information from struct proc to siginfo

Storing struct ptrace_state information inside struct proc was vulnerable
to synchronization bugs, as multiple events emitted in the same time were
overwritting other ones.

Cache the original parent process id in p_oppid. Reusing here p_opptr is
in theory prone to slight race codition.

Change the semantics of PT_GET_PROCESS_STATE, reutning EINVAL for calls
prompting for the value in cases when there wasn't registered an
appropriate event.

Add an alternative approach to check the ptrace_state information, directly
from the siginfo_t value returned from PT_GET_SIGINFO. The original
PT_GET_PROCESS_STATE approach is kept for compat with older NetBSD and
OpenBSD. New code is recommended to keep using PT_GET_PROCESS_STATE.

Add a couple of compile-time asserts for assumptions in the code.

No functional change intended in existing ptrace(2) software.

All ATF ptrace(2) and ATF GDB tests pass.

This change improves reliability of the threading ptrace(2) code.
 1.69  10-Jul-2019  maxv branches: 1.69.2;
Fix info leak: instead of using SS_INIT as a literal compound, use a global
variable from rodata. The compound gets pushed on the stack, the padding
of the structure was therefore not initialized, and was getting leaked to
userland in sys___sigaltstack14().
 1.68  01-Jul-2019  maxv Restrict the size given to copyoutstr. It is safer to do that; even if
there is no actual bug here, since the buffer is guaranteed to be NUL
terminated.

With KASAN we check the whole buffer to cover the "worst" case, and here
it triggered false positives because the buffer size was not filtered.
 1.67  03-May-2019  kamil Register KTR events for debugger related signals

Register signals for:

- crashes (FPE, SEGV, FPE, ILL, BUS)
- LWP events
- CHLD (FORK/VFORK/VFORK_DONE) events -- temporarily disabled
- EXEC events

While there refactor related functions in order to simplify the code.

Add missing comment documentation for recently added kernel functions.
 1.66  02-May-2019  kamil Introduce fixes for ptrace(2)

Stop disabling LWP create and exit events for PT_SYSCALL tracing.
PT_SYSCALL disabled EXEC reporting for legacy reasons, there is no need
to repeat it for LWP and CHLD events.

Pass full siginfo from trapsignal events (SEGV, BUS, ILL, TRAP, FPE).
This adds missing information about signals like fault address.

Set ps_lwp always.

Before passing siginfo to userland through p_sigctx.ps_info, make sure
that it was zeroed for unused bytes. LWP and CHLD events do not set si_addr
and si_trap, these pieces of information are passed for crashes (like
software breakpoint).

LLDB crash reporting works now correctly:

(lldb) r
Process 552 launched: '/tmp/a.out' (x86_64)
Process 552 stopped
* thread #1, stop reason = signal SIGSEGV: invalid address (fault address: 0x123456)
 1.65  01-May-2019  kamil Call MD code in mi_startlwp() before MI check for debugger

This allows to get initialized mcontext.
 1.64  01-May-2019  kamil Correct passing debugger related events for LWP create and exit

Add MI toplevel startlwp function.

Switch all userland LWPs to go through lwp_create using a shared
mi_startlwp() function between all MD ABIs.

Add debugger related event handling in mi_startlwp() and continue with
standard p->p_emul->e_startlwp at the end of this routine.

Use eventswitch() to notify the event of LWP exit in lwp_exit().

ATF ptrace(2) tests signal9 and signal10 now pass.
 1.63  30-Jan-2018  ozaki-r branches: 1.63.4;
Apply C99-style struct initialization to syncobj_t
 1.62  08-Dec-2017  christos make _lwp_park return the remaining time to sleep in the "ts" argument
if it is a relative timestamp, as discussed in tech-kern.
XXX: pullup-8
 1.61  01-Jun-2017  chs branches: 1.61.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.
 1.60  21-Apr-2017  kamil Try to fix build of sys_lwp.c

lwp_create() has been acquired more arguments, there was missing the latest
one. Per analogiam with changes in the same commit to other source files,
go for &SS_INIT.
 1.59  21-Apr-2017  christos - Propagate the signal mask from the ucontext_t to the newly created thread
as specified by _lwp_create(2)
- Reset the signal stack for threads created with _lwp_create(2)
 1.58  15-Jan-2017  maya branches: 1.58.2;
use a bound string copy
 1.57  24-Jul-2015  maxv branches: 1.57.2;
Unused inits (harmless).

Found by Brainy.
 1.56  29-Mar-2013  christos branches: 1.56.12;
Centralize the computation of struct timespec to the int timo.
Make lwp_park take the regular arguments for specifying what kind
of timeout we supply like clock_nanosleep(), namely clockid_t and flags.
 1.55  27-Sep-2012  rmind exit_lwps, lwp_wait: fix a race condition by re-trying if p_lock was dropped
in a case of process exit. Necessary to re-flag all LWPs for exit, as their
state might have changed or new LWPs spawned.

Should fix PR/46168 and PR/46402.
 1.54  21-May-2012  martin branches: 1.54.2;
Calling _lwp_create() with a bogus ucontext could trigger a kernel
assertion failure (and thus a crash in DIAGNOSTIC kernels). Independently
discovered by YAMAMOTO Takashi and Joel Sing.

To avoid this, introduce a cpu_mcontext_validate() function and move all
sanity checks from cpu_setmcontext() there. Also untangle the netbsd32
compat mess slightly and add a cpu_mcontext32_validate() cousin there.

Add an exhaustive atf test case, based partly on code from Joel Sing.

Should finally fix the remaining open part of PR kern/43903.
 1.53  19-Feb-2012  rmind Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.
 1.52  07-Jul-2010  chs branches: 1.52.8; 1.52.12; 1.52.14;
many changes for COMPAT_LINUX:
- update the linux syscall table for each platform.
- support new-style (NPTL) linux pthreads on all platforms.
clone() with CLONE_THREAD uses 1 process with many LWPs
instead of separate processes.
- move the contents of sys__lwp_setprivate() into a new
lwp_setprivate() and use that everywhere.
- update linux_release[] and linux32_release[] to "2.6.18".
- adjust placement of emul fork/exec/exit hooks as needed
and adjust other emul code to match.
- convert all struct emul definitions to use named initializers.
- change the pid allocator to allow multiple pids to refer to the same proc.
- remove a few fields from struct proc that are no longer needed.
- disable the non-functional "vdso" code in linux32/amd64,
glibc works fine without it.
- fix a race in the futex code where we could miss a wakeup after
a requeue operation.
- redo futex locking to be a little more efficient.
 1.51  13-Jun-2010  yamt increment p_nrlwps in lwp_create rather than letting callers do so
as it's always decremented by lwp_exit. this fixes error recovery of
eg. aio_procinit.
 1.50  06-Jun-2010  skrll Follow the correct locking protocol when creating an LWP and the process
is stopping.

Problem found by running the gdb testsuite (gdb didn't have pthreads
support)

Thanks to rmind for help with this.
 1.49  23-Apr-2010  rmind Remove lwp_uc_pool, replace it with kmem(9), plus add some consistency.
As discussed, a while ago, with ad@.
 1.48  01-Nov-2009  rmind branches: 1.48.2; 1.48.4;
- Move inittimeleft() and gettimeleft() to subr_time.c, where they belong.
- Move abstimeout2timo() there too and export. Use it in lwp_park().
 1.47  22-Oct-2009  rmind Make lwp_park_sobj and lwp_park_tab static.
Wrap long lines while here.
 1.46  21-Oct-2009  rmind Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.
 1.45  29-Mar-2009  ad _lwp_setprivate: provide the value to MD code if a hook is present.

This will be used to support TLS. The MD method must match the ELF TLS spec
for that CPU architecture (if there is a spec).

At this time it is only implemented for i386, where it means setting the
per-thread base address for %gs. Please implement this for your platform!
 1.44  11-Jan-2009  christos branches: 1.44.2;
merge christos-time_t
 1.43  16-Oct-2008  ad branches: 1.43.2; 1.43.4; 1.43.10;
_lwp_kill: set SI_LWP in the siginfo, not SI_USER.
 1.42  15-Oct-2008  wrstuden Merge wrstuden-revivesa into HEAD.
 1.41  26-May-2008  ad branches: 1.41.4;
Take the mutex pointer and waiters count out of sleepq_t: the values can
be or are maintained elsewhere. Now a sleepq_t is just a TAILQ_HEAD.
 1.40  28-Apr-2008  martin branches: 1.40.2;
Remove clause 3 and 4 from TNF licenses
 1.39  24-Apr-2008  ad branches: 1.39.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.
 1.38  24-Apr-2008  ad Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.
 1.37  17-Mar-2008  ad branches: 1.37.2; 1.37.4;
Add a boolean parameter to syncobj_t::sobj_unsleep. If true we want the
existing behaviour: the unsleep method unlocks and wakes the swapper if
needs be. If false, the caller is doing a batch operation and will take
care of that later. This is kind of ugly, but it's difficult for the caller
to know which lock to release in some situations.
 1.36  12-Mar-2008  ad +2008 for the copyright
 1.35  12-Mar-2008  ad Add a preemption counter to lwpctl_t, to allow user threads to detect that
they have been preempted.
 1.34  14-Feb-2008  ad branches: 1.34.2; 1.34.6;
Make schedstate_percpu::spc_lwplock an exernally allocated item. Remove
the hacks in sparc/cpu.c to reinitialize it. This should be in its own
cache line but that's another change.
 1.33  02-Jan-2008  ad Merge vmlocking2 to head.
 1.32  20-Dec-2007  dsl Convert all the system call entry points from:
int foo(struct lwp *l, void *v, register_t *retval)
to:
int foo(struct lwp *l, const struct foo_args *uap, register_t *retval)
Fixup compat code to not write into 'uap' and (in some cases) to actually
pass a correctly formatted 'uap' structure with the right name to the
next routine.
A few 'compat' routines that just call standard ones have been deleted.
All the 'compat' code compiles (along with the kernels required to test
build it).
98% done by automated scripts.
 1.31  02-Dec-2007  ad branches: 1.31.2; 1.31.6;
sys__lwp_create: set in the correct lock when the LWP is created suspended.
 1.30  12-Nov-2007  ad Add _lwp_ctl() system call: provides a bidirectional, per-LWP communication
area between processes and the kernel.
 1.29  07-Nov-2007  ad Fix error in previous.
 1.28  07-Nov-2007  ad Add _lwp_setname, _lwp_getname. Proposed on tech-kern.
 1.27  06-Nov-2007  ad Merge scheduler changes from the vmlocking branch. All discussed on
tech-kern:

- Invert priority space so that zero is the lowest priority. Rearrange
number and type of priority levels into bands. Add new bands like
'kernel real time'.
- Ignore the priority level passed to tsleep. Compute priority for
sleep dynamically.
- For SCHED_4BSD, make priority adjustment per-LWP, not per-process.
 1.26  06-Sep-2007  ad branches: 1.26.4; 1.26.6;
- Fix sleepq_block() to return EINTR if the LWP is cancelled. Pointed out
by yamt@.

- Introduce SOBJ_SLEEPQ_LIFO, and use for LWPs sleeping via _lwp_park.
libpthread enqueues most waiters in LIFO order to try and wake LWPs that
ran recently, since their working set is more likely to be in cache.
Matching the order of insertion reduces the time spent searching queues
in the kernel.

- Do not boost the priority of LWPs sleeping in _lwp_park, just let them
sleep at their user priority level. LWPs waiting for some I/O event in
the kernel still wait with kernel priority and get woken more quickly.
This needs more evaluation and is to be revisited, but the effect on a
variety of benchmarks is positive.

- When waking LWPs, do not send an IPI to remote CPUs or arrange for the
current LWP to be preempted unless (a) the thread being awoken has kernel
priority and has higher priority than the currently running thread or (b)
the remote CPU is idle.
 1.25  15-Aug-2007  rmind branches: 1.25.2;
sys__lwp_suspend: Handle the possible problem when target LWP might exit via
lwp_exit() before suspending. In such case, LWP might be already freed after
cv_wait_sig() and checking the list of LWPs via lwp_find() is necessary.

Possible problem catched by Andrew Doran.
 1.24  07-Aug-2007  ad - Fix a bug with _lwp_park() where if the computed wakeup time was under
1 microsecond into the future, the thread could enter an untimed sleep.
- Change the signature of _lwp_park() to accept an lwpid_t and second
hint pointer, but do so in a way that remains compatible with older
pthread libraries. This can be used to wake another thread before the
calling thread goes asleep, saving at least one syscall + involuntary
context switch. This turns out to be a fairly large win on the condvar
benchmarks that I have tried.
- Mark some more syscalls MP safe.
 1.23  02-Aug-2007  rmind branches: 1.23.2; 1.23.4;
sys__lwp_suspend: implement waiting for target LWP status changes (or
process exiting). Removes XXXLWP.

Reviewed by <ad> some time ago..
 1.22  01-Aug-2007  ad KNF
 1.21  11-Jul-2007  rmind branches: 1.21.2;
Fix a problem in sys__lwp_create() where invalid new_lwp would
leak an LWP and memory.
Reviewed by <ad>.
 1.20  03-Jun-2007  dsl Split sys__lwp_park() so that the compat/netbsd32 code can copyin and convert
its timeout then call the standard function.
 1.19  17-May-2007  yamt merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.
 1.18  24-Mar-2007  rmind Handle newlwp() error case. Currently, newlwp() cannot fail, but this
will likely change in the future.
 1.17  21-Mar-2007  ad Improvements to lwp_wait1(), for PR kern/35932:

- Better detect simple cycles of threads calling _lwp_wait and return
EDEADLK. Does not handle deeper cycles like t1 -> t2 -> t3 -> t1.
- If there are multiple threads in _lwp_wait, then make sure that
targeted waits take precedence over waits for any LWP to exit.
- When checking for deadlock, also count the number of zombies currently
in the process as potentially reapable. Whenever a zombie is murdered,
kick all waiters to make them check again for deadlock.
- Add more comments.

Also, while here:

- LOCK_ASSERT -> KASSERT in some places
- lwp_free: change boolean arguments to type 'bool'.
- proc_free: let lwp_free spin waiting for the last LWP to exit, there's
no reason to do it here.
 1.16  20-Mar-2007  ad Changes to LWP wakeup:

- Don't bother sorting the sleep queues, since user space controls the
order of removal.
- Change setrunnable(t) to lwp_unsleep(t). No functional change from the
perspective of user applications.
- Minor cosmetic changes.
 1.15  14-Mar-2007  ad - Remove the LWP counters. The race between park/unpark rarely occurs
so it's not worth counting.

- lwp_wakeup: set LW_UNPARKED on the target. Ensures that _lwp_park will
always be awoken even if another system call eats the wakeup, e.g. as a
result of an intervening signal. To deal with this correctly for other
system calls will require a different approach.

- _lwp_unpark, _lwp_unpark_all: use setrunnable if the LWP is not parked
on the same sync queue: (1) simplifies the code a bit as there no point
doing anything special for this case (2) makes it possible for p_smutex
to be replaced by p_mutex and (3) restores the guarantee that the 'hint'
argument really is just a hint.
 1.14  14-Mar-2007  yamt branches: 1.14.2;
sys__lwp_park: whitespace. no functional change.
 1.13  14-Mar-2007  yamt sys__lwp_park: don't restart on signals. PR/35969 from Andrew Doran.
 1.12  09-Mar-2007  yamt branches: 1.12.2; 1.12.4;
fix typos in comments.
 1.11  02-Mar-2007  ad _lwp_wakeup: set the cancellation pending if the LWP is not sleeping.
 1.10  02-Mar-2007  ad sys__lwp_park: explicitly drop the kernel lock, for the benefit of compat32.
XXX The stack gap stuff is not MP or MT safe and needs to go away.
 1.9  02-Mar-2007  ad sys__lwp_park: on a !MULTIPROCESSOR kernel the LWP is already locked.
 1.8  01-Mar-2007  ad Fix a couple of races with LWP park/unpark.
 1.7  26-Feb-2007  yamt implement priority inheritance.
 1.6  21-Feb-2007  thorpej branches: 1.6.2;
Pick up some additional files that were missed before due to conflicts
with newlock2 merge:

Replace the Mach-derived boolean_t type with the C99 bool type. A
future commit will replace use of TRUE and FALSE with true and false.
 1.5  19-Feb-2007  cube Introduce a new member to struct emul, e_startlwp, to be used by
sys__lwp_create. It allows using the said syscall under COMPAT_NETBSD32.

The libpthread regression tests now pass on amd64 and sparc64.
 1.4  17-Feb-2007  pavel Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.
 1.3  15-Feb-2007  ad branches: 1.3.2;
Add uvm_kick_scheduler() (MP safe) to replace wakeup(&proc0).
 1.2  09-Feb-2007  ad Merge newlock2 to head.
 1.1  21-Oct-2006  ad branches: 1.1.2;
file sys_lwp.c was initially added on branch newlock2.
 1.1.2.12  04-Feb-2007  ad Push kernel_lock back further.
 1.1.2.11  03-Feb-2007  ad - Require that cv_signal/cv_broadcast be called with the interlock held.
- Provide 'async' versions that's don't need the interlock.
 1.1.2.10  30-Jan-2007  ad Remove support for SA. Ok core@.
 1.1.2.9  25-Jan-2007  ad - Make return of _lwp_detach() match other systems.
- Check for signo == 0 in _lwp_kill().
- KNF
 1.1.2.8  17-Jan-2007  ad Put back a missing wakeup.
 1.1.2.7  16-Jan-2007  ad lwp_detach(): if the target's a zombie, then free it.
 1.1.2.6  16-Jan-2007  ad Adjust arguments to _lwp_park() and friends so that in the best case
_lwp_unpark_all() only has to traverse one sleep queue.
 1.1.2.5  11-Jan-2007  ad Checkpoint work in progress.
 1.1.2.4  29-Dec-2006  ad Checkpoint work in progress.
 1.1.2.3  17-Nov-2006  ad Checkpoint work in progress.
 1.1.2.2  24-Oct-2006  ad - Redo LWP locking slightly and fix some races.
- Fix some locking botches.
- Make signal mask / stack per-proc for SA processes.
- Add _lwp_kill().
 1.1.2.1  21-Oct-2006  ad - Split core dump, LWP syscalls and signal syscalls into their own files.
- Checkpoint work in progress on locking & per-LWP signals.
 1.3.2.9  19-Apr-2007  ad Pull up a change from the vmlocking branch:

- Ensure that LWPs going to sleep are on the sleep queue before releasing
any interlocks. This is so that calls to turnstile_wakeup will have the
correct locks held when adjusting priority. Avoids another deadlock.
- Assume that LWPs blocked on a turnstile will never be swapped out.
- LWPs blocking on a turnstile must have kernel priority, as they
are consuming kernel resources.
 1.3.2.8  16-Apr-2007  ad - Nuke the seperate scheduler locking scheme for UP kernels - it has been
at the root of too many bugs.
- Add a LW_BOUND flag that indicates an LWP is bound to a specific CPU.
 1.3.2.7  15-Apr-2007  yamt sync with head.
 1.3.2.6  24-Mar-2007  yamt sync with head.
 1.3.2.5  24-Mar-2007  rmind Checkpoint:
- Abstract for per-CPU locking of runqueues.
As a workaround for SCHED_4BSD global runqueue, covered by sched_mutex,
spc_mutex is a pointer for now. After making SCHED_4BSD runqueues
per-CPU, it will became a storage mutex.
- suspendsched: Locking is not necessary for cpu_need_resched().
- Remove mutex_spin_exit() prototype in patch.c and LOCK_ASSERT() check
in runqueue_nextlwp() in sched_4bsd.c to make them compile again.
 1.3.2.4  17-Mar-2007  rmind Do not do an implicit enqueue in sched_switch(), move enqueueing back to
the dispatcher. Rename sched_switch() back to sched_nextlwp(). Add for
sched_enqueue() new argument, which indicates the calling from mi_switch().

Requested by yamt@
 1.3.2.3  12-Mar-2007  rmind Sync with HEAD.
 1.3.2.2  27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.3.2.1  20-Feb-2007  rmind General Common Scheduler Framework (CSF) patch import. Huge thanks for
Daniel Sieger <dsieger at TechFak.Uni-Bielefeld de> for this work.

Short abstract: Split the dispatcher from the scheduler in order to
make the scheduler more modular. Introduce initial API for other
schedulers' implementations.

Discussed in tech-kern@
OK: yamt@, ad@

Note: further work will go soon.
 1.6.2.10  24-Mar-2008  yamt sync with head.
 1.6.2.9  17-Mar-2008  yamt sync with head.
 1.6.2.8  27-Feb-2008  yamt sync with head.
 1.6.2.7  21-Jan-2008  yamt sync with head
 1.6.2.6  07-Dec-2007  yamt sync with head
 1.6.2.5  15-Nov-2007  yamt sync with head.
 1.6.2.4  27-Oct-2007  yamt sync with head.
 1.6.2.3  03-Sep-2007  yamt sync with head.
 1.6.2.2  26-Feb-2007  yamt sync with head.
 1.6.2.1  21-Feb-2007  yamt file sys_lwp.c was added on branch yamt-lazymbuf on 2007-02-26 09:11:16 +0000
 1.12.4.1  11-Jul-2007  mjf Sync with head.
 1.12.2.12  01-Nov-2007  ad - Fix interactivity problems under high load. Beacuse soft interrupts
are being stacked on top of regular LWPs, more often than not aston()
was being called on a soft interrupt thread instead of a user thread,
meaning that preemption was not happening on EOI.

- Don't use bool in a couple of data structures. Sub-word writes are not
always atomic and may clobber other fields in the containing word.

- For SCHED_4BSD, make p_estcpu per thread (l_estcpu). Rework how the
dynamic priority level is calculated - it's much better behaved now.

- Kill the l_usrpri/l_priority split now that priorities are no longer
directly assigned by tsleep(). There are three fields describing LWP
priority:

l_priority: Dynamic priority calculated by the scheduler.
This does not change for kernel/realtime threads,
and always stays within the correct band. Eg for
timeshared LWPs it never moves out of the user
priority range. This is basically what l_usrpri
was before.

l_inheritedprio: Lent to the LWP due to priority inheritance
(turnstiles).

l_kpriority: A boolean value set true the first time an LWP
sleeps within the kernel. This indicates that the LWP
should get a priority boost as compensation for blocking.
lwp_eprio() now does the equivalent of sched_kpri() if
the flag is set. The flag is cleared in userret().

- Keep track of scheduling class (OTHER, FIFO, RR) in struct lwp, and use
this to make decisions in a few places where we previously tested for a
kernel thread.

- Partially fix itimers and usr/sys/intr time accounting in the presence
of software interrupts.

- Use kthread_create() to create idle LWPs. Move priority definitions
from the various modules into sys/param.h.

- newlwp -> lwp_create
 1.12.2.11  18-Oct-2007  ad Free uareas back to the uarea cache on the CPU where they were last used.
 1.12.2.10  16-Oct-2007  ad kernel_lock isn't needed here. Pointed out by rmind@.
 1.12.2.9  09-Oct-2007  ad Sync with head.
 1.12.2.8  09-Sep-2007  ad Sync with _lwp_park/priority changes on HEAD.
 1.12.2.7  20-Aug-2007  ad Sync with HEAD.
 1.12.2.6  15-Jul-2007  ad Sync with head.
 1.12.2.5  09-Jun-2007  ad Sync with head.
 1.12.2.4  08-Jun-2007  ad Sync with head.
 1.12.2.3  10-Apr-2007  ad - Ensure that that LWPs going to sleep are on the sleep queue and so
have their syncobj pointer updated, so that calls to turnstile_wakeup
will have the correct locks held when adjusting the current LWP's
priority. Avoids another deadlock.
- Assume that LWPs blocked on a turnstile will never be swapped out.
- LWPs blocking on a turnstile must have kernel priority, as they
are consuming kernel resources.
 1.12.2.2  10-Apr-2007  ad Sync with head.
 1.12.2.1  10-Apr-2007  ad kernel_lock isn't needed for memory allocation any more.
 1.14.2.2  29-Mar-2007  reinoud Pullup to -current
 1.14.2.1  18-Mar-2007  reinoud First attempt to bring branch in sync with HEAD
 1.21.2.2  10-Sep-2007  skrll Sync with HEAD.
 1.21.2.1  15-Aug-2007  skrll Sync with HEAD.
 1.23.4.2  02-Aug-2007  rmind sys__lwp_suspend: implement waiting for target LWP status changes (or
process exiting). Removes XXXLWP.

Reviewed by <ad> some time ago..
 1.23.4.1  02-Aug-2007  rmind file sys_lwp.c was added on branch matt-mips64 on 2007-08-02 01:48:46 +0000
 1.23.2.7  03-Dec-2007  joerg Sync with HEAD.
 1.23.2.6  14-Nov-2007  joerg Sync with HEAD.
 1.23.2.5  11-Nov-2007  joerg Sync with HEAD.
 1.23.2.4  06-Nov-2007  joerg Sync with HEAD.
 1.23.2.3  02-Oct-2007  joerg Sync with HEAD.
 1.23.2.2  16-Aug-2007  jmcneill Sync with HEAD.
 1.23.2.1  09-Aug-2007  jmcneill Sync with HEAD.
 1.25.2.4  23-Mar-2008  matt sync with HEAD
 1.25.2.3  09-Jan-2008  matt sync with HEAD
 1.25.2.2  08-Nov-2007  matt sync with -HEAD
 1.25.2.1  06-Nov-2007  matt sync with HEAD
 1.26.6.4  18-Feb-2008  mjf Sync with HEAD.
 1.26.6.3  27-Dec-2007  mjf Sync with HEAD.
 1.26.6.2  08-Dec-2007  mjf Sync with HEAD.
 1.26.6.1  19-Nov-2007  mjf Sync with HEAD.
 1.26.4.1  13-Nov-2007  bouyer Sync with HEAD
 1.31.6.1  02-Jan-2008  bouyer Sync with HEAD
 1.31.2.2  26-Dec-2007  ad Sync with head.
 1.31.2.1  04-Dec-2007  ad Pull the vmlocking changes into a new branch.
 1.34.6.3  17-Jan-2009  mjf Sync with HEAD.
 1.34.6.2  02-Jun-2008  mjf Sync with HEAD.
 1.34.6.1  03-Apr-2008  mjf Sync with HEAD.
 1.34.2.1  24-Mar-2008  keiichi sync with head.
 1.37.4.2  04-Jun-2008  yamt sync with head
 1.37.4.1  18-May-2008  yamt sync with head.
 1.37.2.2  01-Nov-2008  christos Sync with head.
 1.37.2.1  29-Mar-2008  christos Welcome to the time_t=long long dev_t=uint64_t branch.
 1.39.2.4  11-Aug-2010  yamt sync with head.
 1.39.2.3  11-Mar-2010  yamt sync with head
 1.39.2.2  04-May-2009  yamt sync with head.
 1.39.2.1  16-May-2008  yamt sync with head.
 1.40.2.3  26-Jul-2008  wrstuden sys__lwp_create() and sys__lwp_suspend(): Only test to see if a process is
an SA process ifdef KERN_SA.

sys__sched_setaffinity(): Don't allow changing (setting) the affinity
of an SA process (or a thread in an SA process). To really set the
affinity of a thread in an SA process, we need to set the affility
for all LWPs on which that user thread will run. This really means
setting the affinity on all present and future threads on a VP
and also having the user thread always run on an lwp on that VP. The
latter needs libpthread's intervention.
 1.40.2.2  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.40.2.1  22-May-2008  wrstuden Add back checks to ensure we don't mix 1:1 & SA threaded processes.
 1.41.4.1  19-Oct-2008  haad Sync with HEAD.
 1.43.10.1  29-Apr-2011  matt Pull in lwp_setprivate/cpu_lwp_setprivate from -current.
Also pull in lwp_getpcb
 1.43.4.1  21-Nov-2010  riz Pull up following revision(s) (requested by skrll in ticket #1415):
sys/kern/sys_lwp.c: revision 1.50
Follow the correct locking protocol when creating an LWP and the process
is stopping.
Problem found by running the gdb testsuite (gdb didn't have pthreads
support)
Thanks to rmind for help with this.
 1.43.2.2  28-Apr-2009  skrll Sync with HEAD.
 1.43.2.1  19-Jan-2009  skrll Sync with HEAD.
 1.44.2.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.48.4.3  05-Mar-2011  rmind sync with head
 1.48.4.2  03-Jul-2010  rmind sync with head
 1.48.4.1  30-May-2010  rmind sync with head
 1.48.2.2  17-Aug-2010  uebayasi Sync with HEAD.
 1.48.2.1  30-Apr-2010  uebayasi Sync with HEAD.
 1.52.14.2  01-Oct-2012  riz Pull up following revision(s) (requested by rmind in ticket #583):
sys/kern/sys_lwp.c: revision 1.55
sys/sys/lwp.h: revision 1.164
sys/kern/kern_exit.c: revision 1.242
sys/kern/kern_lwp.c: revision 1.173
exit_lwps, lwp_wait: fix a race condition by re-trying if p_lock was dropped
in a case of process exit. Necessary to re-flag all LWPs for exit, as their
state might have changed or new LWPs spawned.
Should fix PR/46168 and PR/46402.
 1.52.14.1  21-May-2012  riz branches: 1.52.14.1.2;
Pull up following revision(s) (requested by martin in ticket #274):
sys/arch/amd64/amd64/process_machdep.c: revision 1.20
sys/kern/sys_lwp.c: revision 1.54
sys/arch/sparc64/sparc64/machdep.c: revision 1.267
sys/arch/mips/mips/cpu_subr.c: revision 1.16
sys/arch/vax/vax/machdep.c: revision 1.188
sys/sys/lwp.h: revision 1.161
sys/arch/sparc64/sparc64/netbsd32_machdep.c: revision 1.98
sys/arch/alpha/alpha/machdep.c: revision 1.339
sys/compat/sys/ucontext.h: revision 1.6
sys/arch/hppa/hppa/hppa_machdep.c: revision 1.28
distrib/sets/lists/tests/mi: revision 1.469
sys/arch/powerpc/powerpc/sig_machdep.c: revision 1.42
tests/lib/libc/sys/t_lwp_create.c: revision 1.1
tests/lib/libc/sys/Makefile: revision 1.23
sys/arch/arm/arm/sig_machdep.c: revision 1.42
sys/arch/amd64/include/mcontext.h: revision 1.15
sys/arch/amd64/amd64/machdep.c: revision 1.183
sys/arch/sh3/sh3/sh3_machdep.c: revision 1.99
sys/arch/i386/i386/machdep.c: revision 1.727
sys/compat/netbsd32/netbsd32_lwp.c: revision 1.13
sys/arch/sparc/sparc/machdep.c: revision 1.319
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.76
sys/arch/m68k/m68k/sig_machdep.c: revision 1.49
sys/sys/ucontext.h: revision 1.16
sys/arch/mips/mips/netbsd32_machdep.c: revision 1.9
lib/libc/sys/_lwp_create.2: revision 1.5
Calling _lwp_create() with a bogus ucontext could trigger a kernel
assertion failure (and thus a crash in DIAGNOSTIC kernels). Independently
discovered by YAMAMOTO Takashi and Joel Sing.
To avoid this, introduce a cpu_mcontext_validate() function and move all
sanity checks from cpu_setmcontext() there. Also untangle the netbsd32
compat mess slightly and add a cpu_mcontext32_validate() cousin there.
Add an exhaustive atf test case, based partly on code from Joel Sing.
Should finally fix the remaining open part of PR kern/43903.
 1.52.14.1.2.1  01-Nov-2012  matt sync with netbsd-6-0-RELEASE.
 1.52.12.2  02-Jun-2012  mrg sync to latest -current.
 1.52.12.1  24-Feb-2012  mrg sync to -current.
 1.52.8.4  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.52.8.3  30-Oct-2012  yamt sync with head
 1.52.8.2  23-May-2012  yamt sync with head.
 1.52.8.1  17-Apr-2012  yamt sync with head
 1.54.2.3  03-Dec-2017  jdolecek update from HEAD
 1.54.2.2  23-Jun-2013  tls resync from head
 1.54.2.1  20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.56.12.3  28-Aug-2017  skrll Sync with HEAD
 1.56.12.2  05-Feb-2017  skrll Sync with HEAD
 1.56.12.1  22-Sep-2015  skrll Sync with HEAD
 1.57.2.2  26-Apr-2017  pgoyette Sync with HEAD
 1.57.2.1  20-Mar-2017  pgoyette Sync with HEAD
 1.58.2.1  21-Apr-2017  bouyer Sync with HEAD
 1.61.2.1  11-Aug-2019  martin Pull up following revision(s) (requested by maxv in ticket #1333):

sys/kern/sys_lwp.c: revision 1.69 (patch)

Fix info leak: instead of using SS_INIT as a literal compound, use a global
variable from rodata. The compound gets pushed on the stack, the padding
of the structure was therefore not initialized, and was getting leaked to
userland in sys___sigaltstack14().
 1.63.4.3  21-Apr-2020  martin Sync with HEAD
 1.63.4.2  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.63.4.1  10-Jun-2019  christos Sync with HEAD
 1.69.2.1  15-Oct-2019  martin Pull up following revision(s) (requested by kamil in ticket #311):

sys/sys/siginfo.h: revision 1.34
sys/kern/sys_ptrace_common.c: revision 1.59
sys/kern/sys_lwp.c: revision 1.70
sys/compat/sys/siginfo.h: revision 1.8
sys/kern/kern_sig.c: revision 1.365
sys/kern/kern_lwp.c: revision 1.203
sys/sys/signalvar.h: revision 1.96
sys/kern/kern_exec.c: revision 1.482
sys/kern/kern_fork.c: revision 1.214

Move TRAP_CHLD/TRAP_LWP ptrace information from struct proc to siginfo

Storing struct ptrace_state information inside struct proc was vulnerable
to synchronization bugs, as multiple events emitted in the same time were
overwritting other ones.

Cache the original parent process id in p_oppid. Reusing here p_opptr is
in theory prone to slight race codition.

Change the semantics of PT_GET_PROCESS_STATE, reutning EINVAL for calls
prompting for the value in cases when there wasn't registered an
appropriate event.

Add an alternative approach to check the ptrace_state information, directly
from the siginfo_t value returned from PT_GET_SIGINFO. The original
PT_GET_PROCESS_STATE approach is kept for compat with older NetBSD and
OpenBSD. New code is recommended to keep using PT_GET_PROCESS_STATE.
Add a couple of compile-time asserts for assumptions in the code.

No functional change intended in existing ptrace(2) software.

All ATF ptrace(2) and ATF GDB tests pass.

This change improves reliability of the threading ptrace(2) code.
 1.71.2.2  29-Feb-2020  ad Sync with head.
 1.71.2.1  25-Jan-2020  ad Sync with head.
 1.76.2.2  25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.76.2.1  20-Apr-2020  bouyer Sync with HEAD

RSS XML Feed