mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-10-15 09:58:30 +00:00
ip: Support IFLA_TXQLEN in ip link command
Eric Dumazet a écrit : > We currently use an expensive ioctl() to get device txqueuelen, while > rtnetlink gave it to us for free. This patch speeds up ip link operation > when many devices are registered. > Here is a 2nd version od this patch, not displaying "qlen 0" useless info [PATCH iproute2] ip: Support IFLA_TXQLEN in ip link show command We currently use an expensive ioctl() to get device txqueuelen, while rtnetlink gave it to us for free. This patch speeds up ip link operation when many devices are registered. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
This commit is contained in:
parent
892eba309f
commit
f78e316f25
@ -130,26 +130,31 @@ static void print_operstate(FILE *f, __u8 state)
|
|||||||
fprintf(f, "state %s ", oper_states[state]);
|
fprintf(f, "state %s ", oper_states[state]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_queuelen(FILE *f, const char *name)
|
static void print_queuelen(FILE *f, struct rtattr *tb[IFLA_MAX + 1])
|
||||||
{
|
{
|
||||||
struct ifreq ifr;
|
int qlen;
|
||||||
int s;
|
|
||||||
|
|
||||||
s = socket(AF_INET, SOCK_STREAM, 0);
|
if (tb[IFLA_TXQLEN])
|
||||||
if (s < 0)
|
qlen = *(int *)RTA_DATA(tb[IFLA_TXQLEN]);
|
||||||
return;
|
else {
|
||||||
|
struct ifreq ifr;
|
||||||
|
int s = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
|
||||||
memset(&ifr, 0, sizeof(ifr));
|
if (s < 0)
|
||||||
strcpy(ifr.ifr_name, name);
|
return;
|
||||||
if (ioctl(s, SIOCGIFTXQLEN, &ifr) < 0) {
|
|
||||||
fprintf(f, "ioctl(SIOCGIFXQLEN) failed: %s\n", strerror(errno));
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
|
strcpy(ifr.ifr_name, (char *)RTA_DATA(tb[IFLA_IFNAME]));
|
||||||
|
if (ioctl(s, SIOCGIFTXQLEN, &ifr) < 0) {
|
||||||
|
fprintf(f, "ioctl(SIOCGIFXQLEN) failed: %s\n", strerror(errno));
|
||||||
|
close(s);
|
||||||
|
return;
|
||||||
|
}
|
||||||
close(s);
|
close(s);
|
||||||
return;
|
qlen = ifr.ifr_qlen;
|
||||||
}
|
}
|
||||||
close(s);
|
if (qlen)
|
||||||
|
fprintf(f, "qlen %d", qlen);
|
||||||
if (ifr.ifr_qlen)
|
|
||||||
fprintf(f, "qlen %d", ifr.ifr_qlen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_linktype(FILE *fp, struct rtattr *tb)
|
static void print_linktype(FILE *fp, struct rtattr *tb)
|
||||||
@ -286,7 +291,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
|
|||||||
print_operstate(fp, *(__u8 *)RTA_DATA(tb[IFLA_OPERSTATE]));
|
print_operstate(fp, *(__u8 *)RTA_DATA(tb[IFLA_OPERSTATE]));
|
||||||
|
|
||||||
if (filter.showqueue)
|
if (filter.showqueue)
|
||||||
print_queuelen(fp, (char*)RTA_DATA(tb[IFLA_IFNAME]));
|
print_queuelen(fp, tb);
|
||||||
|
|
||||||
if (!filter.family || filter.family == AF_PACKET) {
|
if (!filter.family || filter.family == AF_PACKET) {
|
||||||
SPRINT_BUF(b1);
|
SPRINT_BUF(b1);
|
||||||
|
Loading…
Reference in New Issue
Block a user