task #6831: removed the option PBUF_POOL_USES_MEMP and removed the old pbuf pool code, pbuf pool now always allocates from a memp pool

This commit is contained in:
goldsimon 2007-05-13 18:17:22 +00:00
parent a5e2e9ea03
commit 62d705903e
5 changed files with 7 additions and 137 deletions

View File

@ -24,9 +24,9 @@ HISTORY
++ New features: ++ New features:
2007-05-10 Simon Goldschmidt 2007-05-10 Simon Goldschmidt
* opt.h, memp.h, memp.c, pbuf.c (see task #6831): Included new option * opt.h, memp.h, memp.c, pbuf.c (see task #6831): use a new memp pool for
PBUF_POOL_USES_MEMP to use a memp pool for PBUF_POOL pbufs instead of the PBUF_POOL pbufs instead of the old pool implementation in pbuf.c to reduce
old pool implementation in pbuf.c to remove redundant code. code size.
2007-05-11 Frédéric Bernon 2007-05-11 Frédéric Bernon
* sockets.c, api_lib.c, api_msg.h, api_msg.c, netifapi.h, netifapi.c, tcpip.c: * sockets.c, api_lib.c, api_msg.h, api_msg.c, netifapi.h, netifapi.c, tcpip.c:

View File

@ -70,9 +70,7 @@ static const u16_t memp_sizes[MEMP_MAX] = {
#if ARP_QUEUEING #if ARP_QUEUEING
MEM_ALIGN_SIZE(sizeof(struct etharp_q_entry)), MEM_ALIGN_SIZE(sizeof(struct etharp_q_entry)),
#endif #endif
#if PBUF_POOL_USES_MEMP
MEM_ALIGN_SIZE(sizeof(struct pbuf)) + MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE), MEM_ALIGN_SIZE(sizeof(struct pbuf)) + MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE),
#endif
MEM_ALIGN_SIZE(sizeof(struct sys_timeo)) MEM_ALIGN_SIZE(sizeof(struct sys_timeo))
}; };
@ -89,9 +87,7 @@ static const u16_t memp_num[MEMP_MAX] = {
#if ARP_QUEUEING #if ARP_QUEUEING
MEMP_NUM_ARP_QUEUE, MEMP_NUM_ARP_QUEUE,
#endif #endif
#if PBUF_POOL_USES_MEMP
PBUF_POOL_SIZE, PBUF_POOL_SIZE,
#endif
MEMP_NUM_SYS_TIMEOUT MEMP_NUM_SYS_TIMEOUT
}; };
@ -111,10 +107,8 @@ static u8_t memp_memory[MEM_ALIGNMENT - 1 +
#if ARP_QUEUEING #if ARP_QUEUEING
MEMP_TYPE_SIZE(MEMP_NUM_ARP_QUEUE, struct etharp_q_entry) + MEMP_TYPE_SIZE(MEMP_NUM_ARP_QUEUE, struct etharp_q_entry) +
#endif #endif
#if PBUF_POOL_USES_MEMP
MEMP_TYPE_SIZE(PBUF_POOL_SIZE, struct pbuf) + MEMP_TYPE_SIZE(PBUF_POOL_SIZE, struct pbuf) +
PBUF_POOL_SIZE * MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE) + PBUF_POOL_SIZE * MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE) +
#endif
MEMP_TYPE_SIZE(MEMP_NUM_SYS_TIMEOUT, struct sys_timeo)]; MEMP_TYPE_SIZE(MEMP_NUM_SYS_TIMEOUT, struct sys_timeo)];
#if !SYS_LIGHTWEIGHT_PROT #if !SYS_LIGHTWEIGHT_PROT

View File

