Hi all,
we seem to have problems with structure alignment in the new version of the PCUIF protocol:
PCUIFv9: sizeof(struct gsm_pcu_if) -> 212; 212 % 4 == 0 PCUIFv10: sizeof(struct gsm_pcu_if) -> 1006; 1006 % 4 != 0
I think we would need to add/remove some padding. The question is whether we should make sure that all structures are aligned, or having the top level struct gsm_pcu_if aligned would be enough?
Even in PCUIFv9 not all structures are properly aligned:
sizeof(struct gsm_pcu_if_data_cnf_dt) -> 21; 21 % 4 -> 1, sizeof(struct gsm_pcu_if_rts_req) -> 13; 13 % 4 -> 1, sizeof(struct gsm_pcu_if_rach_ind) -> 15; 15 % 4 -> 3, sizeof(struct gsm_pcu_if_pag_req) -> 11; 11 % 4 -> 3, sizeof(struct gsm_pcu_if_susp_req) -> 11; 11 % 4 -> 3.
I devise by 4 because the widest member is uint32_t in all cases.
Kind regards, Vadim.
Hi all,
we seem to have problems with structure alignment in the new version of the PCUIF protocol:
PCUIFv9: sizeof(struct gsm_pcu_if) -> 212; 212 % 4 == 0 PCUIFv10: sizeof(struct gsm_pcu_if) -> 1006; 1006 % 4 != 0
I think we would need to add/remove some padding. The question is whether we should make sure that all structures are aligned, or having the top level struct gsm_pcu_if aligned would be enough?
Even in PCUIFv9 not all structures are properly aligned:
sizeof(struct gsm_pcu_if_data_cnf_dt) -> 21; 21 % 4 -> 1, sizeof(struct gsm_pcu_if_rts_req) -> 13; 13 % 4 -> 1, sizeof(struct gsm_pcu_if_rach_ind) -> 15; 15 % 4 -> 3, sizeof(struct gsm_pcu_if_pag_req) -> 11; 11 % 4 -> 3, sizeof(struct gsm_pcu_if_susp_req) -> 11; 11 % 4 -> 3.
I devise by 4 because the widest member is uint32_t in all cases.
Kind regards, Vadim.
On Fri, Sep 18, 2020 at 03:51:54AM +0700, Vadim Yanitskiy wrote:
we seem to have problems with structure alignment in the new version of the PCUIF protocol:
PCUIFv9: sizeof(struct gsm_pcu_if) -> 212; 212 % 4 == 0 PCUIFv10: sizeof(struct gsm_pcu_if) -> 1006; 1006 % 4 != 0
the total size of the struct doesn't really matter that much.
I think we would need to add/remove some padding. The question is whether we should make sure that all structures are aligned, or having the top level struct gsm_pcu_if aligned would be enough?
I think what is important is that the individual fields / members are aligned at the natural alignment boundary of the most common architectures (so, let's say to DWORD boundary). Of course, for an uint8_t it may not be as relevant as for an unaligned uint32_t in the middle of a struct.
Otherwise each access to a member will cause unaligned accesses, which may be more expensive depending on your architecture. Even though ARMV7 suppors unaligned loads/stores, they are apparently still slower than aligned ones.
For an INFO_IND that doesn't matter, but for primitives/message we exchange at high frequency it may matter.
Regards, Harald