diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2008-05-21 10:59:49 +0100 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2008-05-21 10:59:49 +0100 |
commit | f219d911b7d56e945d29fddece9e4d2654a1fc81 (patch) | |
tree | 8acc0fd83699b7b09414b4d8b21af092106c4c25 /tools/libxc/xc_pm.c | |
parent | c8ddf206ac418b4cb89896cc45f9879c6415f99a (diff) | |
download | xen-f219d911b7d56e945d29fddece9e4d2654a1fc81.tar.gz xen-f219d911b7d56e945d29fddece9e4d2654a1fc81.tar.bz2 xen-f219d911b7d56e945d29fddece9e4d2654a1fc81.zip |
Add statistic interface for cx.
Implement statistic interface for cx via sysctl & libxc. Provide a
easy way to collect processor cx info within dom0.
Signed-off-by: Wei Gang <gang.wei@intel.com>
Diffstat (limited to 'tools/libxc/xc_pm.c')
-rw-r--r-- | tools/libxc/xc_pm.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tools/libxc/xc_pm.c b/tools/libxc/xc_pm.c index 0378cbd521..2737cbe312 100644 --- a/tools/libxc/xc_pm.c +++ b/tools/libxc/xc_pm.c @@ -99,3 +99,71 @@ int xc_pm_reset_pxstat(int xc_handle, int cpuid) return xc_sysctl(xc_handle, &sysctl); } + +int xc_pm_get_max_cx(int xc_handle, int cpuid, int *max_cx) +{ + DECLARE_SYSCTL; + int ret = 0; + + sysctl.cmd = XEN_SYSCTL_get_pmstat; + sysctl.u.get_pmstat.type = PMSTAT_get_max_cx; + sysctl.u.get_pmstat.cpuid = cpuid; + if ( (ret = xc_sysctl(xc_handle, &sysctl)) != 0 ) + return ret; + + *max_cx = sysctl.u.get_pmstat.u.getcx.nr; + return ret; +} + +int xc_pm_get_cxstat(int xc_handle, int cpuid, struct xc_cx_stat *cxpt) +{ + DECLARE_SYSCTL; + int max_cx, ret; + + if( !cxpt || !(cxpt->triggers) || !(cxpt->residencies) ) + return -EINVAL; + + if ( (ret = xc_pm_get_max_cx(xc_handle, cpuid, &max_cx)) ) + goto unlock_0; + + if ( (ret = lock_pages(cxpt, sizeof(struct xc_cx_stat))) ) + goto unlock_0; + if ( (ret = lock_pages(cxpt->triggers, max_cx * sizeof(uint64_t))) ) + goto unlock_1; + if ( (ret = lock_pages(cxpt->residencies, max_cx * sizeof(uint64_t))) ) + goto unlock_2; + + sysctl.cmd = XEN_SYSCTL_get_pmstat; + sysctl.u.get_pmstat.type = PMSTAT_get_cxstat; + sysctl.u.get_pmstat.cpuid = cpuid; + set_xen_guest_handle(sysctl.u.get_pmstat.u.getcx.triggers, cxpt->triggers); + set_xen_guest_handle(sysctl.u.get_pmstat.u.getcx.residencies, + cxpt->residencies); + + if ( (ret = xc_sysctl(xc_handle, &sysctl)) ) + goto unlock_3; + + cxpt->nr = sysctl.u.get_pmstat.u.getcx.nr; + cxpt->last = sysctl.u.get_pmstat.u.getcx.last; + cxpt->idle_time = sysctl.u.get_pmstat.u.getcx.idle_time; + +unlock_3: + unlock_pages(cxpt->residencies, max_cx * sizeof(uint64_t)); +unlock_2: + unlock_pages(cxpt->triggers, max_cx * sizeof(uint64_t)); +unlock_1: + unlock_pages(cxpt, sizeof(struct xc_cx_stat)); +unlock_0: + return ret; +} + +int xc_pm_reset_cxstat(int xc_handle, int cpuid) +{ + DECLARE_SYSCTL; + + sysctl.cmd = XEN_SYSCTL_get_pmstat; + sysctl.u.get_pmstat.type = PMSTAT_reset_cxstat; + sysctl.u.get_pmstat.cpuid = cpuid; + + return xc_sysctl(xc_handle, &sysctl); +} |