From 763760503b18895bdc7ef7dc17c4fb63ab30f260 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Sun, 10 Jan 2010 12:44:09 +0000 Subject: [PATCH] patch #6822 (Add option to place memory pools in separate arrays) - new config option MEMP_SEPARATE_POOLS --- CHANGELOG | 4 ++++ src/core/memp.c | 28 +++++++++++++++++++++++++++- src/include/lwip/opt.h | 9 +++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 1848352e..68ef8e6a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,10 @@ HISTORY ++ New features: + 2010-01-10: Simon Goldschmidt (Bill Auerbach) + * opt.h, memp.c: patch #6822 (Add option to place memory pools in + separate arrays) + 2010-01-10: Simon Goldschmidt * init.c, igmp.c: patch #6463 (IGMP - Adding Random Delay): added define LWIP_RAND() for lwip-wide randomization (to be defined in cc.h) diff --git a/src/core/memp.c b/src/core/memp.c index f6bd5a1b..6cf20b0f 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -143,12 +143,33 @@ static const char *memp_desc[MEMP_MAX] = { }; #endif /* LWIP_DEBUG */ -/** This is the actual memory used by the pools. */ +#if MEMP_SEPARATE_POOLS + +/** This creates each memory pool. These are named memp_memory_XXX (where XXX + * is the name of the pool defined in memp_std.h). + * To relocate a pool, declare it as extern in cc.h. Example for GCC: + * extern u8_t __attribute__((section(".onchip_mem"))) memp_memory_UDP_PCB[]; + */ +#define LWIP_MEMPOOL(name,num,size,desc) u8_t memp_memory_ ## name \ + ## [((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size)))]; +#include "lwip/memp_std.h" + +/** This array holds the base of each memory pool. */ +static u8_t *const memp_bases[] = { +#define LWIP_MEMPOOL(name,num,size,desc) memp_memory_ ## name, +#include "lwip/memp_std.h" +}; + +#else /* MEMP_SEPARATE_POOLS */ + +/** This is the actual memory used by the pools (all pools in one big block). */ static u8_t memp_memory[MEM_ALIGNMENT - 1 #define LWIP_MEMPOOL(name,num,size,desc) + ( (num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size) ) ) #include "lwip/memp_std.h" ]; +#endif /* MEMP_SEPARATE_POOLS */ + #if MEMP_SANITY_CHECK /** * Check that memp-lists don't form a circle @@ -270,10 +291,15 @@ memp_init(void) MEMP_STATS_AVAIL(avail, i, memp_num[i]); } +#if !MEMP_SEPARATE_POOLS memp = LWIP_MEM_ALIGN(memp_memory); +#endif /* !MEMP_SEPARATE_POOLS */ /* for every pool: */ for (i = 0; i < MEMP_MAX; ++i) { memp_tab[i] = NULL; +#if MEMP_SEPARATE_POOLS + memp = (struct memp*)memp_bases[i]; +#endif /* MEMP_SEPARATE_POOLS */ /* create a linked list of memp elements */ for (j = 0; j < memp_num[i]; ++j) { memp->next = memp_tab[i]; diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index a6b81b2a..c23318de 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -124,6 +124,15 @@ #define MEM_SIZE 1600 #endif +/** + * MEMP_SEPARATE_POOLS: if defined to 1, each pool is placed in its own array. + * This can be used to individually change the location of each pool. + * Default is one big array for all pools + */ +#ifndef MEMP_SEPARATE_POOLS +#define MEMP_SEPARATE_POOLS 0 +#endif + /** * MEMP_OVERFLOW_CHECK: memp overflow protection reserves a configurable * amount of bytes before and after each memp element in every pool and fills