ia64/xen-unstable

view tools/misc/xenpm.c @ 18599:10dec51bfa81

xenpm: Fix typo bug.

From: Guanqun Lu <guanqun.lu@intel.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Oct 09 10:16:49 2008 +0100 (2008-10-09)
parents 7592da5118ec
children bf78a531eb66
line source
1 /*
2 * xenpm.c: list the power information of the available processors
3 * Copyright (c) 2008, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16 * Place - Suite 330, Boston, MA 02111-1307 USA.
17 */
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <getopt.h>
22 #include <errno.h>
24 #include <xenctrl.h>
25 #include <inttypes.h>
27 int main(int argc, char **argv)
28 {
29 int xc_fd;
30 int i, j, ret = 0;
31 int cinfo = 0, pinfo = 0;
32 int ch;
33 xc_physinfo_t physinfo = { 0 };
35 while ( (ch = getopt(argc, argv, "cp")) != -1 )
36 {
37 switch ( ch )
38 {
39 case 'c':
40 cinfo = 1;
41 break;
42 case 'p':
43 pinfo = 1;
44 break;
45 default:
46 fprintf(stderr, "%s [-p] [-c]\n", argv[0]);
47 return -1;
48 }
49 }
51 if ( !cinfo && !pinfo )
52 {
53 cinfo = 1;
54 pinfo = 1;
55 }
57 xc_fd = xc_interface_open();
58 if ( xc_fd < 0 )
59 {
60 fprintf(stderr, "failed to get the handler\n");
61 return xc_fd;
62 }
64 ret = xc_physinfo(xc_fd, &physinfo);
65 if ( ret )
66 {
67 fprintf(stderr, "failed to get the processor information\n");
68 xc_interface_close(xc_fd);
69 return ret;
70 }
72 /* print out the C state information */
73 if ( cinfo )
74 {
75 int max_cx_num = 0;
76 struct xc_cx_stat cxstatinfo, *cxstat = &cxstatinfo;
78 for ( i = 0; i < physinfo.nr_cpus; i++ )
79 {
80 ret = xc_pm_get_max_cx(xc_fd, i, &max_cx_num);
81 if ( ret )
82 {
83 if ( errno == ENODEV )
84 fprintf(stderr, "Xen cpuidle is not enabled!\n");
85 else
86 fprintf(stderr, "failed to get max C-state\n");
88 break;
89 }
91 cxstat->triggers = malloc(max_cx_num * sizeof(uint64_t));
92 if ( !cxstat->triggers )
93 {
94 fprintf(stderr, "failed to malloc for C-states triggers\n");
95 break;
96 }
97 cxstat->residencies = malloc(max_cx_num * sizeof(uint64_t));
98 if ( !cxstat->residencies )
99 {
100 fprintf(stderr, "failed to malloc for C-states residencies\n");
101 free(cxstat->triggers);
102 break;
103 }
105 ret = xc_pm_get_cxstat(xc_fd, i, cxstat);
106 if( ret )
107 {
108 fprintf(stderr, "failed to get C-states statistics information\n");
109 free(cxstat->triggers);
110 free(cxstat->residencies);
111 break;
112 }
114 printf("cpu id : %d\n", i);
115 printf("total C-states : %d\n", cxstat->nr);
116 printf("idle time(ms) : %"PRIu64"\n", cxstat->idle_time/1000000UL);
117 for ( j = 0; j < cxstat->nr; j++ )
118 {
119 printf("C%d : transition [%020"PRIu64"]\n",
120 j, cxstat->triggers[j]);
121 printf(" residency [%020"PRIu64" ms]\n",
122 cxstat->residencies[j]*1000000UL/3579/1000000UL);
123 }
125 free(cxstat->triggers);
126 free(cxstat->residencies);
128 printf("\n");
129 }
130 }
132 /* print out P state information */
133 if ( pinfo )
134 {
135 int max_px_num = 0;
136 struct xc_px_stat pxstatinfo, *pxstat = &pxstatinfo;
138 for ( i = 0; i < physinfo.nr_cpus; i++ )
139 {
140 ret = xc_pm_get_max_px(xc_fd, i, &max_px_num);
141 if ( ret ) {
142 if ( errno == ENODEV )
143 printf("Xen cpufreq is not enabled!\n");
144 else
145 fprintf(stderr, "failed to get max P-state\n");
147 break;
148 }
150 pxstat->trans_pt = malloc(max_px_num * max_px_num * sizeof(uint64_t));
151 if ( !pxstat->trans_pt )
152 {
153 fprintf(stderr, "failed to malloc for P-states transition table\n");
154 break;
155 }
156 pxstat->pt = malloc(max_px_num * sizeof(struct xc_px_val));
157 if ( !pxstat->pt )
158 {
159 fprintf(stderr, "failed to malloc for P-states table\n");
160 free(pxstat->pt);
161 break;
162 }
164 ret = xc_pm_get_pxstat(xc_fd, i, pxstat);
165 if( ret ) {
166 fprintf(stderr, "failed to get P-states statistics information\n");
167 free(pxstat->trans_pt);
168 free(pxstat->pt);
169 break;
170 }
172 printf("cpu id : %d\n", i);
173 printf("total P-states : %d\n", pxstat->total);
174 printf("usable P-states : %d\n", pxstat->usable);
175 printf("current frequency : %"PRIu64" MHz\n", pxstat->pt[pxstat->cur].freq);
176 for ( j = 0; j < pxstat->total; j++ )
177 {
178 if ( pxstat->cur == j )
179 printf("*P%d", j);
180 else
181 printf("P%d ", j);
182 printf(" : freq [%04"PRIu64" MHz]\n", pxstat->pt[j].freq);
183 printf(" transition [%020"PRIu64"]\n", pxstat->pt[j].count);
184 printf(" residency [%020"PRIu64" ms]\n", pxstat->pt[j].residency/1000000UL);
185 }
187 free(pxstat->trans_pt);
188 free(pxstat->pt);
190 printf("\n");
191 }
192 }
194 xc_interface_close(xc_fd);
195 return ret;
196 }