Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0553EC2BA1A for ; Sat, 4 Apr 2020 14:38:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D23D12070E for ; Sat, 4 Apr 2020 14:38:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DXYcLgFq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726608AbgDDOix (ORCPT ); Sat, 4 Apr 2020 10:38:53 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:50441 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726485AbgDDOiw (ORCPT ); Sat, 4 Apr 2020 10:38:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586011131; 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=Q5CT8J6SynPPib2nGk/jJo1msopT0GvmIwP+jVblkEA=; b=DXYcLgFqWh0JqgvTZ2JPSW3rHoUHoeNdCGvXNOl909JHnlq9Ri5+AxW4xtsiOaRpNX8RuU /D/LABuZs6J3pzZExOouaXJMKKw2MrPWVdrXAJeXGHejLPU7ykW7XLw2q6GENJbRtH2WEO 52wc/fWF0RRmlyP84w2EvRQOI70LJBM= 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-454-jvfHukaSObSekUMTEQIKnw-1; Sat, 04 Apr 2020 10:38:49 -0400 X-MC-Unique: jvfHukaSObSekUMTEQIKnw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7887C107ACC7; Sat, 4 Apr 2020 14:38:48 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.192.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E34B59B912; Sat, 4 Apr 2020 14:38:46 +0000 (UTC) From: Andrew Jones To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, Eric Auger Subject: [PULL kvm-unit-tests 28/39] page_alloc: Introduce get_order() Date: Sat, 4 Apr 2020 16:37:20 +0200 Message-Id: <20200404143731.208138-29-drjones@redhat.com> In-Reply-To: <20200404143731.208138-1-drjones@redhat.com> References: <20200404143731.208138-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Content-Transfer-Encoding: quoted-printable Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Eric Auger Compute the power of 2 order of a size. Use it in page_memalign. Other users are looming. Signed-off-by: Eric Auger Signed-off-by: Andrew Jones --- 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 ed236389537e..7c8461aa759c 100644 --- a/lib/alloc_page.c +++ b/lib/alloc_page.c @@ -155,7 +155,7 @@ static void *page_memalign(size_t alignment, size_t s= ize) 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 739a91def979..e6a51d2bc270 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.25.1