diff options
author | Eric Norum <WENorum@lbl.gov> | 2006-05-25 17:36:31 +0000 |
---|---|---|
committer | Eric Norum <WENorum@lbl.gov> | 2006-05-25 17:36:31 +0000 |
commit | be31de713feda36d1da3771df5decaa96088713a (patch) | |
tree | d0e0a94c3e92658edad482effc4b086674267069 /cpukit/libnetworking | |
parent | 2006-05-16 Ralf Corsépius <ralf.corsepius@rtems.org> (diff) | |
download | rtems-be31de713feda36d1da3771df5decaa96088713a.tar.bz2 |
Provide customisable mbuf allocation.
Patch from Steven Johnson <sjohnson@sakuraindustries.com>
Diffstat (limited to 'cpukit/libnetworking')
-rw-r--r-- | cpukit/libnetworking/Makefile.am | 2 | ||||
-rw-r--r-- | cpukit/libnetworking/rtems/rtems_bsdnet.h | 16 | ||||
-rw-r--r-- | cpukit/libnetworking/rtems/rtems_glue.c | 6 | ||||
-rw-r--r-- | cpukit/libnetworking/rtems/rtems_malloc_mbuf.c | 33 |
4 files changed, 53 insertions, 4 deletions
diff --git a/cpukit/libnetworking/Makefile.am b/cpukit/libnetworking/Makefile.am index a4b72bd8ba..d475f0de6f 100644 --- a/cpukit/libnetworking/Makefile.am +++ b/cpukit/libnetworking/Makefile.am @@ -118,7 +118,7 @@ include_rtems_HEADERS = rtems/rtems_bsdnet.h rtems/rtems_bsdnet_internal.h \ include_rtems_HEADERS += rtems/rtems_mii_ioctl.h libnetworking_a_SOURCES += rtems/sghostname.c rtems/issetugid.c \ - rtems/rtems_glue.c rtems/rtems_syscall.c \ + rtems/rtems_glue.c rtems/rtems_malloc_mbuf.c rtems/rtems_syscall.c \ rtems/rtems_bootp.c rtems/rtems_dhcp.c \ rtems/rtems_showmbuf.c rtems/rtems_showroute.c rtems/rtems_showifstat.c \ rtems/rtems_showipstat.c rtems/rtems_showicmpstat.c \ diff --git a/cpukit/libnetworking/rtems/rtems_bsdnet.h b/cpukit/libnetworking/rtems/rtems_bsdnet.h index 7c7c2c8df4..3112779078 100644 --- a/cpukit/libnetworking/rtems/rtems_bsdnet.h +++ b/cpukit/libnetworking/rtems/rtems_bsdnet.h @@ -260,4 +260,20 @@ int rtems_bsdnet_synchronize_ntp (int interval, rtems_task_priority priority); */ void rtems_bsdnet_malloc_starvation(void); +/* + * mbuf malloc interface to enable custom allocation of mbuf's + * + * May be declared in user code. If not, then the default is to + * malloc. + */ +void* rtems_bsdnet_malloc_mbuf(size_t size, int type); + +/* + * Possible values of the type parameter to rtems_bsdnet_malloc_mbuf to assist + * in allocation of the structure. + */ +#define MBUF_MALLOC_NMBCLUSTERS (0) +#define MBUF_MALLOC_MCLREFCNT (1) +#define MBUF_MALLOC_MBUF (2) + #endif /* _RTEMS_BSDNET_H */ diff --git a/cpukit/libnetworking/rtems/rtems_glue.c b/cpukit/libnetworking/rtems/rtems_glue.c index dc9fa4bd68..657a2f862e 100644 --- a/cpukit/libnetworking/rtems/rtems_glue.c +++ b/cpukit/libnetworking/rtems/rtems_glue.c @@ -149,7 +149,7 @@ bsd_init (void) /* * Set up mbuf cluster data strutures */ - p = malloc ((nmbclusters*MCLBYTES)+MCLBYTES-1); + p = rtems_bsdnet_malloc_mbuf ((nmbclusters*MCLBYTES)+MCLBYTES-1, MBUF_MALLOC_NMBCLUSTERS); if (p == NULL) { printf ("Can't get network cluster memory.\n"); return -1; @@ -163,7 +163,7 @@ bsd_init (void) mbstat.m_clfree++; } mbstat.m_clusters = nmbclusters; - mclrefcnt = malloc (nmbclusters); + mclrefcnt = rtems_bsdnet_malloc_mbuf (nmbclusters, MBUF_MALLOC_MCLREFCNT); if (mclrefcnt == NULL) { printf ("Can't get mbuf cluster reference counts memory.\n"); return -1; @@ -174,7 +174,7 @@ bsd_init (void) * Set up mbuf data structures */ - p = malloc(nmbuf * MSIZE + MSIZE - 1); + p = rtems_bsdnet_malloc_mbuf(nmbuf * MSIZE + MSIZE - 1,MBUF_MALLOC_MBUF); p = (char *)(((unsigned int)p + MSIZE - 1) & ~(MSIZE - 1)); if (p == NULL) { printf ("Can't get network memory.\n"); diff --git a/cpukit/libnetworking/rtems/rtems_malloc_mbuf.c b/cpukit/libnetworking/rtems/rtems_malloc_mbuf.c new file mode 100644 index 0000000000..d5654c8297 --- /dev/null +++ b/cpukit/libnetworking/rtems/rtems_malloc_mbuf.c @@ -0,0 +1,33 @@ +/* + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#define RTEMS_FAST_MUTEX + +#ifdef RTEMS_FAST_MUTEX +#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ 1 +#endif + +#include <string.h> +#include <stdarg.h> +#include <stdio.h> +#include <errno.h> + +#include <rtems.h> +#include <rtems/rtems_bsdnet.h> + +/* + * Default allocator for mbuf data. Over-ride in user code to change + * the way mbuf's are allocated. + */ + +void* rtems_bsdnet_malloc_mbuf(size_t size, int type) +{ + return malloc(size); +} + + |