1.\" $NetBSD: pcu.9,v 1.2 2012/12/03 07:50:29 wiz Exp $ 2.\" 3.\" Copyright (c) 2012 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Mindaugas Rasiukevicius. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGE. 29.\" 30.Dd December 2, 2012 31.Dt PCU 9 32.Os 33.Sh NAME 34.Nm pcu 35.Nd per-CPU unit (PCU) 36.Sh SYNOPSIS 37.In sys/pcu.h 38.Ft void 39.Fn pcu_load "const pcu_ops_t *pcu" 40.Ft void 41.Fn pcu_save "const pcu_ops_t *pcu" 42.Ft void 43.Fn pcu_save_all "lwp_t *l" 44.Ft void 45.Fn pcu_discard "const pcu_ops_t *pcu" 46.Ft bool 47.Fn pcu_used_p "const pcu_ops_t *pcu" 48.\" ----- 49.Sh DESCRIPTION 50Per CPU Unit (PCU) is an interface to manage synchronization of any 51per-CPU context (unit) tied to an LWP context. 52Typical use of PCU is for "lazy-switch" synchronisation of FPU state. 53Each PCU has its operations defined by a 54.Vt pcu_ops_t 55structure. 56Members of 57.Vt pcu_ops_t 58are 59.Bd -literal 60 u_int pcu_id; 61 void (*pcu_state_save)(lwp_t *l); 62 void (*pcu_state_load)(lwp_t *l, bool used); 63 void (*pcu_state_release)(lwp_t *l); 64.Ed 65.Pp 66.Bl -tag -width compact 67.It Fn pcu_state_save 68save the current CPU's state into the given LWP's MD storage. 69.It Fn pcu_state_load 70load PCU state from the given LWP's MD storage to the current CPU. 71The 72.Ar used 73argument is true if it is not the first time the LWP uses the PCU. 74.It Fn pcu_state_release 75indicate to MD code that the PCU ownership by the LWP was released, 76therefore the next use of PCU on the LWP shall be detected and 77.Fn pcu_load 78be called to reacquire ownership. 79For example, this would often be the changing of a bit for a CPU to 80trap on the execution of one of the PCU's instructions. 81.El 82.Sh FUNCTIONS 83.Bl -tag -width compact 84.It Fn pcu_load 85Load (initialize) the PCU state of the current LWP on the current CPU. 86.It Fn pcu_save 87Save the PCU state to the given LWP. 88.It Fn pcu_discard 89Discard the PCU state of the current LWP. 90.It Fn pcu_used_p 91Return true if PCU was used (i.e. 92.Fn pcu_load 93was called) by the LWP. 94Otherwise, return false. 95.Fn pcu_save_all 96save PCU state of the given LWP, so that it could be used later. 97.El 98.\" ----- 99.Sh CODE REFERENCES 100.Nm 101is implemented within the file 102.Pa sys/kern/subr_pcu.c . 103.Sh HISTORY 104PCU first appeared in 105.Nx 6.0 . 106