bhyverun.c (264916) | bhyverun.c (265062) |
---|---|
1/*- 2 * Copyright (c) 2011 NetApp, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 2011 NetApp, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/usr.sbin/bhyve/bhyverun.c 264916 2014-04-25 13:38:18Z tychon $ | 26 * $FreeBSD: head/usr.sbin/bhyve/bhyverun.c 265062 2014-04-28 22:06:40Z neel $ |
27 */ 28 29#include <sys/cdefs.h> | 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/usr.sbin/bhyve/bhyverun.c 264916 2014-04-25 13:38:18Z tychon $"); | 30__FBSDID("$FreeBSD: head/usr.sbin/bhyve/bhyverun.c 265062 2014-04-28 22:06:40Z neel $"); |
31 32#include <sys/types.h> 33#include <sys/mman.h> 34#include <sys/time.h> 35 36#include <machine/atomic.h> 37#include <machine/segments.h> 38 --- 417 unchanged lines hidden (view full) --- 456 return (VMEXIT_ABORT); 457 } 458 459 return (VMEXIT_CONTINUE); 460} 461 462static pthread_mutex_t resetcpu_mtx = PTHREAD_MUTEX_INITIALIZER; 463static pthread_cond_t resetcpu_cond = PTHREAD_COND_INITIALIZER; | 31 32#include <sys/types.h> 33#include <sys/mman.h> 34#include <sys/time.h> 35 36#include <machine/atomic.h> 37#include <machine/segments.h> 38 --- 417 unchanged lines hidden (view full) --- 456 return (VMEXIT_ABORT); 457 } 458 459 return (VMEXIT_CONTINUE); 460} 461 462static pthread_mutex_t resetcpu_mtx = PTHREAD_MUTEX_INITIALIZER; 463static pthread_cond_t resetcpu_cond = PTHREAD_COND_INITIALIZER; |
464static int resetcpu = -1; | |
465 466static int 467vmexit_suspend(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) 468{ | 464 465static int 466vmexit_suspend(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) 467{ |
469 470 assert(resetcpu != -1); | 468 enum vm_suspend_how how; |
471 | 469 |
470 how = vmexit->u.suspended.how; 471 assert(how == VM_SUSPEND_RESET || how == VM_SUSPEND_POWEROFF); 472 |
|
472 fbsdrun_deletecpu(ctx, *pvcpu); 473 | 473 fbsdrun_deletecpu(ctx, *pvcpu); 474 |
474 if (*pvcpu != resetcpu) { | 475 if (*pvcpu != BSP) { |
475 pthread_mutex_lock(&resetcpu_mtx); 476 pthread_cond_signal(&resetcpu_cond); 477 pthread_mutex_unlock(&resetcpu_mtx); 478 pthread_exit(NULL); 479 } 480 481 pthread_mutex_lock(&resetcpu_mtx); 482 while (!CPU_EMPTY(&cpumask)) { 483 pthread_cond_wait(&resetcpu_cond, &resetcpu_mtx); 484 } 485 pthread_mutex_unlock(&resetcpu_mtx); | 476 pthread_mutex_lock(&resetcpu_mtx); 477 pthread_cond_signal(&resetcpu_cond); 478 pthread_mutex_unlock(&resetcpu_mtx); 479 pthread_exit(NULL); 480 } 481 482 pthread_mutex_lock(&resetcpu_mtx); 483 while (!CPU_EMPTY(&cpumask)) { 484 pthread_cond_wait(&resetcpu_cond, &resetcpu_mtx); 485 } 486 pthread_mutex_unlock(&resetcpu_mtx); |
486 exit(0); | 487 488 if (how == VM_SUSPEND_RESET) 489 exit(0); 490 if (how == VM_SUSPEND_POWEROFF) 491 exit(1); 492 return (0); /* NOTREACHED */ |
487} 488 489static vmexit_handler_t handler[VM_EXITCODE_MAX] = { 490 [VM_EXITCODE_INOUT] = vmexit_inout, 491 [VM_EXITCODE_VMX] = vmexit_vmx, 492 [VM_EXITCODE_BOGUS] = vmexit_bogus, 493 [VM_EXITCODE_RDMSR] = vmexit_rdmsr, 494 [VM_EXITCODE_WRMSR] = vmexit_wrmsr, --- 5 unchanged lines hidden (view full) --- 500}; 501 502static void 503vm_loop(struct vmctx *ctx, int vcpu, uint64_t rip) 504{ 505 cpuset_t mask; 506 int error, rc, prevcpu; 507 enum vm_exitcode exitcode; | 493} 494 495static vmexit_handler_t handler[VM_EXITCODE_MAX] = { 496 [VM_EXITCODE_INOUT] = vmexit_inout, 497 [VM_EXITCODE_VMX] = vmexit_vmx, 498 [VM_EXITCODE_BOGUS] = vmexit_bogus, 499 [VM_EXITCODE_RDMSR] = vmexit_rdmsr, 500 [VM_EXITCODE_WRMSR] = vmexit_wrmsr, --- 5 unchanged lines hidden (view full) --- 506}; 507 508static void 509vm_loop(struct vmctx *ctx, int vcpu, uint64_t rip) 510{ 511 cpuset_t mask; 512 int error, rc, prevcpu; 513 enum vm_exitcode exitcode; |
514 enum vm_suspend_how how; |
|
508 509 if (pincpu >= 0) { 510 CPU_ZERO(&mask); 511 CPU_SET(pincpu + vcpu, &mask); 512 error = pthread_setaffinity_np(pthread_self(), 513 sizeof(mask), &mask); 514 assert(error == 0); 515 } --- 17 unchanged lines hidden (view full) --- 533 switch (rc) { 534 case VMEXIT_CONTINUE: 535 rip = vmexit[vcpu].rip + vmexit[vcpu].inst_length; 536 break; 537 case VMEXIT_RESTART: 538 rip = vmexit[vcpu].rip; 539 break; 540 case VMEXIT_RESET: | 515 516 if (pincpu >= 0) { 517 CPU_ZERO(&mask); 518 CPU_SET(pincpu + vcpu, &mask); 519 error = pthread_setaffinity_np(pthread_self(), 520 sizeof(mask), &mask); 521 assert(error == 0); 522 } --- 17 unchanged lines hidden (view full) --- 540 switch (rc) { 541 case VMEXIT_CONTINUE: 542 rip = vmexit[vcpu].rip + vmexit[vcpu].inst_length; 543 break; 544 case VMEXIT_RESTART: 545 rip = vmexit[vcpu].rip; 546 break; 547 case VMEXIT_RESET: |
541 if (vm_suspend(ctx) == 0) { 542 assert(resetcpu == -1); 543 resetcpu = vcpu; 544 } | 548 case VMEXIT_POWEROFF: 549 if (rc == VMEXIT_RESET) 550 how = VM_SUSPEND_RESET; 551 else 552 how = VM_SUSPEND_POWEROFF; 553 error = vm_suspend(ctx, how); 554 assert(error == 0 || errno == EALREADY); |
545 rip = vmexit[vcpu].rip + vmexit[vcpu].inst_length; 546 break; 547 default: 548 exit(1); 549 } 550 } 551 fprintf(stderr, "vm_run error %d, errno %d\n", error, errno); 552} --- 229 unchanged lines hidden --- | 555 rip = vmexit[vcpu].rip + vmexit[vcpu].inst_length; 556 break; 557 default: 558 exit(1); 559 } 560 } 561 fprintf(stderr, "vm_run error %d, errno %d\n", error, errno); 562} --- 229 unchanged lines hidden --- |