Hello Maxime,
On Mon Mar 24, 2025 at 9:55 AM CET, Maxime Chevallier wrote:
On Fri, 21 Mar 2025 20:09:39 +0100
Théo Lebrun [off-list ref] wrote:
quoted
Introduce macb_dma_is_64b() and macb_dma_is_ptp() helper functions.
Many codepaths are made simpler by dropping conditional compilation.
This implies three changes:
- Always compile related structure definitions inside <macb.h>.
- Make the field hw_dma_cap in struct macb always present.
- MACB_EXT_DESC can be dropped as it is useless now.
The common case is:
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
struct macb_dma_desc_64 *desc_64;
if (bp->hw_dma_cap & HW_DMA_CAP_64B) {
desc_64 = macb_64b_desc(bp, desc);
// ...
}
#endif
And replaced by:
struct macb_dma_desc_64 *desc_64;
if (macb_dma_is_64b(bp)) {
desc_64 = macb_64b_desc(bp, desc);
// ...
}
Just a thought, but this is adding some more branches in the hotpath on
32 bits DMA setups. Did you measure any performance changes on
these platforms (if you have access to one :) )
As the caps can't be changed dynamically, maybe these helpers could be
replaced more efficiently with some static_key ? This would benefit
both 32 and 64 bits systems as the following would be more efficient
if (bp->hw_dma_cap & HW_DMA_CAP_64B) {
// ...
}
Just a thought of course, maybe this patch doesn't really hurt perfs :)
Good question! I asked myself the same thing before posting.
We go from:
void bar(struct macb *bp) {
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
if (bp->hw_dma_cap & HW_DMA_CAP_64B) {
foo();
}
#endif
}
To:
static bool macb_dma_is_64b(struct macb *bp)
{
return IS_ENABLED(CONFIG_ARCH_DMA_ADDR_T_64BIT) &&
bp->hw_dma_cap & HW_DMA_CAP_64B;
}
void bar(struct macb *bp) {
if (macb_dma_is_64b(bp)) {
foo();
}
}
In the first case, we use explicit preprocessor directives to remove
code if CONFIG_ARCH_DMA_ADDR_T_64BIT isn't defined.
In the second case, our compiler optimises away the IS_ENABLED() call.
- If false, then the branch doesn't appear.
- If true, then only the capability check is inlined in bar().
I checked the assembly on arm/arm64/MIPS.
Conclusion: the hotpath doesn't change.
Thanks,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com