-
Notifications
You must be signed in to change notification settings - Fork 6
feat(nic-stats): added NIC statistics in shared memory with FFI and RPC #674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -55,6 +55,8 @@ | |||||||||
|
|
||||||||||
| #include <rte_ethdev.h> | ||||||||||
|
|
||||||||||
| #define NIC_STATS_FREQUENCY 1000 | ||||||||||
|
|
||||||||||
| static void | ||||||||||
| worker_read(struct dataplane_worker *worker, struct packet_list *packets) { | ||||||||||
| struct worker_read_ctx *ctx = &worker->read_ctx; | ||||||||||
|
|
@@ -271,6 +273,21 @@ worker_write(struct dataplane_worker *worker, struct packet_list *packets) { | |||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| void worker_unload_nic_stats(struct dataplane_worker *worker) { | ||||||||||
| struct rte_eth_stats stats1; | ||||||||||
| struct dp_worker *dp_worker = worker->dp_worker; | ||||||||||
|
|
||||||||||
| rte_eth_stats_get(worker->port_id, &stats1); | ||||||||||
|
||||||||||
| rte_eth_stats_get(worker->port_id, &stats1); | |
| if (rte_eth_stats_get(worker->port_id, &stats1) != 0) { | |
| return; | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1648,6 +1648,68 @@ yanet_get_device_counters( | |
| return list; | ||
| } | ||
|
|
||
| struct counter_handle_list * | ||
| yanet_get_nic_counters(struct dp_config *dp_config) { | ||
| const char *query[] = { | ||
| "nic_rx", | ||
| "nic_tx", | ||
| "nic_rx_tx_errors", | ||
| "nic_rx_nombuf", | ||
| }; | ||
| int query_count = sizeof(query) / sizeof(query[0]); | ||
|
|
||
| struct counter_registry *counter_registry = &dp_config->worker_counters; | ||
| struct counter_storage *storage = | ||
| ADDR_OF(&dp_config->worker_counter_storage); | ||
|
|
||
| uint64_t count = counter_registry->count; | ||
| struct counter *names = ADDR_OF(&counter_registry->names); | ||
|
|
||
| uint64_t match_count = 0; | ||
|
|
||
| for (uint64_t idx = 0; idx < count; ++idx) { | ||
| if (!counter_name_matches_query( | ||
| names[idx].name, query, query_count | ||
| )) { | ||
| continue; | ||
| } | ||
|
|
||
| match_count++; | ||
| } | ||
|
|
||
| if (match_count == 0) { | ||
| return NULL; | ||
| } | ||
|
|
||
| struct counter_handle_list *list = (struct counter_handle_list *)malloc( | ||
| sizeof(struct counter_handle_list) + | ||
| sizeof(struct counter_handle) * match_count | ||
| ); | ||
|
|
||
| if (list == NULL) | ||
| return NULL; | ||
| list->instance_count = ADDR_OF(&storage->allocator)->instance_count; | ||
| list->count = count; | ||
| struct counter_handle *handlers = list->counters; | ||
|
|
||
| uint64_t out_idx = 0; | ||
| for (uint64_t idx = 0; idx < count; ++idx) { | ||
| if (!counter_name_matches_query( | ||
| names[idx].name, query, query_count | ||
| )) { | ||
| continue; | ||
| } | ||
| strtcpy(handlers[out_idx].name, names[idx].name, 60); | ||
| handlers[out_idx].size = names[idx].size; | ||
| handlers[out_idx].gen = names[idx].gen; | ||
| handlers[out_idx].value_handle = | ||
| counter_get_value_handle(idx, storage); | ||
| out_idx++; | ||
| } | ||
|
Comment on lines
+1684
to
+1708
|
||
|
|
||
| return list; | ||
| } | ||
|
|
||
| struct counter_handle * | ||
| yanet_get_counter(struct counter_handle_list *counters, uint64_t idx) { | ||
| if (idx >= counters->count) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -62,6 +62,21 @@ struct dp_worker { | |||||||||
| struct rte_mempool *rx_mempool; | ||||||||||
|
|
||||||||||
| uint8_t pad[24]; | ||||||||||
|
|
||||||||||
| // trade-off: nic stats unload not often | ||||||||||
| // bcs put it in second cache line | ||||||||||
|
Comment on lines
+66
to
+67
|
||||||||||
| // trade-off: nic stats unload not often | |
| // bcs put it in second cache line | |
| // Trade-off: place NIC statistics in the second cache line | |
| // because they are accessed less frequently than the fields above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
rpc Nicis added to the public gRPC service, but there is no corresponding handler implemented incontrolplane/internal/gateway/counters_service.go(so clients will getUnimplementedunless/ until it’s wired up). Please add the server-side method that callsDPConfig.NicCounters()(or remove the RPC until it’s supported end-to-end).