Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6820944yba; Wed, 1 May 2019 21:53:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmBOqWdzTecbhIgszBUtzVbtP68+V+hbgSbJHJaub3P+GecuHBkNAWbxGao5LaQimtgEio X-Received: by 2002:aa7:8052:: with SMTP id y18mr1832945pfm.36.1556772807012; Wed, 01 May 2019 21:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556772807; cv=none; d=google.com; s=arc-20160816; b=XO8mCYjqg/hq9jvM3upJZEWDsJcm65q26XzyqVmjU4RxmEI37aNGTknAmxZAZTN0Mw tmEXSybm7AGiUn92yqWunksLV/DGUC1iYpPQJUBBxw93Es9Dah0wIdLDzPsV0KGQDh4Z svj8Xk6kC6brVBFU7UXpfKzn2cWbyonDM1RgEn0eMAvtQd2O3WUqLydFk9W6aEihW9Gj gj+VYO6pz5okI3N7PnTXvdjZjNk5qjK1m8BfNnxy6c7wnZhsEQmdg2gdFbBwVOlXcWkF hACsbin/UacgNmHMvbd9TwnCRaLl77vh0j7ft/CRuo8i1lv5sPPJ5V6Ve2lqH03dNNaa JkYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=bKp40p29ww5rWYWudCtNM/eqZO3Koty1E3gHLJJDIRc=; b=VYEpQvgQ9afWn14WewgamRNaMBgeuldNMljDnBJfMWEwOxaB7Peb7aR+k053C3e0Q/ L2O0aDg2Uket3Z6l6yxLcbbqYPVBbmua9vb5HEPSoEVVZAucAADNYlAH9ogiV20hgLIc bpSjMDH8DuYAQVpVzXW12l5HyZY/JlRuPUK1OsV9tD/P3k+a43p/w2PX9DWvtsRAFegf pe+MY6AOGbaLpwLKhu2/Frcnpxu8whut7WQ+tN3GndqnBlG7ALz4dlcjGCUHOlyJA4Ta 3AQ7SDdm9Kw5YE0aKQbhCxqo16sAvpeprnd7oQDNFpUJAcWQNxAbyL9fnkqgz8p/PZG6 LUwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=RRbCPbxn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i189si7600753pfb.41.2019.05.01.21.52.59; Wed, 01 May 2019 21:53:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=RRbCPbxn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725764AbfEBEvk (ORCPT + 99 others); Thu, 2 May 2019 00:51:40 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:17908 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbfEBEvk (ORCPT ); Thu, 2 May 2019 00:51:40 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44vjXT3tPVz9v0dC; Thu, 2 May 2019 06:51:37 +0200 (CEST) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=RRbCPbxn; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id 3NqOSpeVpOTg; Thu, 2 May 2019 06:51:37 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 44vjXT2pDFz9v0dB; Thu, 2 May 2019 06:51:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1556772697; bh=bKp40p29ww5rWYWudCtNM/eqZO3Koty1E3gHLJJDIRc=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=RRbCPbxnLgXWlaX1rtHvlgQTduiVbrwYwYfPRqWoCouk04XpiXQ4Oit7TlcLBvUqI IORSjyEt82psaGWuAiiWAVwdpQWgiDy+eFb5WNCfasy8kTeLF6pIzHcB/cNJXU0Gtr XCbWeCzkzjM0zp7Lc2jdnYlhWjFqR3hVxBy/aKww= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 305578B84C; Thu, 2 May 2019 06:51:38 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id pErdMFLohumg; Thu, 2 May 2019 06:51:38 +0200 (CEST) Received: from PO15451 (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 894618B74C; Thu, 2 May 2019 06:51:37 +0200 (CEST) Subject: Re: [PATCH v2 2/6] soc/fsl/qe: qe.c: reduce static memory footprint by 1.7K To: Rasmus Villemoes , "devicetree@vger.kernel.org" , Qiang Zhao , Li Yang Cc: "linuxppc-dev@lists.ozlabs.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , Rob Herring , Scott Wood , Mark Rutland , Rasmus Villemoes References: <20190430133615.25721-1-rasmus.villemoes@prevas.dk> <20190501092841.9026-1-rasmus.villemoes@prevas.dk> <20190501092841.9026-3-rasmus.villemoes@prevas.dk> From: Christophe Leroy Message-ID: Date: Thu, 2 May 2019 06:51:37 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190501092841.9026-3-rasmus.villemoes@prevas.dk> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 01/05/2019 à 11:29, Rasmus Villemoes a écrit : > The current array of struct qe_snum use 256*4 bytes for just keeping > track of the free/used state of each index, and the struct layout > means there's another 768 bytes of padding. If we just unzip that > structure, the array of snum values just use 256 bytes, while the > free/inuse state can be tracked in a 32 byte bitmap. > > So this reduces the .data footprint by 1760 bytes. It also serves as > preparation for introducing another DT binding for specifying the snum > values. > > Signed-off-by: Rasmus Villemoes Reviewed-by: Christophe Leroy Trivial comment below > --- > drivers/soc/fsl/qe/qe.c | 43 ++++++++++++----------------------------- > 1 file changed, 12 insertions(+), 31 deletions(-) > > diff --git a/drivers/soc/fsl/qe/qe.c b/drivers/soc/fsl/qe/qe.c > index 855373deb746..303aa29cb27d 100644 > --- a/drivers/soc/fsl/qe/qe.c > +++ b/drivers/soc/fsl/qe/qe.c > @@ -14,6 +14,7 @@ > * Free Software Foundation; either version 2 of the License, or (at your > * option) any later version. > */ > +#include > #include > #include > #include > @@ -43,25 +44,14 @@ static DEFINE_SPINLOCK(qe_lock); > DEFINE_SPINLOCK(cmxgcr_lock); > EXPORT_SYMBOL(cmxgcr_lock); > > -/* QE snum state */ > -enum qe_snum_state { > - QE_SNUM_STATE_USED, > - QE_SNUM_STATE_FREE > -}; > - > -/* QE snum */ > -struct qe_snum { > - u8 num; > - enum qe_snum_state state; > -}; > - > /* We allocate this here because it is used almost exclusively for > * the communication processor devices. > */ > struct qe_immap __iomem *qe_immr; > EXPORT_SYMBOL(qe_immr); > > -static struct qe_snum snums[QE_NUM_OF_SNUM]; /* Dynamically allocated SNUMs */ > +static u8 snums[QE_NUM_OF_SNUM]; /* Dynamically allocated SNUMs */ > +static DECLARE_BITMAP(snum_state, QE_NUM_OF_SNUM); > static unsigned int qe_num_of_snum; > > static phys_addr_t qebase = -1; > @@ -315,10 +305,8 @@ static void qe_snums_init(void) > else > snum_init = snum_init_46; > > - for (i = 0; i < qe_num_of_snum; i++) { > - snums[i].num = snum_init[i]; > - snums[i].state = QE_SNUM_STATE_FREE; > - } > + bitmap_zero(snum_state, QE_NUM_OF_SNUM); > + memcpy(snums, snum_init, qe_num_of_snum); > } > > int qe_get_snum(void) > @@ -328,12 +316,10 @@ int qe_get_snum(void) > int i; > > spin_lock_irqsave(&qe_lock, flags); > - for (i = 0; i < qe_num_of_snum; i++) { > - if (snums[i].state == QE_SNUM_STATE_FREE) { > - snums[i].state = QE_SNUM_STATE_USED; > - snum = snums[i].num; > - break; > - } > + i = find_first_zero_bit(snum_state, qe_num_of_snum); > + if (i < qe_num_of_snum) { > + set_bit(i, snum_state); > + snum = snums[i]; > } > spin_unlock_irqrestore(&qe_lock, flags); > > @@ -343,14 +329,9 @@ EXPORT_SYMBOL(qe_get_snum); > > void qe_put_snum(u8 snum) > { > - int i; > - > - for (i = 0; i < qe_num_of_snum; i++) { > - if (snums[i].num == snum) { > - snums[i].state = QE_SNUM_STATE_FREE; > - break; > - } > - } > + const u8 *p = memchr(snums, snum, qe_num_of_snum); A blank line is expected here. Christophe > + if (p) > + clear_bit(p - snums, snum_state); > } > EXPORT_SYMBOL(qe_put_snum); > >