void qtCPU_thread::load_cpu(qtCPU *u)
{
    stop_flag = true;
    loaded_flag = true;
    if (delete_cpu())
    {
        cpu = u;
        cpu->moveToThread(this);
    }
    else
    {
        qDebug() << "Delete cpu error!";
    }
}
示例#2
0
int main(int argc, char* argv[]) {
  if (argc != 5) {
    printf("usage: cache-sim <set bits> <associativity> <block bits> <tracefile>\n");
    exit(1);
  }
  int sets   = atoi(argv[1]);
  int lines  = atoi(argv[2]);
  int blocks = atoi(argv[3]);
  char* file = argv[4];

  Cache* cache = make_cache(sets, lines, blocks);
  CPU*   cpu   = make_cpu(cache, file);

  run_cpu(cpu);

  delete_cpu(cpu);
  delete_cache(cache);
}
示例#3
0
int
dm_run(int argc, char *argv[])
{
	int c, error, err;
	int max_vcpus, mptgen;
	struct vmctx *ctx;
	size_t memsize;
	int option_idx = 0;

	progname = basename(argv[0]);
	guest_ncpus = 1;
	memsize = 256 * MB;
	mptgen = 1;

	if (signal(SIGHUP, sig_handler_term) == SIG_ERR)
		fprintf(stderr, "cannot register handler for SIGHUP\n");
	if (signal(SIGINT, sig_handler_term) == SIG_ERR)
		fprintf(stderr, "cannot register handler for SIGINT\n");

	while ((c = getopt_long(argc, argv, optstr, long_options,
			&option_idx)) != -1) {
		switch (c) {
		case 'A':
			acpi = 1;
			break;
		case 'p':
			if (pincpu_parse(optarg) != 0) {
				errx(EX_USAGE,
				"invalid vcpu pinning configuration '%s'",
				optarg);
			}
			break;
		case 'c':
			dm_strtoi(optarg, NULL, 0, &guest_ncpus);
			break;
		case 'E':
			if (acrn_parse_elf(optarg) != 0)
				exit(1);
			else
				break;
			break;
		case 'i':
			ioc_parse(optarg);
			break;

		case 'l':
			if (lpc_device_parse(optarg) != 0) {
				errx(EX_USAGE,
					"invalid lpc device configuration '%s'",
					optarg);
			}
			break;
		case 's':
			if (pci_parse_slot(optarg) != 0)
				exit(1);
			else
				break;
		case 'm':
			error = vm_parse_memsize(optarg, &memsize);
			if (error)
				errx(EX_USAGE, "invalid memsize '%s'", optarg);
			break;
		case 'U':
			guest_uuid_str = optarg;
			break;
		case 'W':
			virtio_msix = 0;
			break;
		case 'Y':
			mptgen = 0;
			break;
		case 'k':
			if (acrn_parse_kernel(optarg) != 0)
				exit(1);
			else
				break;
		case 'r':
			if (acrn_parse_ramdisk(optarg) != 0)
				exit(1);
			else
				break;
		case 'B':
			if (acrn_parse_bootargs(optarg) != 0)
				exit(1);
			else
				break;
			break;
		case 'G':
			if (acrn_parse_gvtargs(optarg) != 0) {
				errx(EX_USAGE, "invalid GVT param %s", optarg);
				exit(1);
			}
			break;
		case 'v':
			print_version();
			break;
		case CMD_OPT_VSBL:
			if (high_bios_size() == 0 && acrn_parse_vsbl(optarg) != 0) {
				errx(EX_USAGE, "invalid vsbl param %s", optarg);
				exit(1);
			}
			break;
		case CMD_OPT_OVMF:
			if (!vsbl_file_name && acrn_parse_ovmf(optarg) != 0) {
				errx(EX_USAGE, "invalid ovmf param %s", optarg);
				exit(1);
			}
			break;
		case CMD_OPT_PART_INFO:
			if (acrn_parse_guest_part_info(optarg) != 0) {
				errx(EX_USAGE,
					"invalid guest partition info param %s",
					optarg);
				exit(1);
			}
			break;
		case CMD_OPT_TRUSTY_ENABLE:
			trusty_enabled = 1;
			break;
		case CMD_OPT_VIRTIO_POLL_ENABLE:
			if (acrn_parse_virtio_poll_interval(optarg) != 0) {
				errx(EX_USAGE,
					"invalid virtio poll interval %s",
					optarg);
				exit(1);
			}
			break;
		case CMD_OPT_MAC_SEED:
			strncpy(mac_seed_str, optarg, sizeof(mac_seed_str));
			mac_seed_str[sizeof(mac_seed_str) - 1] = '\0';
			mac_seed = mac_seed_str;
			break;
		case CMD_OPT_PTDEV_NO_RESET:
			ptdev_no_reset(true);
			break;
		case CMD_OPT_DEBUGEXIT:
			debugexit_enabled = true;
			break;
		case CMD_OPT_LAPIC_PT:
			lapic_pt = true;
			break;
		case CMD_OPT_VTPM2:
			if (acrn_parse_vtpm2(optarg) != 0) {
				errx(EX_USAGE, "invalid vtpm2 param %s", optarg);
				exit(1);
			}
			break;
		case CMD_OPT_INTR_MONITOR:
			if (acrn_parse_intr_monitor(optarg) != 0) {
				errx(EX_USAGE, "invalid intr-monitor params %s", optarg);
				exit(1);
			}
			break;
		case 'h':
			usage(0);
		default:
			usage(1);
		}
	}
	argc -= optind;
	argv += optind;

	if (argc != 1)
		usage(1);

	if (!check_hugetlb_support()) {
		fprintf(stderr, "check_hugetlb_support failed\n");
		exit(1);
	}

	vmname = argv[0];

	for (;;) {
		ctx = vm_create(vmname, (unsigned long)vhm_req_buf);
		if (!ctx) {
			perror("vm_open");
			exit(1);
		}

		if (guest_ncpus < 1) {
			fprintf(stderr, "Invalid guest vCPUs (%d)\n",
				guest_ncpus);
			goto fail;
		}

		max_vcpus = num_vcpus_allowed(ctx);
		if (guest_ncpus > max_vcpus) {
			fprintf(stderr, "%d vCPUs requested but %d available\n",
				guest_ncpus, max_vcpus);
			goto fail;
		}

		err = vm_setup_memory(ctx, memsize);
		if (err) {
			fprintf(stderr, "Unable to setup memory (%d)\n", errno);
			goto fail;
		}

		err = mevent_init();
		if (err) {
			fprintf(stderr, "Unable to initialize mevent (%d)\n",
				errno);
			goto mevent_fail;
		}

		if (vm_init_vdevs(ctx) < 0) {
			fprintf(stderr, "Unable to init vdev (%d)\n", errno);
			goto dev_fail;
		}

		/*
		 * build the guest tables, MP etc.
		 */
		if (mptgen) {
			error = mptable_build(ctx, guest_ncpus);
			if (error) {
				goto vm_fail;
			}
		}

		error = smbios_build(ctx);
		if (error)
			goto vm_fail;

		if (acpi) {
			error = acpi_build(ctx, guest_ncpus);
			if (error)
				goto vm_fail;
		}

		error = acrn_sw_load(ctx);
		if (error)
			goto vm_fail;

		/*
		 * Change the proc title to include the VM name.
		 */
		/*setproctitle("%s", vmname);*/

		/*
		 * Add CPU 0
		 */
		error = add_cpu(ctx, guest_ncpus);
		if (error)
			goto vm_fail;

		/* Make a copy for ctx */
		_ctx = ctx;

		/*
		 * Head off to the main event dispatch loop
		 */
		mevent_dispatch();

		vm_pause(ctx);
		delete_cpu(ctx, BSP);

		if (vm_get_suspend_mode() != VM_SUSPEND_FULL_RESET)
			break;

		vm_deinit_vdevs(ctx);
		mevent_deinit();
		vm_unsetup_memory(ctx);
		vm_destroy(ctx);
		_ctx = 0;

		vm_set_suspend_mode(VM_SUSPEND_NONE);
	}

vm_fail:
	vm_deinit_vdevs(ctx);
dev_fail:
	mevent_deinit();
mevent_fail:
	vm_unsetup_memory(ctx);
fail:
	vm_destroy(ctx);
	exit(0);
}