};
struct kvm *kvm__init(const char *kvm_dev, unsigned long ram_size);
+int kvm__max_cpus(struct kvm *self);
void kvm__init_ram(struct kvm *self);
void kvm__delete(struct kvm *self);
bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename,
int kvm_cmd_run(int argc, const char **argv, const char *prefix)
{
static char real_cmdline[2048];
+ unsigned int nr_online_cpus;
+ int max_cpus;
int exit_code = 0;
int i;
struct virtio_net_parameters net_params;
char *hi;
- unsigned int nr_online_cpus;
signal(SIGALRM, handle_sigalrm);
signal(SIGQUIT, handle_sigquit);
kvm = kvm__init(kvm_dev, ram_size);
+ max_cpus = kvm__max_cpus(kvm);
+
+ if (nrcpus > max_cpus) {
+ printf(" # Limit the number of CPUs to %d\n", max_cpus);
+ kvm->nrcpus = max_cpus;
+ }
+
kvm->nrcpus = nrcpus;
memset(real_cmdline, 0, sizeof(real_cmdline));
die_perror("KVM_SET_USER_MEMORY_REGION ioctl");
}
+int kvm__max_cpus(struct kvm *self)
+{
+ int ret;
+
+ ret = ioctl(self->sys_fd, KVM_CHECK_EXTENSION, KVM_CAP_NR_VCPUS);
+ if (ret < 0)
+ die_perror("KVM_CAP_NR_VCPUS");
+
+ return ret;
+}
+
struct kvm *kvm__init(const char *kvm_dev, unsigned long ram_size)
{
struct kvm_pit_config pit_config = { .flags = 0, };