Skip to contentSkip to conversation

softmmu/cpus: Check if the cpu work list is empty atomically

PATCH Applied Idan Horowitz 2 participants 6 messages Jan 14, 2022 – Jun 21, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 softmmu/cpus: Check if the cpu work list is empty atomically

Instead of taking the lock of the cpu work list in order to check if it's empty, we can just read the head pointer atomically. This decreases cpu_work_list_empty's share from 5% to 1.3% in a profile of icount-enabled aarch64-softmmu.

---
 softmmu/cpus.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
softmmu/cpus.c +1 -6
index 23bca46b07..035395ae13 100644
@@ -73,12 +73,7 @@ bool cpu_is_stopped(CPUState *cpu)
 
 bool cpu_work_list_empty(CPUState *cpu)
 {
-    bool ret;
-
-    qemu_mutex_lock(&cpu->work_mutex);
-    ret = QSIMPLEQ_EMPTY(&cpu->work_list);
-    qemu_mutex_unlock(&cpu->work_mutex);
-    return ret;
+    return QSIMPLEQ_EMPTY_ATOMIC(&cpu->work_list);
 }
 
 bool cpu_thread_is_idle(CPUState *cpu)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 qemu-timer: Skip empty timer lists before locking in qemu_clock_deadline_ns_all

This decreases qemu_clock_deadline_ns_all's share from 23.2% to 13% in a profile of icount-enabled aarch64-softmmu.

---
 util/qemu-timer.c | 3 +++
 1 file changed, 3 insertions(+)
util/qemu-timer.c +3 -0
index f36c75e594..e56895ef55 100644
@@ -261,6 +261,9 @@ int64_t qemu_clock_deadline_ns_all(QEMUClockType type, int attr_mask)
     }
 
     QLIST_FOREACH(timer_list, &clock->timerlists, list) {
+        if (!qatomic_read(&timer_list->active_timers)) {
+            continue;
+        }
         qemu_mutex_lock(&timer_list->active_timers_lock);
         ts = timer_list->active_timers;
         /* Skip all external timers */
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH 2/2] qemu-timer: Skip empty timer lists before locking in qemu_clock_deadline_ns_all

Quoted 4 lines · Richard Henderson

r~

Hey, I believe this patch might have accidentally been missed?

Thanks,
Idan Horowitz

#4 lore raw

Re: [PATCH 2/2] qemu-timer: Skip empty timer lists before locking in qemu_clock_deadline_ns_all

Quoted 8 lines · Idan Horowitz
Quoted 4 lines · Richard Henderson

r~

Hey, I believe this patch might have accidentally been missed?

Oops, yes. Got 1/2 but not 2/2. Queued to tcg-next.

r~

Reviewed-by on v1 1/2 Applied
#5 lore raw
In reply to Idan Horowitz
Quoted 9 lines · Idan Horowitz

Instead of taking the lock of the cpu work list in order to check if it's empty, we can just read the head pointer atomically. This decreases cpu_work_list_empty's share from 5% to 1.3% in a profile of icount-enabled aarch64-softmmu.

---
  softmmu/cpus.c | 7 +------
  1 file changed, 1 insertion(+), 6 deletions(-)

Queued to tcg-next.

r~