Re: [PATCH 09/11] media: vsp1: Provide support for extended command pools
Hi Jacopo, On 12/03/18 16:30, jacopo mondi wrote: > Hi Kieran, > just one small thing I noticed below... > > On Fri, Mar 09, 2018 at 10:04:07PM +, Kieran Bingham wrote: >> VSPD and VSP-DL devices can provide extended display lists supporting >> extended command display list objects. >> >> These extended commands require their own dma memory areas for a header >> and body specific to the command type. >> >> Implement a command pool to allocate all necessary memory in a single >> DMA allocation to reduce pressure on the TLB, and provide convenvient >> re-usable command objects for the entities to utilise. >> >> Signed-off-by: Kieran Bingham>> --- >> drivers/media/platform/vsp1/vsp1_dl.c | 189 +++- >> drivers/media/platform/vsp1/vsp1_dl.h | 3 +- >> 2 files changed, 192 insertions(+) >> >> diff --git a/drivers/media/platform/vsp1/vsp1_dl.c >> b/drivers/media/platform/vsp1/vsp1_dl.c >> index 36440a2a2c8b..6d17b8bfa21c 100644 >> --- a/drivers/media/platform/vsp1/vsp1_dl.c >> +++ b/drivers/media/platform/vsp1/vsp1_dl.c >> @@ -121,6 +121,30 @@ struct vsp1_dl_body_pool { >> }; >> >> /** >> + * struct vsp1_cmd_pool - display list body pool >> + * @dma: DMA address of the entries >> + * @size: size of the full DMA memory pool in bytes >> + * @mem: CPU memory pointer for the pool >> + * @bodies: Array of DLB structures for the pool >> + * @free: List of free DLB entries >> + * @lock: Protects the pool and free list >> + * @vsp1: the VSP1 device >> + */ >> +struct vsp1_dl_cmd_pool { >> +/* DMA allocation */ >> +dma_addr_t dma; >> +size_t size; >> +void *mem; >> + >> +struct vsp1_dl_ext_cmd *cmds; >> +struct list_head free; >> + >> +spinlock_t lock; >> + >> +struct vsp1_device *vsp1; >> +}; >> + >> +/** >> * struct vsp1_dl_list - Display list >> * @list: entry in the display list manager lists >> * @dlm: the display list manager >> @@ -176,6 +200,7 @@ struct vsp1_dl_manager { >> struct vsp1_dl_list *pending; >> >> struct vsp1_dl_body_pool *pool; >> +struct vsp1_dl_cmd_pool *autfld_cmds; >> }; >> >> /* >> - >> @@ -339,6 +364,139 @@ void vsp1_dl_body_write(struct vsp1_dl_body *dlb, u32 >> reg, u32 data) >> } >> >> /* >> - >> + * Display List Extended Command Management >> + */ >> + >> +enum vsp1_extcmd_type { >> +VSP1_EXTCMD_AUTODISP, >> +VSP1_EXTCMD_AUTOFLD, >> +}; >> + >> +struct vsp1_extended_command_info { >> +u16 opcode; >> +size_t body_size; >> +} vsp1_extended_commands[] = { >> +[VSP1_EXTCMD_AUTODISP] = { 0x02, 96 }, >> +[VSP1_EXTCMD_AUTOFLD] = { 0x03, 160 }, >> +}; > > How about making this one static and const, since it does not get > modified? Good spot. Certainly. This is just a static descriptor table of the extended command parameter sizes, so it should not change. (but could be added to in later hardware operations I presume). Cheers Kieran > > Thanks >j >
Re: [PATCH 09/11] media: vsp1: Provide support for extended command pools
Hi Kieran, just one small thing I noticed below... On Fri, Mar 09, 2018 at 10:04:07PM +, Kieran Bingham wrote: > VSPD and VSP-DL devices can provide extended display lists supporting > extended command display list objects. > > These extended commands require their own dma memory areas for a header > and body specific to the command type. > > Implement a command pool to allocate all necessary memory in a single > DMA allocation to reduce pressure on the TLB, and provide convenvient > re-usable command objects for the entities to utilise. > > Signed-off-by: Kieran Bingham> --- > drivers/media/platform/vsp1/vsp1_dl.c | 189 +++- > drivers/media/platform/vsp1/vsp1_dl.h | 3 +- > 2 files changed, 192 insertions(+) > > diff --git a/drivers/media/platform/vsp1/vsp1_dl.c > b/drivers/media/platform/vsp1/vsp1_dl.c > index 36440a2a2c8b..6d17b8bfa21c 100644 > --- a/drivers/media/platform/vsp1/vsp1_dl.c > +++ b/drivers/media/platform/vsp1/vsp1_dl.c > @@ -121,6 +121,30 @@ struct vsp1_dl_body_pool { > }; > > /** > + * struct vsp1_cmd_pool - display list body pool > + * @dma: DMA address of the entries > + * @size: size of the full DMA memory pool in bytes > + * @mem: CPU memory pointer for the pool > + * @bodies: Array of DLB structures for the pool > + * @free: List of free DLB entries > + * @lock: Protects the pool and free list > + * @vsp1: the VSP1 device > + */ > +struct vsp1_dl_cmd_pool { > + /* DMA allocation */ > + dma_addr_t dma; > + size_t size; > + void *mem; > + > + struct vsp1_dl_ext_cmd *cmds; > + struct list_head free; > + > + spinlock_t lock; > + > + struct vsp1_device *vsp1; > +}; > + > +/** > * struct vsp1_dl_list - Display list > * @list: entry in the display list manager lists > * @dlm: the display list manager > @@ -176,6 +200,7 @@ struct vsp1_dl_manager { > struct vsp1_dl_list *pending; > > struct vsp1_dl_body_pool *pool; > + struct vsp1_dl_cmd_pool *autfld_cmds; > }; > > /* > - > @@ -339,6 +364,139 @@ void vsp1_dl_body_write(struct vsp1_dl_body *dlb, u32 > reg, u32 data) > } > > /* > - > + * Display List Extended Command Management > + */ > + > +enum vsp1_extcmd_type { > + VSP1_EXTCMD_AUTODISP, > + VSP1_EXTCMD_AUTOFLD, > +}; > + > +struct vsp1_extended_command_info { > + u16 opcode; > + size_t body_size; > +} vsp1_extended_commands[] = { > + [VSP1_EXTCMD_AUTODISP] = { 0x02, 96 }, > + [VSP1_EXTCMD_AUTOFLD] = { 0x03, 160 }, > +}; How about making this one static and const, since it does not get modified? Thanks j signature.asc Description: PGP signature
Re: [PATCH 09/11] media: vsp1: Provide support for extended command pools
On 09/03/18 22:04, Kieran Bingham wrote: > VSPD and VSP-DL devices can provide extended display lists supporting > extended command display list objects. > > These extended commands require their own dma memory areas for a header > and body specific to the command type. > > Implement a command pool to allocate all necessary memory in a single > DMA allocation to reduce pressure on the TLB, and provide convenvient s/convenvient/convenient/ > re-usable command objects for the entities to utilise. > Signed-off-by: Kieran Bingham> --- I feel like this adds quite a bit of 'duplication' against the body pool implementation - and there is scope for re-factoring somehow to make a lot more of this common. I think this is still fine to go in as is for now (as an approach that is) - but I'd like to work out how to make this better as a later task. Then with a reusable implementation then we can easily move the excess display list headers (which are currently being allocated 1 for *every dlb* rather than 1 for every dl) to their own pool and allocate as appropriate. Essentially we have the following 'object's which want to have minimal DMA allocations (to reduce TLB pressure) - and are all sharing the same size. - Display list headers (72 or 96 bytes) - Display list bodys (variable size - multiple per header) if (VSPD) { - Extended display list header (16 bytes * number of bodies) - Extended display list body (autodisp 96 bytes, autofld 160 bytes) } The dma_pool API's don't seem to be suitable here because as far as I can tell it is still calling dma_alloc_coherent for each page.., rather than creating a large pre-allocated slab and carving from it. There certainly doesn't seem to be a way to say the number of elements to pre-allocate... If I'm missing something obvious here - I'd love to hear it as I don't want to re-invent any wheels! Surely this similar pattern occurs elsewhere in the kernel ? -- Kieran > drivers/media/platform/vsp1/vsp1_dl.c | 189 +++- > drivers/media/platform/vsp1/vsp1_dl.h | 3 +- > 2 files changed, 192 insertions(+) > > diff --git a/drivers/media/platform/vsp1/vsp1_dl.c > b/drivers/media/platform/vsp1/vsp1_dl.c > index 36440a2a2c8b..6d17b8bfa21c 100644 > --- a/drivers/media/platform/vsp1/vsp1_dl.c > +++ b/drivers/media/platform/vsp1/vsp1_dl.c > @@ -121,6 +121,30 @@ struct vsp1_dl_body_pool { > }; > > /** > + * struct vsp1_cmd_pool - display list body pool > + * @dma: DMA address of the entries > + * @size: size of the full DMA memory pool in bytes > + * @mem: CPU memory pointer for the pool > + * @bodies: Array of DLB structures for the pool > + * @free: List of free DLB entries > + * @lock: Protects the pool and free list > + * @vsp1: the VSP1 device > + */ > +struct vsp1_dl_cmd_pool { > + /* DMA allocation */ > + dma_addr_t dma; > + size_t size; > + void *mem; > + > + struct vsp1_dl_ext_cmd *cmds; > + struct list_head free; > + > + spinlock_t lock; > + > + struct vsp1_device *vsp1; > +}; > + > +/** > * struct vsp1_dl_list - Display list > * @list: entry in the display list manager lists > * @dlm: the display list manager > @@ -176,6 +200,7 @@ struct vsp1_dl_manager { > struct vsp1_dl_list *pending; > > struct vsp1_dl_body_pool *pool; > + struct vsp1_dl_cmd_pool *autfld_cmds; > }; > > /* > - > @@ -339,6 +364,139 @@ void vsp1_dl_body_write(struct vsp1_dl_body *dlb, u32 > reg, u32 data) > } > > /* > - > + * Display List Extended Command Management > + */ > + > +enum vsp1_extcmd_type { > + VSP1_EXTCMD_AUTODISP, > + VSP1_EXTCMD_AUTOFLD, > +}; > + > +struct vsp1_extended_command_info { > + u16 opcode; > + size_t body_size; > +} vsp1_extended_commands[] = { > + [VSP1_EXTCMD_AUTODISP] = { 0x02, 96 }, > + [VSP1_EXTCMD_AUTOFLD] = { 0x03, 160 }, > +}; > + > +/** > + * vsp1_dl_cmd_pool_create - Create a pool of commands from a single > allocation > + * @vsp1: The VSP1 device > + * @type: The command pool type > + * @num_commands: The quantity of commands to allocate > + * > + * Allocate a pool of commands each with enough memory to contain the private > + * data of each command. The allocation sizes are dependent upon the command > + * type. > + * > + * Return a pointer to a pool on success or NULL if memory can't be > allocated. > + */ > +struct vsp1_dl_cmd_pool * > +vsp1_dl_cmd_pool_create(struct vsp1_device *vsp1, enum vsp1_extcmd_type type, > + unsigned int num_cmds) > +{ > + struct vsp1_dl_cmd_pool *pool; > + unsigned int i; > + size_t cmd_size; > + > + pool = kzalloc(sizeof(*pool), GFP_KERNEL); > + if (!pool) > + return NULL; > + > + pool->cmds = kcalloc(num_cmds, sizeof(*pool->cmds), GFP_KERNEL); > +