--- a/xen/arch/x86/platform_hypercall.c +++ b/xen/arch/x86/platform_hypercall.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -63,6 +63,7 @@ long cpu_down_helper(void *data); ret_t do_platform_op(XEN_GUEST_HANDLE(xen_platform_op_t) u_xenpf_op) { ret_t ret = 0; + struct vcpu *v; struct xen_platform_op curop, *op = &curop; if ( !IS_PRIV(current->domain) ) @@ -522,6 +523,24 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xe op->u.mem_add.epfn, op->u.mem_add.pxm); break; + + case XENPF_get_cpu_freq: + if ( op->u.get_cpu_freq.vcpu >= current->domain->max_vcpus || + !(v = current->domain->vcpu[op->u.get_cpu_freq.vcpu]) ) + { + ret = -EINVAL; + break; + } + + op->u.get_cpu_freq.freq = per_cpu(cpufreq_cpu_policy, v->processor) + ? cpufreq_driver->get + ? cpufreq_driver->get(v->processor) + : per_cpu(cpufreq_cpu_policy, v->processor)->cur + : 0; + if ( copy_field_to_guest(u_xenpf_op, op, u.get_cpu_freq.freq) ) + ret = -EFAULT; + break; + default: ret = -ENOSYS; break; --- a/xen/include/public/platform.h +++ b/xen/include/public/platform.h @@ -451,6 +451,14 @@ struct xenpf_mem_hotadd uint32_t flags; }; +#define XENPF_get_cpu_freq ('N' << 24) +struct xenpf_get_cpu_freq { + /* IN variables */ + uint32_t vcpu; + /* OUT variables */ + uint32_t freq; /* in kHz */ +}; + struct xen_platform_op { uint32_t cmd; uint32_t interface_version; /* XENPF_INTERFACE_VERSION */ @@ -471,6 +479,7 @@ struct xen_platform_op { struct xenpf_cpu_ol cpu_ol; struct xenpf_cpu_hotadd cpu_add; struct xenpf_mem_hotadd mem_add; + struct xenpf_get_cpu_freq get_cpu_freq; uint8_t pad[128]; } u; };