[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH][RFC] add platform call for cpu idle information


  • To: xen-devel@xxxxxxxxxxxxxxxxxxx
  • From: Rik van Riel <riel@xxxxxxxxxx>
  • Date: Mon, 1 Oct 2007 18:57:36 -0400
  • Delivery-date: Mon, 01 Oct 2007 15:59:43 -0700
  • List-id: Xen developer discussion <xen-devel.lists.xensource.com>

In order to make cpu frequency scaling useful from the
dom0 kernel, the cpu idle time really needs to be available
through a hypercall that can be invoked from the kernel.

This patch basically cut'n'pastes the sysctl getcpuinfo
code to platform_hypercall.c.

Unfortunately due to some COMPAT macros the code does not
compile. I have been trying to make it compile all afternoon,
but some magic macros seem to keep getting in my way...

What do I need to change to make the below compile on x86_64?

Signed-off-by: Rik van Riel <riel@xxxxxxxxxx>

diff -r 5c7afb32df99 xen/arch/x86/platform_hypercall.c
--- a/xen/arch/x86/platform_hypercall.c Mon Oct 01 06:39:00 2007 +0100
+++ b/xen/arch/x86/platform_hypercall.c Mon Oct 01 18:54:14 2007 -0400
@@ -294,6 +294,39 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xe
                                         &op->u.change_freq.freq);
         break;
 
+    case XENPF_getcpuinfo:
+    {
+        uint32_t i, nr_cpus;
+        struct xenpf_cpuinfo cpuinfo;
+        struct vcpu *v;
+
+        nr_cpus = min_t(uint32_t, op->u.getcpuinfo.max_cpus, NR_CPUS);
+
+        for ( i = 0; i < nr_cpus; i++ )
+        {
+            /* Assume no holes in idle-vcpu map. */
+            if ( (v = idle_vcpu[i]) == NULL )
+                break;
+
+            cpuinfo.idletime = v->runstate.time[RUNSTATE_running];
+            if ( v->is_running )
+                cpuinfo.idletime += NOW() - v->runstate.state_entry_time;
+
+            if ( copy_to_compat_offset(op->u.getcpuinfo.info, i, &cpuinfo, 1) )
+            {
+                ret = -EFAULT;
+                break;
+            }
+        }
+
+        op->u.getcpuinfo.nr_cpus = i;
+        ret = 0;
+
+        if ( copy_to_guest(u_xenpf_op, op, 1) )
+            ret = -EFAULT;
+    }
+    break;
+
     default:
         ret = -ENOSYS;
         break;
diff -r 5c7afb32df99 xen/include/public/platform.h
--- a/xen/include/public/platform.h     Mon Oct 01 06:39:00 2007 +0100
+++ b/xen/include/public/platform.h     Mon Oct 01 18:54:14 2007 -0400
@@ -173,6 +173,23 @@ struct xenpf_change_freq {
 };
 typedef struct xenpf_change_freq xenpf_change_freq_t;
 DEFINE_XEN_GUEST_HANDLE(xenpf_change_freq_t);
+
+/* Get idle CPU info */
+#define XENPF_getcpuinfo       53
+struct xenpf_cpuinfo {
+    uint64_t idletime;
+};
+typedef struct xenpf_cpuinfo xenpf_cpuinfo_t;
+DEFINE_XEN_GUEST_HANDLE(xenpf_cpuinfo_t);
+struct xenpf_getcpuinfo {
+    /* IN variables. */
+    uint32_t max_cpus;
+    XEN_GUEST_HANDLE_64(xenpf_cpuinfo_t) info;
+    /* OUT variables. */
+    uint32_t nr_cpus;
+};
+typedef struct xenpf_getcpuinfo xenpf_getcpuinfo_t;
+DEFINE_XEN_GUEST_HANDLE(xenpf_getcpuinfo_t);
 
 struct xen_platform_op {
     uint32_t cmd;
@@ -187,6 +204,7 @@ struct xen_platform_op {
         struct xenpf_firmware_info     firmware_info;
         struct xenpf_enter_acpi_sleep  enter_acpi_sleep;
         struct xenpf_change_freq       change_freq;
+        struct xenpf_getcpuinfo        getcpuinfo;
         uint8_t                        pad[128];
     } u;
 };


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.