mbox series

[0/8] Additional features for Hantro HEVC

Message ID 20210604130619.491200-1-benjamin.gaignard@collabora.com
Headers show
Series Additional features for Hantro HEVC | expand

Message

Benjamin Gaignard June 4, 2021, 1:06 p.m. UTC
Basic HEVC support has been added to Hantro driver in this pull request:
https://www.spinics.net/lists/linux-media/msg193744.html

Thanks to that it is now possible to support more features for this driver.

The first patch allow to log the hardware performance per macroblock.
The second patch makes the driver use compressed reference frames to
reduce memory bandwidth consumption.
Patches 3 to 5 allow to decode and produce 10-bits P010 frames.
Patch 6 make usage of G2 post processor to scale down the frames.
Patches 7 and 8 add the support of HEVC scaling matrix by adding a new
control.

All these patches enhance the HEVC support for Hantro (G2) hardware.
Unluckily they almost all touch the same pieces of code, where buffer
size, offset and addresses are set, so they have to be in this order.
They depend of the series pushed in this pull request:
https://www.spinics.net/lists/linux-media/msg193744.html

Benjamin

Benjamin Gaignard (8):
  media: hantro: Trace hevc hw cycles performance register
  media: hantro: Add support of compressed reference buffers
  media: hantro: hevc: Allow 10-bits encoded streams
  media: Add P010 video format
  media: hantro: hevc: Allow to produce 10-bit frames
  media: hantro: enumerate scaled output formats
  media: hevc: Add scaling matrix control
  media: hantro: Add scaling lists feature

 .../media/v4l/ext-ctrls-codec.rst             |  45 +++++
 .../media/v4l/pixfmt-yuv-planar.rst           |   8 +
 .../media/v4l/vidioc-queryctrl.rst            |   6 +
 drivers/media/v4l2-core/v4l2-common.c         |   1 +
 drivers/media/v4l2-core/v4l2-ctrls-core.c     |   6 +
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |   4 +
 drivers/media/v4l2-core/v4l2-ioctl.c          |   1 +
 drivers/staging/media/hantro/hantro.h         |   4 +
 drivers/staging/media/hantro/hantro_drv.c     |  32 +++-
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 175 ++++++++++++++++--
 drivers/staging/media/hantro/hantro_g2_regs.h |  12 ++
 drivers/staging/media/hantro/hantro_hevc.c    |  60 +++++-
 drivers/staging/media/hantro/hantro_hw.h      |   7 +
 drivers/staging/media/hantro/hantro_v4l2.c    |  10 +-
 drivers/staging/media/hantro/imx8m_vpu_hw.c   |   6 +
 drivers/staging/media/hantro/trace.h          |  40 ++++
 include/media/hevc-ctrls.h                    |  11 ++
 include/uapi/linux/videodev2.h                |   1 +
 18 files changed, 407 insertions(+), 22 deletions(-)
 create mode 100644 drivers/staging/media/hantro/trace.h

Comments

Benjamin Gaignard June 7, 2021, 11:20 a.m. UTC | #1
Le 04/06/2021 à 18:49, Ezequiel Garcia a écrit :
> Hi Benjamin,

>

> Thanks for posting this so quickly.

>

> On Fri, 2021-06-04 at 15:06 +0200, Benjamin Gaignard wrote:

>> Basic HEVC support has been added to Hantro driver in this pull request:

>> https://www.spinics.net/lists/linux-media/msg193744.html

>>

>> Thanks to that it is now possible to support more features for this driver.

>>

>> The first patch allow to log the hardware performance per macroblock.

>> The second patch makes the driver use compressed reference frames to

>> reduce memory bandwidth consumption.

> As I commented, it would be nice to do some measurements here


The performances measured by the first patch (the number of macroblock per cycle) remain
the same because the goal of using compressed frames is to save memory bandwidth.
That doesn't impact what is measure by the Hantro hardware block itself.
To give you an example that is the result of decoding one of the fluster reference file.

gst-launch-1.0 filesrc location=AMP_A_Samsung_7.hevc ! h265parse ! v4l2slh265dec ! fakesink

