Skip to contentSkip to conversation

export cpu idle time to guests

PATCH In review Rik van Riel 2 participants 2 messages Jun 15, 2007 – Jun 18, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 export cpu idle time to guests

The attached patch exports cpu idle time to guests. This is one of the things necessary for cpu frequency scaling to work well.

It works, but has the problem that the sysctl hypercall is really only designed to be used from userspace, so we would need a userspace cpufreq daemon running in dom0.

Mark, does this look reasonable to you?

Signature · 3 lines
Politics is the struggle between those who want to make their country
the best in the world, and those who believe it already is.  Each group
calls the other unpatriotic.
xen/common/sysctl.c +27 -0
diff -r 93f77a5a8437 xen/common/sysctl.c
@@ -136,6 +136,33 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysc
     }
     break;
 
+    case XEN_SYSCTL_getidletime:
+    {
+        uint32_t cpu;
+        uint32_t max_cpus = op->u.getidletime.max_cpus;
+        uint64_t idletime;
+
+        for_each_online_cpu (cpu) {
+            if ( cpu >= max_cpus )
+                break;
+
+             idletime = idle_vcpu[cpu]->runstate.time[RUNSTATE_running];
+
+             if ( copy_to_guest_offset(op->u.getidletime.buffer, cpu,
+                                       &idletime, 1) ) {
+                 ret = -EFAULT;
+                 break;
+             }
+         }
+
+         op->u.getidletime.num_cpus = cpu;
+
+         if ( copy_to_guest(u_sysctl, op, 1) )
+             ret = -EFAULT;
+      }
+      break;
+            
+
     default:
         ret = arch_do_sysctl(op, u_sysctl);
         break;
xen/include/public/sysctl.h +12 -0
diff -r 93f77a5a8437 xen/include/public/sysctl.h
@@ -152,6 +152,17 @@ typedef struct xen_sysctl_debug_keys xen
 typedef struct xen_sysctl_debug_keys xen_sysctl_debug_keys_t;
 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_debug_keys_t);
 
+#define XEN_SYSCTL_getidletime 8
+struct xen_sysctl_getidletime {
+    /* IN variables. */
+    uint32_t                   max_cpus;
+    XEN_GUEST_HANDLE(uint64_t) buffer;
+    /* OUT variables. */
+    uint32_t                   num_cpus;
+};
+typedef struct xen_sysctl_getidletime xen_sysctl_getidletime_t;
+DEFINE_XEN_GUEST_HANDLE(xen_sysctl_getidletime_t);
+
 struct xen_sysctl {
     uint32_t cmd;
     uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */
@@ -163,6 +174,7 @@ struct xen_sysctl {
         struct xen_sysctl_perfc_op          perfc_op;
         struct xen_sysctl_getdomaininfolist getdomaininfolist;
         struct xen_sysctl_debug_keys        debug_keys;
+        struct xen_sysctl_getidletime       getidletime;
         uint8_t                             pad[128];
     } u;
 };

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 8 lines

The attached patch exports cpu idle time to guests. This is one of the things necessary for cpu frequency scaling to work well.

It works, but has the problem that the sysctl hypercall is really only designed to be used from userspace, so we would need a userspace cpufreq daemon running in dom0.

Mark, does this look reasonable to you?

As a first pass toward enabling a solution, it looks acceptable. It should be trivial to enable cpuspeed or powersave to use a different call when running on dom0.

In the long run, I'd like to get ondemand working in dom0 so that people don't need to do anything special to get cpufreq support.

-Mark Langsdorf
Operating System Research Center
AMD