debuggers.hg

view tools/libxc/xc_pm.c @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children 5c0bf00e371d
line source
1 /******************************************************************************
2 * xc_pm.c - Libxc API for Xen Power Management (Px/Cx/Tx, etc.) statistic
3 *
4 * Copyright (c) 2008, Liu Jinsong <jinsong.liu@intel.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 */
26 #include "xc_private.h"
28 int xc_pm_get_max_px(int xc_handle, int cpuid, int *max_px)
29 {
30 DECLARE_SYSCTL;
31 int ret;
33 sysctl.cmd = XEN_SYSCTL_get_pmstat;
34 sysctl.u.get_pmstat.type = PMSTAT_get_max_px;
35 sysctl.u.get_pmstat.cpuid = cpuid;
36 ret = xc_sysctl(xc_handle, &sysctl);
37 if ( ret )
38 return ret;
40 *max_px = sysctl.u.get_pmstat.u.getpx.total;
41 return ret;
42 }
44 int xc_pm_get_pxstat(int xc_handle, int cpuid, struct xc_px_stat *pxpt)
45 {
46 DECLARE_SYSCTL;
47 int max_px, ret;
49 if ( !pxpt || !(pxpt->trans_pt) || !(pxpt->pt) )
50 return -EINVAL;
52 if ( (ret = xc_pm_get_max_px(xc_handle, cpuid, &max_px)) != 0)
53 return ret;
55 if ( (ret = lock_pages(pxpt->trans_pt,
56 max_px * max_px * sizeof(uint64_t))) != 0 )
57 return ret;
59 if ( (ret = lock_pages(pxpt->pt,
60 max_px * sizeof(struct xc_px_val))) != 0 )
61 {
62 unlock_pages(pxpt->trans_pt, max_px * max_px * sizeof(uint64_t));
63 return ret;
64 }
66 sysctl.cmd = XEN_SYSCTL_get_pmstat;
67 sysctl.u.get_pmstat.type = PMSTAT_get_pxstat;
68 sysctl.u.get_pmstat.cpuid = cpuid;
69 set_xen_guest_handle(sysctl.u.get_pmstat.u.getpx.trans_pt, pxpt->trans_pt);
70 set_xen_guest_handle(sysctl.u.get_pmstat.u.getpx.pt,
71 (pm_px_val_t *)pxpt->pt);
73 ret = xc_sysctl(xc_handle, &sysctl);
74 if ( ret )
75 {
76 unlock_pages(pxpt->trans_pt, max_px * max_px * sizeof(uint64_t));
77 unlock_pages(pxpt->pt, max_px * sizeof(struct xc_px_val));
78 return ret;
79 }
81 pxpt->total = sysctl.u.get_pmstat.u.getpx.total;
82 pxpt->usable = sysctl.u.get_pmstat.u.getpx.usable;
83 pxpt->last = sysctl.u.get_pmstat.u.getpx.last;
84 pxpt->cur = sysctl.u.get_pmstat.u.getpx.cur;
86 unlock_pages(pxpt->trans_pt, max_px * max_px * sizeof(uint64_t));
87 unlock_pages(pxpt->pt, max_px * sizeof(struct xc_px_val));
89 return ret;
90 }
92 int xc_pm_reset_pxstat(int xc_handle, int cpuid)
93 {
94 DECLARE_SYSCTL;
96 sysctl.cmd = XEN_SYSCTL_get_pmstat;
97 sysctl.u.get_pmstat.type = PMSTAT_reset_pxstat;
98 sysctl.u.get_pmstat.cpuid = cpuid;
100 return xc_sysctl(xc_handle, &sysctl);
101 }