cat /sys/kernel/debug/tracing/trace
#
# entries-in-buffer/entries-written: 17/17   #P:4
#
#                                _-----=> irqs-off
#                               / _----=> need-resched
#                              | / _---=> hardirq/softirq
#                              || / _--=> preempt-depth
#                              ||| /     delay
#           TASK-PID     CPU#  ||||   TIMESTAMP  FUNCTION
#              | |         |   ||||      |         |
           <idle>-0       [000] d.h1   143.745124: hantro_hevc_perf: minor = 1,      180 cycles / mb
           <idle>-0       [000] d.h1   143.758086: hantro_hevc_perf: minor = 1,      172 cycles / mb
           <idle>-0       [000] d.h1   143.770829: hantro_hevc_perf: minor = 1,      167 cycles / mb
           <idle>-0       [000] d.h1   143.782757: hantro_hevc_perf: minor = 1,      166 cycles / mb
           <idle>-0       [000] d.h1   143.794866: hantro_hevc_perf: minor = 1,      165 cycles / mb
           <idle>-0       [000] d.h1   143.808012: hantro_hevc_perf: minor = 1,      165 cycles / mb
           <idle>-0       [000] d.h1   143.818225: hantro_hevc_perf: minor = 1,      166 cycles / mb
           <idle>-0       [000] d.h1   143.828063: hantro_hevc_perf: minor = 1,      165 cycles / mb
           <idle>-0       [000] d.h1   143.838217: hantro_hevc_perf: minor = 1,      165 cycles / mb
           <idle>-0       [000] d.h1   143.848728: hantro_hevc_perf: minor = 1,      172 cycles / mb
           <idle>-0       [000] d.h1   143.858677: hantro_hevc_perf: minor = 1,      167 cycles / mb
           <idle>-0       [000] d.h1   143.868576: hantro_hevc_perf: minor = 1,      166 cycles / mb
           <idle>-0       [000] d.h1   143.878431: hantro_hevc_perf: minor = 1,      165 cycles / mb
           <idle>-0       [000] d.h1   143.888684: hantro_hevc_perf: minor = 1,      165 cycles / mb
           <idle>-0       [000] d.h1   143.898827: hantro_hevc_perf: minor = 1,      166 cycles / mb
           <idle>-0       [000] d.h1   143.908645: hantro_hevc_perf: minor = 1,      165 cycles / mb
           <idle>-0       [000] d.h1   143.918772: hantro_hevc_perf: minor = 1,      165 cycles / mb

>

>> Patches 3 to 5 allow to decode and produce 10-bits P010 frames.

> I suppose this means that some 10-bit test vectors in Fluster HEVC

> test suite are now passing?

>

>> Patch 6 make usage of G2 post processor to scale down the frames.

>> Patches 7 and 8 add the support of HEVC scaling matrix by adding a new

>> control.

>>

> Ditto, the test vectors with scaling lists should now pass, any chance

> you post the test suite run before and after this series, just for reference?


Files like SLIST_A_Sony_5, SLIST_B_Sony_9, SLIST_C_Sony_4, SLIST_D_Sony_9 or
DBLK_A_MAIN10_VIXS_4 are now decoded by the driver.

fluster score is 70/147.
I think it could be better but, in few cases, it seems that the last frames
isn't retrieved by the userland stack but that need to be verify and debug
in an other series ;-)

Benjamin

>

> Thanks again,

> Ezequiel

>

>> All these patches enhance the HEVC support for Hantro (G2) hardware.

>> Unluckily they almost all touch the same pieces of code, where buffer

>> size, offset and addresses are set, so they have to be in this order.

>> They depend of the series pushed in this pull request:

>> https://www.spinics.net/lists/linux-media/msg193744.html

>>

>> Benjamin

>>

>> Benjamin Gaignard (8):

>>    media: hantro: Trace hevc hw cycles performance register

>>    media: hantro: Add support of compressed reference buffers

>>    media: hantro: hevc: Allow 10-bits encoded streams

>>    media: Add P010 video format

>>    media: hantro: hevc: Allow to produce 10-bit frames

>>    media: hantro: enumerate scaled output formats

>>    media: hevc: Add scaling matrix control

>>    media: hantro: Add scaling lists feature

>>

>>   .../media/v4l/ext-ctrls-codec.rst             |  45 +++++

>>   .../media/v4l/pixfmt-yuv-planar.rst           |   8 +

>>   .../media/v4l/vidioc-queryctrl.rst            |   6 +

>>   drivers/media/v4l2-core/v4l2-common.c         |   1 +

>>   drivers/media/v4l2-core/v4l2-ctrls-core.c     |   6 +

