[2/3] sched: introduce a macro for getting approximat CFS part of a timing value

Message ID 20240208093136.178797-2-zhaoyang.huang@unisoc.com
State New
Headers
Series None |

Commit Message

zhaoyang.huang Feb. 8, 2024, 9:31 a.m. UTC
  From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>

A timing value within CFS task could be deemed as being composed
of CFS part and RT part(preempt by RT). We would like to know the
previous value in some scenarios. Introducin a macro here to get its
approximate value by means of CPU utils.

Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
 kernel/sched/sched.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
  

Patch

diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index b0cffc9c0f0d..a6f0051d0b15 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -179,6 +179,16 @@  extern int sched_rr_timeslice;
  */
 #define RUNTIME_INF		((u64)~0ULL)
 
+/*
+ * val is a period of time which composed by CFS part and RT part from CPU's
+ * point of view.
+ * This macro provide its approximate proportion of CFS part by remove the
+ * preempted time by RT.
+ */
+#define CFS_PROPORTION(task, val)               \
+	(div64_ul(task_rq(task)->cfs.avg.util_avg * val,                                \
+		  task_rq(task)->cfs.avg.util_avg + task_rq(task)->avg_rt.util_avg + 1))          \
+
 static inline int idle_policy(int policy)
 {
 	return policy == SCHED_IDLE;