qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3 5/8] block/write-threshold: don't use aio context lock


From: Paolo Bonzini
Subject: Re: [PATCH v3 5/8] block/write-threshold: don't use aio context lock
Date: Fri, 7 May 2021 15:45:45 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1

On 06/05/21 11:06, Vladimir Sementsov-Ogievskiy wrote:
  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);
  }


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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]