On 11/12/2026 5:30 AM, Daniel P. Berrangé wrote:
> Currently the pattern for DEFINE_MACHINE macros is to
> pass a boolean "latest" flag as a macro parameter, which
> is then used in a test. For example
> 
>         ...
>         if (latest) {
>             mc->alias = "s390-ccw-virtio";
>             mc->is_default = true;
>         }
> 
> On the surface this looks fine, but this is actually taking a
> build time static characteristic of the machine type and turning
> it into a runtime tunable that only ever has a single code path.
> ie the macro code expands to:
> 
>         if (true) {
>             mc->alias = "s390-ccw-virtio";
>             mc->is_default = true;
>         }
> 
> or
> 
>         if (false) {
>             mc->alias = "s390-ccw-virtio";
>             mc->is_default = true;
>         }
> 
> The compiler should optimize out the condition, but we can do
> do this explicitly by passing the desired extra initializers
> to the macro directly.
> 

Has it been measured? It looks like a very premature optimization to
remove one if that is absolutely not on any hot path.

> This makes the macro definition a bit more verbose, but it will
> facilitate forthcoming changes that require more complex
> initialization to be added to the class initializer methods.
>

As mentioned on another thread, the DEFINE_* macros seems to create more
problems than they solve, and we would gain clarity by simply accepting
the extra lines of boilerplate.

We could have exception of course (especially for machines defined in a
single file), but for global macros available in multiple files, our
life would be much more easier without all this.

Just my 2 cents.

> Signed-off-by: Daniel P. Berrangé <[email protected]>
Regards,
Pierrick

Reply via email to