Messages in this thread | | | Date | Fri, 7 Oct 2022 13:34:25 -0700 | From | Ricardo Neri <> | Subject | Re: [RFC PATCH 14/23] thermal: intel: hfi: Update the class of the current task |
| |
On Tue, Sep 27, 2022 at 01:46:59PM +0200, Peter Zijlstra wrote: > On Fri, Sep 09, 2022 at 04:11:56PM -0700, Ricardo Neri wrote: > > +union hfi_thread_feedback_char_msr { > > + struct { > > + u8 classid; > > + u64 __reserved:55; > > + u8 valid:1; > > + } split; > > + u64 full; > > +}; > > Urgh, did you perhaps mean: > > struct { > u64 classid :8; > u64 __reserved :55; > u64 valid :1 > }; > > ? > > Because yes, GCC does fold that into a single u64, but that's > implementation defined behaviour; the C spec doesn't require one to pack > adjacent bitfields of different types together. > > I layout of: > > u8 class; // offset 0 > u64 __reserver : 55; // offset 8 > u8 valid : 1; // offset 16 > > with a total size of 24 bytes is, AFAIU, a valid result of what you > wrote.
I checked the C99 and C11 specs and, IIUC, it does prescribe how to handle adjacent bit-fields:
"An implementation may allocate any addressable storage unit large enough to hold a bitfield. If enough space remains, a bit-field that immediately follows another bit-field in a structure shall be packed into adjacent bits of the same unit."
Hence, __reserved and valid should be packed. classid, however, it is not guaranteed to be adjacent to __reserved.
I will implement the struct are you have described.
Thanks and BR, Ricardo
| |