| PERCPU(9) | Kernel Developer's Manual | PERCPU(9) | 
percpu, percpu_alloc,
  percpu_free, percpu_getref,
  percpu_putref, percpu_foreach
  —
#include <sys/percpu.h>
typedef void (*percpu_callback_t)(void *, void *, struct cpu_info *);
percpu_t *
  
  percpu_alloc(size_t
    size);
void
  
  percpu_free(percpu_t
    *pc, size_t
  size);
void *
  
  percpu_getref(percpu_t
    *pc);
void
  
  percpu_putref(percpu_t
    *pc);
void
  
  percpu_foreach(percpu_t
    *pc, percpu_callback_t
    cb, void *arg);
percpu interface provides
  per-CPU, CPU-local memory reservations to kernel subsystems.
  percpu_alloc(size); reserves on
  each CPU an independent memory region of size bytes that
  is local to that CPU, returning a handle (percpu_t) to
  those regions. A thread may subsequently ask for a pointer,
  p, to the region held by the
  percpu_t on the thread's current CPU. Until the thread
  relinquishes the pointer, or voluntarily sleeps, the thread may read or write
  the region at p without causing interprocessor memory
  synchronization.
percpu_alloc(size)percpu_alloc() returns a handle for the per-CPU
      storage.percpu_free(pc,
    size)percpu_alloc(). When
      percpu_free() returns, pc is
      undefined. Treat this as an expensive operation.percpu_getref(pc)percpu_getref() in either thread or interrupt
      context. Follow each percpu_getref() call with a
      matching call to percpu_putref().percpu_putref(pc)percpu_getref(). Re-enables
      preemption.percpu_foreach(pc,
    cb, arg)(*cb)(p,
      arg, ci);. Call this in thread
      context. cb should be non-blocking and fast. Do not
      rely on cb to be run on the CPUs in any particular
      order.percpu interface is implemented within the file
  sys/kern/subr_percpu.c.
percpu interface first appeared in
  NetBSD 6.0.
| May 31, 2017 | NetBSD 9.3 |