FreeBSD kernel kern code
|
#include "opt_witness.h"
#include "opt_hwpmc_hooks.h"
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/msan.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/bitstring.h>
#include <sys/epoch.h>
#include <sys/rangelock.h>
#include <sys/resourcevar.h>
#include <sys/sdt.h>
#include <sys/smp.h>
#include <sys/sched.h>
#include <sys/sleepqueue.h>
#include <sys/selinfo.h>
#include <sys/syscallsubr.h>
#include <sys/dtrace_bsd.h>
#include <sys/sysent.h>
#include <sys/turnstile.h>
#include <sys/taskqueue.h>
#include <sys/ktr.h>
#include <sys/rwlock.h>
#include <sys/umtxvar.h>
#include <sys/vmmeter.h>
#include <sys/cpuset.h>
#include <sys/priv.h>
#include <security/audit/audit.h>
#include <vm/pmap.h>
#include <vm/vm.h>
#include <vm/vm_extern.h>
#include <vm/uma.h>
#include <vm/vm_phys.h>
#include <sys/eventhandler.h>
Go to the source code of this file.
Data Structures | |
struct | thread_domain_data |
struct | tidbatch |
Macros | |
#define | TIDHASH(tid) (&tidhashtbl[(tid) & tidhash]) |
#define | TIDHASHLOCK(tid) (&tidhashtbl_lock[(tid) & tidhashlock]) |
#define | RUN_THRESH 16 |
Functions | |
__FBSDID ("$FreeBSD$") | |
SDT_PROVIDER_DECLARE (proc) | |
SDT_PROBE_DEFINE (proc,,, lwp__exit) | |
struct thread_domain_data | __aligned (CACHE_LINE_SIZE) |
static void | thread_zombie (struct thread *) |
static void | thread_reap (void) |
static void | thread_reap_all (void) |
static void | thread_reap_task_cb (void *, int) |
static void | thread_reap_callout_cb (void *) |
static int | thread_unsuspend_one (struct thread *td, struct proc *p, bool boundary) |
static void | thread_free_batched (struct thread *td) |
static | MALLOC_DEFINE (M_TIDHASH, "tidhash", "thread hash") |
SYSCTL_INT (_kern, OID_AUTO, maxthread, CTLFLAG_RDTUN, &maxthread, 0, "Maximum number of threads") | |
static | LIST_HEAD (tidhashhead, thread) |
static bool | thread_count_inc (void) |
static void | thread_count_sub (int n) |
static void | thread_count_dec (void) |
static lwpid_t | tid_alloc (void) |
static void | tid_free_locked (lwpid_t rtid) |
static void | tid_free (lwpid_t rtid) |
static void | tid_free_batch (lwpid_t *batch, int n) |
static void | tidbatch_prep (struct tidbatch *tb) |
static void | tidbatch_add (struct tidbatch *tb, struct thread *td) |
static void | tidbatch_process (struct tidbatch *tb) |
static void | tidbatch_final (struct tidbatch *tb) |
static int | thread_ctor (void *mem, int size, void *arg, int flags) |
static void | thread_dtor (void *mem, int size, void *arg) |
static int | thread_init (void *mem, int size, int flags) |
static void | thread_fini (void *mem, int size) |
void | proc_linkup0 (struct proc *p, struct thread *td) |
void | proc_linkup (struct proc *p, struct thread *td) |
void | threadinit (void) |
void | thread_stash (struct thread *td) |
static void | thread_reap_domain (struct thread_domain_data *tdd) |
static void | thread_reap_task_cb (void *arg __unused, int pending __unused) |
static void | thread_reap_callout_cb (void *arg __unused) |
void | thread_reap_barrier (void) |
struct thread * | thread_alloc (int pages) |
int | thread_alloc_stack (struct thread *td, int pages) |
void | thread_free (struct thread *td) |
void | thread_cow_get_proc (struct thread *newtd, struct proc *p) |
void | thread_cow_get (struct thread *newtd, struct thread *td) |
void | thread_cow_free (struct thread *td) |
void | thread_cow_update (struct thread *td) |
void | thread_cow_synced (struct thread *td) |
void | thread_exit (void) |
void | thread_wait (struct proc *p) |
void | thread_link (struct thread *td, struct proc *p) |
void | thread_unlink (struct thread *td) |
static int | calc_remaining (struct proc *p, int mode) |
static int | remain_for_mode (int mode) |
static int | weed_inhib (int mode, struct thread *td2, struct proc *p) |
int | thread_single (struct proc *p, int mode) |
bool | thread_suspend_check_needed (void) |
int | thread_suspend_check (int return_instead) |
int | thread_check_susp (struct thread *td, bool sleep) |
void | thread_suspend_switch (struct thread *td, struct proc *p) |
void | thread_suspend_one (struct thread *td) |
void | thread_run_flash (struct thread *td) |
void | thread_unsuspend (struct proc *p) |
void | thread_single_end (struct proc *p, int mode) |
static bool | tdfind_hash (lwpid_t tid, pid_t pid, struct proc **pp, struct thread **tdp) |
struct thread * | tdfind (lwpid_t tid, pid_t pid) |
void | tidhash_add (struct thread *td) |
void | tidhash_remove (struct thread *td) |
Variables | |
static uma_zone_t | thread_zone |
struct thread * | tdd_zombies |
int | tdd_reapticks |
static struct thread_domain_data | thread_domain_data [MAXMEMDOM] |
static struct task | thread_reap_task |
static struct callout | thread_reap_callout |
static __exclusive_cache_line struct mtx | tid_lock |
static bitstr_t * | tid_bitmap |
static int | maxthread |
static __exclusive_cache_line int | nthreads |
struct tidbatch | __aligned |
int | max_threads_per_proc |
#define RUN_THRESH 16 |
#define TIDHASH | ( | tid | ) | (&tidhashtbl[(tid) & tidhash]) |
#define TIDHASHLOCK | ( | tid | ) | (&tidhashtbl_lock[(tid) & tidhashlock]) |
struct thread_domain_data __aligned | ( | CACHE_LINE_SIZE | ) |
__FBSDID | ( | "$FreeBSD$" | ) |
|
static |
Definition at line 1077 of file kern_thread.c.
Referenced by thread_single().
|
static |
Definition at line 166 of file kern_thread.c.
|
static |
void proc_linkup | ( | struct proc * | p, |
struct thread * | td | ||
) |
Definition at line 468 of file kern_thread.c.
References ksiginfo_alloc(), sigqueue_init(), and thread_link().
Referenced by fork1(), and proc_linkup0().
void proc_linkup0 | ( | struct proc * | p, |
struct thread * | td | ||
) |
Definition at line 461 of file kern_thread.c.
References proc_linkup().
|
static |
Definition at line 1095 of file kern_thread.c.
References mode.
Referenced by thread_single(), and thread_single_end().
SDT_PROBE_DEFINE | ( | proc | , |
lwp__exit | |||
) |
SDT_PROVIDER_DECLARE | ( | proc | ) |
SYSCTL_INT | ( | _kern | , |
OID_AUTO | , | ||
maxthread | , | ||
CTLFLAG_RDTUN | , | ||
& | maxthread, | ||
0 | , | ||
"Maximum number of threads" | |||
) |
struct thread * tdfind | ( | lwpid_t | tid, |
pid_t | pid | ||
) |
Definition at line 1729 of file kern_thread.c.
References tdfind_hash().
Referenced by cpuset_which(), get_cputime(), kern_ptrace(), pget(), sigev_findtd(), sys_rtprio_thread(), sys_thr_kill(), sys_thr_kill2(), sys_thr_set_name(), sys_thr_wake(), and umtxq_sleep_pi().
|
static |
Definition at line 1686 of file kern_thread.c.
References RUN_THRESH, TIDHASH, and TIDHASHLOCK.
Referenced by tdfind().
struct thread * thread_alloc | ( | int | pages | ) |
Definition at line 746 of file kern_thread.c.
References kmsan_thread_alloc(), thread_count_dec(), thread_count_inc(), thread_ctor(), thread_zone, tid_alloc(), and tid_free().
Referenced by fork1(), kern_thr_alloc(), and kthread_add().
int thread_alloc_stack | ( | struct thread * | td, |
int | pages | ||
) |
Definition at line 773 of file kern_thread.c.
Referenced by fork1().
int thread_check_susp | ( | struct thread * | td, |
bool | sleep | ||
) |
Definition at line 1476 of file kern_thread.c.
References thread_suspend_check().
Referenced by do_lock_normal(), do_lock_pi(), do_lock_pp(), do_rw_rdlock(), do_rw_unlock(), do_rw_wrlock(), do_sem2_wait(), do_sem2_wake(), do_unlock_normal(), do_unlock_pi(), do_wake2_umutex(), do_wake_umutex(), sigfastblock_setpend1(), and sys_sigfastblock().
|
static |
Definition at line 226 of file kern_thread.c.
References thread_count_sub().
Referenced by thread_alloc(), and thread_free().
|
static |
Definition at line 195 of file kern_thread.c.
References ppsratecheck(), printf(), thread_reap(), and thread_reap_all().
Referenced by thread_alloc(), and threadinit().
|
static |
Definition at line 219 of file kern_thread.c.
References nthreads.
Referenced by thread_count_dec(), and thread_reap_domain().
void thread_cow_free | ( | struct thread * | td | ) |
Definition at line 842 of file kern_thread.c.
References crcowfree(), and lim_free().
Referenced by thread_create(), and thread_wait().
void thread_cow_get | ( | struct thread * | newtd, |
struct thread * | td | ||
) |
Definition at line 831 of file kern_thread.c.
References crcowget(), and lim_hold().
Referenced by thread_create().
void thread_cow_get_proc | ( | struct thread * | newtd, |
struct proc * | p | ||
) |
Definition at line 820 of file kern_thread.c.
References crcowget(), and lim_hold().
Referenced by do_fork(), kthread_add(), and proc0_init().
void thread_cow_synced | ( | struct thread * | td | ) |
Definition at line 871 of file kern_thread.c.
Referenced by kern_proc_setrlimit().
void thread_cow_update | ( | struct thread * | td | ) |
Definition at line 852 of file kern_thread.c.
References crcowsync(), crfree(), lim_cowsync(), and lim_free().
Referenced by ast(), and syscallenter().
|
static |
Definition at line 345 of file kern_thread.c.
References kdtrace_thread_ctor(), and umtx_thread_alloc().
Referenced by proc0_init(), proc_ctor(), thread_alloc(), and threadinit().
|
static |
Definition at line 375 of file kern_thread.c.
References kdtrace_thread_dtor(), panic(), and seltdfini().
Referenced by kcov_init(), proc_dtor(), thread_free(), thread_reap_domain(), and threadinit().
void thread_exit | ( | void | ) |
Definition at line 893 of file kern_thread.c.
References cpu_ticks, Giant, panic(), rucollect(), ruxagg_locked(), sched_exit_thread(), sched_throw(), thread_unlink(), thread_unsuspend_one(), ticks, and witness_thread_exit().
Referenced by exit1(), kern_thr_exit(), and kthread_exit().
|
static |
Definition at line 439 of file kern_thread.c.
References rlqentry_free(), sleepq_free(), thread_fini(), turnstile_free(), and umtx_thread_fini().
Referenced by thread_fini(), and threadinit().
void thread_free | ( | struct thread * | td | ) |
Definition at line 808 of file kern_thread.c.
References thread_count_dec(), thread_dtor(), thread_free_batched(), and tid_free().
Referenced by proc_fini(), and thread_create().
|
static |
Definition at line 788 of file kern_thread.c.
References cpuset_rel(), kmsan_thread_free(), and thread_zone.
Referenced by thread_free(), and thread_reap_domain().
|
static |
Definition at line 418 of file kern_thread.c.
References sleepq_alloc(), thread_init(), turnstile_alloc(), and umtx_thread_init().
Referenced by proc0_init(), thread_init(), and threadinit().
void thread_link | ( | struct thread * | td, |
struct proc * | p | ||
) |
Definition at line 1032 of file kern_thread.c.
References callout_init(), and sigqueue_init().
Referenced by kthread_add(), proc_linkup(), and thread_create().
|
static |
Definition at line 670 of file kern_thread.c.
References domain, and thread_reap_domain().
Referenced by thread_count_inc(), and thread_wait().
|
static |
Definition at line 654 of file kern_thread.c.
References domain, and thread_reap_domain().
Referenced by thread_count_inc(), and thread_reap_task_cb().
void thread_reap_barrier | ( | void | ) |
Definition at line 721 of file kern_thread.c.
References free(), malloc(), quiesce_all_cpus(), taskqueue_drain(), taskqueue_enqueue(), and thread_reap_task_cb().
|
static |
Referenced by thread_reap_callout_cb(), and threadinit().
|
static |
Definition at line 689 of file kern_thread.c.
References hz, taskqueue_enqueue(), thread_domain_data::tdd_reapticks, thread_domain_data::tdd_zombies, thread_reap_callout, thread_reap_callout_cb(), thread_reap_task, and ticks.
|
static |
Definition at line 583 of file kern_thread.c.
References credbatch_add(), credbatch_final(), lim_freen(), thread_domain_data::tdd_reapticks, thread_domain_data::tdd_zombies, thread_count_sub(), thread_dtor(), thread_free_batched(), ticks, tidbatch_add(), tidbatch_final(), tidbatch_prep(), and tidbatch_process().
Referenced by thread_reap(), and thread_reap_all().
|
static |
|
static |
Definition at line 682 of file kern_thread.c.
References thread_reap_all().
void thread_run_flash | ( | struct thread * | td | ) |
Definition at line 1562 of file kern_thread.c.
References setrunnable(), and sleepq_remove_nested().
Referenced by kern_ptrace().
int thread_single | ( | struct proc * | p, |
int | mode | ||
) |
Definition at line 1188 of file kern_thread.c.
References calc_remaining(), Giant, mode, remain_for_mode(), sched_relinquish(), thread_suspend_switch(), and weed_inhib().
Referenced by exit1(), fork_norfproc(), post_execve(), pre_execve(), sigexit(), and stop_all_proc().
void thread_single_end | ( | struct proc * | p, |
int | mode | ||
) |
Definition at line 1628 of file kern_thread.c.
References mode, remain_for_mode(), and thread_unsuspend_one().
Referenced by fork_norfproc(), post_execve(), and resume_all_proc().
void thread_stash | ( | struct thread * | td | ) |
Definition at line 573 of file kern_thread.c.
References thread_zombie().
Referenced by fork_exit(), and mi_switch().
int thread_suspend_check | ( | int | return_instead | ) |
Definition at line 1365 of file kern_thread.c.
References Giant, kern_thr_exit(), mi_switch(), panic(), thread_stopped(), thread_suspend_check_needed(), thread_suspend_one(), thread_unsuspend_one(), and umtx_thread_exit().
Referenced by ast(), exit1(), fork_rfppwait(), kern_sigsuspend(), sig_ast_checksusp(), and thread_check_susp().
bool thread_suspend_check_needed | ( | void | ) |
Definition at line 1319 of file kern_thread.c.
Referenced by fork_rfppwait(), and thread_suspend_check().
void thread_suspend_one | ( | struct thread * | td | ) |
Definition at line 1528 of file kern_thread.c.
References sched_sleep().
Referenced by sig_suspend_threads(), thread_suspend_check(), and weed_inhib().
void thread_suspend_switch | ( | struct thread * | td, |
struct proc * | p | ||
) |
Definition at line 1500 of file kern_thread.c.
References mi_switch(), sched_sleep(), and thread_stopped().
Referenced by ptracestop(), sigprocess(), and thread_single().
void thread_unlink | ( | struct thread * | td | ) |
Definition at line 1061 of file kern_thread.c.
Referenced by thread_exit().
void thread_unsuspend | ( | struct proc * | p | ) |
Definition at line 1590 of file kern_thread.c.
References thread_unsuspend_one().
Referenced by kern_ptrace(), ptrace_unsuspend(), and tdsendsignal().
|
static |
Definition at line 1543 of file kern_thread.c.
References setrunnable().
Referenced by thread_exit(), thread_single_end(), thread_suspend_check(), thread_unsuspend(), and weed_inhib().
void thread_wait | ( | struct proc * | p | ) |
Definition at line 1006 of file kern_thread.c.
References cpuset_rel(), Giant, thread_cow_free(), and thread_reap().
Referenced by proc_reap().
|
static |
Definition at line 553 of file kern_thread.c.
References thread_domain_data::tdd_zombies.
Referenced by thread_stash().
void threadinit | ( | void | ) |
Definition at line 488 of file kern_thread.c.
References callout_init(), flags, hashinit(), hz, malloc(), max_threads_per_proc, maxproc, maxthread, panic(), sched_sizeof_thread(), thread_count_inc(), thread_ctor(), thread_dtor(), thread_fini(), thread_init(), thread_reap_callout, thread_reap_callout_cb(), thread_reap_task, thread_reap_task_cb(), thread_zone, tid_alloc(), tid_bitmap, and tid_lock.
Referenced by proc0_init().
|
static |
Definition at line 233 of file kern_thread.c.
References maxthread, tid_bitmap, and tid_lock.
Referenced by thread_alloc(), and threadinit().
|
static |
Definition at line 273 of file kern_thread.c.
References tid_free_locked(), and tid_lock.
Referenced by thread_alloc(), and thread_free().
|
static |
Definition at line 282 of file kern_thread.c.
References tid_free_locked(), and tid_lock.
Referenced by tidbatch_final(), and tidbatch_process().
|
static |
Definition at line 259 of file kern_thread.c.
References tid_bitmap, and tid_lock.
Referenced by tid_free(), and tid_free_batch().
|
static |
Definition at line 309 of file kern_thread.c.
References tidbatch::n, and tidbatch::tab.
Referenced by thread_reap_domain().
|
static |
Definition at line 331 of file kern_thread.c.
References tidbatch::n, tidbatch::tab, and tid_free_batch().
Referenced by thread_reap_domain().
|
static |
Definition at line 302 of file kern_thread.c.
References tidbatch::n.
Referenced by thread_reap_domain().
|
static |
Definition at line 319 of file kern_thread.c.
References tidbatch::n, tidbatch::tab, and tid_free_batch().
Referenced by thread_reap_domain().
void tidhash_add | ( | struct thread * | td | ) |
Definition at line 1763 of file kern_thread.c.
References TIDHASH, and TIDHASHLOCK.
Referenced by do_fork(), kthread_add(), proc0_init(), and thread_create().
void tidhash_remove | ( | struct thread * | td | ) |
Definition at line 1771 of file kern_thread.c.
References TIDHASHLOCK.
Referenced by exit1(), kern_thr_exit(), and kthread_exit().
|
static |
Definition at line 1102 of file kern_thread.c.
References mode, sleepq_abort(), thread_suspend_one(), and thread_unsuspend_one().
Referenced by thread_single().
struct bufdomain __aligned |
Referenced by sys_ioctl(), and sysctl_load_tunable_by_oid_locked().
|
extern |
Definition at line 70 of file kern_thr.c.
Referenced by kern_thr_alloc(), and threadinit().
|
static |
Definition at line 160 of file kern_thread.c.
Referenced by threadinit(), and tid_alloc().
|
static |
Definition at line 164 of file kern_thread.c.
Referenced by thread_count_sub().
int tdd_reapticks |
Definition at line 1 of file kern_thread.c.
struct thread* tdd_zombies |
Definition at line 0 of file kern_thread.c.
|
static |
Definition at line 141 of file kern_thread.c.
|
static |
Definition at line 144 of file kern_thread.c.
Referenced by thread_reap_callout_cb(), and threadinit().
|
static |
Definition at line 143 of file kern_thread.c.
Referenced by thread_reap_callout_cb(), and threadinit().
|
static |
Definition at line 134 of file kern_thread.c.
Referenced by thread_alloc(), thread_free_batched(), and threadinit().
|
static |
Definition at line 156 of file kern_thread.c.
Referenced by threadinit(), tid_alloc(), and tid_free_locked().
|
static |
Definition at line 155 of file kern_thread.c.
Referenced by threadinit(), tid_alloc(), tid_free(), tid_free_batch(), and tid_free_locked().