FreeBSD kernel kern code
kern_synch.c File Reference
#include <sys/cdefs.h>
#include "opt_ktrace.h"
#include "opt_sched.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/blockcount.h>
#include <sys/condvar.h>
#include <sys/kdb.h>
#include <sys/kernel.h>
#include <sys/ktr.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/resourcevar.h>
#include <sys/sched.h>
#include <sys/sdt.h>
#include <sys/signalvar.h>
#include <sys/sleepqueue.h>
#include <sys/smp.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
#include <sys/sysproto.h>
#include <sys/vmmeter.h>
#include <machine/cpu.h>
Include dependency graph for kern_synch.c:

Go to the source code of this file.

Functions

 __FBSDID ("$FreeBSD$")
 
static void synch_setup (void *dummy)
 
 SYSINIT (synch_setup, SI_SUB_KICK_SCHEDULER, SI_ORDER_FIRST, synch_setup, NULL)
 
 SYSCTL_INT (_kern, OID_AUTO, fscale, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, FSCALE, "Fixed-point scale factor used for calculating load average values")
 
static void loadav (void *arg)
 
 SDT_PROVIDER_DECLARE (sched)
 
 SDT_PROBE_DEFINE (sched,,, preempt)
 
static void sleepinit (void *unused)
 
 SYSINIT (sleepinit, SI_SUB_KMEM, SI_ORDER_ANY, sleepinit, NULL)
 
int _sleep (const void *ident, struct lock_object *lock, int priority, const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags)
 
int msleep_spin_sbt (const void *ident, struct mtx *mtx, const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags)
 
int pause_sbt (const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags)
 
void wakeup (const void *ident)
 
void wakeup_one (const void *ident)
 
void wakeup_any (const void *ident)
 
void _blockcount_wakeup (blockcount_t *bc, u_int old)
 
int _blockcount_sleep (blockcount_t *bc, struct lock_object *lock, const char *wmesg, int prio)
 
static void kdb_switch (void)
 
void mi_switch (int flags)
 
int setrunnable (struct thread *td, int srqflags)
 
int should_yield (void)
 
void maybe_yield (void)
 
void kern_yield (int prio)
 
int sys_yield (struct thread *td, struct yield_args *uap)
 
int sys_sched_getcpu (struct thread *td, struct sched_getcpu_args *uap)
 

Variables

int hogticks
 
static const char pause_wchan [MAXCPU]
 
static struct callout loadav_callout
 
struct loadavg averunnable
 
static fixpt_t cexp [3]
 

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ _blockcount_sleep()

int _blockcount_sleep ( blockcount_t *  bc,
struct lock_object *  lock,
const char *  wmesg,
int  prio 
)

Definition at line 414 of file kern_synch.c.

References Giant, sleepq_add(), sleepq_lock(), sleepq_release(), sleepq_wait(), and sleepq_wait_sig().

Here is the call graph for this function:

◆ _blockcount_wakeup()

void _blockcount_wakeup ( blockcount_t *  bc,
u_int  old 
)

Definition at line 395 of file kern_synch.c.

References wakeup().

Here is the call graph for this function:

◆ _sleep()

int _sleep ( const void *  ident,
struct lock_object *  lock,
int  priority,
const char *  wmesg,
sbintime_t  sbt,
sbintime_t  pr,
int  flags 
)

Definition at line 135 of file kern_synch.c.

References flags, Giant, pause_wchan, pr, priority, sleepq_add(), sleepq_lock(), sleepq_release(), sleepq_set_timeout_sbt(), sleepq_timedwait(), sleepq_timedwait_sig(), sleepq_wait(), and sleepq_wait_sig().

Referenced by pause_sbt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kdb_switch()

static void kdb_switch ( void  )
static

Definition at line 477 of file kern_synch.c.

References kdb_backtrace(), kdb_reenter(), and panic().

Referenced by mi_switch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kern_yield()

void kern_yield ( int  prio)

Definition at line 660 of file kern_synch.c.

References mi_switch(), and sched_prio().

