diff mbox series

[10/15] memory: Replace current_machine by qdev_get_machine()

Message ID 20200109152133.23649-11-philmd@redhat.com
State New
Headers show
Series Replace current_machine by qdev_get_machine() | expand

Commit Message

Philippe Mathieu-Daudé Jan. 9, 2020, 3:21 p.m. UTC
As we want to remove the global current_machine,
replace 'current_machine' by MACHINE(qdev_get_machine()).

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 memory.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Alistair Francis Jan. 12, 2020, 9:48 a.m. UTC | #1
On Thu, Jan 9, 2020 at 11:29 PM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> As we want to remove the global current_machine,
> replace 'current_machine' by MACHINE(qdev_get_machine()).
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  memory.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/memory.c b/memory.c
> index d7b9bb6951..57e38b1f50 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -3004,6 +3004,7 @@ static void mtree_print_flatview(gpointer key, gpointer value,
>      int n = view->nr;
>      int i;
>      AddressSpace *as;
> +    MachineState *ms;
>
>      qemu_printf("FlatView #%d\n", fvi->counter);
>      ++fvi->counter;
> @@ -3026,6 +3027,7 @@ static void mtree_print_flatview(gpointer key, gpointer value,
>          return;
>      }
>
> +    ms = MACHINE(qdev_get_machine());

Why not set this at the top?

Alistair

>      while (n--) {
>          mr = range->mr;
>          if (range->offset_in_region) {
> @@ -3057,7 +3059,7 @@ static void mtree_print_flatview(gpointer key, gpointer value,
>          if (fvi->ac) {
>              for (i = 0; i < fv_address_spaces->len; ++i) {
>                  as = g_array_index(fv_address_spaces, AddressSpace*, i);
> -                if (fvi->ac->has_memory(current_machine, as,
> +                if (fvi->ac->has_memory(ms, as,
>                                          int128_get64(range->addr.start),
>                                          MR_SIZE(range->addr.size) + 1)) {
>                      qemu_printf(" %s", fvi->ac->name);
> --
> 2.21.1
>
>
Philippe Mathieu-Daudé Jan. 12, 2020, 1:45 p.m. UTC | #2
On 1/12/20 10:48 AM, Alistair Francis wrote:
> On Thu, Jan 9, 2020 at 11:29 PM Philippe Mathieu-Daudé
> <philmd@redhat.com> wrote:
>>
>> As we want to remove the global current_machine,
>> replace 'current_machine' by MACHINE(qdev_get_machine()).
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> ---
>>   memory.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/memory.c b/memory.c
>> index d7b9bb6951..57e38b1f50 100644
>> --- a/memory.c
>> +++ b/memory.c
>> @@ -3004,6 +3004,7 @@ static void mtree_print_flatview(gpointer key, gpointer value,
>>       int n = view->nr;
>>       int i;
>>       AddressSpace *as;
>> +    MachineState *ms;
>>
>>       qemu_printf("FlatView #%d\n", fvi->counter);
>>       ++fvi->counter;
>> @@ -3026,6 +3027,7 @@ static void mtree_print_flatview(gpointer key, gpointer value,
>>           return;
>>       }
>>
>> +    ms = MACHINE(qdev_get_machine());
> 
> Why not set this at the top?

Calling qdev_get_machine() is not free as it does some introspection 
checks. Since we can return earlier if there are no rendered FlatView, I 
placed the machinestate initialization just before it we need to access it.

> Alistair
> 
>>       while (n--) {
>>           mr = range->mr;
>>           if (range->offset_in_region) {
>> @@ -3057,7 +3059,7 @@ static void mtree_print_flatview(gpointer key, gpointer value,
>>           if (fvi->ac) {
>>               for (i = 0; i < fv_address_spaces->len; ++i) {
>>                   as = g_array_index(fv_address_spaces, AddressSpace*, i);
>> -                if (fvi->ac->has_memory(current_machine, as,
>> +                if (fvi->ac->has_memory(ms, as,
>>                                           int128_get64(range->addr.start),
>>                                           MR_SIZE(range->addr.size) + 1)) {
>>                       qemu_printf(" %s", fvi->ac->name);
>> --
>> 2.21.1
>>
>>
>
Alistair Francis Jan. 14, 2020, 2:02 a.m. UTC | #3
On Sun, Jan 12, 2020 at 11:45 PM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> On 1/12/20 10:48 AM, Alistair Francis wrote:
> > On Thu, Jan 9, 2020 at 11:29 PM Philippe Mathieu-Daudé
> > <philmd@redhat.com> wrote:
> >>
> >> As we want to remove the global current_machine,
> >> replace 'current_machine' by MACHINE(qdev_get_machine()).
> >>
> >> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> >> ---
> >>   memory.c | 4 +++-
> >>   1 file changed, 3 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/memory.c b/memory.c
> >> index d7b9bb6951..57e38b1f50 100644
> >> --- a/memory.c
> >> +++ b/memory.c
> >> @@ -3004,6 +3004,7 @@ static void mtree_print_flatview(gpointer key, gpointer value,
> >>       int n = view->nr;
> >>       int i;
> >>       AddressSpace *as;
> >> +    MachineState *ms;
> >>
> >>       qemu_printf("FlatView #%d\n", fvi->counter);
> >>       ++fvi->counter;
> >> @@ -3026,6 +3027,7 @@ static void mtree_print_flatview(gpointer key, gpointer value,
> >>           return;
> >>       }
> >>
> >> +    ms = MACHINE(qdev_get_machine());
> >
> > Why not set this at the top?
>
> Calling qdev_get_machine() is not free as it does some introspection
> checks. Since we can return earlier if there are no rendered FlatView, I
> placed the machinestate initialization just before it we need to access it.

Works for me, maybe worth putting this in the commit?

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

>
> > Alistair
> >
> >>       while (n--) {
> >>           mr = range->mr;
> >>           if (range->offset_in_region) {
> >> @@ -3057,7 +3059,7 @@ static void mtree_print_flatview(gpointer key, gpointer value,
> >>           if (fvi->ac) {
> >>               for (i = 0; i < fv_address_spaces->len; ++i) {
> >>                   as = g_array_index(fv_address_spaces, AddressSpace*, i);
> >> -                if (fvi->ac->has_memory(current_machine, as,
> >> +                if (fvi->ac->has_memory(ms, as,
> >>                                           int128_get64(range->addr.start),
> >>                                           MR_SIZE(range->addr.size) + 1)) {
> >>                       qemu_printf(" %s", fvi->ac->name);
> >> --
> >> 2.21.1
> >>
> >>
> >
>
diff mbox series

Patch

diff --git a/memory.c b/memory.c
index d7b9bb6951..57e38b1f50 100644
--- a/memory.c
+++ b/memory.c
@@ -3004,6 +3004,7 @@  static void mtree_print_flatview(gpointer key, gpointer value,
     int n = view->nr;
     int i;
     AddressSpace *as;
+    MachineState *ms;
 
     qemu_printf("FlatView #%d\n", fvi->counter);
     ++fvi->counter;
@@ -3026,6 +3027,7 @@  static void mtree_print_flatview(gpointer key, gpointer value,
         return;
     }
 
+    ms = MACHINE(qdev_get_machine());
     while (n--) {
         mr = range->mr;
         if (range->offset_in_region) {
@@ -3057,7 +3059,7 @@  static void mtree_print_flatview(gpointer key, gpointer value,
         if (fvi->ac) {
             for (i = 0; i < fv_address_spaces->len; ++i) {
                 as = g_array_index(fv_address_spaces, AddressSpace*, i);
-                if (fvi->ac->has_memory(current_machine, as,
+                if (fvi->ac->has_memory(ms, as,
                                         int128_get64(range->addr.start),
                                         MR_SIZE(range->addr.size) + 1)) {
                     qemu_printf(" %s", fvi->ac->name);