Changeset View
Changeset View
Standalone View
Standalone View
head/share/man/man9/dpcpu.9
Show All 19 Lines | |||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
.\" SUCH DAMAGE. | .\" SUCH DAMAGE. | ||||
.\" | .\" | ||||
.\" $FreeBSD$ | .\" $FreeBSD$ | ||||
.\" | .\" | ||||
.Dd March 26, 2017 | .Dd July 5, 2018 | ||||
.Dt DPCPU 9 | .Dt DPCPU 9 | ||||
.Os | .Os | ||||
.Sh NAME | .Sh NAME | ||||
.Nm dpcpu | .Nm dpcpu | ||||
.Nd Kernel Dynamic Per-CPU Memory Allocator | .Nd Kernel Dynamic Per-CPU Memory Allocator | ||||
.Sh SYNOPSIS | .Sh SYNOPSIS | ||||
.In sys/pcpu.h | .In sys/pcpu.h | ||||
.Ss Per-CPU Variable Definition and Declaration | .Ss Per-CPU Variable Definition and Declaration | ||||
.Fn DPCPU_DEFINE "type" "name" | .Fn DPCPU_DEFINE "type" "name" | ||||
.Fn DPCPU_DEFINE_STATIC "type" "name" | |||||
.Fn DPCPU_DECLARE "type" "name" | .Fn DPCPU_DECLARE "type" "name" | ||||
.Ss Current CPU Accessor Functions | .Ss Current CPU Accessor Functions | ||||
.Fn DPCPU_PTR "name" | .Fn DPCPU_PTR "name" | ||||
.Fn DPCPU_GET "name" | .Fn DPCPU_GET "name" | ||||
.Fn DPCPU_SET "name" "value" | .Fn DPCPU_SET "name" "value" | ||||
.Ss Named CPU Accessor Functions | .Ss Named CPU Accessor Functions | ||||
.Fn DPCPU_ID_PTR "cpu" "name" | .Fn DPCPU_ID_PTR "cpu" "name" | ||||
.Fn DPCPU_ID_GET "cpu" "name" | .Fn DPCPU_ID_GET "cpu" "name" | ||||
Show All 15 Lines | |||||
.Ed | .Ed | ||||
.Pp | .Pp | ||||
Values may also be initialized statically with the definition, causing each | Values may also be initialized statically with the definition, causing each | ||||
per-CPU instance to be initialized with the value: | per-CPU instance to be initialized with the value: | ||||
.Bd -literal -offset 1234 | .Bd -literal -offset 1234 | ||||
DPCPU_DEFINE(int, foo_int) = 1; | DPCPU_DEFINE(int, foo_int) = 1; | ||||
.Ed | .Ed | ||||
.Pp | .Pp | ||||
Syntactically, the definition may be treated as a variable. | Values that can be defined as | ||||
For example, a dynamic per-CPU variable may be declared as | .Dv static | ||||
.Dv static : | must use | ||||
.Fn DPCPU_DEFINE_STATIC : | |||||
.Bd -literal -offset 1234 | .Bd -literal -offset 1234 | ||||
static DPCPU_DEFINE(int, foo_int); | DPCPU_DEFINE_STATIC(int, foo_int); | ||||
.Ed | .Ed | ||||
.Pp | .Pp | ||||
.Fn DPCPU_DECLARE | .Fn DPCPU_DECLARE | ||||
produces a declaration of the per-CPU variable suitable for use in header | produces a declaration of the per-CPU variable suitable for use in header | ||||
files. | files. | ||||
.Pp | .Pp | ||||
The current CPU's variable instance can be accessed via | The current CPU's variable instance can be accessed via | ||||
.Nm DPCPU_PTR | .Nm DPCPU_PTR | ||||
Show All 24 Lines | |||||
.Pp | .Pp | ||||
For example, it may be desirable to protect access using | For example, it may be desirable to protect access using | ||||
.Xr critical_section 9 | .Xr critical_section 9 | ||||
to prevent both preemption and migration during use. | to prevent both preemption and migration during use. | ||||
Alternatively, it may be desirable to cache the CPU ID at the start of a | Alternatively, it may be desirable to cache the CPU ID at the start of a | ||||
sequence of accesses, using suitable synchronization to make non-atomic | sequence of accesses, using suitable synchronization to make non-atomic | ||||
sequences safe in the presence of migration. | sequences safe in the presence of migration. | ||||
.Bd -literal -offset 1234 | .Bd -literal -offset 1234 | ||||
static DPCPU_DEFINE(int, foo_int); | DPCPU_DEFINE_STATIC(int, foo_int); | ||||
static DPCPU_DEFINE(struct mutex, foo_lock); | DPCPU_DEFINE_STATIC(struct mutex, foo_lock); | ||||
void | void | ||||
foo_int_increment(void) | foo_int_increment(void) | ||||
{ | { | ||||
int cpu, value; | int cpu, value; | ||||
/* Safe as atomic access. */ | /* Safe as atomic access. */ | ||||
atomic_add_int(DPCPU_PTR(foo_int), 1); | atomic_add_int(DPCPU_PTR(foo_int), 1); | ||||
Show All 40 Lines |