Please don't use __packed unless absolutely necessary. It generates suboptimal code (byte at a time
accesses etc.) and for many of these you don't even need it.
Thank you.
Please don't use __packed unless absolutely necessary. It generates
suboptimal code (byte at a time
accesses etc.) and for many of these you don't even need it.
In the driver code, all the structs/unions marked by __packed are used to
talk with the hardware, so I think __packed is necessary here?
Do you think if it's better if we remove all the __packed, and add
static_assert(sizeof(struct XXX) == YYY) instead? e.g.
Please don't use __packed unless absolutely necessary. It generates
suboptimal code (byte at a time
accesses etc.) and for many of these you don't even need it.
In the driver code, all the structs/unions marked by __packed are used to
talk with the hardware, so I think __packed is necessary here?
It actually isan't in many cases, check with and without the __packed directive
and see if anything chasnges.
quoted hunk
Do you think if it's better if we remove all the __packed, and add
static_assert(sizeof(struct XXX) == YYY) instead? e.g.
This won't make sure the structure member offsets are what you expect.
I think you'll have to go through the structures one-by-one by hand to
figure out which ones really require the __packed attribute and which do not.
Thank you.
This won't make sure the structure member offsets are what you expect.
I think you'll have to go through the structures one-by-one by hand to
figure out which ones really require the __packed attribute and which do not.
Got it. Let me see if I can remove all the __packed.
Please don't use __packed unless absolutely necessary. It generates
suboptimal code (byte at a time
accesses etc.) and for many of these you don't even need it.
In the driver code, all the structs/unions marked by __packed are used to
talk with the hardware, so I think __packed is necessary here?
It actually isan't in many cases, check with and without the __packed
directive
and see if anything chasnges.
quoted
Do you think if it's better if we remove all the __packed, and add
static_assert(sizeof(struct XXX) == YYY) instead? e.g.
This won't make sure the structure member offsets are what you expect.
I think you'll have to go through the structures one-by-one by hand to
figure out which ones really require the __packed attribute and which do not.
For the structs containing variables with the same sizes, or already size aligned
variables, we knew the __packed has no effect. And for these structs, it doesn't
cause performance impact either, correct?
But in the future, if different sized variables are added, the __packed may
become necessary again. To prevent anyone accidently forget to add __packed
when adding new variables to these structs, can we keep the __packed for all
messages going through the "wire"?
Thanks,
- Haiyang
From: Andrew Lunn <andrew@lunn.ch> Date: 2021-04-09 13:35:53
For the structs containing variables with the same sizes, or already size aligned
variables, we knew the __packed has no effect. And for these structs, it doesn't
cause performance impact either, correct?
But in the future, if different sized variables are added, the __packed may
become necessary again. To prevent anyone accidently forget to add __packed
when adding new variables to these structs, can we keep the __packed for all
messages going through the "wire"?
It should not be a problem because anybody adding new variables should
know packed is not liked in the kernel and will take care.
If you want to be paranoid add a BUILD_BUG_ON(size(struct foo) != 42);
Andrew