Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

soc: fsl: qe: reduce static memory footprint by 1.7K

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>
Signed-off-by: Li Yang <leoyang.li@nxp.com>

authored by

Rasmus Villemoes and committed by
Li Yang
875f2aab f03de74d

+12 -30
+12 -30
drivers/soc/fsl/qe/qe.c
··· 14 14 * Free Software Foundation; either version 2 of the License, or (at your 15 15 * option) any later version. 16 16 */ 17 + #include <linux/bitmap.h> 17 18 #include <linux/errno.h> 18 19 #include <linux/sched.h> 19 20 #include <linux/kernel.h> ··· 44 43 DEFINE_SPINLOCK(cmxgcr_lock); 45 44 EXPORT_SYMBOL(cmxgcr_lock); 46 45 47 - /* QE snum state */ 48 - enum qe_snum_state { 49 - QE_SNUM_STATE_USED, 50 - QE_SNUM_STATE_FREE 51 - }; 52 - 53 - /* QE snum */ 54 - struct qe_snum { 55 - u8 num; 56 - enum qe_snum_state state; 57 - }; 58 - 59 46 /* We allocate this here because it is used almost exclusively for 60 47 * the communication processor devices. 61 48 */ 62 49 struct qe_immap __iomem *qe_immr; 63 50 EXPORT_SYMBOL(qe_immr); 64 51 65 - static struct qe_snum snums[QE_NUM_OF_SNUM]; /* Dynamically allocated SNUMs */ 52 + static u8 snums[QE_NUM_OF_SNUM]; /* Dynamically allocated SNUMs */ 53 + static DECLARE_BITMAP(snum_state, QE_NUM_OF_SNUM); 66 54 static unsigned int qe_num_of_snum; 67 55 68 56 static phys_addr_t qebase = -1; ··· 305 315 else 306 316 snum_init = snum_init_46; 307 317 308 - for (i = 0; i < qe_num_of_snum; i++) { 309 - snums[i].num = snum_init[i]; 310 - snums[i].state = QE_SNUM_STATE_FREE; 311 - } 318 + bitmap_zero(snum_state, QE_NUM_OF_SNUM); 319 + memcpy(snums, snum_init, qe_num_of_snum); 312 320 } 313 321 314 322 int qe_get_snum(void) ··· 316 328 int i; 317 329 318 330 spin_lock_irqsave(&qe_lock, flags); 319 - for (i = 0; i < qe_num_of_snum; i++) { 320 - if (snums[i].state == QE_SNUM_STATE_FREE) { 321 - snums[i].state = QE_SNUM_STATE_USED; 322 - snum = snums[i].num; 323 - break; 324 - } 331 + i = find_first_zero_bit(snum_state, qe_num_of_snum); 332 + if (i < qe_num_of_snum) { 333 + set_bit(i, snum_state); 334 + snum = snums[i]; 325 335 } 326 336 spin_unlock_irqrestore(&qe_lock, flags); 327 337 ··· 329 343 330 344 void qe_put_snum(u8 snum) 331 345 { 332 - int i; 346 + const u8 *p = memchr(snums, snum, qe_num_of_snum); 333 347 334 - for (i = 0; i < qe_num_of_snum; i++) { 335 - if (snums[i].num == snum) { 336 - snums[i].state = QE_SNUM_STATE_FREE; 337 - break; 338 - } 339 - } 348 + if (p) 349 + clear_bit(p - snums, snum_state); 340 350 } 341 351 EXPORT_SYMBOL(qe_put_snum); 342 352