From patchwork Thu Nov 12 13:37:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 11900245 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A60CB14C0 for ; Thu, 12 Nov 2020 13:38:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 52DF922248 for ; Thu, 12 Nov 2020 13:38:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AAS2w4uT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 52DF922248 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5F4CA6B0075; Thu, 12 Nov 2020 08:38:52 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5A3D56B0078; Thu, 12 Nov 2020 08:38:52 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 494D36B007B; Thu, 12 Nov 2020 08:38:52 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id 18CC56B0075 for ; Thu, 12 Nov 2020 08:38:52 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B95B38249980 for ; Thu, 12 Nov 2020 13:38:51 +0000 (UTC) X-FDA: 77475871662.09.tin59_5609ba327306 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 9D707180AD801 for ; Thu, 12 Nov 2020 13:38:51 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,david@redhat.com,,RULES_HIT:30025:30034:30045:30054,0,RBL:216.205.24.124:@redhat.com:.lbl8.mailshell.net-62.18.0.100 64.10.201.10;04yfmodnu59mzjierbpcmnrutoj77ycootwkwkowis4dywqoudcwxn8n6mufqwu.99er74gg4nycejyte9phkqm1kep8ya1fhr5hyk5wceh33c18u3f7mfcn8uytnra.o-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:69,LUA_SUMMARY:none X-HE-Tag: tin59_5609ba327306 X-Filterd-Recvd-Size: 5364 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Thu, 12 Nov 2020 13:38:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605188330; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X0WfQnw15Vm9t+Uqndhh69vgkO1/7kUW5WBgUBhjrGY=; b=AAS2w4uT/MWOtwolF8jzHBjkIWkyX4oNPGD2L79h1LMWbzyjN1Sm/GdBO9VeitHJvzKKQx V0RLRKaZmC5hjNXDvtHmxFJQzFSavl4sJWbxlZxwOqCb42Mh0o5ePkhzwDxoBkGLkSZ7oo t89tvy9PmFhqG9xHU7yeoRFe1AwzmZY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-25-k-FLLVhEMsmObHVn5xkdtw-1; Thu, 12 Nov 2020 08:38:46 -0500 X-MC-Unique: k-FLLVhEMsmObHVn5xkdtw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 215E01030986; Thu, 12 Nov 2020 13:38:45 +0000 (UTC) Received: from t480s.redhat.com (ovpn-115-61.ams2.redhat.com [10.36.115.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2EB955765; Thu, 12 Nov 2020 13:38:36 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: virtualization@lists.linux-foundation.org, linux-mm@kvack.org, "Michael S . Tsirkin" , David Hildenbrand , Wei Yang , Pankaj Gupta , Jason Wang Subject: [PATCH v2 06/29] virtio-mem: factor out calculation of the bit number within the subblock bitmap Date: Thu, 12 Nov 2020 14:37:52 +0100 Message-Id: <20201112133815.13332-7-david@redhat.com> In-Reply-To: <20201112133815.13332-1-david@redhat.com> References: <20201112133815.13332-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The calculation is already complicated enough, let's limit it to one location. Reviewed-by: Wei Yang Reviewed-by: Pankaj Gupta Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: Pankaj Gupta Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 94451b401fba..30b4d07f5263 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -290,6 +290,16 @@ static int virtio_mem_mb_state_prepare_next_mb(struct virtio_mem *vm) _mb_id--) \ if (virtio_mem_mb_get_state(_vm, _mb_id) == _state) +/* + * Calculate the bit number in the subblock bitmap for the given subblock + * inside the given memory block. + */ +static int virtio_mem_sb_bitmap_bit_nr(struct virtio_mem *vm, + unsigned long mb_id, int sb_id) +{ + return (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb + sb_id; +} + /* * Mark all selected subblocks plugged. * @@ -299,7 +309,7 @@ static void virtio_mem_mb_set_sb_plugged(struct virtio_mem *vm, unsigned long mb_id, int sb_id, int count) { - const int bit = (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb + sb_id; + const int bit = virtio_mem_sb_bitmap_bit_nr(vm, mb_id, sb_id); __bitmap_set(vm->sb_bitmap, bit, count); } @@ -313,7 +323,7 @@ static void virtio_mem_mb_set_sb_unplugged(struct virtio_mem *vm, unsigned long mb_id, int sb_id, int count) { - const int bit = (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb + sb_id; + const int bit = virtio_mem_sb_bitmap_bit_nr(vm, mb_id, sb_id); __bitmap_clear(vm->sb_bitmap, bit, count); } @@ -325,7 +335,7 @@ static bool virtio_mem_mb_test_sb_plugged(struct virtio_mem *vm, unsigned long mb_id, int sb_id, int count) { - const int bit = (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb + sb_id; + const int bit = virtio_mem_sb_bitmap_bit_nr(vm, mb_id, sb_id); if (count == 1) return test_bit(bit, vm->sb_bitmap); @@ -342,7 +352,7 @@ static bool virtio_mem_mb_test_sb_unplugged(struct virtio_mem *vm, unsigned long mb_id, int sb_id, int count) { - const int bit = (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb + sb_id; + const int bit = virtio_mem_sb_bitmap_bit_nr(vm, mb_id, sb_id); /* TODO: Helper similar to bitmap_set() */ return find_next_bit(vm->sb_bitmap, bit + count, bit) >= bit + count; @@ -355,7 +365,7 @@ static bool virtio_mem_mb_test_sb_unplugged(struct virtio_mem *vm, static int virtio_mem_mb_first_unplugged_sb(struct virtio_mem *vm, unsigned long mb_id) { - const int bit = (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb; + const int bit = virtio_mem_sb_bitmap_bit_nr(vm, mb_id, 0); return find_next_zero_bit(vm->sb_bitmap, bit + vm->nb_sb_per_mb, bit) - bit;