[PATCH] x86/HVM: shrink (pack) struct periodic_time

Jan Beulich posted 1 patch 3 weeks, 4 days ago
[PATCH] x86/HVM: shrink (pack) struct periodic_time
Posted by Jan Beulich 3 weeks, 4 days ago
Except for warned_timeout_too_short, which is used with
test_and_set_bool(), the booleans there don't need to occupy entire bytes.
With them converted to bitfields, pending_intr_nr can move up into the
vacated 4-byte slot.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/x86/include/asm/hvm/vpt.h
+++ b/xen/arch/x86/include/asm/hvm/vpt.h
@@ -21,19 +21,19 @@ typedef void time_cb(struct vcpu *v, voi
 
 struct periodic_time {
     struct list_head list;
-    bool on_list;
-    bool one_shot;
-    bool do_not_freeze;
-    bool irq_issued;
+    bool on_list:1;
+    bool one_shot:1;
+    bool do_not_freeze:1;
+    bool irq_issued:1;
+    bool level:1;
     bool warned_timeout_too_short;
-    bool level;
 #define PTSRC_isa    1 /* ISA time source */
 #define PTSRC_lapic  2 /* LAPIC time source */
 #define PTSRC_ioapic 3 /* IOAPIC time source */
     u8 source;                  /* PTSRC_ */
     u8 irq;
+    uint32_t pending_intr_nr;   /* pending timer interrupts */
     struct vcpu *vcpu;          /* vcpu timer interrupt delivers to */
-    u32 pending_intr_nr;        /* pending timer interrupts */
     uint64_t generation;        /* distinguish two armings of the same timer */
     u64 period;                 /* frequency in ns */
     s_time_t scheduled;         /* scheduled timer interrupt */
Re: [PATCH] x86/HVM: shrink (pack) struct periodic_time
Posted by Andrew Cooper 3 weeks, 4 days ago
On 29/10/2026 1:56 pm, Jan Beulich wrote:
> Except for warned_timeout_too_short, which is used with
> test_and_set_bool(), the booleans there don't need to occupy entire bytes.
> With them converted to bitfields, pending_intr_nr can move up into the
> vacated 4-byte slot.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

test_and_?_bool() are a source of multiple problems, not least because
they have no business living in xen/types.h

Next, most users of them really ought to be using the bit forms, not the
whole boolean form.

Next next, this particular warned_timeout_too_short has no business
being an atomic at all.  It's a printk_once() in disguise.  Worse, it's
a gdprink() so we're doing this atomic work for a no-op in release
builds.  Also the debug message is tantamount to useless as it fails to
identify the domain/vcpu which produced the overly short period.


At a minimum, I think you ought to convert warned_timeout_too_short to
be like the rest, rather than leaving it like this.  Or remove it; I
really do question its utility.

But, if you were to expand the test_and_?_bool() macros to finally
remove them from the code base, leaving behind just the xchg
expressions, that would also be very much appreciated.

~Andrew

Re: [PATCH] x86/HVM: shrink (pack) struct periodic_time
Posted by Jan Beulich 3 weeks, 4 days ago
On 29.10.2026 17:23, Andrew Cooper wrote:
> On 29/10/2026 1:56 pm, Jan Beulich wrote:
>> Except for warned_timeout_too_short, which is used with
>> test_and_set_bool(), the booleans there don't need to occupy entire bytes.
>> With them converted to bitfields, pending_intr_nr can move up into the
>> vacated 4-byte slot.
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 
> test_and_?_bool() are a source of multiple problems, not least because
> they have no business living in xen/types.h
> 
> Next, most users of them really ought to be using the bit forms, not the
> whole boolean form.
> 
> Next next, this particular warned_timeout_too_short has no business
> being an atomic at all.  It's a printk_once() in disguise.  Worse, it's
> a gdprink() so we're doing this atomic work for a no-op in release
> builds.  Also the debug message is tantamount to useless as it fails to
> identify the domain/vcpu which produced the overly short period.
> 
> 
> At a minimum, I think you ought to convert warned_timeout_too_short to
> be like the rest, rather than leaving it like this.  Or remove it; I
> really do question its utility.
> 
> But, if you were to expand the test_and_?_bool() macros to finally
> remove them from the code base, leaving behind just the xchg
> expressions, that would also be very much appreciated.

A lot of largely orthogonal (to this patch) work, which may indeed want
doing, yet surely not right here. There's no problem at all for someone
to do that work on top of this change, assuming it may go in.

Jan