diff options
author | Jesper Dangaard Brouer <brouer@redhat.com> | 2018-05-24 10:46:22 -0400 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2018-05-24 21:36:15 -0400 |
commit | a570e48fee1bc26f47aba2e1493f96a03bed3c8f (patch) | |
tree | 069715fbcf7b0f4b73103861fd0a111e143b5705 /samples | |
parent | e74de52e55c092e7113f839e74400ce9dbe12ceb (diff) |
samples/bpf: xdp_monitor use err code from tracepoint xdp:xdp_devmap_xmit
Update xdp_monitor to use the recently added err code introduced
in tracepoint xdp:xdp_devmap_xmit, to show if the drop count is
caused by some driver general delivery problem. Other kind of drops
will likely just be more normal TX space issues.
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'samples')
-rw-r--r-- | samples/bpf/xdp_monitor_kern.c | 10 | ||||
-rw-r--r-- | samples/bpf/xdp_monitor_user.c | 35 |
2 files changed, 40 insertions, 5 deletions
diff --git a/samples/bpf/xdp_monitor_kern.c b/samples/bpf/xdp_monitor_kern.c index 2854aa0665ea..ad10fe700d7d 100644 --- a/samples/bpf/xdp_monitor_kern.c +++ b/samples/bpf/xdp_monitor_kern.c | |||
@@ -125,6 +125,7 @@ struct datarec { | |||
125 | u64 processed; | 125 | u64 processed; |
126 | u64 dropped; | 126 | u64 dropped; |
127 | u64 info; | 127 | u64 info; |
128 | u64 err; | ||
128 | }; | 129 | }; |
129 | #define MAX_CPUS 64 | 130 | #define MAX_CPUS 64 |
130 | 131 | ||
@@ -228,6 +229,7 @@ struct devmap_xmit_ctx { | |||
228 | int sent; // offset:24; size:4; signed:1; | 229 | int sent; // offset:24; size:4; signed:1; |
229 | int from_ifindex; // offset:28; size:4; signed:1; | 230 | int from_ifindex; // offset:28; size:4; signed:1; |
230 | int to_ifindex; // offset:32; size:4; signed:1; | 231 | int to_ifindex; // offset:32; size:4; signed:1; |
232 | int err; // offset:36; size:4; signed:1; | ||
231 | }; | 233 | }; |
232 | 234 | ||
233 | SEC("tracepoint/xdp/xdp_devmap_xmit") | 235 | SEC("tracepoint/xdp/xdp_devmap_xmit") |
@@ -245,5 +247,13 @@ int trace_xdp_devmap_xmit(struct devmap_xmit_ctx *ctx) | |||
245 | /* Record bulk events, then userspace can calc average bulk size */ | 247 | /* Record bulk events, then userspace can calc average bulk size */ |
246 | rec->info += 1; | 248 | rec->info += 1; |
247 | 249 | ||
250 | /* Record error cases, where no frame were sent */ | ||
251 | if (ctx->err) | ||
252 | rec->err++; | ||
253 | |||
254 | /* Catch API error of drv ndo_xdp_xmit sent more than count */ | ||
255 | if (ctx->drops < 0) | ||
256 | rec->err++; | ||
257 | |||
248 | return 1; | 258 | return 1; |
249 | } | 259 | } |
diff --git a/samples/bpf/xdp_monitor_user.c b/samples/bpf/xdp_monitor_user.c index 7e18a454924c..dd558cbb2309 100644 --- a/samples/bpf/xdp_monitor_user.c +++ b/samples/bpf/xdp_monitor_user.c | |||
@@ -117,6 +117,7 @@ struct datarec { | |||
117 | __u64 processed; | 117 | __u64 processed; |
118 | __u64 dropped; | 118 | __u64 dropped; |
119 | __u64 info; | 119 | __u64 info; |
120 | __u64 err; | ||
120 | }; | 121 | }; |
121 | #define MAX_CPUS 64 | 122 | #define MAX_CPUS 64 |
122 | 123 | ||
@@ -152,6 +153,7 @@ static bool map_collect_record(int fd, __u32 key, struct record *rec) | |||
152 | __u64 sum_processed = 0; | 153 | __u64 sum_processed = 0; |
153 | __u64 sum_dropped = 0; | 154 | __u64 sum_dropped = 0; |
154 | __u64 sum_info = 0; | 155 | __u64 sum_info = 0; |
156 | __u64 sum_err = 0; | ||
155 | int i; | 157 | int i; |
156 | 158 | ||
157 | if ((bpf_map_lookup_elem(fd, &key, values)) != 0) { | 159 | if ((bpf_map_lookup_elem(fd, &key, values)) != 0) { |
@@ -170,10 +172,13 @@ static bool map_collect_record(int fd, __u32 key, struct record *rec) | |||
170 | sum_dropped += values[i].dropped; | 172 | sum_dropped += values[i].dropped; |
171 | rec->cpu[i].info = values[i].info; | 173 | rec->cpu[i].info = values[i].info; |
172 | sum_info += values[i].info; | 174 | sum_info += values[i].info; |
175 | rec->cpu[i].err = values[i].err; | ||
176 | sum_err += values[i].err; | ||
173 | } | 177 | } |
174 | rec->total.processed = sum_processed; | 178 | rec->total.processed = sum_processed; |
175 | rec->total.dropped = sum_dropped; | 179 | rec->total.dropped = sum_dropped; |
176 | rec->total.info = sum_info; | 180 | rec->total.info = sum_info; |
181 | rec->total.err = sum_err; | ||
177 | return true; | 182 | return true; |
178 | } | 183 | } |
179 | 184 | ||
@@ -274,6 +279,18 @@ static double calc_info(struct datarec *r, struct datarec *p, double period) | |||
274 | return pps; | 279 | return pps; |
275 | } | 280 | } |
276 | 281 | ||
282 | static double calc_err(struct datarec *r, struct datarec *p, double period) | ||
283 | { | ||
284 | __u64 packets = 0; | ||
285 | double pps = 0; | ||
286 | |||
287 | if (period > 0) { | ||
288 | packets = r->err - p->err; | ||
289 | pps = packets / period; | ||
290 | } | ||
291 | return pps; | ||
292 | } | ||
293 | |||
277 | static void stats_print(struct stats_record *stats_rec, | 294 | static void stats_print(struct stats_record *stats_rec, |
278 | struct stats_record *stats_prev, | 295 | struct stats_record *stats_prev, |
279 | bool err_only) | 296 | bool err_only) |
@@ -412,11 +429,12 @@ static void stats_print(struct stats_record *stats_rec, | |||
412 | 429 | ||
413 | /* devmap ndo_xdp_xmit stats */ | 430 | /* devmap ndo_xdp_xmit stats */ |
414 | { | 431 | { |
415 | char *fmt1 = "%-15s %-7d %'-12.0f %'-12.0f %'-10.2f %s\n"; | 432 | char *fmt1 = "%-15s %-7d %'-12.0f %'-12.0f %'-10.2f %s %s\n"; |
416 | char *fmt2 = "%-15s %-7s %'-12.0f %'-12.0f %'-10.2f %s\n"; | 433 | char *fmt2 = "%-15s %-7s %'-12.0f %'-12.0f %'-10.2f %s %s\n"; |
417 | struct record *rec, *prev; | 434 | struct record *rec, *prev; |
418 | double drop, info; | 435 | double drop, info, err; |
419 | char *i_str = ""; | 436 | char *i_str = ""; |
437 | char *err_str = ""; | ||
420 | 438 | ||
421 | rec = &stats_rec->xdp_devmap_xmit; | 439 | rec = &stats_rec->xdp_devmap_xmit; |
422 | prev = &stats_prev->xdp_devmap_xmit; | 440 | prev = &stats_prev->xdp_devmap_xmit; |
@@ -428,22 +446,29 @@ static void stats_print(struct stats_record *stats_rec, | |||
428 | pps = calc_pps(r, p, t); | 446 | pps = calc_pps(r, p, t); |
429 | drop = calc_drop(r, p, t); | 447 | drop = calc_drop(r, p, t); |
430 | info = calc_info(r, p, t); | 448 | info = calc_info(r, p, t); |
449 | err = calc_err(r, p, t); | ||
431 | if (info > 0) { | 450 | if (info > 0) { |
432 | i_str = "bulk-average"; | 451 | i_str = "bulk-average"; |
433 | info = (pps+drop) / info; /* calc avg bulk */ | 452 | info = (pps+drop) / info; /* calc avg bulk */ |
434 | } | 453 | } |
454 | if (err > 0) | ||
455 | err_str = "drv-err"; | ||
435 | if (pps > 0 || drop > 0) | 456 | if (pps > 0 || drop > 0) |
436 | printf(fmt1, "devmap-xmit", | 457 | printf(fmt1, "devmap-xmit", |
437 | i, pps, drop, info, i_str); | 458 | i, pps, drop, info, i_str, err_str); |
438 | } | 459 | } |
439 | pps = calc_pps(&rec->total, &prev->total, t); | 460 | pps = calc_pps(&rec->total, &prev->total, t); |
440 | drop = calc_drop(&rec->total, &prev->total, t); | 461 | drop = calc_drop(&rec->total, &prev->total, t); |
441 | info = calc_info(&rec->total, &prev->total, t); | 462 | info = calc_info(&rec->total, &prev->total, t); |
463 | err = calc_err(&rec->total, &prev->total, t); | ||
442 | if (info > 0) { | 464 | if (info > 0) { |
443 | i_str = "bulk-average"; | 465 | i_str = "bulk-average"; |
444 | info = (pps+drop) / info; /* calc avg bulk */ | 466 | info = (pps+drop) / info; /* calc avg bulk */ |
445 | } | 467 | } |
446 | printf(fmt2, "devmap-xmit", "total", pps, drop, info, i_str); | 468 | if (err > 0) |
469 | err_str = "drv-err"; | ||
470 | printf(fmt2, "devmap-xmit", "total", pps, drop, | ||
471 | info, i_str, err_str); | ||
447 | } | 472 | } |
448 | 473 | ||
449 | printf("\n"); | 474 | printf("\n"); |