block: refactor write threshold
PATCH v3 5/8 block/write-threshold: don't use aio context lock
In reply to Vladimir Sementsov-OgievskiyInstead of relying on aio context lock, let's make use of atomic operations.
The tricky place is bdrv_write_threshold_check_write(): we want atomically unset bs->write_threshold_offset iff
offset + bytes > bs->write_threshold_offset
We don't have such atomic operation, so let's go in a loop:
1. fetch wtr atomically
2. if condition satisfied, try cmpxchg (if not satisfied, we are done, don't send event)
3. if cmpxchg succeeded, we are done (send event), else go to [1]
--- include/block/block_int.h | 6 +++++- include/block/write-threshold.h | 6 ++++++ block/write-threshold.c | 34 +++++++++++++++++---------------- 3 files changed, 29 insertions(+), 17 deletions(-)
include/block/block_int.h +5 -1
@@ -954,7 +954,11 @@ struct BlockDriverState {*/ int64_t total_sectors; -/* threshold limit for writes, in bytes. "High water mark". */ +/* +* Threshold limit for writes, in bytes. "High water mark". +* Don't access directly, use bdrw_write_threshold* interface. +* Protected by atomic access, no lock is needed. +*/ uint64_t write_threshold_offset;/* Writing to the list requires the BQL _and_ the dirty_bitmap_mutex.
include/block/write-threshold.h +6 -0
@@ -24,6 +24,8 @@* To be used with thin-provisioned block devices. * * Use threshold_bytes == 0 to disable. +* +* Function is thread-safe, no lock is needed. */ void bdrv_write_threshold_set (BlockDriverState *bs,uint64_t threshold_bytes);
@@ -32,6 +34,8 @@ void bdrv_write_threshold_set(BlockDriverState *bs, uint64_t threshold_bytes);* * Get the configured write threshold, in bytes. * Zero means no threshold configured. +* +* Function is thread-safe, no lock is needed. */ uint64_t bdrv_write_threshold_get (const BlockDriverState *bs);
@@ -40,6 +44,8 @@ uint64_t bdrv_write_threshold_get(const BlockDriverState *bs);* * Check whether the specified request exceeds the write threshold. * If it is, send corresponding event and disable write threshold checking. +* +* Function is thread-safe, no lock is needed. */ void bdrv_write_threshold_check_write (BlockDriverState *bs,int64_t offset,int64_t bytes);
block/write-threshold.c +18 -16
@@ -2,6 +2,7 @@* QEMU System Emulator block write threshold notification * * Copyright Red Hat, Inc. 2014 +* Copyright (c) 2021 Virtuozzo International GmbH. * * Authors: * Francesco Romani <[email protected]>
@@ -14,6 +15,7 @@#include "block/block_int.h" #include "qemu/coroutine.h" #include "block/write-threshold.h" +#include "qemu/atomic.h" #include "qemu/notify.h" #include "qapi/error.h" #include "qapi/qapi-commands-block-core.h"
@@ -21,45 +23,45 @@uint64_t bdrv_write_threshold_get (const BlockDriverState *bs) { -return bs->write_threshold_offset; +return qatomic_read (&bs->write_threshold_offset); }void bdrv_write_threshold_set (BlockDriverState *bs,uint64_t threshold_bytes) { - bs->write_threshold_offset = threshold_bytes; +qatomic_set (&bs->write_threshold_offset, threshold_bytes); }void qmp_block_set_write_threshold (const char *node_name,uint64_t threshold_bytes,Error **errp) { -BlockDriverState *bs; -AioContext *aio_context; - - bs =bdrv_find_node (node_name); +BlockDriverState *bs =bdrv_find_node (node_name);if (!bs) {error_setg (errp,"Device '%s' not found" , node_name);return ; } - aio_context =bdrv_get_aio_context (bs); -aio_context_acquire (aio_context); -bdrv_write_threshold_set (bs, threshold_bytes); - -aio_context_release (aio_context); }void bdrv_write_threshold_check_write (BlockDriverState *bs,int64_t offset,int64_t bytes) {int64_t end = offset + bytes; -uint64_t wtr = bs->write_threshold_offset; +uint64_t wtr; -if (wtr >0 && end > wtr) { -qapi_event_send_block_write_threshold (bs->node_name, end - wtr, wtr); +retry: + wtr =bdrv_write_threshold_get (bs); +if (wtr ==0 || wtr >= end) { +return ; + } -/* autodisable to avoid flooding the monitor */ -bdrv_write_threshold_set (bs,0 ); +/* autodisable to avoid flooding the monitor */ +if (qatomic_cmpxchg (&bs->write_threshold_offset, wtr,0 ) != wtr) { +/* bs->write_threshold_offset changed in parallel */ + goto retry; } + +/* We have cleared bs->write_threshold_offset, so let's send event */ +qapi_event_send_block_write_threshold (bs->node_name, end - wtr, wtr); }
Signature · 1 line
2.29.2
PATCH v3 2/8 block: drop write notifiers
In reply to Vladimir Sementsov-OgievskiyThey are unused now.
--- include/block/block_int.h | 12 ------------ block.c | 1 - block/io.c | 6 ------ 3 files changed, 19 deletions(-)
include/block/block_int.h +0 -12
@@ -954,9 +954,6 @@ struct BlockDriverState {*/ int64_t total_sectors; -/* Callback before write request is processed */ -NotifierWithReturnList before_write_notifiers; -/* threshold limit for writes, in bytes. "High water mark". */ uint64_t write_threshold_offset;
@@ -1083,15 +1080,6 @@ void bdrv_parse_filename_strip_prefix(const char *filename, const char *prefix,bool bdrv_backing_overridden (BlockDriverState *bs); -/** -* bdrv_add_before_write_notifier: -* -* Register a callback that is invoked before write requests are processed but -* after any throttling or waiting for overlapping requests. -*/ -void bdrv_add_before_write_notifier (BlockDriverState *bs, -NotifierWithReturn *notifier); -/** * bdrv_add_aio_context_notifier: *
block.c +0 -1
@@ -400,7 +400,6 @@ BlockDriverState *bdrv_new(void)for (i =0 ; i <BLOCK_OP_TYPE_MAX ; i++) {QLIST_INIT (&bs->op_blockers[i]); } -notifier_with_return_list_init (&bs->before_write_notifiers);qemu_co_mutex_init (&bs->reqs_lock);qemu_mutex_init (&bs->dirty_bitmap_mutex); bs->refcnt =1 ;
block/io.c +0 -6
@@ -3165,12 +3165,6 @@ bool bdrv_qiov_is_aligned(BlockDriverState *bs, QEMUIOVector *qiov)return true; } -void bdrv_add_before_write_notifier (BlockDriverState *bs, -NotifierWithReturn *notifier) -{ -notifier_with_return_list_add (&bs->before_write_notifiers, notifier); -} -void bdrv_io_plug (BlockDriverState *bs) {BdrvChild *child;
Signature · 1 line
2.29.2
PATCH v3 7/8 test-write-threshold: drop extra TestStruct structure
In reply to Vladimir Sementsov-OgievskiyWe don't need this extra logic: it doesn't make code simpler.
--- tests/unit/test-write-threshold.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-)
tests/unit/test-write-threshold.c +3 -17
@@ -37,26 +37,12 @@ static void test_threshold_trigger(void) g_assert_cmpuint(bdrv_write_threshold_get(&bs), ==, 0); } -typedef struct TestStruct { -const char *name; -void (*func)(void ); -}TestStruct ; -int main (int argc,char **argv) { -size_t i; -TestStruct tests[] = { - {"/write-threshold/not-trigger" , - test_threshold_not_trigger }, - {"/write-threshold/trigger" , - test_threshold_trigger }, - {NULL ,NULL } - }; -g_test_init (&argc, &argv,NULL ); -for (i =0 ; tests[i].name !=NULL ; i++) { -g_test_add_func (tests[i].name, tests[i].func); - } +g_test_add_func ("/write-threshold/not-trigger" , test_threshold_not_trigger); +g_test_add_func ("/write-threshold/trigger" , test_threshold_trigger); +return g_test_run (); }
Signature · 1 line
2.29.2
v3 cover block: refactor write threshold
Hi all!
v3:
01-04,06,07: add Max's r-b.
01: improve commit msg and comments
03: improve commit msg
05: add more comments and qemu/atomic.h include
08: new, replacement for v2:08,09
Vladimir Sementsov-Ogievskiy (8):
block/write-threshold: don't use write notifiers
block: drop write notifiers
test-write-threshold: rewrite test_threshold_(not_)trigger tests block/write-threshold: drop extra APIs block/write-threshold: don't use aio context lock
test-write-threshold: drop extra tests
test-write-threshold: drop extra TestStruct structure
write-threshold: deal with includes
include/block/block_int.h | 19 ++--- include/block/write-threshold.h | 31 +++------ block.c | 1 - block/io.c | 11 +-- block/write-threshold.c | 111 +++++++----------------------- tests/unit/test-write-threshold.c | 90 ++---------------------- 6 files changed, 52 insertions(+), 211 deletions(-)
Signature · 1 line
2.29.2
PATCH v3 3/8 test-write-threshold: rewrite test_threshold_(not_)trigger tests
These tests use bdrv_write_threshold_exceeded() API, which is used only for test (since pre-previous commit). Better is testing real API, which is used in block.c as well.
So, let's call bdrv_write_threshold_check_write(), and check is bs->write_threshold_offset cleared or not (it's cleared iff threshold triggered).
Also we get rid of BdrvTrackedRequest use here. Note, that paranoiac bdrv_check_request() calls were added in 8b1170012b1 to protect BdrvTrackedRequest. Drop them now.
--- tests/unit/test-write-threshold.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-)
tests/unit/test-write-threshold.c +4 -18
@@ -55,41 +55,27 @@ static void test_threshold_multi_set_get(void)static void test_threshold_not_trigger (void ) { -uint64_t amount =0 ;uint64_t threshold =4 *1024 *1024 ;BlockDriverState bs; -BdrvTrackedRequest req;memset (&bs,0 ,sizeof (bs)); -memset (&req,0 ,sizeof (req)); - req.offset =1024 ; - req.bytes =1024 ; - -bdrv_check_request (req.offset, req.bytes, &error_abort);bdrv_write_threshold_set (&bs, threshold); - amount =bdrv_write_threshold_exceeded (&bs, &req); - g_assert_cmpuint(amount, ==, 0); +bdrv_write_threshold_check_write (&bs,1024 ,1024 ); + g_assert_cmpuint(bdrv_write_threshold_get(&bs), ==, threshold); }static void test_threshold_trigger (void ) { -uint64_t amount =0 ;uint64_t threshold =4 *1024 *1024 ;BlockDriverState bs; -BdrvTrackedRequest req;memset (&bs,0 ,sizeof (bs)); -memset (&req,0 ,sizeof (req)); - req.offset = (4 *1024 *1024 ) -1024 ; - req.bytes =2 *1024 ; - -bdrv_check_request (req.offset, req.bytes, &error_abort);bdrv_write_threshold_set (&bs, threshold); - amount =bdrv_write_threshold_exceeded (&bs, &req); - g_assert_cmpuint(amount, >=, 1024); +bdrv_write_threshold_check_write (&bs, threshold -1024 ,2 *1024 ); + g_assert_cmpuint(bdrv_write_threshold_get(&bs), ==, 0); } typedef struct TestStruct {
Signature · 1 line
2.29.2
PATCH v3 8/8 write-threshold: deal with includes
In reply to Vladimir Sementsov-Ogievskiy"qemu/typedefs.h" is enough for include/block/write-threshold.h header with forward declaration of BlockDriverState. Also drop extra includes from block/write-threshold.c and tests/unit/test-write-threshold.c
--- include/block/write-threshold.h | 2 +- block/write-threshold.c | 2 -- tests/unit/test-write-threshold.c | 1 - 3 files changed, 1 insertion(+), 4 deletions(-)
include/block/write-threshold.h +1 -1
@@ -13,7 +13,7 @@#ifndef BLOCK_WRITE_THRESHOLD_H #define BLOCK_WRITE_THRESHOLD_H -#include "block/block_int.h" +#include "qemu/typedefs.h" /* * bdrv_write_threshold_set:
block/write-threshold.c +0 -2
@@ -13,10 +13,8 @@#include "qemu/osdep.h" #include "block/block_int.h" -#include "qemu/coroutine.h" #include "block/write-threshold.h" #include "qemu/atomic.h" -#include "qemu/notify.h" #include "qapi/error.h" #include "qapi/qapi-commands-block-core.h" #include "qapi/qapi-events-block-core.h"
tests/unit/test-write-threshold.c +0 -1
@@ -7,7 +7,6 @@*/ #include "qemu/osdep.h" -#include "qapi/error.h" #include "block/block_int.h" #include "block/write-threshold.h"
Signature · 1 line
2.29.2
PATCH v3 1/8 block/write-threshold: don't use write notifiers
In reply to Vladimir Sementsov-Ogievskiywrite-notifiers are used only for write-threshold. New code for such purpose should create filters.
Let's better special-case write-threshold and drop write notifiers at all. (Actually, write-threshold is special-cased anyway, as the only user of write-notifiers)
So, create a new direct interface for bdrv_co_write_req_prepare() and drop all write-notifier related logic from write-threshold.c.
--- include/block/block_int.h | 1 - include/block/write-threshold.h | 9 +++++ block/io.c | 5 ++- block/write-threshold.c | 70 +++++++-------------------------- 4 files changed, 27 insertions(+), 58 deletions(-)
include/block/block_int.h +0 -1
@@ -959,7 +959,6 @@ struct BlockDriverState {/* threshold limit for writes, in bytes. "High water mark". */ uint64_t write_threshold_offset; -NotifierWithReturn write_threshold_notifier;/* Writing to the list requires the BQL _and_ the dirty_bitmap_mutex. * Reading from the list can be done with either the BQL or the
include/block/write-threshold.h +9 -0
@@ -59,4 +59,13 @@ bool bdrv_write_threshold_is_set(const BlockDriverState *bs);uint64_t bdrv_write_threshold_exceeded (const BlockDriverState *bs,const BdrvTrackedRequest *req); +/* +* bdrv_write_threshold_check_write +* +* Check whether the specified request exceeds the write threshold. +* If it is, send corresponding event and disable write threshold checking. +*/ +void bdrv_write_threshold_check_write (BlockDriverState *bs,int64_t offset, +int64_t bytes); +#endif
block/io.c +3 -2
@@ -30,6 +30,7 @@#include "block/blockjob_int.h" #include "block/block_int.h" #include "block/coroutines.h" +#include "block/write-threshold.h" #include "qemu/cutils.h" #include "qapi/error.h" #include "qemu/error-report.h"
@@ -2008,8 +2009,8 @@ bdrv_co_write_req_prepare(BdrvChild *child, int64_t offset, int64_t bytes, }else {assert (child->perm &BLK_PERM_WRITE ); } -return notifier_with_return_list_notify (&bs->before_write_notifiers, - req); +bdrv_write_threshold_check_write (bs, offset, bytes); +return 0 ;case BDRV_TRACKED_TRUNCATE :assert (child->perm &BLK_PERM_RESIZE );return 0 ;
block/write-threshold.c +15 -55
87 lines not on this page · raw message
Signature · 1 line
2.29.2
PATCH v3 4/8 block/write-threshold: drop extra APIs
In reply to Vladimir Sementsov-Ogievskiybdrv_write_threshold_exceeded() is unused at all.
bdrv_write_threshold_is_set() is used only to double check the value of bs->write_threshold_offset in tests. No real sense in it (both tests do check real value with help of bdrv_write_threshold_get())
--- include/block/write-threshold.h | 24 ------------------------ block/write-threshold.c | 19 ------------------- tests/unit/test-write-threshold.c | 4 ---- 3 files changed, 47 deletions(-)
include/block/write-threshold.h +0 -24
@@ -35,30 +35,6 @@ void bdrv_write_threshold_set(BlockDriverState *bs, uint64_t threshold_bytes);*/ uint64_t bdrv_write_threshold_get (const BlockDriverState *bs); -/* -* bdrv_write_threshold_is_set -* -* Tell if a write threshold is set for a given BDS. -*/ -bool bdrv_write_threshold_is_set (const BlockDriverState *bs); - -/* -* bdrv_write_threshold_exceeded -* -* Return the extent of a write request that exceeded the threshold, -* or zero if the request is below the threshold. -* Return zero also if the threshold was not set. -* -* NOTE: here we assume the following holds for each request this code -* deals with: -* -* assert((req->offset + req->bytes) <= UINT64_MAX) -* -* Please not there is *not* an actual C assert(). -*/ -uint64_t bdrv_write_threshold_exceeded (const BlockDriverState *bs, -const BdrvTrackedRequest *req); -/* * bdrv_write_threshold_check_write *
block/write-threshold.c +0 -19
@@ -24,25 +24,6 @@ uint64_t bdrv_write_threshold_get(const BlockDriverState *bs)return bs->write_threshold_offset; } -bool bdrv_write_threshold_is_set (const BlockDriverState *bs) -{ -return bs->write_threshold_offset >0 ; -} - -uint64_t bdrv_write_threshold_exceeded (const BlockDriverState *bs, -const BdrvTrackedRequest *req) -{ -if (bdrv_write_threshold_is_set (bs)) { -if (req->offset > bs->write_threshold_offset) { -return (req->offset - bs->write_threshold_offset) + req->bytes; - } -if ((req->offset + req->bytes) > bs->write_threshold_offset) { -return (req->offset + req->bytes) - bs->write_threshold_offset; - } - } -return 0 ; -} -void bdrv_write_threshold_set (BlockDriverState *bs,uint64_t threshold_bytes) { bs->write_threshold_offset = threshold_bytes;
tests/unit/test-write-threshold.c +0 -4
@@ -18,8 +18,6 @@ static void test_threshold_not_set_on_init(void)BlockDriverState bs;memset (&bs,0 ,sizeof (bs)); -g_assert (!bdrv_write_threshold_is_set (&bs)); - res =bdrv_write_threshold_get (&bs); g_assert_cmpint(res, ==, 0); }
@@ -33,8 +31,6 @@ static void test_threshold_set_get(void)bdrv_write_threshold_set (&bs, threshold); -g_assert (bdrv_write_threshold_is_set (&bs)); - res =bdrv_write_threshold_get (&bs); g_assert_cmpint(res, ==, threshold); }
Signature · 1 line
2.29.2
PATCH v3 6/8 test-write-threshold: drop extra tests
In reply to Vladimir Sementsov-OgievskiyTesting set/get of one 64bit variable doesn't seem necessary. We have a lot of such variables. Also remaining tests do test set/get anyway.
--- tests/unit/test-write-threshold.c | 43 ------------------------------- 1 file changed, 43 deletions(-)
tests/unit/test-write-threshold.c +0 -43
@@ -12,43 +12,6 @@#include "block/write-threshold.h" -static void test_threshold_not_set_on_init (void ) -{ -uint64_t res; -BlockDriverState bs; -memset (&bs,0 ,sizeof (bs)); - - res =bdrv_write_threshold_get (&bs); - g_assert_cmpint(res, ==, 0); -} - -static void test_threshold_set_get (void ) -{ -uint64_t threshold =4 *1024 *1024 ; -uint64_t res; -BlockDriverState bs; -memset (&bs,0 ,sizeof (bs)); - -bdrv_write_threshold_set (&bs, threshold); - - res =bdrv_write_threshold_get (&bs); - g_assert_cmpint(res, ==, threshold); -} - -static void test_threshold_multi_set_get (void ) -{ -uint64_t threshold1 =4 *1024 *1024 ; -uint64_t threshold2 =15 *1024 *1024 ; -uint64_t res; -BlockDriverState bs; -memset (&bs,0 ,sizeof (bs)); - -bdrv_write_threshold_set (&bs, threshold1); -bdrv_write_threshold_set (&bs, threshold2); - res =bdrv_write_threshold_get (&bs); - g_assert_cmpint(res, ==, threshold2); -} -static void test_threshold_not_trigger (void ) {uint64_t threshold =4 *1024 *1024 ;
@@ -84,12 +47,6 @@ int main(int argc, char **argv) {size_t i;TestStruct tests[] = { - {"/write-threshold/not-set-on-init" , - test_threshold_not_set_on_init }, - {"/write-threshold/set-get" , - test_threshold_set_get }, - {"/write-threshold/multi-set-get" , - test_threshold_multi_set_get }, {"/write-threshold/not-trigger" , test_threshold_not_trigger }, {"/write-threshold/trigger" ,
Signature · 1 line
2.29.2
Re: [PATCH v3 5/8] block/write-threshold: don't use aio context lock
In reply to Vladimir Sementsov-OgievskiyQuoted 17 lines · Vladimir Sementsov-Ogievskiy
void bdrv_write_threshold_check_write(BlockDriverState *bs, int64_t offset, int64_t bytes) { int64_t end = offset + bytes;block/write-threshold.c +6
-4-uint64_t wtr = bs->write_threshold_offset; +uint64_t wtr; -if (wtr >0 && end > wtr) { -qapi_event_send_block_write_threshold (bs->node_name, end - wtr, wtr); +retry: + wtr =bdrv_write_threshold_get (bs); +if (wtr ==0 || wtr >= end) { +return ; + } -/* autodisable to avoid flooding the monitor */
block/write-threshold.c line 67
Quoted 10 lines
block/write-threshold.c +7
-1-bdrv_write_threshold_set (bs,0 ); +/* autodisable to avoid flooding the monitor */ +if (qatomic_cmpxchg (&bs->write_threshold_offset, wtr,0 ) != wtr) { +/* bs->write_threshold_offset changed in parallel */ + goto retry; } + +/* We have cleared bs->write_threshold_offset, so let's send event */ +qapi_event_send_block_write_threshold (bs->node_name, end - wtr, wtr); }
This has the problem that 64-bit atomics are not always possible on 32-bit builds. We can use a spinlock (and probably just drop this patch for now).
Paolo
Re: [PATCH v3 1/8] block/write-threshold: don't use write notifiers
In reply to Vladimir Sementsov-OgievskiyQuoted 6 lines · Vladimir Sementsov-Ogievskiy
write-notifiers are used only for write-threshold. New code for such purpose should create filters.
Let's better special-case write-threshold and drop write notifiers at all. (Actually, write-threshold is special-cased anyway, as the only user of write-notifiers)
As write-threshold is already partially special-cased, let's finish that special-casing and drop write notifiers altogether.
Quoted 6 lines
So, create a new direct interface for
bdrv_co_write_req_prepare()and drop all write-notifier related logic fromwrite-threshold.c.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>Reviewed-by Max Reitz <[email protected]>
Quoted 8 lines
---
+/*
+ *bdrv_write_threshold_check_write
+ *
+ * Check whether the specified request exceeds the write threshold.
+ * If it is, send corresponding event and disable write threshold checking.
s/it is, send/so, send a/
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v3 4/8] block/write-threshold: drop extra APIs
In reply to Vladimir Sementsov-OgievskiyQuoted 1 line · Vladimir Sementsov-Ogievskiy
bdrv_write_threshold_exceeded()is unused at all.
either:
s/unused/not used/
or:
s/ at all//
Quoted 8 lines
bdrv_write_threshold_is_set()is used only to double check the value ofbs->write_threshold_offsetin tests. No real sense in it (both tests do check real value with help ofbdrv_write_threshold_get())Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>Reviewed-by Max Reitz <[email protected]>---
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v3 5/8] block/write-threshold: don't use aio context lock
In reply to Paolo BonziniQuoted 29 lines · Paolo Bonzini
Quoted 16 lines · Vladimir Sementsov-Ogievskiy
void
bdrv_write_threshold_check_write(BlockDriverState *bs, int64_t offset, int64_t bytes)
{
int64_tend = offset + bytes;
-uint64_twtr =bs->write_threshold_offset;
+uint64_twtr;
- if (wtr > 0 && end > wtr) {
-qapi_event_send_block_write_threshold(bs->node_name, end - wtr, wtr); +retry:
+ wtr =bdrv_write_threshold_get(bs);
+ if (wtr == 0 || wtr >= end) {
+ return;
+ }
- /* autodisable to avoid flooding the monitor */
-bdrv_write_threshold_set(bs, 0);
+ /* autodisable to avoid flooding the monitor */Quoted 9 lines
+ if (
qatomic_cmpxchg(&bs->write_threshold_offset, wtr, 0)!= wtr) { + /*bs->write_threshold_offsetchanged in parallel */ + goto retry;
}
+
+ /* We have clearedbs->write_threshold_offset, so let's send event */ +qapi_event_send_block_write_threshold(bs->node_name, end - wtr, wtr); }This has the problem that 64-bit atomics are not always possible on 32-bit builds. We can use a spinlock (and probably just drop this patch for now).
Quoted 2 lines
Paolo
OK, let's just drop it for now, the series originally not intended to make something thread-safe, but only to clear the way for.
(And honestly I doubt that write-threshold worth the complexity of this atomic cmpxchg retry loop, mutex would be simpler anyway)
Signature · 2 lines
Best regards, Vladimir
Quoted 19 lines · Vladimir Sementsov-Ogievskiy
Hi all!
v3:
01-04,06,07: add Max's r-b.
01: improve commit msg and comments
03: improve commit msg
05: add more comments andqemu/atomic.hinclude
08: new, replacement for v2:08,09Vladimir Sementsov-Ogievskiy (8):
block/write-threshold: don't use write notifiers
block: drop write notifiers
test-write-threshold: rewrite test_threshold_(not_)trigger testsblock/write-threshold: drop extra APIsblock/write-threshold: don't use aio context lock
test-write-threshold: drop extra tests
test-write-threshold: drop extra TestStruct structure
write-threshold: deal with includes
Quoted 11 lines
include/block/block_int.h | 19 ++--- include/block/write-threshold.h | 31 +++------ block.c | 1 - block/io.c | 11 +-- block/write-threshold.c | 111 +++++++----------------------- tests/unit/test-write-threshold.c | 90 ++---------------------- 6 files changed, 52 insertions(+), 211 deletions(-)Signature · 1 line
2.29.2
Aside from comments:
Quoted 19 lines · Vladimir Sementsov-Ogievskiy
Hi all!
v3:
01-04,06,07: add Max's r-b.
01: improve commit msg and comments
03: improve commit msg
05: add more comments andqemu/atomic.hinclude
08: new, replacement for v2:08,09Vladimir Sementsov-Ogievskiy (8):
block/write-threshold: don't use write notifiers
block: drop write notifiers
test-write-threshold: rewrite test_threshold_(not_)trigger testsblock/write-threshold: drop extra APIsblock/write-threshold: don't use aio context lock
test-write-threshold: drop extra tests
test-write-threshold: drop extra TestStruct structure
write-threshold: deal with includes
Quoted 7 lines
include/block/block_int.h | 19 ++--- include/block/write-threshold.h | 31 +++------ block.c | 1 - block/io.c | 11 +-- block/write-threshold.c | 111 +++++++----------------------- tests/unit/test-write-threshold.c | 90 ++---------------------- 6 files changed, 52 insertions(+), 211 deletions(-)
Thanks, I’ve applied all patches but patch 5 to my block branch, with the changes Eric has suggested:
https://github.com/XanClic/qemu/commits/block
Max