mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 15:53:54 -06:00
throttle: add throttle_detach/attach_aio_context()
Block I/O throttling uses timers and currently always adds them to the main loop. Throttling will break if bdrv_set_aio_context() is used to move a BlockDriverState to a different AioContext. This patch adds throttle_detach/attach_aio_context() interfaces so the throttling timers and uses them to move timers to the new AioContext. Note that bdrv_set_aio_context() already drains all requests so we're sure no throttled requests are pending. The test cases need to be updated since the throttle_init() interface has changed. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Benoit Canet <benoit@irqsave.net>
This commit is contained in:
parent
c9f87b20b9
commit
13af91ebf0
4 changed files with 60 additions and 9 deletions
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "qemu/throttle.h"
|
||||
#include "qemu/timer.h"
|
||||
#include "block/aio.h"
|
||||
|
||||
/* This function make a bucket leak
|
||||
*
|
||||
|
@ -157,8 +158,18 @@ bool throttle_compute_timer(ThrottleState *ts,
|
|||
return false;
|
||||
}
|
||||
|
||||
/* Add timers to event loop */
|
||||
void throttle_attach_aio_context(ThrottleState *ts, AioContext *new_context)
|
||||
{
|
||||
ts->timers[0] = aio_timer_new(new_context, ts->clock_type, SCALE_NS,
|
||||
ts->read_timer_cb, ts->timer_opaque);
|
||||
ts->timers[1] = aio_timer_new(new_context, ts->clock_type, SCALE_NS,
|
||||
ts->write_timer_cb, ts->timer_opaque);
|
||||
}
|
||||
|
||||
/* To be called first on the ThrottleState */
|
||||
void throttle_init(ThrottleState *ts,
|
||||
AioContext *aio_context,
|
||||
QEMUClockType clock_type,
|
||||
QEMUTimerCB *read_timer_cb,
|
||||
QEMUTimerCB *write_timer_cb,
|
||||
|
@ -167,8 +178,10 @@ void throttle_init(ThrottleState *ts,
|
|||
memset(ts, 0, sizeof(ThrottleState));
|
||||
|
||||
ts->clock_type = clock_type;
|
||||
ts->timers[0] = timer_new_ns(clock_type, read_timer_cb, timer_opaque);
|
||||
ts->timers[1] = timer_new_ns(clock_type, write_timer_cb, timer_opaque);
|
||||
ts->read_timer_cb = read_timer_cb;
|
||||
ts->write_timer_cb = write_timer_cb;
|
||||
ts->timer_opaque = timer_opaque;
|
||||
throttle_attach_aio_context(ts, aio_context);
|
||||
}
|
||||
|
||||
/* destroy a timer */
|
||||
|
@ -181,8 +194,8 @@ static void throttle_timer_destroy(QEMUTimer **timer)
|
|||
*timer = NULL;
|
||||
}
|
||||
|
||||
/* To be called last on the ThrottleState */
|
||||
void throttle_destroy(ThrottleState *ts)
|
||||
/* Remove timers from event loop */
|
||||
void throttle_detach_aio_context(ThrottleState *ts)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -191,6 +204,12 @@ void throttle_destroy(ThrottleState *ts)
|
|||
}
|
||||
}
|
||||
|
||||
/* To be called last on the ThrottleState */
|
||||
void throttle_destroy(ThrottleState *ts)
|
||||
{
|
||||
throttle_detach_aio_context(ts);
|
||||
}
|
||||
|
||||
/* is any throttling timer configured */
|
||||
bool throttle_have_timer(ThrottleState *ts)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue