All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: Claudio Fontana <cfontana@suse.de>
Cc: "Paul Durrant" <paul@xen.org>, "Jason Wang" <jasowang@redhat.com>,
	qemu-devel@nongnu.org, "Peter Xu" <peterx@redhat.com>,
	haxm-team@intel.com, "Colin Xu" <colin.xu@intel.com>,
	"Olaf Hering" <ohering@suse.de>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Bruce Rogers" <brogers@suse.com>,
	"Emilio G . Cota" <cota@braap.org>,
	"Anthony Perard" <anthony.perard@citrix.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Cameron Esfahani" <dirty@apple.com>,
	"Dario Faggioli" <dfaggioli@suse.com>,
	"Roman Bolshakov" <r.bolshakov@yadro.com>,
	"Sunil Muthuswamy" <sunilmut@microsoft.com>,
	"Marcelo Tosatti" <mtosatti@redhat.com>,
	"Wenchao Wang" <wenchao.wang@intel.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [RFC v7 12/22] cpu: Introduce TCGCpuOperations struct
Date: Fri, 4 Dec 2020 13:29:32 -0500	[thread overview]
Message-ID: <20201204182932.GR3836@habkost.net> (raw)
In-Reply-To: <f8682afb-6791-303a-367a-28cc46b13e66@suse.de>

