On 11/16/2026 1:36 PM, Daniel P. Berrangé wrote:
> On Mon, Nov 16, 2026 at 12:46:39PM -0800, Pierrick Bouvier wrote:
>> 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.
> 
> To be clear, this is not a performance impact. At this point
> in the series, it is just a bit of "ugliness" when looking
> at the code emitted from the macro.
>

I see. My tolerance seems to be lower and my eyes were already hurt when
seeing those functions instead of proper functions with a struct
parameter :).

> A few patches further along, however, we need to be able to
> set a list of aliases that varies per machine. At that point
> we can't be just passing a bool value in, we need to pass a
> block of code in.
> 
> So this commit is mostly about preparing for that latter
> change, the "optimization" mentioned is just incidental.
>

Ok, let's move forward.

Reviewed-by: Pierrick Bouvier <[email protected]>


>>
>>> 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
>>
> 
> With regards,
> Daniel


Reply via email to