Paolo Bonzini 4951967d84 ratelimit: protect with a mutex
Right now, rate limiting is protected by the AioContext mutex, which is
taken for example both by the block jobs and by qmp_block_job_set_speed
(via find_block_job).

We would like to remove the dependency of block layer code on the
AioContext mutex, since most drivers and the core I/O code are already
not relying on it.  However, there is no existing lock that can easily
be taken by both ratelimit_set_speed and ratelimit_calculate_delay,
especially because the latter might run in coroutine context (and
therefore under a CoMutex) but the former will not.

Since concurrent calls to ratelimit_calculate_delay are not possible,
one idea could be to use a seqlock to get a snapshot of slice_ns and
slice_quota.  But for now keep it simple, and just add a mutex to the
RateLimit struct; block jobs are generally not performance critical to
the point of optimizing the clock cycles spent in synchronization.

This also requires the introduction of init/destroy functions, so
add them to the two users of ratelimit.h.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-05-04 14:15:35 +02:00
..
2020-11-03 09:42:52 -05:00
2020-12-10 12:15:18 -05:00
2020-01-06 18:41:32 +04:00
2016-06-07 18:19:23 +03:00
2017-10-16 20:57:13 +03:00
2020-10-15 16:06:27 +02:00
2021-02-18 07:48:22 -08:00
2021-02-12 11:23:19 -06:00
2020-09-01 12:07:52 +02:00
2019-09-11 08:46:17 +02:00
2020-12-10 17:16:44 +01:00
2018-09-26 08:55:54 -07:00
2019-04-18 22:18:59 +02:00
2019-08-16 13:31:52 +02:00
2021-05-04 14:15:35 +02:00
2018-01-16 14:54:50 +01:00
2016-02-23 12:43:05 +00:00
2021-04-30 12:27:47 +02:00
2018-08-24 20:26:37 +02:00
2016-09-15 15:32:22 +03:00
2017-01-24 23:26:52 +03:00
2021-04-01 15:27:44 +04:00