Changeset View
Changeset View
Standalone View
Standalone View
lib/libkvm/kvm_pcpu.c
Show First 20 Lines • Show All 210 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/* | /* | ||||
* Set up libkvm to handle dynamic per-CPU memory. | * Set up libkvm to handle dynamic per-CPU memory. | ||||
*/ | */ | ||||
static int | static int | ||||
_kvm_dpcpu_init(kvm_t *kd) | _kvm_dpcpu_init(kvm_t *kd) | ||||
{ | { | ||||
struct nlist nl[] = { | struct kvm_nlist nl[] = { | ||||
#define NLIST_START_SET_PCPU 0 | #define NLIST_START_SET_PCPU 0 | ||||
{ .n_name = "___start_" DPCPU_SETNAME }, | { .n_name = "___start_" DPCPU_SETNAME }, | ||||
#define NLIST_STOP_SET_PCPU 1 | #define NLIST_STOP_SET_PCPU 1 | ||||
{ .n_name = "___stop_" DPCPU_SETNAME }, | { .n_name = "___stop_" DPCPU_SETNAME }, | ||||
#define NLIST_DPCPU_OFF 2 | #define NLIST_DPCPU_OFF 2 | ||||
{ .n_name = "_dpcpu_off" }, | { .n_name = "_dpcpu_off" }, | ||||
#define NLIST_MP_MAXCPUS 3 | #define NLIST_MP_MAXCPUS 3 | ||||
{ .n_name = "_mp_maxcpus" }, | { .n_name = "_mp_maxcpus" }, | ||||
{ .n_name = NULL }, | { .n_name = NULL }, | ||||
}; | }; | ||||
uintptr_t *dpcpu_off_buf; | uintptr_t *dpcpu_off_buf; | ||||
size_t len; | size_t len; | ||||
u_int dpcpu_maxcpus; | u_int dpcpu_maxcpus; | ||||
/* | /* | ||||
* XXX: This only works for native kernels for now. | |||||
*/ | |||||
if (!kvm_native(kd)) | |||||
return (-1); | |||||
/* | |||||
* Locate and cache locations of important symbols using the internal | * Locate and cache locations of important symbols using the internal | ||||
* version of _kvm_nlist, turning off initialization to avoid | * version of _kvm_nlist, turning off initialization to avoid | ||||
* recursion in case of unresolveable symbols. | * recursion in case of unresolveable symbols. | ||||
*/ | */ | ||||
if (_kvm_nlist(kd, nl, 0) != 0) | if (_kvm_nlist(kd, nl, 0) != 0) | ||||
return (-1); | return (-1); | ||||
if (kvm_read(kd, nl[NLIST_MP_MAXCPUS].n_value, &dpcpu_maxcpus, | if (kvm_read(kd, nl[NLIST_MP_MAXCPUS].n_value, &dpcpu_maxcpus, | ||||
sizeof(dpcpu_maxcpus)) != sizeof(dpcpu_maxcpus)) | sizeof(dpcpu_maxcpus)) != sizeof(dpcpu_maxcpus)) | ||||
Show All 31 Lines | _kvm_dpcpu_initialized(kvm_t *kd, int intialize) | ||||
return (kd->dpcpu_initialized); | return (kd->dpcpu_initialized); | ||||
} | } | ||||
/* | /* | ||||
* Check whether the value is within the dpcpu symbol range and only if so | * Check whether the value is within the dpcpu symbol range and only if so | ||||
* adjust the offset relative to the current offset. | * adjust the offset relative to the current offset. | ||||
*/ | */ | ||||
uintptr_t | kvaddr_t | ||||
_kvm_dpcpu_validaddr(kvm_t *kd, uintptr_t value) | _kvm_dpcpu_validaddr(kvm_t *kd, kvaddr_t value) | ||||
{ | { | ||||
if (value == 0) | if (value == 0) | ||||
return (value); | return (value); | ||||
if (!kd->dpcpu_initialized) | if (!kd->dpcpu_initialized) | ||||
return (value); | return (value); | ||||
Show All 22 Lines | |||||
/* | /* | ||||
* Obtain a per-CPU copy for given cpu from UMA_ZONE_PCPU allocation. | * Obtain a per-CPU copy for given cpu from UMA_ZONE_PCPU allocation. | ||||
*/ | */ | ||||
ssize_t | ssize_t | ||||
kvm_read_zpcpu(kvm_t *kd, u_long base, void *buf, size_t size, int cpu) | kvm_read_zpcpu(kvm_t *kd, u_long base, void *buf, size_t size, int cpu) | ||||
{ | { | ||||
if (!kvm_native(kd)) | |||||
return (-1); | |||||
return (kvm_read(kd, (uintptr_t)(base + sizeof(struct pcpu) * cpu), | return (kvm_read(kd, (uintptr_t)(base + sizeof(struct pcpu) * cpu), | ||||
buf, size)); | buf, size)); | ||||
} | } | ||||
/* | /* | ||||
* Fetch value of a counter(9). | * Fetch value of a counter(9). | ||||
*/ | */ | ||||
uint64_t | uint64_t | ||||
Show All 17 Lines |