Skip to content

Commit c61a375

Browse files
committed
tools: ynltool: add qstats analysis for HW-GRO efficiency / savings
Extend ynltool to compute HW GRO savings metric - how many packets has HW GRO been able to save the kernel from seeing. Note that this definition does not actually take into account whether the segments were or weren't eligible for HW GRO. If a machine is receiving all-UDP traffic - new metric will show HW-GRO savings of 0%. Conversely since the super-packet still counts as a received packet, savings of 100% is not achievable. Perfect HW-GRO on a machine with 4k MTU and 64kB super-frames would show ~93.75% savings. With 1.5k MTU we may see up to ~97.8% savings (if my math is right). Example after 10 sec of iperf on a freshly booted machine with 1.5k MTU: $ ynltool qstats show eth0 rx-packets: 40681280 rx-bytes: 61575208437 rx-alloc-fail: 0 rx-hw-gro-packets: 1225133 rx-hw-gro-wire-packets: 40656633 $ ynltool qstats hw-gro eth0: 96.9% savings None of the NICs I have access to can report "missed" HW-GRO opportunities so computing a true "effectiveness" metric is not possible. One could also argue that effectiveness metric is inferior in environments where we control both senders and receivers, the savings metrics will capture both regressions in receiver's HW GRO effectiveness but also regressions in senders sending smaller TSO trains. And we care about both. The main downside is that it's hard to tell at a glance how well the NIC is doing because the savings will be dependent on traffic patterns. Reviewed-by: Petr Machata <petrm@nvidia.com> Link: https://patch.msgid.link/20260207003509.3927744-4-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 5374c33 commit c61a375

1 file changed

Lines changed: 71 additions & 5 deletions

File tree

tools/net/ynl/ynltool/qstats.c

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,65 @@ static int do_balance(int argc, char **argv __attribute__((unused)))
568568
return ret;
569569
}
570570

571+
static int do_hw_gro(int argc, char **argv __attribute__((unused)))
572+
{
573+
struct netdev_qstats_get_list *qstats;
574+
575+
if (argc > 0) {
576+
p_err("hw-gro command takes no arguments");
577+
return -1;
578+
}
579+
580+
qstats = qstats_dump(0);
581+
if (!qstats)
582+
return -1;
583+
584+
if (json_output)
585+
jsonw_start_array(json_wtr);
586+
587+
ynl_dump_foreach(qstats, qs) {
588+
char ifname[IF_NAMESIZE];
589+
const char *name;
590+
double savings;
591+
592+
if (!qs->_present.rx_packets ||
593+
!qs->_present.rx_hw_gro_packets ||
594+
!qs->_present.rx_hw_gro_wire_packets)
595+
continue;
596+
597+
if (!qs->rx_packets)
598+
continue;
599+
600+
/* How many skbs did we avoid allocating thanks to HW GRO */
601+
savings = (double)(qs->rx_hw_gro_wire_packets -
602+
qs->rx_hw_gro_packets) /
603+
qs->rx_packets * 100.0;
604+
605+
name = if_indextoname(qs->ifindex, ifname);
606+
607+
if (json_output) {
608+
jsonw_start_object(json_wtr);
609+
jsonw_uint_field(json_wtr, "ifindex", qs->ifindex);
610+
if (name)
611+
jsonw_string_field(json_wtr, "ifname", name);
612+
jsonw_float_field(json_wtr, "savings", savings);
613+
jsonw_end_object(json_wtr);
614+
} else {
615+
if (name)
616+
printf("%s", name);
617+
else
618+
printf("ifindex:%u", qs->ifindex);
619+
printf(": %.1f%% savings\n", savings);
620+
}
621+
}
622+
623+
if (json_output)
624+
jsonw_end_array(json_wtr);
625+
626+
netdev_qstats_get_list_free(qstats);
627+
return 0;
628+
}
629+
571630
static int do_help(int argc __attribute__((unused)),
572631
char **argv __attribute__((unused)))
573632
{
@@ -577,9 +636,10 @@ static int do_help(int argc __attribute__((unused)),
577636
}
578637

579638
fprintf(stderr,
580-
"Usage: %s qstats { COMMAND | help }\n"
581-
" %s qstats [ show ] [ OPTIONS ]\n"
582-
" %s qstats balance\n"
639+
"Usage: %1$s qstats { COMMAND | help }\n"
640+
" %1$s qstats [ show ] [ OPTIONS ]\n"
641+
" %1$s qstats balance\n"
642+
" %1$s qstats hw-gro\n"
583643
"\n"
584644
" OPTIONS := { scope queue | group-by { device | queue } }\n"
585645
"\n"
@@ -588,16 +648,22 @@ static int do_help(int argc __attribute__((unused)),
588648
" show scope queue - Display per-queue statistics\n"
589649
" show group-by device - Display device-aggregated statistics (default)\n"
590650
" show group-by queue - Display per-queue statistics\n"
591-
" balance - Analyze traffic distribution balance.\n"
651+
"\n"
652+
" Analysis:\n"
653+
" balance - Traffic distribution between queues.\n"
654+
" hw-gro - HW GRO effectiveness analysis\n"
655+
" - savings - delta between packets received\n"
656+
" on the wire and packets seen by the kernel.\n"
592657
"",
593-
bin_name, bin_name, bin_name);
658+
bin_name);
594659

595660
return 0;
596661
}
597662

598663
static const struct cmd qstats_cmds[] = {
599664
{ "show", do_show },
600665
{ "balance", do_balance },
666+
{ "hw-gro", do_hw_gro },
601667
{ "help", do_help },
602668
{ 0 }
603669
};

0 commit comments

Comments
 (0)