>>   drivers/media/v4l2-core/v4l2-ctrls-defs.c     |   4 +

>>   drivers/media/v4l2-core/v4l2-ioctl.c          |   1 +

>>   drivers/staging/media/hantro/hantro.h         |   4 +

>>   drivers/staging/media/hantro/hantro_drv.c     |  32 +++-

>>   .../staging/media/hantro/hantro_g2_hevc_dec.c | 175 ++++++++++++++++--

>>   drivers/staging/media/hantro/hantro_g2_regs.h |  12 ++

>>   drivers/staging/media/hantro/hantro_hevc.c    |  60 +++++-

>>   drivers/staging/media/hantro/hantro_hw.h      |   7 +

>>   drivers/staging/media/hantro/hantro_v4l2.c    |  10 +-

>>   drivers/staging/media/hantro/imx8m_vpu_hw.c   |   6 +

>>   drivers/staging/media/hantro/trace.h          |  40 ++++

>>   include/media/hevc-ctrls.h                    |  11 ++

>>   include/uapi/linux/videodev2.h                |   1 +

>>   18 files changed, 407 insertions(+), 22 deletions(-)

>>   create mode 100644 drivers/staging/media/hantro/trace.h

>>

>
Hans Verkuil June 13, 2021, 9:53 a.m. UTC | #2
On 04/06/2021 15:06, Benjamin Gaignard wrote:
> After each hevc decoded frame trace the hardware performance.

> It provides the number of hw cycles spend per decoded macroblock.

> 

> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>

> ---

>  drivers/staging/media/hantro/hantro_drv.c     |  3 ++

>  .../staging/media/hantro/hantro_g2_hevc_dec.c | 16 ++++++++

>  drivers/staging/media/hantro/hantro_g2_regs.h |  1 +

>  drivers/staging/media/hantro/hantro_hw.h      |  1 +

>  drivers/staging/media/hantro/imx8m_vpu_hw.c   |  1 +

>  drivers/staging/media/hantro/trace.h          | 40 +++++++++++++++++++


Can you rename this to hantro_trace.h? I prefer to have the driver prefix in the name.

Regards,

	Hans

>  6 files changed, 62 insertions(+)

>  create mode 100644 drivers/staging/media/hantro/trace.h

> 

> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c

> index dbc69ee0b562..6053c86b1c3f 100644

> --- a/drivers/staging/media/hantro/hantro_drv.c

> +++ b/drivers/staging/media/hantro/hantro_drv.c

> @@ -28,6 +28,9 @@

>  #include "hantro.h"

>  #include "hantro_hw.h"

>  

> +#define CREATE_TRACE_POINTS

> +#include "trace.h"

> +

>  #define DRIVER_NAME "hantro-vpu"

>  

>  int hantro_debug;

> diff --git a/drivers/staging/media/hantro/hantro_g2_hevc_dec.c b/drivers/staging/media/hantro/hantro_g2_hevc_dec.c

> index 340efb57fd18..89fac5146433 100644

> --- a/drivers/staging/media/hantro/hantro_g2_hevc_dec.c

> +++ b/drivers/staging/media/hantro/hantro_g2_hevc_dec.c

> @@ -7,6 +7,7 @@

>  

>  #include "hantro_hw.h"

>  #include "hantro_g2_regs.h"

> +#include "trace.h"

>  

>  #define HEVC_DEC_MODE	0xC

>  

> @@ -22,6 +23,21 @@ static inline void hantro_write_addr(struct hantro_dev *vpu,

>  	vdpu_write(vpu, addr & 0xffffffff, offset);

>  }

>  

> +void hantro_g2_hevc_dec_done(struct hantro_ctx *ctx)

> +{

> +	const struct hantro_hevc_dec_ctrls *ctrls = &ctx->hevc_dec.ctrls;

> +	const struct v4l2_ctrl_hevc_sps *sps = ctrls->sps;

> +	struct hantro_dev *vpu = ctx->dev;

> +	u32 hw_cycles = 0;

> +	u32 mbs = (sps->pic_width_in_luma_samples *

> +		   sps->pic_height_in_luma_samples) >> 8;

> +

> +	if (mbs)

> +		hw_cycles = vdpu_read(vpu, G2_HW_PERFORMANCE) / mbs;

> +

> +	trace_hantro_hevc_perf(ctx, hw_cycles);

> +}

> +

