struct drivelist drives = QTAILQ_HEAD_INITIALIZER(drives);
struct driveoptlist driveopts = QTAILQ_HEAD_INITIALIZER(driveopts);
enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
-static DisplayState *display_state;
DisplayType display_type = DT_DEFAULT;
const char* keyboard_layout = NULL;
ram_addr_t ram_size;
+const char *mem_path = NULL;
+#ifdef MAP_POPULATE
+int mem_prealloc = 0; /* force preallocation of physical target memory */
+#endif
int nb_nics;
NICInfo nd_table[MAX_NICS];
int vm_running;
static QEMUBootSetHandler *boot_set_handler;
static void *boot_set_opaque;
+#ifdef SIGRTMIN
+#define SIG_IPI (SIGRTMIN+4)
+#else
+#define SIG_IPI SIGUSR1
+#endif
+
static int default_serial = 1;
static int default_parallel = 1;
static int default_virtcon = 1;
}
}
+int64_t qemu_get_clock_ns(QEMUClock *clock)
+{
+ switch(clock->type) {
+ case QEMU_CLOCK_REALTIME:
+ return get_clock();
+ default:
+ case QEMU_CLOCK_VIRTUAL:
+ if (use_icount) {
+ return cpu_get_icount();
+ } else {
+ return cpu_get_clock();
+ }
+ case QEMU_CLOCK_HOST:
+ return get_clock_realtime();
+ }
+}
+
static void init_clocks(void)
{
init_get_clock();
return seconds - time(NULL);
}
+void rtc_change_mon_event(struct tm *tm)
+{
+ QObject *data;
+
+ data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
+ monitor_protocol_event(QEVENT_RTC_CHANGE, data);
+ qobject_decref(data);
+}
+
static void configure_rtc_date_offset(const char *startdate, int legacy)
{
time_t rtc_start_date;
fprintf(stderr,
"only 63 CPUs in NUMA mode supported.\n");
}
- value = (1 << (endvalue + 1)) - (1 << value);
+ value = (2ULL << endvalue) - (1ULL << value);
} else {
- value = 1 << value;
+ value = 1ULL << value;
}
}
node_cpumask[nodenr] = value;
{
const char *devname = qdict_get_str(qdict, "devname");
if (usb_device_add(devname, 1) < 0) {
- qemu_error("could not add USB device '%s'\n", devname);
+ error_report("could not add USB device '%s'", devname);
}
}
{
const char *devname = qdict_get_str(qdict, "devname");
if (usb_device_del(devname) < 0) {
- qemu_error("could not delete USB device '%s'\n", devname);
+ error_report("could not delete USB device '%s'", devname);
}
}
"Empty");
}
-/***********************************************************/
-/* register display */
-
-struct DisplayAllocator default_allocator = {
- defaultallocator_create_displaysurface,
- defaultallocator_resize_displaysurface,
- defaultallocator_free_displaysurface
-};
-
-void register_displaystate(DisplayState *ds)
-{
- DisplayState **s;
- s = &display_state;
- while (*s != NULL)
- s = &(*s)->next;
- ds->next = NULL;
- *s = ds;
-}
-
-DisplayState *get_displaystate(void)
-{
- return display_state;
-}
-
-DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *da)
-{
- if(ds->allocator == &default_allocator) ds->allocator = da;
- return ds->allocator;
-}
-
-/* dumb display */
-
-static void dumb_display_init(void)
-{
- DisplayState *ds = qemu_mallocz(sizeof(DisplayState));
- ds->allocator = &default_allocator;
- ds->surface = qemu_create_displaysurface(ds, 640, 480);
- register_displaystate(ds);
-}
-
/***********************************************************/
/* I/O handling */
}
bytes_transferred_last = bytes_transferred;
- bwidth = get_clock();
+ bwidth = qemu_get_clock_ns(rt_clock);
while (!qemu_file_rate_limit(f)) {
int ret;
break;
}
- bwidth = get_clock() - bwidth;
+ bwidth = qemu_get_clock_ns(rt_clock) - bwidth;
bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;
/* if we haven't transferred anything this round, force expected_time to a
qemu_mod_timer(nographic_timer, interval + qemu_get_clock(rt_clock));
}
+void cpu_synchronize_all_states(void)
+{
+ CPUState *cpu;
+
+ for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) {
+ cpu_synchronize_state(cpu);
+ }
+}
+
+void cpu_synchronize_all_post_reset(void)
+{
+ CPUState *cpu;
+
+ for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) {
+ cpu_synchronize_post_reset(cpu);
+ }
+}
+
+void cpu_synchronize_all_post_init(void)
+{
+ CPUState *cpu;
+
+ for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) {
+ cpu_synchronize_post_init(cpu);
+ }
+}
+
struct vm_change_state_entry {
VMChangeStateHandler *cb;
void *opaque;
vm_running = 0;
pause_all_vcpus();
vm_state_notify(0, reason);
+ monitor_protocol_event(QEVENT_STOP, NULL);
}
}
QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
re->func(re->opaque);
}
+ monitor_protocol_event(QEVENT_RESET, NULL);
+ cpu_synchronize_all_post_reset();
}
void qemu_system_reset_request(void)
static void qemu_event_increment(void)
{
- static const char byte = 0;
+ /* Write 8 bytes to be compatible with eventfd. */
+ static uint64_t val = 1;
ssize_t ret;
if (io_thread_fd == -1)
return;
- ret = write(io_thread_fd, &byte, sizeof(byte));
- if (ret < 0 && (errno != EINTR && errno != EAGAIN)) {
+ do {
+ ret = write(io_thread_fd, &val, sizeof(val));
+ } while (ret < 0 && errno == EINTR);
+
+ /* EAGAIN is fine, a read must be pending. */
+ if (ret < 0 && errno != EAGAIN) {
fprintf(stderr, "qemu_event_increment: write() filed: %s\n",
strerror(errno));
exit (1);
{
int fd = (unsigned long)opaque;
ssize_t len;
+ char buffer[512];
- /* Drain the notify pipe */
+ /* Drain the notify pipe. For eventfd, only 8 bytes will be read. */
do {
- char buffer[512];
len = read(fd, buffer, sizeof(buffer));
- } while ((len == -1 && errno == EINTR) || len > 0);
+ } while ((len == -1 && errno == EINTR) || len == sizeof(buffer));
}
static int qemu_event_init(void)
int err;
int fds[2];
- err = qemu_pipe(fds);
+ err = qemu_eventfd(fds);
if (err == -1)
return -errno;
static QemuCond qemu_system_cond;
static QemuCond qemu_pause_cond;
-static void block_io_signals(void);
+static void tcg_block_io_signals(void);
+static void kvm_block_io_signals(CPUState *env);
static void unblock_io_signals(void);
static int tcg_has_work(void);
+static int cpu_has_work(CPUState *env);
static int qemu_init_main_loop(void)
{
return 0;
}
+static void qemu_wait_io_event_common(CPUState *env)
+{
+ if (env->stop) {
+ env->stop = 0;
+ env->stopped = 1;
+ qemu_cond_signal(&qemu_pause_cond);
+ }
+}
+
static void qemu_wait_io_event(CPUState *env)
{
while (!tcg_has_work())
qemu_mutex_unlock(&qemu_fair_mutex);
qemu_mutex_lock(&qemu_global_mutex);
- if (env->stop) {
- env->stop = 0;
- env->stopped = 1;
- qemu_cond_signal(&qemu_pause_cond);
+ qemu_wait_io_event_common(env);
+}
+
+static void qemu_kvm_eat_signal(CPUState *env, int timeout)
+{
+ struct timespec ts;
+ int r, e;
+ siginfo_t siginfo;
+ sigset_t waitset;
+
+ ts.tv_sec = timeout / 1000;
+ ts.tv_nsec = (timeout % 1000) * 1000000;
+
+ sigemptyset(&waitset);
+ sigaddset(&waitset, SIG_IPI);
+
+ qemu_mutex_unlock(&qemu_global_mutex);
+ r = sigtimedwait(&waitset, &siginfo, &ts);
+ e = errno;
+ qemu_mutex_lock(&qemu_global_mutex);
+
+ if (r == -1 && !(e == EAGAIN || e == EINTR)) {
+ fprintf(stderr, "sigtimedwait: %s\n", strerror(e));
+ exit(1);
}
}
+static void qemu_kvm_wait_io_event(CPUState *env)
+{
+ while (!cpu_has_work(env))
+ qemu_cond_timedwait(env->halt_cond, &qemu_global_mutex, 1000);
+
+ qemu_kvm_eat_signal(env, 0);
+ qemu_wait_io_event_common(env);
+}
+
static int qemu_cpu_exec(CPUState *env);
static void *kvm_cpu_thread_fn(void *arg)
{
CPUState *env = arg;
- block_io_signals();
qemu_thread_self(env->thread);
if (kvm_enabled())
kvm_init_vcpu(env);
+ kvm_block_io_signals(env);
+
/* signal CPU creation */
qemu_mutex_lock(&qemu_global_mutex);
env->created = 1;
while (1) {
if (cpu_can_run(env))
qemu_cpu_exec(env);
- qemu_wait_io_event(env);
+ qemu_kvm_wait_io_event(env);
}
return NULL;
{
CPUState *env = arg;
- block_io_signals();
+ tcg_block_io_signals();
qemu_thread_self(env->thread);
/* signal CPU creation */
CPUState *env = _env;
qemu_cond_broadcast(env->halt_cond);
if (kvm_enabled())
- qemu_thread_signal(env->thread, SIGUSR1);
+ qemu_thread_signal(env->thread, SIG_IPI);
}
int qemu_cpu_self(void *_env)
cpu_exit(cpu_single_env);
}
-static void block_io_signals(void)
+static void tcg_block_io_signals(void)
{
sigset_t set;
struct sigaction sigact;
sigaddset(&set, SIGUSR2);
sigaddset(&set, SIGIO);
sigaddset(&set, SIGALRM);
+ sigaddset(&set, SIGCHLD);
pthread_sigmask(SIG_BLOCK, &set, NULL);
sigemptyset(&set);
- sigaddset(&set, SIGUSR1);
+ sigaddset(&set, SIG_IPI);
pthread_sigmask(SIG_UNBLOCK, &set, NULL);
memset(&sigact, 0, sizeof(sigact));
sigact.sa_handler = cpu_signal;
- sigaction(SIGUSR1, &sigact, NULL);
+ sigaction(SIG_IPI, &sigact, NULL);
+}
+
+static void dummy_signal(int sig)
+{
+}
+
+static void kvm_block_io_signals(CPUState *env)
+{
+ int r;
+ sigset_t set;
+ struct sigaction sigact;
+
+ sigemptyset(&set);
+ sigaddset(&set, SIGUSR2);
+ sigaddset(&set, SIGIO);
+ sigaddset(&set, SIGALRM);
+ sigaddset(&set, SIGCHLD);
+ sigaddset(&set, SIG_IPI);
+ pthread_sigmask(SIG_BLOCK, &set, NULL);
+
+ pthread_sigmask(SIG_BLOCK, NULL, &set);
+ sigdelset(&set, SIG_IPI);
+
+ memset(&sigact, 0, sizeof(sigact));
+ sigact.sa_handler = dummy_signal;
+ sigaction(SIG_IPI, &sigact, NULL);
+
+ r = kvm_set_signal_mask(env, &set);
+ if (r) {
+ fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(r));
+ exit(1);
+ }
}
static void unblock_io_signals(void)
pthread_sigmask(SIG_UNBLOCK, &set, NULL);
sigemptyset(&set);
- sigaddset(&set, SIGUSR1);
+ sigaddset(&set, SIG_IPI);
pthread_sigmask(SIG_BLOCK, &set, NULL);
}
qemu_mutex_lock(&qemu_fair_mutex);
while (qemu_mutex_trylock(&qemu_global_mutex)) {
- qemu_thread_signal(tcg_cpu_thread, SIGUSR1);
+ qemu_thread_signal(tcg_cpu_thread, SIG_IPI);
if (!qemu_mutex_timedlock(&qemu_global_mutex, msecs))
break;
}
while (penv) {
penv->stop = 1;
- qemu_thread_signal(penv->thread, SIGUSR1);
+ qemu_thread_signal(penv->thread, SIG_IPI);
qemu_cpu_kick(penv);
penv = (CPUState *)penv->next_cpu;
}
qemu_cond_timedwait(&qemu_pause_cond, &qemu_global_mutex, 100);
penv = first_cpu;
while (penv) {
- qemu_thread_signal(penv->thread, SIGUSR1);
+ qemu_thread_signal(penv->thread, SIG_IPI);
penv = (CPUState *)penv->next_cpu;
}
}
while (penv) {
penv->stop = 0;
penv->stopped = 0;
- qemu_thread_signal(penv->thread, SIGUSR1);
+ qemu_thread_signal(penv->thread, SIG_IPI);
qemu_cpu_kick(penv);
penv = (CPUState *)penv->next_cpu;
}
for (; next_cpu != NULL; next_cpu = next_cpu->next_cpu) {
CPUState *env = cur_cpu = next_cpu;
- if (!vm_running)
- break;
if (timer_alarm_pending) {
timer_alarm_pending = 0;
break;
}
if (cpu_can_run(env))
ret = qemu_cpu_exec(env);
+ else if (env->stop)
+ break;
+
if (ret == EXCP_DEBUG) {
gdb_set_stop_cpu(env);
debug_requested = 1;
} while (vm_can_run());
if (qemu_debug_requested()) {
- monitor_protocol_event(QEVENT_DEBUG, NULL);
vm_stop(EXCP_DEBUG);
}
if (qemu_shutdown_requested()) {
break;
}
if (qemu_reset_requested()) {
- monitor_protocol_event(QEVENT_RESET, NULL);
pause_all_vcpus();
qemu_system_reset();
resume_all_vcpus();
qemu_irq_raise(qemu_system_powerdown);
}
if ((r = qemu_vmstop_requested())) {
- monitor_protocol_event(QEVENT_STOP, NULL);
vm_stop(r);
}
}
static void help(int exitcode)
{
- version();
- printf("usage: %s [options] [disk_image]\n"
- "\n"
- "'disk_image' is a raw hard image image for IDE hard disk 0\n"
- "\n"
+ const char *options_help =
#define DEF(option, opt_arg, opt_enum, opt_help) \
opt_help
#define DEFHEADING(text) stringify(text) "\n"
#undef DEF
#undef DEFHEADING
#undef GEN_DOCS
+ ;
+ version();
+ printf("usage: %s [options] [disk_image]\n"
+ "\n"
+ "'disk_image' is a raw hard image image for IDE hard disk 0\n"
"\n"
+ "%s\n"
"During emulation, the following keys are useful:\n"
"ctrl-alt-f toggle full screen\n"
"ctrl-alt-n switch to virtual console 'n'\n"
"ctrl-alt toggle mouse and keyboard grab\n"
"\n"
- "When using -nographic, press 'ctrl-a h' to get some help.\n"
- ,
+ "When using -nographic, press 'ctrl-a h' to get some help.\n",
"qemu",
- DEFAULT_RAM_SIZE,
-#ifndef _WIN32
- DEFAULT_NETWORK_SCRIPT,
- DEFAULT_NETWORK_DOWN_SCRIPT,
-#endif
- DEFAULT_GDBSTUB_PORT,
- "/tmp/qemu.log");
+ options_help);
exit(exitcode);
}
int show_vnc_port = 0;
int defconfig = 1;
+ error_set_progname(argv[0]);
+
init_clocks();
- qemu_errors_to_file(stderr);
qemu_cache_utils_init(envp);
QLIST_INIT (&vm_change_state_head);
fclose(fp);
}
}
+#if defined(cpudef_setup)
+ cpudef_setup(); /* parse cpu definitions in target config file */
+#endif
/* second pass of option parsing */
optind = 1;
/* hw initialization will check this */
if (*optarg == '?') {
/* XXX: implement xxx_cpu_list for targets that still miss it */
-#if defined(cpu_list)
- cpu_list(stdout, &fprintf);
+#if defined(cpu_list_id)
+ cpu_list_id(stdout, &fprintf, optarg);
+#elif defined(cpu_list)
+ cpu_list(stdout, &fprintf); /* deprecated */
#endif
exit(0);
} else {
ram_size = value;
break;
}
+ case QEMU_OPTION_mempath:
+ mem_path = optarg;
+ break;
+#ifdef MAP_POPULATE
+ case QEMU_OPTION_mem_prealloc:
+ mem_prealloc = 1;
+ break;
+#endif
case QEMU_OPTION_d:
{
int mask;
machine->init(ram_size, boot_devices,
kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
+ cpu_synchronize_all_post_init();
#ifndef _WIN32
/* must be after terminal init, SDL library changes signal handlers */
if (qemu_opts_foreach(&qemu_device_opts, device_init_func, NULL, 1) != 0)
exit(1);
- if (!display_state)
- dumb_display_init();
+ net_check_clients();
+
/* just use the first displaystate for the moment */
- ds = display_state;
+ ds = get_displaystate();
if (display_type == DT_DEFAULT) {
#if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock));
}
- text_consoles_set_display(display_state);
+ text_consoles_set_display(ds);
if (qemu_opts_foreach(&qemu_mon_opts, mon_init_func, NULL, 1) != 0)
exit(1);
qemu_system_reset();
if (loadvm) {
- if (load_vmstate(cur_mon, loadvm) < 0) {
+ if (load_vmstate(loadvm) < 0) {
autostart = 0;
}
}