Referenced by __mnt_vnode_next_all(), __mnt_vnode_next_lazy(), buf_daemon(), fail_point_eval_nontrivial(), getblkx(), maybe_yield(), mnt_vnode_next_lazy(), stop_all_proc(), userland_sysctl(), vlrureclaim(), vn_rdwr_inchunks(), and vnlru_proc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadav()

static void loadav ( void *  arg)
static

Definition at line 612 of file kern_synch.c.

References averunnable, cexp, loadav(), loadav_callout, and sched_load().

Referenced by loadav(), and synch_setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ maybe_yield()

void maybe_yield ( void  )

Definition at line 652 of file kern_synch.c.

References kern_yield(), and should_yield().

Referenced by __umtx_op_nwake_private_compat32(), __umtx_op_nwake_private_native(), boottrace_display(), bufspace_daemon(), flushbufqueues(), mnt_vnode_next_lazy_relock(), uiomove_faultflag(), vn_deallocate_impl(), and vn_fallocate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mi_switch()

◆ msleep_spin_sbt()

int msleep_spin_sbt ( const void *  ident,
struct mtx mtx,
const char *  wmesg,
sbintime_t  sbt,
sbintime_t  pr,
int  flags 
)

Definition at line 242 of file kern_synch.c.

References flags, mtx, pr, sleepq_add(), sleepq_lock(), sleepq_release(), sleepq_set_timeout_sbt(), sleepq_timedwait(), and sleepq_wait().

Here is the call graph for this function:

◆ pause_sbt()

int pause_sbt ( const char *  wmesg,
sbintime_t  sbt,
sbintime_t  pr,
int  flags 
)

Definition at line 317 of file kern_synch.c.

References _sleep(), flags, kdb_active, pause_wchan, pr, and tick_sbt.

Here is the call graph for this function:

◆ SDT_PROBE_DEFINE()

SDT_PROBE_DEFINE ( sched  ,
preempt   
)

◆ SDT_PROVIDER_DECLARE()

SDT_PROVIDER_DECLARE ( sched  )

◆ setrunnable()

int setrunnable ( struct thread *  td,
int  srqflags 
)

Definition at line 567 of file kern_synch.c.

References panic(), and sched_wakeup().

Referenced by sleepq_resume_thread(), thread_run_flash(), and thread_unsuspend_one().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ should_yield()

int should_yield ( void  )

Definition at line 645 of file kern_synch.c.

References hogticks, and ticks.

Referenced by __mnt_vnode_next_all(), __mnt_vnode_next_lazy(), maybe_yield(), mnt_vnode_next_lazy(), vlrureclaim(), vop_stdallocate(), and vop_stddeallocate().

Here is the caller graph for this function:

◆ sleepinit()

static void sleepinit ( void *  unused)
static

Definition at line 106 of file kern_synch.c.

References hogticks, hz, and init_sleepqueues().

Here is the call graph for this function:

◆ synch_setup()

static void synch_setup ( void *  dummy)
static

Definition at line 636 of file kern_synch.c.

References callout_init(), loadav(), and loadav_callout.

Here is the call graph for this function:

◆ sys_sched_getcpu()

int sys_sched_getcpu ( struct thread *  td,
struct sched_getcpu_args *  uap 
)

Definition at line 691 of file kern_synch.c.

◆ sys_yield()

int sys_yield ( struct thread *  td,
struct yield_args *  uap 
)

Definition at line 679 of file kern_synch.c.

References mi_switch(), and sched_prio().

Here is the call graph for this function:

◆ SYSCTL_INT()

SYSCTL_INT ( _kern  ,
OID_AUTO  ,
fscale  ,
CTLFLAG_RD  ,
SYSCTL_NULL_INT_PTR  ,
FSCALE  ,
"Fixed-point scale factor used for calculating load average values"   
)

◆ SYSINIT() [1/2]

SYSINIT ( sleepinit  ,
SI_SUB_KMEM  ,
SI_ORDER_ANY  ,
sleepinit  ,
NULL   
)

◆ SYSINIT() [2/2]

SYSINIT ( synch_setup  ,
SI_SUB_KICK_SCHEDULER  ,
SI_ORDER_FIRST  ,
synch_setup  ,
NULL   
)

◆ wakeup()

void wakeup ( const void *  ident)

Definition at line 349 of file kern_synch.c.

