Sat Oct 15 12:06:27 2016 UTC ()
add -c option to list command for compact list, it displays totals rather then
per-CPU stats


(jdolecek)
diff -r1.3 -r1.4 src/usr.sbin/intrctl/intrctl.8
diff -r1.3 -r1.4 src/usr.sbin/intrctl/intrctl.c

cvs diff -r1.3 -r1.4 src/usr.sbin/intrctl/intrctl.8 (expand / switch to unified diff)

--- src/usr.sbin/intrctl/intrctl.8 2016/10/12 21:47:37 1.3
+++ src/usr.sbin/intrctl/intrctl.8 2016/10/15 12:06:27 1.4
@@ -1,40 +1,40 @@ @@ -1,40 +1,40 @@
1.\" $NetBSD: intrctl.8,v 1.3 2016/10/12 21:47:37 jdolecek Exp $ 1.\" $NetBSD: intrctl.8,v 1.4 2016/10/15 12:06:27 jdolecek Exp $
2.\" 2.\"
3.\" Copyright (c) 2015 Internet Initiative Japan Inc. 3.\" Copyright (c) 2015 Internet Initiative Japan Inc.
4.\" All rights reserved. 4.\" All rights reserved.
5.\" 5.\"
6.\" Redistribution and use in source and binary forms, with or without 6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions 7.\" modification, are permitted provided that the following conditions
8.\" are met: 8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright 9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer. 10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the 12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution. 13.\" documentation and/or other materials provided with the distribution.
14.\" 14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 15.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 16.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 18.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25.\" POSSIBILITY OF SUCH DAMAGE. 25.\" POSSIBILITY OF SUCH DAMAGE.
26.\" 26.\"
27.Dd October 12, 2016 27.Dd October 15, 2016
28.Dt INTRCTL 8 28.Dt INTRCTL 8
29.Os 29.Os
30.Sh NAME 30.Sh NAME
31.Nm intrctl 31.Nm intrctl
32.Nd program to control interrupts 32.Nd program to control interrupts
33.Sh SYNOPSIS 33.Sh SYNOPSIS
34.Nm intrctl 34.Nm intrctl
35.Ar command 35.Ar command
36.Op Ar options 36.Op Ar options
37.Sh DESCRIPTION 37.Sh DESCRIPTION
38The 38The
39.Nm 39.Nm
40command can be used to control and inspect the state of interrupts 40command can be used to control and inspect the state of interrupts
@@ -46,29 +46,34 @@ specifies the action to take. @@ -46,29 +46,34 @@ specifies the action to take.
46Valid commands are: 46Valid commands are:
47.Bl -tag -width XofflineXcpunoX 47.Bl -tag -width XofflineXcpunoX
48.It affinity Fl c Ar cpu_index Fl i Ar intrid 48.It affinity Fl c Ar cpu_index Fl i Ar intrid
49set an 49set an
50.Ar intrid 50.Ar intrid
51interrupt's affinity to 51interrupt's affinity to
52.Ar cpu_index . 52.Ar cpu_index .
53.It intr Fl c Ar cpu_index 53.It intr Fl c Ar cpu_index
54enable to set an interrupt's affinity to 54enable to set an interrupt's affinity to
55.Ar cpu_index . 55.Ar cpu_index .
56If 56If
57.Ar cpu_index 57.Ar cpu_index
58is already enabled, this command has no effect. 58is already enabled, this command has no effect.
59.It list 59.It list Op Fl c
60for each intrid in the system, display interrupt counts per CPU. 60for each intrid in the system, display interrupt counts per CPU.
61The intrid is an interrupt name such as "ioapic0 pin 22" for x86. 61The intrid is an interrupt name such as "ioapic0 pin 22" for x86.
 62.Pp
 63If
 64.Fl c
 65is specified, display compact list with total counts per interrupt,
 66and CPU affinity as comma separated list of CPU indexes.
62.It nointr Fl c Ar cpu_index 67.It nointr Fl c Ar cpu_index
63disable to set an interrupt's affinity to 68disable to set an interrupt's affinity to
64.Ar cpu_index . 69.Ar cpu_index .
65If 70If
66.Ar cpu_index 71.Ar cpu_index
67is already disabled, this command has no effect. 72is already disabled, this command has no effect.
68.El 73.El
69.Sh SEE ALSO 74.Sh SEE ALSO
70.Xr cpuctl 8 75.Xr cpuctl 8
71.Sh HISTORY 76.Sh HISTORY
72.Nm 77.Nm
73first appeared in 78first appeared in
74.Nx 8.0 . 79.Nx 8.0 .

