* [PATCH ethtool 1/2] ethtool-copy.h: sync with net-next
@ 2010-06-30 15:12 Ben Hutchings
2010-06-30 15:13 ` [PATCH ethtool 2/2] ethtool: Add support for control of RX flow hash indirection Ben Hutchings
0 siblings, 1 reply; 4+ messages in thread
From: Ben Hutchings @ 2010-06-30 15:12 UTC (permalink / raw)
To: Jeff Garzik; +Cc: netdev, linux-net-drivers
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
---
This "sync" assumes that "ethtool: Add support for control of RX flow
hash indirection" has been merged into net-next-2.6.
Ben.
ethtool-copy.h | 46 +++++++++++++++++++++++++++++-----------------
1 files changed, 29 insertions(+), 17 deletions(-)
diff --git a/ethtool-copy.h b/ethtool-copy.h
index c5eb680..0b3aea2 100644
--- a/ethtool-copy.h
+++ b/ethtool-copy.h
@@ -36,7 +36,7 @@ struct ethtool_cmd {
__u32 reserved[2];
};
-static inline void ethtool_cmd_speed_set(struct ethtool_cmd *ep,
+static __inline__ void ethtool_cmd_speed_set(struct ethtool_cmd *ep,
__u32 speed)
{
@@ -44,7 +44,7 @@ static inline void ethtool_cmd_speed_set(struct ethtool_cmd *ep,
ep->speed_hi = (__u16)(speed >> 16);
}
-static inline __u32 ethtool_cmd_speed(struct ethtool_cmd *ep)
+static __inline__ __u32 ethtool_cmd_speed(struct ethtool_cmd *ep)
{
return (ep->speed_hi << 16) | ep->speed;
}
@@ -384,6 +384,15 @@ struct ethtool_rxnfc {
__u32 rule_locs[0];
};
+struct ethtool_rxfh_indir {
+ __u32 cmd;
+ /* On entry, this is the array size of the user buffer. On
+ * return from ETHTOOL_GRXFHINDIR, this is the array size of
+ * the hardware indirection table. */
+ __u32 size;
+ __u32 ring_index[0]; /* ring/queue index for each hash value */
+};
+
struct ethtool_rx_ntuple_flow_spec {
__u32 flow_type;
union {
@@ -425,6 +434,7 @@ struct ethtool_flash {
char data[ETHTOOL_FLASH_MAX_FILENAME];
};
+
/* CMDs currently supported */
#define ETHTOOL_GSET 0x00000001 /* Get settings. */
#define ETHTOOL_SSET 0x00000002 /* Set settings. */
@@ -468,21 +478,23 @@ struct ethtool_flash {
#define ETHTOOL_GPFLAGS 0x00000027 /* Get driver-private flags bitmap */
#define ETHTOOL_SPFLAGS 0x00000028 /* Set driver-private flags bitmap */
-#define ETHTOOL_GRXFH 0x00000029 /* Get RX flow hash configuration */
-#define ETHTOOL_SRXFH 0x0000002a /* Set RX flow hash configuration */
+#define ETHTOOL_GRXFH 0x00000029 /* Get RX flow hash configuration */
+#define ETHTOOL_SRXFH 0x0000002a /* Set RX flow hash configuration */
#define ETHTOOL_GGRO 0x0000002b /* Get GRO enable (ethtool_value) */
#define ETHTOOL_SGRO 0x0000002c /* Set GRO enable (ethtool_value) */
-#define ETHTOOL_GRXRINGS 0x0000002d /* Get RX rings available for LB */
-#define ETHTOOL_GRXCLSRLCNT 0x0000002e /* Get RX class rule count */
-#define ETHTOOL_GRXCLSRULE 0x0000002f /* Get RX classification rule */
-#define ETHTOOL_GRXCLSRLALL 0x00000030 /* Get all RX classification rule */
-#define ETHTOOL_SRXCLSRLDEL 0x00000031 /* Delete RX classification rule */
-#define ETHTOOL_SRXCLSRLINS 0x00000032 /* Insert RX classification rule */
-#define ETHTOOL_FLASHDEV 0x00000033 /* Flash firmware to device */
-#define ETHTOOL_RESET 0x00000034 /* Reset hardware */
-#define ETHTOOL_SRXNTUPLE 0x00000035 /* Add an n-tuple filter to device */
-#define ETHTOOL_GRXNTUPLE 0x00000036 /* Get n-tuple filters from device */
-#define ETHTOOL_GSSET_INFO 0x00000037 /* Get string set info */
+#define ETHTOOL_GRXRINGS 0x0000002d /* Get RX rings available for LB */
+#define ETHTOOL_GRXCLSRLCNT 0x0000002e /* Get RX class rule count */
+#define ETHTOOL_GRXCLSRULE 0x0000002f /* Get RX classification rule */
+#define ETHTOOL_GRXCLSRLALL 0x00000030 /* Get all RX classification rule */
+#define ETHTOOL_SRXCLSRLDEL 0x00000031 /* Delete RX classification rule */
+#define ETHTOOL_SRXCLSRLINS 0x00000032 /* Insert RX classification rule */
+#define ETHTOOL_FLASHDEV 0x00000033 /* Flash firmware to device */
+#define ETHTOOL_RESET 0x00000034 /* Reset hardware */
+#define ETHTOOL_SRXNTUPLE 0x00000035 /* Add an n-tuple filter to device */
+#define ETHTOOL_GRXNTUPLE 0x00000036 /* Get n-tuple filters from device */
+#define ETHTOOL_GSSET_INFO 0x00000037 /* Get string set info */
+#define ETHTOOL_GRXFHINDIR 0x00000038 /* Get RX flow hash indir'n table */
+#define ETHTOOL_SRXFHINDIR 0x00000039 /* Set RX flow hash indir'n table */
/* compatibility with older code */
#define SPARC_ETH_GSET ETHTOOL_GSET
@@ -602,8 +614,8 @@ struct ethtool_flash {
#define AH_V6_FLOW 0x0b
#define ESP_V6_FLOW 0x0c
#define IP_USER_FLOW 0x0d
-#define IPV4_FLOW 0x10
-#define IPV6_FLOW 0x11
+#define IPV4_FLOW 0x10
+#define IPV6_FLOW 0x11
/* L3-L4 network traffic flow hash options */
#define RXH_L2DA (1 << 1)
--
1.6.2.5
--
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH ethtool 2/2] ethtool: Add support for control of RX flow hash indirection
2010-06-30 15:12 [PATCH ethtool 1/2] ethtool-copy.h: sync with net-next Ben Hutchings
@ 2010-06-30 15:13 ` Ben Hutchings
2010-07-01 16:03 ` Ben Hutchings
2010-07-02 7:25 ` Jeff Garzik
0 siblings, 2 replies; 4+ messages in thread
From: Ben Hutchings @ 2010-06-30 15:13 UTC (permalink / raw)
To: Jeff Garzik; +Cc: netdev, linux-net-drivers
Many NICs use an indirection table to map an RX flow hash value to one
of an arbitrary number of queues (not necessarily a power of 2). It
can be useful to remove some queues from this indirection table so
that they are only used for flows that are specifically filtered
there. It may also be useful to weight the mapping to account for
user processes with the same CPU-affinity as the RX interrupts.
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
---
ethtool.8 | 26 ++++++++++
ethtool.c | 162 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 188 insertions(+), 0 deletions(-)
diff --git a/ethtool.8 b/ethtool.8
index 5983d0e..6003743 100644
--- a/ethtool.8
+++ b/ethtool.8
@@ -214,6 +214,17 @@ ethtool \- Display or change ethernet card settings
.RB [ rx-flow-hash \ \*(FL
.RB \ \*(HO]
+.B ethtool \-x|\-\-show\-rxfh\-indir
+.I ethX
+
+.B ethtool \-X|\-\-set\-rxfh\-indir
+.I ethX
+.RB [\ equal
+.IR N \ |
+.BI weight\ W0
+.IR W1
+.RB ...\ ]
+
.B ethtool \-f|\-\-flash
.I ethX
.RI FILE
@@ -606,6 +617,21 @@ Discard all packets of this flow type. When this option is set, all other option
.PD
.RE
.TP
+.B \-x \-\-show\-rxfh\-indir
+Retrieves the receive flow hash indirection table.
+.TP
+.B \-X \-\-set\-rxfh\-indir
+Configures the receive flow hash indirection table.
+.TP
+.BI equal\ N
+Sets the receive flow hash indirection table to spread flows evenly
+between the first \fIN\fR receive queues.
+.TP
+\fBweight\fR \fIW0 W1\fR ...
+Sets the receive flow hash indirection table to spread flows between
+receive queues according to the given weights. The sum of the weights
+must be non-zero and must not exceed the size of the indirection table.
+.TP
.B \-f \-\-flash \ FILE
Flash firmware image from the specified file to a region on the adapter.
By default this will flash all the regions on the adapter.
diff --git a/ethtool.c b/ethtool.c
index 4073745..c7c269d 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -98,6 +98,8 @@ static char *unparse_rxfhashopts(u64 opts);
static int dump_rxfhash(int fhash, u64 val);
static int do_srxclass(int fd, struct ifreq *ifr);
static int do_grxclass(int fd, struct ifreq *ifr);
+static int do_grxfhindir(int fd, struct ifreq *ifr);
+static int do_srxfhindir(int fd, struct ifreq *ifr);
static int do_srxntuple(int fd, struct ifreq *ifr);
static int do_grxntuple(int fd, struct ifreq *ifr);
static int do_flash(int fd, struct ifreq *ifr);
@@ -125,6 +127,8 @@ static enum {
MODE_GSTATS,
MODE_GNFC,
MODE_SNFC,
+ MODE_GRXFHINDIR,
+ MODE_SRXFHINDIR,
MODE_SNTUPLE,
MODE_GNTUPLE,
MODE_FLASHDEV,
@@ -225,6 +229,10 @@ static struct option {
"classification options",
" [ rx-flow-hash tcp4|udp4|ah4|sctp4|"
"tcp6|udp6|ah6|sctp6 m|v|t|s|d|f|n|r... ]\n" },
+ { "-x", "--show-rxfh-indir", MODE_GRXFHINDIR, "Show Rx flow hash "
+ "indirection" },
+ { "-X", "--set-rxfh-indir", MODE_SRXFHINDIR, "Set Rx flow hash indirection",
+ " equal N | weight W0 W1 ...\n" },
{ "-U", "--config-ntuple", MODE_SNTUPLE, "Configure Rx ntuple filters "
"and actions",
" [ flow-type tcp4|udp4|sctp4 src-ip <addr> "
@@ -350,6 +358,8 @@ static int rx_fhash_get = 0;
static int rx_fhash_set = 0;
static u32 rx_fhash_val = 0;
static int rx_fhash_changed = 0;
+static int rxfhindir_equal = 0;
+static char **rxfhindir_weight = NULL;
static int sntuple_changed = 0;
static struct ethtool_rx_ntuple_flow_spec ntuple_fs;
static char *flash_file = NULL;
@@ -549,6 +559,11 @@ static int get_int(char *str, int base)
return get_int_range(str, base, INT_MIN, INT_MAX);
}
+static u32 get_u32(char *str, int base)
+{
+ return get_uint_range(str, base, 0xffffffff);
+}
+
static void parse_generic_cmdline(int argc, char **argp,
int first_arg, int *changed,
struct cmdline_info *info,
@@ -725,6 +740,8 @@ static void parse_cmdline(int argc, char **argp)
(mode == MODE_GSTATS) ||
(mode == MODE_GNFC) ||
(mode == MODE_SNFC) ||
+ (mode == MODE_GRXFHINDIR) ||
+ (mode == MODE_SRXFHINDIR) ||
(mode == MODE_SNTUPLE) ||
(mode == MODE_GNTUPLE) ||
(mode == MODE_PHYS_ID) ||
@@ -878,6 +895,30 @@ static void parse_cmdline(int argc, char **argp)
show_usage(1);
break;
}
+ if (mode == MODE_SRXFHINDIR) {
+ if (!strcmp(argp[i], "equal")) {
+ if (argc != i + 2) {
+ show_usage(1);
+ break;
+ }
+ i += 1;
+ rxfhindir_equal =
+ get_int_range(argp[i], 0, 1,
+ INT_MAX);
+ i += 1;
+ } else if (!strcmp(argp[i], "weight")) {
+ i += 1;
+ if (i >= argc) {
+ show_usage(1);
+ break;
+ }
+ rxfhindir_weight = argp + i;
+ i = argc;
+ } else {
+ show_usage(1);
+ }
+ break;
+ }
if (mode != MODE_SSET)
show_usage(1);
if (!strcmp(argp[i], "speed")) {
@@ -1812,6 +1853,10 @@ static int doit(void)
return do_grxclass(fd, &ifr);
} else if (mode == MODE_SNFC) {
return do_srxclass(fd, &ifr);
+ } else if (mode == MODE_GRXFHINDIR) {
+ return do_grxfhindir(fd, &ifr);
+ } else if (mode == MODE_SRXFHINDIR) {
+ return do_srxfhindir(fd, &ifr);
} else if (mode == MODE_SNTUPLE) {
return do_srxntuple(fd, &ifr);
} else if (mode == MODE_GNTUPLE) {
@@ -2751,6 +2796,123 @@ static int do_grxclass(int fd, struct ifreq *ifr)
return 0;
}
+static int do_grxfhindir(int fd, struct ifreq *ifr)
+{
+ struct ethtool_rxnfc ring_count;
+ struct ethtool_rxfh_indir indir_head;
+ struct ethtool_rxfh_indir *indir;
+ u32 i;
+ int err;
+
+ ring_count.cmd = ETHTOOL_GRXRINGS;
+ ifr->ifr_data = (caddr_t) &ring_count;
+ err = send_ioctl(fd, ifr);
+ if (err < 0) {
+ perror("Cannot get RX ring count");
+ return 102;
+ }
+
+ indir_head.cmd = ETHTOOL_GRXFHINDIR;
+ indir_head.size = 0;
+ ifr->ifr_data = (caddr_t) &indir_head;
+ err = send_ioctl(fd, ifr);
+ if (err < 0) {
+ perror("Cannot get RX flow hash indirection table size");
+ return 103;
+ }
+
+ indir = malloc(sizeof(*indir) +
+ indir_head.size * sizeof(*indir->ring_index));
+ indir->cmd = ETHTOOL_GRXFHINDIR;
+ indir->size = indir_head.size;
+ ifr->ifr_data = (caddr_t) indir;
+ err = send_ioctl(fd, ifr);
+ if (err < 0) {
+ perror("Cannot get RX flow hash indirection table");
+ return 103;
+ }
+
+ printf("RX flow hash indirection table for %s with %llu RX ring(s):\n",
+ devname, ring_count.data);
+ for (i = 0; i < indir->size; i++) {
+ if (i % 8 == 0)
+ printf("%5zu: ", i);
+ printf(" %5u", indir->ring_index[i]);
+ if (i % 8 == 7)
+ fputc('\n', stdout);
+ }
+ return 0;
+}
+
+static int do_srxfhindir(int fd, struct ifreq *ifr)
+{
+ struct ethtool_rxfh_indir indir_head;
+ struct ethtool_rxfh_indir *indir;
+ u32 i;
+ int err;
+
+ if (!rxfhindir_equal && !rxfhindir_weight)
+ show_usage(1);
+
+ indir_head.cmd = ETHTOOL_GRXFHINDIR;
+ indir_head.size = 0;
+ ifr->ifr_data = (caddr_t) &indir_head;
+ err = send_ioctl(fd, ifr);
+ if (err < 0) {
+ perror("Cannot get RX flow hash indirection table size");
+ return 104;
+ }
+
+ indir = malloc(sizeof(*indir) +
+ indir_head.size * sizeof(*indir->ring_index));
+ indir->cmd = ETHTOOL_SRXFHINDIR;
+ indir->size = indir_head.size;
+
+ if (rxfhindir_equal) {
+ for (i = 0; i < indir->size; i++)
+ indir->ring_index[i] = i % rxfhindir_equal;
+ } else {
+ u32 j, weight, sum = 0, partial = 0;
+
+ for (j = 0; rxfhindir_weight[j]; j++) {
+ weight = get_u32(rxfhindir_weight[j], 0);
+ sum += weight;
+ }
+
+ if (sum == 0) {
+ fprintf(stderr,
+ "At least one weight must be non-zero\n");
+ exit(1);
+ }
+
+ if (sum > indir->size) {
+ fprintf(stderr,
+ "Total weight exceeds the size of the "
+ "indirection table\n");
+ exit(1);
+ }
+
+ j = -1;
+ for (i = 0; i < indir->size; i++) {
+ if (i >= indir->size * partial / sum) {
+ j += 1;
+ weight = get_u32(rxfhindir_weight[j], 0);
+ partial += weight;
+ }
+ indir->ring_index[i] = j;
+ }
+ }
+
+ ifr->ifr_data = (caddr_t) indir;
+ err = send_ioctl(fd, ifr);
+ if (err < 0) {
+ perror("Cannot set RX flow hash indirection table");
+ return 105;
+ }
+
+ return 0;
+}
+
static int do_flash(int fd, struct ifreq *ifr)
{
struct ethtool_flash efl;
--
1.6.2.5
--
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH ethtool 2/2] ethtool: Add support for control of RX flow hash indirection
2010-06-30 15:13 ` [PATCH ethtool 2/2] ethtool: Add support for control of RX flow hash indirection Ben Hutchings
@ 2010-07-01 16:03 ` Ben Hutchings
2010-07-02 7:25 ` Jeff Garzik
1 sibling, 0 replies; 4+ messages in thread
From: Ben Hutchings @ 2010-07-01 16:03 UTC (permalink / raw)
To: Jeff Garzik; +Cc: netdev, linux-net-drivers
On Wed, 2010-06-30 at 16:13 +0100, Ben Hutchings wrote:
> Many NICs use an indirection table to map an RX flow hash value to one
> of an arbitrary number of queues (not necessarily a power of 2). It
> can be useful to remove some queues from this indirection table so
> that they are only used for flows that are specifically filtered
> there. It may also be useful to weight the mapping to account for
> user processes with the same CPU-affinity as the RX interrupts.
[...]
> + printf("RX flow hash indirection table for %s with %llu RX ring(s):\n",
> + devname, ring_count.data);
> + for (i = 0; i < indir->size; i++) {
> + if (i % 8 == 0)
> + printf("%5zu: ", i);
> + printf(" %5u", indir->ring_index[i]);
> + if (i % 8 == 7)
> + fputc('\n', stdout);
> + }
[...]
The "%5zu: " above should be "%5u: ". I can either send another patch
or leave you to fix this up, as you prefer.
Ben.
--
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH ethtool 2/2] ethtool: Add support for control of RX flow hash indirection
2010-06-30 15:13 ` [PATCH ethtool 2/2] ethtool: Add support for control of RX flow hash indirection Ben Hutchings
2010-07-01 16:03 ` Ben Hutchings
@ 2010-07-02 7:25 ` Jeff Garzik
1 sibling, 0 replies; 4+ messages in thread
From: Jeff Garzik @ 2010-07-02 7:25 UTC (permalink / raw)
To: Ben Hutchings; +Cc: Jeff Garzik, netdev, linux-net-drivers
On 06/30/2010 11:13 AM, Ben Hutchings wrote:
> Many NICs use an indirection table to map an RX flow hash value to one
> of an arbitrary number of queues (not necessarily a power of 2). It
> can be useful to remove some queues from this indirection table so
> that they are only used for flows that are specifically filtered
> there. It may also be useful to weight the mapping to account for
> user processes with the same CPU-affinity as the RX interrupts.
>
> Signed-off-by: Ben Hutchings<bhutchings@solarflare.com>
applied 1-2, after making requested printf correction
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-07-02 7:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-30 15:12 [PATCH ethtool 1/2] ethtool-copy.h: sync with net-next Ben Hutchings
2010-06-30 15:13 ` [PATCH ethtool 2/2] ethtool: Add support for control of RX flow hash indirection Ben Hutchings
2010-07-01 16:03 ` Ben Hutchings
2010-07-02 7:25 ` Jeff Garzik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).