References proc0, sleepq_broadcast(), sleepq_lock(), and sleepq_release().

Referenced by _blockcount_wakeup(), accept_filt_setopt(), addupc_task(), aio_bio_done_notify(), aio_kick(), aio_kick_nowait(), ald_activate(), ald_shutdown(), alq_getn(), alq_writen(), bd_flush(), bd_speedup(), bd_wakeup(), bdirtywakeup(), bdone(), biodone(), buf_daemon(), buf_daemon_shutdown(), bufobj_wdrop(), bufspace_daemon(), bufspace_daemon_shutdown(), bufspace_daemon_wakeup(), childproc_jobstate(), closef(), closefp_hl(), config_intrhook_disestablish_locked(), destroy_devl(), dounmount(), dounmount_cleanup(), epoch_drain_cb(), ether_poll_register(), eventfd_read(), eventfd_write(), eventhandler_prune_list(), exit1(), fail_point_drain(), fail_point_set(), gtaskqueue_run_locked(), gtaskqueue_terminate(), intr_event_add_handler(), intr_event_execute_handlers(), ithread_loop(), itimer_leave(), kern_msgrcv(), kern_msgsnd(), kern_ptrace(), kern_semctl(), knote_fdclose(), kproc_exit(), kproc_resume(), kproc_suspend(), kproc_suspend_check(), kqueue_release(), kqueue_task(), kqueue_wakeup(), kthread_exit(), kthread_resume(), kthread_suspend_check(), ktls_buffer_alloc(), ktls_check_rx(), ktls_enqueue(), ktls_enqueue_to_free(), lf_advlockasync(), lf_iteratelocks_vnode(), lf_purgelocks(), lf_wakeup_lock(), linker_kldload_unbusy(), msq_remove(), pipe_direct_write(), pipe_read(), pipe_write(), pipeclose(), pps_event(), proc_reap(), proc_wkilled(), ptrace_coredump(), rangelock_calc_block(), realitexpire(), rms_wunlock(), root_mount_rel(), runningwakeup(), sem_remove(), semexit_myhook(), sf_buf_free(), sleepq_remove_thread(), softclock_call_cc(), soisconnected(), soisdisconnected(), soisdisconnecting(), soshutdown(), sowakeup(), sys_acct(), sys_semop(), sys_thr_wake(), sysctl_root_handler_locked(), taskqueue_run_locked(), taskqueue_terminate(), turnstile_unpend(), umtxq_signal_queue(), umtxq_signal_thread(), unp_pcb_lock_peer(), vfs_mount_destroy(), vfs_mountroot(), vfs_notify_upper(), vfs_unbusy(), vfs_unregister_upper(), vfs_write_resume(), vfs_write_suspend_umnt(), vn_finished_secondary_write(), vn_finished_write(), vn_open_cred(), vnlru_kick(), and vnlru_proc().

Here is the call graph for this function:

◆ wakeup_any()

void wakeup_any ( const void *  ident)

Definition at line 380 of file kern_synch.c.

References sleepq_lock(), and sleepq_signal().

Referenced by gtaskqueue_thread_enqueue(), and taskqueue_thread_enqueue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wakeup_one()

Variable Documentation

◆ averunnable

struct loadavg averunnable
Initial value:
=
{ {0, 0, 0}, FSCALE }

Definition at line 84 of file kern_synch.c.

Referenced by loadav(), schedcpu(), tty_info(), and updatepri().

◆ cexp

fixpt_t cexp[3]
static
Initial value:
= {
0.9200444146293232 * FSCALE,
0.9834714538216174 * FSCALE,
0.9944598480048967 * FSCALE,
}

Definition at line 90 of file kern_synch.c.

Referenced by loadav().

◆ hogticks

int hogticks

Definition at line 79 of file kern_synch.c.

Referenced by sched_initticks(), should_yield(), sleepinit(), and sysctl_kern_quantum().

◆ loadav_callout

struct callout loadav_callout
static

Definition at line 82 of file kern_synch.c.

Referenced by loadav(), and synch_setup().

◆ pause_wchan

const char pause_wchan[MAXCPU]
static

Definition at line 80 of file kern_synch.c.

Referenced by _sleep(), and pause_sbt().