(see task #6831): Included new option PBUF_POOL_USES_MEMP to use a memp pool for PBUF_POOL pbufs instead of the old pool implementation in pbuf.c to remove redundant code.

This commit is contained in:
goldsimon 2007-05-13 16:16:03 +00:00
parent 055e3d52b6
commit a5e2e9ea03
5 changed files with 37 additions and 4 deletions

View File

@ -23,6 +23,11 @@ HISTORY
++ New features: ++ New features:
2007-05-10 Simon Goldschmidt
* opt.h, memp.h, memp.c, pbuf.c (see task #6831): Included new option
PBUF_POOL_USES_MEMP to use a memp pool for PBUF_POOL pbufs instead of the
old pool implementation in pbuf.c to remove redundant code.
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:
Include a function pointer instead of a table index in the message to reduce Include a function pointer instead of a table index in the message to reduce

View File

@ -69,6 +69,9 @@ static const u16_t memp_sizes[MEMP_MAX] = {
MEM_ALIGN_SIZE(sizeof(struct tcpip_msg)), MEM_ALIGN_SIZE(sizeof(struct tcpip_msg)),
#if ARP_QUEUEING #if ARP_QUEUEING
MEM_ALIGN_SIZE(sizeof(struct etharp_q_entry)), MEM_ALIGN_SIZE(sizeof(struct etharp_q_entry)),
#endif
#if PBUF_POOL_USES_MEMP
MEM_ALIGN_SIZE(sizeof(struct pbuf)) + MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE),
#endif #endif
MEM_ALIGN_SIZE(sizeof(struct sys_timeo)) MEM_ALIGN_SIZE(sizeof(struct sys_timeo))
}; };
@ -85,6 +88,9 @@ static const u16_t memp_num[MEMP_MAX] = {
MEMP_NUM_TCPIP_MSG, MEMP_NUM_TCPIP_MSG,
#if ARP_QUEUEING #if ARP_QUEUEING
MEMP_NUM_ARP_QUEUE, MEMP_NUM_ARP_QUEUE,
#endif
#if PBUF_POOL_USES_MEMP
PBUF_POOL_SIZE,
#endif #endif
MEMP_NUM_SYS_TIMEOUT MEMP_NUM_SYS_TIMEOUT
}; };
@ -104,6 +110,10 @@ static u8_t memp_memory[MEM_ALIGNMENT - 1 +
MEMP_TYPE_SIZE(MEMP_NUM_TCPIP_MSG, struct tcpip_msg) + MEMP_TYPE_SIZE(MEMP_NUM_TCPIP_MSG, struct tcpip_msg) +
#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
#if PBUF_POOL_USES_MEMP
MEMP_TYPE_SIZE(PBUF_POOL_SIZE, struct pbuf) +
PBUF_POOL_SIZE * MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE) +
#endif #endif
MEMP_TYPE_SIZE(MEMP_NUM_SYS_TIMEOUT, struct sys_timeo)]; MEMP_TYPE_SIZE(MEMP_NUM_SYS_TIMEOUT, struct sys_timeo)];

View File

@ -74,12 +74,14 @@
#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 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; static struct pbuf *pbuf_pool = NULL;
/* Forward declaration */ /* Forward declaration */
static void pbuf_pool_init(void); static void pbuf_pool_init(void);
#endif /* PBUF_POOL_USES_MEMP */
/** /**
* Initializes the pbuf module. * Initializes the pbuf module.
@ -93,9 +95,12 @@ 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(); pbuf_pool_init();
#endif /* PBUF_POOL_USES_MEMP */
} }
#if !PBUF_POOL_USES_MEMP
/** /**
* Initializes the pbuf pool. * Initializes the pbuf pool.
* *
@ -192,6 +197,10 @@ pbuf_pool_free(struct pbuf *p)
#endif #endif
SYS_ARCH_UNPROTECT(old_level); 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).
@ -260,6 +269,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
if (p == NULL) { if (p == NULL) {
return NULL; return NULL;
} }
p->flags = PBUF_FLAG_POOL;
p->next = NULL; p->next = NULL;
/* make the payload pointer point 'offset' bytes into pbuf data memory */ /* make the payload pointer point 'offset' bytes into pbuf data memory */
@ -288,6 +298,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
/* bail out unsuccesfully */ /* bail out unsuccesfully */
return NULL; return NULL;
} }
q->flags = PBUF_FLAG_POOL;
q->next = NULL; q->next = NULL;
/* make previous pbuf point to this pbuf */ /* make previous pbuf point to this pbuf */
r->next = q; r->next = q;

View File

@ -53,9 +53,12 @@ typedef enum {
MEMP_TCPIP_MSG, MEMP_TCPIP_MSG,
#if ARP_QUEUEING #if ARP_QUEUEING
MEMP_ARP_QUEUE, MEMP_ARP_QUEUE,
#endif
#if PBUF_POOL_USES_MEMP
MEMP_PBUF_POOL,
#endif #endif
MEMP_SYS_TIMEOUT, MEMP_SYS_TIMEOUT,
MEMP_MAX MEMP_MAX
} memp_t; } memp_t;

View File

@ -377,21 +377,25 @@ a lot of data that needs to be copied, this should be set high. */
/* ---------- Pbuf options ---------- */ /* ---------- Pbuf options ---------- */
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ /* 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. */
#ifndef PBUF_POOL_SIZE #ifndef PBUF_POOL_SIZE
#define PBUF_POOL_SIZE 16 #define PBUF_POOL_SIZE 16
#endif #endif
/* PBUF_LINK_HLEN: the number of bytes that should be allocated for a /* PBUF_LINK_HLEN: the number of bytes that should be allocated for a
link level header. Defaults to 14 for Ethernet. */ link level header. Defaults to 14 for Ethernet. */
#ifndef PBUF_LINK_HLEN #ifndef PBUF_LINK_HLEN
#define PBUF_LINK_HLEN 14 #define PBUF_LINK_HLEN 14
#endif #endif
/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */ /* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
#ifndef PBUF_POOL_BUFSIZE #ifndef PBUF_POOL_BUFSIZE
/* Default designed to accomodate single full size TCP frame in one PBUF */ /* Default designed to accomodate single full size TCP frame in one PBUF */
/* TCP_MSS + 40 for IP and TCP headers + physical layer headers */ /* TCP_MSS + 40 for IP and TCP headers + physical layer headers */