qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PULL 03/16] test-aio-multithread: simplify test_multi_co_schedule
Date: Tue,  9 May 2023 11:04:40 +0200	[thread overview]
Message-ID: <20230509090453.37884-4-pbonzini@redhat.com> (raw)
In-Reply-To: <20230509090453.37884-1-pbonzini@redhat.com>

Instead of using qatomic_mb_{read,set} mindlessly, just use a per-coroutine
flag that requires no synchronization.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tests/unit/test-aio-multithread.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/tests/unit/test-aio-multithread.c b/tests/unit/test-aio-multithread.c
index 3c61526a0b46..80c5d4e2e6e3 100644
--- a/tests/unit/test-aio-multithread.c
+++ b/tests/unit/test-aio-multithread.c
@@ -107,8 +107,7 @@ static void test_lifecycle(void)
 /* aio_co_schedule test.  */
 
 static Coroutine *to_schedule[NUM_CONTEXTS];
-
-static bool now_stopping;
+static bool stop[NUM_CONTEXTS];
 
 static int count_retry;
 static int count_here;
@@ -136,6 +135,7 @@ static bool schedule_next(int n)
 
 static void finish_cb(void *opaque)
 {
+    stop[id] = true;
     schedule_next(id);
 }
 
@@ -143,13 +143,19 @@ static coroutine_fn void test_multi_co_schedule_entry(void *opaque)
 {
     g_assert(to_schedule[id] == NULL);
 
-    while (!qatomic_mb_read(&now_stopping)) {
+    /*
+     * The next iteration will set to_schedule[id] again, but once finish_cb
+     * is scheduled there is no guarantee that it will actually be woken up,
+     * so at that point it must not go to sleep.
+     */
+    while (!stop[id]) {
         int n;
 
         n = g_test_rand_int_range(0, NUM_CONTEXTS);
         schedule_next(n);
 
         qatomic_mb_set(&to_schedule[id], qemu_coroutine_self());
+        /* finish_cb can run here.  */
         qemu_coroutine_yield();
         g_assert(to_schedule[id] == NULL);
     }
@@ -161,7 +167,6 @@ static void test_multi_co_schedule(int seconds)
     int i;
 
     count_here = count_other = count_retry = 0;
-    now_stopping = false;
 
     create_aio_contexts();
     for (i = 0; i < NUM_CONTEXTS; i++) {
@@ -171,10 +176,10 @@ static void test_multi_co_schedule(int seconds)
 
     g_usleep(seconds * 1000000);
 
-    qatomic_mb_set(&now_stopping, true);
+    /* Guarantee that each AioContext is woken up from its last wait.  */
     for (i = 0; i < NUM_CONTEXTS; i++) {
         ctx_run(i, finish_cb, NULL);
-        to_schedule[i] = NULL;
+        g_assert(to_schedule[i] == NULL);
     }
 
     join_aio_contexts();
@@ -199,6 +204,7 @@ static uint32_t atomic_counter;
 static uint32_t running;
 static uint32_t counter;
 static CoMutex comutex;
+static bool now_stopping;
 
 static void coroutine_fn test_multi_co_mutex_entry(void *opaque)
 {
-- 
2.40.1



  parent reply	other threads:[~2023-05-09  9:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-09  9:04 [PULL 00/16] Misc patches for 2023-05-09 Paolo Bonzini
2023-05-09  9:04 ` [PULL 01/16] rcu: remove qatomic_mb_set, expand comments Paolo Bonzini
2023-05-09  9:04 ` [PULL 02/16] test-aio-multithread: do not use mb_read/mb_set for simple flags Paolo Bonzini
2023-05-09  9:04 ` Paolo Bonzini [this message]
2023-05-09  9:04 ` [PULL 04/16] call_rcu: stop using mb_set/mb_read Paolo Bonzini
2023-05-09  9:04 ` [PULL 05/16] tb-maint: do not use mb_read/mb_set Paolo Bonzini
2023-05-09  9:04 ` [PULL 06/16] MAINTAINERS: add stanza for Kconfig files Paolo Bonzini
2023-05-09  9:04 ` [PULL 07/16] include/qemu/osdep.h: Bump _WIN32_WINNT to the Windows 8 API Paolo Bonzini
2023-05-09  9:04 ` [PULL 08/16] target/i386: allow versioned CPUs to specify new cache_info Paolo Bonzini
2023-05-09  9:04 ` [PULL 09/16] target/i386: Add new EPYC CPU versions with updated cache_info Paolo Bonzini
2023-05-09  9:04 ` [PULL 10/16] target/i386: Add a couple of feature bits in 8000_0008_EBX Paolo Bonzini
2023-05-09  9:04 ` [PULL 11/16] target/i386: Add feature bits for CPUID_Fn80000021_EAX Paolo Bonzini
2023-05-09  9:04 ` [PULL 12/16] target/i386: Add missing feature bits in EPYC-Milan model Paolo Bonzini
2023-05-09  9:04 ` [PULL 13/16] target/i386: Add VNMI and automatic IBRS feature bits Paolo Bonzini
2023-05-09  9:04 ` [PULL 14/16] target/i386: Add EPYC-Genoa model to support Zen 4 processor series Paolo Bonzini
2023-05-09  9:04 ` [PULL 15/16] docs: clarify --without-default-devices Paolo Bonzini
2023-05-09  9:04 ` [PULL 16/16] meson: leave unnecessary modules out of the build Paolo Bonzini
2023-05-10  5:12 ` [PULL 00/16] Misc patches for 2023-05-09 Richard Henderson

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=20230509090453.37884-4-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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).