From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: [PATCH 22/22] Fix a few coding style violations in cpus.c Date: Thu, 27 Jan 2011 14:10:06 +0100 Message-ID: <7750bfca381d0fbb97c09e9fc8ba22f8c25249ae.1296133797.git.jan.kiszka@siemens.com> References: Cc: kvm@vger.kernel.org, qemu-devel@nongnu.org To: Avi Kivity , Marcelo Tosatti Return-path: Received: from goliath.siemens.de ([192.35.17.28]:20596 "EHLO goliath.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753166Ab1A0NK1 (ORCPT ); Thu, 27 Jan 2011 08:10:27 -0500 In-Reply-To: In-Reply-To: References: Sender: kvm-owner@vger.kernel.org List-ID: No functional changes. Signed-off-by: Jan Kiszka --- cpus.c | 97 ++++++++++++++++++++++++++++++++++++++------------------------- 1 files changed, 58 insertions(+), 39 deletions(-) diff --git a/cpus.c b/cpus.c index 559ec55..f4ec84e 100644 --- a/cpus.c +++ b/cpus.c @@ -138,25 +138,26 @@ static void do_vm_stop(int reason) static int cpu_can_run(CPUState *env) { - if (env->stop) + if (env->stop) { return 0; - if (env->stopped || !vm_running) + } + if (env->stopped || !vm_running) { return 0; + } return 1; } static int cpu_has_work(CPUState *env) { - if (env->stop) + if (env->stop || env->queued_work_first) { return 1; - if (env->queued_work_first) - return 1; - if (env->stopped || !vm_running) + } + if (env->stopped || !vm_running) { return 0; - if (!env->halted) - return 1; - if (qemu_cpu_has_work(env)) + } + if (!env->halted || qemu_cpu_has_work(env)) { return 1; + } return 0; } @@ -164,9 +165,11 @@ static int any_cpu_has_work(void) { CPUState *env; - for (env = first_cpu; env != NULL; env = env->next_cpu) - if (cpu_has_work(env)) + for (env = first_cpu; env != NULL; env = env->next_cpu) { + if (cpu_has_work(env)) { return 1; + } + } return 0; } @@ -232,9 +235,9 @@ static void qemu_event_increment(void) static const uint64_t val = 1; ssize_t ret; - if (io_thread_fd == -1) + if (io_thread_fd == -1) { return; - + } do { ret = write(io_thread_fd, &val, sizeof(val)); } while (ret < 0 && errno == EINTR); @@ -265,17 +268,17 @@ static int qemu_event_init(void) int fds[2]; err = qemu_eventfd(fds); - if (err == -1) + if (err == -1) { return -errno; - + } err = fcntl_setfl(fds[0], O_NONBLOCK); - if (err < 0) + if (err < 0) { goto fail; - + } err = fcntl_setfl(fds[1], O_NONBLOCK); - if (err < 0) + if (err < 0) { goto fail; - + } qemu_set_fd_handler2(fds[0], NULL, qemu_event_read, NULL, (void *)(unsigned long)fds[0]); @@ -528,7 +531,6 @@ void pause_all_vcpus(void) void qemu_cpu_kick(void *env) { - return; } void qemu_cpu_kick_self(void) @@ -636,13 +638,15 @@ int qemu_init_main_loop(void) blocked_signals = block_io_signals(); ret = qemu_signalfd_init(blocked_signals); - if (ret) + if (ret) { return ret; + } /* Note eventfd must be drained before signalfd handlers run */ ret = qemu_event_init(); - if (ret) + if (ret) { return ret; + } qemu_cond_init(&qemu_pause_cond); qemu_cond_init(&qemu_system_cond); @@ -672,10 +676,11 @@ void run_on_cpu(CPUState *env, void (*func)(void *data), void *data) wi.func = func; wi.data = data; - if (!env->queued_work_first) + if (!env->queued_work_first) { env->queued_work_first = &wi; - else + } else { env->queued_work_last->next = &wi; + } env->queued_work_last = &wi; wi.next = NULL; wi.done = false; @@ -693,8 +698,9 @@ static void flush_queued_work(CPUState *env) { struct qemu_work_item *wi; - if (!env->queued_work_first) + if (!env->queued_work_first) { return; + } while ((wi = env->queued_work_first)) { env->queued_work_first = wi->next; @@ -720,8 +726,9 @@ static void qemu_tcg_wait_io_event(void) { CPUState *env; - while (!any_cpu_has_work()) + while (!any_cpu_has_work()) { qemu_cond_timedwait(tcg_halt_cond, &qemu_global_mutex, 1000); + } qemu_mutex_unlock(&qemu_global_mutex); @@ -742,9 +749,9 @@ static void qemu_tcg_wait_io_event(void) static void qemu_kvm_wait_io_event(CPUState *env) { - while (!cpu_has_work(env)) + while (!cpu_has_work(env)) { qemu_cond_timedwait(env->halt_cond, &qemu_global_mutex, 1000); - + } qemu_kvm_eat_signals(env); qemu_wait_io_event_common(env); } @@ -772,12 +779,14 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) qemu_cond_signal(&qemu_cpu_cond); /* and wait for machine initialization */ - while (!qemu_system_ready) + while (!qemu_system_ready) { qemu_cond_timedwait(&qemu_system_cond, &qemu_global_mutex, 100); + } while (1) { - if (cpu_can_run(env)) + if (cpu_can_run(env)) { qemu_cpu_exec(env); + } qemu_kvm_wait_io_event(env); } @@ -793,13 +802,15 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) /* signal CPU creation */ qemu_mutex_lock(&qemu_global_mutex); - for (env = first_cpu; env != NULL; env = env->next_cpu) + for (env = first_cpu; env != NULL; env = env->next_cpu) { env->created = 1; + } qemu_cond_signal(&qemu_cpu_cond); /* and wait for machine initialization */ - while (!qemu_system_ready) + while (!qemu_system_ready) { qemu_cond_timedwait(&qemu_system_cond, &qemu_global_mutex, 100); + } while (1) { cpu_exec_all(); @@ -812,6 +823,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) void qemu_cpu_kick(void *_env) { CPUState *env = _env; + qemu_cond_broadcast(env->halt_cond); if (!env->thread_kicked) { qemu_thread_signal(env->thread, SIG_IPI); @@ -863,8 +875,9 @@ static int all_vcpus_paused(void) CPUState *penv = first_cpu; while (penv) { - if (!penv->stopped) + if (!penv->stopped) { return 0; + } penv = (CPUState *)penv->next_cpu; } @@ -906,14 +919,16 @@ void resume_all_vcpus(void) static void qemu_tcg_init_vcpu(void *_env) { CPUState *env = _env; + /* share a single thread for all cpus with TCG */ if (!tcg_cpu_thread) { env->thread = qemu_mallocz(sizeof(QemuThread)); env->halt_cond = qemu_mallocz(sizeof(QemuCond)); qemu_cond_init(env->halt_cond); qemu_thread_create(env->thread, qemu_tcg_cpu_thread_fn, env); - while (env->created == 0) + while (env->created == 0) { qemu_cond_timedwait(&qemu_cpu_cond, &qemu_global_mutex, 100); + } tcg_cpu_thread = env->thread; tcg_halt_cond = env->halt_cond; } else { @@ -928,8 +943,9 @@ static void qemu_kvm_start_vcpu(CPUState *env) env->halt_cond = qemu_mallocz(sizeof(QemuCond)); qemu_cond_init(env->halt_cond); qemu_thread_create(env->thread, qemu_kvm_cpu_thread_fn, env); - while (env->created == 0) + while (env->created == 0) { qemu_cond_timedwait(&qemu_cpu_cond, &qemu_global_mutex, 100); + } } void qemu_init_vcpu(void *_env) @@ -938,10 +954,11 @@ void qemu_init_vcpu(void *_env) env->nr_cores = smp_cores; env->nr_threads = smp_threads; - if (kvm_enabled()) + if (kvm_enabled()) { qemu_kvm_start_vcpu(env); - else + } else { qemu_tcg_init_vcpu(env); + } } void qemu_notify_event(void) @@ -1016,16 +1033,18 @@ bool cpu_exec_all(void) { int r; - if (next_cpu == NULL) + if (next_cpu == NULL) { next_cpu = first_cpu; + } for (; next_cpu != NULL && !exit_request; next_cpu = next_cpu->next_cpu) { CPUState *env = next_cpu; qemu_clock_enable(vm_clock, (env->singlestep_enabled & SSTEP_NOTIMER) == 0); - if (qemu_alarm_pending()) + if (qemu_alarm_pending()) { break; + } if (cpu_can_run(env)) { r = qemu_cpu_exec(env); if (kvm_enabled()) { -- 1.7.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=49498 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PiRcH-0001ZZ-4V for qemu-devel@nongnu.org; Thu, 27 Jan 2011 08:10:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PiRc7-0000lg-3s for qemu-devel@nongnu.org; Thu, 27 Jan 2011 08:10:24 -0500 Received: from goliath.siemens.de ([192.35.17.28]:20494) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PiRc6-0000jE-7t for qemu-devel@nongnu.org; Thu, 27 Jan 2011 08:10:14 -0500 From: Jan Kiszka Date: Thu, 27 Jan 2011 14:10:06 +0100 Message-Id: <7750bfca381d0fbb97c09e9fc8ba22f8c25249ae.1296133797.git.jan.kiszka@siemens.com> In-Reply-To: References: In-Reply-To: References: Subject: [Qemu-devel] [PATCH 22/22] Fix a few coding style violations in cpus.c List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org No functional changes. Signed-off-by: Jan Kiszka --- cpus.c | 97 ++++++++++++++++++++++++++++++++++++++------------------------- 1 files changed, 58 insertions(+), 39 deletions(-) diff --git a/cpus.c b/cpus.c index 559ec55..f4ec84e 100644 --- a/cpus.c +++ b/cpus.c @@ -138,25 +138,26 @@ static void do_vm_stop(int reason) static int cpu_can_run(CPUState *env) { - if (env->stop) + if (env->stop) { return 0; - if (env->stopped || !vm_running) + } + if (env->stopped || !vm_running) { return 0; + } return 1; } static int cpu_has_work(CPUState *env) { - if (env->stop) + if (env->stop || env->queued_work_first) { return 1; - if (env->queued_work_first) - return 1; - if (env->stopped || !vm_running) + } + if (env->stopped || !vm_running) { return 0; - if (!env->halted) - return 1; - if (qemu_cpu_has_work(env)) + } + if (!env->halted || qemu_cpu_has_work(env)) { return 1; + } return 0; } @@ -164,9 +165,11 @@ static int any_cpu_has_work(void) { CPUState *env; - for (env = first_cpu; env != NULL; env = env->next_cpu) - if (cpu_has_work(env)) + for (env = first_cpu; env != NULL; env = env->next_cpu) { + if (cpu_has_work(env)) { return 1; + } + } return 0; } @@ -232,9 +235,9 @@ static void qemu_event_increment(void) static const uint64_t val = 1; ssize_t ret; - if (io_thread_fd == -1) + if (io_thread_fd == -1) { return; - + } do { ret = write(io_thread_fd, &val, sizeof(val)); } while (ret < 0 && errno == EINTR); @@ -265,17 +268,17 @@ static int qemu_event_init(void) int fds[2]; err = qemu_eventfd(fds); - if (err == -1) + if (err == -1) { return -errno; - + } err = fcntl_setfl(fds[0], O_NONBLOCK); - if (err < 0) + if (err < 0) { goto fail; - + } err = fcntl_setfl(fds[1], O_NONBLOCK); - if (err < 0) + if (err < 0) { goto fail; - + } qemu_set_fd_handler2(fds[0], NULL, qemu_event_read, NULL, (void *)(unsigned long)fds[0]); @@ -528,7 +531,6 @@ void pause_all_vcpus(void) void qemu_cpu_kick(void *env) { - return; } void qemu_cpu_kick_self(void) @@ -636,13 +638,15 @@ int qemu_init_main_loop(void) blocked_signals = block_io_signals(); ret = qemu_signalfd_init(blocked_signals); - if (ret) + if (ret) { return ret; + } /* Note eventfd must be drained before signalfd handlers run */ ret = qemu_event_init(); - if (ret) + if (ret) { return ret; + } qemu_cond_init(&qemu_pause_cond); qemu_cond_init(&qemu_system_cond); @@ -672,10 +676,11 @@ void run_on_cpu(CPUState *env, void (*func)(void *data), void *data) wi.func = func; wi.data = data; - if (!env->queued_work_first) + if (!env->queued_work_first) { env->queued_work_first = &wi; - else + } else { env->queued_work_last->next = &wi; + } env->queued_work_last = &wi; wi.next = NULL; wi.done = false; @@ -693,8 +698,9 @@ static void flush_queued_work(CPUState *env) { struct qemu_work_item *wi; - if (!env->queued_work_first) + if (!env->queued_work_first) { return; + } while ((wi = env->queued_work_first)) { env->queued_work_first = wi->next; @@ -720,8 +726,9 @@ static void qemu_tcg_wait_io_event(void) { CPUState *env; - while (!any_cpu_has_work()) + while (!any_cpu_has_work()) { qemu_cond_timedwait(tcg_halt_cond, &qemu_global_mutex, 1000); + } qemu_mutex_unlock(&qemu_global_mutex); @@ -742,9 +749,9 @@ static void qemu_tcg_wait_io_event(void) static void qemu_kvm_wait_io_event(CPUState *env) { - while (!cpu_has_work(env)) + while (!cpu_has_work(env)) { qemu_cond_timedwait(env->halt_cond, &qemu_global_mutex, 1000); - + } qemu_kvm_eat_signals(env); qemu_wait_io_event_common(env); } @@ -772,12 +779,14 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) qemu_cond_signal(&qemu_cpu_cond); /* and wait for machine initialization */ - while (!qemu_system_ready) + while (!qemu_system_ready) { qemu_cond_timedwait(&qemu_system_cond, &qemu_global_mutex, 100); + } while (1) { - if (cpu_can_run(env)) + if (cpu_can_run(env)) { qemu_cpu_exec(env); + } qemu_kvm_wait_io_event(env); } @@ -793,13 +802,15 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) /* signal CPU creation */ qemu_mutex_lock(&qemu_global_mutex); - for (env = first_cpu; env != NULL; env = env->next_cpu) + for (env = first_cpu; env != NULL; env = env->next_cpu) { env->created = 1; + } qemu_cond_signal(&qemu_cpu_cond); /* and wait for machine initialization */ - while (!qemu_system_ready) + while (!qemu_system_ready) { qemu_cond_timedwait(&qemu_system_cond, &qemu_global_mutex, 100); + } while (1) { cpu_exec_all(); @@ -812,6 +823,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) void qemu_cpu_kick(void *_env) { CPUState *env = _env; + qemu_cond_broadcast(env->halt_cond); if (!env->thread_kicked) { qemu_thread_signal(env->thread, SIG_IPI); @@ -863,8 +875,9 @@ static int all_vcpus_paused(void) CPUState *penv = first_cpu; while (penv) { - if (!penv->stopped) + if (!penv->stopped) { return 0; + } penv = (CPUState *)penv->next_cpu; } @@ -906,14 +919,16 @@ void resume_all_vcpus(void) static void qemu_tcg_init_vcpu(void *_env) { CPUState *env = _env; + /* share a single thread for all cpus with TCG */ if (!tcg_cpu_thread) { env->thread = qemu_mallocz(sizeof(QemuThread)); env->halt_cond = qemu_mallocz(sizeof(QemuCond)); qemu_cond_init(env->halt_cond); qemu_thread_create(env->thread, qemu_tcg_cpu_thread_fn, env); - while (env->created == 0) + while (env->created == 0) { qemu_cond_timedwait(&qemu_cpu_cond, &qemu_global_mutex, 100); + } tcg_cpu_thread = env->thread; tcg_halt_cond = env->halt_cond; } else { @@ -928,8 +943,9 @@ static void qemu_kvm_start_vcpu(CPUState *env) env->halt_cond = qemu_mallocz(sizeof(QemuCond)); qemu_cond_init(env->halt_cond); qemu_thread_create(env->thread, qemu_kvm_cpu_thread_fn, env); - while (env->created == 0) + while (env->created == 0) { qemu_cond_timedwait(&qemu_cpu_cond, &qemu_global_mutex, 100); + } } void qemu_init_vcpu(void *_env) @@ -938,10 +954,11 @@ void qemu_init_vcpu(void *_env) env->nr_cores = smp_cores; env->nr_threads = smp_threads; - if (kvm_enabled()) + if (kvm_enabled()) { qemu_kvm_start_vcpu(env); - else + } else { qemu_tcg_init_vcpu(env); + } } void qemu_notify_event(void) @@ -1016,16 +1033,18 @@ bool cpu_exec_all(void) { int r; - if (next_cpu == NULL) + if (next_cpu == NULL) { next_cpu = first_cpu; + } for (; next_cpu != NULL && !exit_request; next_cpu = next_cpu->next_cpu) { CPUState *env = next_cpu; qemu_clock_enable(vm_clock, (env->singlestep_enabled & SSTEP_NOTIMER) == 0); - if (qemu_alarm_pending()) + if (qemu_alarm_pending()) { break; + } if (cpu_can_run(env)) { r = qemu_cpu_exec(env); if (kvm_enabled()) { -- 1.7.1