Re: [PATCH 01/27] include/qemu/target-info-qom.h: declare TYPE_TARGET_SPECIFIC interface
Pierrick Bouvier <[email protected]> Wed, 5 Aug 2026 12:10:27 -0700
| Newsgroups | gmane.comp.emulators.qemu |
|---|---|
| Message-ID | <[email protected]> |
On 8/5/2026 9:53 AM, Daniel P. Berrangé wrote: > On Wed, Aug 05, 2026 at 09:16:20AM -0700, Pierrick Bouvier wrote: >> On 8/5/2026 7:05 AM, Daniel P. Berrangé wrote: >>> On Fri, Jul 24, 2026 at 12:09:21AM +0000, Pierrick Bouvier wrote: >>>> In the next commits, We'll replace the logic to filter QOM types per >>>> target from a static one (based on INTERFACES) to a runtime one, based >>>> on is_available() function, that can be overriden per class. >>>> >>>> Introduce the new interface we'll use for that. >>>> >>>> Signed-off-by: Pierrick Bouvier <[email protected]> >>>> --- >>>> include/qemu/target-info-qom.h | 15 +++++++++++++++ >>>> target-info-qom.c | 5 +++++ >>>> 2 files changed, 20 insertions(+) >>>> >>>> diff --git a/include/qemu/target-info-qom.h b/include/qemu/target-info-qom.h >>>> index 91be415ed33..83eb537333b 100644 >>>> --- a/include/qemu/target-info-qom.h >>>> +++ b/include/qemu/target-info-qom.h >>>> @@ -14,6 +14,21 @@ >>>> >>>> #define TYPE_TARGET_INFO "target-info" >>>> >>>> +#define TYPE_TARGET_SPECIFIC "target-specific" >>>> + >>>> +typedef struct TargetSpecific TargetSpecific; >>>> + >>>> +typedef struct TargetSpecificClass { >>>> + InterfaceClass parent_class; >>>> + >>>> + bool (*is_available)(void); >>>> +} TargetSpecificClass; >>>> + >>>> +#define TARGET_SPECIFIC(obj) \ >>>> + INTERFACE_CHECK(TargetSpecific, (obj), TYPE_TARGET_SPECIFIC) >>>> +DECLARE_CLASS_CHECKERS(TargetSpecificClass, TARGET_SPECIFIC, >>>> + TYPE_TARGET_SPECIFIC) >>> >>> Looking through the series,I don't really see the point >>> in this interface. Why is this not possible to do by >>> adding 'is_available' to MachineClass. It would make >>> the rest of the series simpler and especially avoid the >>> need to introduced yet more series of macros for defining >>> machine classes. >>> >> >> We'll need the exact same interface for cpus, and devices also. IMHO, it >> makes sense to have this in an external interface, instead of forcing it >> to be present in all cpus/devices/machines. I also considered adding it >> directly in Object class directly (would be the simplest), but I felt it >> would be hard to motivate it. > > I don't see a need for the common interface across cpus/devices/etc as > as code that's filtering only cares about the specific types. It also > definitely doesn't beloong in Object class, but the Object class could > be changed to make it simpler. > We agree on this. > The object_class_get_list() method could get a 'bool filter(ObjectClass *cl)' > callback which could be invoked on each class to filter it. > > That said I find it pretty undesirable as an approach that we're > registering classes that can't then be used in a given situation. > This has a ripple effect where every bit of code that iterates over > classes needs changing to add filtering after the fact. It is also > not great for scalability, as it means every QEMU process will have > the union of all classes for all targets registered, most of which > have to be discarded / ignored at runtime. > This is inherent to the nature of having a single binary. We need to cover those two requirements: 1. having a filter mechanism (per target) 2. have all the classes accessible for the heterogeneous machines that will be coming in the future 1. could be covered by what you describe, however, it breaks 2. For this, you need to be able to register all types by design. For listing cpus, machines and devices, we provide the filtering functions associated. The surface of what we need to change is very limited. There are less than 10 call sites with TYPE_{CPU, MACHINE, DEVICE}. > > IMHO we should never register the classes to begin with. > > The trick is dealing with dependencies/ordering during early startup. > > eg taking one random example: > > static void zynq_machine_register_types(void) > { > type_register_static(&zynq_machine_type); > } > > IMHO we ought to be able to say in that: > > static void zynq_machine_register_types(void) > { > if (target_arm()) { > type_register_static(&zynq_machine_type); > } > } > > The problem is target_arm() depends on having parsed the '-target' > argument. The type register methods are called from qemu_init_subsystems(), > which is called before we have done CLI parsing. This looks fixable > though. We already have two iterations over argv in qemu_init(). > > We can move qemu_init_subsystems after the first iteration, and > process -target in the first iteration. > I already have all this implemented in the way you describe. However, as explained above, we need to support 2, which brought the current design. It would be bad to implement something and have to change it all again in 6 months when we'll experiment with an heterogeneous machine. We also made the promise (and we'll hold it) that single-binary will not add yet another config. So the last thing I would like to see is: if (target_arm() || single_binary_...()) { type_register_static(&my_heterogeneous_machine_type); } Unfortunately, if we stick to "register only types we can use", it becomes the only way to solve it. > > With regards, > Daniel Regards, Pierrick