[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 05/11] memory: add ref/unref
From: |
Jan Kiszka |
Subject: |
Re: [Qemu-devel] [PATCH v2 05/11] memory: add ref/unref |
Date: |
Mon, 01 Jul 2013 16:29:32 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 |
On 2013-06-28 18:58, Paolo Bonzini wrote:
> Signed-off-by: Paolo Bonzini <address@hidden>
> ---
> include/exec/memory.h | 30 ++++++++++++++++++++++++++++++
> memory.c | 14 ++++++++++++++
> 2 files changed, 44 insertions(+)
>
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index 1ad9c19..9c33bba 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -245,6 +245,36 @@ void memory_region_init(MemoryRegion *mr,
> struct Object *owner,
> const char *name,
> uint64_t size);
> +
> +/**
> + * memory_region_ref: Add 1 to a memory region's reference count
> + *
> + * Whenever memory regions are accessed outside the BQL, they need to be
> + * preserved against hot-unplug. MemoryRegions actually do not have their
> + * own reference count; they piggyback on a QOM object, their "owner".
> + * This function adds a reference to the owner.
> + *
> + * All MemoryRegions must have an owner if they can disappear, even if the
> + * device they belong to operates exclusively under the BQL. This is because
> + * the region could be returned at any time by memory_region_find, and this
> + * is usually under guest control.
> + *
> + * @mr: the #MemoryRegion
> + */
> +void memory_region_ref(MemoryRegion *mr);
> +
> +/**
> + * memory_region_unref: Remove 1 to a memory region's reference count
> + *
> + * Whenever memory regions are accessed outside the BQL, they need to be
> + * preserved against hot-unplug. MemoryRegions actually do not have their
> + * own reference count; they piggyback on a QOM object, their "owner".
> + * This function removes a reference to the owner and possibly destroys it.
> + *
> + * @mr: the #MemoryRegion
> + */
> +void memory_region_unref(MemoryRegion *mr);
> +
> /**
> * memory_region_init_io: Initialize an I/O memory region.
> *
> diff --git a/memory.c b/memory.c
> index 4d396c3..970c448 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -1017,6 +1017,20 @@ Object *memory_region_owner(MemoryRegion *mr)
> return mr->owner;
> }
>
> +void memory_region_ref(MemoryRegion *mr)
> +{
> + if (mr && mr->owner) {
> + object_ref(mr->owner);
> + }
> +}
> +
> +void memory_region_unref(MemoryRegion *mr)
> +{
> + if (mr && mr->owner) {
> + object_unref(mr->owner);
> + }
> +}
> +
> uint64_t memory_region_size(MemoryRegion *mr)
> {
> if (int128_eq(mr->size, int128_2_64())) {
>
Reviewed-by: Jan Kiszka <address@hidden>
BTW, shouldn't object_ref/unref be converted to atomics /
__sync_fetch_and_add/sub? I'm carrying a modified patch by Ping Fan for
this here.
Jan
--
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
- Re: [Qemu-devel] [PATCH v2 05/11] memory: add ref/unref,
Jan Kiszka <=