coroutine: Clean up includes
Subsystems (4)
v2 cover coroutine: Clean up includes
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.c | 2 +- block/block-copy.c | 2 +- block/io_uring.c | 2 +- block/linux-aio.c | 2 +- block/mirror.c | 2 +- block/progress_meter.c | 2 + block/vdi.c | 2 +- blockjob.c | 1 - chardev/char.c | 2 +- crypto/block-luks.c | 1 - hw/9pfs/codir.c | 1 - hw/9pfs/cofile.c | 1 - hw/9pfs/cofs.c | 1 - hw/9pfs/coth.c | 2 +- hw/9pfs/coxattr.c | 1 - hw/block/virtio-blk.c | 2 +- migration/rdma.c | 2 +- nbd/client-connection.c | 1 + net/colo-compare.c | 2 +- qapi/qmp-dispatch.c | 2 +- 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 - util/thread-pool.c | 2 +- 46 files changed, 205 insertions(+), 154 deletions(-) create mode 100644 include/qemu/coroutine-core.h
Signature · 1 line
2.38.1
PATCH v2 1/5 coroutine: Clean up superfluous inclusion of qemu/coroutine.h
--- 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(-)
crypto/block-luks-priv.h +0 -1
@@ -31,7 +31,6 @@#include "crypto/random.h" #include "qemu/uuid.h" -#include "qemu/coroutine.h" #include "qemu/bitmap.h" /*
include/block/raw-aio.h +0 -1
@@ -17,7 +17,6 @@#define QEMU_RAW_AIO_H #include "block/aio.h" -#include "qemu/coroutine.h" #include "qemu/iov.h" /* AIO request types */
include/scsi/pr-manager.h +0 -1
@@ -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"
nbd/nbd-internal.h +0 -1
@@ -13,7 +13,6 @@#include "sysemu/block-backend.h" #include "io/channel-tls.h" -#include "qemu/coroutine.h" #include "qemu/iov.h" #ifndef _WIN32
blockjob.c +0 -1
@@ -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"
crypto/block-luks.c +0 -1
@@ -32,7 +32,6 @@#include "crypto/random.h" #include "qemu/uuid.h" -#include "qemu/coroutine.h" #include "qemu/bitmap.h" /*
hw/9pfs/codir.c +0 -1
@@ -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"
hw/9pfs/cofile.c +0 -1
@@ -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"
hw/9pfs/cofs.c +0 -1
@@ -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"
hw/9pfs/coxattr.c +0 -1
@@ -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"
tests/unit/test-coroutine.c +0 -1
@@ -12,7 +12,6 @@*/ #include "qemu/osdep.h" -#include "qemu/coroutine.h" #include "qemu/coroutine_int.h" #include "qemu/lockable.h"
tests/unit/test-vmstate.c +0 -1
@@ -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"
util/qemu-coroutine-lock.c +0 -1
@@ -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"
util/qemu-coroutine-sleep.c +0 -1
@@ -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"
util/qemu-coroutine.c +0 -1
@@ -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"
Signature · 1 line
2.38.1
PATCH v2 2/5 coroutine: Move coroutine_fn to qemu/osdep.h, trim includes
In reply to Markus Armbrusterblock/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.
--- 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(-)
include/block/aio_task.h +0 -2
@@ -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);
include/block/block-common.h +0 -1
@@ -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"
include/block/graph-lock.h +0 -2
@@ -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
include/monitor/hmp.h +0 -1
@@ -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);
include/qemu/coroutine.h +7 -11
@@ -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_fntypedef struct Coroutine Coroutine ;
include/qemu/osdep.h +16 -0
@@ -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
Signature · 1 line
2.38.1
PATCH v2 3/5 coroutine: Clean up superfluous inclusion of qemu/lockable.h
In reply to Markus Armbruster--- include/qemu/progress_meter.h | 2 +- block/progress_meter.c | 2 ++ tests/unit/test-coroutine.c | 1 - 3 files changed, 3 insertions(+), 2 deletions(-)
include/qemu/progress_meter.h +1 -1
@@ -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 { /**
block/progress_meter.c +2 -0
@@ -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)
tests/unit/test-coroutine.c +0 -1
@@ -13,7 +13,6 @@#include "qemu/osdep.h" #include "qemu/coroutine_int.h" -#include "qemu/lockable.h" /* * Check that qemu_in_coroutine() works
Signature · 1 line
2.38.1
PATCH v2 4/5 coroutine: Split qemu/coroutine-core.h off qemu/coroutine.h
In reply to Markus Armbrusterqemu/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.
--- 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 - block.c | 2 +- block/block-copy.c | 2 +- block/io_uring.c | 2 +- block/linux-aio.c | 2 +- block/mirror.c | 2 +- block/vdi.c | 2 +- chardev/char.c | 2 +- hw/9pfs/coth.c | 2 +- hw/block/virtio-blk.c | 2 +- migration/rdma.c | 2 +- nbd/client-connection.c | 1 + net/colo-compare.c | 2 +- qapi/qmp-dispatch.c | 2 +- tests/unit/test-aio.c | 2 +- ui/console.c | 1 + util/thread-pool.c | 2 +- 23 files changed, 175 insertions(+), 115 deletions(-) create mode 100644 include/qemu/coroutine-core.h
hw/9pfs/coth.h +1 -1
@@ -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" /*
include/block/aio.h +1 -1
@@ -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"
include/io/channel.h +1 -1
@@ -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"
include/qemu/coroutine-core.h new file +154 -0
154 lines not on this page · raw message
include/qemu/coroutine.h +1 -96
115 lines not on this page · raw message
include/qemu/lockable.h +1 -1
@@ -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 *);
include/qemu/typedefs.h +0 -1
@@ -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 ;
block.c +1 -1
@@ -44,7 +44,7 @@#include "sysemu/block-backend.h" #include "qemu/notify.h" #include "qemu/option.h" -#include "qemu/coroutine.h" +#include "qemu/coroutine-core.h" #include "block/qapi.h" #include "qemu/timer.h" #include "qemu/cutils.h"
block/block-copy.c +1 -1
@@ -20,7 +20,7 @@#include "block/reqlist.h" #include "sysemu/block-backend.h" #include "qemu/units.h" -#include "qemu/coroutine.h" +#include "qemu/coroutine-core.h" #include "block/aio_task.h" #include "qemu/error-report.h" #include "qemu/memalign.h"
block/io_uring.c +1 -1
@@ -14,7 +14,7 @@#include "qemu/queue.h" #include "block/block.h" #include "block/raw-aio.h" -#include "qemu/coroutine.h" +#include "qemu/coroutine-core.h" #include "qapi/error.h" #include "trace.h"
block/linux-aio.c +1 -1
@@ -13,7 +13,7 @@#include "block/block.h" #include "block/raw-aio.h" #include "qemu/event_notifier.h" -#include "qemu/coroutine.h" +#include "qemu/coroutine-core.h" #include "qapi/error.h" #include <libaio.h>
block/mirror.c +1 -1
@@ -13,7 +13,7 @@#include "qemu/osdep.h" #include "qemu/cutils.h" -#include "qemu/coroutine.h" +#include "qemu/coroutine-core.h" #include "qemu/range.h" #include "trace.h" #include "block/blockjob_int.h"
block/vdi.c +1 -1
@@ -61,7 +61,7 @@#include "qemu/option.h" #include "qemu/bswap.h" #include "migration/blocker.h" -#include "qemu/coroutine.h" +#include "qemu/coroutine-core.h" #include "qemu/cutils.h" #include "qemu/uuid.h" #include "qemu/memalign.h"
chardev/char.c +1 -1
@@ -37,7 +37,7 @@#include "qemu/module.h" #include "qemu/option.h" #include "qemu/id.h" -#include "qemu/coroutine.h" +#include "qemu/coroutine-core.h" #include "qemu/yank.h" #include "chardev-internal.h"
hw/9pfs/coth.c +1 -1
@@ -19,7 +19,7 @@#include "qemu/osdep.h" #include "block/thread-pool.h" -#include "qemu/coroutine.h" +#include "qemu/coroutine-core.h" #include "qemu/main-loop.h" #include "coth.h"
hw/block/virtio-blk.c +1 -1
@@ -34,7 +34,7 @@#include "migration/qemu-file-types.h" #include "hw/virtio/virtio-access.h" #include "hw/virtio/virtio-blk-common.h" -#include "qemu/coroutine.h" +#include "qemu/coroutine-core.h" static void virtio_blk_init_request (VirtIOBlock *s,VirtQueue *vq,VirtIOBlockReq *req)
migration/rdma.c +1 -1
@@ -27,7 +27,7 @@#include "qemu/rcu.h" #include "qemu/sockets.h" #include "qemu/bitmap.h" -#include "qemu/coroutine.h" +#include "qemu/coroutine-core.h" #include "exec/memory.h" #include <sys/socket.h> #include <netdb.h>
nbd/client-connection.c +1 -0
@@ -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 */
net/colo-compare.c +1 -1
@@ -32,7 +32,7 @@#include "util.h" #include "block/aio-wait.h" -#include "qemu/coroutine.h" +#include "qemu/coroutine-core.h" #define TYPE_COLO_COMPARE "colo-compare"typedef struct CompareState CompareState ;
qapi/qmp-dispatch.c +1 -1
@@ -22,7 +22,7 @@#include "qapi/qobject-input-visitor.h" #include "qapi/qobject-output-visitor.h" #include "qapi/qmp/qbool.h" -#include "qemu/coroutine.h" +#include "qemu/coroutine-core.h" #include "qemu/main-loop.h" Visitor *qobject_input_visitor_new_qmp (QObject *obj)
tests/unit/test-aio.c +1 -1
@@ -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;
ui/console.c +1 -0
@@ -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"
util/thread-pool.c +1 -1
@@ -17,7 +17,7 @@#include "qemu/osdep.h" #include "qemu/queue.h" #include "qemu/thread.h" -#include "qemu/coroutine.h" +#include "qemu/coroutine-core.h" #include "trace.h" #include "block/thread-pool.h" #include "qemu/main-loop.h"
Signature · 1 line
2.38.1
Re: [PATCH v2 4/5] coroutine: Split qemu/coroutine-core.h off qemu/coroutine.h
Quoted 13 lines · Markus Armbruster
qemu/coroutine.handqemu/lockable.hinclude 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.hto newqemu/coroutine-core.hso thatqemu/coroutine-core.hdoesn't needqemu/lockable.h, andqemu/lockable.honly needsqemu/coroutine-core.h. Result:qemu/coroutine.hincludesqemu/lockable.hincludesqemu/coroutine-core.h.Signed-off-by Markus Armbruster <[email protected]>
[...]
block.c line 50
Quoted 13 lines
block.c +1
-1@@ -44,7 +44,7 @@#include "sysemu/block-backend.h" #include "qemu/notify.h" #include "qemu/option.h" -#include "qemu/coroutine.h" +#include "qemu/coroutine-core.h" #include "block/qapi.h" #include "qemu/timer.h" #include "qemu/cutils.h"
Err, the include is useless before and after the patch: we get coroutine.h from headers. I'll drop the hunk to reduce churn.
Same for
block/block-copy.c block/io_uring.c block/linux-aio.c block/mirror.c block/vdi.c chardev/char.c hw/9pfs/coth.c hw/block/virtio-blk.c migration/rdma.c net/colo-compare.c qapi/qmp-dispatch.c util/thread-pool.c
[...]
PATCH v2 5/5 coroutine: Use Coroutine typedef name instead of structure tag
In reply to Markus Armbruster--- include/block/aio.h | 7 +++---- util/async.c | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-)
include/block/aio.h +3 -4
@@ -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.
util/async.c +2 -2
@@ -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);
Signature · 1 line
2.38.1
Re: [PATCH v2 5/5] coroutine: Use Coroutine typedef name instead of structure tag
Quoted 5 lines · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>--- include/block/aio.h | 7 +++---- util/async.c | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-)