>  static void prepare_tile_info_buffer(struct hantro_ctx *ctx)

>  {

>  	struct hantro_dev *vpu = ctx->dev;

> diff --git a/drivers/staging/media/hantro/hantro_g2_regs.h b/drivers/staging/media/hantro/hantro_g2_regs.h

> index bb22fa921914..17d84ec9c5c2 100644

> --- a/drivers/staging/media/hantro/hantro_g2_regs.h

> +++ b/drivers/staging/media/hantro/hantro_g2_regs.h

> @@ -177,6 +177,7 @@

>  #define G2_REG_CONFIG_DEC_CLK_GATE_E		BIT(16)

>  #define G2_REG_CONFIG_DEC_CLK_GATE_IDLE_E	BIT(17)

>  

> +#define G2_HW_PERFORMANCE	(G2_SWREG(63))

>  #define G2_ADDR_DST		(G2_SWREG(65))

>  #define G2_REG_ADDR_REF(i)	(G2_SWREG(67)  + ((i) * 0x8))

>  #define G2_ADDR_DST_CHR		(G2_SWREG(99))

> diff --git a/drivers/staging/media/hantro/hantro_hw.h b/drivers/staging/media/hantro/hantro_hw.h

> index 5737a7707944..8fa0aacb61cd 100644

> --- a/drivers/staging/media/hantro/hantro_hw.h

> +++ b/drivers/staging/media/hantro/hantro_hw.h

> @@ -240,6 +240,7 @@ void hantro_h264_dec_exit(struct hantro_ctx *ctx);

>  int hantro_hevc_dec_init(struct hantro_ctx *ctx);

>  void hantro_hevc_dec_exit(struct hantro_ctx *ctx);

>  int hantro_g2_hevc_dec_run(struct hantro_ctx *ctx);

> +void hantro_g2_hevc_dec_done(struct hantro_ctx *ctx);

>  int hantro_hevc_dec_prepare_run(struct hantro_ctx *ctx);

>  dma_addr_t hantro_hevc_get_ref_buf(struct hantro_ctx *ctx, int poc);

>  void hantro_hevc_ref_remove_unused(struct hantro_ctx *ctx);

> diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c b/drivers/staging/media/hantro/imx8m_vpu_hw.c

> index ea919bfb9891..7e9e24bb5057 100644

> --- a/drivers/staging/media/hantro/imx8m_vpu_hw.c

> +++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c

> @@ -239,6 +239,7 @@ static const struct hantro_codec_ops imx8mq_vpu_g2_codec_ops[] = {

>  		.reset = imx8m_vpu_g2_reset,

>  		.init = hantro_hevc_dec_init,

>  		.exit = hantro_hevc_dec_exit,

> +		.done = hantro_g2_hevc_dec_done,

>  	},

>  };

>  

> diff --git a/drivers/staging/media/hantro/trace.h b/drivers/staging/media/hantro/trace.h

> new file mode 100644

> index 000000000000..8abe5ddb4814

> --- /dev/null

> +++ b/drivers/staging/media/hantro/trace.h

> @@ -0,0 +1,40 @@

> +/* SPDX-License-Identifier: GPL-2.0 */

> +#undef TRACE_SYSTEM

> +#define TRACE_SYSTEM hantro

> +

> +#if !defined(__HANTRO_TRACE_H__) || defined(TRACE_HEADER_MULTI_READ)

> +#define __HANTRO_TRACE_H__

> +

> +#include <linux/tracepoint.h>

> +#include <media/videobuf2-v4l2.h>

> +

> +#include "hantro.h"

> +

> +TRACE_EVENT(hantro_hevc_perf,

> +	TP_PROTO(struct hantro_ctx *ctx, u32 hw_cycles),

> +

> +	TP_ARGS(ctx, hw_cycles),

> +

> +	TP_STRUCT__entry(

> +		__field(int, minor)

> +		__field(u32, hw_cycles)

> +	),

> +

> +	TP_fast_assign(

> +		__entry->minor = ctx->fh.vdev->minor;

> +		__entry->hw_cycles = hw_cycles;

> +	),

> +

> +	TP_printk("minor = %d, %8d cycles / mb",

> +		  __entry->minor, __entry->hw_cycles)

> +);

> +

> +#endif /* __HANTRO_TRACE_H__ */

> +

> +#undef TRACE_INCLUDE_PATH

