author | Albert Lee <trisk@forkgnu.org> |
Tue, 01 Feb 2011 16:10:01 -0500 | |
changeset 4 | a42e422f55c0 |
parent 3 | 380ada8fd621 |
permissions | -rw-r--r-- |
3 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
5 |
* Common Development and Distribution License (the "License"). |
|
6 |
* You may not use this file except in compliance with the License. |
|
7 |
* |
|
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
||
22 |
/* |
|
23 |
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
|
24 |
*/ |
|
25 |
||
26 |
#include <stdio.h> |
|
27 |
#include <errno.h> |
|
28 |
#include <unistd.h> |
|
29 |
#include <stdlib.h> |
|
30 |
#include <limits.h> |
|
31 |
#include <string.h> |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
32 |
#include <getopt.h> |
3 | 33 |
#include <libgen.h> |
34 |
#include <syslog.h> |
|
35 |
#include <kstat.h> |
|
36 |
#include <sys/processor.h> |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
37 |
#include <sys/modhash.h> |
3 | 38 |
|
39 |
#include "intrs.h" |
|
40 |
||
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
41 |
/* Interrupt vector info */ |
3 | 42 |
typedef struct ivec { |
43 |
int cookie; |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
44 |
uint64_t time; |
3 | 45 |
hrtime_t crtime; |
46 |
int pil; |
|
47 |
int ino; |
|
48 |
int ihs; |
|
49 |
int num_ino; |
|
50 |
int origcpu; |
|
51 |
int nowcpu; |
|
52 |
int inum; |
|
53 |
} ivec_t; |
|
54 |
||
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
55 |
uu_list_pool_t *ivec_pool; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
56 |
|
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
57 |
/* MSI device info */ |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
58 |
typedef struct msi_dev { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
59 |
msi_dev_t *next; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
60 |
char *devpath[MAXPATHLEN]; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
61 |
int num_intr; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
62 |
*ivec_t ivecs; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
63 |
} msi_dev_t; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
64 |
|
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
65 |
uu_list_pool_t *msi_dev_pool; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
66 |
|
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
67 |
/* Bus info */ |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
68 |
typedef struct bus_dev { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
69 |
bus_dev_t *next; |
3 | 70 |
char *buspath[MAXPATHLEN]; |
71 |
int num_intr; |
|
72 |
ivec_t *ivecs; |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
73 |
int is_pcplusmp; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
74 |
msi_dev_t *msi_head; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
75 |
} bus_dev_t; |
3 | 76 |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
77 |
uu_list_pool_t *bus_dev_pool; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
78 |
|
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
79 |
/* Per-CPU statistics */ |
3 | 80 |
typedef struct cpu_stat { |
81 |
int state; |
|
82 |
uint64_t tot; |
|
83 |
hrtime_t crtime; |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
84 |
bus_dev_t *bus_head; |
3 | 85 |
} cpu_stat_t; |
86 |
||
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
87 |
uu_list_pool_t *cpu_stat_pool; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
88 |
|
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
89 |
/* Interrupt statistics */ |
3 | 90 |
type def struct intr_stat { |
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
91 |
hrtime_t snaptime; |
3 | 92 |
*cpu_stat_t *cpus; |
93 |
} intr_stat_t; |
|
94 |
||
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
95 |
uu_list_pool_t *intr_stat_pool; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
96 |
|
3 | 97 |
typedef enum sleeptime { |
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
98 |
NORMAL_SLEEPTIME = 10, /* time to sleep between samples */ |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
99 |
IDLE_SLEEPTIME = 45, /* time to sleep when idle */ |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
100 |
ONECPU_SLEEPTIME = 60 * 15, /* used if only 1 CPU on system */ |
3 | 101 |
} sleeptime_t; |
102 |
||
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
103 |
int using_scengen; /* 1 if using scenario simulator */ |
3 | 104 |
int debug; |
105 |
int foreground; |
|
106 |
||
107 |
int max_cpus; |
|
108 |
||
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
109 |
sleeptime_t sleeptime = NORMAL_SLEEPTIME; |
3 | 110 |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
111 |
float idle_intrload = 0.1; /* idle if interrupt load < 10% */ |
3 | 112 |
|
113 |
float timerange_toohi = 0.1; |
|
114 |
int statslen = 60; /* time period (in secs) to keep in @deltas */ |
|
115 |
||
116 |
int main(int argc, char **argv) |
|
117 |
{ |
|
118 |
const char *cmdname; |
|
119 |
kstat_ctl_t *kc; |
|
120 |
kstat_t *ksp; |
|
121 |
intr_stat_t stat; |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
122 |
char c; |
3 | 123 |
|
124 |
max_cpus = sysconf(_SC_CPUID_MAX) + 1; |
|
125 |
||
126 |
cmdname = basename(argv[0]); |
|
127 |
/* |
|
128 |
* Parse arguments. intrd does not accept any public arguments; the two |
|
129 |
* arguments below are meant for testing purposes. -D generates a significant |
|
130 |
* amount of syslog output. -S <filename> loads the filename as a perl |
|
131 |
* script. That file is expected to implement a kstat "simulator" which |
|
132 |
* can be used to feed information to intrd and verify intrd's responses. |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
133 |
*/ |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
134 |
while ((c = getopt(argc, argv, "S:Df")) != EOF) { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
135 |
switch (c) { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
136 |
case 'S': |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
137 |
using_scengen = 1; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
138 |
foreground = 1; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
139 |
load_simulator(optarg); |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
140 |
break; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
141 |
case 'D': |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
142 |
debug = 1; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
143 |
break; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
144 |
case 'f': |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
145 |
foreground = 1; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
146 |
break; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
147 |
default: |
3 | 148 |
} |
149 |
} |
|
150 |
||
151 |
if (!foreground) { |
|
152 |
if (daemon(0, 0) == -1) { |
|
153 |
return 1; |
|
154 |
} |
|
155 |
} |
|
156 |
||
157 |
if (!using_scengen) { |
|
158 |
openlog(cmdname, LOG_PID, LOG_DAEMON); |
|
159 |
(void) setlogmask(LOG_UPTO(debug ? LOG_DEBUG : LOG_INFO)); |
|
160 |
} |
|
161 |
||
162 |
if (!using_scengen) { |
|
163 |
kc = kstat_open(); |
|
164 |
if (kc == NULL) { |
|
165 |
return 1; |
|
166 |
} |
|
167 |
} else { |
|
168 |
/* scengen not implemented */ |
|
169 |
return 1; |
|
170 |
} |
|
171 |
||
172 |
/* |
|
173 |
* If no pci_intrs kstats were found, we need to exit, but we can't because |
|
174 |
* SMF will restart us and/or report an error to the administrator. But |
|
175 |
* there's nothing an administrator can do. So print out a message to syslog |
|
176 |
* and silently pause forever. |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
177 |
*/ |
3 | 178 |
for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) { |
179 |
if ((ksp->ks_type == KSTAT_TYPE_NAMED) && |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
180 |
(strcmp(ksp->ks_module, "pci_intrs") == 0)) { |
3 | 181 |
break; |
182 |
} |
|
183 |
} |
|
184 |
if (ksp == NULL) { |
|
185 |
kstat_close(kc); |
|
186 |
syslog(LOG_INFO, "no interrupts were found: " \ |
|
187 |
"your I/O bus may not yet be supported\n"); |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
188 |
do {} while (sleep(ONECPU_SLEEPTIME) == 0); |
3 | 189 |
return 0; |
190 |
} |
|
191 |
||
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
192 |
stat.cpus = malloc(sizeof (cpu_stat_t) * max_cpus); |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
193 |
if (stat.cpus == NULL) { |
3 | 194 |
return 1; |
195 |
} |
|
196 |
} |
|
197 |
||
198 |
||
199 |
static int verify(int condition, const char *msg) |
|
200 |
{ |
|
201 |
int bad = !condition; |
|
202 |
if (bad) { |
|
203 |
syslog(LOG_DEBUG, "VERIFY: %s", msg); |
|
204 |
} |
|
205 |
return bad; |
|
206 |
} |
|
207 |
||
208 |
static void load_simulator(const char *file) |
|
209 |
{ |
|
210 |
} |
|
211 |
||
212 |
static int getstat($$); |
|
213 |
/* |
|
214 |
int generate_delta($$); |
|
215 |
int compress_deltas($); |
|
216 |
int dumpdelta($); |
|
217 |
||
218 |
int goodness($); |
|
219 |
int imbalanced($$); |
|
220 |
int do_reconfig($); |
|
221 |
||
222 |
int goodness_cpu($$); # private function |
|
223 |
int move_intr($$$$); # private function |
|
224 |
int ivecs_to_string(@); # private function |
|
225 |
int do_find_goal($$$$); # private function |
|
226 |
int find_goal($$); # private function |
|
227 |
int do_reconfig_cpu2cpu($$$$); # private function |
|
228 |
int do_reconfig_cpu($$$); |
|
229 |
*/ |
|
230 |
||
231 |
||
232 |
/* |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
233 |
* |
3 | 234 |
* What follow are the basic data structures routines of intrd. |
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
235 |
* |
3 | 236 |
* getstat() is responsible for reading the kstats and generating a "stat" hash. |
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
237 |
* |
3 | 238 |
* generate_delta() is responsible for taking two "stat" hashes and creating |
239 |
* a new "delta" hash that represents what has changed over time. |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
240 |
* |
3 | 241 |
* compress_deltas() is responsible for taking a list of deltas and generating |
242 |
* a single delta hash that encompasses all the time periods described by the |
|
243 |
* deltas. |
|
244 |
*/ |
|
245 |
||
246 |
||
247 |
/* |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
248 |
* |
3 | 249 |
* getstat() is handed a reference to a kstat and generates a hash, returned |
250 |
* by reference, containing all the fields from the kstats which we need. |
|
251 |
* If it returns the scalar 0, it failed to gather the kstats, and the caller |
|
252 |
* should react accordingly. |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
253 |
* |
3 | 254 |
* getstat() is also responsible for maintaining a reasonable $sleeptime. |
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
255 |
* |
3 | 256 |
* {"snaptime"} kstat's snaptime |
257 |
* {<cpuid>} one hash reference per online cpu |
|
258 |
* ->{"tot"} == cpu:<cpuid>:sys:cpu_nsec_{user + kernel + idle} |
|
259 |
* ->{"crtime"} == cpu:<cpuid>:sys:crtime |
|
260 |
* ->{"ivecs"} |
|
261 |
* ->{<cookie#>} iterates over pci_intrs::<nexus>:cookie |
|
262 |
* ->{"time"} == pci_intrs:<ivec#>:<nexus>:time (in nsec) |
|
263 |
* ->{"pil"} == pci_intrs:<ivec#>:<nexus>:pil |
|
264 |
* ->{"crtime"} == pci_intrs:<ivec#>:<nexus>:crtime |
|
265 |
* ->{"ino"} == pci_intrs:<ivec#>:<nexus>:ino |
|
266 |
* ->{"num_ino"} == num inos of single device instance sharing this entry |
|
267 |
* Will be > 1 on pcplusmp X86 systems for devices |
|
268 |
* with multiple MSI interrupts. |
|
269 |
* ->{"buspath"} == pci_intrs:<ivec#>:<nexus>:buspath |
|
270 |
* ->{"name"} == pci_intrs:<ivec#>:<nexus>:name |
|
271 |
* ->{"ihs"} == pci_intrs:<ivec#>:<nexus>:ihs |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
272 |
* |
3 | 273 |
*/ |
274 |
||
275 |
int getstat(kstat_ctl_t *kc, intr_stat_t *stat) |
|
276 |
{ |
|
277 |
int cpucnt = 0; |
|
278 |
kstat_t *ksp; |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
279 |
hrtime_t minsnap, maxsnap; |
3 | 280 |
|
281 |
/* Hash of hash which matches (MSI device, ino) combos to kstats. */ |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
282 |
msi_dev_t *msidevs; |
3 | 283 |
|
284 |
/* |
|
285 |
* kstats are not generated atomically. Each kstat hierarchy will |
|
286 |
* have been generated within the kernel at a different time. On a |
|
287 |
* thrashing system, we may not run quickly enough in order to get |
|
288 |
* coherent kstat timing information across all the kstats. To |
|
289 |
* determine if this is occurring, $minsnap/$maxsnap are used to |
|
290 |
* find the breadth between the first and last snaptime of all the |
|
291 |
* kstats we access. $maxsnap - $minsnap roughly represents the |
|
292 |
* total time taken up in getstat(). If this time approaches the |
|
293 |
* time between snapshots, our results may not be useful. |
|
294 |
*/ |
|
295 |
||
296 |
minsnap = -1; /* snaptime is always a positive number */ |
|
297 |
maxsnap = minsnap; |
|
298 |
||
299 |
/* |
|
300 |
* iterate over the cpus in cpu:<cpuid>::. check |
|
301 |
* cpu_info:<cpuid>:cpu_info<cpuid>:state to make sure the |
|
302 |
* processor is "on-line". if not, it isn't accepting interrupts |
|
303 |
* and doesn't concern us. |
|
304 |
* |
|
305 |
* record cpu:<cpuid>:sys:snaptime, and check $minsnap/$maxsnap. |
|
306 |
*/ |
|
307 |
||
308 |
cpu_stats = stat->cpus; |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
309 |
bzero(cpu_stats, sizeof (cpu_stat_t) * max_cpus); |
3 | 310 |
|
311 |
for (ksp = kc->kc_chain; ksp != null; ksp = ksp->ks_next) { |
|
312 |
kstat_t *ksp_sys; |
|
313 |
kstat_named_t *knp; |
|
314 |
int cpu; |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
315 |
hrtime_t snaptime; |
3 | 316 |
|
317 |
if ((ksp->ks_type != kstat_type_named) || |
|
318 |
strcmp(ksp->ks_module, "cpu_info") || |
|
319 |
(kstat_read(kc, ksp) == -1)) { |
|
320 |
continue; |
|
321 |
} |
|
322 |
knp = kstat_data_lookup(ksp, "state"); |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
323 |
if ((knp == NULL) || strcmp(knp->name, PS_ONLINE) || |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
324 |
((cpu = ksp->ks_instance) >= max_cpus)) { |
3 | 325 |
continue; |
326 |
} |
|
327 |
ksp_sys = kstat_lookup(kc, "cpu", cpu, "sys"); |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
328 |
if ((ksp_sys == NULL) || (kstat_read(kc, ksp_sys) == -1)) { |
3 | 329 |
continue; |
330 |
} |
|
331 |
cpu_stats[cpu].state = P_ONLINE; |
|
332 |
knp = ksp_sys->ks_data; |
|
333 |
for (i = 0; i < ksp_sys->ks_ndata; i++) { |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
334 |
if ((strcmp(knp[i].name, "cpu_nsec_idle") == 0) || |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
335 |
(strcmp(knp[i].name, "cpu_nsec_user") == 0) || |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
336 |
(strcmp(knp[i].name, "cpu_nsec_kernel") == 0)) { |
3 | 337 |
cpu_stats[cpu].tot += knp[i].value.ui64; |
338 |
} |
|
339 |
cpu_stats[cpu].crtime = ksp_sys->crtime; |
|
340 |
snaptime = ksp_sys->snaptime; |
|
341 |
if (minsnap == -1 || snaptime < minsnap) { |
|
342 |
minsnap = snaptime; |
|
343 |
} |
|
344 |
if (snaptime > maxsnap) { |
|
345 |
maxsnap = snaptime; |
|
346 |
} |
|
347 |
cpucnt++; |
|
348 |
||
349 |
} |
|
350 |
||
351 |
if (cpucnt <= 1) { |
|
352 |
sleeptime = ONECPU_SLEEPTIME; |
|
353 |
return 0; /* nothing to do with 1 CPU */ |
|
354 |
} |
|
355 |
||
356 |
/* |
|
357 |
* Iterate over the ivecs. If the cpu is not on-line, ignore the |
|
358 |
* ivecs mapped to it, if any. |
|
359 |
* |
|
360 |
* Record pci_intrs:{inum}:<nexus>:time, snaptime, crtime, pil, |
|
361 |
* ino, name, and buspath. Check $minsnap/$maxsnap. |
|
362 |
*/ |
|
363 |
||
364 |
for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) { |
|
365 |
kstat_named_t *knp; |
|
366 |
int cpu; |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
367 |
int ino; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
368 |
cpu_stat_t *cpup; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
369 |
bus_dev_t *busp; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
370 |
bus_dev_t *bus_last; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
371 |
ivec_t *ivecp; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
372 |
hrtime_t snaptime; |
3 | 373 |
|
374 |
if ((ksp->ks_type != KSTAT_TYPE_NAMED) || |
|
375 |
strcmp(ksp->ks_module, "pci_intrs") || |
|
376 |
(kstat_read(kc, ksp) == -1)) { |
|
377 |
continue; |
|
378 |
} |
|
379 |
knp = kstat_data_lookup(ksp, "cpu"); |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
380 |
if ((knp == NULL) || ((cpu = knp->value.ui32) >= max_cpus) || |
3 | 381 |
(cpu_stats[cpu].state != P_ONLINE)) { |
382 |
continue; |
|
383 |
} |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
384 |
cpup = &cpu_stats[cpu]; |
3 | 385 |
knp = kstat_data_lookup(ksp, "type"); |
386 |
if ((knp == NULL) || strcmp(knp->value.c, "disabled")) { |
|
387 |
continue; |
|
388 |
} |
|
389 |
knp = kstat_data_lookup(ksp, "buspath"); |
|
390 |
if (knp == NULL) { |
|
391 |
continue; |
|
392 |
} |
|
4
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
393 |
|
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
394 |
for (bus_last = NULL, busp = cpup->bus_head; busp != NULL; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
395 |
bus_last = busp, busp = busp->next) { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
396 |
if (strcmp(knp->value.c, busp->buspath) == 0) { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
397 |
break; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
398 |
} |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
399 |
} |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
400 |
|
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
401 |
if (busp == NULL) { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
402 |
busp = malloc(sizeof (bus_dev_t)); |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
403 |
if (busp == NULL) { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
404 |
return -1; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
405 |
} |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
406 |
|
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
407 |
busp->next = NULL; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
408 |
|
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
409 |
strlcpy(busp->buspath, knp->value.c, MAXPATHLEN); |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
410 |
busp->is_pcplusmp = |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
411 |
intrinfo(busp->buspath, &(busp->num_intr)); |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
412 |
|
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
413 |
busp->ivecs = malloc(sizeof (ivec_t) * busp->num_intr); |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
414 |
if (busp->ivecs == NULL) { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
415 |
free(busp); |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
416 |
return -1; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
417 |
} |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
418 |
bzero(busp->ivecs, sizeof (ivec_t) * busp->num_intr); |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
419 |
|
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
420 |
if (bus_last == NULL) { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
421 |
cpup->bus_head = busp; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
422 |
} else { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
423 |
bus_last->next = busp; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
424 |
} |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
425 |
} |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
426 |
knp = kstat_data_lookup(ksp, "ino"); |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
427 |
if ((knp == NULL) || |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
428 |
((ino = knp->value.ui32) >= busp->num_intr)) { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
429 |
continue; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
430 |
} |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
431 |
ivecp = &(busp->ivecs[ino]); |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
432 |
|
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
433 |
knp = kstat_data_lookup(ksp, "time"); |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
434 |
if (knp == NULL) { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
435 |
continue; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
436 |
} |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
437 |
ivecp->time = knp->value.ui64; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
438 |
|
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
439 |
if (busp->is_pcplusmp) { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
440 |
knp = kstat_data_lookup(ksp, "type"); |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
441 |
if (knp == NULL) { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
442 |
continue; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
443 |
} |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
444 |
if (strcmp(knp->value.c, "msi") == 0) { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
445 |
for (msi_last = NULL, msip = busp->msi_head; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
446 |
msip != NULL; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
447 |
msi_last = msip, msip = msip->next) { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
448 |
if (ivecp->cookie == msip->cookie) { |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
449 |
break; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
450 |
} |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
451 |
} |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
452 |
|
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
453 |
} |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
454 |
|
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
455 |
ivecp->num_ino = 1; |
a42e422f55c0
More WIP, need to convert to uu_list.
Albert Lee <trisk@forkgnu.org>
parents:
3
diff
changeset
|
456 |
ivecp->crtime = ksp->crtime; |
3 | 457 |
snaptime = ksp->snaptime; |
458 |
if (minsnap == -1 || snaptime < minsnap) { |
|
459 |
minsnap = snaptime; |
|
460 |
} |
|
461 |
if (snaptime > maxsnap) { |
|
462 |
maxsnap = snaptime; |
|
463 |
} |
|
464 |
} |
|
465 |
||
466 |
/* |
|
467 |
* All MSI interrupts of a device instance share a single MSI address. |
|
468 |
* On X86 systems with an APIC, this MSI address is interpreted as CPU |
|
469 |
* routing info by the APIC. For this reason, on these platforms, all |
|
470 |
* interrupts for MSI devices must be moved to the same CPU at the same |
|
471 |
* time. |
|
472 |
* |
|
473 |
* Since all interrupts will be on the same CPU on these platforms, all |
|
474 |
* interrupts can be consolidated into one ivec entry. For such devices, |
|
475 |
* num_ino will be > 1 to denote that a group move is needed. |
|
476 |
*/ |
|
477 |
||
478 |
/* |
|
479 |
* Loop thru all MSI devices on X86 pcplusmp systems. |
|
480 |
* Nop on other systems. |
|
481 |
*/ |
|
482 |
||
483 |
||
484 |
/* |
|
485 |
* We define the timerange as the amount of time spent gathering the |
|
486 |
* various kstats, divided by our sleeptime. If we take a lot of time |
|
487 |
* to access the kstats, and then we create a delta comparing these |
|
488 |
* kstats with a prior set of kstats, that delta will cover |
|
489 |
* substaintially different amount of time depending upon which |
|
490 |
* interrupt or CPU is being examined. |
|
491 |
* |
|
492 |
* By checking the timerange here, we guarantee that any deltas |
|
493 |
* created from these kstats will contain self-consistent data, |
|
494 |
* in that all CPUs and interrupts cover a similar span of time. |
|
495 |
* |
|
496 |
* $timerange_toohi is the upper bound. Any timerange above |
|
497 |
* this is thrown out as garbage. If the stat is safely within this |
|
498 |
* bound, we treat the stat as representing an instant in time, rather |
|
499 |
* than the time range it actually spans. We arbitrarily choose minsnap |
|
500 |
* as the snaptime of the stat. |
|
501 |
*/ |
|
502 |
||
503 |
stat->snaptime = minsnap; |
|
504 |
if (((maxsnap - minsnap) / sleeptime) > timerange_toohi) { |
|
505 |
return 0; |
|
506 |
} |
|
507 |
return 1; |
|
508 |
} |
|
509 |