Messages in this thread | | | From | Howard Yen <> | Date | Thu, 8 Feb 2024 22:57:34 +0800 | Subject | Re: [PATCH v2] dma-coherent: add support for multi coherent rmems per dev |
| |
On Thu, Feb 8, 2024 at 6:56 PM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > > On Thu, Feb 08, 2024 at 03:53:37PM +0800, Howard Yen wrote: > > On Tue, Feb 6, 2024 at 11:43 PM Andy Shevchenko > > <andriy.shevchenko@linux.intel.com> wrote: > > > On Mon, Feb 05, 2024 at 02:08:00PM +0200, Andy Shevchenko wrote: > > > > On Mon, Feb 05, 2024 at 07:23:00AM +0000, Howard Yen wrote: > > ... > > > > > > @@ -18,15 +18,9 @@ struct dma_coherent_mem { > > > > > unsigned long *bitmap; > > > > > spinlock_t spinlock; > > > > > bool use_dev_dma_pfn_offset; > > > > > + struct list_head node; > > > > > > > > Have you run `pahole`? Here I see wasted bytes for nothing. > > > > > > On top of that one may make container_of() to be no-op, by placing this member > > > to be the first one. But, double check this with bloat-o-meter (that it indeed > > > does better code generation) and on the other hand check if the current first > > > member is not performance critical and having additional pointer arithmetics is > > > okay. > > > > > > > > }; > > > > I'm trying to re-org the members as below > > > > from ===> > > > > struct dma_coherent_mem { > > void * virt_base; /* 0 8 */ > > dma_addr_t device_base; /* 8 8 */ > > unsigned long pfn_base; /* 16 8 */ > > int size; /* 24 4 */ > > > > /* XXX 4 bytes hole, try to pack */ > > > > unsigned long * bitmap; /* 32 8 */ > > spinlock_t spinlock; /* 40 4 */ > > bool use_dev_dma_pfn_offset; /* 44 1 */ > > > > /* XXX 3 bytes hole, try to pack */ > > > > struct list_head node; /* 48 16 */ > > > > /* size: 64, cachelines: 1, members: 8 */ > > /* sum members: 57, holes: 2, sum holes: 7 */ > > }; > > > > > > to ===> > > > > struct dma_coherent_mem { > > struct list_head node; /* 0 16 */ > > void * virt_base; /* 16 8 */ > > dma_addr_t device_base; /* 24 8 */ > > unsigned long pfn_base; /* 32 8 */ > > int size; /* 40 4 */ > > spinlock_t spinlock; /* 44 4 */ > > unsigned long * bitmap; /* 48 8 */ > > bool use_dev_dma_pfn_offset; /* 56 1 */ > > > > /* size: 64, cachelines: 1, members: 8 */ > > /* padding: 7 */ > > Which seems better that above, right? > > > }; > > > > Looks like there is about 7 bytes padding at the end of the structure. > > Should I add __attribute__((__packed__)) to not add the padding? > > No, __packed is about alignment, may give you much worse code generation. > With list_head member first you might get better code from the original, > check it with bloat-o-meter. > > -- > With Best Regards, > Andy Shevchenko > >
From the check result with bloat-o-meter, there is about 3.38% reduction totally from the original version. Thanks for the suggestion!
add/remove: 0/0 grow/shrink: 0/7 up/down: 0/-60 (-60) Function old new delta rmem_dma_device_release 104 100 -4 dma_release_from_dev_coherent 184 180 -4 dma_release_coherent_memory 144 140 -4 dma_mmap_from_dev_coherent 228 224 -4 dma_init_coherent_memory 292 284 -8 rmem_dma_device_init 168 152 -16 dma_declare_coherent_memory 184 164 -20 Total: Before=1776, After=1716, chg -3.38% add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0 (0) Data old new delta Total: Before=0, After=0, chg +0.00% add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0 (0) RO Data old new delta Total: Before=216, After=216, chg +0.00%
For the dev check, in the previous comment, they're in the static function and are assigned to ops function pointers, I think the check is required because they might be invoked from others.
I'll submit v3 with the members reorg, the return variable naming changes and if (!dev) return; .
-- Regards,
Howard
| |