> +#define TRACE_INCLUDE_PATH ../../drivers/staging/media/hantro

> +#undef TRACE_INCLUDE_FILE

> +#define TRACE_INCLUDE_FILE trace

> +

> +/* This part must be outside protection */

> +#include <trace/define_trace.h>

>
Hans Verkuil June 13, 2021, 9:55 a.m. UTC | #3
On 13/06/2021 11:53, Hans Verkuil wrote:
> On 04/06/2021 15:06, Benjamin Gaignard wrote:

>> After each hevc decoded frame trace the hardware performance.

>> It provides the number of hw cycles spend per decoded macroblock.

>>

>> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>

>> ---

>>  drivers/staging/media/hantro/hantro_drv.c     |  3 ++

>>  .../staging/media/hantro/hantro_g2_hevc_dec.c | 16 ++++++++

>>  drivers/staging/media/hantro/hantro_g2_regs.h |  1 +

>>  drivers/staging/media/hantro/hantro_hw.h      |  1 +

>>  drivers/staging/media/hantro/imx8m_vpu_hw.c   |  1 +

>>  drivers/staging/media/hantro/trace.h          | 40 +++++++++++++++++++

> 

> Can you rename this to hantro_trace.h? I prefer to have the driver prefix in the name.


Ah, I accidentally replied to the v1, but the same comment applies to v2.

Regards,

	Hans

> 

> Regards,

> 

> 	Hans

> 

>>  6 files changed, 62 insertions(+)

>>  create mode 100644 drivers/staging/media/hantro/trace.h

>>

>> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c

>> index dbc69ee0b562..6053c86b1c3f 100644

>> --- a/drivers/staging/media/hantro/hantro_drv.c

>> +++ b/drivers/staging/media/hantro/hantro_drv.c

>> @@ -28,6 +28,9 @@

>>  #include "hantro.h"

>>  #include "hantro_hw.h"

>>  

>> +#define CREATE_TRACE_POINTS

>> +#include "trace.h"

>> +

>>  #define DRIVER_NAME "hantro-vpu"

>>  

>>  int hantro_debug;

>> diff --git a/drivers/staging/media/hantro/hantro_g2_hevc_dec.c b/drivers/staging/media/hantro/hantro_g2_hevc_dec.c

>> index 340efb57fd18..89fac5146433 100644

>> --- a/drivers/staging/media/hantro/hantro_g2_hevc_dec.c

>> +++ b/drivers/staging/media/hantro/hantro_g2_hevc_dec.c

>> @@ -7,6 +7,7 @@

>>  

>>  #include "hantro_hw.h"

>>  #include "hantro_g2_regs.h"

>> +#include "trace.h"

>>  

>>  #define HEVC_DEC_MODE	0xC

>>  

>> @@ -22,6 +23,21 @@ static inline void hantro_write_addr(struct hantro_dev *vpu,

>>  	vdpu_write(vpu, addr & 0xffffffff, offset);

>>  }

>>  

>> +void hantro_g2_hevc_dec_done(struct hantro_ctx *ctx)

>> +{

>> +	const struct hantro_hevc_dec_ctrls *ctrls = &ctx->hevc_dec.ctrls;

>> +	const struct v4l2_ctrl_hevc_sps *sps = ctrls->sps;

>> +	struct hantro_dev *vpu = ctx->dev;

>> +	u32 hw_cycles = 0;

>> +	u32 mbs = (sps->pic_width_in_luma_samples *

>> +		   sps->pic_height_in_luma_samples) >> 8;

>> +

>> +	if (mbs)

>> +		hw_cycles = vdpu_read(vpu, G2_HW_PERFORMANCE) / mbs;

>> +

>> +	trace_hantro_hevc_perf(ctx, hw_cycles);

>> +}

>> +

>>  static void prepare_tile_info_buffer(struct hantro_ctx *ctx)

