netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Lemoine <eric.lemoine@gmail.com>
To: hadi@cyberus.ca
Cc: netdev@oss.sgi.com
Subject: Re: [PATCH] Allow setting dev->weight using ip(8)
Date: Mon, 30 Aug 2004 16:33:01 +0200	[thread overview]
Message-ID: <5cac192f0408300733477c6c9@mail.gmail.com> (raw)
In-Reply-To: <1093868860.1075.573.camel@jzny.localdomain>

[-- Attachment #1: Type: text/plain, Size: 1319 bytes --]

> > For my own testing purposes, I often need to modify dev->weight. So I
> > patched the kernel and iproute2 to be able to modify dev->weight using
> > ip(8). After all, one can modify tx_queue_len so why not weight?
> >
> > Two kernel patches attached: one using the ioctl framework and another
> > using the rtnetlink framework. Warning: the attached rtnetlink patch
> > is a superset of Thomas Graf's rtnetlink patch for setting mtu and
> > tx_queue_len.
> >
> > PS: both patches are against 2.6.5-rc3-ben0 but should apply to any 2.6.
 
> Looks sane.
> Not sure if you should encourage ioctl though ;->

iproute still uses ioctl at that time, doesn't it?

> Out of curiosity, what/when do you change weight? I think its valuable
> to do so, just curious.

With weight one can have the NIC fetch rx descriptors while the rx
interrupt remains disabled. This further means that under high input
load, one single rx interrupt can result in more than RX_RING_SIZE rx
packets polled. Using this + tx polling, I could observe a system
fully loaded by the network with no interrupts at all.

> missing user space/ip patch btw.

I attached a patch to iproute-2.6.8. To make the patch compile I had
to tinker with the Makefile - it seems that KERNEL_INCLUDE does no
longer serve any purpose, except for ATM maybe.

-- 
Eric

[-- Attachment #2: patch-ioctl_dev_weight-iproute-2-6-8 --]
[-- Type: application/octet-stream, Size: 3130 bytes --]

--- ip/iplink.c.old	2004-08-30 15:32:20.361781064 +0200
+++ ip/iplink.c	2004-08-30 15:45:23.701826039 +0200
@@ -44,6 +44,7 @@
 	fprintf(stderr, "	                     promisc { on | off } |\n");
 	fprintf(stderr, "	                     trailers { on | off } |\n");
 	fprintf(stderr, "	                     txqueuelen PACKETS |\n");
+	fprintf(stderr, "	                     weight PACKETS |\n");
 	fprintf(stderr, "	                     name NEWNAME |\n");
 	fprintf(stderr, "	                     address LLADDR | broadcast LLADDR |\n");
 	fprintf(stderr, "	                     mtu MTU }\n");
@@ -174,6 +175,28 @@
 	return 0; 
 }
 
+static int set_weight(char *dev, int weight)
+{
+	struct ifreq ifr;
+	int s;
+
+	s = get_ctl_fd();
+	if (s < 0)
+		return -1;
+
+	memset(&ifr, 0, sizeof(ifr));
+	strcpy(ifr.ifr_name, dev);
+	ifr.ifr_weight = weight;
+	if (ioctl(s, SIOCSIFWEIGHT, &ifr) < 0) {
+		perror("SIOCSIFWEIGHT");
+		close(s);
+		return -1;
+	}
+	close(s);
+
+	return 0;
+}
+
 static int get_address(char *dev, int *htype)
 {
 	struct ifreq ifr;
@@ -257,6 +280,7 @@
 	__u32 flags = 0;
 	int qlen = -1;
 	int mtu = -1;
+	int weight = -1;
 	char *newaddr = NULL;
 	char *newbrd = NULL;
 	struct ifreq ifr0, ifr1;
@@ -294,6 +318,12 @@
 				duparg("mtu", *argv);
 			if (get_integer(&mtu, *argv, 0))
 				invarg("Invalid \"mtu\" value\n", *argv);
+		} else if (matches(*argv, "weight") == 0) {
+			NEXT_ARG();
+			if (weight != -1)
+				duparg("weight", *argv);
+			if (get_integer(&weight, *argv, 0))
+				invarg("Invalid \"weight\" value\n", *argv);
 		} else if (strcmp(*argv, "multicast") == 0) {
 			NEXT_ARG();
 			mask |= IFF_MULTICAST;
@@ -395,6 +425,10 @@
 		if (set_mtu(dev, mtu) < 0)
 			return -1; 
 	}
+	if (weight != -1) {
+		if (set_weight(dev, weight) < 0)
+			return -1;
+	}
 	if (newaddr || newbrd) {
 		if (newbrd) {
 			if (set_address(&ifr1, 1) < 0)
--- ip/ipaddress.c.old	2004-08-30 15:45:36.811492080 +0200
+++ ip/ipaddress.c	2004-08-30 16:14:10.722831419 +0200
@@ -40,6 +40,7 @@
 	int family;
 	int oneline;
 	int showqueue;
+	int showweight;
 	inet_prefix pfx;
 	int scope, scopemask;
 	int flags, flagmask;
@@ -126,6 +127,28 @@
 		printf("qlen %d", ifr.ifr_qlen);
 }
 
+void print_weight(char *name)
+{
+	struct ifreq ifr;
+	int s;
+
+	s = socket(AF_INET, SOCK_STREAM, 0);
+	if (s < 0)
+		return;
+
+	memset(&ifr, 0, sizeof(ifr));
+	strcpy(ifr.ifr_name, name);
+	if (ioctl(s, SIOCGIFWEIGHT, &ifr) < 0) {
+		perror("SIOCGIFWEIGHT");
+		close(s);
+		return;
+	}
+	close(s);
+
+	if (ifr.ifr_weight)
+		printf(" weight %d", ifr.ifr_weight);
+}
+
 int print_linkinfo(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 {
 	FILE *fp = (FILE*)arg;
@@ -191,6 +214,9 @@
 	if (filter.showqueue)
 		print_queuelen((char*)RTA_DATA(tb[IFLA_IFNAME]));
 	
+	if (filter.showweight)
+		print_weight((char*)RTA_DATA(tb[IFLA_IFNAME]));
+
 	if (!filter.family || filter.family == AF_PACKET) {
 		SPRINT_BUF(b1);
 		fprintf(fp, "%s", _SL_);
@@ -496,6 +522,7 @@
 
 	ipaddr_reset_filter(oneline);
 	filter.showqueue = 1;
+	filter.showweight = 1;
 
 	if (filter.family == AF_UNSPEC)
 		filter.family = preferred_family;

  parent reply	other threads:[~2004-08-30 14:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-30 10:56 [PATCH] Allow setting dev->weight using ip(8) Eric Lemoine
2004-08-30 12:27 ` jamal
2004-08-30 12:42   ` jamal
2004-08-30 14:35     ` Eric Lemoine
2004-08-30 23:58       ` David S. Miller
2004-08-31  9:58         ` Eric Lemoine
2004-08-30 14:33   ` Eric Lemoine [this message]
2004-09-08 13:45     ` Thomas Graf

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=5cac192f0408300733477c6c9@mail.gmail.com \
    --to=eric.lemoine@gmail.com \
    --cc=hadi@cyberus.ca \
    --cc=netdev@oss.sgi.com \
    /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;
as well as URLs for NNTP newsgroup(s).