Unverified Commit 0d41232e authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!3573 Support dynamic affinity scheduler

Merge Pull Request from: @ci-robot 
 
PR sync from: Hui Tang <tanghui20@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/ULLRVPXRL6D4PIUXCDADV77RYYSPJVN7/ 
patch 1->7: Introduce dynamic affinity for cfs scheduler.
patch 8->9: Tiny bugfix.

v1->v2:
 * move sysctl interface to fair.c

Hui Tang (7):
  sched: Introduce dynamic affinity for cfs scheduler
  cpuset: Introduce new interface for scheduler dynamic affinity
  sched: Adjust wakeup cpu range according CPU util dynamicly
  sched: Adjust cpu allowed in load balance dynamicly
  sched: Add statistics for scheduler dynamic affinity
  sched: Add cmdline for dynamic affinity
  config: enable CONFIG_QOS_SCHED_DYNAMIC_AFFINITY by default

zhangwei123171 (2):
  sched/fair: Remove invalid cpu selection logic in dynamic affinity
  sched/fair: Modify idle cpu judgment in dynamic affinity


-- 
2.34.1
 
https://gitee.com/openeuler/kernel/issues/I8LL9S
https://gitee.com/openeuler/kernel/issues/I8PGQ2
https://gitee.com/openeuler/kernel/issues/I8PGQ3 
 
Link:https://gitee.com/openeuler/kernel/pulls/3573

 

Reviewed-by: default avatarWeilong Chen <chenweilong@huawei.com>
Reviewed-by: default avatarZhang Jianhua <chris.zjh@huawei.com>
Reviewed-by: default avatarzhangyi (F) <yi.zhang@huawei.com>
Reviewed-by: default avatarZucheng Zheng <zhengzucheng@huawei.com>
Reviewed-by: default avatarLu Jialin <lujialin4@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parents 780692d2 72c9b284
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -170,6 +170,7 @@ CONFIG_FAIR_GROUP_SCHED=y
CONFIG_CFS_BANDWIDTH=y
CONFIG_RT_GROUP_SCHED=y
CONFIG_SCHED_MM_CID=y
CONFIG_QOS_SCHED_DYNAMIC_AFFINITY=y
CONFIG_CGROUP_PIDS=y
CONFIG_CGROUP_RDMA=y
CONFIG_CGROUP_FREEZER=y
+1 −0
Original line number Diff line number Diff line
@@ -192,6 +192,7 @@ CONFIG_FAIR_GROUP_SCHED=y
CONFIG_CFS_BANDWIDTH=y
CONFIG_RT_GROUP_SCHED=y
CONFIG_SCHED_MM_CID=y
CONFIG_QOS_SCHED_DYNAMIC_AFFINITY=y
CONFIG_CGROUP_PIDS=y
CONFIG_CGROUP_RDMA=y
CONFIG_CGROUP_FREEZER=y
+73 −0
Original line number Diff line number Diff line
@@ -3165,6 +3165,76 @@ static const struct file_operations proc_setgroups_operations = {
};
#endif /* CONFIG_USER_NS */

#ifdef CONFIG_QOS_SCHED_DYNAMIC_AFFINITY

static int preferred_cpuset_show(struct seq_file *m, void *v)
{
	struct inode *inode = m->private;
	struct task_struct *p;

	p = get_proc_task(inode);
	if (!p)
		return -ESRCH;

	if (p->prefer_cpus)
		seq_printf(m, "%*pbl\n", cpumask_pr_args(p->prefer_cpus));
	else
		seq_putc(m, '\n');

	put_task_struct(p);

	return 0;
}

static ssize_t preferred_cpuset_write(struct file *file, const char __user *buf,
					size_t count, loff_t *offset)
{
	cpumask_var_t new_mask;
	int retval;
	struct inode *inode = file_inode(file);
	struct task_struct *p;

	p = get_proc_task(inode);
	if (!p)
		return -ESRCH;

	if (!alloc_cpumask_var(&new_mask, GFP_KERNEL)) {
		retval = -ENOMEM;
		goto out_put_task;
	}

	retval = cpumask_parselist_user(buf, count, new_mask);
	if (retval < 0)
		goto out_free_cpumask;

	retval = set_prefer_cpus_ptr(p, new_mask);
	if (retval < 0)
		goto out_free_cpumask;

	retval = count;

out_free_cpumask:
	free_cpumask_var(new_mask);
out_put_task:
	put_task_struct(p);

	return retval;
}

static int preferred_cpuset_open(struct inode *inode, struct file *filp)
{
	return single_open(filp, preferred_cpuset_show, inode);
}

static const struct file_operations proc_preferred_cpuset_operations = {
	.open		= preferred_cpuset_open,
	.write		= preferred_cpuset_write,
	.read		= seq_read,
	.llseek		= seq_lseek,
	.release	= single_release,
};
#endif

static int proc_pid_personality(struct seq_file *m, struct pid_namespace *ns,
				struct pid *pid, struct task_struct *task)
{
@@ -3691,6 +3761,9 @@ static const struct pid_entry tid_base_stuff[] = {
	ONE("ksm_merging_pages",  S_IRUSR, proc_pid_ksm_merging_pages),
	ONE("ksm_stat",  S_IRUSR, proc_pid_ksm_stat),
#endif
#ifdef CONFIG_QOS_SCHED_DYNAMIC_AFFINITY
	REG("preferred_cpuset", 0644, proc_preferred_cpuset_operations),
#endif
};

static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
+22 −0
Original line number Diff line number Diff line
@@ -543,6 +543,11 @@ struct sched_statistics {
#ifdef CONFIG_SCHED_CORE
	u64				core_forceidle_sum;
#endif

#ifdef CONFIG_QOS_SCHED_DYNAMIC_AFFINITY
	u64				nr_wakeups_preferred_cpus;
	u64				nr_wakeups_force_preferred_cpus;
#endif
#endif /* CONFIG_SCHEDSTATS */
} ____cacheline_aligned;

@@ -1537,6 +1542,11 @@ struct task_struct {
	struct user_event_mm		*user_event_mm;
#endif

#ifdef CONFIG_QOS_SCHED_DYNAMIC_AFFINITY
	cpumask_t			*prefer_cpus;
	const cpumask_t			*select_cpus;
#endif

	/*
	 * New fields for task_struct should be added above here, so that
	 * they are included in the randomized portion of task_struct.
@@ -2469,4 +2479,16 @@ static inline int sched_qos_cpu_overload(void)
}
#endif

#ifdef CONFIG_QOS_SCHED_DYNAMIC_AFFINITY
int set_prefer_cpus_ptr(struct task_struct *p,
			const struct cpumask *new_mask);
int sched_prefer_cpus_fork(struct task_struct *p, struct cpumask *mask);
void sched_prefer_cpus_free(struct task_struct *p);

extern struct static_key_false __dynamic_affinity_switch;
static inline bool dynamic_affinity_enabled(void)
{
	return static_branch_unlikely(&__dynamic_affinity_switch);
}
#endif
#endif
+10 −0
Original line number Diff line number Diff line
@@ -1060,6 +1060,16 @@ config RT_GROUP_SCHED

endif #CGROUP_SCHED

config QOS_SCHED_DYNAMIC_AFFINITY
	bool "qos dynamic affinity"
	depends on CPUSETS
	default n
	help
	 This feature lets you allocate preferred cpus to taskgroup. If enabled,
	 it will make taskgroup only to use preferred cpus when cpu utilization
	 of taskgroup is below threshold setted, otherwise make taskgroup to use
	 cpus allowed.

config SCHED_MM_CID
	def_bool y
	depends on SMP && RSEQ
Loading