Browse Source

video: driver: fix residency print implementation

Residency print is not working for 2 cases-
1. when the prev session stopped in the middle without
   setting clk->prev freq to 0, in next session
   the residency stats
   for the same clk freq will not come as the start time will be
   reset to 0 during next session open.
2. when last session close and clk rate not changed to 0
   but, before that print residency stats come,
   then in residency print the residency for
   the last clk freq will not come.

Change-Id: I63a59202ca145e83e0bc129105df0b0182d3cb1e
Signed-off-by: Ankush Mitra <[email protected]>
Ankush Mitra 2 năm trước cách đây
mục cha
commit
5c1e2b8431
3 tập tin đã thay đổi với 25 bổ sung75 xóa
  1. 2 0
      driver/vidc/inc/resources.h
  2. 21 4
      driver/vidc/src/resources.c
  3. 2 71
      driver/vidc/src/resources_ext.c

+ 2 - 0
driver/vidc/inc/resources.h

@@ -283,6 +283,8 @@ struct msm_vidc_resources_ops {
 		const char *name, enum msm_vidc_branch_mem_flags flag);
 	int (*clk_print_residency_stats)(struct msm_vidc_core *core);
 	int (*clk_reset_residency_stats)(struct msm_vidc_core *core);
+	int (*clk_update_residency_stats)(
+		struct msm_vidc_core *core,struct clock_info *cl, u64 rate);
 };
 
 const struct msm_vidc_resources_ops *get_resources_ops(void);

+ 21 - 4
driver/vidc/src/resources.c

@@ -29,6 +29,9 @@
 	((a) > (b) ? (a) - (b) < TRIVIAL_BW_THRESHOLD : \
 		(b) - (a) < TRIVIAL_BW_THRESHOLD)
 
+static struct clock_residency *get_residency_stats(struct clock_info *cl, u64 rate);
+static int __update_residency_stats(struct msm_vidc_core *core,
+		struct clock_info *cl, u64 rate);
 enum reset_state {
 	INIT = 1,
 	ASSERT,
@@ -1164,7 +1167,14 @@ static int reset_residency_stats(struct msm_vidc_core *core, struct clock_info *
 		residency->start_time_us = 0;
 		residency->total_time_us = 0;
 	}
-
+	/*
+	 * During the reset make sure to update start time of the clk prev freq,
+	 * because the prev clk freq might not be 0 so when the next seesion start
+	 * voting from that freq, then those resideny print will not come in stats
+	 */
+	residency = get_residency_stats(cl, cl->prev);
+	if (residency)
+		residency->start_time_us = ktime_get_ns() / 1000;
 	return rc;
 }
 
@@ -1188,8 +1198,8 @@ static struct clock_residency *get_residency_stats(struct clock_info *cl, u64 ra
 	return found ? residency : NULL;
 }
 
-static int update_residency_stats(
-	struct msm_vidc_core *core, struct clock_info *cl, u64 rate)
+static int __update_residency_stats(struct msm_vidc_core *core,
+		struct clock_info *cl, u64 rate)
 {
 	struct clock_residency *cur_residency = NULL, *prev_residency = NULL;
 	u64 cur_time_us = 0;
@@ -1243,7 +1253,7 @@ static int __set_clk_rate(struct msm_vidc_core *core, struct clock_info *cl,
 	int rc = 0;
 
 	/* update clock residency stats */
-	update_residency_stats(core, cl, rate);
+	__update_residency_stats(core, cl, rate);
 
 	/* bail early if requested clk rate is not changed */
 	if (rate == cl->prev)
@@ -1644,6 +1654,12 @@ static int __print_clock_residency_stats(struct msm_vidc_core *core)
 		if (!cl->has_scaling)
 			continue;
 
+		/*
+		 * residency for the last clk corner entry will be updated in stats
+		 * only if we call update residency with rate 0
+		 */
+		__update_residency_stats(core, cl, 0);
+
 		/* print clock residency stats */
 		print_residency_stats(core, cl);
 	}
@@ -1687,6 +1703,7 @@ static const struct msm_vidc_resources_ops res_ops = {
 	.clk_disable = __disable_unprepare_clock,
 	.clk_print_residency_stats = __print_clock_residency_stats,
 	.clk_reset_residency_stats = __reset_clock_residency_stats,
+	.clk_update_residency_stats = __update_residency_stats,
 };
 
 const struct msm_vidc_resources_ops *get_resources_ops(void)

+ 2 - 71
driver/vidc/src/resources_ext.c

@@ -291,75 +291,6 @@ static int __acquire_regulators(struct msm_vidc_core *core)
 	return rc;
 }
 
-static struct clock_residency *get_residency_stats(struct clock_info *cl, u64 rate)
-{
-	struct clock_residency *residency = NULL;
-	bool found = false;
-
-	if (!cl) {
-		d_vpr_e("%s: invalid params\n", __func__);
-		return NULL;
-	}
-
-	list_for_each_entry(residency, &cl->residency_list, list) {
-		if (residency->rate == rate) {
-			found = true;
-			break;
-		}
-	}
-
-	return found ? residency : NULL;
-}
-
-static int update_residency_stats(
-	struct msm_vidc_core *core, struct clock_info *cl, u64 rate)
-{
-	struct clock_residency *cur_residency = NULL, *prev_residency = NULL;
-	u64 cur_time_us = 0;
-	int rc = 0;
-
-	/* skip update if high or stats logs not enabled */
-	if (!(msm_vidc_debug & (VIDC_HIGH | VIDC_STAT)))
-		return 0;
-
-	/* skip update if scaling not supported */
-	if (!cl->has_scaling)
-		return 0;
-
-	/* skip update if rate not changed */
-	if (rate == cl->prev)
-		return 0;
-
-	/* get current time in ns */
-	cur_time_us = ktime_get_ns() / 1000;
-
-	/* update previous rate residency end or total time */
-	prev_residency = get_residency_stats(cl, cl->prev);
-	if (prev_residency) {
-		if (prev_residency->start_time_us)
-			prev_residency->total_time_us += cur_time_us - prev_residency->start_time_us;
-
-		/* reset start time us */
-		prev_residency->start_time_us = 0;
-	}
-
-	/* clk disable case - no need to update new entry */
-	if (rate == 0)
-		return 0;
-
-	/* check if rate entry is present */
-	cur_residency = get_residency_stats(cl, rate);
-	if (!cur_residency) {
-		d_vpr_e("%s: entry not found. rate %llu\n", __func__, rate);
-		return -EINVAL;
-	}
-
-	/* update residency start time for current rate/freq */
-	cur_residency->start_time_us = cur_time_us;
-
-	return rc;
-}
-
 #ifdef CONFIG_MSM_MMRM
 static int __set_clk_rate(struct msm_vidc_core *core, struct clock_info *cl,
 			  u64 rate)
@@ -375,7 +306,7 @@ static int __set_clk_rate(struct msm_vidc_core *core, struct clock_info *cl,
 	}
 
 	/* update clock residency stats */
-	update_residency_stats(core, cl, rate);
+	call_res_op(core, clk_update_residency_stats, core, cl, rate);
 
 	/*
 	 * This conversion is necessary since we are scaling clock values based on
@@ -423,7 +354,7 @@ static int __set_clk_rate(struct msm_vidc_core *core, struct clock_info *cl,
 	int rc = 0;
 
 	/* update clock residency stats */
-	update_residency_stats(core, cl, rate);
+	call_res_op(core, clk_update_residency_stats, core, cl, rate);
 
 	/*
 	 * This conversion is necessary since we are scaling clock values based on