[PATCH 4/8] store and set cpu affinities

Glauber Costa
2008-03-04T16:21:57Z

This patch provides a cpu_set variable to vcpu_info structure.
It stores the current cpu mask for a thread.

We also provide a wrapper for storing a provided affinity, and a
function to set default affinities: The default affinities are current
process'

Signed-off-by: Glauber Costa <gcosta@redhat.com>
---
qemu/qemu-kvm.c | 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c
index 1aeb97b..a36fbf6 100644
--- a/qemu/qemu-kvm.c
+++ b/qemu/qemu-kvm.c
@@ -49,8 +49,25 @@ struct vcpu_info {
int stop;
int stopped;
int thread_id;
+ cpu_set_t cpu_set;
} vcpu_info[256];

+void kvm_store_cpu_affinity(int cpu, cpu_set_t *map)
+{
+ memcpy(&vcpu_info[cpu].cpu_set, map, sizeof(*map));
+}
+
+void kvm_register_default_affinities(void)
+{
+ int i;
+ cpu_set_t dfl;
+ sched_getaffinity(0, sizeof(dfl), &dfl);
+
+ for (i = 0; i < 256; i++) {
+ memcpy(&vcpu_info[i].cpu_set, &dfl, sizeof(dfl));
+ }
+}
+
static inline unsigned long kvm_get_thread_id(void)
{
return syscall(SYS_gettid);
--
1.5.0.6