PCU(9)
πΈ NAME πΈ
Okay bestie, meet pcu(9) from the Kernel Developer's Manual β the per-CPU unit, aka PCU. It's the kernel interface that manages synchronization of any per-CPU context (unit) tied to an LWP context. The classic iconic use case is "lazy-switch" synchronization of the FPU state. Each PCU has its operations defined by a pcu_ops_t structure. π
β¨ 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. Slay, save that state. πΎ
π 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"whenpcu_load()is called by the LWP. Otherwise, return false. βpcu_discard_all()β Discard all PCU states of the given LWP; generally used byexecandexit. πͺ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. That's the code address, bestie. π
π¦ HISTORY π¦
PCU first appeared in NetBSD 6.0. A whole icon. β
π AUTHORS π
Mindaugas Rasiukevicius <rmind@NetBSD.org> β author credit, periodt. π
source/version: Debian β’ date: May 16, 2017 β’ page: PCU(9) β byeee bestie! π«Άπ
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2012-2014 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms