-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update: Native qemu cpu thread pinning
Updated cpus.c file with new qemu_thread_set_affinity (1) Removed redundant definition from already exisitng patch No. 14 (2) Signed-off-by: Roja Eswaran <roja@zededa.com>
- Loading branch information
1 parent
46fb0f1
commit 227a75a
Showing
3 changed files
with
58 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
pkg/xen-tools/patches-4.19.0/16-qemu-native-thread-affinity.patch
This file was deleted.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
pkg/xen-tools/patches-4.19.0/23-qemu-native-thread-affinity.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- a/tools/qemu-xen/softmmu/cpus.c 2023-08-16 02:43:53 | ||
+++ b/tools/qemu-xen/softmmu/cpus.c 2024-10-22 11:51:09 | ||
@@ -619,6 +619,23 @@ const AccelOpsClass *cpus_get_accel(void) | ||
cpus_accel = ops; | ||
} | ||
|
||
+static inline void cpumask_clear_bit(uint64_t *mask, uint8_t bit) | ||
+{ | ||
+ *mask &= ~(1ul << bit); | ||
+} | ||
+ | ||
+static inline long cpumask_get_min_bit(uint64_t mask) | ||
+{ | ||
+ return __builtin_ffsll(mask) - 1; | ||
+} | ||
+ | ||
+static long pick_pcpu(uint64_t *cpumask) | ||
+{ | ||
+ long ret = cpumask_get_min_bit(*cpumask); | ||
+ cpumask_clear_bit(cpumask, ret); | ||
+ return ret; | ||
+} | ||
+ | ||
const AccelOpsClass *cpus_get_accel(void) | ||
{ | ||
/* broken if we call this early */ | ||
@@ -629,12 +646,30 @@ void qemu_init_vcpu(CPUState *cpu) | ||
void qemu_init_vcpu(CPUState *cpu) | ||
{ | ||
MachineState *ms = MACHINE(qdev_get_machine()); | ||
- | ||
+ unsigned long *bitmap = NULL; | ||
cpu->nr_cores = ms->smp.cores; | ||
cpu->nr_threads = ms->smp.threads; | ||
cpu->stopped = true; | ||
cpu->random_seed = qemu_guest_random_seed_thread_part1(); | ||
+ cpu->pinned = ms->cpu_pin; | ||
+ static uint64_t vm_cpumask; | ||
+ uint64_t vcpu_cpumask; | ||
+ if (!vm_cpumask) | ||
+ vm_cpumask = ms->cpumask; | ||
+ if (!cpu->pinned) { | ||
+ vcpu_cpumask = vm_cpumask; | ||
+ } else { | ||
+ vcpu_cpumask = 1ull << pick_pcpu(&vm_cpumask); | ||
+ } | ||
+ cpu->cpumask = vcpu_cpumask; | ||
|
||
+ if(cpu_can_run(cpu)) | ||
+ warn_report("Change a CPU affinity after the CPU may have been running for a while\n"); | ||
+ if (cpu->cpumask){ | ||
+ bitmap = bitmap_new(cpu->cpumask); | ||
+ qemu_thread_set_affinity(cpu->thread, bitmap, cpu->cpumask); | ||
+ } | ||
+ | ||
if (!cpu->as) { | ||
/* If the target cpu hasn't set up any address spaces itself, | ||
* give it the default one. |