2024-02-08 09:32:52

by zhaoyang.huang

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

From: Zhaoyang Huang <[email protected]>

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 <[email protected]>
---
kernel/sched/sched.h | 10 ++++++++++
1 file changed, 10 insertions(+)

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;
--
2.25.1