>>  {

>>  	struct hantro_dev *vpu = ctx->dev;

>> diff --git a/drivers/staging/media/hantro/hantro_g2_regs.h b/drivers/staging/media/hantro/hantro_g2_regs.h

>> index bb22fa921914..17d84ec9c5c2 100644

>> --- a/drivers/staging/media/hantro/hantro_g2_regs.h

>> +++ b/drivers/staging/media/hantro/hantro_g2_regs.h

>> @@ -177,6 +177,7 @@

>>  #define G2_REG_CONFIG_DEC_CLK_GATE_E		BIT(16)

>>  #define G2_REG_CONFIG_DEC_CLK_GATE_IDLE_E	BIT(17)

>>  

>> +#define G2_HW_PERFORMANCE	(G2_SWREG(63))

>>  #define G2_ADDR_DST		(G2_SWREG(65))

>>  #define G2_REG_ADDR_REF(i)	(G2_SWREG(67)  + ((i) * 0x8))

>>  #define G2_ADDR_DST_CHR		(G2_SWREG(99))

>> diff --git a/drivers/staging/media/hantro/hantro_hw.h b/drivers/staging/media/hantro/hantro_hw.h

>> index 5737a7707944..8fa0aacb61cd 100644

>> --- a/drivers/staging/media/hantro/hantro_hw.h

>> +++ b/drivers/staging/media/hantro/hantro_hw.h

>> @@ -240,6 +240,7 @@ void hantro_h264_dec_exit(struct hantro_ctx *ctx);

>>  int hantro_hevc_dec_init(struct hantro_ctx *ctx);

>>  void hantro_hevc_dec_exit(struct hantro_ctx *ctx);

>>  int hantro_g2_hevc_dec_run(struct hantro_ctx *ctx);

>> +void hantro_g2_hevc_dec_done(struct hantro_ctx *ctx);

>>  int hantro_hevc_dec_prepare_run(struct hantro_ctx *ctx);

>>  dma_addr_t hantro_hevc_get_ref_buf(struct hantro_ctx *ctx, int poc);

>>  void hantro_hevc_ref_remove_unused(struct hantro_ctx *ctx);

>> diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c b/drivers/staging/media/hantro/imx8m_vpu_hw.c

>> index ea919bfb9891..7e9e24bb5057 100644

>> --- a/drivers/staging/media/hantro/imx8m_vpu_hw.c

>> +++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c

>> @@ -239,6 +239,7 @@ static const struct hantro_codec_ops imx8mq_vpu_g2_codec_ops[] = {

>>  		.reset = imx8m_vpu_g2_reset,

>>  		.init = hantro_hevc_dec_init,

>>  		.exit = hantro_hevc_dec_exit,

>> +		.done = hantro_g2_hevc_dec_done,

>>  	},

>>  };

>>  

>> diff --git a/drivers/staging/media/hantro/trace.h b/drivers/staging/media/hantro/trace.h

>> new file mode 100644

>> index 000000000000..8abe5ddb4814

>> --- /dev/null

>> +++ b/drivers/staging/media/hantro/trace.h

>> @@ -0,0 +1,40 @@

>> +/* SPDX-License-Identifier: GPL-2.0 */

>> +#undef TRACE_SYSTEM

>> +#define TRACE_SYSTEM hantro

>> +

>> +#if !defined(__HANTRO_TRACE_H__) || defined(TRACE_HEADER_MULTI_READ)

>> +#define __HANTRO_TRACE_H__

>> +

>> +#include <linux/tracepoint.h>

>> +#include <media/videobuf2-v4l2.h>

>> +

>> +#include "hantro.h"

>> +

>> +TRACE_EVENT(hantro_hevc_perf,

>> +	TP_PROTO(struct hantro_ctx *ctx, u32 hw_cycles),

>> +

>> +	TP_ARGS(ctx, hw_cycles),

>> +

>> +	TP_STRUCT__entry(

>> +		__field(int, minor)

>> +		__field(u32, hw_cycles)

>> +	),

>> +

>> +	TP_fast_assign(

>> +		__entry->minor = ctx->fh.vdev->minor;

>> +		__entry->hw_cycles = hw_cycles;

>> +	),

>> +

>> +	TP_printk("minor = %d, %8d cycles / mb",

>> +		  __entry->minor, __entry->hw_cycles)

>> +);

>> +

>> +#endif /* __HANTRO_TRACE_H__ */

>> +

>> +#undef TRACE_INCLUDE_PATH

>> +#define TRACE_INCLUDE_PATH ../../drivers/staging/media/hantro

>> +#undef TRACE_INCLUDE_FILE

>> +#define TRACE_INCLUDE_FILE trace

>> +

>> +/* This part must be outside protection */

>> +#include <trace/define_trace.h>

>>

>
Benjamin Gaignard June 14, 2021, 7:45 a.m. UTC | #4
Le 13/06/2021 à 11:55, Hans Verkuil a écrit :
> On 13/06/2021 11:53, Hans Verkuil wrote:

