1 | The following changes since commit 6c769690ac845fa62642a5f93b4e4bd906adab95: | 1 | The following changes since commit 9af638cc1f665712522608c5d6b8c03d8fa67666: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/vsementsov/tags/pull-simplebench-2021-05-04' into staging (2021-05-21 12:02:34 +0100) | 3 | Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20200504' into staging (2020-05-04 13:37:17 +0100) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://gitlab.com/stefanha/qemu.git tags/block-pull-request | 7 | https://github.com/stefanha/qemu.git tags/block-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to 0a6f0c76a030710780ce10d6347a70f098024d21: | 9 | for you to fetch changes up to 08b689aa6b521964b8275dd7a2564aefa5d68129: |
10 | 10 | ||
11 | coroutine-sleep: introduce qemu_co_sleep (2021-05-21 18:22:33 +0100) | 11 | lockable: Replace locks with lock guard macros (2020-05-04 16:07:43 +0100) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Pull request | 14 | Pull request |
15 | 15 | ||
16 | (Resent due to an email preparation mistake.) | 16 | v2: |
17 | * Fixed stray slirp submodule change [Peter] | ||
18 | |||
19 | Fixes for the lock guard macros, code conversions to the lock guard macros, and | ||
20 | support for selecting fuzzer targets with argv[0]. | ||
17 | 21 | ||
18 | ---------------------------------------------------------------- | 22 | ---------------------------------------------------------------- |
19 | 23 | ||
20 | Paolo Bonzini (6): | 24 | Alexander Bulekov (1): |
21 | coroutine-sleep: use a stack-allocated timer | 25 | fuzz: select fuzz target using executable name |
22 | coroutine-sleep: disallow NULL QemuCoSleepState** argument | ||
23 | coroutine-sleep: allow qemu_co_sleep_wake that wakes nothing | ||
24 | coroutine-sleep: move timer out of QemuCoSleepState | ||
25 | coroutine-sleep: replace QemuCoSleepState pointer with struct in the | ||
26 | API | ||
27 | coroutine-sleep: introduce qemu_co_sleep | ||
28 | 26 | ||
29 | Philippe Mathieu-Daudé (1): | 27 | Daniel Brodsky (2): |
30 | bitops.h: Improve find_xxx_bit() documentation | 28 | lockable: fix __COUNTER__ macro to be referenced properly |
29 | lockable: replaced locks with lock guard macros where appropriate | ||
31 | 30 | ||
32 | Zenghui Yu (1): | 31 | Simran Singhal (1): |
33 | multi-process: Initialize variables declared with g_auto* | 32 | lockable: Replace locks with lock guard macros |
34 | 33 | ||
35 | include/qemu/bitops.h | 15 ++++++-- | 34 | include/qemu/lockable.h | 7 +++--- |
36 | include/qemu/coroutine.h | 27 ++++++++----- | 35 | include/qemu/rcu.h | 2 +- |
37 | block/block-copy.c | 10 ++--- | 36 | block/iscsi.c | 7 ++---- |
38 | block/nbd.c | 14 +++---- | 37 | block/nfs.c | 51 +++++++++++++++++++---------------------- |
39 | hw/remote/memory.c | 5 +-- | 38 | cpus-common.c | 14 ++++------- |
40 | hw/remote/proxy.c | 3 +- | 39 | hw/display/qxl.c | 43 ++++++++++++++++------------------ |
41 | util/qemu-coroutine-sleep.c | 75 +++++++++++++++++++------------------ | 40 | hw/hyperv/hyperv.c | 15 ++++++------ |
42 | 7 files changed, 79 insertions(+), 70 deletions(-) | 41 | hw/rdma/rdma_backend.c | 50 ++++++++++++++++++++-------------------- |
42 | hw/rdma/rdma_rm.c | 3 +-- | ||
43 | hw/vfio/platform.c | 5 ++-- | ||
44 | migration/migration.c | 3 +-- | ||
45 | migration/multifd.c | 8 +++---- | ||
46 | migration/ram.c | 3 +-- | ||
47 | monitor/misc.c | 4 +--- | ||
48 | tests/qtest/fuzz/fuzz.c | 19 ++++++++------- | ||
49 | ui/spice-display.c | 14 +++++------ | ||
50 | util/log.c | 4 ++-- | ||
51 | util/qemu-timer.c | 17 +++++++------- | ||
52 | util/rcu.c | 8 +++---- | ||
53 | util/thread-pool.c | 3 +-- | ||
54 | util/vfio-helpers.c | 5 ++-- | ||
55 | 21 files changed, 132 insertions(+), 153 deletions(-) | ||
43 | 56 | ||
44 | -- | 57 | -- |
45 | 2.31.1 | 58 | 2.25.3 |
46 | 59 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Zenghui Yu <yuzenghui@huawei.com> | ||
2 | 1 | ||
3 | Quote docs/devel/style.rst (section "Automatic memory deallocation"): | ||
4 | |||
5 | * Variables declared with g_auto* MUST always be initialized, | ||
6 | otherwise the cleanup function will use uninitialized stack memory | ||
7 | |||
8 | Initialize @name properly to get rid of the compilation error (using | ||
9 | gcc-7.3.0 on CentOS): | ||
10 | |||
11 | ../hw/remote/proxy.c: In function 'pci_proxy_dev_realize': | ||
12 | /usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: 'name' may be used uninitialized in this function [-Werror=maybe-uninitialized] | ||
13 | g_free (*pp); | ||
14 | ^~~~~~~~~~~~ | ||
15 | ../hw/remote/proxy.c:350:30: note: 'name' was declared here | ||
16 | g_autofree char *name; | ||
17 | ^~~~ | ||
18 | |||
19 | Signed-off-by: Zenghui Yu <yuzenghui@huawei.com> | ||
20 | Reviewed-by: Jagannathan Raman <jag.raman@oracle.com> | ||
21 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
22 | Reviewed-by: Miroslav Rezanina <mrezanin@redhat.com> | ||
23 | Message-id: 20210312112143.1369-1-yuzenghui@huawei.com | ||
24 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
25 | --- | ||
26 | hw/remote/memory.c | 5 ++--- | ||
27 | hw/remote/proxy.c | 3 +-- | ||
28 | 2 files changed, 3 insertions(+), 5 deletions(-) | ||
29 | |||
30 | diff --git a/hw/remote/memory.c b/hw/remote/memory.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/hw/remote/memory.c | ||
33 | +++ b/hw/remote/memory.c | ||
34 | @@ -XXX,XX +XXX,XX @@ void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp) | ||
35 | |||
36 | remote_sysmem_reset(); | ||
37 | |||
38 | - for (region = 0; region < msg->num_fds; region++) { | ||
39 | - g_autofree char *name; | ||
40 | + for (region = 0; region < msg->num_fds; region++, suffix++) { | ||
41 | + g_autofree char *name = g_strdup_printf("remote-mem-%u", suffix); | ||
42 | subregion = g_new(MemoryRegion, 1); | ||
43 | - name = g_strdup_printf("remote-mem-%u", suffix++); | ||
44 | memory_region_init_ram_from_fd(subregion, NULL, | ||
45 | name, sysmem_info->sizes[region], | ||
46 | true, msg->fds[region], | ||
47 | diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/hw/remote/proxy.c | ||
50 | +++ b/hw/remote/proxy.c | ||
51 | @@ -XXX,XX +XXX,XX @@ static void probe_pci_info(PCIDevice *dev, Error **errp) | ||
52 | PCI_BASE_ADDRESS_SPACE_IO : PCI_BASE_ADDRESS_SPACE_MEMORY; | ||
53 | |||
54 | if (size) { | ||
55 | - g_autofree char *name; | ||
56 | + g_autofree char *name = g_strdup_printf("bar-region-%d", i); | ||
57 | pdev->region[i].dev = pdev; | ||
58 | pdev->region[i].present = true; | ||
59 | if (type == PCI_BASE_ADDRESS_SPACE_MEMORY) { | ||
60 | pdev->region[i].memory = true; | ||
61 | } | ||
62 | - name = g_strdup_printf("bar-region-%d", i); | ||
63 | memory_region_init_io(&pdev->region[i].mr, OBJECT(pdev), | ||
64 | &proxy_mr_ops, &pdev->region[i], | ||
65 | name, size); | ||
66 | -- | ||
67 | 2.31.1 | ||
68 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
2 | 1 | ||
3 | Document the following functions return the bitmap size | ||
4 | if no matching bit is found: | ||
5 | |||
6 | - find_first_bit | ||
7 | - find_next_bit | ||
8 | - find_last_bit | ||
9 | - find_first_zero_bit | ||
10 | - find_next_zero_bit | ||
11 | |||
12 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
13 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
14 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
15 | Message-id: 20210510200758.2623154-2-philmd@redhat.com | ||
16 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
17 | --- | ||
18 | include/qemu/bitops.h | 15 ++++++++++++--- | ||
19 | 1 file changed, 12 insertions(+), 3 deletions(-) | ||
20 | |||
21 | diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/include/qemu/bitops.h | ||
24 | +++ b/include/qemu/bitops.h | ||
25 | @@ -XXX,XX +XXX,XX @@ static inline int test_bit(long nr, const unsigned long *addr) | ||
26 | * @addr: The address to start the search at | ||
27 | * @size: The maximum size to search | ||
28 | * | ||
29 | - * Returns the bit number of the first set bit, or size. | ||
30 | + * Returns the bit number of the last set bit, | ||
31 | + * or @size if there is no set bit in the bitmap. | ||
32 | */ | ||
33 | unsigned long find_last_bit(const unsigned long *addr, | ||
34 | unsigned long size); | ||
35 | @@ -XXX,XX +XXX,XX @@ unsigned long find_last_bit(const unsigned long *addr, | ||
36 | * @addr: The address to base the search on | ||
37 | * @offset: The bitnumber to start searching at | ||
38 | * @size: The bitmap size in bits | ||
39 | + * | ||
40 | + * Returns the bit number of the next set bit, | ||
41 | + * or @size if there are no further set bits in the bitmap. | ||
42 | */ | ||
43 | unsigned long find_next_bit(const unsigned long *addr, | ||
44 | unsigned long size, | ||
45 | @@ -XXX,XX +XXX,XX @@ unsigned long find_next_bit(const unsigned long *addr, | ||
46 | * @addr: The address to base the search on | ||
47 | * @offset: The bitnumber to start searching at | ||
48 | * @size: The bitmap size in bits | ||
49 | + * | ||
50 | + * Returns the bit number of the next cleared bit, | ||
51 | + * or @size if there are no further clear bits in the bitmap. | ||
52 | */ | ||
53 | |||
54 | unsigned long find_next_zero_bit(const unsigned long *addr, | ||
55 | @@ -XXX,XX +XXX,XX @@ unsigned long find_next_zero_bit(const unsigned long *addr, | ||
56 | * @addr: The address to start the search at | ||
57 | * @size: The maximum size to search | ||
58 | * | ||
59 | - * Returns the bit number of the first set bit. | ||
60 | + * Returns the bit number of the first set bit, | ||
61 | + * or @size if there is no set bit in the bitmap. | ||
62 | */ | ||
63 | static inline unsigned long find_first_bit(const unsigned long *addr, | ||
64 | unsigned long size) | ||
65 | @@ -XXX,XX +XXX,XX @@ static inline unsigned long find_first_bit(const unsigned long *addr, | ||
66 | * @addr: The address to start the search at | ||
67 | * @size: The maximum size to search | ||
68 | * | ||
69 | - * Returns the bit number of the first cleared bit. | ||
70 | + * Returns the bit number of the first cleared bit, | ||
71 | + * or @size if there is no clear bit in the bitmap. | ||
72 | */ | ||
73 | static inline unsigned long find_first_zero_bit(const unsigned long *addr, | ||
74 | unsigned long size) | ||
75 | -- | ||
76 | 2.31.1 | ||
77 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Alexander Bulekov <alxndr@bu.edu> |
---|---|---|---|
2 | 2 | ||
3 | Allow using QemuCoSleep to sleep forever until woken by qemu_co_sleep_wake. | 3 | The fuzzers are built into a binary (e.g. qemu-fuzz-i386). To select the |
4 | This makes the logic of qemu_co_sleep_ns_wakeable easy to understand. | 4 | device to fuzz/fuzz target, we usually use the --fuzz-target= argument. |
5 | This commit allows the fuzz-target to be specified using the name of the | ||
6 | executable. If the executable name ends with -target-FUZZ_TARGET, then | ||
7 | we select the fuzz target based on this name, rather than the | ||
8 | --fuzz-target argument. This is useful for systems such as oss-fuzz | ||
9 | where we don't have control of the arguments passed to the fuzzer. | ||
5 | 10 | ||
6 | In the future we will introduce an API that can work even if the | 11 | [Fixed incorrect indentation. |
7 | sleep and wake happen from different threads. For now, initializing | 12 | --Stefan] |
8 | w->to_wake after timer_mod is fine because the timer can only fire in | ||
9 | the same AioContext. | ||
10 | 13 | ||
11 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 14 | Signed-off-by: Alexander Bulekov <alxndr@bu.edu> |
12 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | 15 | Reviewed-by: Darren Kenny <darren.kenny@oracle.com> |
13 | Message-id: 20210517100548.28806-7-pbonzini@redhat.com | 16 | Message-id: 20200421182230.6313-1-alxndr@bu.edu |
14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 17 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
15 | --- | 18 | --- |
16 | include/qemu/coroutine.h | 5 +++++ | 19 | tests/qtest/fuzz/fuzz.c | 19 +++++++++++-------- |
17 | util/qemu-coroutine-sleep.c | 26 +++++++++++++++++++------- | 20 | 1 file changed, 11 insertions(+), 8 deletions(-) |
18 | 2 files changed, 24 insertions(+), 7 deletions(-) | ||
19 | 21 | ||
20 | diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h | 22 | diff --git a/tests/qtest/fuzz/fuzz.c b/tests/qtest/fuzz/fuzz.c |
21 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/include/qemu/coroutine.h | 24 | --- a/tests/qtest/fuzz/fuzz.c |
23 | +++ b/include/qemu/coroutine.h | 25 | +++ b/tests/qtest/fuzz/fuzz.c |
24 | @@ -XXX,XX +XXX,XX @@ typedef struct QemuCoSleep { | 26 | @@ -XXX,XX +XXX,XX @@ static void usage(char *path) |
25 | void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, | 27 | printf(" * %s : %s\n", tmp->target->name, |
26 | QEMUClockType type, int64_t ns); | 28 | tmp->target->description); |
27 | 29 | } | |
28 | +/** | 30 | + printf("Alternatively, add -target-FUZZ_TARGET to the executable name\n"); |
29 | + * Yield the coroutine until the next call to qemu_co_sleep_wake. | 31 | exit(0); |
30 | + */ | ||
31 | +void coroutine_fn qemu_co_sleep(QemuCoSleep *w); | ||
32 | + | ||
33 | static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns) | ||
34 | { | ||
35 | QemuCoSleep w = { 0 }; | ||
36 | diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/util/qemu-coroutine-sleep.c | ||
39 | +++ b/util/qemu-coroutine-sleep.c | ||
40 | @@ -XXX,XX +XXX,XX @@ static void co_sleep_cb(void *opaque) | ||
41 | qemu_co_sleep_wake(w); | ||
42 | } | 32 | } |
43 | 33 | ||
44 | -void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, | 34 | @@ -XXX,XX +XXX,XX @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp) |
45 | - QEMUClockType type, int64_t ns) | 35 | module_call_init(MODULE_INIT_QOM); |
46 | +void coroutine_fn qemu_co_sleep(QemuCoSleep *w) | 36 | module_call_init(MODULE_INIT_LIBQOS); |
47 | { | 37 | |
48 | Coroutine *co = qemu_coroutine_self(); | 38 | - if (*argc <= 1) { |
49 | - AioContext *ctx = qemu_get_current_aio_context(); | 39 | + target_name = strstr(**argv, "-target-"); |
50 | - QEMUTimer ts; | 40 | + if (target_name) { /* The binary name specifies the target */ |
51 | 41 | + target_name += strlen("-target-"); | |
52 | const char *scheduled = qatomic_cmpxchg(&co->scheduled, NULL, | 42 | + } else if (*argc > 1) { /* The target is specified as an argument */ |
53 | qemu_co_sleep_ns__scheduled); | 43 | + target_name = (*argv)[1]; |
54 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, | 44 | + if (!strstr(target_name, "--fuzz-target=")) { |
45 | + usage(**argv); | ||
46 | + } | ||
47 | + target_name += strlen("--fuzz-target="); | ||
48 | + } else { | ||
49 | usage(**argv); | ||
55 | } | 50 | } |
56 | 51 | ||
57 | w->to_wake = co; | 52 | /* Identify the fuzz target */ |
58 | - aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w), | 53 | - target_name = (*argv)[1]; |
59 | - timer_mod(&ts, qemu_clock_get_ns(type) + ns); | 54 | - if (!strstr(target_name, "--fuzz-target=")) { |
60 | qemu_coroutine_yield(); | 55 | - usage(**argv); |
61 | - timer_del(&ts); | 56 | - } |
62 | 57 | - | |
63 | /* w->to_wake is cleared before resuming this coroutine. */ | 58 | - target_name += strlen("--fuzz-target="); |
64 | assert(w->to_wake == NULL); | 59 | - |
65 | } | 60 | fuzz_target = fuzz_get_target(target_name); |
66 | + | 61 | if (!fuzz_target) { |
67 | +void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, | 62 | usage(**argv); |
68 | + QEMUClockType type, int64_t ns) | ||
69 | +{ | ||
70 | + AioContext *ctx = qemu_get_current_aio_context(); | ||
71 | + QEMUTimer ts; | ||
72 | + | ||
73 | + aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w); | ||
74 | + timer_mod(&ts, qemu_clock_get_ns(type) + ns); | ||
75 | + | ||
76 | + /* | ||
77 | + * The timer will fire in the current AiOContext, so the callback | ||
78 | + * must happen after qemu_co_sleep yields and there is no race | ||
79 | + * between timer_mod and qemu_co_sleep. | ||
80 | + */ | ||
81 | + qemu_co_sleep(w); | ||
82 | + timer_del(&ts); | ||
83 | +} | ||
84 | -- | 63 | -- |
85 | 2.31.1 | 64 | 2.25.3 |
86 | 65 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Daniel Brodsky <dnbrdsky@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Right now, users of qemu_co_sleep_ns_wakeable are simply passing | 3 | - __COUNTER__ doesn't work with ## concat |
4 | a pointer to QemuCoSleepState by reference to the function. But | 4 | - replaced ## with glue() macro so __COUNTER__ is evaluated |
5 | QemuCoSleepState really is just a Coroutine*; making the | ||
6 | content of the struct public is just as efficient and lets us | ||
7 | skip the user_state_pointer indirection. | ||
8 | 5 | ||
9 | Since the usage is changed, take the occasion to rename the | 6 | Fixes: 3284c3ddc4 |
10 | struct to QemuCoSleep. | ||
11 | 7 | ||
12 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 8 | Signed-off-by: Daniel Brodsky <dnbrdsky@gmail.com> |
13 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | 9 | Message-id: 20200404042108.389635-2-dnbrdsky@gmail.com |
14 | Message-id: 20210517100548.28806-6-pbonzini@redhat.com | ||
15 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
16 | --- | 11 | --- |
17 | include/qemu/coroutine.h | 23 +++++++++++---------- | 12 | include/qemu/lockable.h | 7 ++++--- |
18 | block/block-copy.c | 8 ++++---- | 13 | include/qemu/rcu.h | 2 +- |
19 | block/nbd.c | 10 ++++----- | 14 | 2 files changed, 5 insertions(+), 4 deletions(-) |
20 | util/qemu-coroutine-sleep.c | 41 ++++++++++++++++--------------------- | ||
21 | 4 files changed, 39 insertions(+), 43 deletions(-) | ||
22 | 15 | ||
23 | diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h | 16 | diff --git a/include/qemu/lockable.h b/include/qemu/lockable.h |
24 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/include/qemu/coroutine.h | 18 | --- a/include/qemu/lockable.h |
26 | +++ b/include/qemu/coroutine.h | 19 | +++ b/include/qemu/lockable.h |
27 | @@ -XXX,XX +XXX,XX @@ void qemu_co_rwlock_wrlock(CoRwlock *lock); | 20 | @@ -XXX,XX +XXX,XX @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuLockable, qemu_lockable_auto_unlock) |
21 | * } | ||
28 | */ | 22 | */ |
29 | void qemu_co_rwlock_unlock(CoRwlock *lock); | 23 | #define WITH_QEMU_LOCK_GUARD(x) \ |
30 | 24 | - WITH_QEMU_LOCK_GUARD_((x), qemu_lockable_auto##__COUNTER__) | |
31 | -typedef struct QemuCoSleepState QemuCoSleepState; | 25 | + WITH_QEMU_LOCK_GUARD_((x), glue(qemu_lockable_auto, __COUNTER__)) |
32 | +typedef struct QemuCoSleep { | ||
33 | + Coroutine *to_wake; | ||
34 | +} QemuCoSleep; | ||
35 | 26 | ||
36 | /** | 27 | /** |
37 | - * Yield the coroutine for a given duration. During this yield, @sleep_state | 28 | * QEMU_LOCK_GUARD - Lock an object until the end of the scope |
38 | - * is set to an opaque pointer, which may be used for | 29 | @@ -XXX,XX +XXX,XX @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuLockable, qemu_lockable_auto_unlock) |
39 | - * qemu_co_sleep_wake(). Be careful, the pointer is set back to zero when the | 30 | * return; <-- mutex is automatically unlocked |
40 | - * timer fires. Don't save the obtained value to other variables and don't call | 31 | * } |
41 | - * qemu_co_sleep_wake from another aio context. | ||
42 | + * Yield the coroutine for a given duration. Initializes @w so that, | ||
43 | + * during this yield, it can be passed to qemu_co_sleep_wake() to | ||
44 | + * terminate the sleep. | ||
45 | */ | 32 | */ |
46 | -void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | 33 | -#define QEMU_LOCK_GUARD(x) \ |
47 | - QemuCoSleepState **sleep_state); | 34 | - g_autoptr(QemuLockable) qemu_lockable_auto##__COUNTER__ = \ |
48 | +void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, | 35 | +#define QEMU_LOCK_GUARD(x) \ |
49 | + QEMUClockType type, int64_t ns); | 36 | + g_autoptr(QemuLockable) \ |
50 | + | 37 | + glue(qemu_lockable_auto, __COUNTER__) G_GNUC_UNUSED = \ |
51 | static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns) | 38 | qemu_lockable_auto_lock(QEMU_MAKE_LOCKABLE((x))) |
52 | { | 39 | |
53 | - QemuCoSleepState *unused = NULL; | 40 | #endif |
54 | - qemu_co_sleep_ns_wakeable(type, ns, &unused); | 41 | diff --git a/include/qemu/rcu.h b/include/qemu/rcu.h |
55 | + QemuCoSleep w = { 0 }; | ||
56 | + qemu_co_sleep_ns_wakeable(&w, type, ns); | ||
57 | } | ||
58 | |||
59 | /** | ||
60 | @@ -XXX,XX +XXX,XX @@ static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns) | ||
61 | * qemu_co_sleep_ns() and should be checked to be non-NULL before calling | ||
62 | * qemu_co_sleep_wake(). | ||
63 | */ | ||
64 | -void qemu_co_sleep_wake(QemuCoSleepState *sleep_state); | ||
65 | +void qemu_co_sleep_wake(QemuCoSleep *w); | ||
66 | |||
67 | /** | ||
68 | * Yield until a file descriptor becomes readable | ||
69 | diff --git a/block/block-copy.c b/block/block-copy.c | ||
70 | index XXXXXXX..XXXXXXX 100644 | 42 | index XXXXXXX..XXXXXXX 100644 |
71 | --- a/block/block-copy.c | 43 | --- a/include/qemu/rcu.h |
72 | +++ b/block/block-copy.c | 44 | +++ b/include/qemu/rcu.h |
73 | @@ -XXX,XX +XXX,XX @@ typedef struct BlockCopyCallState { | 45 | @@ -XXX,XX +XXX,XX @@ static inline void rcu_read_auto_unlock(RCUReadAuto *r) |
74 | /* State */ | 46 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(RCUReadAuto, rcu_read_auto_unlock) |
75 | int ret; | 47 | |
76 | bool finished; | 48 | #define WITH_RCU_READ_LOCK_GUARD() \ |
77 | - QemuCoSleepState *sleep_state; | 49 | - WITH_RCU_READ_LOCK_GUARD_(_rcu_read_auto##__COUNTER__) |
78 | + QemuCoSleep sleep; | 50 | + WITH_RCU_READ_LOCK_GUARD_(glue(_rcu_read_auto, __COUNTER__)) |
79 | bool cancelled; | 51 | |
80 | 52 | #define WITH_RCU_READ_LOCK_GUARD_(var) \ | |
81 | /* OUT parameters */ | 53 | for (g_autoptr(RCUReadAuto) var = rcu_read_auto_lock(); \ |
82 | @@ -XXX,XX +XXX,XX @@ block_copy_dirty_clusters(BlockCopyCallState *call_state) | ||
83 | if (ns > 0) { | ||
84 | block_copy_task_end(task, -EAGAIN); | ||
85 | g_free(task); | ||
86 | - qemu_co_sleep_ns_wakeable(QEMU_CLOCK_REALTIME, ns, | ||
87 | - &call_state->sleep_state); | ||
88 | + qemu_co_sleep_ns_wakeable(&call_state->sleep, | ||
89 | + QEMU_CLOCK_REALTIME, ns); | ||
90 | continue; | ||
91 | } | ||
92 | } | ||
93 | @@ -XXX,XX +XXX,XX @@ out: | ||
94 | |||
95 | void block_copy_kick(BlockCopyCallState *call_state) | ||
96 | { | ||
97 | - qemu_co_sleep_wake(call_state->sleep_state); | ||
98 | + qemu_co_sleep_wake(&call_state->sleep); | ||
99 | } | ||
100 | |||
101 | /* | ||
102 | diff --git a/block/nbd.c b/block/nbd.c | ||
103 | index XXXXXXX..XXXXXXX 100644 | ||
104 | --- a/block/nbd.c | ||
105 | +++ b/block/nbd.c | ||
106 | @@ -XXX,XX +XXX,XX @@ typedef struct BDRVNBDState { | ||
107 | CoQueue free_sema; | ||
108 | Coroutine *connection_co; | ||
109 | Coroutine *teardown_co; | ||
110 | - QemuCoSleepState *connection_co_sleep_ns_state; | ||
111 | + QemuCoSleep reconnect_sleep; | ||
112 | bool drained; | ||
113 | bool wait_drained_end; | ||
114 | int in_flight; | ||
115 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn nbd_client_co_drain_begin(BlockDriverState *bs) | ||
116 | BDRVNBDState *s = (BDRVNBDState *)bs->opaque; | ||
117 | |||
118 | s->drained = true; | ||
119 | - qemu_co_sleep_wake(s->connection_co_sleep_ns_state); | ||
120 | + qemu_co_sleep_wake(&s->reconnect_sleep); | ||
121 | |||
122 | nbd_co_establish_connection_cancel(bs, false); | ||
123 | |||
124 | @@ -XXX,XX +XXX,XX @@ static void nbd_teardown_connection(BlockDriverState *bs) | ||
125 | |||
126 | s->state = NBD_CLIENT_QUIT; | ||
127 | if (s->connection_co) { | ||
128 | - qemu_co_sleep_wake(s->connection_co_sleep_ns_state); | ||
129 | + qemu_co_sleep_wake(&s->reconnect_sleep); | ||
130 | nbd_co_establish_connection_cancel(bs, true); | ||
131 | } | ||
132 | if (qemu_in_coroutine()) { | ||
133 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn void nbd_co_reconnect_loop(BDRVNBDState *s) | ||
134 | } | ||
135 | bdrv_inc_in_flight(s->bs); | ||
136 | } else { | ||
137 | - qemu_co_sleep_ns_wakeable(QEMU_CLOCK_REALTIME, timeout, | ||
138 | - &s->connection_co_sleep_ns_state); | ||
139 | + qemu_co_sleep_ns_wakeable(&s->reconnect_sleep, | ||
140 | + QEMU_CLOCK_REALTIME, timeout); | ||
141 | if (s->drained) { | ||
142 | continue; | ||
143 | } | ||
144 | diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c | ||
145 | index XXXXXXX..XXXXXXX 100644 | ||
146 | --- a/util/qemu-coroutine-sleep.c | ||
147 | +++ b/util/qemu-coroutine-sleep.c | ||
148 | @@ -XXX,XX +XXX,XX @@ | ||
149 | |||
150 | static const char *qemu_co_sleep_ns__scheduled = "qemu_co_sleep_ns"; | ||
151 | |||
152 | -struct QemuCoSleepState { | ||
153 | +void qemu_co_sleep_wake(QemuCoSleep *w) | ||
154 | +{ | ||
155 | Coroutine *co; | ||
156 | - QemuCoSleepState **user_state_pointer; | ||
157 | -}; | ||
158 | |||
159 | -void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) | ||
160 | -{ | ||
161 | - if (sleep_state) { | ||
162 | + co = w->to_wake; | ||
163 | + w->to_wake = NULL; | ||
164 | + if (co) { | ||
165 | /* Write of schedule protected by barrier write in aio_co_schedule */ | ||
166 | - const char *scheduled = qatomic_cmpxchg(&sleep_state->co->scheduled, | ||
167 | + const char *scheduled = qatomic_cmpxchg(&co->scheduled, | ||
168 | qemu_co_sleep_ns__scheduled, NULL); | ||
169 | |||
170 | assert(scheduled == qemu_co_sleep_ns__scheduled); | ||
171 | - *sleep_state->user_state_pointer = NULL; | ||
172 | - aio_co_wake(sleep_state->co); | ||
173 | + aio_co_wake(co); | ||
174 | } | ||
175 | } | ||
176 | |||
177 | static void co_sleep_cb(void *opaque) | ||
178 | { | ||
179 | - QemuCoSleepState **sleep_state = opaque; | ||
180 | - qemu_co_sleep_wake(*sleep_state); | ||
181 | + QemuCoSleep *w = opaque; | ||
182 | + qemu_co_sleep_wake(w); | ||
183 | } | ||
184 | |||
185 | -void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | ||
186 | - QemuCoSleepState **sleep_state) | ||
187 | +void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, | ||
188 | + QEMUClockType type, int64_t ns) | ||
189 | { | ||
190 | + Coroutine *co = qemu_coroutine_self(); | ||
191 | AioContext *ctx = qemu_get_current_aio_context(); | ||
192 | QEMUTimer ts; | ||
193 | - QemuCoSleepState state = { | ||
194 | - .co = qemu_coroutine_self(), | ||
195 | - .user_state_pointer = sleep_state, | ||
196 | - }; | ||
197 | |||
198 | - const char *scheduled = qatomic_cmpxchg(&state.co->scheduled, NULL, | ||
199 | - qemu_co_sleep_ns__scheduled); | ||
200 | + const char *scheduled = qatomic_cmpxchg(&co->scheduled, NULL, | ||
201 | + qemu_co_sleep_ns__scheduled); | ||
202 | if (scheduled) { | ||
203 | fprintf(stderr, | ||
204 | "%s: Co-routine was already scheduled in '%s'\n", | ||
205 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | ||
206 | abort(); | ||
207 | } | ||
208 | |||
209 | - aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, sleep_state); | ||
210 | - *sleep_state = &state; | ||
211 | + w->to_wake = co; | ||
212 | + aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w), | ||
213 | timer_mod(&ts, qemu_clock_get_ns(type) + ns); | ||
214 | qemu_coroutine_yield(); | ||
215 | timer_del(&ts); | ||
216 | |||
217 | - /* qemu_co_sleep_wake clears *sleep_state before resuming this coroutine. */ | ||
218 | - assert(*sleep_state == NULL); | ||
219 | + /* w->to_wake is cleared before resuming this coroutine. */ | ||
220 | + assert(w->to_wake == NULL); | ||
221 | } | ||
222 | -- | 54 | -- |
223 | 2.31.1 | 55 | 2.25.3 |
224 | 56 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Daniel Brodsky <dnbrdsky@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Simplify the code by removing conditionals. qemu_co_sleep_ns | 3 | - ran regexp "qemu_mutex_lock\(.*\).*\n.*if" to find targets |
4 | can simply point the argument to an on-stack temporary. | 4 | - replaced result with QEMU_LOCK_GUARD if all unlocks at function end |
5 | - replaced result with WITH_QEMU_LOCK_GUARD if unlock not at end | ||
5 | 6 | ||
6 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 7 | Signed-off-by: Daniel Brodsky <dnbrdsky@gmail.com> |
7 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | 8 | Reviewed-by: Juan Quintela <quintela@redhat.com> |
8 | Message-id: 20210517100548.28806-3-pbonzini@redhat.com | 9 | Message-id: 20200404042108.389635-3-dnbrdsky@gmail.com |
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
10 | --- | 11 | --- |
11 | include/qemu/coroutine.h | 5 +++-- | 12 | block/iscsi.c | 7 ++---- |
12 | util/qemu-coroutine-sleep.c | 18 +++++------------- | 13 | block/nfs.c | 51 ++++++++++++++++++++----------------------- |
13 | 2 files changed, 8 insertions(+), 15 deletions(-) | 14 | cpus-common.c | 14 +++++------- |
15 | hw/display/qxl.c | 43 +++++++++++++++++------------------- | ||
16 | hw/vfio/platform.c | 5 ++--- | ||
17 | migration/migration.c | 3 +-- | ||
18 | migration/multifd.c | 8 +++---- | ||
19 | migration/ram.c | 3 +-- | ||
20 | monitor/misc.c | 4 +--- | ||
21 | ui/spice-display.c | 14 ++++++------ | ||
22 | util/log.c | 4 ++-- | ||
23 | util/qemu-timer.c | 17 +++++++-------- | ||
24 | util/rcu.c | 8 +++---- | ||
25 | util/thread-pool.c | 3 +-- | ||
26 | util/vfio-helpers.c | 5 ++--- | ||
27 | 15 files changed, 83 insertions(+), 106 deletions(-) | ||
14 | 28 | ||
15 | diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h | 29 | diff --git a/block/iscsi.c b/block/iscsi.c |
16 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/include/qemu/coroutine.h | 31 | --- a/block/iscsi.c |
18 | +++ b/include/qemu/coroutine.h | 32 | +++ b/block/iscsi.c |
19 | @@ -XXX,XX +XXX,XX @@ typedef struct QemuCoSleepState QemuCoSleepState; | 33 | @@ -XXX,XX +XXX,XX @@ static void iscsi_nop_timed_event(void *opaque) |
34 | { | ||
35 | IscsiLun *iscsilun = opaque; | ||
36 | |||
37 | - qemu_mutex_lock(&iscsilun->mutex); | ||
38 | + QEMU_LOCK_GUARD(&iscsilun->mutex); | ||
39 | if (iscsi_get_nops_in_flight(iscsilun->iscsi) >= MAX_NOP_FAILURES) { | ||
40 | error_report("iSCSI: NOP timeout. Reconnecting..."); | ||
41 | iscsilun->request_timed_out = true; | ||
42 | } else if (iscsi_nop_out_async(iscsilun->iscsi, NULL, NULL, 0, NULL) != 0) { | ||
43 | error_report("iSCSI: failed to sent NOP-Out. Disabling NOP messages."); | ||
44 | - goto out; | ||
45 | + return; | ||
46 | } | ||
47 | |||
48 | timer_mod(iscsilun->nop_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + NOP_INTERVAL); | ||
49 | iscsi_set_events(iscsilun); | ||
50 | - | ||
51 | -out: | ||
52 | - qemu_mutex_unlock(&iscsilun->mutex); | ||
53 | } | ||
54 | |||
55 | static void iscsi_readcapacity_sync(IscsiLun *iscsilun, Error **errp) | ||
56 | diff --git a/block/nfs.c b/block/nfs.c | ||
57 | index XXXXXXX..XXXXXXX 100644 | ||
58 | --- a/block/nfs.c | ||
59 | +++ b/block/nfs.c | ||
60 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn nfs_co_preadv(BlockDriverState *bs, uint64_t offset, | ||
61 | nfs_co_init_task(bs, &task); | ||
62 | task.iov = iov; | ||
63 | |||
64 | - qemu_mutex_lock(&client->mutex); | ||
65 | - if (nfs_pread_async(client->context, client->fh, | ||
66 | - offset, bytes, nfs_co_generic_cb, &task) != 0) { | ||
67 | - qemu_mutex_unlock(&client->mutex); | ||
68 | - return -ENOMEM; | ||
69 | - } | ||
70 | + WITH_QEMU_LOCK_GUARD(&client->mutex) { | ||
71 | + if (nfs_pread_async(client->context, client->fh, | ||
72 | + offset, bytes, nfs_co_generic_cb, &task) != 0) { | ||
73 | + return -ENOMEM; | ||
74 | + } | ||
75 | |||
76 | - nfs_set_events(client); | ||
77 | - qemu_mutex_unlock(&client->mutex); | ||
78 | + nfs_set_events(client); | ||
79 | + } | ||
80 | while (!task.complete) { | ||
81 | qemu_coroutine_yield(); | ||
82 | } | ||
83 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn nfs_co_pwritev(BlockDriverState *bs, uint64_t offset, | ||
84 | buf = iov->iov[0].iov_base; | ||
85 | } | ||
86 | |||
87 | - qemu_mutex_lock(&client->mutex); | ||
88 | - if (nfs_pwrite_async(client->context, client->fh, | ||
89 | - offset, bytes, buf, | ||
90 | - nfs_co_generic_cb, &task) != 0) { | ||
91 | - qemu_mutex_unlock(&client->mutex); | ||
92 | - if (my_buffer) { | ||
93 | - g_free(buf); | ||
94 | + WITH_QEMU_LOCK_GUARD(&client->mutex) { | ||
95 | + if (nfs_pwrite_async(client->context, client->fh, | ||
96 | + offset, bytes, buf, | ||
97 | + nfs_co_generic_cb, &task) != 0) { | ||
98 | + if (my_buffer) { | ||
99 | + g_free(buf); | ||
100 | + } | ||
101 | + return -ENOMEM; | ||
102 | } | ||
103 | - return -ENOMEM; | ||
104 | - } | ||
105 | |||
106 | - nfs_set_events(client); | ||
107 | - qemu_mutex_unlock(&client->mutex); | ||
108 | + nfs_set_events(client); | ||
109 | + } | ||
110 | while (!task.complete) { | ||
111 | qemu_coroutine_yield(); | ||
112 | } | ||
113 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn nfs_co_flush(BlockDriverState *bs) | ||
114 | |||
115 | nfs_co_init_task(bs, &task); | ||
116 | |||
117 | - qemu_mutex_lock(&client->mutex); | ||
118 | - if (nfs_fsync_async(client->context, client->fh, nfs_co_generic_cb, | ||
119 | - &task) != 0) { | ||
120 | - qemu_mutex_unlock(&client->mutex); | ||
121 | - return -ENOMEM; | ||
122 | - } | ||
123 | + WITH_QEMU_LOCK_GUARD(&client->mutex) { | ||
124 | + if (nfs_fsync_async(client->context, client->fh, nfs_co_generic_cb, | ||
125 | + &task) != 0) { | ||
126 | + return -ENOMEM; | ||
127 | + } | ||
128 | |||
129 | - nfs_set_events(client); | ||
130 | - qemu_mutex_unlock(&client->mutex); | ||
131 | + nfs_set_events(client); | ||
132 | + } | ||
133 | while (!task.complete) { | ||
134 | qemu_coroutine_yield(); | ||
135 | } | ||
136 | diff --git a/cpus-common.c b/cpus-common.c | ||
137 | index XXXXXXX..XXXXXXX 100644 | ||
138 | --- a/cpus-common.c | ||
139 | +++ b/cpus-common.c | ||
140 | @@ -XXX,XX +XXX,XX @@ | ||
141 | #include "exec/cpu-common.h" | ||
142 | #include "hw/core/cpu.h" | ||
143 | #include "sysemu/cpus.h" | ||
144 | +#include "qemu/lockable.h" | ||
145 | |||
146 | static QemuMutex qemu_cpu_list_lock; | ||
147 | static QemuCond exclusive_cond; | ||
148 | @@ -XXX,XX +XXX,XX @@ static int cpu_get_free_index(void) | ||
149 | |||
150 | void cpu_list_add(CPUState *cpu) | ||
151 | { | ||
152 | - qemu_mutex_lock(&qemu_cpu_list_lock); | ||
153 | + QEMU_LOCK_GUARD(&qemu_cpu_list_lock); | ||
154 | if (cpu->cpu_index == UNASSIGNED_CPU_INDEX) { | ||
155 | cpu->cpu_index = cpu_get_free_index(); | ||
156 | assert(cpu->cpu_index != UNASSIGNED_CPU_INDEX); | ||
157 | @@ -XXX,XX +XXX,XX @@ void cpu_list_add(CPUState *cpu) | ||
158 | assert(!cpu_index_auto_assigned); | ||
159 | } | ||
160 | QTAILQ_INSERT_TAIL_RCU(&cpus, cpu, node); | ||
161 | - qemu_mutex_unlock(&qemu_cpu_list_lock); | ||
162 | } | ||
163 | |||
164 | void cpu_list_remove(CPUState *cpu) | ||
165 | { | ||
166 | - qemu_mutex_lock(&qemu_cpu_list_lock); | ||
167 | + QEMU_LOCK_GUARD(&qemu_cpu_list_lock); | ||
168 | if (!QTAILQ_IN_USE(cpu, node)) { | ||
169 | /* there is nothing to undo since cpu_exec_init() hasn't been called */ | ||
170 | - qemu_mutex_unlock(&qemu_cpu_list_lock); | ||
171 | return; | ||
172 | } | ||
173 | |||
174 | @@ -XXX,XX +XXX,XX @@ void cpu_list_remove(CPUState *cpu) | ||
175 | |||
176 | QTAILQ_REMOVE_RCU(&cpus, cpu, node); | ||
177 | cpu->cpu_index = UNASSIGNED_CPU_INDEX; | ||
178 | - qemu_mutex_unlock(&qemu_cpu_list_lock); | ||
179 | } | ||
180 | |||
181 | struct qemu_work_item { | ||
182 | @@ -XXX,XX +XXX,XX @@ void cpu_exec_start(CPUState *cpu) | ||
183 | * see cpu->running == true, and it will kick the CPU. | ||
184 | */ | ||
185 | if (unlikely(atomic_read(&pending_cpus))) { | ||
186 | - qemu_mutex_lock(&qemu_cpu_list_lock); | ||
187 | + QEMU_LOCK_GUARD(&qemu_cpu_list_lock); | ||
188 | if (!cpu->has_waiter) { | ||
189 | /* Not counted in pending_cpus, let the exclusive item | ||
190 | * run. Since we have the lock, just set cpu->running to true | ||
191 | @@ -XXX,XX +XXX,XX @@ void cpu_exec_start(CPUState *cpu) | ||
192 | * waiter at cpu_exec_end. | ||
193 | */ | ||
194 | } | ||
195 | - qemu_mutex_unlock(&qemu_cpu_list_lock); | ||
196 | } | ||
197 | } | ||
198 | |||
199 | @@ -XXX,XX +XXX,XX @@ void cpu_exec_end(CPUState *cpu) | ||
200 | * next cpu_exec_start. | ||
201 | */ | ||
202 | if (unlikely(atomic_read(&pending_cpus))) { | ||
203 | - qemu_mutex_lock(&qemu_cpu_list_lock); | ||
204 | + QEMU_LOCK_GUARD(&qemu_cpu_list_lock); | ||
205 | if (cpu->has_waiter) { | ||
206 | cpu->has_waiter = false; | ||
207 | atomic_set(&pending_cpus, pending_cpus - 1); | ||
208 | @@ -XXX,XX +XXX,XX @@ void cpu_exec_end(CPUState *cpu) | ||
209 | qemu_cond_signal(&exclusive_cond); | ||
210 | } | ||
211 | } | ||
212 | - qemu_mutex_unlock(&qemu_cpu_list_lock); | ||
213 | } | ||
214 | } | ||
215 | |||
216 | diff --git a/hw/display/qxl.c b/hw/display/qxl.c | ||
217 | index XXXXXXX..XXXXXXX 100644 | ||
218 | --- a/hw/display/qxl.c | ||
219 | +++ b/hw/display/qxl.c | ||
220 | @@ -XXX,XX +XXX,XX @@ static int qxl_track_command(PCIQXLDevice *qxl, struct QXLCommandExt *ext) | ||
221 | cmd->u.surface_create.stride); | ||
222 | return 1; | ||
223 | } | ||
224 | - qemu_mutex_lock(&qxl->track_lock); | ||
225 | - if (cmd->type == QXL_SURFACE_CMD_CREATE) { | ||
226 | - qxl->guest_surfaces.cmds[id] = ext->cmd.data; | ||
227 | - qxl->guest_surfaces.count++; | ||
228 | - if (qxl->guest_surfaces.max < qxl->guest_surfaces.count) | ||
229 | - qxl->guest_surfaces.max = qxl->guest_surfaces.count; | ||
230 | + WITH_QEMU_LOCK_GUARD(&qxl->track_lock) { | ||
231 | + if (cmd->type == QXL_SURFACE_CMD_CREATE) { | ||
232 | + qxl->guest_surfaces.cmds[id] = ext->cmd.data; | ||
233 | + qxl->guest_surfaces.count++; | ||
234 | + if (qxl->guest_surfaces.max < qxl->guest_surfaces.count) { | ||
235 | + qxl->guest_surfaces.max = qxl->guest_surfaces.count; | ||
236 | + } | ||
237 | + } | ||
238 | + if (cmd->type == QXL_SURFACE_CMD_DESTROY) { | ||
239 | + qxl->guest_surfaces.cmds[id] = 0; | ||
240 | + qxl->guest_surfaces.count--; | ||
241 | + } | ||
242 | } | ||
243 | - if (cmd->type == QXL_SURFACE_CMD_DESTROY) { | ||
244 | - qxl->guest_surfaces.cmds[id] = 0; | ||
245 | - qxl->guest_surfaces.count--; | ||
246 | - } | ||
247 | - qemu_mutex_unlock(&qxl->track_lock); | ||
248 | break; | ||
249 | } | ||
250 | case QXL_CMD_CURSOR: | ||
251 | @@ -XXX,XX +XXX,XX @@ static void interface_update_area_complete(QXLInstance *sin, | ||
252 | int i; | ||
253 | int qxl_i; | ||
254 | |||
255 | - qemu_mutex_lock(&qxl->ssd.lock); | ||
256 | + QEMU_LOCK_GUARD(&qxl->ssd.lock); | ||
257 | if (surface_id != 0 || !num_updated_rects || | ||
258 | !qxl->render_update_cookie_num) { | ||
259 | - qemu_mutex_unlock(&qxl->ssd.lock); | ||
260 | return; | ||
261 | } | ||
262 | trace_qxl_interface_update_area_complete(qxl->id, surface_id, dirty->left, | ||
263 | @@ -XXX,XX +XXX,XX @@ static void interface_update_area_complete(QXLInstance *sin, | ||
264 | * Don't bother copying or scheduling the bh since we will flip | ||
265 | * the whole area anyway on completion of the update_area async call | ||
266 | */ | ||
267 | - qemu_mutex_unlock(&qxl->ssd.lock); | ||
268 | return; | ||
269 | } | ||
270 | qxl_i = qxl->num_dirty_rects; | ||
271 | @@ -XXX,XX +XXX,XX @@ static void interface_update_area_complete(QXLInstance *sin, | ||
272 | trace_qxl_interface_update_area_complete_schedule_bh(qxl->id, | ||
273 | qxl->num_dirty_rects); | ||
274 | qemu_bh_schedule(qxl->update_area_bh); | ||
275 | - qemu_mutex_unlock(&qxl->ssd.lock); | ||
276 | } | ||
277 | |||
278 | /* called from spice server thread context only */ | ||
279 | @@ -XXX,XX +XXX,XX @@ static void ioport_write(void *opaque, hwaddr addr, | ||
280 | case QXL_IO_MONITORS_CONFIG_ASYNC: | ||
281 | async_common: | ||
282 | async = QXL_ASYNC; | ||
283 | - qemu_mutex_lock(&d->async_lock); | ||
284 | - if (d->current_async != QXL_UNDEFINED_IO) { | ||
285 | - qxl_set_guest_bug(d, "%d async started before last (%d) complete", | ||
286 | - io_port, d->current_async); | ||
287 | - qemu_mutex_unlock(&d->async_lock); | ||
288 | - return; | ||
289 | + WITH_QEMU_LOCK_GUARD(&d->async_lock) { | ||
290 | + if (d->current_async != QXL_UNDEFINED_IO) { | ||
291 | + qxl_set_guest_bug(d, "%d async started before last (%d) complete", | ||
292 | + io_port, d->current_async); | ||
293 | + return; | ||
294 | + } | ||
295 | + d->current_async = orig_io_port; | ||
296 | } | ||
297 | - d->current_async = orig_io_port; | ||
298 | - qemu_mutex_unlock(&d->async_lock); | ||
299 | break; | ||
300 | default: | ||
301 | break; | ||
302 | diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c | ||
303 | index XXXXXXX..XXXXXXX 100644 | ||
304 | --- a/hw/vfio/platform.c | ||
305 | +++ b/hw/vfio/platform.c | ||
306 | @@ -XXX,XX +XXX,XX @@ | ||
307 | #include "hw/vfio/vfio-platform.h" | ||
308 | #include "migration/vmstate.h" | ||
309 | #include "qemu/error-report.h" | ||
310 | +#include "qemu/lockable.h" | ||
311 | #include "qemu/main-loop.h" | ||
312 | #include "qemu/module.h" | ||
313 | #include "qemu/range.h" | ||
314 | @@ -XXX,XX +XXX,XX @@ static void vfio_intp_interrupt(VFIOINTp *intp) | ||
315 | VFIOPlatformDevice *vdev = intp->vdev; | ||
316 | bool delay_handling = false; | ||
317 | |||
318 | - qemu_mutex_lock(&vdev->intp_mutex); | ||
319 | + QEMU_LOCK_GUARD(&vdev->intp_mutex); | ||
320 | if (intp->state == VFIO_IRQ_INACTIVE) { | ||
321 | QLIST_FOREACH(tmp, &vdev->intp_list, next) { | ||
322 | if (tmp->state == VFIO_IRQ_ACTIVE || | ||
323 | @@ -XXX,XX +XXX,XX @@ static void vfio_intp_interrupt(VFIOINTp *intp) | ||
324 | QSIMPLEQ_INSERT_TAIL(&vdev->pending_intp_queue, | ||
325 | intp, pqnext); | ||
326 | ret = event_notifier_test_and_clear(intp->interrupt); | ||
327 | - qemu_mutex_unlock(&vdev->intp_mutex); | ||
328 | return; | ||
329 | } | ||
330 | |||
331 | @@ -XXX,XX +XXX,XX @@ static void vfio_intp_interrupt(VFIOINTp *intp) | ||
332 | qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + | ||
333 | vdev->mmap_timeout); | ||
334 | } | ||
335 | - qemu_mutex_unlock(&vdev->intp_mutex); | ||
336 | } | ||
20 | 337 | ||
21 | /** | 338 | /** |
22 | * Yield the coroutine for a given duration. During this yield, @sleep_state | 339 | diff --git a/migration/migration.c b/migration/migration.c |
23 | - * (if not NULL) is set to an opaque pointer, which may be used for | 340 | index XXXXXXX..XXXXXXX 100644 |
24 | + * is set to an opaque pointer, which may be used for | 341 | --- a/migration/migration.c |
25 | * qemu_co_sleep_wake(). Be careful, the pointer is set back to zero when the | 342 | +++ b/migration/migration.c |
26 | * timer fires. Don't save the obtained value to other variables and don't call | 343 | @@ -XXX,XX +XXX,XX @@ static void migrate_fd_cleanup_bh(void *opaque) |
27 | * qemu_co_sleep_wake from another aio context. | 344 | |
28 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | 345 | void migrate_set_error(MigrationState *s, const Error *error) |
29 | QemuCoSleepState **sleep_state); | ||
30 | static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns) | ||
31 | { | 346 | { |
32 | - qemu_co_sleep_ns_wakeable(type, ns, NULL); | 347 | - qemu_mutex_lock(&s->error_mutex); |
33 | + QemuCoSleepState *unused = NULL; | 348 | + QEMU_LOCK_GUARD(&s->error_mutex); |
34 | + qemu_co_sleep_ns_wakeable(type, ns, &unused); | 349 | if (!s->error) { |
35 | } | 350 | s->error = error_copy(error); |
36 | 351 | } | |
37 | /** | 352 | - qemu_mutex_unlock(&s->error_mutex); |
38 | diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c | 353 | } |
39 | index XXXXXXX..XXXXXXX 100644 | 354 | |
40 | --- a/util/qemu-coroutine-sleep.c | 355 | void migrate_fd_error(MigrationState *s, const Error *error) |
41 | +++ b/util/qemu-coroutine-sleep.c | 356 | diff --git a/migration/multifd.c b/migration/multifd.c |
42 | @@ -XXX,XX +XXX,XX @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) | 357 | index XXXXXXX..XXXXXXX 100644 |
43 | qemu_co_sleep_ns__scheduled, NULL); | 358 | --- a/migration/multifd.c |
44 | 359 | +++ b/migration/multifd.c | |
45 | assert(scheduled == qemu_co_sleep_ns__scheduled); | 360 | @@ -XXX,XX +XXX,XX @@ void multifd_recv_sync_main(void) |
46 | - if (sleep_state->user_state_pointer) { | 361 | for (i = 0; i < migrate_multifd_channels(); i++) { |
47 | - *sleep_state->user_state_pointer = NULL; | 362 | MultiFDRecvParams *p = &multifd_recv_state->params[i]; |
48 | - } | 363 | |
49 | + *sleep_state->user_state_pointer = NULL; | 364 | - qemu_mutex_lock(&p->mutex); |
50 | timer_del(&sleep_state->ts); | 365 | - if (multifd_recv_state->packet_num < p->packet_num) { |
51 | aio_co_wake(sleep_state->co); | 366 | - multifd_recv_state->packet_num = p->packet_num; |
52 | } | 367 | + WITH_QEMU_LOCK_GUARD(&p->mutex) { |
53 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | 368 | + if (multifd_recv_state->packet_num < p->packet_num) { |
54 | } | 369 | + multifd_recv_state->packet_num = p->packet_num; |
55 | 370 | + } | |
56 | aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state); | 371 | } |
57 | - if (sleep_state) { | 372 | - qemu_mutex_unlock(&p->mutex); |
58 | - *sleep_state = &state; | 373 | trace_multifd_recv_sync_main_signal(p->id); |
59 | - } | 374 | qemu_sem_post(&p->sem_sync); |
60 | + *sleep_state = &state; | 375 | } |
61 | timer_mod(&state.ts, qemu_clock_get_ns(type) + ns); | 376 | diff --git a/migration/ram.c b/migration/ram.c |
62 | qemu_coroutine_yield(); | 377 | index XXXXXXX..XXXXXXX 100644 |
63 | - if (sleep_state) { | 378 | --- a/migration/ram.c |
64 | - /* | 379 | +++ b/migration/ram.c |
65 | - * Note that *sleep_state is cleared during qemu_co_sleep_wake | 380 | @@ -XXX,XX +XXX,XX @@ static RAMBlock *unqueue_page(RAMState *rs, ram_addr_t *offset) |
66 | - * before resuming this coroutine. | 381 | return NULL; |
67 | - */ | 382 | } |
68 | - assert(*sleep_state == NULL); | 383 | |
69 | - } | 384 | - qemu_mutex_lock(&rs->src_page_req_mutex); |
70 | + | 385 | + QEMU_LOCK_GUARD(&rs->src_page_req_mutex); |
71 | + /* qemu_co_sleep_wake clears *sleep_state before resuming this coroutine. */ | 386 | if (!QSIMPLEQ_EMPTY(&rs->src_page_requests)) { |
72 | + assert(*sleep_state == NULL); | 387 | struct RAMSrcPageRequest *entry = |
73 | } | 388 | QSIMPLEQ_FIRST(&rs->src_page_requests); |
389 | @@ -XXX,XX +XXX,XX @@ static RAMBlock *unqueue_page(RAMState *rs, ram_addr_t *offset) | ||
390 | migration_consume_urgent_request(); | ||
391 | } | ||
392 | } | ||
393 | - qemu_mutex_unlock(&rs->src_page_req_mutex); | ||
394 | |||
395 | return block; | ||
396 | } | ||
397 | diff --git a/monitor/misc.c b/monitor/misc.c | ||
398 | index XXXXXXX..XXXXXXX 100644 | ||
399 | --- a/monitor/misc.c | ||
400 | +++ b/monitor/misc.c | ||
401 | @@ -XXX,XX +XXX,XX @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id, | ||
402 | MonFdsetFd *mon_fdset_fd; | ||
403 | AddfdInfo *fdinfo; | ||
404 | |||
405 | - qemu_mutex_lock(&mon_fdsets_lock); | ||
406 | + QEMU_LOCK_GUARD(&mon_fdsets_lock); | ||
407 | if (has_fdset_id) { | ||
408 | QLIST_FOREACH(mon_fdset, &mon_fdsets, next) { | ||
409 | /* Break if match found or match impossible due to ordering by ID */ | ||
410 | @@ -XXX,XX +XXX,XX @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id, | ||
411 | if (fdset_id < 0) { | ||
412 | error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "fdset-id", | ||
413 | "a non-negative value"); | ||
414 | - qemu_mutex_unlock(&mon_fdsets_lock); | ||
415 | return NULL; | ||
416 | } | ||
417 | /* Use specified fdset ID */ | ||
418 | @@ -XXX,XX +XXX,XX @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id, | ||
419 | fdinfo->fdset_id = mon_fdset->id; | ||
420 | fdinfo->fd = mon_fdset_fd->fd; | ||
421 | |||
422 | - qemu_mutex_unlock(&mon_fdsets_lock); | ||
423 | return fdinfo; | ||
424 | } | ||
425 | |||
426 | diff --git a/ui/spice-display.c b/ui/spice-display.c | ||
427 | index XXXXXXX..XXXXXXX 100644 | ||
428 | --- a/ui/spice-display.c | ||
429 | +++ b/ui/spice-display.c | ||
430 | @@ -XXX,XX +XXX,XX @@ | ||
431 | #include "qemu/osdep.h" | ||
432 | #include "ui/qemu-spice.h" | ||
433 | #include "qemu/timer.h" | ||
434 | +#include "qemu/lockable.h" | ||
435 | #include "qemu/main-loop.h" | ||
436 | #include "qemu/option.h" | ||
437 | #include "qemu/queue.h" | ||
438 | @@ -XXX,XX +XXX,XX @@ void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd) | ||
439 | { | ||
440 | graphic_hw_update(ssd->dcl.con); | ||
441 | |||
442 | - qemu_mutex_lock(&ssd->lock); | ||
443 | - if (QTAILQ_EMPTY(&ssd->updates) && ssd->ds) { | ||
444 | - qemu_spice_create_update(ssd); | ||
445 | - ssd->notify++; | ||
446 | + WITH_QEMU_LOCK_GUARD(&ssd->lock) { | ||
447 | + if (QTAILQ_EMPTY(&ssd->updates) && ssd->ds) { | ||
448 | + qemu_spice_create_update(ssd); | ||
449 | + ssd->notify++; | ||
450 | + } | ||
451 | } | ||
452 | - qemu_mutex_unlock(&ssd->lock); | ||
453 | |||
454 | trace_qemu_spice_display_refresh(ssd->qxl.id, ssd->notify); | ||
455 | if (ssd->notify) { | ||
456 | @@ -XXX,XX +XXX,XX @@ static int interface_get_cursor_command(QXLInstance *sin, QXLCommandExt *ext) | ||
457 | SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl); | ||
458 | int ret; | ||
459 | |||
460 | - qemu_mutex_lock(&ssd->lock); | ||
461 | + QEMU_LOCK_GUARD(&ssd->lock); | ||
462 | if (ssd->ptr_define) { | ||
463 | *ext = ssd->ptr_define->ext; | ||
464 | ssd->ptr_define = NULL; | ||
465 | @@ -XXX,XX +XXX,XX @@ static int interface_get_cursor_command(QXLInstance *sin, QXLCommandExt *ext) | ||
466 | } else { | ||
467 | ret = false; | ||
468 | } | ||
469 | - qemu_mutex_unlock(&ssd->lock); | ||
470 | return ret; | ||
471 | } | ||
472 | |||
473 | diff --git a/util/log.c b/util/log.c | ||
474 | index XXXXXXX..XXXXXXX 100644 | ||
475 | --- a/util/log.c | ||
476 | +++ b/util/log.c | ||
477 | @@ -XXX,XX +XXX,XX @@ | ||
478 | #include "qemu/cutils.h" | ||
479 | #include "trace/control.h" | ||
480 | #include "qemu/thread.h" | ||
481 | +#include "qemu/lockable.h" | ||
482 | |||
483 | static char *logfilename; | ||
484 | static QemuMutex qemu_logfile_mutex; | ||
485 | @@ -XXX,XX +XXX,XX @@ void qemu_set_log(int log_flags) | ||
486 | if (qemu_loglevel && (!is_daemonized() || logfilename)) { | ||
487 | need_to_open_file = true; | ||
488 | } | ||
489 | - qemu_mutex_lock(&qemu_logfile_mutex); | ||
490 | + QEMU_LOCK_GUARD(&qemu_logfile_mutex); | ||
491 | if (qemu_logfile && !need_to_open_file) { | ||
492 | logfile = qemu_logfile; | ||
493 | atomic_rcu_set(&qemu_logfile, NULL); | ||
494 | @@ -XXX,XX +XXX,XX @@ void qemu_set_log(int log_flags) | ||
495 | } | ||
496 | atomic_rcu_set(&qemu_logfile, logfile); | ||
497 | } | ||
498 | - qemu_mutex_unlock(&qemu_logfile_mutex); | ||
499 | } | ||
500 | |||
501 | void qemu_log_needs_buffers(void) | ||
502 | diff --git a/util/qemu-timer.c b/util/qemu-timer.c | ||
503 | index XXXXXXX..XXXXXXX 100644 | ||
504 | --- a/util/qemu-timer.c | ||
505 | +++ b/util/qemu-timer.c | ||
506 | @@ -XXX,XX +XXX,XX @@ void timer_mod_anticipate_ns(QEMUTimer *ts, int64_t expire_time) | ||
507 | QEMUTimerList *timer_list = ts->timer_list; | ||
508 | bool rearm; | ||
509 | |||
510 | - qemu_mutex_lock(&timer_list->active_timers_lock); | ||
511 | - if (ts->expire_time == -1 || ts->expire_time > expire_time) { | ||
512 | - if (ts->expire_time != -1) { | ||
513 | - timer_del_locked(timer_list, ts); | ||
514 | + WITH_QEMU_LOCK_GUARD(&timer_list->active_timers_lock) { | ||
515 | + if (ts->expire_time == -1 || ts->expire_time > expire_time) { | ||
516 | + if (ts->expire_time != -1) { | ||
517 | + timer_del_locked(timer_list, ts); | ||
518 | + } | ||
519 | + rearm = timer_mod_ns_locked(timer_list, ts, expire_time); | ||
520 | + } else { | ||
521 | + rearm = false; | ||
522 | } | ||
523 | - rearm = timer_mod_ns_locked(timer_list, ts, expire_time); | ||
524 | - } else { | ||
525 | - rearm = false; | ||
526 | } | ||
527 | - qemu_mutex_unlock(&timer_list->active_timers_lock); | ||
528 | - | ||
529 | if (rearm) { | ||
530 | timerlist_rearm(timer_list); | ||
531 | } | ||
532 | diff --git a/util/rcu.c b/util/rcu.c | ||
533 | index XXXXXXX..XXXXXXX 100644 | ||
534 | --- a/util/rcu.c | ||
535 | +++ b/util/rcu.c | ||
536 | @@ -XXX,XX +XXX,XX @@ | ||
537 | #include "qemu/atomic.h" | ||
538 | #include "qemu/thread.h" | ||
539 | #include "qemu/main-loop.h" | ||
540 | +#include "qemu/lockable.h" | ||
541 | #if defined(CONFIG_MALLOC_TRIM) | ||
542 | #include <malloc.h> | ||
543 | #endif | ||
544 | @@ -XXX,XX +XXX,XX @@ static void wait_for_readers(void) | ||
545 | |||
546 | void synchronize_rcu(void) | ||
547 | { | ||
548 | - qemu_mutex_lock(&rcu_sync_lock); | ||
549 | + QEMU_LOCK_GUARD(&rcu_sync_lock); | ||
550 | |||
551 | /* Write RCU-protected pointers before reading p_rcu_reader->ctr. | ||
552 | * Pairs with smp_mb_placeholder() in rcu_read_lock(). | ||
553 | */ | ||
554 | smp_mb_global(); | ||
555 | |||
556 | - qemu_mutex_lock(&rcu_registry_lock); | ||
557 | + QEMU_LOCK_GUARD(&rcu_registry_lock); | ||
558 | if (!QLIST_EMPTY(®istry)) { | ||
559 | /* In either case, the atomic_mb_set below blocks stores that free | ||
560 | * old RCU-protected pointers. | ||
561 | @@ -XXX,XX +XXX,XX @@ void synchronize_rcu(void) | ||
562 | |||
563 | wait_for_readers(); | ||
564 | } | ||
565 | - | ||
566 | - qemu_mutex_unlock(&rcu_registry_lock); | ||
567 | - qemu_mutex_unlock(&rcu_sync_lock); | ||
568 | } | ||
569 | |||
570 | |||
571 | diff --git a/util/thread-pool.c b/util/thread-pool.c | ||
572 | index XXXXXXX..XXXXXXX 100644 | ||
573 | --- a/util/thread-pool.c | ||
574 | +++ b/util/thread-pool.c | ||
575 | @@ -XXX,XX +XXX,XX @@ static void thread_pool_cancel(BlockAIOCB *acb) | ||
576 | |||
577 | trace_thread_pool_cancel(elem, elem->common.opaque); | ||
578 | |||
579 | - qemu_mutex_lock(&pool->lock); | ||
580 | + QEMU_LOCK_GUARD(&pool->lock); | ||
581 | if (elem->state == THREAD_QUEUED && | ||
582 | /* No thread has yet started working on elem. we can try to "steal" | ||
583 | * the item from the worker if we can get a signal from the | ||
584 | @@ -XXX,XX +XXX,XX @@ static void thread_pool_cancel(BlockAIOCB *acb) | ||
585 | elem->ret = -ECANCELED; | ||
586 | } | ||
587 | |||
588 | - qemu_mutex_unlock(&pool->lock); | ||
589 | } | ||
590 | |||
591 | static AioContext *thread_pool_get_aio_context(BlockAIOCB *acb) | ||
592 | diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c | ||
593 | index XXXXXXX..XXXXXXX 100644 | ||
594 | --- a/util/vfio-helpers.c | ||
595 | +++ b/util/vfio-helpers.c | ||
596 | @@ -XXX,XX +XXX,XX @@ | ||
597 | #include "standard-headers/linux/pci_regs.h" | ||
598 | #include "qemu/event_notifier.h" | ||
599 | #include "qemu/vfio-helpers.h" | ||
600 | +#include "qemu/lockable.h" | ||
601 | #include "trace.h" | ||
602 | |||
603 | #define QEMU_VFIO_DEBUG 0 | ||
604 | @@ -XXX,XX +XXX,XX @@ int qemu_vfio_dma_reset_temporary(QEMUVFIOState *s) | ||
605 | .size = QEMU_VFIO_IOVA_MAX - s->high_water_mark, | ||
606 | }; | ||
607 | trace_qemu_vfio_dma_reset_temporary(s); | ||
608 | - qemu_mutex_lock(&s->lock); | ||
609 | + QEMU_LOCK_GUARD(&s->lock); | ||
610 | if (ioctl(s->container, VFIO_IOMMU_UNMAP_DMA, &unmap)) { | ||
611 | error_report("VFIO_UNMAP_DMA failed: %s", strerror(errno)); | ||
612 | - qemu_mutex_unlock(&s->lock); | ||
613 | return -errno; | ||
614 | } | ||
615 | s->high_water_mark = QEMU_VFIO_IOVA_MAX; | ||
616 | - qemu_mutex_unlock(&s->lock); | ||
617 | return 0; | ||
618 | } | ||
619 | |||
74 | -- | 620 | -- |
75 | 2.31.1 | 621 | 2.25.3 |
76 | 622 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Simran Singhal <singhalsimran0@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | The lifetime of the timer is well-known (it cannot outlive | 3 | Replace manual lock()/unlock() calls with lock guard macros |
4 | qemu_co_sleep_ns_wakeable, because it's deleted by the time the | 4 | (QEMU_LOCK_GUARD/WITH_QEMU_LOCK_GUARD). |
5 | coroutine resumes), so it is not necessary to place it on the heap. | ||
6 | 5 | ||
7 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 6 | Signed-off-by: Simran Singhal <singhalsimran0@gmail.com> |
8 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | 7 | Reviewed-by: Yuval Shaia <yuval.shaia.ml@gmail.com> |
9 | Message-id: 20210517100548.28806-2-pbonzini@redhat.com | 8 | Reviewed-by: Marcel Apfelbaum<marcel.apfelbaum@gmail.com> |
9 | Tested-by: Yuval Shaia <yuval.shaia.ml@gmail.com> | ||
10 | Message-id: 20200402065035.GA15477@simran-Inspiron-5558 | ||
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
11 | --- | 12 | --- |
12 | util/qemu-coroutine-sleep.c | 9 ++++----- | 13 | hw/hyperv/hyperv.c | 15 ++++++------- |
13 | 1 file changed, 4 insertions(+), 5 deletions(-) | 14 | hw/rdma/rdma_backend.c | 50 +++++++++++++++++++++--------------------- |
15 | hw/rdma/rdma_rm.c | 3 +-- | ||
16 | 3 files changed, 33 insertions(+), 35 deletions(-) | ||
14 | 17 | ||
15 | diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c | 18 | diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c |
16 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/util/qemu-coroutine-sleep.c | 20 | --- a/hw/hyperv/hyperv.c |
18 | +++ b/util/qemu-coroutine-sleep.c | 21 | +++ b/hw/hyperv/hyperv.c |
19 | @@ -XXX,XX +XXX,XX @@ static const char *qemu_co_sleep_ns__scheduled = "qemu_co_sleep_ns"; | 22 | @@ -XXX,XX +XXX,XX @@ |
20 | 23 | #include "sysemu/kvm.h" | |
21 | struct QemuCoSleepState { | 24 | #include "qemu/bitops.h" |
22 | Coroutine *co; | 25 | #include "qemu/error-report.h" |
23 | - QEMUTimer *ts; | 26 | +#include "qemu/lockable.h" |
24 | + QEMUTimer ts; | 27 | #include "qemu/queue.h" |
25 | QemuCoSleepState **user_state_pointer; | 28 | #include "qemu/rcu.h" |
26 | }; | 29 | #include "qemu/rcu_queue.h" |
27 | 30 | @@ -XXX,XX +XXX,XX @@ int hyperv_set_msg_handler(uint32_t conn_id, HvMsgHandler handler, void *data) | |
28 | @@ -XXX,XX +XXX,XX @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) | 31 | int ret; |
29 | if (sleep_state->user_state_pointer) { | 32 | MsgHandler *mh; |
30 | *sleep_state->user_state_pointer = NULL; | 33 | |
34 | - qemu_mutex_lock(&handlers_mutex); | ||
35 | + QEMU_LOCK_GUARD(&handlers_mutex); | ||
36 | QLIST_FOREACH(mh, &msg_handlers, link) { | ||
37 | if (mh->conn_id == conn_id) { | ||
38 | if (handler) { | ||
39 | @@ -XXX,XX +XXX,XX @@ int hyperv_set_msg_handler(uint32_t conn_id, HvMsgHandler handler, void *data) | ||
40 | g_free_rcu(mh, rcu); | ||
41 | ret = 0; | ||
42 | } | ||
43 | - goto unlock; | ||
44 | + return ret; | ||
45 | } | ||
31 | } | 46 | } |
32 | - timer_del(sleep_state->ts); | 47 | |
33 | + timer_del(&sleep_state->ts); | 48 | @@ -XXX,XX +XXX,XX @@ int hyperv_set_msg_handler(uint32_t conn_id, HvMsgHandler handler, void *data) |
34 | aio_co_wake(sleep_state->co); | 49 | } else { |
50 | ret = -ENOENT; | ||
51 | } | ||
52 | -unlock: | ||
53 | - qemu_mutex_unlock(&handlers_mutex); | ||
54 | + | ||
55 | return ret; | ||
35 | } | 56 | } |
36 | 57 | ||
37 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | 58 | @@ -XXX,XX +XXX,XX @@ static int set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier) |
38 | AioContext *ctx = qemu_get_current_aio_context(); | 59 | int ret; |
39 | QemuCoSleepState state = { | 60 | EventFlagHandler *handler; |
40 | .co = qemu_coroutine_self(), | 61 | |
41 | - .ts = aio_timer_new(ctx, type, SCALE_NS, co_sleep_cb, &state), | 62 | - qemu_mutex_lock(&handlers_mutex); |
42 | .user_state_pointer = sleep_state, | 63 | + QEMU_LOCK_GUARD(&handlers_mutex); |
43 | }; | 64 | QLIST_FOREACH(handler, &event_flag_handlers, link) { |
44 | 65 | if (handler->conn_id == conn_id) { | |
45 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | 66 | if (notifier) { |
46 | abort(); | 67 | @@ -XXX,XX +XXX,XX @@ static int set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier) |
68 | g_free_rcu(handler, rcu); | ||
69 | ret = 0; | ||
70 | } | ||
71 | - goto unlock; | ||
72 | + return ret; | ||
73 | } | ||
47 | } | 74 | } |
48 | 75 | ||
49 | + aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state); | 76 | @@ -XXX,XX +XXX,XX @@ static int set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier) |
50 | if (sleep_state) { | 77 | } else { |
51 | *sleep_state = &state; | 78 | ret = -ENOENT; |
52 | } | 79 | } |
53 | - timer_mod(state.ts, qemu_clock_get_ns(type) + ns); | 80 | -unlock: |
54 | + timer_mod(&state.ts, qemu_clock_get_ns(type) + ns); | 81 | - qemu_mutex_unlock(&handlers_mutex); |
55 | qemu_coroutine_yield(); | 82 | + |
56 | if (sleep_state) { | 83 | return ret; |
57 | /* | 84 | } |
58 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | 85 | |
59 | */ | 86 | diff --git a/hw/rdma/rdma_backend.c b/hw/rdma/rdma_backend.c |
60 | assert(*sleep_state == NULL); | 87 | index XXXXXXX..XXXXXXX 100644 |
88 | --- a/hw/rdma/rdma_backend.c | ||
89 | +++ b/hw/rdma/rdma_backend.c | ||
90 | @@ -XXX,XX +XXX,XX @@ static int rdma_poll_cq(RdmaDeviceResources *rdma_dev_res, struct ibv_cq *ibcq) | ||
91 | struct ibv_wc wc[2]; | ||
92 | RdmaProtectedGSList *cqe_ctx_list; | ||
93 | |||
94 | - qemu_mutex_lock(&rdma_dev_res->lock); | ||
95 | - do { | ||
96 | - ne = ibv_poll_cq(ibcq, ARRAY_SIZE(wc), wc); | ||
97 | + WITH_QEMU_LOCK_GUARD(&rdma_dev_res->lock) { | ||
98 | + do { | ||
99 | + ne = ibv_poll_cq(ibcq, ARRAY_SIZE(wc), wc); | ||
100 | |||
101 | - trace_rdma_poll_cq(ne, ibcq); | ||
102 | + trace_rdma_poll_cq(ne, ibcq); | ||
103 | |||
104 | - for (i = 0; i < ne; i++) { | ||
105 | - bctx = rdma_rm_get_cqe_ctx(rdma_dev_res, wc[i].wr_id); | ||
106 | - if (unlikely(!bctx)) { | ||
107 | - rdma_error_report("No matching ctx for req %"PRId64, | ||
108 | - wc[i].wr_id); | ||
109 | - continue; | ||
110 | - } | ||
111 | + for (i = 0; i < ne; i++) { | ||
112 | + bctx = rdma_rm_get_cqe_ctx(rdma_dev_res, wc[i].wr_id); | ||
113 | + if (unlikely(!bctx)) { | ||
114 | + rdma_error_report("No matching ctx for req %"PRId64, | ||
115 | + wc[i].wr_id); | ||
116 | + continue; | ||
117 | + } | ||
118 | |||
119 | - comp_handler(bctx->up_ctx, &wc[i]); | ||
120 | + comp_handler(bctx->up_ctx, &wc[i]); | ||
121 | |||
122 | - if (bctx->backend_qp) { | ||
123 | - cqe_ctx_list = &bctx->backend_qp->cqe_ctx_list; | ||
124 | - } else { | ||
125 | - cqe_ctx_list = &bctx->backend_srq->cqe_ctx_list; | ||
126 | - } | ||
127 | + if (bctx->backend_qp) { | ||
128 | + cqe_ctx_list = &bctx->backend_qp->cqe_ctx_list; | ||
129 | + } else { | ||
130 | + cqe_ctx_list = &bctx->backend_srq->cqe_ctx_list; | ||
131 | + } | ||
132 | |||
133 | - rdma_protected_gslist_remove_int32(cqe_ctx_list, wc[i].wr_id); | ||
134 | - rdma_rm_dealloc_cqe_ctx(rdma_dev_res, wc[i].wr_id); | ||
135 | - g_free(bctx); | ||
136 | - } | ||
137 | - total_ne += ne; | ||
138 | - } while (ne > 0); | ||
139 | - atomic_sub(&rdma_dev_res->stats.missing_cqe, total_ne); | ||
140 | - qemu_mutex_unlock(&rdma_dev_res->lock); | ||
141 | + rdma_protected_gslist_remove_int32(cqe_ctx_list, wc[i].wr_id); | ||
142 | + rdma_rm_dealloc_cqe_ctx(rdma_dev_res, wc[i].wr_id); | ||
143 | + g_free(bctx); | ||
144 | + } | ||
145 | + total_ne += ne; | ||
146 | + } while (ne > 0); | ||
147 | + atomic_sub(&rdma_dev_res->stats.missing_cqe, total_ne); | ||
148 | + } | ||
149 | |||
150 | if (ne < 0) { | ||
151 | rdma_error_report("ibv_poll_cq fail, rc=%d, errno=%d", ne, errno); | ||
152 | diff --git a/hw/rdma/rdma_rm.c b/hw/rdma/rdma_rm.c | ||
153 | index XXXXXXX..XXXXXXX 100644 | ||
154 | --- a/hw/rdma/rdma_rm.c | ||
155 | +++ b/hw/rdma/rdma_rm.c | ||
156 | @@ -XXX,XX +XXX,XX @@ static inline void rdma_res_tbl_dealloc(RdmaRmResTbl *tbl, uint32_t handle) | ||
157 | { | ||
158 | trace_rdma_res_tbl_dealloc(tbl->name, handle); | ||
159 | |||
160 | - qemu_mutex_lock(&tbl->lock); | ||
161 | + QEMU_LOCK_GUARD(&tbl->lock); | ||
162 | |||
163 | if (handle < tbl->tbl_sz) { | ||
164 | clear_bit(handle, tbl->bitmap); | ||
165 | tbl->used--; | ||
61 | } | 166 | } |
62 | - timer_free(state.ts); | 167 | |
168 | - qemu_mutex_unlock(&tbl->lock); | ||
63 | } | 169 | } |
170 | |||
171 | int rdma_rm_alloc_pd(RdmaDeviceResources *dev_res, RdmaBackendDev *backend_dev, | ||
64 | -- | 172 | -- |
65 | 2.31.1 | 173 | 2.25.3 |
66 | 174 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Paolo Bonzini <pbonzini@redhat.com> | ||
2 | 1 | ||
3 | All callers of qemu_co_sleep_wake are checking whether they are passing | ||
4 | a NULL argument inside the pointer-to-pointer: do the check in | ||
5 | qemu_co_sleep_wake itself. | ||
6 | |||
7 | As a side effect, qemu_co_sleep_wake can be called more than once and | ||
8 | it will only wake the coroutine once; after the first time, the argument | ||
9 | will be set to NULL via *sleep_state->user_state_pointer. However, this | ||
10 | would not be safe unless co_sleep_cb keeps using the QemuCoSleepState* | ||
11 | directly, so make it go through the pointer-to-pointer instead. | ||
12 | |||
13 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
14 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
15 | Message-id: 20210517100548.28806-4-pbonzini@redhat.com | ||
16 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
17 | --- | ||
18 | block/block-copy.c | 4 +--- | ||
19 | block/nbd.c | 8 ++------ | ||
20 | util/qemu-coroutine-sleep.c | 21 ++++++++++++--------- | ||
21 | 3 files changed, 15 insertions(+), 18 deletions(-) | ||
22 | |||
23 | diff --git a/block/block-copy.c b/block/block-copy.c | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/block/block-copy.c | ||
26 | +++ b/block/block-copy.c | ||
27 | @@ -XXX,XX +XXX,XX @@ out: | ||
28 | |||
29 | void block_copy_kick(BlockCopyCallState *call_state) | ||
30 | { | ||
31 | - if (call_state->sleep_state) { | ||
32 | - qemu_co_sleep_wake(call_state->sleep_state); | ||
33 | - } | ||
34 | + qemu_co_sleep_wake(call_state->sleep_state); | ||
35 | } | ||
36 | |||
37 | /* | ||
38 | diff --git a/block/nbd.c b/block/nbd.c | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/block/nbd.c | ||
41 | +++ b/block/nbd.c | ||
42 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn nbd_client_co_drain_begin(BlockDriverState *bs) | ||
43 | BDRVNBDState *s = (BDRVNBDState *)bs->opaque; | ||
44 | |||
45 | s->drained = true; | ||
46 | - if (s->connection_co_sleep_ns_state) { | ||
47 | - qemu_co_sleep_wake(s->connection_co_sleep_ns_state); | ||
48 | - } | ||
49 | + qemu_co_sleep_wake(s->connection_co_sleep_ns_state); | ||
50 | |||
51 | nbd_co_establish_connection_cancel(bs, false); | ||
52 | |||
53 | @@ -XXX,XX +XXX,XX @@ static void nbd_teardown_connection(BlockDriverState *bs) | ||
54 | |||
55 | s->state = NBD_CLIENT_QUIT; | ||
56 | if (s->connection_co) { | ||
57 | - if (s->connection_co_sleep_ns_state) { | ||
58 | - qemu_co_sleep_wake(s->connection_co_sleep_ns_state); | ||
59 | - } | ||
60 | + qemu_co_sleep_wake(s->connection_co_sleep_ns_state); | ||
61 | nbd_co_establish_connection_cancel(bs, true); | ||
62 | } | ||
63 | if (qemu_in_coroutine()) { | ||
64 | diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c | ||
65 | index XXXXXXX..XXXXXXX 100644 | ||
66 | --- a/util/qemu-coroutine-sleep.c | ||
67 | +++ b/util/qemu-coroutine-sleep.c | ||
68 | @@ -XXX,XX +XXX,XX @@ struct QemuCoSleepState { | ||
69 | |||
70 | void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) | ||
71 | { | ||
72 | - /* Write of schedule protected by barrier write in aio_co_schedule */ | ||
73 | - const char *scheduled = qatomic_cmpxchg(&sleep_state->co->scheduled, | ||
74 | - qemu_co_sleep_ns__scheduled, NULL); | ||
75 | + if (sleep_state) { | ||
76 | + /* Write of schedule protected by barrier write in aio_co_schedule */ | ||
77 | + const char *scheduled = qatomic_cmpxchg(&sleep_state->co->scheduled, | ||
78 | + qemu_co_sleep_ns__scheduled, NULL); | ||
79 | |||
80 | - assert(scheduled == qemu_co_sleep_ns__scheduled); | ||
81 | - *sleep_state->user_state_pointer = NULL; | ||
82 | - timer_del(&sleep_state->ts); | ||
83 | - aio_co_wake(sleep_state->co); | ||
84 | + assert(scheduled == qemu_co_sleep_ns__scheduled); | ||
85 | + *sleep_state->user_state_pointer = NULL; | ||
86 | + timer_del(&sleep_state->ts); | ||
87 | + aio_co_wake(sleep_state->co); | ||
88 | + } | ||
89 | } | ||
90 | |||
91 | static void co_sleep_cb(void *opaque) | ||
92 | { | ||
93 | - qemu_co_sleep_wake(opaque); | ||
94 | + QemuCoSleepState **sleep_state = opaque; | ||
95 | + qemu_co_sleep_wake(*sleep_state); | ||
96 | } | ||
97 | |||
98 | void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | ||
99 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | ||
100 | abort(); | ||
101 | } | ||
102 | |||
103 | - aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state); | ||
104 | + aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, sleep_state); | ||
105 | *sleep_state = &state; | ||
106 | timer_mod(&state.ts, qemu_clock_get_ns(type) + ns); | ||
107 | qemu_coroutine_yield(); | ||
108 | -- | ||
109 | 2.31.1 | ||
110 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Paolo Bonzini <pbonzini@redhat.com> | ||
2 | 1 | ||
3 | This simplification is enabled by the previous patch. Now aio_co_wake | ||
4 | will only be called once, therefore we do not care about a spurious | ||
5 | firing of the timer after a qemu_co_sleep_wake. | ||
6 | |||
7 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
8 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
9 | Message-id: 20210517100548.28806-5-pbonzini@redhat.com | ||
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
11 | --- | ||
12 | util/qemu-coroutine-sleep.c | 8 ++++---- | ||
13 | 1 file changed, 4 insertions(+), 4 deletions(-) | ||
14 | |||
15 | diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/util/qemu-coroutine-sleep.c | ||
18 | +++ b/util/qemu-coroutine-sleep.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static const char *qemu_co_sleep_ns__scheduled = "qemu_co_sleep_ns"; | ||
20 | |||
21 | struct QemuCoSleepState { | ||
22 | Coroutine *co; | ||
23 | - QEMUTimer ts; | ||
24 | QemuCoSleepState **user_state_pointer; | ||
25 | }; | ||
26 | |||
27 | @@ -XXX,XX +XXX,XX @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) | ||
28 | |||
29 | assert(scheduled == qemu_co_sleep_ns__scheduled); | ||
30 | *sleep_state->user_state_pointer = NULL; | ||
31 | - timer_del(&sleep_state->ts); | ||
32 | aio_co_wake(sleep_state->co); | ||
33 | } | ||
34 | } | ||
35 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | ||
36 | QemuCoSleepState **sleep_state) | ||
37 | { | ||
38 | AioContext *ctx = qemu_get_current_aio_context(); | ||
39 | + QEMUTimer ts; | ||
40 | QemuCoSleepState state = { | ||
41 | .co = qemu_coroutine_self(), | ||
42 | .user_state_pointer = sleep_state, | ||
43 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | ||
44 | abort(); | ||
45 | } | ||
46 | |||
47 | - aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, sleep_state); | ||
48 | + aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, sleep_state); | ||
49 | *sleep_state = &state; | ||
50 | - timer_mod(&state.ts, qemu_clock_get_ns(type) + ns); | ||
51 | + timer_mod(&ts, qemu_clock_get_ns(type) + ns); | ||
52 | qemu_coroutine_yield(); | ||
53 | + timer_del(&ts); | ||
54 | |||
55 | /* qemu_co_sleep_wake clears *sleep_state before resuming this coroutine. */ | ||
56 | assert(*sleep_state == NULL); | ||
57 | -- | ||
58 | 2.31.1 | ||
59 | diff view generated by jsdifflib |