Date: Mon, 8 Feb 2010 14:04:33 +0000 (UTC) From: Lawrence Stewart <lstewart@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r203661 - in projects/tcp_cc_head/sys: modules/ertt netinet Message-ID: <201002081404.o18E4Xkh063380@svn.freebsd.org>
index | next in thread | raw e-mail
Author: lstewart Date: Mon Feb 8 14:04:32 2010 New Revision: 203661 URL: http://svn.freebsd.org/changeset/base/203661 Log: - Switch to using UMA for helper data block memory management. - Add concept of helpers belonging to one or more classes so that we can eventually group related helpers. - Lots of bug fixing and cleanup around the place. Added: projects/tcp_cc_head/sys/netinet/h_ertt.c - copied, changed from r203640, projects/tcp_cc_head/sys/netinet/ertt.c Deleted: projects/tcp_cc_head/sys/netinet/ertt.c Modified: projects/tcp_cc_head/sys/modules/ertt/Makefile projects/tcp_cc_head/sys/netinet/helper.c projects/tcp_cc_head/sys/netinet/helper.h projects/tcp_cc_head/sys/netinet/helper_module.h projects/tcp_cc_head/sys/netinet/hhooks.c Modified: projects/tcp_cc_head/sys/modules/ertt/Makefile ============================================================================== --- projects/tcp_cc_head/sys/modules/ertt/Makefile Mon Feb 8 10:02:01 2010 (r203660) +++ projects/tcp_cc_head/sys/modules/ertt/Makefile Mon Feb 8 14:04:32 2010 (r203661) @@ -3,8 +3,8 @@ .include <bsd.own.mk> .PATH: ${.CURDIR}/../../netinet -KMOD=hlpr_ertt -SRCS=ertt.c +KMOD=h_ertt +SRCS=h_ertt.c .include <bsd.kmod.mk> Copied and modified: projects/tcp_cc_head/sys/netinet/h_ertt.c (from r203640, projects/tcp_cc_head/sys/netinet/ertt.c) ============================================================================== --- projects/tcp_cc_head/sys/netinet/ertt.c Sun Feb 7 22:24:04 2010 (r203640, copy source) +++ projects/tcp_cc_head/sys/netinet/h_ertt.c Mon Feb 8 14:04:32 2010 (r203661) @@ -55,8 +55,8 @@ __FBSDID("$FreeBSD$"); void ertt_tcpest_hook(void *udata, void *ctx_data, void *dblock); int ertt_mod_init(void); int ertt_mod_destroy(void); -int ertt_block_init(void **block); -int ertt_block_destroy(void *block); +int ertt_uma_ctor(void *mem, int size, void *arg, int flags); +void ertt_uma_dtor(void *mem, int size, void *arg); struct ertt { int test; @@ -65,9 +65,8 @@ struct ertt { struct helper ertt_helper = { .mod_init = ertt_mod_init, .mod_destroy = ertt_mod_destroy, - .block_init = ertt_block_init, - .block_destroy = ertt_block_destroy, - .flags = HELPER_NEEDS_DBLOCK + .flags = HELPER_NEEDS_DBLOCK, + .class = HELPER_CLASS_TCP }; @@ -96,25 +95,19 @@ ertt_mod_destroy(void) } int -ertt_block_init(void **block) +ertt_uma_ctor(void *mem, int size, void *arg, int flags) { - *block = malloc(sizeof(struct ertt), M_HELPER, M_NOWAIT); + printf("Creating ertt block %p\n", mem); - ((struct ertt *)*block)->test = 5; - - printf("Malloced %ld bytes for ertt and set the value to %d\n", - sizeof(struct ertt), ((struct ertt *)*block)->test); + ((struct ertt *)mem)->test = 5; return (0); } -int -ertt_block_destroy(void *block) +void +ertt_uma_dtor(void *mem, int size, void *arg) { - KASSERT(block != NULL, ("Block is NULL!")); - free(block, M_HELPER); - - return (0); + printf("Destroying ertt block %p\n", mem); } -DECLARE_HELPER(ertt, &ertt_helper); +DECLARE_HELPER_UMA(ertt, &ertt_helper, sizeof(struct ertt), ertt_uma_ctor, ertt_uma_dtor); Modified: projects/tcp_cc_head/sys/netinet/helper.c ============================================================================== --- projects/tcp_cc_head/sys/netinet/helper.c Mon Feb 8 10:02:01 2010 (r203660) +++ projects/tcp_cc_head/sys/netinet/helper.c Mon Feb 8 14:04:32 2010 (r203661) @@ -40,6 +40,8 @@ __FBSDID("$FreeBSD$"); #include <sys/rwlock.h> #include <sys/systm.h> +#include <vm/uma.h> + #include <netinet/helper.h> #include <netinet/helper_module.h> @@ -78,16 +80,23 @@ init_helper_dblocks(struct helper_dblock if (*dblocks != NULL) { printf("Malloced ptr %p for %d data blocks\n", *dblocks, num_dblocks); STAILQ_FOREACH(h, &helpers, h_next) { - if (h->block_init != NULL) { + if (h->flags & HELPER_NEEDS_DBLOCK) { dblock = dblocks[i]; - h->block_init(&dblock->block); + dblock->block = uma_zalloc(h->zone, M_NOWAIT); + /* + if (dblock[i]->block == NULL) { + XXX: Free all previous dblocks. + error = ENOMEM + break; + } + */ dblock->id = h->id; printf("dblock[%d]: id=%d, block=%p\n", i, dblock->id, dblock->block); + i++; } - i++; } - *nblocks = num_dblocks; + *nblocks = i; } else error = ENOMEM; @@ -96,26 +105,26 @@ init_helper_dblocks(struct helper_dblock } int -destroy_helper_dblocks(struct helper_dblock *array_head, int nblocks) +destroy_helper_dblocks(struct helper_dblock *dblocks, int nblocks) { struct helper *h; HELPER_LIST_WLOCK(); for (nblocks--; nblocks >= 0; nblocks--) { - h = get_helper(array_head[nblocks].id); - if (h->block_destroy != NULL) - h->block_destroy(array_head[nblocks].block); + h = get_helper(dblocks[nblocks].id); + uma_zfree(h->zone, dblocks[nblocks].block); } HELPER_LIST_WUNLOCK(); + free(dblocks, M_HELPER); return (0); } int register_helper(struct helper *h) { - printf("Register helper 0x%p\n", h); + printf("Register helper %p\n", h); HELPER_LIST_WLOCK(); @@ -123,26 +132,27 @@ register_helper(struct helper *h) num_dblocks++; h->id = helper_id++; - STAILQ_INSERT_TAIL(&helpers, h, h_next); - HELPER_LIST_WUNLOCK(); - return (0); } int deregister_helper(struct helper *h) { - printf("Deregister helper 0x%p\n", h); + printf("Deregister helper %p\n", h); + + /* + HHOOK_WLOCK + Remove this helper's hooks + HHOOK_WUNLOCK + */ HELPER_LIST_WLOCK(); STAILQ_REMOVE(&helpers, h, helper, h_next); - num_dblocks--; + if (h->flags | HELPER_NEEDS_DBLOCK) + num_dblocks--; HELPER_LIST_WUNLOCK(); - - /* Block unload if there are still consumers to avoid mem leak*/ - return (0); } @@ -167,23 +177,38 @@ get_helper(int id) * Handles kld related events. Returns 0 on success, non-zero on failure. */ int -hlpr_modevent(module_t mod, int event_type, void *data) +helper_modevent(module_t mod, int event_type, void *data) { int error = 0; - struct helper *h = (struct helper *)data; + struct helper_modevent_data *hmd = (struct helper_modevent_data *)data; switch(event_type) { case MOD_LOAD: - if (h->mod_init != NULL) - error = h->mod_init(); + if (hmd->helper->flags & HELPER_NEEDS_DBLOCK) { + if (hmd->uma_zsize <= 0) { + printf("Use DECLARE_HELPER_UMA() instead!\n"); + error = EDOOFUS; + break; + } + hmd->helper->zone = uma_zcreate(hmd->name, + hmd->uma_zsize, hmd->umactor, hmd->umadtor, + NULL, NULL, 0, 0); + if (hmd->helper->zone == NULL) { + error = ENOMEM; + break; + } + } + if (hmd->helper->mod_init != NULL) + error = hmd->helper->mod_init(); if (!error) - error = register_helper(h); + error = register_helper(hmd->helper); break; case MOD_QUIESCE: - error = deregister_helper(h); - if (!error && h->mod_destroy != NULL) - h->mod_destroy(); + error = deregister_helper(hmd->helper); + uma_zdestroy(hmd->helper->zone); + if (!error && hmd->helper->mod_destroy != NULL) + hmd->helper->mod_destroy(); break; case MOD_SHUTDOWN: Modified: projects/tcp_cc_head/sys/netinet/helper.h ============================================================================== --- projects/tcp_cc_head/sys/netinet/helper.h Mon Feb 8 10:02:01 2010 (r203660) +++ projects/tcp_cc_head/sys/netinet/helper.h Mon Feb 8 14:04:32 2010 (r203661) @@ -48,10 +48,10 @@ struct helper { /* Cleanup global module state on kldunload. */ int (*mod_destroy) (void); - int (*block_init) (void **data); - int (*block_destroy) (void *data); - uint16_t flags; + uint32_t class; + + uma_zone_t zone; //STAILQ hooks; /* which hooks does this helper want to be called from */ unsigned int id; /* ID assigned by system to this hlpr's data in the @@ -64,6 +64,8 @@ struct helper { /* Helper flags */ #define HELPER_NEEDS_DBLOCK 0x0001 +/* Helper classes */ +#define HELPER_CLASS_TCP 0x00000001 int init_helper_dblocks(struct helper_dblock **dblocks, int *nblocks); int destroy_helper_dblocks(struct helper_dblock *array_head, int nblocks); Modified: projects/tcp_cc_head/sys/netinet/helper_module.h ============================================================================== --- projects/tcp_cc_head/sys/netinet/helper_module.h Mon Feb 8 10:02:01 2010 (r203660) +++ projects/tcp_cc_head/sys/netinet/helper_module.h Mon Feb 8 14:04:32 2010 (r203661) @@ -30,22 +30,50 @@ * $FreeBSD$ */ -#ifndef _NETINET_TCP_HELPER_MODULE_H_ -#define _NETINET_TCP_HELPER_MODULE_H_ +#ifndef _NETINET_HELPER_MODULE_H_ +#define _NETINET_HELPER_MODULE_H_ -#define DECLARE_HELPER(hlprname, hlpr_data) \ - static moduledata_t hlpr_##hlprname = { \ - #hlprname, \ - hlpr_modevent, \ - hlpr_data \ +struct helper_modevent_data { + char *name; + struct helper *helper; + int uma_zsize; + uma_ctor umactor; + uma_dtor umadtor; +}; + +#define DECLARE_HELPER(hname, hdata) \ + static struct helper_modevent_data hmd_##hname = { \ + .name = #hname, \ + .helper = hdata \ }; \ - DECLARE_MODULE(hlprname, hlpr_##hlprname, SI_SUB_PROTO_IFATTACHDOMAIN, \ + static moduledata_t h_##hname = { \ + .name = #hname, \ + .evhand = helper_modevent, \ + .priv = &hmd_##hname \ + }; \ + DECLARE_MODULE(hname, h_##hname, SI_SUB_PROTO_IFATTACHDOMAIN, \ + SI_ORDER_ANY) + +#define DECLARE_HELPER_UMA(hname, hdata, size, ctor, dtor) \ + static struct helper_modevent_data hmd_##hname = { \ + .name = #hname, \ + .helper = hdata, \ + .uma_zsize = size, \ + .umactor = ctor, \ + .umadtor = dtor \ + }; \ + static moduledata_t h_##hname = { \ + .name = #hname, \ + .evhand = helper_modevent, \ + .priv = &hmd_##hname \ + }; \ + DECLARE_MODULE(hname, h_##hname, SI_SUB_PROTO_IFATTACHDOMAIN, \ SI_ORDER_ANY) -int hlpr_modevent(module_t mod, int type, void *data); +int helper_modevent(module_t mod, int type, void *data); MALLOC_DECLARE(M_HELPER); MALLOC_DEFINE(M_HELPER, "helper data", "Blah"); -#endif +#endif /* _NETINET_HELPER_MODULE_H_ */ Modified: projects/tcp_cc_head/sys/netinet/hhooks.c ============================================================================== --- projects/tcp_cc_head/sys/netinet/hhooks.c Mon Feb 8 10:02:01 2010 (r203660) +++ projects/tcp_cc_head/sys/netinet/hhooks.c Mon Feb 8 14:04:32 2010 (r203661) @@ -39,6 +39,8 @@ __FBSDID("$FreeBSD$"); #include <sys/rmlock.h> #include <sys/systm.h> +#include <vm/uma.h> + #include <net/vnet.h> #include <netinet/helper.h> @@ -227,8 +229,8 @@ run_hhooks(int hhook_type, int hhook_id, return; STAILQ_FOREACH(tmp, &hh->hh_hooks, h_next) { - printf("Running hook %p for helper %d\n", tmp, - tmp->h_helper->id); + //printf("Running hook %p for helper %d\n", tmp, + //tmp->h_helper->id); if (tmp->h_helper->flags & HELPER_NEEDS_DBLOCK) { if (n_dblocks == 0 || i >= n_dblockshelp
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201002081404.o18E4Xkh063380>
