@@ -6881,6 +6881,7 @@ void __init sched_init(void)
#ifdef CONFIG_NO_HZ_FULL
rq->last_sched_tick = 0;
#endif
+ init_cpu_concurrency(rq);
#endif
init_rq_hrtick(rq);
atomic_set(&rq->nr_iowait, 0);
@@ -7688,3 +7688,25 @@ __init void init_sched_fair_class(void)
#endif /* SMP */
}
+
+#ifdef CONFIG_SMP
+
+/*
+ * CPU ConCurrency (CC) measures the CPU load by averaging
+ * the number of running tasks. Using CC, the scheduler can
+ * evaluate the load of CPUs to improve load balance for power
+ * efficiency without sacrificing performance.
+ */
+
+void init_cpu_concurrency(struct rq *rq)
+{
+ rq->concurrency.sum = 0;
+ rq->concurrency.sum_now = 0;
+ rq->concurrency.contrib = 0;
+ rq->concurrency.nr_running = 0;
+ rq->concurrency.sum_timestamp = ULLONG_MAX;
+ rq->concurrency.contrib_timestamp = ULLONG_MAX;
+ rq->concurrency.unload = 0;
+}
+
+#endif /* CONFIG_SMP */
@@ -506,6 +506,18 @@ struct root_domain {
extern struct root_domain def_root_domain;
+struct cpu_concurrency_t {
+ u64 sum;
+ u64 sum_now;
+ u64 contrib;
+ u64 sum_timestamp;
+ u64 contrib_timestamp;
+ unsigned int nr_running;
+ int unload;
+ int dst_cpu;
+ struct cpu_stop_work unload_work;
+};
+
#endif /* CONFIG_SMP */
/*
@@ -640,6 +652,8 @@ struct rq {
#ifdef CONFIG_SMP
struct llist_head wake_list;
+
+ struct cpu_concurrency_t concurrency;
#endif
};
@@ -1182,11 +1196,15 @@ extern void trigger_load_balance(struct rq *rq);
extern void idle_enter_fair(struct rq *this_rq);
extern void idle_exit_fair(struct rq *this_rq);
+extern void init_cpu_concurrency(struct rq *rq);
+
#else
static inline void idle_enter_fair(struct rq *rq) { }
static inline void idle_exit_fair(struct rq *rq) { }
+static inline void init_cpu_concurrency(struct rq *rq) {}
+
#endif
extern void sysrq_sched_debug_show(void);
This struct is in CPU's rq and updated with rq->lock held. Signed-off-by: Yuyang Du <yuyang.du@intel.com> --- kernel/sched/core.c | 1 + kernel/sched/fair.c | 22 ++++++++++++++++++++++ kernel/sched/sched.h | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+)