svn commit: r203908 - projects/tcp_cc_head/sys/netinet
Lawrence Stewart
lstewart at FreeBSD.org
Mon Feb 15 01:15:38 UTC 2010
Author: lstewart
Date: Mon Feb 15 01:15:37 2010
New Revision: 203908
URL: http://svn.freebsd.org/changeset/base/203908
Log:
Collapse helper dblock related management info into a single struct, and pass
this around as appropriate.
Modified:
projects/tcp_cc_head/sys/netinet/h_ertt.c
projects/tcp_cc_head/sys/netinet/helper.c
projects/tcp_cc_head/sys/netinet/helper.h
projects/tcp_cc_head/sys/netinet/hhooks.c
projects/tcp_cc_head/sys/netinet/hhooks.h
projects/tcp_cc_head/sys/netinet/tcp_input.c
projects/tcp_cc_head/sys/netinet/tcp_output.c
projects/tcp_cc_head/sys/netinet/tcp_subr.c
projects/tcp_cc_head/sys/netinet/tcp_var.h
Modified: projects/tcp_cc_head/sys/netinet/h_ertt.c
==============================================================================
--- projects/tcp_cc_head/sys/netinet/h_ertt.c Sun Feb 14 22:10:06 2010 (r203907)
+++ projects/tcp_cc_head/sys/netinet/h_ertt.c Mon Feb 15 01:15:37 2010 (r203908)
@@ -63,8 +63,10 @@ static VNET_DEFINE(uma_zone_t, txseginfo
#define DLYACK_SMOOTH 5 /* smoothing factor for delayed ack guess */
#define MAX_TS_ERR 10 /* maximum number of time stamp errors allowed in a session */
-void ertt_packet_measurement_hook(void *udata, void *ctx_data, void *dblock);
-void ertt_add_tx_segment_info_hook(void *udata, void *ctx_data, void *dblock);
+void ertt_packet_measurement_hook(void *udata, void *ctx_data, void *dblock,
+ struct helper_dblocks *hdbs);
+void ertt_add_tx_segment_info_hook(void *udata, void *ctx_data, void *dblock,
+ struct helper_dblocks *hdbs);
int ertt_mod_init(void);
int ertt_mod_destroy(void);
int ertt_uma_ctor(void *mem, int size, void *arg, int flags);
@@ -93,8 +95,8 @@ struct txseginfo {
struct helper ertt_helper = {
.mod_init = ertt_mod_init,
.mod_destroy = ertt_mod_destroy,
- .flags = HELPER_NEEDS_DBLOCK,
- .class = HELPER_CLASS_TCP
+ .h_flags = HELPER_NEEDS_DBLOCK,
+ .h_class = HELPER_CLASS_TCP
};
#define MULTI_ACK 1
@@ -135,7 +137,8 @@ marked_packet_rtt(struct txseginfo *txsi
* congestion control algorithms which require a more accurate time.
*/
void
-ertt_packet_measurement_hook(void *udata, void *ctx_data, void *dblock)
+ertt_packet_measurement_hook(void *udata, void *ctx_data, void *dblock,
+ struct helper_dblocks *hdbs)
{
//struct ertt *e = (struct ertt *)(((struct tcpcb *)inp->inp_ppcb)->helper_data[0]);
struct tcpcb *tp = ((struct tcp_hhook_data *)ctx_data)->tp;
@@ -264,7 +267,8 @@ ertt_packet_measurement_hook(void *udata
/* add transmitted segment info to the list */
void
-ertt_add_tx_segment_info_hook(void *udata, void *ctx_data, void *dblock)
+ertt_add_tx_segment_info_hook(void *udata, void *ctx_data, void *dblock,
+ struct helper_dblocks *hdbs)
{
struct tcpcb *tp = ((struct tcp_hhook_data *)ctx_data)->tp;
struct tcphdr *th = ((struct tcp_hhook_data *)ctx_data)->th;
Modified: projects/tcp_cc_head/sys/netinet/helper.c
==============================================================================
--- projects/tcp_cc_head/sys/netinet/helper.c Sun Feb 14 22:10:06 2010 (r203907)
+++ projects/tcp_cc_head/sys/netinet/helper.c Mon Feb 15 01:15:37 2010 (r203908)
@@ -48,25 +48,27 @@ __FBSDID("$FreeBSD$");
static struct rwlock helper_list_lock;
RW_SYSINIT(helperlistlock, &helper_list_lock, "helper list lock");
-static STAILQ_HEAD(hlpr_head, helper) helpers = STAILQ_HEAD_INITIALIZER(helpers);
+static STAILQ_HEAD(helper_head, helper) helpers = STAILQ_HEAD_INITIALIZER(helpers);
static int num_dblocks = 0;
/* Monotonically increasing ID assigned to helpers on registration. */
-static int helper_id = 0;
+static int32_t helper_id = 0;
-static struct helper * get_helper(int id);
+static struct helper * get_helper(int32_t id);
/*
* Public KPI functions.
*/
int
-init_helper_dblocks(struct helper_dblock **dblocks, int *nblocks)
+init_helper_dblocks(struct helper_dblocks *hdbs)
{
struct helper *h;
struct helper_dblock *dblock;
int i = 0, error = 0;
+ KASSERT(hdbs != NULL, ("struct helper_dblocks not initialised!"));
+
HELPER_LIST_RLOCK();
if (num_dblocks == 0) {
@@ -74,15 +76,18 @@ init_helper_dblocks(struct helper_dblock
return (0);
}
- *dblocks = malloc(num_dblocks * sizeof(struct helper_dblock), M_HELPER,
+ /* XXXLAS: Should only allocate for helpers of the appropriate class. */
+ hdbs->blocks = malloc(num_dblocks * sizeof(struct helper_dblock), M_HELPER,
M_NOWAIT | M_ZERO);
- if (*dblocks != NULL) {
- printf("Malloced ptr %p for %d data blocks\n", *dblocks, num_dblocks);
+ if (hdbs->blocks != NULL) {
+ printf("Malloced ptr %p for %d data blocks\n", hdbs->blocks,
+ hdbs->nblocks);
STAILQ_FOREACH(h, &helpers, h_next) {
- if (h->flags & HELPER_NEEDS_DBLOCK) {
- dblock = dblocks[i];
- dblock->block = uma_zalloc(h->zone, M_NOWAIT);
+ if (h->h_flags & HELPER_NEEDS_DBLOCK) {
+ dblock = hdbs->blocks+i;
+ dblock->hd_block = uma_zalloc(h->h_zone,
+ M_NOWAIT);
/*
if (dblock[i]->block == NULL) {
XXX: Free all previous dblocks.
@@ -90,13 +95,13 @@ init_helper_dblocks(struct helper_dblock
break;
}
*/
- dblock->id = h->id;
+ dblock->hd_id = h->h_id;
printf("dblock[%d]: id=%d, block=%p\n", i,
- dblock->id, dblock->block);
+ dblock->hd_id, dblock->hd_block);
i++;
}
}
- *nblocks = i;
+ hdbs->nblocks = i;
} else
error = ENOMEM;
@@ -105,19 +110,20 @@ init_helper_dblocks(struct helper_dblock
}
int
-destroy_helper_dblocks(struct helper_dblock *dblocks, int nblocks)
+destroy_helper_dblocks(struct helper_dblocks *hdbs)
{
struct helper *h;
+ int32_t nblocks = hdbs->nblocks;
HELPER_LIST_WLOCK();
for (nblocks--; nblocks >= 0; nblocks--) {
- if ((h = get_helper(dblocks[nblocks].id)) != NULL)
- uma_zfree(h->zone, dblocks[nblocks].block);
+ if ((h = get_helper(hdbs->blocks[nblocks].hd_id)) != NULL)
+ uma_zfree(h->h_zone, hdbs->blocks[nblocks].hd_block);
}
HELPER_LIST_WUNLOCK();
- free(dblocks, M_HELPER);
+ free(hdbs->blocks, M_HELPER);
return (0);
}
@@ -128,10 +134,10 @@ register_helper(struct helper *h)
HELPER_LIST_WLOCK();
- if (h->flags | HELPER_NEEDS_DBLOCK)
+ if (h->h_flags | HELPER_NEEDS_DBLOCK)
num_dblocks++;
- h->id = helper_id++;
+ h->h_id = helper_id++;
STAILQ_INSERT_TAIL(&helpers, h, h_next);
HELPER_LIST_WUNLOCK();
return (0);
@@ -150,22 +156,22 @@ deregister_helper(struct helper *h)
HELPER_LIST_WLOCK();
STAILQ_REMOVE(&helpers, h, helper, h_next);
- if (h->flags | HELPER_NEEDS_DBLOCK)
+ if (h->h_flags | HELPER_NEEDS_DBLOCK)
num_dblocks--;
HELPER_LIST_WUNLOCK();
return (0);
}
-int
+int32_t
get_helper_id(char *hname)
{
struct helper *h;
- int id = -1;
+ int32_t id = -1;
HELPER_LIST_RLOCK();
STAILQ_FOREACH(h, &helpers, h_next) {
- if (strncmp(h->name, hname, HELPER_NAME_MAXLEN) == 0) {
- id = h->id;
+ if (strncmp(h->h_name, hname, HELPER_NAME_MAXLEN) == 0) {
+ id = h->h_id;
break;
}
}
@@ -174,11 +180,13 @@ get_helper_id(char *hname)
}
void *
-get_helper_dblock(struct helper_dblock *dblocks, int nblocks, int id)
+get_helper_dblock(struct helper_dblocks *hdbs, int32_t id)
{
+ uint32_t nblocks = hdbs->nblocks;
+
for (nblocks--; nblocks >= 0; nblocks--) {
- if (dblocks[nblocks].id == id)
- return (dblocks[nblocks].block);
+ if (hdbs->blocks[nblocks].hd_id == id)
+ return (hdbs->blocks[nblocks].hd_block);
}
return (NULL);
}
@@ -187,14 +195,14 @@ get_helper_dblock(struct helper_dblock *
* Private KPI functions.
*/
static struct helper *
-get_helper(int id)
+get_helper(int32_t id)
{
struct helper *h;
HELPER_LIST_LOCK_ASSERT();
STAILQ_FOREACH(h, &helpers, h_next) {
- if (h->id == id)
+ if (h->h_id == id)
return (h);
}
return (NULL);
@@ -211,21 +219,22 @@ helper_modevent(module_t mod, int event_
switch(event_type) {
case MOD_LOAD:
- if (hmd->helper->flags & HELPER_NEEDS_DBLOCK) {
+ if (hmd->helper->h_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) {
+ hmd->helper->h_zone =
+ uma_zcreate(hmd->name, hmd->uma_zsize,
+ hmd->umactor, hmd->umadtor, NULL, NULL, 0,
+ 0);
+ if (hmd->helper->h_zone == NULL) {
error = ENOMEM;
break;
}
}
- strlcpy(hmd->helper->name, hmd->name,
+ strlcpy(hmd->helper->h_name, hmd->name,
HELPER_NAME_MAXLEN);
if (hmd->helper->mod_init != NULL)
error = hmd->helper->mod_init();
@@ -235,8 +244,7 @@ helper_modevent(module_t mod, int event_
case MOD_QUIESCE:
error = deregister_helper(hmd->helper);
- uma_zfree_all(hmd->helper->zone);
- uma_zdestroy(hmd->helper->zone);
+ uma_zdestroy(hmd->helper->h_zone);
if (!error && hmd->helper->mod_destroy != NULL)
hmd->helper->mod_destroy();
break;
Modified: projects/tcp_cc_head/sys/netinet/helper.h
==============================================================================
--- projects/tcp_cc_head/sys/netinet/helper.h Sun Feb 14 22:10:06 2010 (r203907)
+++ projects/tcp_cc_head/sys/netinet/helper.h Mon Feb 15 01:15:37 2010 (r203908)
@@ -35,31 +35,25 @@
struct helper_dblock {
- /* ID of the helper this data block is associated with */
- int id;
+ int32_t hd_id;
+ void *hd_block;
+};
- void *block;
+struct helper_dblocks {
+ struct helper_dblock *blocks;
+ int32_t nblocks;
+ uint32_t class;
};
-#define HELPER_NAME_MAXLEN 16
struct helper {
- char name[HELPER_NAME_MAXLEN];
- /* Init global module state on kldload. */
int (*mod_init) (void);
-
- /* Cleanup global module state on kldunload. */
int (*mod_destroy) (void);
-
- 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
- dynamic array */
-
-
+ uma_zone_t h_zone;
+#define HELPER_NAME_MAXLEN 16
+ char h_name[HELPER_NAME_MAXLEN];
+ uint16_t h_flags;
+ uint32_t h_class;
+ int32_t h_id;
STAILQ_ENTRY(helper) h_next;
};
@@ -69,13 +63,12 @@ struct helper {
/* Helper classes */
#define HELPER_CLASS_TCP 0x00000001
-int init_helper_dblocks(struct helper_dblock **dblocks, int *nblocks);
-int destroy_helper_dblocks(struct helper_dblock *dblocks, int nblocks);
+int init_helper_dblocks(struct helper_dblocks *hdbs);
+int destroy_helper_dblocks(struct helper_dblocks *hdbs);
int register_helper(struct helper *h);
int deregister_helper(struct helper *h);
-int get_helper_id(char *hname);
-void * get_helper_dblock(struct helper_dblock *dblocks,
- int nblocks, int id);
+int32_t get_helper_id(char *hname);
+void * get_helper_dblock(struct helper_dblocks *hdbs, int32_t id);
#define HELPER_LIST_WLOCK() rw_wlock(&helper_list_lock)
#define HELPER_LIST_WUNLOCK() rw_wunlock(&helper_list_lock)
Modified: projects/tcp_cc_head/sys/netinet/hhooks.c
==============================================================================
--- projects/tcp_cc_head/sys/netinet/hhooks.c Sun Feb 14 22:10:06 2010 (r203907)
+++ projects/tcp_cc_head/sys/netinet/hhooks.c Mon Feb 15 01:15:37 2010 (r203908)
@@ -215,13 +215,14 @@ deregister_hhook(int hhook_type, int hho
void
run_hhooks(int hhook_type, int hhook_id, void *ctx_data,
- struct helper_dblock *dblocks, int n_dblocks)
+ struct helper_dblocks *hdbs)
{
struct hhook_head *hh;
struct hhook *tmp;
struct rm_priotracker rmpt;
int i = 0;
void *dblock = NULL;
+ uint32_t nblocks = hdbs->nblocks;
hh = get_hhook_head(hhook_type, hhook_id, &rmpt, RLOCK_HHOOK_HEAD);
@@ -231,15 +232,15 @@ run_hhooks(int hhook_type, int hhook_id,
STAILQ_FOREACH(tmp, &hh->hh_hooks, h_next) {
//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_dblocks
- || tmp->h_helper->id != dblocks[i].id)
+ if (tmp->h_helper->h_flags & HELPER_NEEDS_DBLOCK) {
+ if (nblocks == 0
+ || i >= nblocks
+ || tmp->h_helper->h_id != hdbs->blocks[i].hd_id)
continue;
- dblock = dblocks[i].block;
+ dblock = hdbs->blocks[i].hd_block;
i++;
}
- tmp->h_func(tmp->h_udata, ctx_data, dblock);
+ tmp->h_func(tmp->h_udata, ctx_data, dblock, hdbs);
dblock = NULL;
}
Modified: projects/tcp_cc_head/sys/netinet/hhooks.h
==============================================================================
--- projects/tcp_cc_head/sys/netinet/hhooks.h Sun Feb 14 22:10:06 2010 (r203907)
+++ projects/tcp_cc_head/sys/netinet/hhooks.h Mon Feb 15 01:15:37 2010 (r203908)
@@ -38,12 +38,13 @@
#define HHOOK_TYPE_TCP 1
-typedef void (*hhook_func_t)(void *udata, void *ctx_data, void *helper_dblock);
-
struct helper;
-struct helper_dblock;
+struct helper_dblocks;
struct hhook_head;
+typedef void (*hhook_func_t)(void *udata, void *ctx_data, void *helper_dblock,
+ struct helper_dblocks *hdbs);
+
int register_hhook_head(int hhook_type, int hhook_id, int flags);
int deregister_hhook_head(int hhook_type, int hhook_id);
int register_hhook(int hhook_type, int hhook_id, struct helper *helper,
@@ -51,7 +52,7 @@ int register_hhook(int hhook_type, int h
int deregister_hhook(int hhook_type, int hhook_id, hhook_func_t hook,
void *udata, int flags);
void run_hhooks(int hhook_type, int hhook_id, void *ctx_data,
- struct helper_dblock *dblocks, int n_dblocks);
+ struct helper_dblocks *hdbs);
#define HHOOK_HEAD_LIST_LOCK() mtx_lock(&hhook_head_list_lock)
#define HHOOK_HEAD_LIST_UNLOCK() mtx_unlock(&hhook_head_list_lock)
Modified: projects/tcp_cc_head/sys/netinet/tcp_input.c
==============================================================================
--- projects/tcp_cc_head/sys/netinet/tcp_input.c Sun Feb 14 22:10:06 2010 (r203907)
+++ projects/tcp_cc_head/sys/netinet/tcp_input.c Mon Feb 15 01:15:37 2010 (r203908)
@@ -2131,8 +2131,8 @@ tcp_do_segment(struct mbuf *m, struct tc
hhook_data.tp = tp;
hhook_data.th = th;
hhook_data.to = &to;
- run_hhooks(HHOOK_TYPE_TCP, HHOOK_TCP_ESTABLISHED_IN, &hhook_data,
- tp->dblocks, tp->n_dblocks);
+ run_hhooks(HHOOK_TYPE_TCP, HHOOK_TCP_ESTABLISHED_IN,
+ &hhook_data, tp->hdbs);
if (SEQ_LEQ(th->th_ack, tp->snd_una)) {
if (tlen == 0 && tiwin == tp->snd_wnd) {
Modified: projects/tcp_cc_head/sys/netinet/tcp_output.c
==============================================================================
--- projects/tcp_cc_head/sys/netinet/tcp_output.c Sun Feb 14 22:10:06 2010 (r203907)
+++ projects/tcp_cc_head/sys/netinet/tcp_output.c Mon Feb 15 01:15:37 2010 (r203908)
@@ -1120,7 +1120,7 @@ timer:
hhook_data.len = len;
hhook_data.tso = tso;
run_hhooks(HHOOK_TYPE_TCP, HHOOK_TCP_ESTABLISHED_OUT, &hhook_data,
- tp->dblocks, tp->n_dblocks);
+ tp->hdbs);
#ifdef TCPDEBUG
Modified: projects/tcp_cc_head/sys/netinet/tcp_subr.c
==============================================================================
--- projects/tcp_cc_head/sys/netinet/tcp_subr.c Sun Feb 14 22:10:06 2010 (r203907)
+++ projects/tcp_cc_head/sys/netinet/tcp_subr.c Mon Feb 15 01:15:37 2010 (r203908)
@@ -294,6 +294,7 @@ static void tcp_isn_tick(void *);
struct tcpcb_mem {
struct tcpcb tcb;
struct tcp_timer tt;
+ struct helper_dblocks hdbs;
};
static VNET_DEFINE(uma_zone_t, tcpcb_zone);
@@ -773,13 +774,16 @@ tcp_newtcpcb(struct inpcb *inp)
if (CC_ALGO(tp)->cb_init != NULL)
if (CC_ALGO(tp)->cb_init(tp) > 0) {
- uma_zfree(V_tcpcb_zone, tp);
- return NULL;
+ uma_zfree(V_tcpcb_zone, tm);
+ return (NULL);
}
- KASSERT(tp->dblocks == NULL, ("tp->dblocks NOT NULL!"));
- init_helper_dblocks(&tp->dblocks, &tp->n_dblocks);
- printf("tp->dblocks = %p, tp->n_dblocks = %d\n", tp->dblocks, tp->n_dblocks);
+ tp->hdbs = &tm->hdbs;
+ tp->hdbs->class = HELPER_CLASS_TCP;
+ if (init_helper_dblocks(tp->hdbs)) {
+ uma_zfree(V_tcpcb_zone, tm);
+ return (NULL);
+ }
#ifdef VIMAGE
tp->t_vnet = inp->inp_vnet;
@@ -950,7 +954,7 @@ tcp_discardcb(struct tcpcb *tp)
if (CC_ALGO(tp)->cb_destroy != NULL)
CC_ALGO(tp)->cb_destroy(tp);
- destroy_helper_dblocks(tp->dblocks, tp->n_dblocks);
+ destroy_helper_dblocks(tp->hdbs);
CC_ALGO(tp) = NULL;
inp->inp_ppcb = NULL;
Modified: projects/tcp_cc_head/sys/netinet/tcp_var.h
==============================================================================
--- projects/tcp_cc_head/sys/netinet/tcp_var.h Sun Feb 14 22:10:06 2010 (r203907)
+++ projects/tcp_cc_head/sys/netinet/tcp_var.h Mon Feb 15 01:15:37 2010 (r203908)
@@ -206,8 +206,7 @@ struct tcpcb {
uint64_t _pad[12]; /* 7 UTO, 5 TBD (1-2 CC/RTT?) */
struct cc_algo *cc_algo; /* the algorithm that will manage congestion control*/
void *cc_data; /* pointer to a struct containing data required for the cc algorithm in use */
- struct helper_dblock *dblocks; /* */
- int n_dblocks;
+ struct helper_dblocks *hdbs;
};
/*
More information about the svn-src-projects
mailing list