[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v1 07/17] background snapshot: introduce page bu
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH v1 07/17] background snapshot: introduce page buffer |
Date: |
Fri, 20 Jul 2018 12:34:14 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 |
On 18/07/2018 17:41, Denis Plotnikov wrote:
> +static void ram_page_buffer_decrease_used(void)
> +{
> + qemu_event_reset(&ram_state->page_buffer.used_decreased);
> + atomic_dec(&ram_state->page_buffer.used);
> + qemu_event_set(&ram_state->page_buffer.used_decreased);
As Peter noted, only the qemu_event_set is needed here, while...
> +}
> +
> +static void ram_page_buffer_increase_used_wait(void)
> +{
> + int used, *used_ptr;
> + RAMState *rs = ram_state;
> + used_ptr = &rs->page_buffer.used;
> + do {
> + used = atomic_read(used_ptr);
> + if (rs->page_buffer.capacity > used) {
> + if (atomic_cmpxchg(used_ptr, used, used + 1) == used) {
> + return;
> + } else {
> + continue;
> + }
> + } else {
> + qemu_event_wait(&rs->page_buffer.used_decreased);
> + }
> + } while (true);
... the right idiom for using qemu_event_wait is this:
if test condition
reset
if test condition
wait
So something like
for(;;) {
used = atomic_read(used_ptr);
if (rs->page_buffer.capacity <= used) {
qemu_event_reset(&rs->page_buffer.used_decreased);
used = atomic_read(used_ptr);
if (rs->page_buffer.capacity <= used) {
qemu_event_wait(&rs->page_buffer.used_decreased);
continue;
}
}
if (atomic_cmpxchg(used_ptr, used, used + 1) == used) {
return;
}
}
Note that there must be a single thread doing the above. Otherwise, you
have to use mutex and condvar.
Paolo
- [Qemu-devel] [PATCH v1 10/17] background snapshots: adapt the page queueing code for using page copies, (continued)
- [Qemu-devel] [PATCH v1 10/17] background snapshots: adapt the page queueing code for using page copies, Denis Plotnikov, 2018/07/18
- [Qemu-devel] [PATCH v1 09/17] background snapshot: extend RAM request for holding a page copy pointer, Denis Plotnikov, 2018/07/18
- [Qemu-devel] [PATCH v1 15/17] kvm: add vCPU failed memeory access processing, Denis Plotnikov, 2018/07/18
- [Qemu-devel] [PATCH v1 14/17] kvm: add failed memeory access exit reason, Denis Plotnikov, 2018/07/18
- [Qemu-devel] [PATCH v1 12/17] ram: add background snapshot support in ram page saving part of migration, Denis Plotnikov, 2018/07/18
- [Qemu-devel] [PATCH v1 04/17] background snapshot: make a dedicated type for ram block list, Denis Plotnikov, 2018/07/18
- [Qemu-devel] [PATCH v1 07/17] background snapshot: introduce page buffer, Denis Plotnikov, 2018/07/18
- [Qemu-devel] [PATCH v1 11/17] background snapshot: add a memory page copying function, Denis Plotnikov, 2018/07/18
- [Qemu-devel] [PATCH v1 03/17] threads: add infrastructure to process sigsegv, Denis Plotnikov, 2018/07/18
- [Qemu-devel] [PATCH v1 16/17] migration: move the device state saving logic to a separate function, Denis Plotnikov, 2018/07/18
- [Qemu-devel] [PATCH v1 17/17] background snapshot: enable background snapshot, Denis Plotnikov, 2018/07/18
- Re: [Qemu-devel] [PATCH v1 00/17] Background snapshots, Peter Xu, 2018/07/20