From nobody Fri Nov 14 00:46:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583749573; cv=none; d=zohomail.com; s=zohoarc; b=kOVDEQ+QlJXM8EPKj7YCW1+BwXLDhfA1oHjWrJyzG8ou//XfmeqEUuETqfHS+1231nDq9rUxUzmRYRgLkJoxMF5iLWyuTlp/tY921ngAQlKgZv3iVs94T0JbPWpaBjkvpMNW6cuvnA1avkWzbU4fmmGjJoGeurHVg2LZao+cIeU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583749573; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jUPGPmIvaDDGzVaAE49y1ve21avwQxlD6sBJrt5aqiw=; b=QlOkHcP+GPXMYIS2qgE12cei7Nu1g/ZEODBF7BQhU3G319JDDie5t5VVkyhsM/xJKlRt1IJ+ULWx+wT/Q08xy0bfNLnSFWCvCtBWpWmFASe8K3RfMM18c03d0MS/RVZWYVKXR/kQxT20fEgkc9x84rrTTwkH5NRZtg3H4VgEuRU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583749573834285.1133215932963; Mon, 9 Mar 2020 03:26:13 -0700 (PDT) Received: from localhost ([::1]:40250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBFbw-0001VA-Kp for importer@patchew.org; Mon, 09 Mar 2020 06:26:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37751) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBFaZ-0008CK-MZ for qemu-devel@nongnu.org; Mon, 09 Mar 2020 06:24:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBFaY-0001v3-Pp for qemu-devel@nongnu.org; Mon, 09 Mar 2020 06:24:47 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:52147 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jBFaY-0001uh-MB for qemu-devel@nongnu.org; Mon, 09 Mar 2020 06:24:46 -0400 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-349-kn_oEwKnOn2anCLGpUgNTg-1; Mon, 09 Mar 2020 06:24:44 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7FDD0800D48; Mon, 9 Mar 2020 10:24:42 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1269587B08; Mon, 9 Mar 2020 10:24:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583749486; 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=jUPGPmIvaDDGzVaAE49y1ve21avwQxlD6sBJrt5aqiw=; b=UTUqO30TPKFqz/Znns9sVN+bEOm+a0tJt/Lmp3Bw0QJQf7qsGR0ccEtIwlwrv1wW3gYYdN kNaOeM7WqqyIKdUqDjbd7Otiaif4ykYiE22sy/5hKh/osqyGXxBe7IYF9i17XOqN2bjJc3 /EwL/vyE3sxnLp1FqeW4bKOsfYIGv88= X-MC-Unique: kn_oEwKnOn2anCLGpUgNTg-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, maz@kernel.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [kvm-unit-tests PATCH v4 02/13] page_alloc: Introduce get_order() Date: Mon, 9 Mar 2020 11:24:09 +0100 Message-Id: <20200309102420.24498-3-eric.auger@redhat.com> In-Reply-To: <20200309102420.24498-1-eric.auger@redhat.com> References: <20200309102420.24498-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, drjones@redhat.com, andre.przywara@arm.com, thuth@redhat.com, yuzenghui@huawei.com, alexandru.elisei@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Compute the power of 2 order of a size. Use it in page_memalign. Other users are looming. Signed-off-by: Eric Auger --- lib/alloc_page.c | 7 ++++++- lib/alloc_page.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/alloc_page.c b/lib/alloc_page.c index ed23638..7c8461a 100644 --- a/lib/alloc_page.c +++ b/lib/alloc_page.c @@ -155,7 +155,7 @@ static void *page_memalign(size_t alignment, size_t siz= e) if (!size) return NULL; =20 - order =3D is_power_of_2(n) ? fls(n) : fls(n) + 1; + order =3D get_order(n); =20 return alloc_pages(order); } @@ -175,3 +175,8 @@ void page_alloc_ops_enable(void) { alloc_ops =3D &page_alloc_ops; } + +int get_order(size_t size) +{ + return is_power_of_2(size) ? fls(size) : fls(size) + 1; +} diff --git a/lib/alloc_page.h b/lib/alloc_page.h index 739a91d..e6a51d2 100644 --- a/lib/alloc_page.h +++ b/lib/alloc_page.h @@ -15,5 +15,6 @@ void *alloc_pages(unsigned long order); void free_page(void *page); void free_pages(void *mem, unsigned long size); void free_pages_by_order(void *mem, unsigned long order); +int get_order(size_t size); =20 #endif --=20 2.20.1