2010-02-22 15:57:36 +00:00
|
|
|
/*-
|
2011-01-24 10:54:09 +00:00
|
|
|
* Copyright (c) 2010-2011 Juniper Networks, Inc.
|
2010-02-22 15:57:36 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by Robert N. M. Watson under contract
|
|
|
|
* to Juniper Networks, Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2010-03-01 00:46:45 +00:00
|
|
|
#include <sys/param.h>
|
2010-02-22 15:57:36 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
2010-03-01 00:46:45 +00:00
|
|
|
#include <sys/_lock.h>
|
|
|
|
#include <sys/_mutex.h>
|
|
|
|
|
|
|
|
#define _WANT_NETISR_INTERNAL
|
2010-02-22 15:57:36 +00:00
|
|
|
#include <net/netisr.h>
|
2010-03-01 00:46:45 +00:00
|
|
|
#include <net/netisr_internal.h>
|
2010-02-22 15:57:36 +00:00
|
|
|
|
|
|
|
#include <err.h>
|
2010-03-01 00:46:45 +00:00
|
|
|
#include <kvm.h>
|
2010-02-22 15:57:36 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2015-02-21 23:47:20 +00:00
|
|
|
#include <stdbool.h>
|
2010-03-01 00:46:45 +00:00
|
|
|
#include <string.h>
|
2015-02-21 23:47:20 +00:00
|
|
|
#include <libxo/xo.h>
|
2010-02-22 15:57:36 +00:00
|
|
|
#include "netstat.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print statistics for the kernel netisr subsystem.
|
|
|
|
*/
|
|
|
|
static u_int bindthreads;
|
|
|
|
static u_int maxthreads;
|
|
|
|
static u_int numthreads;
|
|
|
|
|
|
|
|
static u_int defaultqlimit;
|
|
|
|
static u_int maxqlimit;
|
|
|
|
|
2011-05-24 12:38:00 +00:00
|
|
|
static char dispatch_policy[20];
|
2010-02-22 15:57:36 +00:00
|
|
|
|
|
|
|
static struct sysctl_netisr_proto *proto_array;
|
|
|
|
static u_int proto_array_len;
|
|
|
|
|
|
|
|
static struct sysctl_netisr_workstream *workstream_array;
|
|
|
|
static u_int workstream_array_len;
|
|
|
|
|
|
|
|
static struct sysctl_netisr_work *work_array;
|
|
|
|
static u_int work_array_len;
|
|
|
|
|
2010-03-01 00:46:45 +00:00
|
|
|
static u_int *nws_array;
|
|
|
|
|
|
|
|
static u_int maxprot;
|
|
|
|
|
2011-05-24 12:38:00 +00:00
|
|
|
static void
|
2013-02-19 13:17:16 +00:00
|
|
|
netisr_dispatch_policy_to_string(u_int policy, char *buf,
|
2011-05-24 12:38:00 +00:00
|
|
|
size_t buflen)
|
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
|
2013-02-19 13:17:16 +00:00
|
|
|
switch (policy) {
|
2011-05-24 12:38:00 +00:00
|
|
|
case NETISR_DISPATCH_DEFAULT:
|
|
|
|
str = "default";
|
|
|
|
break;
|
|
|
|
case NETISR_DISPATCH_DEFERRED:
|
|
|
|
str = "deferred";
|
|
|
|
break;
|
|
|
|
case NETISR_DISPATCH_HYBRID:
|
|
|
|
str = "hybrid";
|
|
|
|
break;
|
|
|
|
case NETISR_DISPATCH_DIRECT:
|
|
|
|
str = "direct";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
snprintf(buf, buflen, "%s", str);
|
|
|
|
}
|
|
|
|
|
2010-03-01 00:46:45 +00:00
|
|
|
static void
|
2013-02-19 13:17:16 +00:00
|
|
|
netisr_load_kvm_uint(kvm_t *kd, const char *name, u_int *p)
|
2010-03-01 00:46:45 +00:00
|
|
|
{
|
|
|
|
struct nlist nl[] = {
|
|
|
|
{ .n_name = name },
|
|
|
|
{ .n_name = NULL },
|
|
|
|
};
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = kvm_nlist(kd, nl);
|
|
|
|
if (ret < 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "%s: kvm_nlist(%s): %s", __func__, name,
|
2010-03-01 00:46:45 +00:00
|
|
|
kvm_geterr(kd));
|
|
|
|
if (ret != 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "%s: kvm_nlist(%s): unresolved symbol", __func__,
|
2010-03-01 00:46:45 +00:00
|
|
|
name);
|
|
|
|
if (kvm_read(kd, nl[0].n_value, p, sizeof(*p)) != sizeof(*p))
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "%s: kvm_read(%s): %s", __func__, name,
|
2010-03-01 00:46:45 +00:00
|
|
|
kvm_geterr(kd));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load a nul-terminated string from KVM up to 'limit', guarantee that the
|
|
|
|
* string in local memory is nul-terminated.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
netisr_load_kvm_string(kvm_t *kd, uintptr_t addr, char *dest, u_int limit)
|
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
for (i = 0; i < limit; i++) {
|
|
|
|
if (kvm_read(kd, addr + i, &dest[i], sizeof(dest[i])) !=
|
|
|
|
sizeof(dest[i]))
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_err(-1, "%s: kvm_read: %s", __func__,
|
2010-03-01 00:46:45 +00:00
|
|
|
kvm_geterr(kd));
|
|
|
|
if (dest[i] == '\0')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dest[limit - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
netisr_proto2name(u_int proto)
|
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
for (i = 0; i < proto_array_len; i++) {
|
|
|
|
if (proto_array[i].snp_proto == proto)
|
|
|
|
return (proto_array[i].snp_name);
|
|
|
|
}
|
|
|
|
return ("unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
netisr_protoispresent(u_int proto)
|
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
for (i = 0; i < proto_array_len; i++) {
|
|
|
|
if (proto_array[i].snp_proto == proto)
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
netisr_load_kvm_config(kvm_t *kd)
|
|
|
|
{
|
2011-05-24 12:38:00 +00:00
|
|
|
u_int tmp;
|
2010-03-01 00:46:45 +00:00
|
|
|
|
|
|
|
netisr_load_kvm_uint(kd, "_netisr_bindthreads", &bindthreads);
|
|
|
|
netisr_load_kvm_uint(kd, "_netisr_maxthreads", &maxthreads);
|
|
|
|
netisr_load_kvm_uint(kd, "_nws_count", &numthreads);
|
|
|
|
|
|
|
|
netisr_load_kvm_uint(kd, "_netisr_defaultqlimit", &defaultqlimit);
|
|
|
|
netisr_load_kvm_uint(kd, "_netisr_maxqlimit", &maxqlimit);
|
|
|
|
|
2011-05-24 12:38:00 +00:00
|
|
|
netisr_load_kvm_uint(kd, "_netisr_dispatch_policy", &tmp);
|
|
|
|
netisr_dispatch_policy_to_string(tmp, dispatch_policy,
|
|
|
|
sizeof(dispatch_policy));
|
2010-03-01 00:46:45 +00:00
|
|
|
}
|
|
|
|
|
2010-02-22 15:57:36 +00:00
|
|
|
static void
|
|
|
|
netisr_load_sysctl_uint(const char *name, u_int *p)
|
|
|
|
{
|
|
|
|
size_t retlen;
|
|
|
|
|
|
|
|
retlen = sizeof(u_int);
|
|
|
|
if (sysctlbyname(name, p, &retlen, NULL, 0) < 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_err(-1, "%s", name);
|
2010-02-22 15:57:36 +00:00
|
|
|
if (retlen != sizeof(u_int))
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "%s: invalid len %ju", name, (uintmax_t)retlen);
|
2010-02-22 15:57:36 +00:00
|
|
|
}
|
|
|
|
|
2011-05-24 12:38:00 +00:00
|
|
|
static void
|
|
|
|
netisr_load_sysctl_string(const char *name, char *p, size_t len)
|
|
|
|
{
|
|
|
|
size_t retlen;
|
|
|
|
|
|
|
|
retlen = len;
|
|
|
|
if (sysctlbyname(name, p, &retlen, NULL, 0) < 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_err(-1, "%s", name);
|
2011-05-24 12:38:00 +00:00
|
|
|
p[len - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
2010-02-22 15:57:36 +00:00
|
|
|
static void
|
2010-03-01 00:46:45 +00:00
|
|
|
netisr_load_sysctl_config(void)
|
2010-02-22 15:57:36 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
netisr_load_sysctl_uint("net.isr.bindthreads", &bindthreads);
|
|
|
|
netisr_load_sysctl_uint("net.isr.maxthreads", &maxthreads);
|
|
|
|
netisr_load_sysctl_uint("net.isr.numthreads", &numthreads);
|
|
|
|
|
|
|
|
netisr_load_sysctl_uint("net.isr.defaultqlimit", &defaultqlimit);
|
|
|
|
netisr_load_sysctl_uint("net.isr.maxqlimit", &maxqlimit);
|
|
|
|
|
2011-05-24 12:38:00 +00:00
|
|
|
netisr_load_sysctl_string("net.isr.dispatch", dispatch_policy,
|
|
|
|
sizeof(dispatch_policy));
|
2010-02-22 15:57:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-01 00:46:45 +00:00
|
|
|
netisr_load_kvm_proto(kvm_t *kd)
|
|
|
|
{
|
|
|
|
struct nlist nl[] = {
|
|
|
|
#define NLIST_NETISR_PROTO 0
|
|
|
|
{ .n_name = "_netisr_proto" },
|
|
|
|
{ .n_name = NULL },
|
|
|
|
};
|
|
|
|
struct netisr_proto *np_array, *npp;
|
|
|
|
u_int i, protocount;
|
|
|
|
struct sysctl_netisr_proto *snpp;
|
|
|
|
size_t len;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kernel compile-time and user compile-time definitions of
|
|
|
|
* NETISR_MAXPROT must match, as we use that to size work arrays.
|
|
|
|
*/
|
|
|
|
netisr_load_kvm_uint(kd, "_netisr_maxprot", &maxprot);
|
|
|
|
if (maxprot != NETISR_MAXPROT)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "%s: NETISR_MAXPROT mismatch", __func__);
|
2010-03-01 00:46:45 +00:00
|
|
|
len = maxprot * sizeof(*np_array);
|
|
|
|
np_array = malloc(len);
|
|
|
|
if (np_array == NULL)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_err(-1, "%s: malloc", __func__);
|
2010-03-01 00:46:45 +00:00
|
|
|
ret = kvm_nlist(kd, nl);
|
|
|
|
if (ret < 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "%s: kvm_nlist(_netisr_proto): %s", __func__,
|
2010-03-01 00:46:45 +00:00
|
|
|
kvm_geterr(kd));
|
|
|
|
if (ret != 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "%s: kvm_nlist(_netisr_proto): unresolved symbol",
|
2010-03-01 00:46:45 +00:00
|
|
|
__func__);
|
|
|
|
if (kvm_read(kd, nl[NLIST_NETISR_PROTO].n_value, np_array, len) !=
|
|
|
|
(ssize_t)len)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "%s: kvm_read(_netisr_proto): %s", __func__,
|
2010-03-01 00:46:45 +00:00
|
|
|
kvm_geterr(kd));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Size and allocate memory to hold only live protocols.
|
|
|
|
*/
|
|
|
|
protocount = 0;
|
|
|
|
for (i = 0; i < maxprot; i++) {
|
|
|
|
if (np_array[i].np_name == NULL)
|
|
|
|
continue;
|
|
|
|
protocount++;
|
|
|
|
}
|
|
|
|
proto_array = calloc(protocount, sizeof(*proto_array));
|
|
|
|
if (proto_array == NULL)
|
|
|
|
err(-1, "malloc");
|
|
|
|
protocount = 0;
|
|
|
|
for (i = 0; i < maxprot; i++) {
|
|
|
|
npp = &np_array[i];
|
|
|
|
if (npp->np_name == NULL)
|
|
|
|
continue;
|
|
|
|
snpp = &proto_array[protocount];
|
|
|
|
snpp->snp_version = sizeof(*snpp);
|
|
|
|
netisr_load_kvm_string(kd, (uintptr_t)npp->np_name,
|
|
|
|
snpp->snp_name, sizeof(snpp->snp_name));
|
|
|
|
snpp->snp_proto = i;
|
|
|
|
snpp->snp_qlimit = npp->np_qlimit;
|
|
|
|
snpp->snp_policy = npp->np_policy;
|
2011-05-24 12:38:00 +00:00
|
|
|
snpp->snp_dispatch = npp->np_dispatch;
|
2010-03-01 00:46:45 +00:00
|
|
|
if (npp->np_m2flow != NULL)
|
|
|
|
snpp->snp_flags |= NETISR_SNP_FLAGS_M2FLOW;
|
|
|
|
if (npp->np_m2cpuid != NULL)
|
|
|
|
snpp->snp_flags |= NETISR_SNP_FLAGS_M2CPUID;
|
|
|
|
if (npp->np_drainedcpu != NULL)
|
|
|
|
snpp->snp_flags |= NETISR_SNP_FLAGS_DRAINEDCPU;
|
|
|
|
protocount++;
|
|
|
|
}
|
|
|
|
proto_array_len = protocount;
|
|
|
|
free(np_array);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
netisr_load_sysctl_proto(void)
|
2010-02-22 15:57:36 +00:00
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (sysctlbyname("net.isr.proto", NULL, &len, NULL, 0) < 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_err(-1, "net.isr.proto: query len");
|
2010-02-22 15:57:36 +00:00
|
|
|
if (len % sizeof(*proto_array) != 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "net.isr.proto: invalid len");
|
2010-02-22 15:57:36 +00:00
|
|
|
proto_array = malloc(len);
|
|
|
|
if (proto_array == NULL)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_err(-1, "malloc");
|
2010-02-22 15:57:36 +00:00
|
|
|
if (sysctlbyname("net.isr.proto", proto_array, &len, NULL, 0) < 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_err(-1, "net.isr.proto: query data");
|
2010-02-22 15:57:36 +00:00
|
|
|
if (len % sizeof(*proto_array) != 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "net.isr.proto: invalid len");
|
2010-02-22 15:57:36 +00:00
|
|
|
proto_array_len = len / sizeof(*proto_array);
|
|
|
|
if (proto_array_len < 1)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "net.isr.proto: no data");
|
2010-02-22 15:57:36 +00:00
|
|
|
if (proto_array[0].snp_version != sizeof(proto_array[0]))
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "net.isr.proto: invalid version");
|
2010-02-22 15:57:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-01 00:46:45 +00:00
|
|
|
netisr_load_kvm_workstream(kvm_t *kd)
|
|
|
|
{
|
|
|
|
struct nlist nl[] = {
|
|
|
|
#define NLIST_NWS_ARRAY 0
|
|
|
|
{ .n_name = "_nws_array" },
|
|
|
|
{ .n_name = NULL },
|
|
|
|
};
|
|
|
|
struct netisr_workstream nws;
|
|
|
|
struct sysctl_netisr_workstream *snwsp;
|
|
|
|
struct sysctl_netisr_work *snwp;
|
|
|
|
struct netisr_work *nwp;
|
|
|
|
struct nlist nl_nws[2];
|
|
|
|
u_int counter, cpuid, proto, wsid;
|
|
|
|
size_t len;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
len = numthreads * sizeof(*nws_array);
|
|
|
|
nws_array = malloc(len);
|
|
|
|
if (nws_array == NULL)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_err(-1, "malloc");
|
2010-03-01 00:46:45 +00:00
|
|
|
ret = kvm_nlist(kd, nl);
|
|
|
|
if (ret < 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "%s: kvm_nlist: %s", __func__, kvm_geterr(kd));
|
2010-03-01 00:46:45 +00:00
|
|
|
if (ret != 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "%s: kvm_nlist: unresolved symbol", __func__);
|
2010-03-01 00:46:45 +00:00
|
|
|
if (kvm_read(kd, nl[NLIST_NWS_ARRAY].n_value, nws_array, len) !=
|
|
|
|
(ssize_t)len)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "%s: kvm_read(_nws_array): %s", __func__,
|
2010-03-01 00:46:45 +00:00
|
|
|
kvm_geterr(kd));
|
|
|
|
workstream_array = calloc(numthreads, sizeof(*workstream_array));
|
|
|
|
if (workstream_array == NULL)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_err(-1, "calloc");
|
2010-03-01 00:46:45 +00:00
|
|
|
workstream_array_len = numthreads;
|
|
|
|
work_array = calloc(numthreads * proto_array_len, sizeof(*work_array));
|
|
|
|
if (work_array == NULL)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_err(-1, "calloc");
|
2010-03-01 00:46:45 +00:00
|
|
|
counter = 0;
|
|
|
|
for (wsid = 0; wsid < numthreads; wsid++) {
|
|
|
|
cpuid = nws_array[wsid];
|
|
|
|
if (kvm_dpcpu_setcpu(kd, cpuid) < 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "%s: kvm_dpcpu_setcpu(%u): %s", __func__,
|
2010-03-01 00:46:45 +00:00
|
|
|
cpuid, kvm_geterr(kd));
|
|
|
|
bzero(nl_nws, sizeof(nl_nws));
|
|
|
|
nl_nws[0].n_name = "_nws";
|
|
|
|
ret = kvm_nlist(kd, nl_nws);
|
|
|
|
if (ret < 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "%s: kvm_nlist looking up nws on CPU "
|
|
|
|
"%u: %s", __func__, cpuid, kvm_geterr(kd));
|
2010-03-01 00:46:45 +00:00
|
|
|
if (ret != 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "%s: kvm_nlist(nws): unresolved symbol on "
|
2010-03-01 00:46:45 +00:00
|
|
|
"CPU %u", __func__, cpuid);
|
|
|
|
if (kvm_read(kd, nl_nws[0].n_value, &nws, sizeof(nws)) !=
|
|
|
|
sizeof(nws))
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "%s: kvm_read(nw): %s", __func__,
|
2010-03-01 00:46:45 +00:00
|
|
|
kvm_geterr(kd));
|
|
|
|
snwsp = &workstream_array[wsid];
|
|
|
|
snwsp->snws_version = sizeof(*snwsp);
|
|
|
|
snwsp->snws_wsid = cpuid;
|
|
|
|
snwsp->snws_cpu = cpuid;
|
|
|
|
if (nws.nws_intr_event != NULL)
|
|
|
|
snwsp->snws_flags |= NETISR_SNWS_FLAGS_INTR;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Extract the CPU's per-protocol work information.
|
|
|
|
*/
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_emit("counting to maxprot: {:maxprot/%u}\n", maxprot);
|
2010-03-01 00:46:45 +00:00
|
|
|
for (proto = 0; proto < maxprot; proto++) {
|
|
|
|
if (!netisr_protoispresent(proto))
|
|
|
|
continue;
|
|
|
|
nwp = &nws.nws_work[proto];
|
|
|
|
snwp = &work_array[counter];
|
|
|
|
snwp->snw_version = sizeof(*snwp);
|
|
|
|
snwp->snw_wsid = cpuid;
|
|
|
|
snwp->snw_proto = proto;
|
|
|
|
snwp->snw_len = nwp->nw_len;
|
|
|
|
snwp->snw_watermark = nwp->nw_watermark;
|
|
|
|
snwp->snw_dispatched = nwp->nw_dispatched;
|
|
|
|
snwp->snw_hybrid_dispatched =
|
|
|
|
nwp->nw_hybrid_dispatched;
|
|
|
|
snwp->snw_qdrops = nwp->nw_qdrops;
|
|
|
|
snwp->snw_queued = nwp->nw_queued;
|
|
|
|
snwp->snw_handled = nwp->nw_handled;
|
|
|
|
counter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
work_array_len = counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
netisr_load_sysctl_workstream(void)
|
2010-02-22 15:57:36 +00:00
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (sysctlbyname("net.isr.workstream", NULL, &len, NULL, 0) < 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_err(-1, "net.isr.workstream: query len");
|
2010-02-22 15:57:36 +00:00
|
|
|
if (len % sizeof(*workstream_array) != 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "net.isr.workstream: invalid len");
|
2010-02-22 15:57:36 +00:00
|
|
|
workstream_array = malloc(len);
|
|
|
|
if (workstream_array == NULL)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_err(-1, "malloc");
|
2010-02-22 15:57:36 +00:00
|
|
|
if (sysctlbyname("net.isr.workstream", workstream_array, &len, NULL,
|
|
|
|
0) < 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_err(-1, "net.isr.workstream: query data");
|
2010-02-22 15:57:36 +00:00
|
|
|
if (len % sizeof(*workstream_array) != 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "net.isr.workstream: invalid len");
|
2010-02-22 15:57:36 +00:00
|
|
|
workstream_array_len = len / sizeof(*workstream_array);
|
|
|
|
if (workstream_array_len < 1)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "net.isr.workstream: no data");
|
2010-02-22 15:57:36 +00:00
|
|
|
if (workstream_array[0].snws_version != sizeof(workstream_array[0]))
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "net.isr.workstream: invalid version");
|
2010-02-22 15:57:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-01 00:46:45 +00:00
|
|
|
netisr_load_sysctl_work(void)
|
2010-02-22 15:57:36 +00:00
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (sysctlbyname("net.isr.work", NULL, &len, NULL, 0) < 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_err(-1, "net.isr.work: query len");
|
2010-02-22 15:57:36 +00:00
|
|
|
if (len % sizeof(*work_array) != 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "net.isr.work: invalid len");
|
2010-02-22 15:57:36 +00:00
|
|
|
work_array = malloc(len);
|
|
|
|
if (work_array == NULL)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_err(-1, "malloc");
|
2010-02-22 15:57:36 +00:00
|
|
|
if (sysctlbyname("net.isr.work", work_array, &len, NULL, 0) < 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_err(-1, "net.isr.work: query data");
|
2010-02-22 15:57:36 +00:00
|
|
|
if (len % sizeof(*work_array) != 0)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "net.isr.work: invalid len");
|
2010-02-22 15:57:36 +00:00
|
|
|
work_array_len = len / sizeof(*work_array);
|
|
|
|
if (work_array_len < 1)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "net.isr.work: no data");
|
2010-02-22 15:57:36 +00:00
|
|
|
if (work_array[0].snw_version != sizeof(work_array[0]))
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "net.isr.work: invalid version");
|
2010-02-22 15:57:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
netisr_print_proto(struct sysctl_netisr_proto *snpp)
|
|
|
|
{
|
2011-05-24 12:38:00 +00:00
|
|
|
char tmp[20];
|
2010-02-22 15:57:36 +00:00
|
|
|
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_emit("{[:-6}{k:name/%s}{]:}", snpp->snp_name);
|
|
|
|
xo_emit(" {:protocol/%5u}", snpp->snp_proto);
|
|
|
|
xo_emit(" {:queue-limit/%6u}", snpp->snp_qlimit);
|
|
|
|
xo_emit(" {:policy-type/%6s}",
|
2010-02-22 15:57:36 +00:00
|
|
|
(snpp->snp_policy == NETISR_POLICY_SOURCE) ? "source" :
|
|
|
|
(snpp->snp_policy == NETISR_POLICY_FLOW) ? "flow" :
|
|
|
|
(snpp->snp_policy == NETISR_POLICY_CPU) ? "cpu" : "-");
|
2011-05-24 12:38:00 +00:00
|
|
|
netisr_dispatch_policy_to_string(snpp->snp_dispatch, tmp,
|
|
|
|
sizeof(tmp));
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_emit(" {:policy/%8s}", tmp);
|
|
|
|
xo_emit(" {:flags/%s%s%s}\n",
|
2010-02-22 15:57:36 +00:00
|
|
|
(snpp->snp_flags & NETISR_SNP_FLAGS_M2CPUID) ? "C" : "-",
|
|
|
|
(snpp->snp_flags & NETISR_SNP_FLAGS_DRAINEDCPU) ? "D" : "-",
|
|
|
|
(snpp->snp_flags & NETISR_SNP_FLAGS_M2FLOW) ? "F" : "-");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
netisr_print_workstream(struct sysctl_netisr_workstream *snwsp)
|
|
|
|
{
|
|
|
|
struct sysctl_netisr_work *snwp;
|
|
|
|
u_int i;
|
|
|
|
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_open_list("work");
|
2010-02-22 15:57:36 +00:00
|
|
|
for (i = 0; i < work_array_len; i++) {
|
|
|
|
snwp = &work_array[i];
|
|
|
|
if (snwp->snw_wsid != snwsp->snws_wsid)
|
|
|
|
continue;
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_open_instance("work");
|
|
|
|
xo_emit("{t:workstream/%4u} ", snwsp->snws_wsid);
|
|
|
|
xo_emit("{t:cpu/%3u} ", snwsp->snws_cpu);
|
|
|
|
xo_emit("{P: }");
|
|
|
|
xo_emit("{t:name/%-6s}", netisr_proto2name(snwp->snw_proto));
|
|
|
|
xo_emit(" {t:length/%5u}", snwp->snw_len);
|
|
|
|
xo_emit(" {t:watermark/%5u}", snwp->snw_watermark);
|
|
|
|
xo_emit(" {t:dispatched/%8ju}", snwp->snw_dispatched);
|
|
|
|
xo_emit(" {t:hybrid-dispatched/%8ju}",
|
|
|
|
snwp->snw_hybrid_dispatched);
|
|
|
|
xo_emit(" {t:queue-drops/%8ju}", snwp->snw_qdrops);
|
|
|
|
xo_emit(" {t:queued/%8ju}", snwp->snw_queued);
|
|
|
|
xo_emit(" {t:handled/%8ju}", snwp->snw_handled);
|
|
|
|
xo_emit("\n");
|
|
|
|
xo_close_instance("work");
|
2010-02-22 15:57:36 +00:00
|
|
|
}
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_close_list("work");
|
2010-02-22 15:57:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-01 00:46:45 +00:00
|
|
|
netisr_stats(void *kvmd)
|
2010-02-22 15:57:36 +00:00
|
|
|
{
|
|
|
|
struct sysctl_netisr_workstream *snwsp;
|
|
|
|
struct sysctl_netisr_proto *snpp;
|
2010-03-01 00:46:45 +00:00
|
|
|
kvm_t *kd = kvmd;
|
2010-02-22 15:57:36 +00:00
|
|
|
u_int i;
|
|
|
|
|
2010-03-01 00:46:45 +00:00
|
|
|
if (live) {
|
|
|
|
netisr_load_sysctl_config();
|
|
|
|
netisr_load_sysctl_proto();
|
|
|
|
netisr_load_sysctl_workstream();
|
|
|
|
netisr_load_sysctl_work();
|
|
|
|
} else {
|
|
|
|
if (kd == NULL)
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_errx(-1, "netisr_stats: !live but !kd");
|
2010-03-01 00:46:45 +00:00
|
|
|
netisr_load_kvm_config(kd);
|
|
|
|
netisr_load_kvm_proto(kd);
|
|
|
|
netisr_load_kvm_workstream(kd); /* Also does work. */
|
|
|
|
}
|
2010-02-22 15:57:36 +00:00
|
|
|
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_open_container("netisr");
|
|
|
|
|
|
|
|
xo_emit("{T:Configuration}:\n");
|
|
|
|
xo_emit("{T:/%-25s} {T:/%12s} {T:/%12s}\n",
|
|
|
|
"Setting", "Current", "Limit");
|
|
|
|
xo_emit("{T:/%-25s} {T:/%12u} {T:/%12u}\n",
|
|
|
|
"Thread count", numthreads, maxthreads);
|
|
|
|
xo_emit("{T:/%-25s} {T:/%12u} {T:/%12u}\n",
|
|
|
|
"Default queue limit", defaultqlimit, maxqlimit);
|
|
|
|
xo_emit("{T:/%-25s} {T:/%12s} {T:/%12s}\n",
|
|
|
|
"Dispatch policy", dispatch_policy, "n/a");
|
|
|
|
xo_emit("{T:/%-25s} {T:/%12s} {T:/%12s}\n",
|
|
|
|
"Threads bound to CPUs", bindthreads ? "enabled" : "disabled",
|
2011-05-24 12:38:00 +00:00
|
|
|
"n/a");
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_emit("\n");
|
2010-02-22 15:57:36 +00:00
|
|
|
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_emit("{T:Protocols}:\n");
|
|
|
|
xo_emit("{T:/%-6s} {T:/%5s} {T:/%6s} {T:/%-6s} {T:/%-8s} {T:/%-5s}\n",
|
|
|
|
"Name", "Proto", "QLimit", "Policy", "Dispatch", "Flags");
|
|
|
|
xo_open_list("protocol");
|
2010-02-22 15:57:36 +00:00
|
|
|
for (i = 0; i < proto_array_len; i++) {
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_open_instance("protocol");
|
2010-02-22 15:57:36 +00:00
|
|
|
snpp = &proto_array[i];
|
|
|
|
netisr_print_proto(snpp);
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_close_instance("protocol");
|
2010-02-22 15:57:36 +00:00
|
|
|
}
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_close_list("protocol");
|
|
|
|
xo_emit("\n");
|
|
|
|
|
|
|
|
xo_emit("{T:Workstreams}:\n");
|
|
|
|
xo_emit("{T:/%4s} {T:/%3s} ", "WSID", "CPU");
|
|
|
|
xo_emit("{P:/%2s}", "");
|
|
|
|
xo_emit("{T:/%-6s} {T:/%5s} {T:/%5s} {T:/%8s} {T:/%8s} {T:/%8s} "
|
|
|
|
"{T:/%8s} {T:/%8s}\n",
|
|
|
|
"Name", "Len", "WMark", "Disp'd", "HDisp'd", "QDrops", "Queued",
|
|
|
|
"Handled");
|
|
|
|
xo_open_list("workstream");
|
2010-02-22 15:57:36 +00:00
|
|
|
for (i = 0; i < workstream_array_len; i++) {
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_open_instance("workstream");
|
2010-02-22 15:57:36 +00:00
|
|
|
snwsp = &workstream_array[i];
|
|
|
|
netisr_print_workstream(snwsp);
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_close_instance("workstream");
|
2010-02-22 15:57:36 +00:00
|
|
|
}
|
2015-02-21 23:47:20 +00:00
|
|
|
xo_close_list("workstream");
|
|
|
|
xo_close_container("netisr");
|
2010-02-22 15:57:36 +00:00
|
|
|
}
|