>> On 04/06/2021 15:06, Benjamin Gaignard wrote:

>>> After each hevc decoded frame trace the hardware performance.

>>> It provides the number of hw cycles spend per decoded macroblock.

>>>

>>> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>

>>> ---

>>>   drivers/staging/media/hantro/hantro_drv.c     |  3 ++

>>>   .../staging/media/hantro/hantro_g2_hevc_dec.c | 16 ++++++++

>>>   drivers/staging/media/hantro/hantro_g2_regs.h |  1 +

>>>   drivers/staging/media/hantro/hantro_hw.h      |  1 +

>>>   drivers/staging/media/hantro/imx8m_vpu_hw.c   |  1 +

>>>   drivers/staging/media/hantro/trace.h          | 40 +++++++++++++++++++

>> Can you rename this to hantro_trace.h? I prefer to have the driver prefix in the name.

> Ah, I accidentally replied to the v1, but the same comment applies to v2.


I have fix that, it will be in v3.
I just wait for more feedback before send it.

Thanks,
Benjamin

>

> Regards,

>

> 	Hans

>

>> Regards,

>>

>> 	Hans

>>

>>>   6 files changed, 62 insertions(+)

>>>   create mode 100644 drivers/staging/media/hantro/trace.h

>>>

>>> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c

>>> index dbc69ee0b562..6053c86b1c3f 100644

>>> --- a/drivers/staging/media/hantro/hantro_drv.c

>>> +++ b/drivers/staging/media/hantro/hantro_drv.c

>>> @@ -28,6 +28,9 @@

>>>   #include "hantro.h"

>>>   #include "hantro_hw.h"

>>>   

>>> +#define CREATE_TRACE_POINTS

>>> +#include "trace.h"

>>> +

>>>   #define DRIVER_NAME "hantro-vpu"

>>>   

>>>   int hantro_debug;

>>> diff --git a/drivers/staging/media/hantro/hantro_g2_hevc_dec.c b/drivers/staging/media/hantro/hantro_g2_hevc_dec.c

>>> index 340efb57fd18..89fac5146433 100644

>>> --- a/drivers/staging/media/hantro/hantro_g2_hevc_dec.c

>>> +++ b/drivers/staging/media/hantro/hantro_g2_hevc_dec.c

>>> @@ -7,6 +7,7 @@

>>>   

>>>   #include "hantro_hw.h"

>>>   #include "hantro_g2_regs.h"

>>> +#include "trace.h"

>>>   

>>>   #define HEVC_DEC_MODE	0xC

>>>   

>>> @@ -22,6 +23,21 @@ static inline void hantro_write_addr(struct hantro_dev *vpu,

>>>   	vdpu_write(vpu, addr & 0xffffffff, offset);

>>>   }

>>>   

>>> +void hantro_g2_hevc_dec_done(struct hantro_ctx *ctx)

>>> +{

>>> +	const struct hantro_hevc_dec_ctrls *ctrls = &ctx->hevc_dec.ctrls;

>>> +	const struct v4l2_ctrl_hevc_sps *sps = ctrls->sps;

>>> +	struct hantro_dev *vpu = ctx->dev;

>>> +	u32 hw_cycles = 0;

>>> +	u32 mbs = (sps->pic_width_in_luma_samples *

>>> +		   sps->pic_height_in_luma_samples) >> 8;

>>> +

>>> +	if (mbs)

>>> +		hw_cycles = vdpu_read(vpu, G2_HW_PERFORMANCE) / mbs;

>>> +

>>> +	trace_hantro_hevc_perf(ctx, hw_cycles);

>>> +}

>>> +

>>>   static void prepare_tile_info_buffer(struct hantro_ctx *ctx)

