Wed Jan 28 22:37:09 2009 UTC ()
cpuctl list: map hardware id after getting state. avoids screwed up display
when ci_cpuid != cpu_index()


(ad)
diff -r1.12 -r1.13 src/usr.sbin/cpuctl/cpuctl.c

cvs diff -r1.12 -r1.13 src/usr.sbin/cpuctl/cpuctl.c (expand / switch to unified diff)

--- src/usr.sbin/cpuctl/cpuctl.c 2008/11/19 20:56:08 1.12
+++ src/usr.sbin/cpuctl/cpuctl.c 2009/01/28 22:37:09 1.13
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cpuctl.c,v 1.12 2008/11/19 20:56:08 cegger Exp $ */ 1/* $NetBSD: cpuctl.c,v 1.13 2009/01/28 22:37:09 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran. 8 * by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#ifndef lint 32#ifndef lint
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__RCSID("$NetBSD: cpuctl.c,v 1.12 2008/11/19 20:56:08 cegger Exp $"); 34__RCSID("$NetBSD: cpuctl.c,v 1.13 2009/01/28 22:37:09 ad Exp $");
35#endif /* not lint */ 35#endif /* not lint */
36 36
37#include <sys/param.h> 37#include <sys/param.h>
38#include <sys/ioctl.h> 38#include <sys/ioctl.h>
39#include <sys/uio.h> 39#include <sys/uio.h>
40#include <sys/cpuio.h> 40#include <sys/cpuio.h>
41 41
42#include <err.h> 42#include <err.h>
43#include <errno.h> 43#include <errno.h>
44#include <fcntl.h> 44#include <fcntl.h>
45#include <stdio.h> 45#include <stdio.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <stdarg.h> 47#include <stdarg.h>
@@ -197,30 +197,30 @@ cpu_list(char **argv) @@ -197,30 +197,30 @@ cpu_list(char **argv)
197{ 197{
198 const char *state, *intr; 198 const char *state, *intr;
199 cpustate_t cs; 199 cpustate_t cs;
200 u_int cnt, i; 200 u_int cnt, i;
201  201
202 if (ioctl(fd, IOC_CPU_GETCOUNT, &cnt) < 0) 202 if (ioctl(fd, IOC_CPU_GETCOUNT, &cnt) < 0)
203 err(EXIT_FAILURE, "IOC_CPU_GETCOUNT"); 203 err(EXIT_FAILURE, "IOC_CPU_GETCOUNT");
204 204
205 printf("Num HwId Unbound LWPs Interrupts Last change\n"); 205 printf("Num HwId Unbound LWPs Interrupts Last change\n");
206 printf("---- ---- ------------ -------------- ----------------------------\n"); 206 printf("---- ---- ------------ -------------- ----------------------------\n");
207 207
208 for (i = 0; i < cnt; i++) { 208 for (i = 0; i < cnt; i++) {
209 cs.cs_id = i; 209 cs.cs_id = i;
210 if (ioctl(fd, IOC_CPU_MAPID, &cs.cs_id) < 0) 
211 err(EXIT_FAILURE, "IOC_CPU_MAPID"); 
212 if (ioctl(fd, IOC_CPU_GETSTATE, &cs) < 0) 210 if (ioctl(fd, IOC_CPU_GETSTATE, &cs) < 0)
213 err(EXIT_FAILURE, "IOC_CPU_GETINFO"); 211 err(EXIT_FAILURE, "IOC_CPU_GETINFO");
 212 if (ioctl(fd, IOC_CPU_MAPID, &cs.cs_id) < 0)
 213 err(EXIT_FAILURE, "IOC_CPU_MAPID");
214 if (cs.cs_online) 214 if (cs.cs_online)
215 state = "online"; 215 state = "online";
216 else 216 else
217 state = "offline"; 217 state = "offline";
218 if (cs.cs_intr) 218 if (cs.cs_intr)
219 intr = "intr"; 219 intr = "intr";
220 else 220 else
221 intr = "nointr"; 221 intr = "nointr";
222 printf("%-4d %-4x %-12s %-12s %s", i, cs.cs_id, state, 222 printf("%-4d %-4x %-12s %-12s %s", i, cs.cs_id, state,
223 intr, asctime(localtime(&cs.cs_lastmod))); 223 intr, asctime(localtime(&cs.cs_lastmod)));
224 } 224 }
225} 225}
226 226