qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@web.de>
To: Avi Kivity <avi@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org
Subject: [Qemu-devel] [PATCH v2 24/24] Fix a few coding style violations in cpus.c
Date: Tue,  1 Feb 2011 22:16:04 +0100	[thread overview]
Message-ID: <5e37ebb378a0fd46ea65681e37825ed1ed39c036.1296594961.git.jan.kiszka@web.de> (raw)
In-Reply-To: <cover.1296594961.git.jan.kiszka@web.de>
In-Reply-To: <cover.1296594961.git.jan.kiszka@web.de>

From: Jan Kiszka <jan.kiszka@siemens.com>

No functional changes.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 cpus.c |   97 ++++++++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 58 insertions(+), 39 deletions(-)

diff --git a/cpus.c b/cpus.c
index 0d11a20..dd24fe8 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]);
 
@@ -534,7 +537,6 @@ void pause_all_vcpus(void)
 
 void qemu_cpu_kick(void *env)
 {
-    return;
 }
 
 void qemu_cpu_kick_self(void)
@@ -663,13 +665,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);
@@ -699,10 +703,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;
@@ -720,8 +725,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;
@@ -747,8 +753,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);
 
@@ -769,9 +776,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);
 }
@@ -799,12 +806,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);
     }
 
@@ -820,13 +829,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();
@@ -839,6 +850,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);
@@ -890,8 +902,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;
     }
 
@@ -933,14 +946,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 {
@@ -955,8 +970,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)
@@ -965,10 +981,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)
@@ -1043,16 +1060,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

  parent reply	other threads:[~2011-02-01 21:24 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-01 21:15 [Qemu-devel] [PATCH v2 00/24] [uq/master] Patch queue, part II Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 01/24] kvm: x86: Fix build in absence of KVM_CAP_ASYNC_PF Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 02/24] Prevent abortion on multiple VCPU kicks Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 03/24] Stop current VCPU on synchronous reset requests Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 04/24] Process vmstop requests in IO thread Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 05/24] Trigger exit from cpu_exec_all on pending IO events Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 06/24] Leave inner main_loop faster on pending requests Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 07/24] Flatten the main loop Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 08/24] kvm: Report proper error on GET_VCPU_MMAP_SIZE failures Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 09/24] kvm: Drop redundant kvm_enabled from kvm_cpu_thread_fn Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 10/24] kvm: Handle kvm_init_vcpu errors Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 11/24] kvm: Provide sigbus services arch-independently Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 12/24] Refactor signal setup functions in cpus.c Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 13/24] kvm: Set up signal mask also for !CONFIG_IOTHREAD Jan Kiszka
2011-02-28 15:55   ` [Qemu-devel] " Avi Kivity
2011-02-28 16:02     ` Jan Kiszka
2011-02-28 16:05       ` Jan Kiszka
2011-02-28 16:16     ` Jan Kiszka
2011-02-28 16:45       ` Avi Kivity
2011-02-28 16:48         ` Avi Kivity
2011-02-28 16:49         ` Jan Kiszka
2011-02-28 16:54           ` Avi Kivity
2011-03-01  8:39             ` Avi Kivity
2011-03-01  8:58               ` Jan Kiszka
2011-03-01  9:03                 ` Avi Kivity
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 14/24] kvm: Refactor qemu_kvm_eat_signals Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 15/24] kvm: Call qemu_kvm_eat_signals also under !CONFIG_IOTHREAD Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 16/24] Set up signalfd " Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 17/24] kvm: Fix race between timer signals and vcpu entry under !IOTHREAD Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 18/24] kvm: Add MCE signal support for !CONFIG_IOTHREAD Jan Kiszka
2011-02-01 21:15 ` [Qemu-devel] [PATCH v2 19/24] Introduce VCPU self-signaling service Jan Kiszka
2011-02-01 21:16 ` [Qemu-devel] [PATCH v2 20/24] kvm: Unconditionally reenter kernel after IO exits Jan Kiszka
2011-02-01 21:16 ` [Qemu-devel] [PATCH v2 21/24] kvm: Remove static return code of kvm_handle_io Jan Kiszka
2011-02-01 21:16 ` [Qemu-devel] [PATCH v2 22/24] kvm: Leave kvm_cpu_exec directly after KVM_EXIT_SHUTDOWN Jan Kiszka
2011-02-01 21:16 ` [Qemu-devel] [PATCH v2 23/24] Refactor kvm&tcg function names in cpus.c Jan Kiszka
2011-02-01 21:16 ` Jan Kiszka [this message]
2011-02-04 13:54 ` [Qemu-devel] Re: [PATCH v2 00/24] [uq/master] Patch queue, part II Marcelo Tosatti
2011-02-04 16:29   ` Jan Kiszka
2011-02-04 16:37     ` Marcelo Tosatti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5e37ebb378a0fd46ea65681e37825ed1ed39c036.1296594961.git.jan.kiszka@web.de \
    --to=jan.kiszka@web.de \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).