| @@ -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 | |
97 | static void | | 97 | static void |
98 | usage(void) | | 98 | usage(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 | |
110 | static int intrctl_io_alloc_retry_count = 4; | | 110 | static int intrctl_io_alloc_retry_count = 4; |
111 | | | 111 | |
112 | static void | | 112 | static void |
113 | intrctl_list(int argc, char **argv) | | 113 | intrctl_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 | |
178 | static void | | 218 | static void |
179 | intrctl_affinity(int argc, char **argv) | | 219 | intrctl_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; |