>>>   {

>>>   	struct hantro_dev *vpu = ctx->dev;

>>> diff --git a/drivers/staging/media/hantro/hantro_g2_regs.h b/drivers/staging/media/hantro/hantro_g2_regs.h

>>> index bb22fa921914..17d84ec9c5c2 100644

>>> --- a/drivers/staging/media/hantro/hantro_g2_regs.h

>>> +++ b/drivers/staging/media/hantro/hantro_g2_regs.h

>>> @@ -177,6 +177,7 @@

>>>   #define G2_REG_CONFIG_DEC_CLK_GATE_E		BIT(16)

>>>   #define G2_REG_CONFIG_DEC_CLK_GATE_IDLE_E	BIT(17)

>>>   

>>> +#define G2_HW_PERFORMANCE	(G2_SWREG(63))

>>>   #define G2_ADDR_DST		(G2_SWREG(65))

>>>   #define G2_REG_ADDR_REF(i)	(G2_SWREG(67)  + ((i) * 0x8))

>>>   #define G2_ADDR_DST_CHR		(G2_SWREG(99))

>>> diff --git a/drivers/staging/media/hantro/hantro_hw.h b/drivers/staging/media/hantro/hantro_hw.h

>>> index 5737a7707944..8fa0aacb61cd 100644

>>> --- a/drivers/staging/media/hantro/hantro_hw.h

>>> +++ b/drivers/staging/media/hantro/hantro_hw.h

>>> @@ -240,6 +240,7 @@ void hantro_h264_dec_exit(struct hantro_ctx *ctx);

>>>   int hantro_hevc_dec_init(struct hantro_ctx *ctx);

>>>   void hantro_hevc_dec_exit(struct hantro_ctx *ctx);

>>>   int hantro_g2_hevc_dec_run(struct hantro_ctx *ctx);

>>> +void hantro_g2_hevc_dec_done(struct hantro_ctx *ctx);

>>>   int hantro_hevc_dec_prepare_run(struct hantro_ctx *ctx);

>>>   dma_addr_t hantro_hevc_get_ref_buf(struct hantro_ctx *ctx, int poc);

>>>   void hantro_hevc_ref_remove_unused(struct hantro_ctx *ctx);

>>> diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c b/drivers/staging/media/hantro/imx8m_vpu_hw.c

>>> index ea919bfb9891..7e9e24bb5057 100644

>>> --- a/drivers/staging/media/hantro/imx8m_vpu_hw.c

>>> +++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c

>>> @@ -239,6 +239,7 @@ static const struct hantro_codec_ops imx8mq_vpu_g2_codec_ops[] = {

>>>   		.reset = imx8m_vpu_g2_reset,

>>>   		.init = hantro_hevc_dec_init,

>>>   		.exit = hantro_hevc_dec_exit,

>>> +		.done = hantro_g2_hevc_dec_done,

>>>   	},

>>>   };

>>>   

>>> diff --git a/drivers/staging/media/hantro/trace.h b/drivers/staging/media/hantro/trace.h

>>> new file mode 100644

>>> index 000000000000..8abe5ddb4814

>>> --- /dev/null

>>> +++ b/drivers/staging/media/hantro/trace.h

>>> @@ -0,0 +1,40 @@

>>> +/* SPDX-License-Identifier: GPL-2.0 */

>>> +#undef TRACE_SYSTEM

>>> +#define TRACE_SYSTEM hantro

>>> +

>>> +#if !defined(__HANTRO_TRACE_H__) || defined(TRACE_HEADER_MULTI_READ)

>>> +#define __HANTRO_TRACE_H__

>>> +

>>> +#include <linux/tracepoint.h>

>>> +#include <media/videobuf2-v4l2.h>

>>> +

>>> +#include "hantro.h"

>>> +

>>> +TRACE_EVENT(hantro_hevc_perf,

>>> +	TP_PROTO(struct hantro_ctx *ctx, u32 hw_cycles),

>>> +

>>> +	TP_ARGS(ctx, hw_cycles),

>>> +

>>> +	TP_STRUCT__entry(

>>> +		__field(int, minor)

>>> +		__field(u32, hw_cycles)

>>> +	),

>>> +

>>> +	TP_fast_assign(

>>> +		__entry->minor = ctx->fh.vdev->minor;

>>> +		__entry->hw_cycles = hw_cycles;

>>> +	),

>>> +

>>> +	TP_printk("minor = %d, %8d cycles / mb",

>>> +		  __entry->minor, __entry->hw_cycles)

>>> +);

>>> +

>>> +#endif /* __HANTRO_TRACE_H__ */

>>> +

>>> +#undef TRACE_INCLUDE_PATH

>>> +#define TRACE_INCLUDE_PATH ../../drivers/staging/media/hantro

>>> +#undef TRACE_INCLUDE_FILE

>>> +#define TRACE_INCLUDE_FILE trace

>>> +

>>> +/* This part must be outside protection */

>>> +#include <trace/define_trace.h>

>>>