Changeset View
Changeset View
Standalone View
Standalone View
sys/amd64/vmm/vmm_stat.c
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | vmm_stat_register(void *arg) | ||||
vst->index = vst_num_elems; | vst->index = vst_num_elems; | ||||
vst_num_elems += vst->nelems; | vst_num_elems += vst->nelems; | ||||
vsttab[vst_num_types++] = vst; | vsttab[vst_num_types++] = vst; | ||||
} | } | ||||
int | int | ||||
vmm_stat_copy(struct vm *vm, int vcpu, int *num_stats, uint64_t *buf) | vmm_stat_copy(struct vm *vm, int vcpu, int index, int count, int *num_stats, uint64_t *buf) | ||||
markj: Long line. | |||||
markjUnsubmitted Done Inline ActionsStill unwrapped. markj: Still unwrapped. | |||||
jhbAuthorUnsubmitted Done Inline ActionsOops, fixed before commit. jhb: Oops, fixed before commit. | |||||
{ | { | ||||
struct vmm_stat_type *vst; | struct vmm_stat_type *vst; | ||||
uint64_t *stats; | uint64_t *stats; | ||||
int i; | int i, tocopy; | ||||
if (vcpu < 0 || vcpu >= vm_get_maxcpus(vm)) | if (vcpu < 0 || vcpu >= vm_get_maxcpus(vm)) | ||||
return (EINVAL); | return (EINVAL); | ||||
if (index < 0 || count < 0) | |||||
Done Inline ActionsShould we guard against a negative index? Or perhaps change index and count to be unsigned. markj: Should we guard against a negative `index`? Or perhaps change `index` and `count` to be… | |||||
return (EINVAL); | |||||
if (index >= vst_num_elems) | |||||
jhbAuthorUnsubmitted Done Inline ActionsSo here we would just need to return (0) and set *num_stats to 0 for the 'index == vst_num_elems' case? jhb: So here we would just need to return (0) and set *num_stats to 0 for the 'index ==… | |||||
markjUnsubmitted Not Done Inline ActionsYeah, that was my thinking. If the index > vst_num_elems case continues to return an error, then vm_get_stats() needs to be adjusted to increment index by the number of entries returned rather than nitems(vmstats.statbuf). I'm not sure if it's worth the hassle, just a suggestion. markj: Yeah, that was my thinking. If the `index > vst_num_elems` case continues to return an error… | |||||
return (ENOENT); | |||||
tocopy = min(vst_num_elems - index, count); | |||||
/* Let stats functions update their counters */ | /* Let stats functions update their counters */ | ||||
for (i = 0; i < vst_num_types; i++) { | for (i = 0; i < vst_num_types; i++) { | ||||
Done Inline ActionsPossibly the stats should only be refreshed for requests with an index of 0. jhb: Possibly the stats should only be refreshed for requests with an index of 0. | |||||
vst = vsttab[i]; | vst = vsttab[i]; | ||||
if (vst->func != NULL) | if (vst->func != NULL) | ||||
(*vst->func)(vm, vcpu, vst); | (*vst->func)(vm, vcpu, vst); | ||||
} | } | ||||
/* Copy over the stats */ | /* Copy over the stats */ | ||||
stats = vcpu_stats(vm, vcpu); | stats = vcpu_stats(vm, vcpu); | ||||
for (i = 0; i < vst_num_elems; i++) | memcpy(buf, stats + index, tocopy * sizeof(stats[0])); | ||||
buf[i] = stats[i]; | *num_stats = tocopy; | ||||
*num_stats = vst_num_elems; | |||||
return (0); | return (0); | ||||
} | } | ||||
void * | void * | ||||
vmm_stat_alloc(void) | vmm_stat_alloc(void) | ||||
{ | { | ||||
return (malloc(vst_size, M_VMM_STAT, M_WAITOK)); | return (malloc(vst_size, M_VMM_STAT, M_WAITOK)); | ||||
▲ Show 20 Lines • Show All 59 Lines • Show Last 20 Lines |
Long line.