On Fri, Dec 04, 2020 at 07:07:09PM +0100, Claudio Fontana wrote:
> On 12/4/20 7:04 PM, Claudio Fontana wrote:
> > On 12/4/20 6:28 PM, Eduardo Habkost wrote:
> >> On Fri, Dec 04, 2020 at 06:10:49PM +0100, Philippe Mathieu-Daudé wrote:
> >>> On 11/30/20 3:35 AM, Claudio Fontana wrote:
> >>>> From: Eduardo Habkost <ehabkost@redhat.com>
> >>>>
> >>>> The TCG-specific CPU methods will be moved to a separate struct,
> >>>> to make it easier to move accel-specific code outside generic CPU
> >>>> code in the future.  Start by moving tcg_initialize().
> >>>
> >>> Good idea! One minor comment below.
> >>>
> >>>>
> >>>> The new CPUClass.tcg_opts field may eventually become a pointer,
> >>>> but keep it an embedded struct for now, to make code conversion
> >>>> easier.
> >>>>
> >>>> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> >>>> ---
> >>>>  MAINTAINERS                     |  1 +
> >>>>  cpu.c                           |  2 +-
> >>>>  include/hw/core/cpu.h           |  9 ++++++++-
> >>>>  include/hw/core/tcg-cpu-ops.h   | 25 +++++++++++++++++++++++++
> >>>>  target/alpha/cpu.c              |  2 +-
> >>>>  target/arm/cpu.c                |  2 +-
> >>>>  target/avr/cpu.c                |  2 +-
> >>>>  target/cris/cpu.c               | 12 ++++++------
> >>>>  target/hppa/cpu.c               |  2 +-
> >>>>  target/i386/tcg-cpu.c           |  2 +-
> >>>>  target/lm32/cpu.c               |  2 +-
> >>>>  target/m68k/cpu.c               |  2 +-
> >>>>  target/microblaze/cpu.c         |  2 +-
> >>>>  target/mips/cpu.c               |  2 +-
> >>>>  target/moxie/cpu.c              |  2 +-
> >>>>  target/nios2/cpu.c              |  2 +-
> >>>>  target/openrisc/cpu.c           |  2 +-
> >>>>  target/ppc/translate_init.c.inc |  2 +-
> >>>>  target/riscv/cpu.c              |  2 +-
> >>>>  target/rx/cpu.c                 |  2 +-
> >>>>  target/s390x/cpu.c              |  2 +-
> >>>>  target/sh4/cpu.c                |  2 +-
> >>>>  target/sparc/cpu.c              |  2 +-
> >>>>  target/tilegx/cpu.c             |  2 +-
> >>>>  target/tricore/cpu.c            |  2 +-
> >>>>  target/unicore32/cpu.c          |  2 +-
> >>>>  target/xtensa/cpu.c             |  2 +-
> >>>>  27 files changed, 63 insertions(+), 30 deletions(-)
> >>>>  create mode 100644 include/hw/core/tcg-cpu-ops.h
> >>>>
> >>>> diff --git a/MAINTAINERS b/MAINTAINERS
> >>>> index f53f2678d8..d876f504a6 100644
> >>>> --- a/MAINTAINERS
> >>>> +++ b/MAINTAINERS
> >>>> @@ -1535,6 +1535,7 @@ F: qapi/machine.json
> >>>>  F: qapi/machine-target.json
> >>>>  F: include/hw/boards.h
> >>>>  F: include/hw/core/cpu.h
> >>>> +F: include/hw/core/tcg-cpu-ops.h
> >>>>  F: include/hw/cpu/cluster.h
> >>>>  F: include/sysemu/numa.h
> >>>>  T: git https://github.com/ehabkost/qemu.git machine-next
> >>>> diff --git a/cpu.c b/cpu.c
> >>>> index 0be5dcb6f3..d02c2a17f1 100644
> >>>> --- a/cpu.c
> >>>> +++ b/cpu.c
> >>>> @@ -180,7 +180,7 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)
> >>>>  
> >>>>      if (tcg_enabled() && !tcg_target_initialized) {
> >>>>          tcg_target_initialized = true;
> >>>> -        cc->tcg_initialize();
> >>>> +        cc->tcg_ops.initialize();
> >>>>      }
> >>>>      tlb_init(cpu);
> >>>>  
> >>>> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> >>>> index 3d92c967ff..c93b08a0fb 100644
> >>>> --- a/include/hw/core/cpu.h
> >>>> +++ b/include/hw/core/cpu.h
> >>>> @@ -76,6 +76,10 @@ typedef struct CPUWatchpoint CPUWatchpoint;
> >>>>  
> >>>>  struct TranslationBlock;
> >>>>  
> >>>> +#ifdef CONFIG_TCG
> >>>> +#include "tcg-cpu-ops.h"
> >>>> +#endif /* CONFIG_TCG */
> >>>> +
> >>>>  /**
> >>>>   * CPUClass:
> >>>>   * @class_by_name: Callback to map -cpu command line model name to an
> >>>> @@ -221,12 +225,15 @@ struct CPUClass {
> >>>>  
> >>>>      void (*disas_set_info)(CPUState *cpu, disassemble_info *info);
> >>>>      vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len);
> >>>> -    void (*tcg_initialize)(void);
> >>>>  
> >>>>      const char *deprecation_note;
> >>>>      /* Keep non-pointer data at the end to minimize holes.  */
> >>>>      int gdb_num_core_regs;
> >>>>      bool gdb_stop_before_watchpoint;
> >>>> +
> >>>> +#ifdef CONFIG_TCG
> >>>> +    TcgCpuOperations tcg_ops;
> >>>> +#endif /* CONFIG_TCG */
> >>>>  };
> >>
> >> I'm not a fan of #ifdefs in struct definitions (especially in
> >> generic code like hw/cpu), because there's risk the same header
> >> generate different struct layout when used by different .c files.
> >> I would prefer to gradually refactor the code so that tcg_ops is
> >> eventually removed from CPUClass.
> >>
> >> This is not a dealbreaker, because both approaches are steps in
> >> the same direction.  But the #ifdef here makes review harder and
> >> has more risks of unwanted side effects.
> >>
> >>>>  
> >>>>  /*
> >>>> diff --git a/include/hw/core/tcg-cpu-ops.h b/include/hw/core/tcg-cpu-ops.h
> >>>> new file mode 100644
> >>>> index 0000000000..4475ef0996
> >>>> --- /dev/null
> >>>> +++ b/include/hw/core/tcg-cpu-ops.h
> >>>> @@ -0,0 +1,25 @@
> >>>> +/*
> >>>> + * TCG-Specific operations that are not meaningful for hardware accelerators
> >>>> + *
> >>>> + * Copyright 2020 SUSE LLC
> >>>> + *
> >>>> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> >>>> + * See the COPYING file in the top-level directory.
> >>>> + */
> >>>> +
> >>>> +#ifndef TCG_CPU_OPS_H
> >>>> +#define TCG_CPU_OPS_H
> >>>> +
> >>>> +/**
> >>>> + * struct TcgCpuOperations: TCG operations specific to a CPU class
> >>>> + */
> >>>> +typedef struct TcgCpuOperations {
> >>>> +    /**
> >>>> +     * @initialize: Initalize TCG state
> >>>> +     *
> >>>> +     * Called when the first CPU is realized.
> >>>> +     */
> >>>> +    void (*initialize)(void);
> >>>> +} TcgCpuOperations;
> >>>> +
> >>>> +#endif /* TCG_CPU_OPS_H */
> >>> ...
> >>>
> >>>> diff --git a/target/arm/cpu.c b/target/arm/cpu.c
> >>>> index 07492e9f9a..1fa9382a7c 100644
> >>>> --- a/target/arm/cpu.c
> >>>> +++ b/target/arm/cpu.c
> >>>> @@ -2261,7 +2261,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
> >>>>      cc->gdb_stop_before_watchpoint = true;
> >>>>      cc->disas_set_info = arm_disas_set_info;
> >>>>  #ifdef CONFIG_TCG
> >>>> -    cc->tcg_initialize = arm_translate_init;
> >>>> +    cc->tcg_ops.initialize = arm_translate_init;
> >>>
> >>> This one is correctly guarded by '#ifdef CONFIG_TCG'.
> >>>
> >>> For the other targets, can you either place it within
> >>> the '#ifdef CONFIG_TCG' block or if there is none, add
> >>> one please?
> >>
> >> As a new #ifdef risks having additional unwanted side effects, I
> >> would prefer to do it in separate patch, just in case.
> >>
> >> This also applies to the #ifdef Claudio added to hw/core/cpu.h
> >> above.  In case we really want to do it, I would do it in a
> >> separate patch.
> > 
> > Hi Eduardo,
> > 
> > yes, once things are settling we should dispose of as many #ifdefs are possible
> 
> 
> By that I mean, as targets are adapted (arm, s390, ...) things can be refactored in a similar was as for x86,
> so that the ifdefs disappear, and meson instead controls which pieces are built.
> 
> When it comes to the extra field, it was already very useful to have it #ifdef ed,
> because it identified quite a few problem with the existing patches, ie, code that was trying to use the field even though it was not there.
> 
> So this step helps with finding all the right pieces to refactor away,
> and then once things are in their proper place, we can take away the ifdef I think.

