From nobody Sat Feb 7 03:44:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620677290; cv=none; d=zohomail.com; s=zohoarc; b=XZEfk8Ei1Y1W1Yw8LhYJ9nEd6zxW3tgryqee5VBH+S8jiDghzifIBdVGqbxoAp7qRvIAysmuwFkfa2QSb+mH6CzWoPTYErAXKV9f1tTQeS3oU1HhuAnx2HISXdI5qyrotbcvUGidwFAJhppwCtOoUwuo+dRoadfH50cjE9duk/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620677290; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=PY2uspWQizT0OsgRvnrGyb/uvN3JDAbEU0Ccc5/rcB0=; b=XE8fBuGZ6m/M7PPkH8njJ0DyHFTtNDip1VMm9fGNLx6WA/o/ifqC9DbeexS1tdBSWLdexWsRSn8AcAmyu2PrmglamRZD+Bt0KOCjLJy7n5VIfy8eYCjJHpElLXHSTlxFeMj1gXLE3zCNRseEJuzHO+TZanSo/MsHrpm8Vbe2DIk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1620677290610726.7963714341978; Mon, 10 May 2021 13:08:10 -0700 (PDT) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-443-lVb2LVFVMTO_FN88g5KvpQ-1; Mon, 10 May 2021 16:08:06 -0400 Received: by mail-ed1-f69.google.com with SMTP id o12-20020aa7d3cc0000b02903891695ceabso9655146edr.3 for ; Mon, 10 May 2021 13:08:06 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (39.red-81-40-121.staticip.rima-tde.net. [81.40.121.39]) by smtp.gmail.com with ESMTPSA id k26sm9870163eje.67.2021.05.10.13.08.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 13:08:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620677289; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PY2uspWQizT0OsgRvnrGyb/uvN3JDAbEU0Ccc5/rcB0=; b=J1m37pa2IkHJgCCrSMgZcQPTQAConv21j8oeTUYY1y2UT7FTZVX4MU664SpQOpS66lOd58 bZ946H78g9ih2JShw7Cp+jL68hl9j6otfCvrH6euNbzP9OJrG7gaZBmRuEHTRAzMj16fgS kOKzUKFoS/Ld/mn56ya7V4KuVEWhZrU= X-MC-Unique: lVb2LVFVMTO_FN88g5KvpQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PY2uspWQizT0OsgRvnrGyb/uvN3JDAbEU0Ccc5/rcB0=; b=CR6APrUdPzyZRtS483DK/wiEFw2LiwRSuQUaAJzcV0K2XAt8YLJ0bUqLwvSWGYT3dx xdxGlzZIGNj2YPNIq8wor2rMKi2kjWc9lpe8K5WZU9gLIhOI29mLFxjdMLo9SyWpIxXO zt/mynCcTpHVZ6Z+0xCvwi00Yia2jisEbBCdJ+RkGNDr5qSazatIHsFoV1kcpS0OC3wX HZ5ZD2R8OoyMyJzDipSOqAQkxtsJwVb0g2QNG8d2kir16xptUdgUnqEIkiE16P7ztEsq aJMH/taiP1bJgwS+3Z+pGZFwL1q4wn+rDnsUMcyzOWATw07NdMO1592fxmlJW1RdQclQ 4+BQ== X-Gm-Message-State: AOAM533hEzAJMMGPecKc14T+3HCCRDxl4dDwgcz009AD6/4gmHTRb9jV 5yprC/Vi/m/933wN4YxqkBnwMsuEEleoMNlSopQLw2jd4Y+GYGKCI2BoRfAilzrE5HSIzCSUCK6 zc3nFvM3bL2wgFQ== X-Received: by 2002:a05:6402:234b:: with SMTP id r11mr31441262eda.137.1620677285672; Mon, 10 May 2021 13:08:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5e47iTwtxQbH1Q3pkRPqYKXp7ISyBVc++aS377RGFr245sMe6vqS42Uve0X4I9ajEC/zT/g== X-Received: by 2002:a05:6402:234b:: with SMTP id r11mr31441243eda.137.1620677285556; Mon, 10 May 2021 13:08:05 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Kevin Wolf , Max Reitz , Stefan Hajnoczi , Richard Henderson , Chai Wen , qemu-block@nongnu.org, Sergio Lopez , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 1/2] bitops.h: Improve find_xxx_bit() documentation Date: Mon, 10 May 2021 22:07:57 +0200 Message-Id: <20210510200758.2623154-2-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210510200758.2623154-1-philmd@redhat.com> References: <20210510200758.2623154-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Document the following functions return the bitmap size if no matching bit is found: - find_first_bit - find_next_bit - find_last_bit - find_first_zero_bit - find_next_zero_bit Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- include/qemu/bitops.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h index 3acbf3384c6..a72f69fea85 100644 --- a/include/qemu/bitops.h +++ b/include/qemu/bitops.h @@ -140,7 +140,8 @@ static inline int test_bit(long nr, const unsigned long= *addr) * @addr: The address to start the search at * @size: The maximum size to search * - * Returns the bit number of the first set bit, or size. + * Returns the bit number of the last set bit, + * or @size if there is no set bit in the bitmap. */ unsigned long find_last_bit(const unsigned long *addr, unsigned long size); @@ -150,6 +151,9 @@ unsigned long find_last_bit(const unsigned long *addr, * @addr: The address to base the search on * @offset: The bitnumber to start searching at * @size: The bitmap size in bits + * + * Returns the bit number of the next set bit, + * or @size if there are no further set bits in the bitmap. */ unsigned long find_next_bit(const unsigned long *addr, unsigned long size, @@ -160,6 +164,9 @@ unsigned long find_next_bit(const unsigned long *addr, * @addr: The address to base the search on * @offset: The bitnumber to start searching at * @size: The bitmap size in bits + * + * Returns the bit number of the next cleared bit, + * or @size if there are no further clear bits in the bitmap. */ =20 unsigned long find_next_zero_bit(const unsigned long *addr, @@ -171,7 +178,8 @@ unsigned long find_next_zero_bit(const unsigned long *a= ddr, * @addr: The address to start the search at * @size: The maximum size to search * - * Returns the bit number of the first set bit. + * Returns the bit number of the first set bit, + * or @size if there is no set bit in the bitmap. */ static inline unsigned long find_first_bit(const unsigned long *addr, unsigned long size) @@ -194,7 +202,8 @@ static inline unsigned long find_first_bit(const unsign= ed long *addr, * @addr: The address to start the search at * @size: The maximum size to search * - * Returns the bit number of the first cleared bit. + * Returns the bit number of the first cleared bit, + * or @size if there is no clear bit in the bitmap. */ static inline unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size) --=20 2.26.3 From nobody Sat Feb 7 03:44:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620677295; cv=none; d=zohomail.com; s=zohoarc; b=I7nFysCsTmPAmOvofo3LdlL8fq1fkNbsW5+Hzfbdxfd6E5sSxaG21v+DHKOTpj8cCnE9WudotBesB7s5WS6Nsm+mWHDrhggYCYRcg80GRmig5GzZe/gQMfYAk7Vpjw6ypCj4cFzlyd4dSuU49mWnbfBnz/hzlbeBATz7OUjIJX4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620677295; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=TZ/Rh00bbSJXCAJmQZlicOzVjHxFbE+L7BQwV2hTVDQ=; b=Gwv7spKp+Fx1EXhHqaLPNR8CukKDgADRQ/E6XiZAiUWsMqABMdfPCP8+7D8TcjNumhnit7kGENr3iYqrGSj8pm56MfbrlxBLej07LUGDMur7113Ms9/ogF5MJSpNg30JdZ+7m/5OqM538rxTgo08tP/6I15F572ryh8Qia0Cmao= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 162067729520573.8207979160643; Mon, 10 May 2021 13:08:15 -0700 (PDT) Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-129-8ejZ8unWO7Cw_CyVaDBCAA-1; Mon, 10 May 2021 16:08:11 -0400 Received: by mail-ej1-f69.google.com with SMTP id h9-20020a1709063c09b0290393e97fec0fso5209445ejg.13 for ; Mon, 10 May 2021 13:08:11 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (39.red-81-40-121.staticip.rima-tde.net. [81.40.121.39]) by smtp.gmail.com with ESMTPSA id d18sm9900402eja.71.2021.05.10.13.08.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 13:08:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620677294; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TZ/Rh00bbSJXCAJmQZlicOzVjHxFbE+L7BQwV2hTVDQ=; b=YyZ4qNGZSw+xZozR4GoLZ+C4OkDQOidh4FITOVfS6JoTg+xjBwC4aWGruULaH6YHMfVGcQ HqueLji4CBmnihWboIUKBerDpnzRyULb/1G+OXd4W69LkaaTExz5d9X9tkspJEPRnjSSQZ D1z0chWhv+sSVaV32nqzIDVXUia1iMA= X-MC-Unique: 8ejZ8unWO7Cw_CyVaDBCAA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TZ/Rh00bbSJXCAJmQZlicOzVjHxFbE+L7BQwV2hTVDQ=; b=ek9HvGllbf+uVoLVOtUPprFVhfTvqgqjWSGI8Zt7PQNJQISpn5heRJmErh3l43U7j6 ScVuLBWhnDvk0UnuAAmFohKAL7Y5N8K8o1v3PEonFwXn8VTfGbhsfjrAzXK3HEiMdC9k tlWHn3IdXFCT5/PJ3nK2lNNfsmyH//dK1INTk33MyQQu+UUGwUc6PDSoBrzneQCG3bjE ThMTMY3NTwcDuuVKUSZZUPjJKkZeCZdSikiGGLplBvxARIMXbjrRRxltq1v6ekTZJZP4 IzWPP8RgunVxAc6n8wbQlgwQAsbm/vG292gubxVNIfE2Ce9VoPrhdQzl23gdyhTaK9KG 8l4w== X-Gm-Message-State: AOAM530QmRcG3MaSshHmxnglkhTkin61cQ9uFe2MOYMadZ6xalnhuuBL 4BOCkOnYu4VJntvWltE/PJYQh3J3dW2YzWR5O9F9jAC7qEXg0CpOr5nLqldvNmtethzHS6yCxrf fPufmCTrNi8lLLg== X-Received: by 2002:aa7:d1d9:: with SMTP id g25mr32577747edp.30.1620677290638; Mon, 10 May 2021 13:08:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy90ilun4fbJ6qxwkOV4ZaHv7fKHOsZzvLF0GVL1/6vt8Aki6QixpcYDoXD110pGM1ObTsVzg== X-Received: by 2002:aa7:d1d9:: with SMTP id g25mr32577727edp.30.1620677290518; Mon, 10 May 2021 13:08:10 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Kevin Wolf , Max Reitz , Stefan Hajnoczi , Richard Henderson , Chai Wen , qemu-block@nongnu.org, Sergio Lopez , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 2/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API Date: Mon, 10 May 2021 22:07:58 +0200 Message-Id: <20210510200758.2623154-3-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210510200758.2623154-1-philmd@redhat.com> References: <20210510200758.2623154-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) By directly using find_first_bit() and find_next_bit from the "bitops.h" API to iterate over the bitmap, we can remove the bitmap[] variable-length array copy on the stack and the complex manual bit testing/clearing logic. Suggested-by: Stefan Hajnoczi Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- hw/block/dataplane/virtio-blk.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-bl= k.c index e9050c8987e..a31fa94ca33 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -60,24 +60,14 @@ static void notify_guest_bh(void *opaque) { VirtIOBlockDataPlane *s =3D opaque; unsigned nvqs =3D s->conf->num_queues; - unsigned long bitmap[BITS_TO_LONGS(nvqs)]; - unsigned j; =20 - memcpy(bitmap, s->batch_notify_vqs, sizeof(bitmap)); - memset(s->batch_notify_vqs, 0, sizeof(bitmap)); + for (unsigned long i =3D find_first_bit(s->batch_notify_vqs, nvqs); + i < nvqs; i =3D find_next_bit(s->batch_notify_vqs, nvqs, i)) { + VirtQueue *vq =3D virtio_get_queue(s->vdev, i); =20 - for (j =3D 0; j < nvqs; j +=3D BITS_PER_LONG) { - unsigned long bits =3D bitmap[j / BITS_PER_LONG]; - - while (bits !=3D 0) { - unsigned i =3D j + ctzl(bits); - VirtQueue *vq =3D virtio_get_queue(s->vdev, i); - - virtio_notify_irqfd(s->vdev, vq); - - bits &=3D bits - 1; /* clear right-most bit */ - } + virtio_notify_irqfd(s->vdev, vq); } + bitmap_clear(s->batch_notify_vqs, 0, nvqs); } =20 /* Context: QEMU global mutex held */ --=20 2.26.3