linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
To: "devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	Qiang Zhao <qiang.zhao@nxp.com>, Li Yang <leoyang.li@nxp.com>
Cc: Mark Rutland <mark.rutland@arm.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Scott Wood <oss@buserror.net>,
	Rasmus Villemoes <Rasmus.Villemoes@prevas.se>,
	Rob Herring <robh+dt@kernel.org>,
	"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>
Subject: [PATCH v3 2/6] soc/fsl/qe: qe.c: reduce static memory footprint by 1.7K
Date: Mon, 13 May 2019 11:14:56 +0000	[thread overview]
Message-ID: <20190513111442.25724-3-rasmus.villemoes@prevas.dk> (raw)
In-Reply-To: <20190513111442.25724-1-rasmus.villemoes@prevas.dk>

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.

Reviewed-by: Christophe Leroy <christophe.leroy@c-s.fr>
Reviewed-by: Qiang Zhao <qiang.zhao@nxp.com>
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
 drivers/soc/fsl/qe/qe.c | 42 ++++++++++++-----------------------------
 1 file changed, 12 insertions(+), 30 deletions(-)

diff --git a/drivers/soc/fsl/qe/qe.c b/drivers/soc/fsl/qe/qe.c
index 855373deb746..4b59109df22b 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 <linux/bitmap.h>
 #include <linux/errno.h>
 #include <linux/sched.h>
 #include <linux/kernel.h>
@@ -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,10 @@ EXPORT_SYMBOL(qe_get_snum);
 
 void qe_put_snum(u8 snum)
 {
-	int i;
+	const u8 *p = memchr(snums, snum, qe_num_of_snum);
 
-	for (i = 0; i < qe_num_of_snum; i++) {
-		if (snums[i].num == snum) {
-			snums[i].state = QE_SNUM_STATE_FREE;
-			break;
-		}
-	}
+	if (p)
+		clear_bit(p - snums, snum_state);
 }
 EXPORT_SYMBOL(qe_put_snum);
 
-- 
2.20.1


  parent reply	other threads:[~2019-05-13 11:18 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-30 13:36 [PATCH RESEND 0/5] soc/fsl/qe: cleanups and new DT binding Rasmus Villemoes
2019-04-30 13:36 ` [PATCH 1/5] soc/fsl/qe: qe.c: drop useless static qualifier Rasmus Villemoes
2019-04-30 17:03   ` Christophe Leroy
2019-04-30 13:36 ` [PATCH 2/5] soc/fsl/qe: qe.c: reduce static memory footprint by 1.7K Rasmus Villemoes
2019-04-30 17:12   ` Christophe Leroy
2019-05-01  5:51     ` Rasmus Villemoes
2019-04-30 13:36 ` [PATCH 3/5] soc/fsl/qe: qe.c: introduce qe_get_device_node helper Rasmus Villemoes
2019-04-30 17:14   ` Christophe Leroy
2019-04-30 13:36 ` [PATCH 4/5] soc/fsl/qe: qe.c: support fsl,qe-snums property Rasmus Villemoes
2019-04-30 17:19   ` Christophe Leroy
2019-05-01  6:00     ` Rasmus Villemoes
2019-04-30 13:36 ` [PATCH 5/5] soc/fsl/qe: qe.c: fold qe_get_num_of_snums into qe_snums_init Rasmus Villemoes
2019-04-30 17:27   ` Christophe Leroy
2019-05-01  9:29 ` [PATCH v2 0/6] soc/fsl/qe: cleanups and new DT binding Rasmus Villemoes
2019-05-01  9:29   ` [PATCH v2 1/6] soc/fsl/qe: qe.c: drop useless static qualifier Rasmus Villemoes
2019-05-01  9:29   ` [PATCH v2 2/6] soc/fsl/qe: qe.c: reduce static memory footprint by 1.7K Rasmus Villemoes
2019-05-02  4:51     ` Christophe Leroy
2019-05-01  9:29   ` [PATCH v2 3/6] soc/fsl/qe: qe.c: introduce qe_get_device_node helper Rasmus Villemoes
2019-05-01  9:29   ` [PATCH v2 4/6] dt-bindings: soc/fsl: qe: document new fsl,qe-snums binding Rasmus Villemoes
2019-05-01 15:12     ` Joakim Tjernlund
2019-05-01 18:47       ` Rasmus Villemoes
2019-05-01 21:00     ` Rob Herring
2019-05-01  9:29   ` [PATCH v2 5/6] soc/fsl/qe: qe.c: support fsl,qe-snums property Rasmus Villemoes
2019-05-02  4:52     ` Christophe Leroy
2019-05-01  9:29   ` [PATCH v2 6/6] soc/fsl/qe: qe.c: fold qe_get_num_of_snums into qe_snums_init Rasmus Villemoes
2019-05-02  4:54     ` Christophe Leroy
2019-05-09  2:35     ` [EXT] " Qiang Zhao
2019-05-13 11:14   ` [PATCH v3 0/6] soc/fsl/qe: cleanups and new DT binding Rasmus Villemoes
2019-05-13 11:14     ` [PATCH v3 1/6] soc/fsl/qe: qe.c: drop useless static qualifier Rasmus Villemoes
2019-05-13 11:14     ` Rasmus Villemoes [this message]
2019-05-13 11:14     ` [PATCH v3 3/6] soc/fsl/qe: qe.c: introduce qe_get_device_node helper Rasmus Villemoes
2019-05-13 11:14     ` [PATCH v3 4/6] dt-bindings: soc/fsl: qe: document new fsl,qe-snums binding Rasmus Villemoes
2019-05-13 11:39       ` Joakim Tjernlund
2019-05-13 17:51       ` Rob Herring
2019-05-13 11:15     ` [PATCH v3 5/6] soc/fsl/qe: qe.c: support fsl,qe-snums property Rasmus Villemoes
2019-05-13 11:15     ` [PATCH v3 6/6] soc/fsl/qe: qe.c: fold qe_get_num_of_snums into qe_snums_init Rasmus Villemoes
2019-06-03 19:53     ` [PATCH v3 0/6] soc/fsl/qe: cleanups and new DT binding Rasmus Villemoes
2019-06-03 19:55       ` Leo Li
2019-06-04 20:29     ` Li Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190513111442.25724-3-rasmus.villemoes@prevas.dk \
    --to=rasmus.villemoes@prevas.dk \
    --cc=Rasmus.Villemoes@prevas.se \
    --cc=devicetree@vger.kernel.org \
    --cc=leoyang.li@nxp.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mark.rutland@arm.com \
    --cc=oss@buserror.net \
    --cc=qiang.zhao@nxp.com \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).