Skip to contentSkip to conversation

add platform call for cpu idle information

RFC PATCH In review Rik van Riel 2 participants 2 messages Oct 1, 2007 – Oct 8, 2007

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 add platform call for cpu idle information

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?

xen/arch/x86/platform_hypercall.c +33 -0
diff -r 5c7afb32df99 xen/arch/x86/platform_hypercall.c
@@ -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;
xen/include/public/platform.h +18 -0
diff -r 5c7afb32df99 xen/include/public/platform.h
@@ -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;
 };
#1 lore raw
Quoted 5 lines
Quoted 1 line
Quoted 1 line

Rik van Riel <[email protected]> 02.10.07 00:57 >>>

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.

Quoted 8 lines

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?

You'd definitely need to extend the #ifndef COMPAT section close to the top of the file with

# undef copy_to_compat_offset
# define copy_to_compat_offset copy_to_guest_offset

I can't immediately see what else might be needed.

Jan