cvs diff -r1.3 -r1.4 src/usr.sbin/intrctl/intrctl.c (expand / switch to unified diff)

--- src/usr.sbin/intrctl/intrctl.c 2016/09/19 18:46:39 1.3
+++ src/usr.sbin/intrctl/intrctl.c 2016/10/15 12:06:27 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: intrctl.c,v 1.3 2016/09/19 18:46:39 ryo Exp $ */ 1/* $NetBSD: intrctl.c,v 1.4 2016/10/15 12:06:27 jdolecek Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2015 Internet Initiative Japan Inc. 4 * Copyright (c) 2015 Internet Initiative Japan Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__RCSID("$NetBSD: intrctl.c,v 1.3 2016/09/19 18:46:39 ryo Exp $"); 30__RCSID("$NetBSD: intrctl.c,v 1.4 2016/10/15 12:06:27 jdolecek Exp $");
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/sysctl.h> 33#include <sys/sysctl.h>
34#include <sys/intrio.h> 34#include <sys/intrio.h>
35#include <sys/types.h> 35#include <sys/types.h>
36 36
37#include <err.h> 37#include <err.h>
38#include <errno.h> 38#include <errno.h>
39#include <fcntl.h> 39#include <fcntl.h>
40#include <limits.h> 40#include <limits.h>
41#include <paths.h> 41#include <paths.h>
42#include <sched.h> 42#include <sched.h>
43#include <stdint.h> 43#include <stdint.h>
@@ -89,44 +89,56 @@ main(int argc, char **argv) @@ -89,44 +89,56 @@ main(int argc, char **argv)
89 if (ct->label == NULL) 89 if (ct->label == NULL)
90 errx(EXIT_FAILURE, "unknown command ``%s''", cmdname); 90 errx(EXIT_FAILURE, "unknown command ``%s''", cmdname);
91 91
92 (*ct->func)(argc, argv); 92 (*ct->func)(argc, argv);
93 exit(EXIT_SUCCESS); 93 exit(EXIT_SUCCESS);
94 /* NOTREACHED */ 94 /* NOTREACHED */
95} 95}
96 96
97static void 97static void
98usage(void) 98usage(void)
99{ 99{
100 const char *progname = getprogname(); 100 const char *progname = getprogname();
101 101
102 fprintf(stderr, "usage: %s list\n", progname); 102 fprintf(stderr, "usage: %s list [-c]\n", progname);
103 fprintf(stderr, " %s affinity -i interrupt_name -c cpu_index\n", progname); 103 fprintf(stderr, " %s affinity -i interrupt_name -c cpu_index\n", progname);
104 fprintf(stderr, " %s intr -c cpu_index\n", progname); 104 fprintf(stderr, " %s intr -c cpu_index\n", progname);
105 fprintf(stderr, " %s nointr -c cpu_index\n", progname); 105 fprintf(stderr, " %s nointr -c cpu_index\n", progname);
106 exit(EXIT_FAILURE); 106 exit(EXIT_FAILURE);
107 /* NOTREACHED */ 107 /* NOTREACHED */
108} 108}
109 109
110static int intrctl_io_alloc_retry_count = 4; 110static int intrctl_io_alloc_retry_count = 4;
111 111
112static void 112static void
113intrctl_list(int argc, char **argv) 113intrctl_list(int argc, char **argv)
114{ 114{
115 char buf[64]; 115 char buf[64];
116 struct intrio_list_line *illine; 116 struct intrio_list_line *illine;
117 int i, ncpus, *cpucol; 117 int i, ncpus, *cpucol;
118 void *handle; 118 void *handle;
119 size_t intridlen; 119 size_t intridlen;
 120 int compact = 0;
 121 char ch;
 122
 123 while ((ch = getopt(argc, argv, "c")) != -1) {
 124 switch (ch) {
 125 case 'c':
 126 compact = 1;
 127 break;
 128 default:
 129 usage();
 130 }
 131 }
120 132
121 handle = intrctl_io_alloc(intrctl_io_alloc_retry_count); 133 handle = intrctl_io_alloc(intrctl_io_alloc_retry_count);
122 if (handle == NULL) 134 if (handle == NULL)
123 err(EXIT_FAILURE, "intrctl_io_alloc"); 135 err(EXIT_FAILURE, "intrctl_io_alloc");
124 136
125 /* calc columns */ 137 /* calc columns */
126 ncpus = intrctl_io_ncpus(handle); 138 ncpus = intrctl_io_ncpus(handle);
127 intridlen = strlen("interrupt id"); 139 intridlen = strlen("interrupt id");
128 for (illine = intrctl_io_firstline(handle); illine != NULL; 140 for (illine = intrctl_io_firstline(handle); illine != NULL;
129 illine = intrctl_io_nextline(handle, illine)) { 141 illine = intrctl_io_nextline(handle, illine)) {
130 size_t len = strlen(illine->ill_intrid); 142 size_t len = strlen(illine->ill_intrid);
131 if (intridlen < len) 143 if (intridlen < len)
132 intridlen = len; 144 intridlen = len;
@@ -142,41 +154,69 @@ intrctl_list(int argc, char **argv) @@ -142,41 +154,69 @@ intrctl_list(int argc, char **argv)
142 for (illine = intrctl_io_firstline(handle); illine != NULL; 154 for (illine = intrctl_io_firstline(handle); illine != NULL;
143 illine = intrctl_io_nextline(handle, illine)) { 155 illine = intrctl_io_nextline(handle, illine)) {
144 for (i = 0; i < ncpus; i++) { 156 for (i = 0; i < ncpus; i++) {
145 int len; 157 int len;
146 snprintf(buf, sizeof(buf), "%" PRIu64, 158 snprintf(buf, sizeof(buf), "%" PRIu64,
147 illine->ill_cpu[i].illc_count); 159 illine->ill_cpu[i].illc_count);
148 len = (int)strlen(buf); 160 len = (int)strlen(buf);
149 if (cpucol[i] < len) 161 if (cpucol[i] < len)
150 cpucol[i] = len; 162 cpucol[i] = len;
151 } 163 }
152 } 164 }
153 165
154 /* header */ 166 /* header */
155 printf("%-*s ", (int)intridlen, "interrupt id"); 167 printf("%-*s", (int)intridlen, "interrupt id");
156 for (i = 0; i < ncpus; i++) { 168 if (compact) {
157 snprintf(buf, sizeof(buf), "CPU%u", i); 169 printf(" %20s ", "total");
158 printf("%*s ", cpucol[i], buf); 170 printf(" %20s ", "affinity");
 171 } else {
 172 for (i = 0; i < ncpus; i++) {
 173 snprintf(buf, sizeof(buf), "CPU%u", i);
 174 printf("%*s ", cpucol[i], buf);
 175 }
159 } 176 }
160 printf("device name(s)\n"); 177 printf("device name(s)\n");
161 178
162 /* body */ 179 /* body */
163 for (illine = intrctl_io_firstline(handle); illine != NULL; 180 for (illine = intrctl_io_firstline(handle); illine != NULL;
164 illine = intrctl_io_nextline(handle, illine)) { 181 illine = intrctl_io_nextline(handle, illine)) {
165 printf("%-*s ", (int)intridlen, illine->ill_intrid); 182 struct intrio_list_line_cpu *illc;
166 for (i = 0; i < ncpus; i++) { 183
167 struct intrio_list_line_cpu *illc = &illine->ill_cpu[i]; 184 printf("%-*s ", (int)intridlen, illine->ill_intrid);
168 printf("%*" PRIu64 "%c ", cpucol[i], illc->illc_count, 185 if (compact) {
169 illc->illc_assigned ? '*' : ' '); 186 uint64_t total = 0;
 187 char *affinity, *oaffinity = NULL;
 188 for (i = 0; i < ncpus; i++) {
 189 illc = &illine->ill_cpu[i];
 190 total += illc->illc_count;
 191 if (illc->illc_assigned) {
 192 asprintf(&affinity, "%s%s%d",
 193 oaffinity ? oaffinity : "",
 194 oaffinity ? ", " : "",
 195 i);
 196 if (oaffinity)
 197 free(oaffinity);
 198 oaffinity = affinity;
 199 }
 200 }
 201 printf("%20" PRIu64 " ", total);
 202 printf("%20s ", affinity ? affinity : "none");
 203 free(affinity);
 204 } else {
 205 for (i = 0; i < ncpus; i++) {
 206 illc = &illine->ill_cpu[i];
 207 printf("%*" PRIu64 "%c ", cpucol[i], illc->illc_count,
 208 illc->illc_assigned ? '*' : ' ');
 209 }
170 } 210 }
171 printf("%s\n", illine->ill_xname); 211 printf("%s\n", illine->ill_xname);
172 } 212 }
173 213
174 free(cpucol); 214 free(cpucol);
175 intrctl_io_free(handle); 215 intrctl_io_free(handle);
176} 216}
177 217
178static void 218static void
179intrctl_affinity(int argc, char **argv) 219intrctl_affinity(int argc, char **argv)
180{ 220{
181 struct intrio_set iset; 221 struct intrio_set iset;
182 cpuset_t *cpuset; 222 cpuset_t *cpuset;