Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/mem.c
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | |||||
RB_HEAD(mmio_rb_tree, mmio_rb_range) mmio_rb_root, mmio_rb_fallback; | RB_HEAD(mmio_rb_tree, mmio_rb_range) mmio_rb_root, mmio_rb_fallback; | ||||
/* | /* | ||||
* Per-vCPU cache. Since most accesses from a vCPU will be to | * Per-vCPU cache. Since most accesses from a vCPU will be to | ||||
* consecutive addresses in a range, it makes sense to cache the | * consecutive addresses in a range, it makes sense to cache the | ||||
* result of a lookup. | * result of a lookup. | ||||
*/ | */ | ||||
static struct mmio_rb_range *mmio_hint[VM_MAXCPU]; | static struct mmio_rb_range **mmio_hint; | ||||
static int mmio_ncpu; | |||||
static pthread_rwlock_t mmio_rwlock; | static pthread_rwlock_t mmio_rwlock; | ||||
static int | static int | ||||
mmio_rb_range_compare(struct mmio_rb_range *a, struct mmio_rb_range *b) | mmio_rb_range_compare(struct mmio_rb_range *a, struct mmio_rb_range *b) | ||||
{ | { | ||||
if (a->mr_end < b->mr_base) | if (a->mr_end < b->mr_base) | ||||
return (-1); | return (-1); | ||||
▲ Show 20 Lines • Show All 267 Lines • ▼ Show 20 Lines | unregister_mem(struct mem_range *memp) | ||||
if (err == 0) { | if (err == 0) { | ||||
mr = &entry->mr_param; | mr = &entry->mr_param; | ||||
assert(mr->name == memp->name); | assert(mr->name == memp->name); | ||||
assert(mr->base == memp->base && mr->size == memp->size); | assert(mr->base == memp->base && mr->size == memp->size); | ||||
assert((mr->flags & MEM_F_IMMUTABLE) == 0); | assert((mr->flags & MEM_F_IMMUTABLE) == 0); | ||||
RB_REMOVE(mmio_rb_tree, &mmio_rb_root, entry); | RB_REMOVE(mmio_rb_tree, &mmio_rb_root, entry); | ||||
/* flush Per-vCPU cache */ | /* flush Per-vCPU cache */ | ||||
for (i=0; i < VM_MAXCPU; i++) { | for (i = 0; i < mmio_ncpu; i++) { | ||||
if (mmio_hint[i] == entry) | if (mmio_hint[i] == entry) | ||||
mmio_hint[i] = NULL; | mmio_hint[i] = NULL; | ||||
} | } | ||||
} | } | ||||
perror = pthread_rwlock_unlock(&mmio_rwlock); | perror = pthread_rwlock_unlock(&mmio_rwlock); | ||||
assert(perror == 0); | assert(perror == 0); | ||||
if (entry) | if (entry) | ||||
free(entry); | free(entry); | ||||
return (err); | return (err); | ||||
} | } | ||||
void | void | ||||
init_mem(void) | init_mem(int ncpu) | ||||
{ | { | ||||
mmio_ncpu = ncpu; | |||||
mmio_hint = calloc(ncpu, sizeof(*mmio_hint)); | |||||
RB_INIT(&mmio_rb_root); | RB_INIT(&mmio_rb_root); | ||||
RB_INIT(&mmio_rb_fallback); | RB_INIT(&mmio_rb_fallback); | ||||
pthread_rwlock_init(&mmio_rwlock, NULL); | pthread_rwlock_init(&mmio_rwlock, NULL); | ||||
} | } |