From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752560AbbLNHOG (ORCPT ); Mon, 14 Dec 2015 02:14:06 -0500 Received: from cmccmta1.chinamobile.com ([221.176.66.79]:5348 "EHLO cmccmta1.chinamobile.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752296AbbLNHOF (ORCPT ); Mon, 14 Dec 2015 02:14:05 -0500 X-RM-TRANSID: 2ee2566e6c38e2a-af982 X-RM-SPAM-FLAG: 00000000 X-RM-TRANSID: 2ee5566e6c37b47-e35f2 From: Xiubo Li To: broonie@kernel.org Cc: linux-kernel@vger.kernel.org, Xiubo Li Subject: [PATCH] regmap: flat: introduce register striding to save some memories Date: Mon, 14 Dec 2015 15:14:34 +0800 Message-Id: <1450077274-25942-1-git-send-email-lixiubo@cmss.chinamobile.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Throughout the regcache-flat code, for the flat cache array, the actual register address offsets are used to index the values, and this will waste some memory spaces. For example, on 64-BIT platform, device A has three registers: register offsets: {0x00, 0x08, 0x10} max_register: 0x10 regsiter striding: 8 And the size of flat cache memory space will be: (max_register + 1 ) * sizeof(unsigned int) = (0x10 + 1) * sizeof(unsigned int) = 17 * 8 = 136 Bytes Since map->reg_stride has been introduced and all extant register addresses are a multiple of this value, it could use the address offsets divide by the stride to determine the index. Then the size of flat cache memory space will be: (max_register / reg_stride + 1 ) * sizeof(unsigned int) = (0x10 / 8 + 1) * sizeof(unsigned int) = 3 * 8 = 24 Bytes And the bigger of the striding value, there will be more memory space wasted. After introducing the register striding here can save some memeories for the system. Signed-off-by: Xiubo Li --- drivers/base/regmap/regcache-flat.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/base/regmap/regcache-flat.c b/drivers/base/regmap/regcache-flat.c index 686c9e0..160d636 100644 --- a/drivers/base/regmap/regcache-flat.c +++ b/drivers/base/regmap/regcache-flat.c @@ -19,17 +19,19 @@ static int regcache_flat_init(struct regmap *map) { int i; - unsigned int *cache; + unsigned int index, *cache; - map->cache = kcalloc(map->max_register + 1, sizeof(unsigned int), - GFP_KERNEL); + map->cache = kcalloc(map->max_register / map->reg_stride + 1, + sizeof(unsigned int), GFP_KERNEL); if (!map->cache) return -ENOMEM; cache = map->cache; - for (i = 0; i < map->num_reg_defaults; i++) - cache[map->reg_defaults[i].reg] = map->reg_defaults[i].def; + for (i = 0; i < map->num_reg_defaults; i++) { + index = map->reg_defaults[i].reg / map->reg_stride; + cache[index] = map->reg_defaults[i].def; + } return 0; } @@ -45,9 +47,10 @@ static int regcache_flat_exit(struct regmap *map) static int regcache_flat_read(struct regmap *map, unsigned int reg, unsigned int *value) { + unsigned int index = reg / map->reg_stride; unsigned int *cache = map->cache; - *value = cache[reg]; + *value = cache[index]; return 0; } @@ -55,9 +58,10 @@ static int regcache_flat_read(struct regmap *map, static int regcache_flat_write(struct regmap *map, unsigned int reg, unsigned int value) { + unsigned int index = reg / map->reg_stride; unsigned int *cache = map->cache; - cache[reg] = value; + cache[index] = value; return 0; } -- 1.8.3.1