add -c option to list command for compact list, it displays totals rather then

per-CPU stats
This commit is contained in:
jdolecek 2016-10-15 12:06:27 +00:00
parent 10dd1ce273
commit 8804f261c0
2 changed files with 60 additions and 15 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: intrctl.8,v 1.3 2016/10/12 21:47:37 jdolecek Exp $
.\" $NetBSD: intrctl.8,v 1.4 2016/10/15 12:06:27 jdolecek Exp $
.\"
.\" Copyright (c) 2015 Internet Initiative Japan Inc.
.\" All rights reserved.
@ -24,7 +24,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd October 12, 2016
.Dd October 15, 2016
.Dt INTRCTL 8
.Os
.Sh NAME
@ -56,9 +56,14 @@ enable to set an interrupt's affinity to
If
.Ar cpu_index
is already enabled, this command has no effect.
.It list
.It list Op Fl c
for each intrid in the system, display interrupt counts per CPU.
The intrid is an interrupt name such as "ioapic0 pin 22" for x86.
.Pp
If
.Fl c
is specified, display compact list with total counts per interrupt,
and CPU affinity as comma separated list of CPU indexes.
.It nointr Fl c Ar cpu_index
disable to set an interrupt's affinity to
.Ar cpu_index .

View File

@ -1,4 +1,4 @@
/* $NetBSD: intrctl.c,v 1.3 2016/09/19 18:46:39 ryo Exp $ */
/* $NetBSD: intrctl.c,v 1.4 2016/10/15 12:06:27 jdolecek Exp $ */
/*
* Copyright (c) 2015 Internet Initiative Japan Inc.
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: intrctl.c,v 1.3 2016/09/19 18:46:39 ryo Exp $");
__RCSID("$NetBSD: intrctl.c,v 1.4 2016/10/15 12:06:27 jdolecek Exp $");
#include <sys/param.h>
#include <sys/sysctl.h>
@ -99,7 +99,7 @@ usage(void)
{
const char *progname = getprogname();
fprintf(stderr, "usage: %s list\n", progname);
fprintf(stderr, "usage: %s list [-c]\n", progname);
fprintf(stderr, " %s affinity -i interrupt_name -c cpu_index\n", progname);
fprintf(stderr, " %s intr -c cpu_index\n", progname);
fprintf(stderr, " %s nointr -c cpu_index\n", progname);
@ -117,6 +117,18 @@ intrctl_list(int argc, char **argv)
int i, ncpus, *cpucol;
void *handle;
size_t intridlen;
int compact = 0;
char ch;
while ((ch = getopt(argc, argv, "c")) != -1) {
switch (ch) {
case 'c':
compact = 1;
break;
default:
usage();
}
}
handle = intrctl_io_alloc(intrctl_io_alloc_retry_count);
if (handle == NULL)
@ -152,21 +164,49 @@ intrctl_list(int argc, char **argv)
}
/* header */
printf("%-*s ", (int)intridlen, "interrupt id");
for (i = 0; i < ncpus; i++) {
snprintf(buf, sizeof(buf), "CPU%u", i);
printf("%*s ", cpucol[i], buf);
printf("%-*s", (int)intridlen, "interrupt id");
if (compact) {
printf(" %20s ", "total");
printf(" %20s ", "affinity");
} else {
for (i = 0; i < ncpus; i++) {
snprintf(buf, sizeof(buf), "CPU%u", i);
printf("%*s ", cpucol[i], buf);
}
}
printf("device name(s)\n");
/* body */
for (illine = intrctl_io_firstline(handle); illine != NULL;
illine = intrctl_io_nextline(handle, illine)) {
printf("%-*s ", (int)intridlen, illine->ill_intrid);
for (i = 0; i < ncpus; i++) {
struct intrio_list_line_cpu *illc = &illine->ill_cpu[i];
printf("%*" PRIu64 "%c ", cpucol[i], illc->illc_count,
illc->illc_assigned ? '*' : ' ');
struct intrio_list_line_cpu *illc;
printf("%-*s ", (int)intridlen, illine->ill_intrid);
if (compact) {
uint64_t total = 0;
char *affinity, *oaffinity = NULL;
for (i = 0; i < ncpus; i++) {
illc = &illine->ill_cpu[i];
total += illc->illc_count;
if (illc->illc_assigned) {
asprintf(&affinity, "%s%s%d",
oaffinity ? oaffinity : "",
oaffinity ? ", " : "",
i);
if (oaffinity)
free(oaffinity);
oaffinity = affinity;
}
}
printf("%20" PRIu64 " ", total);
printf("%20s ", affinity ? affinity : "none");
free(affinity);
} else {
for (i = 0; i < ncpus; i++) {
illc = &illine->ill_cpu[i];
printf("%*" PRIu64 "%c ", cpucol[i], illc->illc_count,
illc->illc_assigned ? '*' : ' ');
}
}
printf("%s\n", illine->ill_xname);
}