diff options
author | neel <neel@FreeBSD.org> | 2013-02-11 20:36:07 +0000 |
---|---|---|
committer | neel <neel@FreeBSD.org> | 2013-02-11 20:36:07 +0000 |
commit | 3a9eeaa765cdfd3940dbf4b881957c057c6d6576 (patch) | |
tree | 08d417f2f979935bc451028d59ec525a42e021c6 /usr.sbin | |
parent | 7bafa2ca4141fce3978c17cea165f86ce0c9ac69 (diff) | |
download | FreeBSD-src-3a9eeaa765cdfd3940dbf4b881957c057c6d6576.zip FreeBSD-src-3a9eeaa765cdfd3940dbf4b881957c057c6d6576.tar.gz |
Implement guest vcpu pinning using 'pthread_setaffinity_np(3)'.
Prior to this change pinning was implemented via an ioctl (VM_SET_PINNING)
that called 'sched_bind()' on behalf of the user thread.
The ULE implementation of 'sched_bind()' bumps up 'td_pinned' which in turn
runs afoul of the assertion '(td_pinned == 0)' in userret().
Using the cpuset affinity to implement pinning of the vcpu threads works with
both 4BSD and ULE schedulers and has the happy side-effect of getting rid
of a bunch of code in vmm.ko.
Discussed with: grehan
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/bhyve/bhyverun.c | 6 | ||||
-rw-r--r-- | usr.sbin/bhyvectl/bhyvectl.c | 23 |
2 files changed, 5 insertions, 24 deletions
diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index 8d03649..ea4b68c 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -520,13 +520,17 @@ static vmexit_handler_t handler[VM_EXITCODE_MAX] = { static void vm_loop(struct vmctx *ctx, int vcpu, uint64_t rip) { + cpuset_t mask; int error, rc, prevcpu; if (guest_vcpu_mux) setup_timeslice(); if (pincpu >= 0) { - error = vm_set_pinning(ctx, vcpu, pincpu + vcpu); + CPU_ZERO(&mask); + CPU_SET(pincpu + vcpu, &mask); + error = pthread_setaffinity_np(pthread_self(), + sizeof(mask), &mask); assert(error == 0); } diff --git a/usr.sbin/bhyvectl/bhyvectl.c b/usr.sbin/bhyvectl/bhyvectl.c index 35e1388..4eb87f9 100644 --- a/usr.sbin/bhyvectl/bhyvectl.c +++ b/usr.sbin/bhyvectl/bhyvectl.c @@ -183,8 +183,6 @@ usage(void) " [--get-vmcs-exit-interruption-info]\n" " [--get-vmcs-exit-interruption-error]\n" " [--get-vmcs-interruptibility]\n" - " [--set-pinning=<host_cpuid>]\n" - " [--get-pinning]\n" " [--set-x2apic-state=<state>]\n" " [--get-x2apic-state]\n" " [--set-lowmem=<memory below 4GB in units of MB>]\n" @@ -218,7 +216,6 @@ static int set_desc_tr, get_desc_tr; static int set_desc_ldtr, get_desc_ldtr; static int set_cs, set_ds, set_es, set_fs, set_gs, set_ss, set_tr, set_ldtr; static int get_cs, get_ds, get_es, get_fs, get_gs, get_ss, get_tr, get_ldtr; -static int set_pinning, get_pinning, pincpu; static int set_x2apic_state, get_x2apic_state; enum x2apic_state x2apic_state; static int run; @@ -374,7 +371,6 @@ enum { SET_SS, SET_TR, SET_LDTR, - SET_PINNING, SET_X2APIC_STATE, SET_VMCS_EXCEPTION_BITMAP, SET_VMCS_ENTRY_INTERRUPTION_INFO, @@ -423,7 +419,6 @@ main(int argc, char *argv[]) { "set-ss", REQ_ARG, 0, SET_SS }, { "set-tr", REQ_ARG, 0, SET_TR }, { "set-ldtr", REQ_ARG, 0, SET_LDTR }, - { "set-pinning",REQ_ARG, 0, SET_PINNING }, { "set-x2apic-state",REQ_ARG, 0, SET_X2APIC_STATE }, { "set-vmcs-exception-bitmap", REQ_ARG, 0, SET_VMCS_EXCEPTION_BITMAP }, @@ -552,7 +547,6 @@ main(int argc, char *argv[]) NO_ARG, &get_vmcs_exit_interruption_error, 1}, { "get-vmcs-interruptibility", NO_ARG, &get_vmcs_interruptibility, 1 }, - { "get-pinning",NO_ARG, &get_pinning, 1 }, { "get-x2apic-state",NO_ARG, &get_x2apic_state, 1 }, { "get-all", NO_ARG, &get_all, 1 }, { "run", NO_ARG, &run, 1 }, @@ -659,10 +653,6 @@ main(int argc, char *argv[]) ldtr = strtoul(optarg, NULL, 0); set_ldtr = 1; break; - case SET_PINNING: - pincpu = strtol(optarg, NULL, 0); - set_pinning = 1; - break; case SET_X2APIC_STATE: x2apic_state = strtol(optarg, NULL, 0); set_x2apic_state = 1; @@ -812,9 +802,6 @@ main(int argc, char *argv[]) if (!error && set_ldtr) error = vm_set_register(ctx, vcpu, VM_REG_GUEST_LDTR, ldtr); - if (!error && set_pinning) - error = vm_set_pinning(ctx, vcpu, pincpu); - if (!error && set_x2apic_state) error = vm_set_x2apic_state(ctx, vcpu, x2apic_state); @@ -1135,16 +1122,6 @@ main(int argc, char *argv[]) printf("ldtr[%d]\t\t0x%04lx\n", vcpu, ldtr); } - if (!error && (get_pinning || get_all)) { - error = vm_get_pinning(ctx, vcpu, &pincpu); - if (error == 0) { - if (pincpu < 0) - printf("pincpu[%d]\tunpinned\n", vcpu); - else - printf("pincpu[%d]\t%d\n", vcpu, pincpu); - } - } - if (!error && (get_x2apic_state || get_all)) { error = vm_get_x2apic_state(ctx, vcpu, &x2apic_state); if (error == 0) |