@ -74,15 +74,6 @@
#define SIZEOF_STRUCT_PBUF MEM_ALIGN_SIZE(sizeof(struct pbuf)) #define SIZEOF_STRUCT_PBUF MEM_ALIGN_SIZE(sizeof(struct pbuf))
#if !PBUF_POOL_USES_MEMP
static u8_t pbuf_pool_memory[MEM_ALIGNMENT - 1 + PBUF_POOL_SIZE * MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE) + SIZEOF_STRUCT_PBUF];
static struct pbuf *pbuf_pool = NULL;
/* Forward declaration */
static void pbuf_pool_init(void);
#endif /* PBUF_POOL_USES_MEMP */
/** /**
* Initializes the pbuf module. * Initializes the pbuf module.
* *
@ -94,114 +85,8 @@ pbuf_init(void)
{ {
LWIP_ASSERT("pbuf_init: PBUF_POOL_BUFSIZE not aligned", LWIP_ASSERT("pbuf_init: PBUF_POOL_BUFSIZE not aligned",
(PBUF_POOL_BUFSIZE % MEM_ALIGNMENT) == 0); (PBUF_POOL_BUFSIZE % MEM_ALIGNMENT) == 0);
#if !PBUF_POOL_USES_MEMP
pbuf_pool_init();
#endif /* PBUF_POOL_USES_MEMP */
} }
#if !PBUF_POOL_USES_MEMP
/**
* Initializes the pbuf pool.
*
* A large part of memory is allocated for holding the pool of pbufs.
* The size of the individual pbufs in the pool is given by the size
* parameter, and the number of pbufs in the pool by the num parameter.
*
* After the memory has been allocated, the pbufs are set up. The
* ->next pointer in each pbuf is set up to point to the next pbuf in
* the pool.
*
*/
static void
pbuf_pool_init(void)
{
struct pbuf *p, *q = NULL;
u16_t i;
pbuf_pool = (struct pbuf *)MEM_ALIGN(pbuf_pool_memory);
#if PBUF_STATS
lwip_stats.pbuf.avail = PBUF_POOL_SIZE;
#endif /* PBUF_STATS */
/* Set up ->next pointers to link the pbufs of the pool together */
p = pbuf_pool;
for(i = 0; i < PBUF_POOL_SIZE; ++i) {
p->next = (struct pbuf *)((u8_t *)p + PBUF_POOL_BUFSIZE + SIZEOF_STRUCT_PBUF);
p->len = p->tot_len = PBUF_POOL_BUFSIZE;
p->payload = MEM_ALIGN((void *)((u8_t *)p + SIZEOF_STRUCT_PBUF));
p->flags = PBUF_FLAG_POOL;
q = p;
p = p->next;
}
/* The ->next pointer of last pbuf is NULL to indicate that there
are no more pbufs in the pool */
q->next = NULL;
}
/**
* @internal only called from pbuf_alloc()
*/
static struct pbuf *
pbuf_pool_alloc(void)
{
struct pbuf *p;
SYS_ARCH_DECL_PROTECT(old_level);
SYS_ARCH_PROTECT(old_level);
p = pbuf_pool;
if (p) {
pbuf_pool = p->next;
#if PBUF_STATS
++lwip_stats.pbuf.used;
if (lwip_stats.pbuf.used > lwip_stats.pbuf.max) {
lwip_stats.pbuf.max = lwip_stats.pbuf.used;
}
#endif /* PBUF_STATS */
} else {
LWIP_DEBUGF(PBUF_DEBUG | 2, ("pbuf_pool_alloc: Out of pbufs in pool.\n"));
#if PBUF_STATS
++lwip_stats.pbuf.err;
#endif /* PBUF_STATS */
}
SYS_ARCH_UNPROTECT(old_level);
return p;
}
/**
* @internal only called from pbuf_free()
*
* Implemented as static function to make it easy to change pbuf_pool
* implementation.
*/
static void
pbuf_pool_free(struct pbuf *p)
{
SYS_ARCH_DECL_PROTECT(old_level);
LWIP_DEBUG_ASSERT("p->ref == 0", p->ref == 0);
p->len = p->tot_len = PBUF_POOL_BUFSIZE;
p->payload = (void *)((u8_t *)p + SIZEOF_STRUCT_PBUF);
/* put p at the front of the pool */
SYS_ARCH_PROTECT(old_level);
p->next = pbuf_pool;
pbuf_pool = p;
#if PBUF_STATS
--lwip_stats.pbuf.used;
#endif
SYS_ARCH_UNPROTECT(old_level);
}
#else /* PBUF_POOL_USES_MEMP */
#define pbuf_pool_alloc() memp_malloc(MEMP_PBUF_POOL)
#define pbuf_pool_free(p) memp_free(MEMP_PBUF_POOL, p)
#endif /* PBUF_POOL_USES_MEMP */
/** /**
* Allocates a pbuf of the given type (possibly a chain for PBUF_POOL type). * Allocates a pbuf of the given type (possibly a chain for PBUF_POOL type).
* *
@ -264,7 +149,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
switch (flag) { switch (flag) {
case PBUF_POOL: case PBUF_POOL:
/* allocate head of pbuf chain into p */ /* allocate head of pbuf chain into p */
p = pbuf_pool_alloc(); p = memp_malloc(MEMP_PBUF_POOL);
LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE | 3, ("pbuf_alloc: allocated pbuf %p\n", (void *)p)); LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE | 3, ("pbuf_alloc: allocated pbuf %p\n", (void *)p));
if (p == NULL) { if (p == NULL) {
return NULL; return NULL;
@ -291,7 +176,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
rem_len = length - p->len; rem_len = length - p->len;
/* any remaining pbufs to be allocated? */ /* any remaining pbufs to be allocated? */
while (rem_len > 0) { while (rem_len > 0) {
q = pbuf_pool_alloc(); q = memp_malloc(MEMP_PBUF_POOL);
if (q == NULL) { if (q == NULL) {
/* free chain so far allocated */ /* free chain so far allocated */
pbuf_free(p); pbuf_free(p);
@ -603,7 +488,7 @@ pbuf_free(struct pbuf *p)
flags = p->flags; flags = p->flags;
/* is this a pbuf from the pool? */ /* is this a pbuf from the pool? */
if (flags == PBUF_FLAG_POOL) { if (flags == PBUF_FLAG_POOL) {
pbuf_pool_free(p); memp_free(MEMP_PBUF_POOL, p);
/* is this a ROM or RAM referencing pbuf? */ /* is this a ROM or RAM referencing pbuf? */
} else if (flags == PBUF_FLAG_ROM || flags == PBUF_FLAG_REF) { } else if (flags == PBUF_FLAG_ROM || flags == PBUF_FLAG_REF) {
memp_free(MEMP_PBUF, p); memp_free(MEMP_PBUF, p);

View File

@ -54,9 +54,7 @@ typedef enum {
#if ARP_QUEUEING #if ARP_QUEUEING
MEMP_ARP_QUEUE, MEMP_ARP_QUEUE,
#endif #endif
#if PBUF_POOL_USES_MEMP
MEMP_PBUF_POOL, MEMP_PBUF_POOL,
#endif
MEMP_SYS_TIMEOUT, MEMP_SYS_TIMEOUT,
MEMP_MAX MEMP_MAX

View File

@ -377,13 +377,6 @@ a lot of data that needs to be copied, this should be set high. */
/* ---------- Pbuf options ---------- */ /* ---------- Pbuf options ---------- */
/* PBUF_POOL_USES_MEMP: if set to 1, PBUF_POOL pbufs are allocated using an
additional memp type, which saves some code since a dedicated pbuf pool
is not used any more */
#ifndef PBUF_POOL_USES_MEMP
#define PBUF_POOL_USES_MEMP 0
#endif
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ /* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
#ifndef PBUF_POOL_SIZE #ifndef PBUF_POOL_SIZE
#define PBUF_POOL_SIZE 16 #define PBUF_POOL_SIZE 16