1a76bab49Saliguori /* 2a76bab49Saliguori * QEMU aio implementation 3a76bab49Saliguori * 4a76bab49Saliguori * Copyright IBM, Corp. 2008 5a76bab49Saliguori * 6a76bab49Saliguori * Authors: 7a76bab49Saliguori * Anthony Liguori <aliguori@us.ibm.com> 8a76bab49Saliguori * 9a76bab49Saliguori * This work is licensed under the terms of the GNU GPL, version 2. See 10a76bab49Saliguori * the COPYING file in the top-level directory. 11a76bab49Saliguori * 12a76bab49Saliguori */ 13a76bab49Saliguori 14a76bab49Saliguori #ifndef QEMU_AIO_H 15a76bab49Saliguori #define QEMU_AIO_H 16a76bab49Saliguori 176a1751b7SAlex Bligh #include "qemu/typedefs.h" 18a76bab49Saliguori #include "qemu-common.h" 191de7afc9SPaolo Bonzini #include "qemu/queue.h" 201de7afc9SPaolo Bonzini #include "qemu/event_notifier.h" 21dcc772e2SLiu Ping Fan #include "qemu/thread.h" 2298563fc3SStefan Hajnoczi #include "qemu/rfifolock.h" 23dae21b98SAlex Bligh #include "qemu/timer.h" 24a76bab49Saliguori 257c84b1b8SMarkus Armbruster typedef struct BlockAIOCB BlockAIOCB; 26097310b5SMarkus Armbruster typedef void BlockCompletionFunc(void *opaque, int ret); 2785e8dab1SPaolo Bonzini 28d7331bedSStefan Hajnoczi typedef struct AIOCBInfo { 297c84b1b8SMarkus Armbruster void (*cancel_async)(BlockAIOCB *acb); 307c84b1b8SMarkus Armbruster AioContext *(*get_aio_context)(BlockAIOCB *acb); 318c82e9a4SStefan Hajnoczi size_t aiocb_size; 32d7331bedSStefan Hajnoczi } AIOCBInfo; 3385e8dab1SPaolo Bonzini 347c84b1b8SMarkus Armbruster struct BlockAIOCB { 35d7331bedSStefan Hajnoczi const AIOCBInfo *aiocb_info; 3685e8dab1SPaolo Bonzini BlockDriverState *bs; 37097310b5SMarkus Armbruster BlockCompletionFunc *cb; 3885e8dab1SPaolo Bonzini void *opaque; 39f197fe2bSFam Zheng int refcnt; 4085e8dab1SPaolo Bonzini }; 4185e8dab1SPaolo Bonzini 42d7331bedSStefan Hajnoczi void *qemu_aio_get(const AIOCBInfo *aiocb_info, BlockDriverState *bs, 43097310b5SMarkus Armbruster BlockCompletionFunc *cb, void *opaque); 448007429aSFam Zheng void qemu_aio_unref(void *p); 45f197fe2bSFam Zheng void qemu_aio_ref(void *p); 4685e8dab1SPaolo Bonzini 47f627aab1SPaolo Bonzini typedef struct AioHandler AioHandler; 48f627aab1SPaolo Bonzini typedef void QEMUBHFunc(void *opaque); 49f627aab1SPaolo Bonzini typedef void IOHandler(void *opaque); 50f627aab1SPaolo Bonzini 516a1751b7SAlex Bligh struct AioContext { 52e3713e00SPaolo Bonzini GSource source; 53e3713e00SPaolo Bonzini 5498563fc3SStefan Hajnoczi /* Protects all fields from multi-threaded access */ 5598563fc3SStefan Hajnoczi RFifoLock lock; 5698563fc3SStefan Hajnoczi 57a915f4bcSPaolo Bonzini /* The list of registered AIO handlers */ 58a915f4bcSPaolo Bonzini QLIST_HEAD(, AioHandler) aio_handlers; 59a915f4bcSPaolo Bonzini 60a915f4bcSPaolo Bonzini /* This is a simple lock used to protect the aio_handlers list. 61a915f4bcSPaolo Bonzini * Specifically, it's used to ensure that no callbacks are removed while 62a915f4bcSPaolo Bonzini * we're walking and dispatching callbacks. 63a915f4bcSPaolo Bonzini */ 64a915f4bcSPaolo Bonzini int walking_handlers; 65a915f4bcSPaolo Bonzini 66eabc9779SPaolo Bonzini /* Used to avoid unnecessary event_notifier_set calls in aio_notify; 67eabc9779SPaolo Bonzini * accessed with atomic primitives. If this field is 0, everything 68eabc9779SPaolo Bonzini * (file descriptors, bottom halves, timers) will be re-evaluated 69eabc9779SPaolo Bonzini * before the next blocking poll(), thus the event_notifier_set call 70eabc9779SPaolo Bonzini * can be skipped. If it is non-zero, you may need to wake up a 71eabc9779SPaolo Bonzini * concurrent aio_poll or the glib main event loop, making 72eabc9779SPaolo Bonzini * event_notifier_set necessary. 73eabc9779SPaolo Bonzini * 74eabc9779SPaolo Bonzini * Bit 0 is reserved for GSource usage of the AioContext, and is 1 75eabc9779SPaolo Bonzini * between a call to aio_ctx_check and the next call to aio_ctx_dispatch. 76eabc9779SPaolo Bonzini * Bits 1-31 simply count the number of active calls to aio_poll 77eabc9779SPaolo Bonzini * that are in the prepare or poll phase. 78eabc9779SPaolo Bonzini * 79eabc9779SPaolo Bonzini * The GSource and aio_poll must use a different mechanism because 80eabc9779SPaolo Bonzini * there is no certainty that a call to GSource's prepare callback 81eabc9779SPaolo Bonzini * (via g_main_context_prepare) is indeed followed by check and 82eabc9779SPaolo Bonzini * dispatch. It's not clear whether this would be a bug, but let's 83eabc9779SPaolo Bonzini * play safe and allow it---it will just cause extra calls to 84eabc9779SPaolo Bonzini * event_notifier_set until the next call to dispatch. 85eabc9779SPaolo Bonzini * 86eabc9779SPaolo Bonzini * Instead, the aio_poll calls include both the prepare and the 87eabc9779SPaolo Bonzini * dispatch phase, hence a simple counter is enough for them. 880ceb849bSPaolo Bonzini */ 89eabc9779SPaolo Bonzini uint32_t notify_me; 900ceb849bSPaolo Bonzini 91dcc772e2SLiu Ping Fan /* lock to protect between bh's adders and deleter */ 92dcc772e2SLiu Ping Fan QemuMutex bh_lock; 930ceb849bSPaolo Bonzini 94f627aab1SPaolo Bonzini /* Anchor of the list of Bottom Halves belonging to the context */ 95f627aab1SPaolo Bonzini struct QEMUBH *first_bh; 96f627aab1SPaolo Bonzini 97f627aab1SPaolo Bonzini /* A simple lock used to protect the first_bh list, and ensure that 98f627aab1SPaolo Bonzini * no callbacks are removed while we're walking and dispatching callbacks. 99f627aab1SPaolo Bonzini */ 100f627aab1SPaolo Bonzini int walking_bh; 1012f4dc3c1SPaolo Bonzini 10205e514b1SPaolo Bonzini /* Used by aio_notify. 10305e514b1SPaolo Bonzini * 10405e514b1SPaolo Bonzini * "notified" is used to avoid expensive event_notifier_test_and_clear 10505e514b1SPaolo Bonzini * calls. When it is clear, the EventNotifier is clear, or one thread 10605e514b1SPaolo Bonzini * is going to clear "notified" before processing more events. False 10705e514b1SPaolo Bonzini * positives are possible, i.e. "notified" could be set even though the 10805e514b1SPaolo Bonzini * EventNotifier is clear. 10905e514b1SPaolo Bonzini * 11005e514b1SPaolo Bonzini * Note that event_notifier_set *cannot* be optimized the same way. For 11105e514b1SPaolo Bonzini * more information on the problem that would result, see "#ifdef BUG2" 11205e514b1SPaolo Bonzini * in the docs/aio_notify_accept.promela formal model. 11305e514b1SPaolo Bonzini */ 11405e514b1SPaolo Bonzini bool notified; 1152f4dc3c1SPaolo Bonzini EventNotifier notifier; 1166b5f8762SStefan Hajnoczi 117ca96ac44SStefan Hajnoczi /* Scheduling this BH forces the event loop it iterate */ 118ca96ac44SStefan Hajnoczi QEMUBH *notify_dummy_bh; 119ca96ac44SStefan Hajnoczi 1209b34277dSStefan Hajnoczi /* Thread pool for performing work and receiving completion callbacks */ 1219b34277dSStefan Hajnoczi struct ThreadPool *thread_pool; 122dae21b98SAlex Bligh 123dae21b98SAlex Bligh /* TimerLists for calling timers - one per clock type */ 124dae21b98SAlex Bligh QEMUTimerListGroup tlg; 1256a1751b7SAlex Bligh }; 126f627aab1SPaolo Bonzini 127f627aab1SPaolo Bonzini /** 128f627aab1SPaolo Bonzini * aio_context_new: Allocate a new AioContext. 129f627aab1SPaolo Bonzini * 130f627aab1SPaolo Bonzini * AioContext provide a mini event-loop that can be waited on synchronously. 131f627aab1SPaolo Bonzini * They also provide bottom halves, a service to execute a piece of code 132f627aab1SPaolo Bonzini * as soon as possible. 133f627aab1SPaolo Bonzini */ 1342f78e491SChrysostomos Nanakos AioContext *aio_context_new(Error **errp); 135f627aab1SPaolo Bonzini 136f627aab1SPaolo Bonzini /** 137e3713e00SPaolo Bonzini * aio_context_ref: 138e3713e00SPaolo Bonzini * @ctx: The AioContext to operate on. 139e3713e00SPaolo Bonzini * 140e3713e00SPaolo Bonzini * Add a reference to an AioContext. 141e3713e00SPaolo Bonzini */ 142e3713e00SPaolo Bonzini void aio_context_ref(AioContext *ctx); 143e3713e00SPaolo Bonzini 144e3713e00SPaolo Bonzini /** 145e3713e00SPaolo Bonzini * aio_context_unref: 146e3713e00SPaolo Bonzini * @ctx: The AioContext to operate on. 147e3713e00SPaolo Bonzini * 148e3713e00SPaolo Bonzini * Drop a reference to an AioContext. 149e3713e00SPaolo Bonzini */ 150e3713e00SPaolo Bonzini void aio_context_unref(AioContext *ctx); 151e3713e00SPaolo Bonzini 15298563fc3SStefan Hajnoczi /* Take ownership of the AioContext. If the AioContext will be shared between 15349110174SPaolo Bonzini * threads, and a thread does not want to be interrupted, it will have to 15449110174SPaolo Bonzini * take ownership around calls to aio_poll(). Otherwise, aio_poll() 15549110174SPaolo Bonzini * automatically takes care of calling aio_context_acquire and 15649110174SPaolo Bonzini * aio_context_release. 15798563fc3SStefan Hajnoczi * 15849110174SPaolo Bonzini * Access to timers and BHs from a thread that has not acquired AioContext 15949110174SPaolo Bonzini * is possible. Access to callbacks for now must be done while the AioContext 16049110174SPaolo Bonzini * is owned by the thread (FIXME). 16198563fc3SStefan Hajnoczi */ 16298563fc3SStefan Hajnoczi void aio_context_acquire(AioContext *ctx); 16398563fc3SStefan Hajnoczi 16498563fc3SStefan Hajnoczi /* Relinquish ownership of the AioContext. */ 16598563fc3SStefan Hajnoczi void aio_context_release(AioContext *ctx); 16698563fc3SStefan Hajnoczi 167e3713e00SPaolo Bonzini /** 168f627aab1SPaolo Bonzini * aio_bh_new: Allocate a new bottom half structure. 169f627aab1SPaolo Bonzini * 170f627aab1SPaolo Bonzini * Bottom halves are lightweight callbacks whose invocation is guaranteed 171f627aab1SPaolo Bonzini * to be wait-free, thread-safe and signal-safe. The #QEMUBH structure 172f627aab1SPaolo Bonzini * is opaque and must be allocated prior to its use. 173f627aab1SPaolo Bonzini */ 174f627aab1SPaolo Bonzini QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque); 175f627aab1SPaolo Bonzini 176f627aab1SPaolo Bonzini /** 1772f4dc3c1SPaolo Bonzini * aio_notify: Force processing of pending events. 1782f4dc3c1SPaolo Bonzini * 1792f4dc3c1SPaolo Bonzini * Similar to signaling a condition variable, aio_notify forces 1802f4dc3c1SPaolo Bonzini * aio_wait to exit, so that the next call will re-examine pending events. 1812f4dc3c1SPaolo Bonzini * The caller of aio_notify will usually call aio_wait again very soon, 1822f4dc3c1SPaolo Bonzini * or go through another iteration of the GLib main loop. Hence, aio_notify 1832f4dc3c1SPaolo Bonzini * also has the side effect of recalculating the sets of file descriptors 1842f4dc3c1SPaolo Bonzini * that the main loop waits for. 1852f4dc3c1SPaolo Bonzini * 1862f4dc3c1SPaolo Bonzini * Calling aio_notify is rarely necessary, because for example scheduling 1872f4dc3c1SPaolo Bonzini * a bottom half calls it already. 1882f4dc3c1SPaolo Bonzini */ 1892f4dc3c1SPaolo Bonzini void aio_notify(AioContext *ctx); 1902f4dc3c1SPaolo Bonzini 1912f4dc3c1SPaolo Bonzini /** 19205e514b1SPaolo Bonzini * aio_notify_accept: Acknowledge receiving an aio_notify. 19305e514b1SPaolo Bonzini * 19405e514b1SPaolo Bonzini * aio_notify() uses an EventNotifier in order to wake up a sleeping 19505e514b1SPaolo Bonzini * aio_poll() or g_main_context_iteration(). Calls to aio_notify() are 19605e514b1SPaolo Bonzini * usually rare, but the AioContext has to clear the EventNotifier on 19705e514b1SPaolo Bonzini * every aio_poll() or g_main_context_iteration() in order to avoid 19805e514b1SPaolo Bonzini * busy waiting. This event_notifier_test_and_clear() cannot be done 19905e514b1SPaolo Bonzini * using the usual aio_context_set_event_notifier(), because it must 20005e514b1SPaolo Bonzini * be done before processing all events (file descriptors, bottom halves, 20105e514b1SPaolo Bonzini * timers). 20205e514b1SPaolo Bonzini * 20305e514b1SPaolo Bonzini * aio_notify_accept() is an optimized event_notifier_test_and_clear() 20405e514b1SPaolo Bonzini * that is specific to an AioContext's notifier; it is used internally 20505e514b1SPaolo Bonzini * to clear the EventNotifier only if aio_notify() had been called. 20605e514b1SPaolo Bonzini */ 20705e514b1SPaolo Bonzini void aio_notify_accept(AioContext *ctx); 20805e514b1SPaolo Bonzini 20905e514b1SPaolo Bonzini /** 210f627aab1SPaolo Bonzini * aio_bh_poll: Poll bottom halves for an AioContext. 211f627aab1SPaolo Bonzini * 212f627aab1SPaolo Bonzini * These are internal functions used by the QEMU main loop. 213dcc772e2SLiu Ping Fan * And notice that multiple occurrences of aio_bh_poll cannot 214dcc772e2SLiu Ping Fan * be called concurrently 215f627aab1SPaolo Bonzini */ 216f627aab1SPaolo Bonzini int aio_bh_poll(AioContext *ctx); 217f627aab1SPaolo Bonzini 218f627aab1SPaolo Bonzini /** 219f627aab1SPaolo Bonzini * qemu_bh_schedule: Schedule a bottom half. 220f627aab1SPaolo Bonzini * 221f627aab1SPaolo Bonzini * Scheduling a bottom half interrupts the main loop and causes the 222f627aab1SPaolo Bonzini * execution of the callback that was passed to qemu_bh_new. 223f627aab1SPaolo Bonzini * 224f627aab1SPaolo Bonzini * Bottom halves that are scheduled from a bottom half handler are instantly 225f627aab1SPaolo Bonzini * invoked. This can create an infinite loop if a bottom half handler 226f627aab1SPaolo Bonzini * schedules itself. 227f627aab1SPaolo Bonzini * 228f627aab1SPaolo Bonzini * @bh: The bottom half to be scheduled. 229f627aab1SPaolo Bonzini */ 230f627aab1SPaolo Bonzini void qemu_bh_schedule(QEMUBH *bh); 231f627aab1SPaolo Bonzini 232f627aab1SPaolo Bonzini /** 233f627aab1SPaolo Bonzini * qemu_bh_cancel: Cancel execution of a bottom half. 234f627aab1SPaolo Bonzini * 235f627aab1SPaolo Bonzini * Canceling execution of a bottom half undoes the effect of calls to 236f627aab1SPaolo Bonzini * qemu_bh_schedule without freeing its resources yet. While cancellation 237f627aab1SPaolo Bonzini * itself is also wait-free and thread-safe, it can of course race with the 238f627aab1SPaolo Bonzini * loop that executes bottom halves unless you are holding the iothread 239f627aab1SPaolo Bonzini * mutex. This makes it mostly useless if you are not holding the mutex. 240f627aab1SPaolo Bonzini * 241f627aab1SPaolo Bonzini * @bh: The bottom half to be canceled. 242f627aab1SPaolo Bonzini */ 243f627aab1SPaolo Bonzini void qemu_bh_cancel(QEMUBH *bh); 244f627aab1SPaolo Bonzini 245f627aab1SPaolo Bonzini /** 246f627aab1SPaolo Bonzini *qemu_bh_delete: Cancel execution of a bottom half and free its resources. 247f627aab1SPaolo Bonzini * 248f627aab1SPaolo Bonzini * Deleting a bottom half frees the memory that was allocated for it by 249f627aab1SPaolo Bonzini * qemu_bh_new. It also implies canceling the bottom half if it was 250f627aab1SPaolo Bonzini * scheduled. 251dcc772e2SLiu Ping Fan * This func is async. The bottom half will do the delete action at the finial 252dcc772e2SLiu Ping Fan * end. 253f627aab1SPaolo Bonzini * 254f627aab1SPaolo Bonzini * @bh: The bottom half to be deleted. 255f627aab1SPaolo Bonzini */ 256f627aab1SPaolo Bonzini void qemu_bh_delete(QEMUBH *bh); 257f627aab1SPaolo Bonzini 258cd9ba1ebSPaolo Bonzini /* Return whether there are any pending callbacks from the GSource 259a3462c65SPaolo Bonzini * attached to the AioContext, before g_poll is invoked. 260a3462c65SPaolo Bonzini * 261a3462c65SPaolo Bonzini * This is used internally in the implementation of the GSource. 262a3462c65SPaolo Bonzini */ 263a3462c65SPaolo Bonzini bool aio_prepare(AioContext *ctx); 264a3462c65SPaolo Bonzini 265a3462c65SPaolo Bonzini /* Return whether there are any pending callbacks from the GSource 266a3462c65SPaolo Bonzini * attached to the AioContext, after g_poll is invoked. 267cd9ba1ebSPaolo Bonzini * 268cd9ba1ebSPaolo Bonzini * This is used internally in the implementation of the GSource. 269cd9ba1ebSPaolo Bonzini */ 270cd9ba1ebSPaolo Bonzini bool aio_pending(AioContext *ctx); 271cd9ba1ebSPaolo Bonzini 272e4c7e2d1SPaolo Bonzini /* Dispatch any pending callbacks from the GSource attached to the AioContext. 273e4c7e2d1SPaolo Bonzini * 274e4c7e2d1SPaolo Bonzini * This is used internally in the implementation of the GSource. 275e4c7e2d1SPaolo Bonzini */ 276e4c7e2d1SPaolo Bonzini bool aio_dispatch(AioContext *ctx); 277e4c7e2d1SPaolo Bonzini 2787c0628b2SPaolo Bonzini /* Progress in completing AIO work to occur. This can issue new pending 2797c0628b2SPaolo Bonzini * aio as a result of executing I/O completion or bh callbacks. 280bcdc1857SPaolo Bonzini * 281acfb23adSPaolo Bonzini * Return whether any progress was made by executing AIO or bottom half 282acfb23adSPaolo Bonzini * handlers. If @blocking == true, this should always be true except 283acfb23adSPaolo Bonzini * if someone called aio_notify. 2847c0628b2SPaolo Bonzini * 2857c0628b2SPaolo Bonzini * If there are no pending bottom halves, but there are pending AIO 2867c0628b2SPaolo Bonzini * operations, it may not be possible to make any progress without 2877c0628b2SPaolo Bonzini * blocking. If @blocking is true, this function will wait until one 2887c0628b2SPaolo Bonzini * or more AIO events have completed, to ensure something has moved 2897c0628b2SPaolo Bonzini * before returning. 2907c0628b2SPaolo Bonzini */ 2917c0628b2SPaolo Bonzini bool aio_poll(AioContext *ctx, bool blocking); 292a76bab49Saliguori 293a76bab49Saliguori /* Register a file descriptor and associated callbacks. Behaves very similarly 2946484e422SFam Zheng * to qemu_set_fd_handler. Unlike qemu_set_fd_handler, these callbacks will 29587f68d31SPaolo Bonzini * be invoked when using aio_poll(). 296a76bab49Saliguori * 297a76bab49Saliguori * Code that invokes AIO completion functions should rely on this function 298a76bab49Saliguori * instead of qemu_set_fd_handler[2]. 299a76bab49Saliguori */ 300a915f4bcSPaolo Bonzini void aio_set_fd_handler(AioContext *ctx, 301a915f4bcSPaolo Bonzini int fd, 302*dca21ef2SFam Zheng bool is_external, 303a76bab49Saliguori IOHandler *io_read, 304a76bab49Saliguori IOHandler *io_write, 305a76bab49Saliguori void *opaque); 3069958c351SPaolo Bonzini 3079958c351SPaolo Bonzini /* Register an event notifier and associated callbacks. Behaves very similarly 3089958c351SPaolo Bonzini * to event_notifier_set_handler. Unlike event_notifier_set_handler, these callbacks 30987f68d31SPaolo Bonzini * will be invoked when using aio_poll(). 3109958c351SPaolo Bonzini * 3119958c351SPaolo Bonzini * Code that invokes AIO completion functions should rely on this function 3129958c351SPaolo Bonzini * instead of event_notifier_set_handler. 3139958c351SPaolo Bonzini */ 314a915f4bcSPaolo Bonzini void aio_set_event_notifier(AioContext *ctx, 315a915f4bcSPaolo Bonzini EventNotifier *notifier, 316*dca21ef2SFam Zheng bool is_external, 317f2e5dca4SStefan Hajnoczi EventNotifierHandler *io_read); 318a915f4bcSPaolo Bonzini 319e3713e00SPaolo Bonzini /* Return a GSource that lets the main loop poll the file descriptors attached 320e3713e00SPaolo Bonzini * to this AioContext. 321e3713e00SPaolo Bonzini */ 322e3713e00SPaolo Bonzini GSource *aio_get_g_source(AioContext *ctx); 323e3713e00SPaolo Bonzini 3249b34277dSStefan Hajnoczi /* Return the ThreadPool bound to this AioContext */ 3259b34277dSStefan Hajnoczi struct ThreadPool *aio_get_thread_pool(AioContext *ctx); 3269b34277dSStefan Hajnoczi 3274e29e831SAlex Bligh /** 3284e29e831SAlex Bligh * aio_timer_new: 3294e29e831SAlex Bligh * @ctx: the aio context 3304e29e831SAlex Bligh * @type: the clock type 3314e29e831SAlex Bligh * @scale: the scale 3324e29e831SAlex Bligh * @cb: the callback to call on timer expiry 3334e29e831SAlex Bligh * @opaque: the opaque pointer to pass to the callback 3344e29e831SAlex Bligh * 3354e29e831SAlex Bligh * Allocate a new timer attached to the context @ctx. 3364e29e831SAlex Bligh * The function is responsible for memory allocation. 3374e29e831SAlex Bligh * 3384e29e831SAlex Bligh * The preferred interface is aio_timer_init. Use that 3394e29e831SAlex Bligh * unless you really need dynamic memory allocation. 3404e29e831SAlex Bligh * 3414e29e831SAlex Bligh * Returns: a pointer to the new timer 3424e29e831SAlex Bligh */ 3434e29e831SAlex Bligh static inline QEMUTimer *aio_timer_new(AioContext *ctx, QEMUClockType type, 3444e29e831SAlex Bligh int scale, 3454e29e831SAlex Bligh QEMUTimerCB *cb, void *opaque) 3464e29e831SAlex Bligh { 3474e29e831SAlex Bligh return timer_new_tl(ctx->tlg.tl[type], scale, cb, opaque); 3484e29e831SAlex Bligh } 3494e29e831SAlex Bligh 3504e29e831SAlex Bligh /** 3514e29e831SAlex Bligh * aio_timer_init: 3524e29e831SAlex Bligh * @ctx: the aio context 3534e29e831SAlex Bligh * @ts: the timer 3544e29e831SAlex Bligh * @type: the clock type 3554e29e831SAlex Bligh * @scale: the scale 3564e29e831SAlex Bligh * @cb: the callback to call on timer expiry 3574e29e831SAlex Bligh * @opaque: the opaque pointer to pass to the callback 3584e29e831SAlex Bligh * 3594e29e831SAlex Bligh * Initialise a new timer attached to the context @ctx. 3604e29e831SAlex Bligh * The caller is responsible for memory allocation. 3614e29e831SAlex Bligh */ 3624e29e831SAlex Bligh static inline void aio_timer_init(AioContext *ctx, 3634e29e831SAlex Bligh QEMUTimer *ts, QEMUClockType type, 3644e29e831SAlex Bligh int scale, 3654e29e831SAlex Bligh QEMUTimerCB *cb, void *opaque) 3664e29e831SAlex Bligh { 367f186aa97SPaolo Bonzini timer_init_tl(ts, ctx->tlg.tl[type], scale, cb, opaque); 3684e29e831SAlex Bligh } 3694e29e831SAlex Bligh 370845ca10dSPaolo Bonzini /** 371845ca10dSPaolo Bonzini * aio_compute_timeout: 372845ca10dSPaolo Bonzini * @ctx: the aio context 373845ca10dSPaolo Bonzini * 374845ca10dSPaolo Bonzini * Compute the timeout that a blocking aio_poll should use. 375845ca10dSPaolo Bonzini */ 376845ca10dSPaolo Bonzini int64_t aio_compute_timeout(AioContext *ctx); 377845ca10dSPaolo Bonzini 378a76bab49Saliguori #endif 379