That's a good point.  Grepping for CONFIG_TCG will help us find
out cases where the code still has to be moved to a separate
file.

I was probably being overly cautious about the ifdef.  CONFIG_TCG
is not as tricky as target-specific macros that can't be used in
any header.

-- 
Eduardo



  reply	other threads:[~2020-12-04 20:35 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-30  2:35 [RFC v7 00/22] i386 cleanup Claudio Fontana
2020-11-30  2:35 ` [RFC v7 01/22] i386: move kvm accel files into kvm/ Claudio Fontana
2020-11-30  2:35 ` [RFC v7 02/22] i386: move whpx accel files into whpx/ Claudio Fontana
2020-11-30  2:35 ` [RFC v7 03/22] i386: move hax accel files into hax/ Claudio Fontana
2020-11-30  2:35 ` [RFC v7 04/22] i386: hvf: remove stale MAINTAINERS entry for old hvf stubs Claudio Fontana
2020-11-30  2:35 ` [RFC v7 05/22] i386: move TCG accel files into tcg/ Claudio Fontana
2020-11-30  2:35 ` [RFC v7 06/22] i386: move cpu dump out of helper.c into cpu-dump.c Claudio Fontana
2020-11-30  2:35 ` [RFC v7 07/22] i386: move TCG cpu class initialization out of helper.c Claudio Fontana
2020-11-30  2:35 ` [RFC v7 08/22] tcg: cpu_exec_{enter,exit} helpers Claudio Fontana
2020-11-30  2:35 ` [RFC v7 09/22] tcg: make CPUClass.cpu_exec_* optional Claudio Fontana
2020-11-30  2:35 ` [RFC v7 10/22] tcg: Make CPUClass.debug_excp_handler optional Claudio Fontana
2020-11-30  2:35 ` [RFC v7 11/22] cpu: Remove unnecessary noop methods Claudio Fontana
2020-11-30  2:35 ` [RFC v7 12/22] cpu: Introduce TCGCpuOperations struct Claudio Fontana
2020-12-04 17:10   ` Philippe Mathieu-Daudé
2020-12-04 17:28     ` Eduardo Habkost
2020-12-04 18:04       ` Claudio Fontana
2020-12-04 18:07         ` Claudio Fontana
2020-12-04 18:29           ` Eduardo Habkost [this message]
2020-12-04 18:02     ` Claudio Fontana
2020-11-30  2:35 ` [RFC v7 13/22] cpu: Move synchronize_from_tb() to tcg_ops Claudio Fontana
2020-12-04 17:12   ` Philippe Mathieu-Daudé
2020-11-30  2:35 ` [RFC v7 14/22] cpu: Move cpu_exec_* " Claudio Fontana
2020-12-04 17:13   ` Philippe Mathieu-Daudé
2020-11-30  2:35 ` [RFC v7 15/22] cpu: Move tlb_fill " Claudio Fontana
2020-12-04 17:14   ` Philippe Mathieu-Daudé
2020-12-04 17:37     ` Eduardo Habkost
2020-12-04 18:00       ` Philippe Mathieu-Daudé
2020-12-04 18:14         ` Claudio Fontana
2020-12-04 19:27           ` Philippe Mathieu-Daudé
2020-12-05 10:06             ` Claudio Fontana
2020-12-04 18:09       ` Claudio Fontana
2020-11-30  2:35 ` [RFC v7 16/22] cpu: Move debug_excp_handler " Claudio Fontana
2020-11-30  2:35 ` [RFC v7 17/22] accel: extend AccelState and AccelClass to user-mode Claudio Fontana
2020-11-30  2:35 ` [RFC v7 18/22] accel: replace struct CpusAccel with AccelOpsClass Claudio Fontana
2020-11-30  2:35 ` [RFC v7 19/22] accel: introduce AccelCPUClass extending CPUClass Claudio Fontana
2020-11-30  2:35 ` [RFC v7 20/22] i386: split cpu accelerators from cpu.c, using AccelCPUClass Claudio Fontana
2020-11-30  2:35 ` [RFC v7 21/22] cpu-exec: refactor realizefn for all targets Claudio Fontana
2020-11-30  2:35 ` [RFC v7 22/22] cpu: introduce cpu_accel_instance_init Claudio Fontana
2020-12-04 13:54 ` [RFC v7 00/22] i386 cleanup [hw/core/cpu.c common] Claudio Fontana
2020-12-04 13:55   ` Claudio Fontana
2020-12-04 16:07   ` Paolo Bonzini
2020-12-04 17:34     ` Eduardo Habkost
2020-12-04 17:59     ` Claudio Fontana

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201204182932.GR3836@habkost.net \
    --to=ehabkost@redhat.com \
    --cc=anthony.perard@citrix.com \
    --cc=brogers@suse.com \
    --cc=cfontana@suse.de \
    --cc=colin.xu@intel.com \
    --cc=cota@braap.org \
    --cc=dfaggioli@suse.com \
    --cc=dirty@apple.com \
    --cc=haxm-team@intel.com \
    --cc=jasowang@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=ohering@suse.de \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=r.bolshakov@yadro.com \
    --cc=richard.henderson@linaro.org \
    --cc=sstabellini@kernel.org \
    --cc=sunilmut@microsoft.com \
    --cc=thuth@redhat.com \
    --cc=wenchao.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.