diff options
author | Rafael Zalamena <rzalamena@users.noreply.github.com> | 2023-01-24 22:46:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-24 22:46:52 +0100 |
commit | 9ffd15013a7597106770bf8383be462694204bde (patch) | |
tree | 0ed220a1dd9080c65731cd33e99ca9233357f581 /zebra | |
parent | Merge pull request #12670 from louis-6wind/fix-bfd-zclient (diff) | |
parent | zebra: use typesafe lib lists in zebra dplane (diff) | |
download | frr-9ffd15013a7597106770bf8383be462694204bde.tar.xz frr-9ffd15013a7597106770bf8383be462694204bde.zip |
Merge pull request #12680 from mjstapp/fix_dplane_lists
zebra: use typesafe lib lists in zebra dplane
Diffstat (limited to 'zebra')
-rw-r--r-- | zebra/dplane_fpm_nl.c | 4 | ||||
-rw-r--r-- | zebra/kernel_netlink.c | 17 | ||||
-rw-r--r-- | zebra/kernel_socket.c | 8 | ||||
-rw-r--r-- | zebra/rt.h | 2 | ||||
-rw-r--r-- | zebra/zebra_dplane.c | 229 | ||||
-rw-r--r-- | zebra/zebra_dplane.h | 25 | ||||
-rw-r--r-- | zebra/zebra_rib.c | 10 |
7 files changed, 144 insertions, 151 deletions
diff --git a/zebra/dplane_fpm_nl.c b/zebra/dplane_fpm_nl.c index af75ddf74..0a9fecc9d 100644 --- a/zebra/dplane_fpm_nl.c +++ b/zebra/dplane_fpm_nl.c @@ -89,7 +89,7 @@ struct fpm_nl_ctx { * When a FPM server connection becomes a bottleneck, we must keep the * data plane contexts until we get a chance to process them. */ - struct dplane_ctx_q ctxqueue; + struct dplane_ctx_list_head ctxqueue; pthread_mutex_t ctxqueue_mutex; /* data plane events. */ @@ -1473,7 +1473,7 @@ static int fpm_nl_start(struct zebra_dplane_provider *prov) fnc->socket = -1; fnc->disabled = true; fnc->prov = prov; - TAILQ_INIT(&fnc->ctxqueue); + dplane_ctx_q_init(&fnc->ctxqueue); pthread_mutex_init(&fnc->ctxqueue_mutex, NULL); /* Set default values. */ diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c index 54d9561e2..42afe6146 100644 --- a/zebra/kernel_netlink.c +++ b/zebra/kernel_netlink.c @@ -202,13 +202,13 @@ struct nl_batch { const struct zebra_dplane_info *zns; - struct dplane_ctx_q ctx_list; + struct dplane_ctx_list_head ctx_list; /* * Pointer to the queue of completed contexts outbound back * towards the dataplane module. */ - struct dplane_ctx_q *ctx_out_q; + struct dplane_ctx_list_head *ctx_out_q; }; int netlink_config_write_helper(struct vty *vty) @@ -1446,10 +1446,11 @@ static void nl_batch_reset(struct nl_batch *bth) bth->msgcnt = 0; bth->zns = NULL; - TAILQ_INIT(&(bth->ctx_list)); + dplane_ctx_q_init(&(bth->ctx_list)); } -static void nl_batch_init(struct nl_batch *bth, struct dplane_ctx_q *ctx_out_q) +static void nl_batch_init(struct nl_batch *bth, + struct dplane_ctx_list_head *ctx_out_q) { /* * If the size of the buffer has changed, free and then allocate a new @@ -1665,14 +1666,14 @@ static enum netlink_msg_status nl_put_msg(struct nl_batch *bth, return FRR_NETLINK_ERROR; } -void kernel_update_multi(struct dplane_ctx_q *ctx_list) +void kernel_update_multi(struct dplane_ctx_list_head *ctx_list) { struct nl_batch batch; struct zebra_dplane_ctx *ctx; - struct dplane_ctx_q handled_list; + struct dplane_ctx_list_head handled_list; enum netlink_msg_status res; - TAILQ_INIT(&handled_list); + dplane_ctx_q_init(&handled_list); nl_batch_init(&batch, &handled_list); while (true) { @@ -1703,7 +1704,7 @@ void kernel_update_multi(struct dplane_ctx_q *ctx_list) nl_batch_send(&batch); - TAILQ_INIT(ctx_list); + dplane_ctx_q_init(ctx_list); dplane_ctx_list_append(ctx_list, &handled_list); } diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index f84d31cc4..684ccc3ed 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -1516,13 +1516,13 @@ int kernel_dplane_read(struct zebra_dplane_info *info) return 0; } -void kernel_update_multi(struct dplane_ctx_q *ctx_list) +void kernel_update_multi(struct dplane_ctx_list_head *ctx_list) { struct zebra_dplane_ctx *ctx; - struct dplane_ctx_q handled_list; + struct dplane_ctx_list_head handled_list; enum zebra_dplane_result res = ZEBRA_DPLANE_REQUEST_SUCCESS; - TAILQ_INIT(&handled_list); + dplane_ctx_q_init(&handled_list); while (true) { ctx = dplane_ctx_dequeue(ctx_list); @@ -1642,7 +1642,7 @@ void kernel_update_multi(struct dplane_ctx_q *ctx_list) dplane_ctx_enqueue_tail(&handled_list, ctx); } - TAILQ_INIT(ctx_list); + dplane_ctx_q_init(ctx_list); dplane_ctx_list_append(ctx_list, &handled_list); } diff --git a/zebra/rt.h b/zebra/rt.h index 4cf4c9d78..6f4dd48a5 100644 --- a/zebra/rt.h +++ b/zebra/rt.h @@ -121,7 +121,7 @@ extern int kernel_del_mac_nhg(uint32_t nhg_id); /* * Message batching interface. */ -extern void kernel_update_multi(struct dplane_ctx_q *ctx_list); +extern void kernel_update_multi(struct dplane_ctx_list_head *ctx_list); /* * Called by the dplane pthread to read incoming OS messages and dispatch them. diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c index 739f6adce..7db8fba95 100644 --- a/zebra/zebra_dplane.c +++ b/zebra/zebra_dplane.c @@ -26,7 +26,6 @@ #include "lib/frratomic.h" #include "lib/frr_pthread.h" #include "lib/memory.h" -#include "lib/queue.h" #include "lib/zebra.h" #include "zebra/netconf_netlink.h" #include "zebra/zebra_router.h" @@ -103,7 +102,7 @@ struct dplane_intf_extra { uint32_t flags; uint32_t status; - TAILQ_ENTRY(dplane_intf_extra) link; + struct dplane_intf_extra_list_item dlink; }; /* @@ -152,7 +151,7 @@ struct dplane_route_info { struct nexthop_group old_backup_ng; /* Optional list of extra interface info */ - TAILQ_HEAD(dp_intf_extra_q, dplane_intf_extra) intf_extra_q; + struct dplane_intf_extra_list_head intf_extra_list; }; /* @@ -415,7 +414,7 @@ struct zebra_dplane_ctx { struct zebra_dplane_info zd_ns_info; /* Embedded list linkage */ - TAILQ_ENTRY(zebra_dplane_ctx) zd_q_entries; + struct dplane_ctx_list_item zd_entries; }; /* Flag that can be set by a pre-kernel provider as a signal that an update @@ -423,6 +422,12 @@ struct zebra_dplane_ctx { */ #define DPLANE_CTX_FLAG_NO_KERNEL 0x01 +/* List types declared now that the structs involved are defined. */ +DECLARE_DLIST(dplane_ctx_list, struct zebra_dplane_ctx, zd_entries); +DECLARE_DLIST(dplane_intf_extra_list, struct dplane_intf_extra, dlink); + +/* List for dplane plugins/providers */ +PREDECL_DLIST(dplane_prov_list); /* * Registration block for one dataplane provider. @@ -461,17 +466,20 @@ struct zebra_dplane_provider { _Atomic uint32_t dp_error_counter; /* Queue of contexts inbound to the provider */ - struct dplane_ctx_q dp_ctx_in_q; + struct dplane_ctx_list_head dp_ctx_in_list; /* Queue of completed contexts outbound from the provider back * towards the dataplane module. */ - struct dplane_ctx_q dp_ctx_out_q; + struct dplane_ctx_list_head dp_ctx_out_list; /* Embedded list linkage for provider objects */ - TAILQ_ENTRY(zebra_dplane_provider) dp_prov_link; + struct dplane_prov_list_item dp_link; }; +/* Declare list of providers/plugins */ +DECLARE_DLIST(dplane_prov_list, struct zebra_dplane_provider, dp_link); + /* Declare types for list of zns info objects */ PREDECL_DLIST(zns_info_list); @@ -496,7 +504,7 @@ static struct zebra_dplane_globals { pthread_mutex_t dg_mutex; /* Results callback registered by zebra 'core' */ - int (*dg_results_cb)(struct dplane_ctx_q *ctxlist); + int (*dg_results_cb)(struct dplane_ctx_list_head *ctxlist); /* Sentinel for beginning of shutdown */ volatile bool dg_is_shutdown; @@ -505,10 +513,10 @@ static struct zebra_dplane_globals { volatile bool dg_run; /* Update context queue inbound to the dataplane */ - TAILQ_HEAD(zdg_ctx_q, zebra_dplane_ctx) dg_update_ctx_q; + struct dplane_ctx_list_head dg_update_list; /* Ordered list of providers */ - TAILQ_HEAD(zdg_prov_q, zebra_dplane_provider) dg_providers_q; + struct dplane_prov_list_head dg_providers; /* List of info about each zns */ struct zns_info_list_head dg_zns_list; @@ -668,7 +676,7 @@ void dplane_enable_sys_route_notifs(void) */ static void dplane_ctx_free_internal(struct zebra_dplane_ctx *ctx) { - struct dplane_intf_extra *if_extra, *if_tmp; + struct dplane_intf_extra *if_extra; /* * Some internal allocations may need to be freed, depending on @@ -713,12 +721,9 @@ static void dplane_ctx_free_internal(struct zebra_dplane_ctx *ctx) } /* Optional extra interface info */ - TAILQ_FOREACH_SAFE(if_extra, &ctx->u.rinfo.intf_extra_q, - link, if_tmp) { - TAILQ_REMOVE(&ctx->u.rinfo.intf_extra_q, if_extra, - link); + while ((if_extra = dplane_intf_extra_list_pop( + &ctx->u.rinfo.intf_extra_list))) XFREE(MTYPE_DP_INTF, if_extra); - } break; @@ -885,39 +890,40 @@ void dplane_ctx_fini(struct zebra_dplane_ctx **pctx) dplane_ctx_free(pctx); } +/* Init a list of contexts */ +void dplane_ctx_q_init(struct dplane_ctx_list_head *q) +{ + dplane_ctx_list_init(q); +} + /* Enqueue a context block */ -void dplane_ctx_enqueue_tail(struct dplane_ctx_q *q, +void dplane_ctx_enqueue_tail(struct dplane_ctx_list_head *list, const struct zebra_dplane_ctx *ctx) { - TAILQ_INSERT_TAIL(q, (struct zebra_dplane_ctx *)ctx, zd_q_entries); + dplane_ctx_list_add_tail(list, (struct zebra_dplane_ctx *)ctx); } /* Append a list of context blocks to another list */ -void dplane_ctx_list_append(struct dplane_ctx_q *to_list, - struct dplane_ctx_q *from_list) +void dplane_ctx_list_append(struct dplane_ctx_list_head *to_list, + struct dplane_ctx_list_head *from_list) { - if (TAILQ_FIRST(from_list)) { - TAILQ_CONCAT(to_list, from_list, zd_q_entries); + struct zebra_dplane_ctx *ctx; - /* And clear 'from' list */ - TAILQ_INIT(from_list); - } + while ((ctx = dplane_ctx_list_pop(from_list)) != NULL) + dplane_ctx_list_add_tail(to_list, ctx); } -struct zebra_dplane_ctx *dplane_ctx_get_head(struct dplane_ctx_q *q) +struct zebra_dplane_ctx *dplane_ctx_get_head(struct dplane_ctx_list_head *q) { - struct zebra_dplane_ctx *ctx = TAILQ_FIRST(q); + struct zebra_dplane_ctx *ctx = dplane_ctx_list_first(q); return ctx; } /* Dequeue a context block from the head of a list */ -struct zebra_dplane_ctx *dplane_ctx_dequeue(struct dplane_ctx_q *q) +struct zebra_dplane_ctx *dplane_ctx_dequeue(struct dplane_ctx_list_head *q) { - struct zebra_dplane_ctx *ctx = TAILQ_FIRST(q); - - if (ctx) - TAILQ_REMOVE(q, ctx, zd_q_entries); + struct zebra_dplane_ctx *ctx = dplane_ctx_list_pop(q); return ctx; } @@ -2597,14 +2603,16 @@ void dplane_ctx_rule_set_dp_flow_ptr(struct zebra_dplane_ctx *ctx, const struct dplane_intf_extra * dplane_ctx_get_intf_extra(const struct zebra_dplane_ctx *ctx) { - return TAILQ_FIRST(&ctx->u.rinfo.intf_extra_q); + return dplane_intf_extra_list_const_first( + &ctx->u.rinfo.intf_extra_list); } const struct dplane_intf_extra * dplane_ctx_intf_extra_next(const struct zebra_dplane_ctx *ctx, const struct dplane_intf_extra *ptr) { - return TAILQ_NEXT(ptr, link); + return dplane_intf_extra_list_const_next(&ctx->u.rinfo.intf_extra_list, + ptr); } vrf_id_t dplane_intf_extra_get_vrfid(const struct dplane_intf_extra *ptr) @@ -2793,7 +2801,7 @@ int dplane_ctx_route_init_basic(struct zebra_dplane_ctx *ctx, if (!ctx || !re) return ret; - TAILQ_INIT(&ctx->u.rinfo.intf_extra_q); + dplane_intf_extra_list_init(&ctx->u.rinfo.intf_extra_list); ctx->zd_op = op; ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; @@ -2896,8 +2904,9 @@ int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op, if_extra->flags = ifp->flags; if_extra->status = ifp->status; - TAILQ_INSERT_TAIL(&ctx->u.rinfo.intf_extra_q, - if_extra, link); + dplane_intf_extra_list_add_tail( + &ctx->u.rinfo.intf_extra_list, + if_extra); } } @@ -3622,8 +3631,7 @@ static int dplane_update_enqueue(struct zebra_dplane_ctx *ctx) /* Enqueue for processing by the dataplane pthread */ DPLANE_LOCK(); { - TAILQ_INSERT_TAIL(&zdplane_info.dg_update_ctx_q, ctx, - zd_q_entries); + dplane_ctx_list_add_tail(&zdplane_info.dg_update_list, ctx); } DPLANE_UNLOCK(); @@ -5520,7 +5528,7 @@ int dplane_show_provs_helper(struct vty *vty, bool detailed) vty_out(vty, "Zebra dataplane providers:\n"); DPLANE_LOCK(); - prov = TAILQ_FIRST(&zdplane_info.dg_providers_q); + prov = dplane_prov_list_first(&zdplane_info.dg_providers); DPLANE_UNLOCK(); /* Show counters, useful info from each registered provider */ @@ -5544,7 +5552,7 @@ int dplane_show_provs_helper(struct vty *vty, bool detailed) out, out_q, out_max); DPLANE_LOCK(); - prov = TAILQ_NEXT(prov, dp_prov_link); + prov = dplane_prov_list_next(&zdplane_info.dg_providers, prov); DPLANE_UNLOCK(); } @@ -5595,8 +5603,8 @@ int dplane_provider_register(const char *name, p = XCALLOC(MTYPE_DP_PROV, sizeof(struct zebra_dplane_provider)); pthread_mutex_init(&(p->dp_mutex), NULL); - TAILQ_INIT(&(p->dp_ctx_in_q)); - TAILQ_INIT(&(p->dp_ctx_out_q)); + dplane_ctx_list_init(&p->dp_ctx_in_list); + dplane_ctx_list_init(&p->dp_ctx_out_list); p->dp_flags = flags; p->dp_priority = prio; @@ -5617,16 +5625,15 @@ int dplane_provider_register(const char *name, "provider-%u", p->dp_id); /* Insert into list ordered by priority */ - TAILQ_FOREACH(last, &zdplane_info.dg_providers_q, dp_prov_link) { + frr_each (dplane_prov_list, &zdplane_info.dg_providers, last) { if (last->dp_priority > p->dp_priority) break; } if (last) - TAILQ_INSERT_BEFORE(last, p, dp_prov_link); + dplane_prov_list_add_after(&zdplane_info.dg_providers, last, p); else - TAILQ_INSERT_TAIL(&zdplane_info.dg_providers_q, p, - dp_prov_link); + dplane_prov_list_add_tail(&zdplane_info.dg_providers, p); /* And unlock */ DPLANE_UNLOCK(); @@ -5688,10 +5695,8 @@ struct zebra_dplane_ctx *dplane_provider_dequeue_in_ctx( dplane_provider_lock(prov); - ctx = TAILQ_FIRST(&(prov->dp_ctx_in_q)); + ctx = dplane_ctx_list_pop(&(prov->dp_ctx_in_list)); if (ctx) { - TAILQ_REMOVE(&(prov->dp_ctx_in_q), ctx, zd_q_entries); - atomic_fetch_sub_explicit(&prov->dp_in_queued, 1, memory_order_relaxed); } @@ -5705,7 +5710,7 @@ struct zebra_dplane_ctx *dplane_provider_dequeue_in_ctx( * Dequeue work to a list, return count */ int dplane_provider_dequeue_in_list(struct zebra_dplane_provider *prov, - struct dplane_ctx_q *listp) + struct dplane_ctx_list_head *listp) { int limit, ret; struct zebra_dplane_ctx *ctx; @@ -5715,14 +5720,11 @@ int dplane_provider_dequeue_in_list(struct zebra_dplane_provider *prov, dplane_provider_lock(prov); for (ret = 0; ret < limit; ret++) { - ctx = TAILQ_FIRST(&(prov->dp_ctx_in_q)); - if (ctx) { - TAILQ_REMOVE(&(prov->dp_ctx_in_q), ctx, zd_q_entries); - - TAILQ_INSERT_TAIL(listp, ctx, zd_q_entries); - } else { + ctx = dplane_ctx_list_pop(&(prov->dp_ctx_in_list)); + if (ctx) + dplane_ctx_list_add_tail(listp, ctx); + else break; - } } if (ret > 0) @@ -5750,8 +5752,7 @@ void dplane_provider_enqueue_out_ctx(struct zebra_dplane_provider *prov, dplane_provider_lock(prov); - TAILQ_INSERT_TAIL(&(prov->dp_ctx_out_q), ctx, - zd_q_entries); + dplane_ctx_list_add_tail(&(prov->dp_ctx_out_list), ctx); /* Maintain out-queue counters */ atomic_fetch_add_explicit(&(prov->dp_out_queued), 1, @@ -5921,12 +5922,12 @@ int dplane_provider_work_ready(void) */ void dplane_provider_enqueue_to_zebra(struct zebra_dplane_ctx *ctx) { - struct dplane_ctx_q temp_list; + struct dplane_ctx_list_head temp_list; /* Zebra's api takes a list, so we need to use a temporary list */ - TAILQ_INIT(&temp_list); + dplane_ctx_list_init(&temp_list); - TAILQ_INSERT_TAIL(&temp_list, ctx, zd_q_entries); + dplane_ctx_list_add_tail(&temp_list, ctx); (zdplane_info.dg_results_cb)(&temp_list); } @@ -6321,11 +6322,11 @@ void dplane_rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p, */ static int kernel_dplane_process_func(struct zebra_dplane_provider *prov) { - struct zebra_dplane_ctx *ctx, *tctx; - struct dplane_ctx_q work_list; + struct zebra_dplane_ctx *ctx; + struct dplane_ctx_list_head work_list; int counter, limit; - TAILQ_INIT(&work_list); + dplane_ctx_list_init(&work_list); limit = dplane_provider_get_work_limit(prov); @@ -6351,15 +6352,14 @@ static int kernel_dplane_process_func(struct zebra_dplane_provider *prov) == DPLANE_OP_IPSET_ENTRY_DELETE)) kernel_dplane_process_ipset_entry(prov, ctx); else - TAILQ_INSERT_TAIL(&work_list, ctx, zd_q_entries); + dplane_ctx_list_add_tail(&work_list, ctx); } kernel_update_multi(&work_list); - TAILQ_FOREACH_SAFE (ctx, &work_list, zd_q_entries, tctx) { + while ((ctx = dplane_ctx_list_pop(&work_list)) != NULL) { kernel_dplane_handle_result(ctx); - TAILQ_REMOVE(&work_list, ctx, zd_q_entries); dplane_provider_enqueue_out_ctx(prov, ctx); } @@ -6486,10 +6486,10 @@ static void dplane_provider_init(void) int dplane_clean_ctx_queue(bool (*context_cb)(struct zebra_dplane_ctx *ctx, void *arg), void *val) { - struct zebra_dplane_ctx *ctx, *temp; - struct dplane_ctx_q work_list; + struct zebra_dplane_ctx *ctx; + struct dplane_ctx_list_head work_list; - TAILQ_INIT(&work_list); + dplane_ctx_list_init(&work_list); if (context_cb == NULL) return AOK; @@ -6497,12 +6497,10 @@ int dplane_clean_ctx_queue(bool (*context_cb)(struct zebra_dplane_ctx *ctx, /* Walk the pending context queue under the dplane lock. */ DPLANE_LOCK(); - TAILQ_FOREACH_SAFE(ctx, &zdplane_info.dg_update_ctx_q, zd_q_entries, - temp) { + frr_each_safe (dplane_ctx_list, &zdplane_info.dg_update_list, ctx) { if (context_cb(ctx, val)) { - TAILQ_REMOVE(&zdplane_info.dg_update_ctx_q, ctx, - zd_q_entries); - TAILQ_INSERT_TAIL(&work_list, ctx, zd_q_entries); + dplane_ctx_list_del(&zdplane_info.dg_update_list, ctx); + dplane_ctx_list_add_tail(&work_list, ctx); } } @@ -6511,10 +6509,8 @@ int dplane_clean_ctx_queue(bool (*context_cb)(struct zebra_dplane_ctx *ctx, /* Now free any contexts selected by the caller, without holding * the lock. */ - TAILQ_FOREACH_SAFE(ctx, &work_list, zd_q_entries, temp) { - TAILQ_REMOVE(&work_list, ctx, zd_q_entries); + while ((ctx = dplane_ctx_list_pop(&work_list)) != NULL) dplane_ctx_fini(&ctx); - } return AOK; } @@ -6552,7 +6548,7 @@ void zebra_dplane_pre_finish(void) zdplane_info.dg_is_shutdown = true; /* Notify provider(s) of pending shutdown. */ - TAILQ_FOREACH(prov, &zdplane_info.dg_providers_q, dp_prov_link) { + frr_each (dplane_prov_list, &zdplane_info.dg_providers, prov) { if (prov->dp_fini == NULL) continue; @@ -6575,8 +6571,8 @@ static bool dplane_work_pending(void) */ DPLANE_LOCK(); { - ctx = TAILQ_FIRST(&zdplane_info.dg_update_ctx_q); - prov = TAILQ_FIRST(&zdplane_info.dg_providers_q); + ctx = dplane_ctx_list_first(&zdplane_info.dg_update_list); + prov = dplane_prov_list_first(&zdplane_info.dg_providers); } DPLANE_UNLOCK(); @@ -6587,9 +6583,9 @@ static bool dplane_work_pending(void) dplane_provider_lock(prov); - ctx = TAILQ_FIRST(&(prov->dp_ctx_in_q)); + ctx = dplane_ctx_list_first(&(prov->dp_ctx_in_list)); if (ctx == NULL) - ctx = TAILQ_FIRST(&(prov->dp_ctx_out_q)); + ctx = dplane_ctx_list_first(&(prov->dp_ctx_out_list)); dplane_provider_unlock(prov); @@ -6597,7 +6593,7 @@ static bool dplane_work_pending(void) break; DPLANE_LOCK(); - prov = TAILQ_NEXT(prov, dp_prov_link); + prov = dplane_prov_list_next(&zdplane_info.dg_providers, prov); DPLANE_UNLOCK(); } @@ -6683,10 +6679,10 @@ void zebra_dplane_finish(void) */ static void dplane_thread_loop(struct thread *event) { - struct dplane_ctx_q work_list; - struct dplane_ctx_q error_list; + struct dplane_ctx_list_head work_list; + struct dplane_ctx_list_head error_list; struct zebra_dplane_provider *prov; - struct zebra_dplane_ctx *ctx, *tctx; + struct zebra_dplane_ctx *ctx; int limit, counter, error_counter; uint64_t curr, high; bool reschedule = false; @@ -6695,8 +6691,9 @@ static void dplane_thread_loop(struct thread *event) limit = zdplane_info.dg_updates_per_cycle; /* Init temporary lists used to move contexts among providers */ - TAILQ_INIT(&work_list); - TAILQ_INIT(&error_list); + dplane_ctx_list_init(&work_list); + dplane_ctx_list_init(&error_list); + error_counter = 0; /* Check for zebra shutdown */ @@ -6709,18 +6706,15 @@ static void dplane_thread_loop(struct thread *event) DPLANE_LOCK(); /* Locate initial registered provider */ - prov = TAILQ_FIRST(&zdplane_info.dg_providers_q); + prov = dplane_prov_list_first(&zdplane_info.dg_providers); /* Move new work from incoming list to temp list */ for (counter = 0; counter < limit; counter++) { - ctx = TAILQ_FIRST(&zdplane_info.dg_update_ctx_q); + ctx = dplane_ctx_list_pop(&zdplane_info.dg_update_list); if (ctx) { - TAILQ_REMOVE(&zdplane_info.dg_update_ctx_q, ctx, - zd_q_entries); - ctx->zd_provider = prov->dp_id; - TAILQ_INSERT_TAIL(&work_list, ctx, zd_q_entries); + dplane_ctx_list_add_tail(&work_list, ctx); } else { break; } @@ -6750,7 +6744,7 @@ static void dplane_thread_loop(struct thread *event) /* Capture current provider id in each context; check for * error status. */ - TAILQ_FOREACH_SAFE(ctx, &work_list, zd_q_entries, tctx) { + frr_each_safe (dplane_ctx_list, &work_list, ctx) { if (dplane_ctx_get_status(ctx) == ZEBRA_DPLANE_REQUEST_SUCCESS) { ctx->zd_provider = prov->dp_id; @@ -6764,9 +6758,8 @@ static void dplane_thread_loop(struct thread *event) /* Move to error list; will be returned * zebra main. */ - TAILQ_REMOVE(&work_list, ctx, zd_q_entries); - TAILQ_INSERT_TAIL(&error_list, - ctx, zd_q_entries); + dplane_ctx_list_del(&work_list, ctx); + dplane_ctx_list_add_tail(&error_list, ctx); error_counter++; } } @@ -6774,9 +6767,8 @@ static void dplane_thread_loop(struct thread *event) /* Enqueue new work to the provider */ dplane_provider_lock(prov); - if (TAILQ_FIRST(&work_list)) - TAILQ_CONCAT(&(prov->dp_ctx_in_q), &work_list, - zd_q_entries); + while ((ctx = dplane_ctx_list_pop(&work_list)) != NULL) + dplane_ctx_list_add_tail(&(prov->dp_ctx_in_list), ctx); atomic_fetch_add_explicit(&prov->dp_in_counter, counter, memory_order_relaxed); @@ -6795,7 +6787,7 @@ static void dplane_thread_loop(struct thread *event) /* Reset the temp list (though the 'concat' may have done this * already), and the counter */ - TAILQ_INIT(&work_list); + dplane_ctx_list_init(&work_list); counter = 0; /* Call into the provider code. Note that this is @@ -6812,13 +6804,9 @@ static void dplane_thread_loop(struct thread *event) dplane_provider_lock(prov); while (counter < limit) { - ctx = TAILQ_FIRST(&(prov->dp_ctx_out_q)); + ctx = dplane_ctx_list_pop(&(prov->dp_ctx_out_list)); if (ctx) { - TAILQ_REMOVE(&(prov->dp_ctx_out_q), ctx, - zd_q_entries); - - TAILQ_INSERT_TAIL(&work_list, - ctx, zd_q_entries); + dplane_ctx_list_add_tail(&work_list, ctx); counter++; } else break; @@ -6835,7 +6823,7 @@ static void dplane_thread_loop(struct thread *event) /* Locate next provider */ DPLANE_LOCK(); - prov = TAILQ_NEXT(prov, dp_prov_link); + prov = dplane_prov_list_next(&zdplane_info.dg_providers, prov); DPLANE_UNLOCK(); } @@ -6861,12 +6849,12 @@ static void dplane_thread_loop(struct thread *event) /* Call through to zebra main */ (zdplane_info.dg_results_cb)(&error_list); - TAILQ_INIT(&error_list); + dplane_ctx_list_init(&error_list); /* Call through to zebra main */ (zdplane_info.dg_results_cb)(&work_list); - TAILQ_INIT(&work_list); + dplane_ctx_list_init(&work_list); } /* @@ -6899,7 +6887,7 @@ void zebra_dplane_shutdown(void) * Note that this call is in the main pthread, so providers must * be prepared for that. */ - TAILQ_FOREACH(dp, &zdplane_info.dg_providers_q, dp_prov_link) { + frr_each (dplane_prov_list, &zdplane_info.dg_providers, dp) { if (dp->dp_fini == NULL) continue; @@ -6920,8 +6908,9 @@ static void zebra_dplane_init_internal(void) pthread_mutex_init(&zdplane_info.dg_mutex, NULL); - TAILQ_INIT(&zdplane_info.dg_update_ctx_q); - TAILQ_INIT(&zdplane_info.dg_providers_q); + dplane_prov_list_init(&zdplane_info.dg_providers); + + dplane_ctx_list_init(&zdplane_info.dg_update_list); zns_info_list_init(&zdplane_info.dg_zns_list); zdplane_info.dg_updates_per_cycle = DPLANE_DEFAULT_NEW_WORK; @@ -6970,7 +6959,7 @@ void zebra_dplane_start(void) /* Call start callbacks for registered providers */ DPLANE_LOCK(); - prov = TAILQ_FIRST(&zdplane_info.dg_providers_q); + prov = dplane_prov_list_first(&zdplane_info.dg_providers); DPLANE_UNLOCK(); while (prov) { @@ -6980,7 +6969,7 @@ void zebra_dplane_start(void) /* Locate next provider */ DPLANE_LOCK(); - prov = TAILQ_NEXT(prov, dp_prov_link); + prov = dplane_prov_list_next(&zdplane_info.dg_providers, prov); DPLANE_UNLOCK(); } @@ -6990,7 +6979,7 @@ void zebra_dplane_start(void) /* * Initialize the dataplane module at startup; called by zebra rib_init() */ -void zebra_dplane_init(int (*results_fp)(struct dplane_ctx_q *)) +void zebra_dplane_init(int (*results_fp)(struct dplane_ctx_list_head *)) { zebra_dplane_init_internal(); zdplane_info.dg_results_cb = results_fp; diff --git a/zebra/zebra_dplane.h b/zebra/zebra_dplane.h index 51f6f3d89..ae13243a1 100644 --- a/zebra/zebra_dplane.h +++ b/zebra/zebra_dplane.h @@ -24,7 +24,6 @@ #include "lib/prefix.h" #include "lib/nexthop.h" #include "lib/nexthop_group.h" -#include "lib/queue.h" #include "lib/vlan.h" #include "zebra/zebra_ns.h" #include "zebra/rib.h" @@ -265,14 +264,15 @@ void dplane_enable_sys_route_notifs(void); * they cannot share existing global data structures safely. */ -/* Define a tailq list type for context blocks. The list is exposed/public, +/* Define a list type for context blocks. The list is exposed/public, * but the internal linkage in the context struct is private, so there * are accessor apis that support enqueue and dequeue. */ -TAILQ_HEAD(dplane_ctx_q, zebra_dplane_ctx); + +PREDECL_DLIST(dplane_ctx_list); /* Declare a type for (optional) extended interface info objects. */ -TAILQ_HEAD(dplane_intf_extra_q, dplane_intf_extra); +PREDECL_DLIST(dplane_intf_extra_list); /* Allocate a context object */ struct zebra_dplane_ctx *dplane_ctx_alloc(void); @@ -300,18 +300,21 @@ void dplane_ctx_fini(struct zebra_dplane_ctx **pctx); /* Enqueue a context block to caller's tailq. This exists so that the * context struct can remain opaque. */ -void dplane_ctx_enqueue_tail(struct dplane_ctx_q *q, +void dplane_ctx_enqueue_tail(struct dplane_ctx_list_head *q, const struct zebra_dplane_ctx *ctx); /* Append a list of context blocks to another list - again, just keeping * the context struct opaque. */ -void dplane_ctx_list_append(struct dplane_ctx_q *to_list, - struct dplane_ctx_q *from_list); +void dplane_ctx_list_append(struct dplane_ctx_list_head *to_list, + struct dplane_ctx_list_head *from_list); /* Dequeue a context block from the head of caller's tailq */ -struct zebra_dplane_ctx *dplane_ctx_dequeue(struct dplane_ctx_q *q); -struct zebra_dplane_ctx *dplane_ctx_get_head(struct dplane_ctx_q *q); +struct zebra_dplane_ctx *dplane_ctx_dequeue(struct dplane_ctx_list_head *q); +struct zebra_dplane_ctx *dplane_ctx_get_head(struct dplane_ctx_list_head *q); + +/* Init a list of contexts */ +void dplane_ctx_q_init(struct dplane_ctx_list_head *q); /* * Accessors for information from the context object @@ -1036,7 +1039,7 @@ struct zebra_dplane_ctx *dplane_provider_dequeue_in_ctx( /* Dequeue work to a list, maintain counter and locking, return count */ int dplane_provider_dequeue_in_list(struct zebra_dplane_provider *prov, - struct dplane_ctx_q *listp); + struct dplane_ctx_list_head *listp); /* Current completed work queue length */ uint32_t dplane_provider_out_ctx_queue_len(struct zebra_dplane_provider *prov); @@ -1061,7 +1064,7 @@ void dplane_enable_intf_extra_info(void); * so the expectation is that the contexts are queued for the zebra * main pthread. */ -void zebra_dplane_init(int (*) (struct dplane_ctx_q *)); +void zebra_dplane_init(int (*)(struct dplane_ctx_list_head *)); /* * Start the dataplane pthread. This step needs to be run later than the diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 81910f68b..d5375105a 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -72,7 +72,7 @@ DEFINE_MTYPE_STATIC(ZEBRA, WQ_WRAPPER, "WQ wrapper"); */ static pthread_mutex_t dplane_mutex; static struct thread *t_dplane; -static struct dplane_ctx_q rib_dplane_q; +static struct dplane_ctx_list_head rib_dplane_q; DEFINE_HOOK(rib_update, (struct route_node * rn, const char *reason), (rn, reason)); @@ -4613,13 +4613,13 @@ static void handle_pw_result(struct zebra_dplane_ctx *ctx) static void rib_process_dplane_results(struct thread *thread) { struct zebra_dplane_ctx *ctx; - struct dplane_ctx_q ctxlist; + struct dplane_ctx_list_head ctxlist; bool shut_p = false; /* Dequeue a list of completed updates with one lock/unlock cycle */ do { - TAILQ_INIT(&ctxlist); + dplane_ctx_q_init(&ctxlist); /* Take lock controlling queue of results */ frr_with_mutex (&dplane_mutex) { @@ -4788,7 +4788,7 @@ static void rib_process_dplane_results(struct thread *thread) * the dataplane pthread. We enqueue the results here for processing by * the main thread later. */ -static int rib_dplane_results(struct dplane_ctx_q *ctxlist) +static int rib_dplane_results(struct dplane_ctx_list_head *ctxlist) { /* Take lock controlling queue of results */ frr_with_mutex (&dplane_mutex) { @@ -4833,7 +4833,7 @@ void rib_init(void) /* Init dataplane, and register for results */ pthread_mutex_init(&dplane_mutex, NULL); - TAILQ_INIT(&rib_dplane_q); + dplane_ctx_q_init(&rib_dplane_q); zebra_dplane_init(rib_dplane_results); } |