@@ -19,3 +19,4 @@ obj-$(CONFIG_SCHED_AUTOGROUP) += auto_group.o
obj-$(CONFIG_SCHEDSTATS) += stats.o
obj-$(CONFIG_SCHED_DEBUG) += debug.o
obj-$(CONFIG_CGROUP_CPUACCT) += cpuacct.o
+obj-$(CONFIG_CPU_CONCURRENCY) += concurrency.o
new file mode 100644
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ *
+ */
+
+#ifdef CONFIG_CPU_CONCURRENCY
+
+#include "sched.h"
+
+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;
+}
+#endif
@@ -6884,6 +6884,8 @@ void __init sched_init(void)
#endif
init_rq_hrtick(rq);
atomic_set(&rq->nr_iowait, 0);
+
+ init_cpu_concurrency(rq);
}
set_load_weight(&init_task);
@@ -508,6 +508,17 @@ extern struct root_domain def_root_domain;
#endif /* CONFIG_SMP */
+#ifdef CONFIG_CPU_CONCURRENCY
+struct cpu_concurrency_t {
+ u64 sum;
+ u64 sum_now;
+ u64 contrib;
+ u64 sum_timestamp;
+ u64 contrib_timestamp;
+ unsigned int nr_running;
+};
+#endif
+
/*
* This is the main, per-CPU runqueue data structure.
*
@@ -643,6 +654,10 @@ struct rq {
#ifdef CONFIG_SMP
struct llist_head wake_list;
#endif
+
+#ifdef CONFIG_CPU_CONCURRENCY
+ struct cpu_concurrency_t concurrency;
+#endif
};
static inline int cpu_of(struct rq *rq)
@@ -1203,6 +1218,12 @@ extern void init_sched_dl_class(void);
extern void resched_task(struct task_struct *p);
extern void resched_cpu(int cpu);
+#ifdef CONFIG_CPU_CONCURRENCY
+extern void init_cpu_concurrency(struct rq *rq);
+#else
+static inline void init_cpu_concurrency(struct rq *rq) {}
+#endif
+
extern struct rt_bandwidth def_rt_bandwidth;
extern void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime);
CPU ConCurrency (CC) is inserted as a member in each CPU's rq, and initiated the same time as rq. Updating CC is protected by rq's lock. Signed-off-by: Yuyang Du <yuyang.du@intel.com> --- kernel/sched/Makefile | 1 + kernel/sched/concurrency.c | 22 ++++++++++++++++++++++ kernel/sched/core.c | 2 ++ kernel/sched/sched.h | 21 +++++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 kernel/sched/concurrency.c