media: venus: Update clock scaling and core selection
Subsystems (4)
v3 cover media: venus: Update clock scaling and core selection
In this patch series, clock scaling and core selection methods are updated. Current clock scaling and core selection methods are same for vpu4 and previous versions. Introducing load calculations using vpp cycles, which indicates the cycles required by video hardware to process each macroblock. Clock scaling is now done more precisely using vpp cycles. Instance is assigned to core with minimum load, instead of of static assignment.
Changes since v2 addressing the comments:
- Codec_data and vpp_cycles have renamed to codec_freq_data and vpp_freq respectively.
- Conditional check in patch 4 for checking max cores available is updated to VIDC_CORE_ID_2.
- venus_helper_decide_core renamed to venus_helper_set_core.
- scale_clocks_vpu4 renamed scale_clocks_v4.
For comment on freq fied in clk_data structure, it is getting initialized and used in scale_clocks_v4 function.
Aniket Masule (4):
media: venus: Add codec data table
media: venus: Update clock scaling
media: venus: Add interface for load per core
media: venus: Update core selection
drivers/media/platform/qcom/venus/core.c | 13 ++ drivers/media/platform/qcom/venus/core.h | 15 ++ drivers/media/platform/qcom/venus/helpers.c | 190 +++++++++++++++++++++++-- drivers/media/platform/qcom/venus/helpers.h | 3 +- drivers/media/platform/qcom/venus/hfi_helper.h | 1 + drivers/media/platform/qcom/venus/hfi_parser.h | 5 + drivers/media/platform/qcom/venus/vdec.c | 6 +- drivers/media/platform/qcom/venus/venc.c | 6 +- 8 files changed, 226 insertions(+), 13 deletions(-)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v3 1/4 media: venus: Add codec data table
Add vpp cycles for for different types of codec It indicates the cycles required by video hardware to process each macroblock. Initialize the codec data with core resources.
--- drivers/media/platform/qcom/venus/core.c | 13 +++++++++++++ drivers/media/platform/qcom/venus/core.h | 15 +++++++++++++++ drivers/media/platform/qcom/venus/helpers.c | 30 +++++++++++++++++++++++++++++ drivers/media/platform/qcom/venus/helpers.h | 1 + drivers/media/platform/qcom/venus/vdec.c | 4 ++++ drivers/media/platform/qcom/venus/venc.c | 4 ++++ 6 files changed, 67 insertions(+)
drivers/media/platform/qcom/venus/core.c +13 -0
@@ -473,9 +473,22 @@ static __maybe_unused int venus_runtime_resume(struct device *dev) { 244800, 100000000 }, /* 1920x1080@30 */ }; +static struct codec_freq_data sdm845_codec_freq_data[] = { + {V4L2_PIX_FMT_H264 ,VIDC_SESSION_TYPE_ENC ,675 }, + {V4L2_PIX_FMT_HEVC ,VIDC_SESSION_TYPE_ENC ,675 }, + {V4L2_PIX_FMT_VP8 ,VIDC_SESSION_TYPE_ENC ,675 }, + {V4L2_PIX_FMT_MPEG2 ,VIDC_SESSION_TYPE_DEC ,200 }, + {V4L2_PIX_FMT_H264 ,VIDC_SESSION_TYPE_DEC ,200 }, + {V4L2_PIX_FMT_HEVC ,VIDC_SESSION_TYPE_DEC ,200 }, + {V4L2_PIX_FMT_VP8 ,VIDC_SESSION_TYPE_DEC ,200 }, + {V4L2_PIX_FMT_VP9 ,VIDC_SESSION_TYPE_DEC ,200 }, +}; +static const struct venus_resources sdm845_res = { .freq_tbl = sdm845_freq_table, .freq_tbl_size =ARRAY_SIZE (sdm845_freq_table), + .codec_freq_data = sdm845_codec_freq_data, + .codec_freq_data_size =ARRAY_SIZE (sdm845_codec_freq_data), .clks = {"core" ,"iface" ,"bus" }, .clks_num =3 , .max_load = 2563200,
drivers/media/platform/qcom/venus/core.h +15 -0
@@ -35,12 +35,20 @@ struct reg_val {u32 value; }; +struct codec_freq_data { +u32 pixfmt; +u32 session_type; +unsigned int vpp_freq; +}; +struct venus_resources {u64 dma_mask;const struct freq_tbl *freq_tbl;unsigned int freq_tbl_size;const struct reg_val *reg_tbl;unsigned int reg_tbl_size; +const struct codec_freq_data *codec_freq_data; +unsigned int codec_freq_data_size;const char *const clks[VIDC_CLKS_NUM_MAX ];unsigned int clks_num;enum hfi_version hfi_version;
@@ -216,6 +224,12 @@ struct venus_buffer {struct list_head ref_list; }; +struct clock_data { +u32 core_id; +unsigned long freq; +struct codec_freq_data *codec_freq_data; +}; +#define to_venus_buffer (ptr) container_of(ptr, struct venus_buffer, vb)/**
@@ -275,6 +289,7 @@ struct venus_inst {struct list_head list;struct mutex lock;struct venus_core *core; +struct clock_data clk_data;struct list_head dpbbufs;struct list_head internalbufs;struct list_head registeredbufs;
drivers/media/platform/qcom/venus/helpers.c +30 -0
@@ -715,6 +715,36 @@ int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage) }EXPORT_SYMBOL_GPL (venus_helper_set_core_usage); +int venus_helper_init_codec_data (struct venus_inst *inst) +{ +const struct codec_data *codec_data; +unsigned int i, codec_data_size; +u32 pixfmt; +int ret =0 ; + +if (!IS_V4 (inst->core)) +return 0 ; + + codec_data = inst->core->res->codec_data; + codec_data_size = inst->core->res->codec_data_size; + pixfmt = inst->session_type ==VIDC_SESSION_TYPE_DEC ? + inst->fmt_out->pixfmt : inst->fmt_cap->pixfmt; + +for (i =0 ; i < codec_data_size; i++) { +if (codec_data[i].pixfmt == pixfmt && + codec_data[i].session_type == inst->session_type) { + inst->clk_data.codec_data = &codec_data[i]; +break ; + } + } + +if (!inst->clk_data.codec_data) + ret = -EINVAL ; + +return ret; +} +EXPORT_SYMBOL_GPL (venus_helper_init_codec_data); +int venus_helper_set_num_bufs (struct venus_inst *inst,unsigned int input_bufs,unsigned int output_bufs,unsigned int output2_bufs)
drivers/media/platform/qcom/venus/helpers.h +1 -0
@@ -41,6 +41,7 @@ int venus_helper_set_output_resolution(struct venus_inst *inst, unsigned int width, unsigned int height, u32 buftype);int venus_helper_set_work_mode (struct venus_inst *inst,u32 mode); +int venus_helper_init_codec_data (struct venus_inst *inst);int venus_helper_set_core_usage (struct venus_inst *inst,u32 usage); int venus_helper_set_num_bufs(struct venus_inst *inst, unsigned int input_bufs, unsigned int output_bufs,
drivers/media/platform/qcom/venus/vdec.c +4 -0
@@ -660,6 +660,10 @@ static int vdec_init_session(struct venus_inst *inst)if (ret) goto deinit; + ret =venus_helper_init_codec_data (inst); +if (ret) + goto deinit; +return 0 ; deinit:hfi_session_deinit (inst);
drivers/media/platform/qcom/venus/venc.c +4 -0
@@ -847,6 +847,10 @@ static int venc_init_session(struct venus_inst *inst)if (ret) goto deinit; + ret =venus_helper_init_codec_data (inst); +if (ret) + goto deinit; + ret =venc_set_properties (inst);if (ret) goto deinit;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v3 1/4] media: venus: Add codec data table
Quoted 47 lines · Aniket Masule
Add vpp cycles for for different types of codec It indicates the cycles required by video hardware to process each macroblock. Initialize the codec data with core resources.
Signed-off-by Aniket Masule <[email protected]>--- drivers/media/platform/qcom/venus/core.c | 13 +++++++++++++ drivers/media/platform/qcom/venus/core.h | 15 +++++++++++++++ drivers/media/platform/qcom/venus/helpers.c | 30 +++++++++++++++++++++++++++++ drivers/media/platform/qcom/venus/helpers.h | 1 + drivers/media/platform/qcom/venus/vdec.c | 4 ++++ drivers/media/platform/qcom/venus/venc.c | 4 ++++ 6 files changed, 67 insertions(+)drivers/media/platform/qcom/venus/core.c +13
-0@@ -473,9 +473,22 @@ static __maybe_unused int venus_runtime_resume(struct device *dev) { 244800, 100000000 }, /* 1920x1080@30 */ }; +static struct codec_freq_data sdm845_codec_freq_data[] = { + {V4L2_PIX_FMT_H264 ,VIDC_SESSION_TYPE_ENC ,675 }, + {V4L2_PIX_FMT_HEVC ,VIDC_SESSION_TYPE_ENC ,675 }, + {V4L2_PIX_FMT_VP8 ,VIDC_SESSION_TYPE_ENC ,675 }, + {V4L2_PIX_FMT_MPEG2 ,VIDC_SESSION_TYPE_DEC ,200 }, + {V4L2_PIX_FMT_H264 ,VIDC_SESSION_TYPE_DEC ,200 }, + {V4L2_PIX_FMT_HEVC ,VIDC_SESSION_TYPE_DEC ,200 }, + {V4L2_PIX_FMT_VP8 ,VIDC_SESSION_TYPE_DEC ,200 }, + {V4L2_PIX_FMT_VP9 ,VIDC_SESSION_TYPE_DEC ,200 }, +}; +static const struct venus_resources sdm845_res = { .freq_tbl = sdm845_freq_table, .freq_tbl_size =ARRAY_SIZE (sdm845_freq_table), + .codec_freq_data = sdm845_codec_freq_data, + .codec_freq_data_size =ARRAY_SIZE (sdm845_codec_freq_data), .clks = {"core" ,"iface" ,"bus" }, .clks_num =3 , .max_load = 2563200,drivers/media/platform/qcom/venus/core.h +0
-0
drivers/media/platform/qcom/venus/core.h struct reg_val { · line 41
Quoted 7 lines
drivers/media/platform/qcom/venus/core.h +4
-0@@ -35,12 +35,20 @@ struct reg_val {u32 value; }; +struct codec_freq_data { +u32 pixfmt; +u32 session_type; +unsigned int vpp_freq;
isn't unsigned long more suitable?
Quoted 39 lines
drivers/media/platform/qcom/venus/core.h +11
-0+}; +struct venus_resources {u64 dma_mask;const struct freq_tbl *freq_tbl;unsigned int freq_tbl_size;const struct reg_val *reg_tbl;unsigned int reg_tbl_size; +const struct codec_freq_data *codec_freq_data; +unsigned int codec_freq_data_size;const char *const clks[VIDC_CLKS_NUM_MAX ];unsigned int clks_num;enum hfi_version hfi_version;@@ -216,6 +224,12 @@ struct venus_buffer {struct list_head ref_list; }; +struct clock_data { +u32 core_id; +unsigned long freq; +struct codec_freq_data *codec_freq_data; +}; +#define to_venus_buffer (ptr) container_of(ptr, struct venus_buffer, vb)/** @@ -275,6 +289,7 @@ struct venus_inst {struct list_head list;struct mutex lock;struct venus_core *core; +struct clock_data clk_data;struct list_head dpbbufs;struct list_head internalbufs;struct list_head registeredbufs;drivers/media/platform/qcom/venus/helpers.c +0
-0
drivers/media/platform/qcom/venus/helpers.c int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage) · line 720
Quoted 6 lines
drivers/media/platform/qcom/venus/helpers.c +3
-0@@ -715,6 +715,36 @@ int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage) }EXPORT_SYMBOL_GPL (venus_helper_set_core_usage); +int venus_helper_init_codec_data (struct venus_inst *inst) +{ +const struct codec_data *codec_data;
Something is wrong here, there is no prototype of struct codec_data.
Signature · 2 lines
regards, Stan
Re: [PATCH v3 1/4] media: venus: Add codec data table
Hi Stan,
Quoted 53 lines · Stanimir Varbanov
Quoted 52 lines · Aniket Masule
Add vpp cycles for for different types of codec It indicates the cycles required by video hardware to process each macroblock. Initialize the codec data with core resources.
Signed-off-by Aniket Masule <[email protected]>--- drivers/media/platform/qcom/venus/core.c | 13 +++++++++++++ drivers/media/platform/qcom/venus/core.h | 15 +++++++++++++++ drivers/media/platform/qcom/venus/helpers.c | 30 +++++++++++++++++++++++++++++ drivers/media/platform/qcom/venus/helpers.h | 1 + drivers/media/platform/qcom/venus/vdec.c | 4 ++++ drivers/media/platform/qcom/venus/venc.c | 4 ++++ 6 files changed, 67 insertions(+)drivers/media/platform/qcom/venus/core.c +13
-0@@ -473,9 +473,22 @@ static __maybe_unused int venus_runtime_resume(struct device *dev) { 244800, 100000000 }, /* 1920x1080@30 */ }; +static struct codec_freq_data sdm845_codec_freq_data[] = { + {V4L2_PIX_FMT_H264 ,VIDC_SESSION_TYPE_ENC ,675 }, + {V4L2_PIX_FMT_HEVC ,VIDC_SESSION_TYPE_ENC ,675 }, + {V4L2_PIX_FMT_VP8 ,VIDC_SESSION_TYPE_ENC ,675 }, + {V4L2_PIX_FMT_MPEG2 ,VIDC_SESSION_TYPE_DEC ,200 }, + {V4L2_PIX_FMT_H264 ,VIDC_SESSION_TYPE_DEC ,200 }, + {V4L2_PIX_FMT_HEVC ,VIDC_SESSION_TYPE_DEC ,200 }, + {V4L2_PIX_FMT_VP8 ,VIDC_SESSION_TYPE_DEC ,200 }, + {V4L2_PIX_FMT_VP9 ,VIDC_SESSION_TYPE_DEC ,200 }, +}; +static const struct venus_resources sdm845_res = { .freq_tbl = sdm845_freq_table, .freq_tbl_size =ARRAY_SIZE (sdm845_freq_table), + .codec_freq_data = sdm845_codec_freq_data, + .codec_freq_data_size =ARRAY_SIZE (sdm845_codec_freq_data), .clks = {"core" ,"iface" ,"bus" }, .clks_num = 3,drivers/media/platform/qcom/venus/core.c +0
-0.max_load = 2563200,drivers/media/platform/qcom/venus/core.h +0
-0@@ -35,12 +35,20 @@ struct reg_val {u32 value; };
Quoted 7 lines
drivers/media/platform/qcom/venus/core.h struct reg_val { · line 41
Quoted 4 lines
drivers/media/platform/qcom/venus/core.h +4
-0+struct codec_freq_data { +u32 pixfmt; +u32 session_type; +unsigned int vpp_freq;isn't unsigned long more suitable?
The hard-coded values for this vpp will be in few hundreds. So, unsigned int would be fine.
Quoted 44 lines
Quoted 44 lines
drivers/media/platform/qcom/venus/core.h +10
-0+}; +struct venus_resources {u64 dma_mask;const struct freq_tbl *freq_tbl;unsigned int freq_tbl_size;const struct reg_val *reg_tbl;unsigned int reg_tbl_size; +const struct codec_freq_data *codec_freq_data; +unsigned int codec_freq_data_size;const char *const clks[VIDC_CLKS_NUM_MAX ];unsigned int clks_num;enum hfi_version hfi_version;@@ -216,6 +224,12 @@ struct venus_buffer {struct list_head ref_list; }; +struct clock_data { +u32 core_id; +unsigned long freq; +struct codec_freq_data *codec_freq_data; +}; +#define to_venus_buffer (ptr) container_of(ptr, struct venus_buffer, vb)/**
drivers/media/platform/qcom/venus/core.h +1
-0@@ -275,6 +289,7 @@ struct venus_inst {struct list_head list;struct mutex lock;struct venus_core *core; +struct clock_data clk_data;struct list_head dpbbufs;struct list_head internalbufs;struct list_head registeredbufs;drivers/media/platform/qcom/venus/helpers.c +0
-0@@ -715,6 +715,36 @@ int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage) }EXPORT_SYMBOL_GPL (venus_helper_set_core_usage);
Quoted 5 lines
drivers/media/platform/qcom/venus/helpers.c int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage) · line 720
Quoted 3 lines
drivers/media/platform/qcom/venus/helpers.c +3
-0+int venus_helper_init_codec_data (struct venus_inst *inst) +{ +const struct codec_data *codec_data;Something is wrong here, there is no prototype of struct
codec_data.
Something went wrong during git rebase, will correct this.
Regards,
Aniket
PATCH v3 2/4 media: venus: Update clock scaling
In reply to Aniket MasuleCurrent clock scaling calculations are same for vpu4 and previous versions. For vpu4, Clock scaling calculations are updated with cycles/mb. This helps in getting precise clock required.
--- drivers/media/platform/qcom/venus/helpers.c | 111 ++++++++++++++++++++++++---- drivers/media/platform/qcom/venus/helpers.h | 2 +- drivers/media/platform/qcom/venus/vdec.c | 2 +- drivers/media/platform/qcom/venus/venc.c | 2 +- 4 files changed, 99 insertions(+), 18 deletions(-)
drivers/media/platform/qcom/venus/helpers.c +96 -15
@@ -348,8 +348,9 @@ static u32 load_per_type(struct venus_core *core, u32 session_type)return mbs_per_sec; } -static int load_scale_clocks (struct venus_core *core) +static int scale_clocks (struct venus_inst *inst) { +struct venus_core *core = inst->core;const struct freq_tbl *table = core->res->freq_tbl;unsigned int num_rows = core->res->freq_tbl_size;unsigned long freq = table[0 ].freq;
@@ -398,6 +399,86 @@ static int load_scale_clocks(struct venus_core *core)return ret; } +static unsigned long calculate_vpp_freq (struct venus_inst *inst) +{ +unsigned long vpp_freq =0 ; +u32 mbs_per_sec; + + mbs_per_sec =load_per_instance (inst); + vpp_freq = mbs_per_sec * inst->clk_data.codec_freq_data->vpp_freq; +/* 21 / 20 is overhead factor */ + vpp_freq += vpp_freq /20 ; + +return vpp_freq; +} + +static int scale_clocks_v4 (struct venus_inst *inst) +{ +struct venus_core *core = inst->core; +const struct freq_tbl *table = core->res->freq_tbl; +unsigned int num_rows = core->res->freq_tbl_size; + +struct clk *clk = core->clks[0 ]; +struct device *dev = core->dev; +unsigned int i; +unsigned long freq =0 , freq_core0 =0 , freq_core1 =0 ; +int ret; + + freq =calculate_vpp_freq (inst); + +if (freq > table[0 ].freq) + goto err; + +for (i =0 ; i < num_rows; i++) { +if (freq > table[i].freq) +break ; + freq = table[i].freq; + } + + inst->clk_data.freq = freq; + +mutex_lock (&core->lock); +list_for_each_entry (inst, &core->instances, list) { +if (inst->clk_data.core_id ==VIDC_CORE_ID_1 ) { + freq_core0 += inst->clk_data.freq; + }else if (inst->clk_data.core_id ==VIDC_CORE_ID_2 ) { + freq_core1 += inst->clk_data.freq; + }else if (inst->clk_data.core_id ==VIDC_CORE_ID_3 ) { + freq_core0 += inst->clk_data.freq; + freq_core1 += inst->clk_data.freq; + } + } +mutex_unlock (&core->lock); + + freq =max (freq_core0, freq_core1); + + ret =clk_set_rate (clk, freq); +if (ret) + goto err; + + ret =clk_set_rate (core->core0_clk, freq); +if (ret) + goto err; + + ret =clk_set_rate (core->core1_clk, freq); +if (ret) + goto err; + +return 0 ; + +err: +dev_err (dev,"failed to set clock rate %lu (%d)\n" , freq, ret); +return ret; +} + +static int load_scale_clocks (struct venus_inst *inst) +{ +if (IS_V4 (inst->core)) +return scale_clocks_v4 (inst); + +return scale_clocks (inst); +} +static void fill_buffer_desc (const struct venus_buffer *buf,struct hfi_buffer_desc *bd,bool response) {
@@ -715,35 +796,36 @@ int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage) }EXPORT_SYMBOL_GPL (venus_helper_set_core_usage); -int venus_helper_init_codec_data (struct venus_inst *inst) +int venus_helper_init_codec_freq_data (struct venus_inst *inst) { -const struct codec_data *codec_data; -unsigned int i, codec_data_size; +const struct codec_freq_data *codec_freq_data; +unsigned int i, codec_freq_data_size;u32 pixfmt;int ret =0 ;if (!IS_V4 (inst->core))return 0 ; - codec_data = inst->core->res->codec_data; - codec_data_size = inst->core->res->codec_data_size; + codec_freq_data = inst->core->res->codec_freq_data; + codec_freq_data_size = inst->core->res->codec_freq_data_size; pixfmt = inst->session_type ==VIDC_SESSION_TYPE_DEC ? inst->fmt_out->pixfmt : inst->fmt_cap->pixfmt; -for (i =0 ; i < codec_data_size; i++) { -if (codec_data[i].pixfmt == pixfmt && - codec_data[i].session_type == inst->session_type) { - inst->clk_data.codec_data = &codec_data[i]; +for (i =0 ; i < codec_freq_data_size; i++) { +if (codec_freq_data[i].pixfmt == pixfmt && + codec_freq_data[i].session_type == inst->session_type) { + inst->clk_data.codec_freq_data = + &codec_freq_data[i];break ; } } -if (!inst->clk_data.codec_data) +if (!inst->clk_data.codec_freq_data) ret = -EINVAL ;return ret; } -EXPORT_SYMBOL_GPL (venus_helper_init_codec_data); +EXPORT_SYMBOL_GPL (venus_helper_init_codec_freq_data); int venus_helper_set_num_bufs(struct venus_inst *inst, unsigned int input_bufs, unsigned int output_bufs,
@@ -1053,7 +1135,7 @@ void venus_helper_vb2_stop_streaming(struct vb2_queue *q)venus_helper_free_dpb_bufs (inst); -load_scale_clocks (core); +load_scale_clocks (inst);INIT_LIST_HEAD (&inst->registeredbufs); }
@@ -1070,7 +1152,6 @@ void venus_helper_vb2_stop_streaming(struct vb2_queue *q)int venus_helper_vb2_start_streaming (struct venus_inst *inst) { -struct venus_core *core = inst->core;int ret; ret =intbufs_alloc (inst);
@@ -1081,7 +1162,7 @@ int venus_helper_vb2_start_streaming(struct venus_inst *inst)if (ret) goto err_bufs_free; -load_scale_clocks (core); +load_scale_clocks (inst); ret =hfi_session_load_res (inst);if (ret)
drivers/media/platform/qcom/venus/helpers.h +1 -1
@@ -41,7 +41,7 @@ int venus_helper_set_output_resolution(struct venus_inst *inst, unsigned int width, unsigned int height, u32 buftype);int venus_helper_set_work_mode (struct venus_inst *inst,u32 mode); -int venus_helper_init_codec_data (struct venus_inst *inst); +int venus_helper_init_codec_freq_data (struct venus_inst *inst);int venus_helper_set_core_usage (struct venus_inst *inst,u32 usage); int venus_helper_set_num_bufs(struct venus_inst *inst, unsigned int input_bufs, unsigned int output_bufs,
drivers/media/platform/qcom/venus/vdec.c +1 -1
@@ -660,7 +660,7 @@ static int vdec_init_session(struct venus_inst *inst)if (ret) goto deinit; - ret =venus_helper_init_codec_data (inst); + ret =venus_helper_init_codec_freq_data (inst);if (ret) goto deinit;
drivers/media/platform/qcom/venus/venc.c +1 -1
@@ -847,7 +847,7 @@ static int venc_init_session(struct venus_inst *inst)if (ret) goto deinit; - ret =venus_helper_init_codec_data (inst); + ret =venus_helper_init_codec_freq_data (inst);if (ret) goto deinit;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v3 2/4] media: venus: Update clock scaling
Quoted 41 lines · Aniket Masule
Current clock scaling calculations are same for vpu4 and previous versions. For vpu4, Clock scaling calculations are updated with cycles/mb. This helps in getting precise clock required.
Signed-off-by Aniket Masule <[email protected]>--- drivers/media/platform/qcom/venus/helpers.c | 111 ++++++++++++++++++++++++---- drivers/media/platform/qcom/venus/helpers.h | 2 +- drivers/media/platform/qcom/venus/vdec.c | 2 +- drivers/media/platform/qcom/venus/venc.c | 2 +- 4 files changed, 99 insertions(+), 18 deletions(-)drivers/media/platform/qcom/venus/helpers.c +11
-1@@ -348,8 +348,9 @@ static u32 load_per_type(struct venus_core *core, u32 session_type)return mbs_per_sec; } -static int load_scale_clocks (struct venus_core *core) +static int scale_clocks (struct venus_inst *inst) { +struct venus_core *core = inst->core;const struct freq_tbl *table = core->res->freq_tbl;unsigned int num_rows = core->res->freq_tbl_size;unsigned long freq = table[0 ].freq;@@ -398,6 +399,86 @@ static int load_scale_clocks(struct venus_core *core)return ret; } +static unsigned long calculate_vpp_freq (struct venus_inst *inst) +{ +unsigned long vpp_freq =0 ; +u32 mbs_per_sec; + + mbs_per_sec =load_per_instance (inst); + vpp_freq = mbs_per_sec * inst->clk_data.codec_freq_data->vpp_freq; +/* 21 / 20 is overhead factor */ + vpp_freq += vpp_freq /20 ;
drivers/media/platform/qcom/venus/helpers.c static int load_scale_clocks(struct venus_core *core) · line 420
Quoted 10 lines
drivers/media/platform/qcom/venus/helpers.c +10
-0+ +return vpp_freq; +} + +static int scale_clocks_v4 (struct venus_inst *inst) +{ +struct venus_core *core = inst->core; +const struct freq_tbl *table = core->res->freq_tbl; +unsigned int num_rows = core->res->freq_tbl_size; +
please remove this blank line.
drivers/media/platform/qcom/venus/helpers.c static int load_scale_clocks(struct venus_core *core) · line 424
Quoted 4 lines
drivers/media/platform/qcom/venus/helpers.c +4
-0+struct clk *clk = core->clks[0 ]; +struct device *dev = core->dev; +unsigned int i; +unsigned long freq =0 , freq_core0 =0 , freq_core1 =0 ;
could you count the cores as it is done for VIDC_CORE_ID_ ? i.e. start counting from one.
drivers/media/platform/qcom/venus/helpers.c static int load_scale_clocks(struct venus_core *core) · line 430
Quoted 6 lines
drivers/media/platform/qcom/venus/helpers.c +6
-0+int ret; + + freq =calculate_vpp_freq (inst); + +if (freq > table[0 ].freq) + goto err;
if the goto is triggered the error message will be wrong. Infact the dev_err message is targeted for clk_set_rate failure.
Quoted 55 lines
drivers/media/platform/qcom/venus/helpers.c +51
-0+ +for (i =0 ; i < num_rows; i++) { +if (freq > table[i].freq) +break ; + freq = table[i].freq; + } + + inst->clk_data.freq = freq; + +mutex_lock (&core->lock); +list_for_each_entry (inst, &core->instances, list) { +if (inst->clk_data.core_id ==VIDC_CORE_ID_1 ) { + freq_core0 += inst->clk_data.freq; + }else if (inst->clk_data.core_id ==VIDC_CORE_ID_2 ) { + freq_core1 += inst->clk_data.freq; + }else if (inst->clk_data.core_id ==VIDC_CORE_ID_3 ) { + freq_core0 += inst->clk_data.freq; + freq_core1 += inst->clk_data.freq; + } + } +mutex_unlock (&core->lock); + + freq =max (freq_core0, freq_core1); + + ret =clk_set_rate (clk, freq); +if (ret) + goto err; + + ret =clk_set_rate (core->core0_clk, freq); +if (ret) + goto err; + + ret =clk_set_rate (core->core1_clk, freq); +if (ret) + goto err; + +return 0 ; + +err: +dev_err (dev,"failed to set clock rate %lu (%d)\n" , freq, ret); +return ret; +} + +static int load_scale_clocks (struct venus_inst *inst) +{ +if (IS_V4 (inst->core)) +return scale_clocks_v4 (inst); + +return scale_clocks (inst); +} +static void fill_buffer_desc (const struct venus_buffer *buf,struct hfi_buffer_desc *bd,bool response) {
drivers/media/platform/qcom/venus/helpers.c int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage) · line 721
Quoted 8 lines
drivers/media/platform/qcom/venus/helpers.c +1
-3@@ -715,35 +796,36 @@ int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage) }EXPORT_SYMBOL_GPL (venus_helper_set_core_usage); -int venus_helper_init_codec_data (struct venus_inst *inst) +int venus_helper_init_codec_freq_data (struct venus_inst *inst) { -const struct codec_data *codec_data; -unsigned int i, codec_data_size;
those deletions shouldn't exist once you fix the git rebase issue.
drivers/media/platform/qcom/venus/helpers.c int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage) · line 802
Quoted 2 lines
drivers/media/platform/qcom/venus/helpers.c +2
-0+const struct codec_freq_data *codec_freq_data; +unsigned int i, codec_freq_data_size;
could you rename the variables to shorter?
Quoted 35 lines
drivers/media/platform/qcom/venus/helpers.c +9
-8u32 pixfmt;int ret =0 ;if (!IS_V4 (inst->core))return 0 ; - codec_data = inst->core->res->codec_data; - codec_data_size = inst->core->res->codec_data_size; + codec_freq_data = inst->core->res->codec_freq_data; + codec_freq_data_size = inst->core->res->codec_freq_data_size; pixfmt = inst->session_type ==VIDC_SESSION_TYPE_DEC ? inst->fmt_out->pixfmt : inst->fmt_cap->pixfmt; -for (i =0 ; i < codec_data_size; i++) { -if (codec_data[i].pixfmt == pixfmt && - codec_data[i].session_type == inst->session_type) { - inst->clk_data.codec_data = &codec_data[i]; +for (i =0 ; i < codec_freq_data_size; i++) { +if (codec_freq_data[i].pixfmt == pixfmt && + codec_freq_data[i].session_type == inst->session_type) { + inst->clk_data.codec_freq_data = + &codec_freq_data[i];break ; } } -if (!inst->clk_data.codec_data) +if (!inst->clk_data.codec_freq_data) ret = -EINVAL ;return ret; } -EXPORT_SYMBOL_GPL (venus_helper_init_codec_data); +EXPORT_SYMBOL_GPL (venus_helper_init_codec_freq_data);
Signature · 2 lines
regards, Stan
Re: [PATCH v3 2/4] media: venus: Update clock scaling
Hi Stan,
Quoted 58 lines · Stanimir Varbanov
Quoted 44 lines · Aniket Masule
Current clock scaling calculations are same for vpu4 and previous versions. For vpu4, Clock scaling calculations are updated with cycles/mb. This helps in getting precise clock required.
Signed-off-by Aniket Masule <[email protected]>--- drivers/media/platform/qcom/venus/helpers.c | 111 ++++++++++++++++++++++++---- drivers/media/platform/qcom/venus/helpers.h | 2 +- drivers/media/platform/qcom/venus/vdec.c | 2 +- drivers/media/platform/qcom/venus/venc.c | 2 +- 4 files changed, 99 insertions(+), 18 deletions(-)drivers/media/platform/qcom/venus/helpers.c +2
-1@@ -348,8 +348,9 @@ static u32 load_per_type(struct venus_core *core, u32 session_type)return mbs_per_sec; } -static int load_scale_clocks (struct venus_core *core) +static int scale_clocks (struct venus_inst *inst) { +struct venus_core *core = inst->core;const struct freq_tbl *table = core->res->freq_tbl;unsigned int num_rows = core->res->freq_tbl_size;drivers/media/platform/qcom/venus/helpers.c +9
-0unsigned long freq = table[0 ].freq;@@ -398,6 +399,86 @@ static int load_scale_clocks(struct venus_core *core)return ret; } +static unsigned long calculate_vpp_freq (struct venus_inst *inst) +{ +unsigned long vpp_freq =0 ; +u32 mbs_per_sec; + + mbs_per_sec =load_per_instance (inst); + vpp_freq = mbs_per_sec * inst->clk_data.codec_freq_data->vpp_freq; +/* 21 / 20 is overhead factor */ + vpp_freq += vpp_freq /20 ;drivers/media/platform/qcom/venus/helpers.c static int load_scale_clocks(struct venus_core · line 421
Quoted 10 lines
drivers/media/platform/qcom/venus/helpers.c +10
-0+ +return vpp_freq; +} + +static int scale_clocks_v4 (struct venus_inst *inst) +{ +struct venus_core *core = inst->core; +const struct freq_tbl *table = core->res->freq_tbl; +unsigned int num_rows = core->res->freq_tbl_size; +please remove this blank line.
Quoted 8 lines
drivers/media/platform/qcom/venus/helpers.c static int load_scale_clocks(struct venus_core *core) · line 424
Quoted 4 lines
drivers/media/platform/qcom/venus/helpers.c +4
-0+struct clk *clk = core->clks[0 ]; +struct device *dev = core->dev; +unsigned int i; +unsigned long freq =0 , freq_core0 =0 , freq_core1 =0 ;could you count the cores as it is done for
VIDC_CORE_ID_? i.e. start counting from one.
Sure, I was aligning it with clock handle name in core, but aligning it with VIDC_CORE_ID_ would give good readability.
Quoted 10 lines
drivers/media/platform/qcom/venus/helpers.c static int load_scale_clocks(struct venus_core *core) · line 430
Quoted 6 lines
drivers/media/platform/qcom/venus/helpers.c +6
-0+int ret; + + freq =calculate_vpp_freq (inst); + +if (freq > table[0 ].freq) + goto err;if the goto is triggered the error message will be wrong. Infact the
dev_errmessage is targeted forclk_set_ratefailure.
I will add separate exit for this.
Quoted 67 lines
Quoted 55 lines
drivers/media/platform/qcom/venus/helpers.c +51
-0+ +for (i =0 ; i < num_rows; i++) { +if (freq > table[i].freq) +break ; + freq = table[i].freq; + } + + inst->clk_data.freq = freq; + +mutex_lock (&core->lock); +list_for_each_entry (inst, &core->instances, list) { +if (inst->clk_data.core_id ==VIDC_CORE_ID_1 ) { + freq_core0 += inst->clk_data.freq; + }else if (inst->clk_data.core_id ==VIDC_CORE_ID_2 ) { + freq_core1 += inst->clk_data.freq; + }else if (inst->clk_data.core_id ==VIDC_CORE_ID_3 ) { + freq_core0 += inst->clk_data.freq; + freq_core1 += inst->clk_data.freq; + } + } +mutex_unlock (&core->lock); + + freq =max (freq_core0, freq_core1); + + ret =clk_set_rate (clk, freq); +if (ret) + goto err; + + ret =clk_set_rate (core->core0_clk, freq); +if (ret) + goto err; + + ret =clk_set_rate (core->core1_clk, freq); +if (ret) + goto err; + +return 0 ; + +err: +dev_err (dev,"failed to set clock rate %lu (%d)\n" , freq, ret); +return ret; +} + +static int load_scale_clocks (struct venus_inst *inst) +{ +if (IS_V4 (inst->core)) +return scale_clocks_v4 (inst); + +return scale_clocks (inst); +} +static void fill_buffer_desc (const struct venus_buffer *buf,struct hfi_buffer_desc *bd,bool response){
drivers/media/platform/qcom/venus/helpers.c int venus_helper_set_core_usage(struct · line 722
Quoted 9 lines
drivers/media/platform/qcom/venus/helpers.c +1
-3@@ -715,35 +796,36 @@ int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage) }EXPORT_SYMBOL_GPL (venus_helper_set_core_usage ); -int venus_helper_init_codec_data (struct venus_inst *inst) +int venus_helper_init_codec_freq_data (struct venus_inst *inst) { -const struct codec_data *codec_data; -unsigned int i, codec_data_size;those deletions shouldn't exist once you fix the git rebase issue.
Quoted 5 lines
drivers/media/platform/qcom/venus/helpers.c int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage) · line 802
Quoted 2 lines
drivers/media/platform/qcom/venus/helpers.c +2
-0+const struct codec_freq_data *codec_freq_data; +unsigned int i, codec_freq_data_size;could you rename the variables to shorter?
Yes
Quoted 30 lines
Quoted 30 lines
drivers/media/platform/qcom/venus/helpers.c +8
-7u32 pixfmt;int ret =0 ;if (!IS_V4 (inst->core))return 0 ; - codec_data = inst->core->res->codec_data; - codec_data_size = inst->core->res->codec_data_size; + codec_freq_data = inst->core->res->codec_freq_data; + codec_freq_data_size = inst->core->res->codec_freq_data_size; pixfmt = inst->session_type ==VIDC_SESSION_TYPE_DEC ? inst->fmt_out->pixfmt : inst->fmt_cap->pixfmt; -for (i =0 ; i < codec_data_size; i++) { -if (codec_data[i].pixfmt == pixfmt && - codec_data[i].session_type == inst->session_type) { - inst->clk_data.codec_data = &codec_data[i]; +for (i =0 ; i < codec_freq_data_size; i++) { +if (codec_freq_data[i].pixfmt == pixfmt && + codec_freq_data[i].session_type == inst->session_type) { + inst->clk_data.codec_freq_data = + &codec_freq_data[i];break ; } } -if (!inst->clk_data.codec_data) +if (!inst->clk_data.codec_freq_data) ret = -EINVAL ;
Quoted 5 lines
drivers/media/platform/qcom/venus/helpers.c int venus_helper_set_core_usage(struct venus_inst *inst, u32 usage) · line 829
Quoted 5 lines
drivers/media/platform/qcom/venus/helpers.c +1
-1return ret; } -EXPORT_SYMBOL_GPL (venus_helper_init_codec_data); +EXPORT_SYMBOL_GPL (venus_helper_init_codec_freq_data);
Thanks,
Aniket
PATCH v3 3/4 media: venus: Add interface for load per core
In reply to Aniket MasuleAdd and interface to calculate load per core. Also, add an interface to get maximum cores available with video. This interface is preparation for updating core selection.
--- drivers/media/platform/qcom/venus/helpers.c | 19 +++++++++++++++++++ drivers/media/platform/qcom/venus/hfi_helper.h | 1 + drivers/media/platform/qcom/venus/hfi_parser.h | 5 +++++ 3 files changed, 25 insertions(+)
drivers/media/platform/qcom/venus/helpers.c +19 -0
@@ -26,6 +26,7 @@#include "helpers.h" #include "hfi_helper.h" #include "hfi_venus_io.h" +#include "hfi_parser.h" struct intbuf {struct list_head list;
@@ -331,6 +332,24 @@ static u32 load_per_instance(struct venus_inst *inst)return mbs * inst->fps; } +static u32 load_per_core (struct venus_core *core,u32 core_id) +{ +struct venus_inst *inst =NULL ; +u32 mbs_per_sec =0 , load =0 ; + +mutex_lock (&core->lock); +list_for_each_entry (inst, &core->instances, list) { +if (!(inst->clk_data.core_id == core_id)) +continue ; + + mbs_per_sec =load_per_instance (inst); + load = mbs_per_sec * inst->clk_data.codec_freq_data->vpp_freq; + } +mutex_unlock (&core->lock); + +return load; +} +static u32 load_per_type (struct venus_core *core,u32 session_type) {struct venus_inst *inst =NULL ;
drivers/media/platform/qcom/venus/hfi_helper.h +1 -0
@@ -559,6 +559,7 @@ struct hfi_bitrate {#define HFI_CAPABILITY_LCU_SIZE 0x14#define HFI_CAPABILITY_HIER_P_HYBRID_NUM_ENH_LAYERS 0x15#define HFI_CAPABILITY_MBS_PER_SECOND_POWERSAVE 0x16 +#define HFI_CAPABILITY_MAX_VIDEOCORES 0x2Bstruct hfi_capability {u32 capability_type;
drivers/media/platform/qcom/venus/hfi_parser.h +5 -0
@@ -107,4 +107,9 @@ static inline u32 frate_step(struct venus_inst *inst) return cap_step(inst, HFI_CAPABILITY_FRAMERATE); } +static inline u32 core_num_max (struct venus_inst *inst) +{ +return cap_max (inst,HFI_CAPABILITY_MAX_VIDEOCORES ); +} +#endif
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v3 3/4] media: venus: Add interface for load per core
Hi Aniket,
Quoted 36 lines · Aniket Masule
Add and interface to calculate load per core. Also, add an interface to get maximum cores available with video. This interface is preparation for updating core selection.
Signed-off-by Aniket Masule <[email protected]>--- drivers/media/platform/qcom/venus/helpers.c | 19 +++++++++++++++++++ drivers/media/platform/qcom/venus/hfi_helper.h | 1 + drivers/media/platform/qcom/venus/hfi_parser.h | 5 +++++ 3 files changed, 25 insertions(+)drivers/media/platform/qcom/venus/helpers.c +9
-0@@ -26,6 +26,7 @@#include "helpers.h" #include "hfi_helper.h" #include "hfi_venus_io.h" +#include "hfi_parser.h" struct intbuf {struct list_head list;@@ -331,6 +332,24 @@ static u32 load_per_instance(struct venus_inst *inst)return mbs * inst->fps; } +static u32 load_per_core (struct venus_core *core,u32 core_id) +{ +struct venus_inst *inst =NULL ; +u32 mbs_per_sec =0 , load =0 ; + +mutex_lock (&core->lock); +list_for_each_entry (inst, &core->instances, list) { +if (!(inst->clk_data.core_id == core_id))
drivers/media/platform/qcom/venus/helpers.c static u32 load_per_instance(struct venus_inst *inst) · line 352
Quoted 10 lines
drivers/media/platform/qcom/venus/helpers.c +10
-0+continue ; + + mbs_per_sec =load_per_instance (inst); + load = mbs_per_sec * inst->clk_data.codec_freq_data->vpp_freq; + } +mutex_unlock (&core->lock); + +return load; +} +
Please squash this patch with the next one where load_per_core() is used to avoid compiler warnings.
Signature · 2 lines
regards, Stan
PATCH v3 4/4 media: venus: Update core selection
In reply to Aniket MasulePresent core assignment is static. Introduced load balancing across the cores. Load on earch core is calculated and core with minimum load is assigned to given instance.
--- drivers/media/platform/qcom/venus/helpers.c | 52 +++++++++++++++++++++++++---- drivers/media/platform/qcom/venus/helpers.h | 2 +- drivers/media/platform/qcom/venus/vdec.c | 2 +- drivers/media/platform/qcom/venus/venc.c | 2 +- 4 files changed, 49 insertions(+), 9 deletions(-)
drivers/media/platform/qcom/venus/helpers.c +46 -6
@@ -498,6 +498,16 @@ static int load_scale_clocks(struct venus_inst *inst)return scale_clocks (inst); } +int set_core_usage (struct venus_inst *inst,u32 usage) +{ +const u32 ptype =HFI_PROPERTY_CONFIG_VIDEOCORES_USAGE ; +struct hfi_videocores_usage_type cu; + + cu.video_core_enable_mask = usage; + +return hfi_session_set_property (inst, ptype, &cu); +} +static void fill_buffer_desc (const struct venus_buffer *buf,struct hfi_buffer_desc *bd,bool response) {
@@ -801,19 +811,49 @@ int venus_helper_set_work_mode(struct venus_inst *inst, u32 mode) }EXPORT_SYMBOL_GPL (venus_helper_set_work_mode); -int venus_helper_set_core_usage (struct venus_inst *inst,u32 usage) +int venus_helper_set_core (struct venus_inst *inst) { -const u32 ptype =HFI_PROPERTY_CONFIG_VIDEOCORES_USAGE ; -struct hfi_videocores_usage_type cu; +struct venus_core *core = inst->core; +u32 min_core_id =0 , core0_load =0 , core1_load =0 ; +unsigned long min_load, max_freq, cur_inst_load; +u32 cores_max; +int ret;if (!IS_V4 (inst->core))return 0 ; - cu.video_core_enable_mask = usage; + core0_load =load_per_core (core,VIDC_CORE_ID_1 ); + core1_load =load_per_core (core,VIDC_CORE_ID_2 ); -return hfi_session_set_property (inst, ptype, &cu); + min_core_id = core0_load < core1_load ?VIDC_CORE_ID_1 :VIDC_CORE_ID_2 ; + min_load =min (core0_load, core1_load); + cores_max =core_num_max (inst); + +if (cores_max <VIDC_CORE_ID_2 ) { + min_core_id =VIDC_CORE_ID_1 ; + min_load = core0_load; + } + + cur_inst_load =load_per_instance (inst) * + inst->clk_data.codec_freq_data->vpp_freq; + max_freq = core->res->freq_tbl[0 ].freq; + +if ((cur_inst_load + min_load) > max_freq) { +dev_warn (core->dev,"HW is overloaded, needed: %lu max: %lu\n" , + cur_inst_load, max_freq); +return -EINVAL ; + } + + ret =set_core_usage (inst, min_core_id); + +if (ret) +return ret; + + inst->clk_data.core_id = min_core_id; + +return 0 ; } -EXPORT_SYMBOL_GPL (venus_helper_set_core_usage); +EXPORT_SYMBOL_GPL (venus_helper_set_core);int venus_helper_init_codec_freq_data (struct venus_inst *inst) {
drivers/media/platform/qcom/venus/helpers.h +1 -1
@@ -42,7 +42,7 @@ int venus_helper_set_output_resolution(struct venus_inst *inst, u32 buftype);int venus_helper_set_work_mode (struct venus_inst *inst,u32 mode);int venus_helper_init_codec_freq_data (struct venus_inst *inst); -int venus_helper_set_core_usage (struct venus_inst *inst,u32 usage); +int venus_helper_set_core (struct venus_inst *inst);int venus_helper_set_num_bufs (struct venus_inst *inst,unsigned int input_bufs,unsigned int output_bufs,unsigned int output2_bufs);
drivers/media/platform/qcom/venus/vdec.c +1 -1
@@ -551,7 +551,7 @@ static int vdec_output_conf(struct venus_inst *inst)if (ret)return ret; - ret =venus_helper_set_core_usage (inst,VIDC_CORE_ID_1 ); + ret =venus_helper_set_core (inst);if (ret)return ret;
drivers/media/platform/qcom/venus/venc.c +1 -1
@@ -660,7 +660,7 @@ static int venc_set_properties(struct venus_inst *inst)if (ret)return ret; - ret =venus_helper_set_core_usage (inst,VIDC_CORE_ID_2 ); + ret =venus_helper_set_core (inst);if (ret)return ret;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v3 4/4] media: venus: Update core selection
Hi,
Quoted 34 lines · Aniket Masule
Present core assignment is static. Introduced load balancing across the cores. Load on earch core is calculated and core with minimum load is assigned to given instance.
Signed-off-by Aniket Masule <[email protected]>--- drivers/media/platform/qcom/venus/helpers.c | 52 +++++++++++++++++++++++++---- drivers/media/platform/qcom/venus/helpers.h | 2 +- drivers/media/platform/qcom/venus/vdec.c | 2 +- drivers/media/platform/qcom/venus/venc.c | 2 +- 4 files changed, 49 insertions(+), 9 deletions(-)drivers/media/platform/qcom/venus/helpers.c +10
-0@@ -498,6 +498,16 @@ static int load_scale_clocks(struct venus_inst *inst)return scale_clocks (inst); } +int set_core_usage (struct venus_inst *inst,u32 usage) +{ +const u32 ptype =HFI_PROPERTY_CONFIG_VIDEOCORES_USAGE ; +struct hfi_videocores_usage_type cu; + + cu.video_core_enable_mask = usage; + +return hfi_session_set_property (inst, ptype, &cu); +} +static void fill_buffer_desc (const struct venus_buffer *buf,struct hfi_buffer_desc *bd,bool response) {
drivers/media/platform/qcom/venus/helpers.c int venus_helper_set_work_mode(struct venus_inst *inst, u32 mode) · line 817
Quoted 10 lines
drivers/media/platform/qcom/venus/helpers.c +3
-3@@ -801,19 +811,49 @@ int venus_helper_set_work_mode(struct venus_inst *inst, u32 mode) }EXPORT_SYMBOL_GPL (venus_helper_set_work_mode); -int venus_helper_set_core_usage (struct venus_inst *inst,u32 usage) +int venus_helper_set_core (struct venus_inst *inst) { -const u32 ptype =HFI_PROPERTY_CONFIG_VIDEOCORES_USAGE ; -struct hfi_videocores_usage_type cu; +struct venus_core *core = inst->core; +u32 min_core_id =0 , core0_load =0 , core1_load =0 ;
the same comment, please use the same counting scheme as for VIDC_CORE_ID_
Quoted 23 lines
drivers/media/platform/qcom/venus/helpers.c +16
-2+unsigned long min_load, max_freq, cur_inst_load; +u32 cores_max; +int ret;if (!IS_V4 (inst->core))return 0 ; - cu.video_core_enable_mask = usage; + core0_load =load_per_core (core,VIDC_CORE_ID_1 ); + core1_load =load_per_core (core,VIDC_CORE_ID_2 ); -return hfi_session_set_property (inst, ptype, &cu); + min_core_id = core0_load < core1_load ?VIDC_CORE_ID_1 :VIDC_CORE_ID_2 ; + min_load =min (core0_load, core1_load); + cores_max =core_num_max (inst); + +if (cores_max <VIDC_CORE_ID_2 ) { + min_core_id =VIDC_CORE_ID_1 ; + min_load = core0_load; + } + + cur_inst_load =load_per_instance (inst) * + inst->clk_data.codec_freq_data->vpp_freq;
drivers/media/platform/qcom/venus/helpers.c int venus_helper_set_work_mode(struct venus_inst *inst, u32 mode) · line 848
Quoted 10 lines
drivers/media/platform/qcom/venus/helpers.c +10
-0+ max_freq = core->res->freq_tbl[0 ].freq; + +if ((cur_inst_load + min_load) > max_freq) { +dev_warn (core->dev,"HW is overloaded, needed: %lu max: %lu\n" , + cur_inst_load, max_freq); +return -EINVAL ; + } + + ret =set_core_usage (inst, min_core_id); +
please, delete this blank line
Quoted 52 lines
drivers/media/platform/qcom/venus/helpers.c +7
-1+if (ret) +return ret; + + inst->clk_data.core_id = min_core_id; + +return 0 ; } -EXPORT_SYMBOL_GPL (venus_helper_set_core_usage); +EXPORT_SYMBOL_GPL (venus_helper_set_core);int venus_helper_init_codec_freq_data (struct venus_inst *inst) {drivers/media/platform/qcom/venus/helpers.h +1
-1@@ -42,7 +42,7 @@ int venus_helper_set_output_resolution(struct venus_inst *inst, u32 buftype);int venus_helper_set_work_mode (struct venus_inst *inst,u32 mode);int venus_helper_init_codec_freq_data (struct venus_inst *inst); -int venus_helper_set_core_usage (struct venus_inst *inst,u32 usage); +int venus_helper_set_core (struct venus_inst *inst);int venus_helper_set_num_bufs (struct venus_inst *inst,unsigned int input_bufs,unsigned int output_bufs,unsigned int output2_bufs);drivers/media/platform/qcom/venus/vdec.c +1
-1@@ -551,7 +551,7 @@ static int vdec_output_conf(struct venus_inst *inst)if (ret)return ret; - ret =venus_helper_set_core_usage (inst,VIDC_CORE_ID_1 ); + ret =venus_helper_set_core (inst);if (ret)return ret;drivers/media/platform/qcom/venus/venc.c +1
-1@@ -660,7 +660,7 @@ static int venc_set_properties(struct venus_inst *inst)if (ret)return ret; - ret =venus_helper_set_core_usage (inst,VIDC_CORE_ID_2 ); + ret =venus_helper_set_core (inst);if (ret)return ret;
Signature · 2 lines
regards, Stan
Re: [PATCH v3 4/4] media: venus: Update core selection
Hi Stan,
Quoted 43 lines · Stanimir Varbanov
Hi,
Quoted 40 lines · Aniket Masule
Present core assignment is static. Introduced load balancing across the cores. Load on earch core is calculated and core with minimum load is assigned to given instance.
Signed-off-by Aniket Masule <[email protected]>--- drivers/media/platform/qcom/venus/helpers.c | 52 +++++++++++++++++++++++++---- drivers/media/platform/qcom/venus/helpers.h | 2 +- drivers/media/platform/qcom/venus/vdec.c | 2 +- drivers/media/platform/qcom/venus/venc.c | 2 +- 4 files changed, 49 insertions(+), 9 deletions(-)drivers/media/platform/qcom/venus/helpers.c +10
-0@@ -498,6 +498,16 @@ static int load_scale_clocks(struct venus_inst *inst)return scale_clocks (inst); } +int set_core_usage (struct venus_inst *inst,u32 usage) +{ +const u32 ptype =HFI_PROPERTY_CONFIG_VIDEOCORES_USAGE ; +struct hfi_videocores_usage_type cu; + + cu.video_core_enable_mask = usage; + +return hfi_session_set_property (inst, ptype, &cu); +} +static void fill_buffer_desc (const struct venus_buffer *buf,struct hfi_buffer_desc *bd,bool response){
drivers/media/platform/qcom/venus/helpers.c +0
-0@@ -801,19 +811,49 @@ int venus_helper_set_work_mode(struct venus_inst *inst, u32 mode) }EXPORT_SYMBOL_GPL (venus_helper_set_work_mode);
Quoted 10 lines
drivers/media/platform/qcom/venus/helpers.c int venus_helper_set_work_mode(struct venus_inst *inst, u32 mode) · line 817
Quoted 7 lines
drivers/media/platform/qcom/venus/helpers.c +3
-3-int venus_helper_set_core_usage (struct venus_inst *inst,u32 usage) +int venus_helper_set_core (struct venus_inst *inst) { -const u32 ptype =HFI_PROPERTY_CONFIG_VIDEOCORES_USAGE ; -struct hfi_videocores_usage_type cu; +struct venus_core *core = inst->core; +u32 min_core_id =0 , core0_load =0 , core1_load =0 ;the same comment, please use the same counting scheme as for
VIDC_CORE_ID_
Yes, I will align this with VIDC_CORE_ID_.
Quoted 87 lines
Quoted 24 lines
drivers/media/platform/qcom/venus/helpers.c +16
-2+unsigned long min_load, max_freq, cur_inst_load; +u32 cores_max; +int ret;if (!IS_V4 (inst->core))return 0 ; - cu.video_core_enable_mask = usage; + core0_load =load_per_core (core,VIDC_CORE_ID_1 ); + core1_load =load_per_core (core,VIDC_CORE_ID_2 ); -return hfi_session_set_property (inst, ptype, &cu); + min_core_id = core0_load < core1_load ?VIDC_CORE_ID_1 :VIDC_CORE_ID_2 ; + min_load =min (core0_load, core1_load); + cores_max =core_num_max (inst); + +if (cores_max <VIDC_CORE_ID_2 ) { + min_core_id =VIDC_CORE_ID_1 ; + min_load = core0_load; + } + + cur_inst_load =load_per_instance (inst) * + inst->clk_data.codec_freq_data->vpp_freq;drivers/media/platform/qcom/venus/helpers.c int venus_helper_set_work_mode(struct venus_inst *inst, u32 mode) · line 848
Quoted 10 lines
drivers/media/platform/qcom/venus/helpers.c +10
-0+ max_freq = core->res->freq_tbl[0 ].freq; + +if ((cur_inst_load + min_load) > max_freq) { +dev_warn (core->dev,"HW is overloaded, needed: %lu max: %lu\n" , + cur_inst_load, max_freq); +return -EINVAL ; + } + + ret =set_core_usage (inst, min_core_id); +please, delete this blank line
Quoted 50 lines
drivers/media/platform/qcom/venus/helpers.c +7
-1+if (ret) +return ret; + + inst->clk_data.core_id = min_core_id; + +return 0 ; } -EXPORT_SYMBOL_GPL (venus_helper_set_core_usage); +EXPORT_SYMBOL_GPL (venus_helper_set_core);int
venus_helper_init_codec_freq_data(struct venus_inst *inst){drivers/media/platform/qcom/venus/helpers.h +1
-1@@ -42,7 +42,7 @@ int venus_helper_set_output_resolution(structvenus_inst *inst, u32 buftype);int venus_helper_set_work_mode (struct venus_inst *inst,u32 mode);int venus_helper_init_codec_freq_data (struct venus_inst *inst); -int venus_helper_set_core_usage (struct venus_inst *inst,u32 usage); +int venus_helper_set_core (struct venus_inst *inst); int venus_helper_set_num_bufs(struct venus_inst *inst, unsigned int input_bufs,drivers/media/platform/qcom/venus/helpers.h +0
-0unsigned int output_bufs, unsigned int output2_bufs);drivers/media/platform/qcom/venus/vdec.c +1
-1@@ -551,7 +551,7 @@ static int vdec_output_conf(struct venus_inst *inst)if (ret)return ret; - ret =venus_helper_set_core_usage (inst,VIDC_CORE_ID_1 ); + ret =venus_helper_set_core (inst);if (ret)return ret;drivers/media/platform/qcom/venus/venc.c +0
-0@@ -660,7 +660,7 @@ static int venc_set_properties(struct venus_inst *inst)if (ret)return ret;
Quoted 6 lines
drivers/media/platform/qcom/venus/venc.c static int venc_set_properties(struct venus_inst *inst) · line 665
Quoted 6 lines
drivers/media/platform/qcom/venus/venc.c +1
-1- ret =venus_helper_set_core_usage (inst,VIDC_CORE_ID_2 ); + ret =venus_helper_set_core (inst);if (ret)return ret;
Regards,
Aniket