diff options
author | Kazuya Goda <goda@cvs.openbsd.org> | 2016-09-04 16:47:42 +0000 |
---|---|---|
committer | Kazuya Goda <goda@cvs.openbsd.org> | 2016-09-04 16:47:42 +0000 |
commit | 11028848166a1912e780e741d81ce0a0a6bc0077 (patch) | |
tree | 8283f7ea6a8b29483afcb494221c3c5614400dfc /sys | |
parent | 77773221a4822f6cc13b6af75c7fd84d3e560f46 (diff) |
Make per-packet allocated memory use pool in switch(4)
ok yasuoka@ reyk@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/net/if_switch.c | 7 | ||||
-rw-r--r-- | sys/net/if_switch.h | 7 | ||||
-rw-r--r-- | sys/net/switchofp.c | 70 |
3 files changed, 32 insertions, 52 deletions
diff --git a/sys/net/if_switch.c b/sys/net/if_switch.c index c0032f93749..e6264a149ef 100644 --- a/sys/net/if_switch.c +++ b/sys/net/if_switch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_switch.c,v 1.3 2016/09/03 13:46:57 reyk Exp $ */ +/* $OpenBSD: if_switch.c,v 1.4 2016/09/04 16:47:41 goda Exp $ */ /* * Copyright (c) 2016 Kazuya GODA <goda@openbsd.org> @@ -144,6 +144,7 @@ switchattach(int n) { pool_init(&swfcl_pool, sizeof(union switch_field), 0, 0, 0, "swfcl", NULL); + swofp_attach(); LIST_INIT(&switch_list); if_clone_attach(&switch_cloner); DPRINTF("switch attached\n"); @@ -190,7 +191,7 @@ switch_clone_create(struct if_clone *ifc, int unit) return (ENOMEM); } - swofp_attach(sc); + swofp_create(sc); if_attach(ifp); if_alloc_sadl(ifp); @@ -229,7 +230,7 @@ switch_clone_destroy(struct ifnet *ifp) } LIST_REMOVE(sc, sc_switch_next); bstp_destroy(sc->sc_stp); - swofp_detach(sc); + swofp_destroy(sc); switch_dev_destroy(sc); if_deactivate(ifp); if_detach(ifp); diff --git a/sys/net/if_switch.h b/sys/net/if_switch.h index 48dbcbd1f70..7765ac20e11 100644 --- a/sys/net/if_switch.h +++ b/sys/net/if_switch.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_switch.h,v 1.1 2016/09/01 10:06:33 goda Exp $ */ +/* $OpenBSD: if_switch.h,v 1.2 2016/09/04 16:47:41 goda Exp $ */ /* * Copyright (c) 2016 Kazuya GODA <goda@openbsd.org> @@ -220,9 +220,10 @@ void switch_swfcl_free(struct switch_flow_classify *); void switch_dev_destroy(struct switch_softc *); /* in switchofp.c */ -int swofp_attach(struct switch_softc *); +void swofp_attach(void); +int swofp_create(struct switch_softc *); int swofp_init(struct switch_softc *); -void swofp_detach(struct switch_softc *); +void swofp_destroy(struct switch_softc *); int swofp_ioctl(struct ifnet *, unsigned long, caddr_t); uint32_t swofp_assign_portno(struct switch_softc *, uint32_t); diff --git a/sys/net/switchofp.c b/sys/net/switchofp.c index 6b9102cf59e..2fc1521710b 100644 --- a/sys/net/switchofp.c +++ b/sys/net/switchofp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: switchofp.c,v 1.2 2016/09/02 10:01:36 goda Exp $ */ +/* $OpenBSD: switchofp.c,v 1.3 2016/09/04 16:47:41 goda Exp $ */ /* * Copyright (c) 2016 Kazuya GODA <goda@openbsd.org> @@ -113,15 +113,17 @@ struct swofp_action_set { struct ofp_action_header *swas_action; }; +/* Same as total number of OFP_ACTION_ */ +#define SWOFP_ACTION_SET_MAX 18 struct swofp_pipline_desc { uint32_t swpld_table_id; uint64_t swpld_cookie; uint64_t swpld_metadata; struct switch_flow_classify *swpld_swfcl; - struct switch_flow_classify *swpld_pre_swfcl; + struct switch_flow_classify swpld_pre_swfcl; struct switch_fwdp_queue swpld_fwdp_q; - struct swofp_action_set *swpld_action_set; - struct ofp_action_header *swpld_set_fields; /* using for free */ + struct swofp_action_set swpld_action_set[SWOFP_ACTION_SET_MAX]; + struct ofp_action_header *swpld_set_fields[OFP_XM_T_MAX]; }; struct swofp_ofs { @@ -918,11 +920,20 @@ struct ofp_action_handler ofp_action_handlers[] = { }; extern struct pool swfcl_pool; +struct pool swpld_pool; int swofp_flow_id = 0; +void +swofp_attach(void) +{ + pool_init(&swpld_pool, sizeof(struct swofp_pipline_desc), 0, 0, 0, + "swpld", NULL); +} + + int -swofp_attach(struct switch_softc *sc) +swofp_create(struct switch_softc *sc) { struct swofp_ofs *swofs; int error; @@ -964,7 +975,7 @@ swofp_attach(struct switch_softc *sc) } void -swofp_detach(struct switch_softc *sc) +swofp_destroy(struct switch_softc *sc) { struct swofp_ofs *swofs = sc->sc_ofs; @@ -1167,30 +1178,17 @@ swofp_pipline_desc_create(struct switch_flow_classify *swfcl) struct swofp_pipline_desc *swpld = NULL; struct swofp_action_set *swas = NULL; struct ofp_action_header *set_fields = NULL; - struct switch_flow_classify *pre_swfcl = NULL; int i; - swpld = malloc(sizeof(*swpld), M_DEVBUF, M_NOWAIT|M_ZERO); + swpld = pool_get(&swpld_pool, PR_NOWAIT|PR_ZERO); if (swpld == NULL) - goto failed; - - swas = malloc((sizeof(*swas) * nitems(ofp_action_handlers)), - M_DEVBUF, M_NOWAIT|M_ZERO); - if (swas == NULL) - goto failed; - - set_fields = malloc((sizeof(set_fields) * OFP_XM_T_MAX), - M_DEVBUF, M_NOWAIT|M_ZERO); - if (set_fields == NULL) - goto failed; + return (NULL); - pre_swfcl = malloc(sizeof(*pre_swfcl), M_DEVBUF, M_NOWAIT|M_ZERO); - if (pre_swfcl == NULL) - goto failed; /* * ofp_action_handlers is sorted by applying action-set order, * so it can be used for initializer for action-set. */ + swas = swpld->swpld_action_set; for (i = 0; i < nitems(ofp_action_handlers); i++) { swas[i].swas_type = ofp_action_handlers[i].action_type; if (swas[i].swas_type == OFP_ACTION_SET_FIELD) @@ -1199,36 +1197,16 @@ swofp_pipline_desc_create(struct switch_flow_classify *swfcl) swas[i].swas_action = NULL; } - swpld->swpld_action_set = swas; swpld->swpld_swfcl = swfcl; - swpld->swpld_pre_swfcl = pre_swfcl; - swpld->swpld_set_fields = set_fields; return (swpld); - - failed: - free(set_fields, M_DEVBUF, (sizeof(set_fields) * OFP_XM_T_MAX)); - free(swas, M_DEVBUF, (sizeof(*swas) * nitems(ofp_action_handlers))); - free(swpld, M_DEVBUF, sizeof(*swpld)); - - return (NULL); } void swofp_pipline_desc_destroy(struct swofp_pipline_desc *swpld) { - switch_swfcl_free(swpld->swpld_pre_swfcl); - - free(swpld->swpld_pre_swfcl, M_DEVBUF, - sizeof(*swpld->swpld_pre_swfcl)); - - free(swpld->swpld_set_fields, M_DEVBUF, - (sizeof(struct ofp_action_header) * OFP_XM_T_MAX)); - - free(swpld->swpld_action_set, M_DEVBUF, - (sizeof(struct swofp_action_set) * nitems(ofp_action_handlers))); - - free(swpld, M_DEVBUF, sizeof(*swpld)); + switch_swfcl_free(&swpld->swpld_pre_swfcl); + pool_put(&swpld_pool, swpld); } @@ -3768,7 +3746,7 @@ struct mbuf * swofp_apply_set_field(struct mbuf *m, struct swofp_pipline_desc *swpld) { return swofp_apply_set_field_ether(m, 0, - swpld->swpld_pre_swfcl, swpld->swpld_swfcl); + &swpld->swpld_pre_swfcl, swpld->swpld_swfcl); } struct mbuf * @@ -3789,7 +3767,7 @@ swofp_action_set_field(struct switch_softc *sc, struct mbuf *m, goto failed; swfcl = swpld->swpld_swfcl; - pre_swfcl = swpld->swpld_pre_swfcl; + pre_swfcl = &swpld->swpld_pre_swfcl; if (oxm->oxm_class == htons(OFP_OXM_C_NXM_1)) { switch (OFP_OXM_GET_FIELD(oxm)) { |