From: greearb@candelatech.com
To: netdev@vger.kernel.org
Cc: Ben Greear <greearb@candelatech.com>
Subject: [PATCH] ethtool: Support ETHTOOL_GSTATS2 API.
Date: Tue, 17 Apr 2018 18:50:07 -0700 [thread overview]
Message-ID: <1524016207-4005-1-git-send-email-greearb@candelatech.com> (raw)
From: Ben Greear <greearb@candelatech.com>
This allows users to specify flags to the get-stats
API, potentially saving expensive stats queries when
they are not desired.
Signed-off-by: Ben Greear <greearb@candelatech.com>
---
ethtool-copy.h | 9 +++++++++
ethtool.c | 25 ++++++++++++++++++++-----
2 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/ethtool-copy.h b/ethtool-copy.h
index 8cc61e9..11ce456 100644
--- a/ethtool-copy.h
+++ b/ethtool-copy.h
@@ -1390,11 +1390,20 @@ enum ethtool_fec_config_bits {
#define ETHTOOL_PHY_STUNABLE 0x0000004f /* Set PHY tunable configuration */
#define ETHTOOL_GFECPARAM 0x00000050 /* Get FEC settings */
#define ETHTOOL_SFECPARAM 0x00000051 /* Set FEC settings */
+#define ETHTOOL_GSTATS2 0x00000052 /* get NIC-specific statistics
+ * with ability to specify flags.
+ * See ETHTOOL_GS2* below.
+ */
/* compatibility with older code */
#define SPARC_ETH_GSET ETHTOOL_GSET
#define SPARC_ETH_SSET ETHTOOL_SSET
+/* GSTATS2 flags */
+#define ETHTOOL_GS2_SKIP_NONE (0) /* default is to update all stats */
+#define ETHTOOL_GS2_SKIP_FW (1<<0) /* Skip reading stats that probe firmware,
+ * and thus are slow/expensive.
+ */
/* Link mode bit indices */
enum ethtool_link_mode_bit_indices {
ETHTOOL_LINK_MODE_10baseT_Half_BIT = 0,
diff --git a/ethtool.c b/ethtool.c
index 3289e0f..6a11077 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -3440,14 +3440,14 @@ static int do_phys_id(struct cmd_context *ctx)
}
static int do_gstats(struct cmd_context *ctx, int cmd, int stringset,
- const char *name)
+ const char *name, u32 flags)
{
struct ethtool_gstrings *strings;
struct ethtool_stats *stats;
unsigned int n_stats, sz_stats, i;
int err;
- if (ctx->argc != 0)
+ if ((ctx->argc != 0) && (flags == ETHTOOL_GS2_SKIP_NONE))
exit_bad_args();
strings = get_stringset(ctx, stringset,
@@ -3475,7 +3475,10 @@ static int do_gstats(struct cmd_context *ctx, int cmd, int stringset,
}
stats->cmd = cmd;
- stats->n_stats = n_stats;
+ if (cmd == ETHTOOL_GSTATS2)
+ stats->n_stats = flags;
+ else
+ stats->n_stats = n_stats;
err = send_ioctl(ctx, stats);
if (err < 0) {
perror("Cannot get stats information");
@@ -3500,12 +3503,22 @@ static int do_gstats(struct cmd_context *ctx, int cmd, int stringset,
static int do_gnicstats(struct cmd_context *ctx)
{
- return do_gstats(ctx, ETHTOOL_GSTATS, ETH_SS_STATS, "NIC");
+ return do_gstats(ctx, ETHTOOL_GSTATS, ETH_SS_STATS, "NIC", ETHTOOL_GS2_SKIP_NONE);
+}
+
+static int do_gnicstats2(struct cmd_context *ctx)
+{
+ u32 flags = ETHTOOL_GS2_SKIP_NONE;
+ if (ctx->argc >= 1)
+ if (strcmp(ctx->argp[0], "nofw") == 0)
+ flags |= ETHTOOL_GS2_SKIP_FW;
+ return do_gstats(ctx, ETHTOOL_GSTATS2, ETH_SS_STATS, "NIC", flags);
}
static int do_gphystats(struct cmd_context *ctx)
{
- return do_gstats(ctx, ETHTOOL_GPHYSTATS, ETH_SS_PHY_STATS, "PHY");
+ return do_gstats(ctx, ETHTOOL_GPHYSTATS, ETH_SS_PHY_STATS, "PHY",
+ ETHTOOL_GS2_SKIP_NONE);
}
static int do_srxntuple(struct cmd_context *ctx,
@@ -5118,6 +5131,8 @@ static const struct option {
{ "-t|--test", 1, do_test, "Execute adapter self test",
" [ online | offline | external_lb ]\n" },
{ "-S|--statistics", 1, do_gnicstats, "Show adapter statistics" },
+ { "-2|--S2", 1, do_gnicstats2, "Show adapter statistics with flags",
+ " [ nofw ]\n" },
{ "--phy-statistics", 1, do_gphystats,
"Show phy statistics" },
{ "-n|-u|--show-nfc|--show-ntuple", 1, do_grxclass,
--
2.4.11
reply other threads:[~2018-04-18 1:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1524016207-4005-1-git-send-email-greearb@candelatech.com \
--to=greearb@candelatech.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox