* [PATCH v3 0/5] coroutine: Clean up includes
@ 2022-12-21 13:14 Markus Armbruster
2022-12-21 13:14 ` [PATCH v3 1/5] coroutine: Clean up superfluous inclusion of qemu/coroutine.h Markus Armbruster
` (5 more replies)
0 siblings, 6 replies; 13+ messages in thread
From: Markus Armbruster @ 2022-12-21 13:14 UTC (permalink / raw)
To: qemu-devel; +Cc: stefanha, kwolf, pbonzini
v3:
* PATCH 4: Unnecessary hunks dropped
v2:
* Rebased
* PATCH 4: Rewritten [Paolo]
* PATCH 5: New
Markus Armbruster (5):
coroutine: Clean up superfluous inclusion of qemu/coroutine.h
coroutine: Move coroutine_fn to qemu/osdep.h, trim includes
coroutine: Clean up superfluous inclusion of qemu/lockable.h
coroutine: Split qemu/coroutine-core.h off qemu/coroutine.h
coroutine: Use Coroutine typedef name instead of structure tag
crypto/block-luks-priv.h | 1 -
hw/9pfs/coth.h | 2 +-
include/block/aio.h | 9 +-
include/block/aio_task.h | 2 -
include/block/block-common.h | 1 -
include/block/graph-lock.h | 2 -
include/block/raw-aio.h | 1 -
include/io/channel.h | 2 +-
include/monitor/hmp.h | 1 -
include/qemu/coroutine-core.h | 154 ++++++++++++++++++++++++++++++++++
include/qemu/coroutine.h | 113 ++-----------------------
include/qemu/lockable.h | 2 +-
include/qemu/osdep.h | 16 ++++
include/qemu/progress_meter.h | 2 +-
include/qemu/typedefs.h | 1 -
include/scsi/pr-manager.h | 1 -
nbd/nbd-internal.h | 1 -
block/progress_meter.c | 2 +
blockjob.c | 1 -
crypto/block-luks.c | 1 -
hw/9pfs/codir.c | 1 -
hw/9pfs/cofile.c | 1 -
hw/9pfs/cofs.c | 1 -
hw/9pfs/coxattr.c | 1 -
nbd/client-connection.c | 1 +
tests/unit/test-aio.c | 2 +-
tests/unit/test-coroutine.c | 2 -
tests/unit/test-vmstate.c | 1 -
ui/console.c | 1 +
util/async.c | 4 +-
util/qemu-coroutine-lock.c | 1 -
util/qemu-coroutine-sleep.c | 1 -
util/qemu-coroutine.c | 1 -
33 files changed, 192 insertions(+), 141 deletions(-)
create mode 100644 include/qemu/coroutine-core.h
--
2.38.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3 1/5] coroutine: Clean up superfluous inclusion of qemu/coroutine.h
2022-12-21 13:14 [PATCH v3 0/5] coroutine: Clean up includes Markus Armbruster
@ 2022-12-21 13:14 ` Markus Armbruster
2022-12-21 13:14 ` [PATCH v3 2/5] coroutine: Move coroutine_fn to qemu/osdep.h, trim includes Markus Armbruster
` (4 subsequent siblings)
5 siblings, 0 replies; 13+ messages in thread
From: Markus Armbruster @ 2022-12-21 13:14 UTC (permalink / raw)
To: qemu-devel; +Cc: stefanha, kwolf, pbonzini
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
crypto/block-luks-priv.h | 1 -
include/block/raw-aio.h | 1 -
include/scsi/pr-manager.h | 1 -
nbd/nbd-internal.h | 1 -
blockjob.c | 1 -
crypto/block-luks.c | 1 -
hw/9pfs/codir.c | 1 -
hw/9pfs/cofile.c | 1 -
hw/9pfs/cofs.c | 1 -
hw/9pfs/coxattr.c | 1 -
tests/unit/test-coroutine.c | 1 -
tests/unit/test-vmstate.c | 1 -
util/qemu-coroutine-lock.c | 1 -
util/qemu-coroutine-sleep.c | 1 -
util/qemu-coroutine.c | 1 -
15 files changed, 15 deletions(-)
diff --git a/crypto/block-luks-priv.h b/crypto/block-luks-priv.h
index 90a20d432b..dc2dd14e52 100644
--- a/crypto/block-luks-priv.h
+++ b/crypto/block-luks-priv.h
@@ -31,7 +31,6 @@
#include "crypto/random.h"
#include "qemu/uuid.h"
-#include "qemu/coroutine.h"
#include "qemu/bitmap.h"
/*
diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h
index 21fc10c4c9..f8cda9df91 100644
--- a/include/block/raw-aio.h
+++ b/include/block/raw-aio.h
@@ -17,7 +17,6 @@
#define QEMU_RAW_AIO_H
#include "block/aio.h"
-#include "qemu/coroutine.h"
#include "qemu/iov.h"
/* AIO request types */
diff --git a/include/scsi/pr-manager.h b/include/scsi/pr-manager.h
index e4ecbe00f6..45de28d354 100644
--- a/include/scsi/pr-manager.h
+++ b/include/scsi/pr-manager.h
@@ -5,7 +5,6 @@
#include "qapi/visitor.h"
#include "qom/object_interfaces.h"
#include "block/aio.h"
-#include "qemu/coroutine.h"
#define TYPE_PR_MANAGER "pr-manager"
diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h
index 1b2141ab4b..df42fef706 100644
--- a/nbd/nbd-internal.h
+++ b/nbd/nbd-internal.h
@@ -13,7 +13,6 @@
#include "sysemu/block-backend.h"
#include "io/channel-tls.h"
-#include "qemu/coroutine.h"
#include "qemu/iov.h"
#ifndef _WIN32
diff --git a/blockjob.c b/blockjob.c
index b7daf2a9f6..54b4091a36 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -32,7 +32,6 @@
#include "qapi/error.h"
#include "qapi/qapi-events-block-core.h"
#include "qapi/qmp/qerror.h"
-#include "qemu/coroutine.h"
#include "qemu/main-loop.h"
#include "qemu/timer.h"
diff --git a/crypto/block-luks.c b/crypto/block-luks.c
index ff9e3945d1..5688783ab1 100644
--- a/crypto/block-luks.c
+++ b/crypto/block-luks.c
@@ -32,7 +32,6 @@
#include "crypto/random.h"
#include "qemu/uuid.h"
-#include "qemu/coroutine.h"
#include "qemu/bitmap.h"
/*
diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
index 93ba44fb75..7ba63be489 100644
--- a/hw/9pfs/codir.c
+++ b/hw/9pfs/codir.c
@@ -19,7 +19,6 @@
#include "qemu/osdep.h"
#include "fsdev/qemu-fsdev.h"
#include "qemu/thread.h"
-#include "qemu/coroutine.h"
#include "qemu/main-loop.h"
#include "coth.h"
#include "9p-xattr.h"
diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c
index 20f93a90e7..9c5344039e 100644
--- a/hw/9pfs/cofile.c
+++ b/hw/9pfs/cofile.c
@@ -19,7 +19,6 @@
#include "qemu/osdep.h"
#include "fsdev/qemu-fsdev.h"
#include "qemu/thread.h"
-#include "qemu/coroutine.h"
#include "qemu/main-loop.h"
#include "coth.h"
diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
index 9d0adc2e78..67e3ae5c5c 100644
--- a/hw/9pfs/cofs.c
+++ b/hw/9pfs/cofs.c
@@ -19,7 +19,6 @@
#include "qemu/osdep.h"
#include "fsdev/qemu-fsdev.h"
#include "qemu/thread.h"
-#include "qemu/coroutine.h"
#include "qemu/main-loop.h"
#include "coth.h"
diff --git a/hw/9pfs/coxattr.c b/hw/9pfs/coxattr.c
index dbcd09e0fd..cd0f8488ac 100644
--- a/hw/9pfs/coxattr.c
+++ b/hw/9pfs/coxattr.c
@@ -19,7 +19,6 @@
#include "qemu/osdep.h"
#include "fsdev/qemu-fsdev.h"
#include "qemu/thread.h"
-#include "qemu/coroutine.h"
#include "qemu/main-loop.h"
#include "coth.h"
diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c
index e16b80c245..513800d3db 100644
--- a/tests/unit/test-coroutine.c
+++ b/tests/unit/test-coroutine.c
@@ -12,7 +12,6 @@
*/
#include "qemu/osdep.h"
-#include "qemu/coroutine.h"
#include "qemu/coroutine_int.h"
#include "qemu/lockable.h"
diff --git a/tests/unit/test-vmstate.c b/tests/unit/test-vmstate.c
index 541bb4f63e..79357b29ca 100644
--- a/tests/unit/test-vmstate.c
+++ b/tests/unit/test-vmstate.c
@@ -29,7 +29,6 @@
#include "migration/qemu-file-types.h"
#include "../migration/qemu-file.h"
#include "../migration/savevm.h"
-#include "qemu/coroutine.h"
#include "qemu/module.h"
#include "io/channel-file.h"
diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c
index 45c6b57374..58f3f77181 100644
--- a/util/qemu-coroutine-lock.c
+++ b/util/qemu-coroutine-lock.c
@@ -27,7 +27,6 @@
*/
#include "qemu/osdep.h"
-#include "qemu/coroutine.h"
#include "qemu/coroutine_int.h"
#include "qemu/processor.h"
#include "qemu/queue.h"
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
index 571ab521ff..af59f9af98 100644
--- a/util/qemu-coroutine-sleep.c
+++ b/util/qemu-coroutine-sleep.c
@@ -12,7 +12,6 @@
*/
#include "qemu/osdep.h"
-#include "qemu/coroutine.h"
#include "qemu/coroutine_int.h"
#include "qemu/timer.h"
#include "block/aio.h"
diff --git a/util/qemu-coroutine.c b/util/qemu-coroutine.c
index 356b746f0b..8494523692 100644
--- a/util/qemu-coroutine.c
+++ b/util/qemu-coroutine.c
@@ -16,7 +16,6 @@
#include "trace.h"
#include "qemu/thread.h"
#include "qemu/atomic.h"
-#include "qemu/coroutine.h"
#include "qemu/coroutine_int.h"
#include "qemu/coroutine-tls.h"
#include "block/aio.h"
--
2.38.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 2/5] coroutine: Move coroutine_fn to qemu/osdep.h, trim includes
2022-12-21 13:14 [PATCH v3 0/5] coroutine: Clean up includes Markus Armbruster
2022-12-21 13:14 ` [PATCH v3 1/5] coroutine: Clean up superfluous inclusion of qemu/coroutine.h Markus Armbruster
@ 2022-12-21 13:14 ` Markus Armbruster
2022-12-21 13:14 ` [PATCH v3 3/5] coroutine: Clean up superfluous inclusion of qemu/lockable.h Markus Armbruster
` (3 subsequent siblings)
5 siblings, 0 replies; 13+ messages in thread
From: Markus Armbruster @ 2022-12-21 13:14 UTC (permalink / raw)
To: qemu-devel; +Cc: stefanha, kwolf, pbonzini
block/block-hmp-cmds.h and qemu/co-shared-resource.h use coroutine_fn
without including qemu/coroutine.h. They compile only if it's already
included from elsewhere.
I could fix that, but pulling in qemu/coroutine.h and everything it
includes just for a macro that expands into nothing feels silly.
Instead, move the macro to qemu/osdep.h.
Inclusions of qemu/coroutine.h just for coroutine_fn become
superfluous. Drop them.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
include/block/aio_task.h | 2 --
include/block/block-common.h | 1 -
include/block/graph-lock.h | 2 --
include/monitor/hmp.h | 1 -
include/qemu/coroutine.h | 18 +++++++-----------
include/qemu/osdep.h | 16 ++++++++++++++++
6 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/include/block/aio_task.h b/include/block/aio_task.h
index 50bc1e1817..18a9c41f4e 100644
--- a/include/block/aio_task.h
+++ b/include/block/aio_task.h
@@ -25,8 +25,6 @@
#ifndef BLOCK_AIO_TASK_H
#define BLOCK_AIO_TASK_H
-#include "qemu/coroutine.h"
-
typedef struct AioTaskPool AioTaskPool;
typedef struct AioTask AioTask;
typedef int coroutine_fn (*AioTaskFunc)(AioTask *task);
diff --git a/include/block/block-common.h b/include/block/block-common.h
index 4749c46a5e..434ffc5d34 100644
--- a/include/block/block-common.h
+++ b/include/block/block-common.h
@@ -27,7 +27,6 @@
#include "block/aio.h"
#include "block/aio-wait.h"
#include "qemu/iov.h"
-#include "qemu/coroutine.h"
#include "block/accounting.h"
#include "qemu/hbitmap.h"
#include "qemu/transactions.h"
diff --git a/include/block/graph-lock.h b/include/block/graph-lock.h
index 4c92cd8edf..3ab924d5e2 100644
--- a/include/block/graph-lock.h
+++ b/include/block/graph-lock.h
@@ -23,8 +23,6 @@
#include "qemu/osdep.h"
#include "qemu/clang-tsa.h"
-#include "qemu/coroutine.h"
-
/**
* Graph Lock API
* This API provides a rwlock used to protect block layer
diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h
index dfbc0c9a2f..c92f69da8b 100644
--- a/include/monitor/hmp.h
+++ b/include/monitor/hmp.h
@@ -15,7 +15,6 @@
#define HMP_H
#include "qemu/readline.h"
-#include "qemu/coroutine.h"
#include "qapi/qapi-types-common.h"
bool hmp_handle_error(Monitor *mon, Error *err);
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
index 89650a2d7f..2496a4f4ef 100644
--- a/include/qemu/coroutine.h
+++ b/include/qemu/coroutine.h
@@ -26,23 +26,19 @@
* waiting for events to complete.
*
* These functions are re-entrant and may be used outside the global mutex.
- */
-
-/**
- * Mark a function that executes in coroutine context
*
- * Functions that execute in coroutine context cannot be called directly from
- * normal functions. In the future it would be nice to enable compiler or
- * static checker support for catching such errors. This annotation might make
- * it possible and in the meantime it serves as documentation.
- *
- * For example:
+ * Functions that execute in coroutine context cannot be called
+ * directly from normal functions. Use @coroutine_fn to mark such
+ * functions. For example:
*
* static void coroutine_fn foo(void) {
* ....
* }
+ *
+ * In the future it would be nice to have the compiler or a static
+ * checker catch misuse of such functions. This annotation might make
+ * it possible and in the meantime it serves as documentation.
*/
-#define coroutine_fn
typedef struct Coroutine Coroutine;
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index b9c4307779..8e97e5d79a 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -157,6 +157,22 @@ extern "C" {
#include "qemu/typedefs.h"
+/**
+ * Mark a function that executes in coroutine context
+ *
+ * Functions that execute in coroutine context cannot be called directly from
+ * normal functions. In the future it would be nice to enable compiler or
+ * static checker support for catching such errors. This annotation might make
+ * it possible and in the meantime it serves as documentation.
+ *
+ * For example:
+ *
+ * static void coroutine_fn foo(void) {
+ * ....
+ * }
+ */
+#define coroutine_fn
+
/*
* For mingw, as of v6.0.0, the function implementing the assert macro is
* not marked as noreturn, so the compiler cannot delete code following an
--
2.38.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 3/5] coroutine: Clean up superfluous inclusion of qemu/lockable.h
2022-12-21 13:14 [PATCH v3 0/5] coroutine: Clean up includes Markus Armbruster
2022-12-21 13:14 ` [PATCH v3 1/5] coroutine: Clean up superfluous inclusion of qemu/coroutine.h Markus Armbruster
2022-12-21 13:14 ` [PATCH v3 2/5] coroutine: Move coroutine_fn to qemu/osdep.h, trim includes Markus Armbruster
@ 2022-12-21 13:14 ` Markus Armbruster
2022-12-21 13:14 ` [PATCH v3 4/5] coroutine: Split qemu/coroutine-core.h off qemu/coroutine.h Markus Armbruster
` (2 subsequent siblings)
5 siblings, 0 replies; 13+ messages in thread
From: Markus Armbruster @ 2022-12-21 13:14 UTC (permalink / raw)
To: qemu-devel; +Cc: stefanha, kwolf, pbonzini
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
include/qemu/progress_meter.h | 2 +-
block/progress_meter.c | 2 ++
tests/unit/test-coroutine.c | 1 -
3 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/include/qemu/progress_meter.h b/include/qemu/progress_meter.h
index dadf822bbf..0f2c0a32d2 100644
--- a/include/qemu/progress_meter.h
+++ b/include/qemu/progress_meter.h
@@ -27,7 +27,7 @@
#ifndef QEMU_PROGRESS_METER_H
#define QEMU_PROGRESS_METER_H
-#include "qemu/lockable.h"
+#include "qemu/thread.h"
typedef struct ProgressMeter {
/**
diff --git a/block/progress_meter.c b/block/progress_meter.c
index aa2e60248c..31a170a2cd 100644
--- a/block/progress_meter.c
+++ b/block/progress_meter.c
@@ -23,7 +23,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+
#include "qemu/osdep.h"
+#include "qemu/coroutine.h"
#include "qemu/progress_meter.h"
void progress_init(ProgressMeter *pm)
diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c
index 513800d3db..b0d21d673a 100644
--- a/tests/unit/test-coroutine.c
+++ b/tests/unit/test-coroutine.c
@@ -13,7 +13,6 @@
#include "qemu/osdep.h"
#include "qemu/coroutine_int.h"
-#include "qemu/lockable.h"
/*
* Check that qemu_in_coroutine() works
--
2.38.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 4/5] coroutine: Split qemu/coroutine-core.h off qemu/coroutine.h
2022-12-21 13:14 [PATCH v3 0/5] coroutine: Clean up includes Markus Armbruster
` (2 preceding siblings ...)
2022-12-21 13:14 ` [PATCH v3 3/5] coroutine: Clean up superfluous inclusion of qemu/lockable.h Markus Armbruster
@ 2022-12-21 13:14 ` Markus Armbruster
2022-12-22 8:01 ` Paolo Bonzini
2022-12-21 13:14 ` [PATCH v3 5/5] coroutine: Use Coroutine typedef name instead of structure tag Markus Armbruster
2022-12-21 21:47 ` [PATCH v3 0/5] coroutine: Clean up includes Philippe Mathieu-Daudé
5 siblings, 1 reply; 13+ messages in thread
From: Markus Armbruster @ 2022-12-21 13:14 UTC (permalink / raw)
To: qemu-devel; +Cc: stefanha, kwolf, pbonzini
qemu/coroutine.h and qemu/lockable.h include each other.
They need each other only in macro expansions, so we could simply drop
both inclusions to break the loop, and add suitable includes to files
that expand the macros.
Instead, move a part of qemu/coroutine.h to new qemu/coroutine-core.h
so that qemu/coroutine-core.h doesn't need qemu/lockable.h, and
qemu/lockable.h only needs qemu/coroutine-core.h. Result:
qemu/coroutine.h includes qemu/lockable.h includes
qemu/coroutine-core.h.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
hw/9pfs/coth.h | 2 +-
include/block/aio.h | 2 +-
include/io/channel.h | 2 +-
include/qemu/coroutine-core.h | 154 ++++++++++++++++++++++++++++++++++
include/qemu/coroutine.h | 97 +--------------------
include/qemu/lockable.h | 2 +-
include/qemu/typedefs.h | 1 -
nbd/client-connection.c | 1 +
tests/unit/test-aio.c | 2 +-
ui/console.c | 1 +
10 files changed, 162 insertions(+), 102 deletions(-)
create mode 100644 include/qemu/coroutine-core.h
diff --git a/hw/9pfs/coth.h b/hw/9pfs/coth.h
index 1a1edbdc2a..2c54249b35 100644
--- a/hw/9pfs/coth.h
+++ b/hw/9pfs/coth.h
@@ -16,7 +16,7 @@
#define QEMU_9P_COTH_H
#include "qemu/thread.h"
-#include "qemu/coroutine.h"
+#include "qemu/coroutine-core.h"
#include "9p.h"
/*
diff --git a/include/block/aio.h b/include/block/aio.h
index 0f65a3cc9e..3a546e7515 100644
--- a/include/block/aio.h
+++ b/include/block/aio.h
@@ -17,7 +17,7 @@
#ifdef CONFIG_LINUX_IO_URING
#include <liburing.h>
#endif
-#include "qemu/coroutine.h"
+#include "qemu/coroutine-core.h"
#include "qemu/queue.h"
#include "qemu/event_notifier.h"
#include "qemu/thread.h"
diff --git a/include/io/channel.h b/include/io/channel.h
index f1b7e05f81..78b15f7870 100644
--- a/include/io/channel.h
+++ b/include/io/channel.h
@@ -22,7 +22,7 @@
#define QIO_CHANNEL_H
#include "qom/object.h"
-#include "qemu/coroutine.h"
+#include "qemu/coroutine-core.h"
#include "block/aio.h"
#define TYPE_QIO_CHANNEL "qio-channel"
diff --git a/include/qemu/coroutine-core.h b/include/qemu/coroutine-core.h
new file mode 100644
index 0000000000..230bb56517
--- /dev/null
+++ b/include/qemu/coroutine-core.h
@@ -0,0 +1,154 @@
+/*
+ * QEMU coroutine implementation
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
+ * Kevin Wolf <kwolf@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#ifndef QEMU_COROUTINE_CORE_H
+#define QEMU_COROUTINE_CORE_H
+
+/**
+ * Coroutines are a mechanism for stack switching and can be used for
+ * cooperative userspace threading. These functions provide a simple but
+ * useful flavor of coroutines that is suitable for writing sequential code,
+ * rather than callbacks, for operations that need to give up control while
+ * waiting for events to complete.
+ *
+ * These functions are re-entrant and may be used outside the global mutex.
+ *
+ * Functions that execute in coroutine context cannot be called
+ * directly from normal functions. Use @coroutine_fn to mark such
+ * functions. For example:
+ *
+ * static void coroutine_fn foo(void) {
+ * ....
+ * }
+ *
+ * In the future it would be nice to have the compiler or a static
+ * checker catch misuse of such functions. This annotation might make
+ * it possible and in the meantime it serves as documentation.
+ */
+
+/**
+ * Mark a function that executes in coroutine context
+ *
+ *
+ * Functions that execute in coroutine context cannot be called
+ * directly from normal functions. Use @coroutine_fn to mark such
+ * functions. For example:
+ *
+ * static void coroutine_fn foo(void) {
+ * ....
+ * }
+ *
+ * In the future it would be nice to have the compiler or a static
+ * checker catch misuse of such functions. This annotation might make
+ * it possible and in the meantime it serves as documentation.
+ */
+
+typedef struct Coroutine Coroutine;
+typedef struct CoMutex CoMutex;
+
+/**
+ * Coroutine entry point
+ *
+ * When the coroutine is entered for the first time, opaque is passed in as an
+ * argument.
+ *
+ * When this function returns, the coroutine is destroyed automatically and
+ * execution continues in the caller who last entered the coroutine.
+ */
+typedef void coroutine_fn CoroutineEntry(void *opaque);
+
+/**
+ * Create a new coroutine
+ *
+ * Use qemu_coroutine_enter() to actually transfer control to the coroutine.
+ * The opaque argument is passed as the argument to the entry point.
+ */
+Coroutine *qemu_coroutine_create(CoroutineEntry *entry, void *opaque);
+
+/**
+ * Transfer control to a coroutine
+ */
+void qemu_coroutine_enter(Coroutine *coroutine);
+
+/**
+ * Transfer control to a coroutine if it's not active (i.e. part of the call
+ * stack of the running coroutine). Otherwise, do nothing.
+ */
+void qemu_coroutine_enter_if_inactive(Coroutine *co);
+
+/**
+ * Transfer control to a coroutine and associate it with ctx
+ */
+void qemu_aio_coroutine_enter(AioContext *ctx, Coroutine *co);
+
+/**
+ * Transfer control back to a coroutine's caller
+ *
+ * This function does not return until the coroutine is re-entered using
+ * qemu_coroutine_enter().
+ */
+void coroutine_fn qemu_coroutine_yield(void);
+
+/**
+ * Get the AioContext of the given coroutine
+ */
+AioContext *qemu_coroutine_get_aio_context(Coroutine *co);
+
+/**
+ * Get the currently executing coroutine
+ */
+Coroutine *qemu_coroutine_self(void);
+
+/**
+ * Return whether or not currently inside a coroutine
+ *
+ * This can be used to write functions that work both when in coroutine context
+ * and when not in coroutine context. Note that such functions cannot use the
+ * coroutine_fn annotation since they work outside coroutine context.
+ */
+bool qemu_in_coroutine(void);
+
+/**
+ * Return true if the coroutine is currently entered
+ *
+ * A coroutine is "entered" if it has not yielded from the current
+ * qemu_coroutine_enter() call used to run it. This does not mean that the
+ * coroutine is currently executing code since it may have transferred control
+ * to another coroutine using qemu_coroutine_enter().
+ *
+ * When several coroutines enter each other there may be no way to know which
+ * ones have already been entered. In such situations this function can be
+ * used to avoid recursively entering coroutines.
+ */
+bool qemu_coroutine_entered(Coroutine *co);
+
+/**
+ * Initialises a CoMutex. This must be called before any other operation is used
+ * on the CoMutex.
+ */
+void qemu_co_mutex_init(CoMutex *mutex);
+
+/**
+ * Locks the mutex. If the lock cannot be taken immediately, control is
+ * transferred to the caller of the current coroutine.
+ */
+void coroutine_fn qemu_co_mutex_lock(CoMutex *mutex);
+
+/**
+ * Unlocks the mutex and schedules the next coroutine that was waiting for this
+ * lock to be run.
+ */
+void coroutine_fn qemu_co_mutex_unlock(CoMutex *mutex);
+
+#endif
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
index 2496a4f4ef..a65be6697f 100644
--- a/include/qemu/coroutine.h
+++ b/include/qemu/coroutine.h
@@ -15,6 +15,7 @@
#ifndef QEMU_COROUTINE_H
#define QEMU_COROUTINE_H
+#include "qemu/coroutine-core.h"
#include "qemu/queue.h"
#include "qemu/timer.h"
@@ -40,84 +41,6 @@
* it possible and in the meantime it serves as documentation.
*/
-typedef struct Coroutine Coroutine;
-
-/**
- * Coroutine entry point
- *
- * When the coroutine is entered for the first time, opaque is passed in as an
- * argument.
- *
- * When this function returns, the coroutine is destroyed automatically and
- * execution continues in the caller who last entered the coroutine.
- */
-typedef void coroutine_fn CoroutineEntry(void *opaque);
-
-/**
- * Create a new coroutine
- *
- * Use qemu_coroutine_enter() to actually transfer control to the coroutine.
- * The opaque argument is passed as the argument to the entry point.
- */
-Coroutine *qemu_coroutine_create(CoroutineEntry *entry, void *opaque);
-
-/**
- * Transfer control to a coroutine
- */
-void qemu_coroutine_enter(Coroutine *coroutine);
-
-/**
- * Transfer control to a coroutine if it's not active (i.e. part of the call
- * stack of the running coroutine). Otherwise, do nothing.
- */
-void qemu_coroutine_enter_if_inactive(Coroutine *co);
-
-/**
- * Transfer control to a coroutine and associate it with ctx
- */
-void qemu_aio_coroutine_enter(AioContext *ctx, Coroutine *co);
-
-/**
- * Transfer control back to a coroutine's caller
- *
- * This function does not return until the coroutine is re-entered using
- * qemu_coroutine_enter().
- */
-void coroutine_fn qemu_coroutine_yield(void);
-
-/**
- * Get the AioContext of the given coroutine
- */
-AioContext *qemu_coroutine_get_aio_context(Coroutine *co);
-
-/**
- * Get the currently executing coroutine
- */
-Coroutine *qemu_coroutine_self(void);
-
-/**
- * Return whether or not currently inside a coroutine
- *
- * This can be used to write functions that work both when in coroutine context
- * and when not in coroutine context. Note that such functions cannot use the
- * coroutine_fn annotation since they work outside coroutine context.
- */
-bool qemu_in_coroutine(void);
-
-/**
- * Return true if the coroutine is currently entered
- *
- * A coroutine is "entered" if it has not yielded from the current
- * qemu_coroutine_enter() call used to run it. This does not mean that the
- * coroutine is currently executing code since it may have transferred control
- * to another coroutine using qemu_coroutine_enter().
- *
- * When several coroutines enter each other there may be no way to know which
- * ones have already been entered. In such situations this function can be
- * used to avoid recursively entering coroutines.
- */
-bool qemu_coroutine_entered(Coroutine *co);
-
/**
* Provides a mutex that can be used to synchronise coroutines
*/
@@ -145,24 +68,6 @@ struct CoMutex {
Coroutine *holder;
};
-/**
- * Initialises a CoMutex. This must be called before any other operation is used
- * on the CoMutex.
- */
-void qemu_co_mutex_init(CoMutex *mutex);
-
-/**
- * Locks the mutex. If the lock cannot be taken immediately, control is
- * transferred to the caller of the current coroutine.
- */
-void coroutine_fn qemu_co_mutex_lock(CoMutex *mutex);
-
-/**
- * Unlocks the mutex and schedules the next coroutine that was waiting for this
- * lock to be run.
- */
-void coroutine_fn qemu_co_mutex_unlock(CoMutex *mutex);
-
/**
* Assert that the current coroutine holds @mutex.
*/
diff --git a/include/qemu/lockable.h b/include/qemu/lockable.h
index 86db7cb04c..9823220446 100644
--- a/include/qemu/lockable.h
+++ b/include/qemu/lockable.h
@@ -13,7 +13,7 @@
#ifndef QEMU_LOCKABLE_H
#define QEMU_LOCKABLE_H
-#include "qemu/coroutine.h"
+#include "qemu/coroutine-core.h"
#include "qemu/thread.h"
typedef void QemuLockUnlockFunc(void *);
diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
index 688408e048..0f7329b70f 100644
--- a/include/qemu/typedefs.h
+++ b/include/qemu/typedefs.h
@@ -37,7 +37,6 @@ typedef struct BusState BusState;
typedef struct Chardev Chardev;
typedef struct Clock Clock;
typedef struct CompatProperty CompatProperty;
-typedef struct CoMutex CoMutex;
typedef struct ConfidentialGuestSupport ConfidentialGuestSupport;
typedef struct CPUAddressSpace CPUAddressSpace;
typedef struct CPUArchState CPUArchState;
diff --git a/nbd/client-connection.c b/nbd/client-connection.c
index 0c5f917efa..e5b1046a1c 100644
--- a/nbd/client-connection.c
+++ b/nbd/client-connection.c
@@ -29,6 +29,7 @@
#include "qapi/qapi-visit-sockets.h"
#include "qapi/clone-visitor.h"
+#include "qemu/coroutine.h"
struct NBDClientConnection {
/* Initialization constants, never change */
diff --git a/tests/unit/test-aio.c b/tests/unit/test-aio.c
index 178048d2f2..321d7ab01a 100644
--- a/tests/unit/test-aio.c
+++ b/tests/unit/test-aio.c
@@ -16,7 +16,7 @@
#include "qemu/timer.h"
#include "qemu/sockets.h"
#include "qemu/error-report.h"
-#include "qemu/coroutine.h"
+#include "qemu/coroutine-core.h"
#include "qemu/main-loop.h"
static AioContext *ctx;
diff --git a/ui/console.c b/ui/console.c
index 9ff9217f9b..ab43561fe1 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -27,6 +27,7 @@
#include "hw/qdev-core.h"
#include "qapi/error.h"
#include "qapi/qapi-commands-ui.h"
+#include "qemu/coroutine.h"
#include "qemu/fifo8.h"
#include "qemu/main-loop.h"
#include "qemu/module.h"
--
2.38.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 5/5] coroutine: Use Coroutine typedef name instead of structure tag
2022-12-21 13:14 [PATCH v3 0/5] coroutine: Clean up includes Markus Armbruster
` (3 preceding siblings ...)
2022-12-21 13:14 ` [PATCH v3 4/5] coroutine: Split qemu/coroutine-core.h off qemu/coroutine.h Markus Armbruster
@ 2022-12-21 13:14 ` Markus Armbruster
2022-12-21 21:47 ` [PATCH v3 0/5] coroutine: Clean up includes Philippe Mathieu-Daudé
5 siblings, 0 replies; 13+ messages in thread
From: Markus Armbruster @ 2022-12-21 13:14 UTC (permalink / raw)
To: qemu-devel; +Cc: stefanha, kwolf, pbonzini, Philippe Mathieu-Daudé
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/block/aio.h | 7 +++----
util/async.c | 4 ++--
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/include/block/aio.h b/include/block/aio.h
index 3a546e7515..8fba6a3584 100644
--- a/include/block/aio.h
+++ b/include/block/aio.h
@@ -52,7 +52,6 @@ typedef void QEMUBHFunc(void *opaque);
typedef bool AioPollFn(void *opaque);
typedef void IOHandler(void *opaque);
-struct Coroutine;
struct ThreadPool;
struct LinuxAioState;
struct LuringState;
@@ -694,7 +693,7 @@ static inline bool aio_node_check(AioContext *ctx, bool is_external)
* is the context in which the coroutine is running (i.e. the value of
* qemu_get_current_aio_context() from the coroutine itself).
*/
-void aio_co_schedule(AioContext *ctx, struct Coroutine *co);
+void aio_co_schedule(AioContext *ctx, Coroutine *co);
/**
* aio_co_reschedule_self:
@@ -717,7 +716,7 @@ void coroutine_fn aio_co_reschedule_self(AioContext *new_ctx);
* context. The coroutine must not be entered by anyone else while
* aio_co_wake() is active.
*/
-void aio_co_wake(struct Coroutine *co);
+void aio_co_wake(Coroutine *co);
/**
* aio_co_enter:
@@ -726,7 +725,7 @@ void aio_co_wake(struct Coroutine *co);
*
* Enter a coroutine in the specified AioContext.
*/
-void aio_co_enter(AioContext *ctx, struct Coroutine *co);
+void aio_co_enter(AioContext *ctx, Coroutine *co);
/**
* Return the AioContext whose event loop runs in the current thread.
diff --git a/util/async.c b/util/async.c
index 14d63b3091..0657b75397 100644
--- a/util/async.c
+++ b/util/async.c
@@ -640,7 +640,7 @@ void coroutine_fn aio_co_reschedule_self(AioContext *new_ctx)
}
}
-void aio_co_wake(struct Coroutine *co)
+void aio_co_wake(Coroutine *co)
{
AioContext *ctx;
@@ -653,7 +653,7 @@ void aio_co_wake(struct Coroutine *co)
aio_co_enter(ctx, co);
}
-void aio_co_enter(AioContext *ctx, struct Coroutine *co)
+void aio_co_enter(AioContext *ctx, Coroutine *co)
{
if (ctx != qemu_get_current_aio_context()) {
aio_co_schedule(ctx, co);
--
2.38.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v3 0/5] coroutine: Clean up includes
2022-12-21 13:14 [PATCH v3 0/5] coroutine: Clean up includes Markus Armbruster
` (4 preceding siblings ...)
2022-12-21 13:14 ` [PATCH v3 5/5] coroutine: Use Coroutine typedef name instead of structure tag Markus Armbruster
@ 2022-12-21 21:47 ` Philippe Mathieu-Daudé
2022-12-22 5:21 ` Markus Armbruster
5 siblings, 1 reply; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2022-12-21 21:47 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel
Cc: stefanha, kwolf, pbonzini, Michael S. Tsirkin
On 21/12/22 14:14, Markus Armbruster wrote:
> v3:
> * PATCH 4: Unnecessary hunks dropped
>
> v2:
> * Rebased
> * PATCH 4: Rewritten [Paolo]
> * PATCH 5: New
>
> Markus Armbruster (5):
> coroutine: Clean up superfluous inclusion of qemu/coroutine.h
> coroutine: Move coroutine_fn to qemu/osdep.h, trim includes
> coroutine: Clean up superfluous inclusion of qemu/lockable.h
> coroutine: Split qemu/coroutine-core.h off qemu/coroutine.h
> coroutine: Use Coroutine typedef name instead of structure tag
I had to add:
-- >8 --
diff --git a/hw/pci/pci-hmp-cmds.c b/hw/pci/pci-hmp-cmds.c
index fb7591d6ab..b09fce9377 100644
--- a/hw/pci/pci-hmp-cmds.c
+++ b/hw/pci/pci-hmp-cmds.c
@@ -15,6 +15,7 @@
#include "qemu/osdep.h"
#include "hw/pci/pci.h"
+#include "hw/pci/pci_device.h"
#include "monitor/hmp.h"
#include "monitor/monitor.h"
#include "pci-internal.h"
diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c
index 8e7282658f..3d4497da99 100644
--- a/hw/virtio/virtio-qmp.c
+++ b/hw/virtio/virtio-qmp.c
@@ -11,6 +11,7 @@
#include "qemu/osdep.h"
#include "hw/virtio/virtio.h"
+#include "hw/virtio/vhost.h"
#include "virtio-qmp.h"
---
Otherwise I get:
../hw/pci/pci-hmp-cmds.c: In function ‘pcibus_dev_print’:
../hw/pci/pci-hmp-cmds.c:129:31: error: invalid use of incomplete
typedef ‘PCIDevice’
129 | int class = pci_get_word(d->config + PCI_CLASS_DEVICE);
| ^~
../hw/virtio/virtio-qmp.c:187:19: error:
‘VHOST_USER_F_PROTOCOL_FEATURES’ undeclared here (not in a function);
did you mean ‘VHOST_USER_PROTOCOL_F_RARP’?
187 | FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Maybe some recently merged change?
Otherwise:
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v3 0/5] coroutine: Clean up includes
2022-12-21 21:47 ` [PATCH v3 0/5] coroutine: Clean up includes Philippe Mathieu-Daudé
@ 2022-12-22 5:21 ` Markus Armbruster
2022-12-22 7:09 ` Philippe Mathieu-Daudé
2022-12-22 10:02 ` Markus Armbruster
0 siblings, 2 replies; 13+ messages in thread
From: Markus Armbruster @ 2022-12-22 5:21 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, stefanha, kwolf, pbonzini, Michael S. Tsirkin
Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> On 21/12/22 14:14, Markus Armbruster wrote:
>> v3:
>> * PATCH 4: Unnecessary hunks dropped
>> v2:
>> * Rebased
>> * PATCH 4: Rewritten [Paolo]
>> * PATCH 5: New
>> Markus Armbruster (5):
>> coroutine: Clean up superfluous inclusion of qemu/coroutine.h
>> coroutine: Move coroutine_fn to qemu/osdep.h, trim includes
>> coroutine: Clean up superfluous inclusion of qemu/lockable.h
>> coroutine: Split qemu/coroutine-core.h off qemu/coroutine.h
>> coroutine: Use Coroutine typedef name instead of structure tag
>
> I had to add:
>
> -- >8 --
> diff --git a/hw/pci/pci-hmp-cmds.c b/hw/pci/pci-hmp-cmds.c
> index fb7591d6ab..b09fce9377 100644
> --- a/hw/pci/pci-hmp-cmds.c
> +++ b/hw/pci/pci-hmp-cmds.c
> @@ -15,6 +15,7 @@
>
> #include "qemu/osdep.h"
> #include "hw/pci/pci.h"
> +#include "hw/pci/pci_device.h"
> #include "monitor/hmp.h"
> #include "monitor/monitor.h"
> #include "pci-internal.h"
> diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c
> index 8e7282658f..3d4497da99 100644
> --- a/hw/virtio/virtio-qmp.c
> +++ b/hw/virtio/virtio-qmp.c
> @@ -11,6 +11,7 @@
>
> #include "qemu/osdep.h"
> #include "hw/virtio/virtio.h"
> +#include "hw/virtio/vhost.h"
> #include "virtio-qmp.h"
>
> ---
>
> Otherwise I get:
>
> ../hw/pci/pci-hmp-cmds.c: In function ‘pcibus_dev_print’:
> ../hw/pci/pci-hmp-cmds.c:129:31: error: invalid use of incomplete typedef ‘PCIDevice’
> 129 | int class = pci_get_word(d->config + PCI_CLASS_DEVICE);
> | ^~
>
> ../hw/virtio/virtio-qmp.c:187:19: error: ‘VHOST_USER_F_PROTOCOL_FEATURES’ undeclared here (not in a function);
> did you mean ‘VHOST_USER_PROTOCOL_F_RARP’?
> 187 | FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
> Maybe some recently merged change?
Yes. I'll rebase.
> Otherwise:
> Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Thanks!
PS: While looking for commits that caused these conflicts, I saw
commit 28b629ab4aa93b9b7ec79c7e480611e4554586be
Signed-off-by: Philippe Mathieu-Daudé <a class="moz-txt-link-rfc2396E" href="mailto:philmd@linaro.org"><philmd@linaro.org></a>
commit 69779192acfeb9480183fd076be7480de56b1009
Signed-off-by: Philippe Mathieu-Daudé <a class="moz-txt-link-rfc2396E" href="mailto:philmd@linaro.org"><philmd@linaro.org></a>
commit f983e598e5a4eada5bfa4731c9db9fba1943e4e6
Suggested-by: Richard Henderson <a class="moz-txt-link-rfc2396E" href="mailto:richard.henderson@linaro.org"><richard.henderson@linaro.org></a>
Signed-off-by: Philippe Mathieu-Daudé <a class="moz-txt-link-rfc2396E" href="mailto:philmd@linaro.org"><philmd@linaro.org></a>
Please stop that :)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 0/5] coroutine: Clean up includes
2022-12-22 5:21 ` Markus Armbruster
@ 2022-12-22 7:09 ` Philippe Mathieu-Daudé
2022-12-22 10:02 ` Markus Armbruster
1 sibling, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2022-12-22 7:09 UTC (permalink / raw)
To: Markus Armbruster
Cc: qemu-devel, stefanha, kwolf, pbonzini, Michael S. Tsirkin
On 22/12/22 06:21, Markus Armbruster wrote:
> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> PS: While looking for commits that caused these conflicts, I saw
>
> commit 28b629ab4aa93b9b7ec79c7e480611e4554586be
> Signed-off-by: Philippe Mathieu-Daudé <a class="moz-txt-link-rfc2396E" href="mailto:philmd@linaro.org"><philmd@linaro.org></a>
>
> commit 69779192acfeb9480183fd076be7480de56b1009
> Signed-off-by: Philippe Mathieu-Daudé <a class="moz-txt-link-rfc2396E" href="mailto:philmd@linaro.org"><philmd@linaro.org></a>
>
> commit f983e598e5a4eada5bfa4731c9db9fba1943e4e6
> Suggested-by: Richard Henderson <a class="moz-txt-link-rfc2396E" href="mailto:richard.henderson@linaro.org"><richard.henderson@linaro.org></a>
> Signed-off-by: Philippe Mathieu-Daudé <a class="moz-txt-link-rfc2396E" href="mailto:philmd@linaro.org"><philmd@linaro.org></a>
>
> Please stop that :)
The original patch looks fine:
https://lore.kernel.org/qemu-devel/20221213111707.34921-7-philmd@linaro.org/
Michael, did you change something in your workflow?
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 4/5] coroutine: Split qemu/coroutine-core.h off qemu/coroutine.h
2022-12-21 13:14 ` [PATCH v3 4/5] coroutine: Split qemu/coroutine-core.h off qemu/coroutine.h Markus Armbruster
@ 2022-12-22 8:01 ` Paolo Bonzini
2022-12-22 8:56 ` Markus Armbruster
0 siblings, 1 reply; 13+ messages in thread
From: Paolo Bonzini @ 2022-12-22 8:01 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel; +Cc: stefanha, kwolf
On 12/21/22 14:14, Markus Armbruster wrote:
> +/**
> + * Mark a function that executes in coroutine context
> + *
> + *
> + * Functions that execute in coroutine context cannot be called
> + * directly from normal functions. Use @coroutine_fn to mark such
> + * functions. For example:
> + *
> + * static void coroutine_fn foo(void) {
> + * ....
> + * }
> + *
> + * In the future it would be nice to have the compiler or a static
> + * checker catch misuse of such functions. This annotation might make
> + * it possible and in the meantime it serves as documentation.
> + */
> +
Is it intentional that "#define coroutine_fn" is not here?
Paolo
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 4/5] coroutine: Split qemu/coroutine-core.h off qemu/coroutine.h
2022-12-22 8:01 ` Paolo Bonzini
@ 2022-12-22 8:56 ` Markus Armbruster
2022-12-22 11:14 ` Paolo Bonzini
0 siblings, 1 reply; 13+ messages in thread
From: Markus Armbruster @ 2022-12-22 8:56 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel, stefanha, kwolf
Paolo Bonzini <pbonzini@redhat.com> writes:
> On 12/21/22 14:14, Markus Armbruster wrote:
>> +/**
>> + * Mark a function that executes in coroutine context
>> + *
>> + *
>> + * Functions that execute in coroutine context cannot be called
>> + * directly from normal functions. Use @coroutine_fn to mark such
>> + * functions. For example:
>> + *
>> + * static void coroutine_fn foo(void) {
>> + * ....
>> + * }
>> + *
>> + * In the future it would be nice to have the compiler or a static
>> + * checker catch misuse of such functions. This annotation might make
>> + * it possible and in the meantime it serves as documentation.
>> + */
>> +
>
> Is it intentional that "#define coroutine_fn" is not here?
Yes: I moved it to qemu/osdep.h in PATCH 2, along with its doc comment.
To avoid compromising coroutine.h as overview documentation, I added
rephrased documentation there.
This patch copies this rephrased documentation to coroutine-core.h.
I'm open to better ideas.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 0/5] coroutine: Clean up includes
2022-12-22 5:21 ` Markus Armbruster
2022-12-22 7:09 ` Philippe Mathieu-Daudé
@ 2022-12-22 10:02 ` Markus Armbruster
1 sibling, 0 replies; 13+ messages in thread
From: Markus Armbruster @ 2022-12-22 10:02 UTC (permalink / raw)
To: qemu-devel
Cc: Philippe Mathieu-Daudé, stefanha, kwolf, pbonzini,
Michael S. Tsirkin
Markus Armbruster <armbru@redhat.com> writes:
> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
>
>> On 21/12/22 14:14, Markus Armbruster wrote:
>>> v3:
>>> * PATCH 4: Unnecessary hunks dropped
>>> v2:
>>> * Rebased
>>> * PATCH 4: Rewritten [Paolo]
>>> * PATCH 5: New
>>> Markus Armbruster (5):
>>> coroutine: Clean up superfluous inclusion of qemu/coroutine.h
>>> coroutine: Move coroutine_fn to qemu/osdep.h, trim includes
>>> coroutine: Clean up superfluous inclusion of qemu/lockable.h
>>> coroutine: Split qemu/coroutine-core.h off qemu/coroutine.h
>>> coroutine: Use Coroutine typedef name instead of structure tag
>>
>> I had to add:
>>
>> -- >8 --
>> diff --git a/hw/pci/pci-hmp-cmds.c b/hw/pci/pci-hmp-cmds.c
>> index fb7591d6ab..b09fce9377 100644
>> --- a/hw/pci/pci-hmp-cmds.c
>> +++ b/hw/pci/pci-hmp-cmds.c
>> @@ -15,6 +15,7 @@
>>
>> #include "qemu/osdep.h"
>> #include "hw/pci/pci.h"
>> +#include "hw/pci/pci_device.h"
>> #include "monitor/hmp.h"
>> #include "monitor/monitor.h"
>> #include "pci-internal.h"
>> diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c
>> index 8e7282658f..3d4497da99 100644
>> --- a/hw/virtio/virtio-qmp.c
>> +++ b/hw/virtio/virtio-qmp.c
>> @@ -11,6 +11,7 @@
>>
>> #include "qemu/osdep.h"
>> #include "hw/virtio/virtio.h"
>> +#include "hw/virtio/vhost.h"
>> #include "virtio-qmp.h"
>>
>> ---
>>
>> Otherwise I get:
>>
>> ../hw/pci/pci-hmp-cmds.c: In function ‘pcibus_dev_print’:
>> ../hw/pci/pci-hmp-cmds.c:129:31: error: invalid use of incomplete typedef ‘PCIDevice’
>> 129 | int class = pci_get_word(d->config + PCI_CLASS_DEVICE);
>> | ^~
>>
>> ../hw/virtio/virtio-qmp.c:187:19: error: ‘VHOST_USER_F_PROTOCOL_FEATURES’ undeclared here (not in a function);
>> did you mean ‘VHOST_USER_PROTOCOL_F_RARP’?
>> 187 | FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
>> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>>
>> Maybe some recently merged change?
>
> Yes. I'll rebase.
To avoid confusion: this series doesn't need a rebase. "[PATCH 0/5]
include/hw/pci include/hw/cxl: Clean up includes" does.
[...]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v3 4/5] coroutine: Split qemu/coroutine-core.h off qemu/coroutine.h
2022-12-22 8:56 ` Markus Armbruster
@ 2022-12-22 11:14 ` Paolo Bonzini
0 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2022-12-22 11:14 UTC (permalink / raw)
To: Markus Armbruster; +Cc: qemu-devel, stefanha, kwolf
On 12/22/22 09:56, Markus Armbruster wrote:
>>> +/**
>>> + * Mark a function that executes in coroutine context
>>> + *
>>> + *
>>> + * Functions that execute in coroutine context cannot be called
>>> + * directly from normal functions. Use @coroutine_fn to mark such
>>> + * functions. For example:
>>> + *
>>> + * static void coroutine_fn foo(void) {
>>> + * ....
>>> + * }
>>> + *
>>> + * In the future it would be nice to have the compiler or a static
>>> + * checker catch misuse of such functions. This annotation might make
>>> + * it possible and in the meantime it serves as documentation.
>>> + */
>>> +
>> Is it intentional that "#define coroutine_fn" is not here?
> Yes: I moved it to qemu/osdep.h in PATCH 2, along with its doc comment.
> To avoid compromising coroutine.h as overview documentation, I added
> rephrased documentation there.
Got it. coroutine.h is not included in the developer documentation so
that didn't occur to me but I understand it now.
Paolo
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2022-12-22 11:15 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-21 13:14 [PATCH v3 0/5] coroutine: Clean up includes Markus Armbruster
2022-12-21 13:14 ` [PATCH v3 1/5] coroutine: Clean up superfluous inclusion of qemu/coroutine.h Markus Armbruster
2022-12-21 13:14 ` [PATCH v3 2/5] coroutine: Move coroutine_fn to qemu/osdep.h, trim includes Markus Armbruster
2022-12-21 13:14 ` [PATCH v3 3/5] coroutine: Clean up superfluous inclusion of qemu/lockable.h Markus Armbruster
2022-12-21 13:14 ` [PATCH v3 4/5] coroutine: Split qemu/coroutine-core.h off qemu/coroutine.h Markus Armbruster
2022-12-22 8:01 ` Paolo Bonzini
2022-12-22 8:56 ` Markus Armbruster
2022-12-22 11:14 ` Paolo Bonzini
2022-12-21 13:14 ` [PATCH v3 5/5] coroutine: Use Coroutine typedef name instead of structure tag Markus Armbruster
2022-12-21 21:47 ` [PATCH v3 0/5] coroutine: Clean up includes Philippe Mathieu-Daudé
2022-12-22 5:21 ` Markus Armbruster
2022-12-22 7:09 ` Philippe Mathieu-Daudé
2022-12-22 10:02 ` Markus Armbruster
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).