Skip to contentSkip to conversation

x86/HVM: shrink (pack) struct periodic_time

PATCH In review Jan Beulich 2 participants 3 messages Oct 29

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/HVM: shrink (pack) struct periodic_time

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.

xen/arch/x86/include/asm/hvm/vpt.h +6 -6
@@ -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 */
#1 lore raw
Quoted 6 lines · Jan Beulich

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.

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

#2 lore raw
Quoted 21 lines · Andrew Cooper
Quoted 6 lines · Jan Beulich

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.

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.

Quoted 7 lines

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