PCU(9)

PCU(9) | Kernel Developer's Manual | PCU(9)

# NAME

`pcu` —
per-CPU unit (PCU)

# SYNOPSIS

`#include <sys/pcu.h>`

void
`pcu_load`(const pcu_ops_t *pcu);

void
`pcu_save`(const pcu_ops_t *pcu, lwp_t *l);

void
`pcu_save_all`(lwp_t *l);

void
`pcu_discard`(const pcu_ops_t *pcu, lwp_t *l, bool valid);

void
`pcu_discard_all`(lwp_t *l);

bool
`pcu_valid_p`(const pcu_ops_t *pcu);

# DESCRIPTION

Per CPU Unit (PCU) is an interface to manage synchronization of any per-CPU context (unit) tied to an LWP context. Typical use of PCU is for "lazy-switch" synchronization of the FPU state. Each PCU has its operations defined by a pcu_ops_t structure. Members of pcu_ops_t are

            u_int	pcu_id;
            void	(*pcu_state_save)(lwp_t *l);
            void	(*pcu_state_load)(lwp_t *l, u_int flags);
            void	(*pcu_state_release)(lwp_t *l);

`pcu_state_save`()
  Indicate to MD code that the PCU state on the current CPU should be saved into the given LWP's MD storage.
`pcu_state_load`()
  Load PCU state from the given LWP's MD storage to the current CPU. The flags argument is a combination of one or more of the following:
  `PCU_VALID`
    Indicate that the PCU state is considered valid and need not be initialized. This is the case if the PCU state was already used (and thus loaded) by the LWP and has not been discarded since.
  `PCU_REENABLE`
    Indicate that a fault reoccurred while the PCU state is loaded, therefore PCU should be re-enabled. This happens if LWP is context switched to another CPU and then switched back to the original CPU while the state on that CPU has not been changed by other LWPs. It may also happen due to instruction "bouncing" on some architectures.
`pcu_state_release`()
  Indicate to MD code that the PCU ownership by the LWP was released, therefore the next use of PCU on the LWP shall be detected and `pcu_load`() be called to reacquire the ownership. For example, this would normally be the changing of a bit for a CPU to trap on the execution of one of the PCU's instructions.

# FUNCTIONS

`pcu_load`()
  Load or initialize the PCU state of the current LWP on the current CPU.
`pcu_save`()
  Save the specified PCU state to the given LWP.
`pcu_discard`()
  Discard the specified PCU state of the current LWP. The PCU state will be considered invalid, unless the "valid" parameter is set to true.
`pcu_valid_p`()
  Return true if PCU state is considered valid. Generally, it always becomes "valid" when `pcu_load`() is called by the LWP. Otherwise, return false.
`pcu_discard_all`()
  Discard all PCU states of the given LWP; generally used by exec and exit.
`pcu_save_all`()
  Save all PCU states of the given LWP; generally used during new LWP creation so that the PCU state of the parent could be copied.

# CODE REFERENCES

`pcu` is implemented within the file sys/kern/subr_pcu.c.

# HISTORY

PCU first appeared in NetBSD 6.0.

# AUTHORS

Mindaugas Rasiukevicius <rmind@NetBSD.org>

May 16, 2017 | NetBSD 10.1