Unverified Commit 085b5978 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!877 sched: fix performance degradation on lmbench

Merge Pull Request from: @barry19901226 
 
There are worse performance with the 'Fixes'
when running "./lat_ctx -P $SYNC_MAX -s 64 16".

The 'Fixes' which allocates memory for p->prefer_cpus
even if "prefer_cpus" not be set.

Before the 'Fixes', only test "p->prefer_cpus",
after, add test "!cpumask_empty(p->prefer_cpus)"
which causing performance degradation.

select_task_rq_fair
  ->set_task_select_cpus
    ->prefer_cpus_valid  ----  test cpumask_empty(p->prefer_cpus) 
 
Link:https://gitee.com/openeuler/kernel/pulls/877

 

Reviewed-by: default avatarZucheng Zheng <zhengzucheng@huawei.com>
Signed-off-by: default avatarXie XiuQi <xiexiuqi@huawei.com>
parents c06ba533 d8f77f89
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -3298,6 +3298,12 @@ static ssize_t preferred_cpuset_write(struct file *file, const char __user *buf,
	if (retval < 0)
	if (retval < 0)
		goto out_free_cpumask;
		goto out_free_cpumask;


	if (!cpumask_empty(new_mask)) {
		cpus_read_lock();
		dynamic_affinity_enable();
		cpus_read_unlock();
	}

	retval = count;
	retval = count;


out_free_cpumask:
out_free_cpumask:
+1 −0
Original line number Original line Diff line number Diff line
@@ -2227,6 +2227,7 @@ int set_prefer_cpus_ptr(struct task_struct *p,
			const struct cpumask *new_mask);
			const struct cpumask *new_mask);
int sched_prefer_cpus_fork(struct task_struct *p, struct cpumask *mask);
int sched_prefer_cpus_fork(struct task_struct *p, struct cpumask *mask);
void sched_prefer_cpus_free(struct task_struct *p);
void sched_prefer_cpus_free(struct task_struct *p);
void dynamic_affinity_enable(void);
#endif
#endif


#ifdef CONFIG_BPF_SCHED
#ifdef CONFIG_BPF_SCHED
+3 −0
Original line number Original line Diff line number Diff line
@@ -734,6 +734,9 @@ static int update_prefer_cpumask(struct cpuset *cs, struct cpuset *trialcs,


	update_tasks_prefer_cpumask(trialcs);
	update_tasks_prefer_cpumask(trialcs);


	if (!cpumask_empty(trialcs->prefer_cpus))
		dynamic_affinity_enable();

	spin_lock_irq(&callback_lock);
	spin_lock_irq(&callback_lock);
	cpumask_copy(cs->prefer_cpus, trialcs->prefer_cpus);
	cpumask_copy(cs->prefer_cpus, trialcs->prefer_cpus);
	spin_unlock_irq(&callback_lock);
	spin_unlock_irq(&callback_lock);
+24 −0
Original line number Original line Diff line number Diff line
@@ -7067,6 +7067,27 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
}
}


#ifdef CONFIG_QOS_SCHED_DYNAMIC_AFFINITY
#ifdef CONFIG_QOS_SCHED_DYNAMIC_AFFINITY

#ifdef CONFIG_JUMP_LABEL
static DEFINE_STATIC_KEY_FALSE(__dynamic_affinity_used);

static inline bool dynamic_affinity_used(void)
{
	return static_branch_unlikely(&__dynamic_affinity_used);
}

void dynamic_affinity_enable(void)
{
	static_branch_enable_cpuslocked(&__dynamic_affinity_used);
}

#else /* CONFIG_JUMP_LABEL */
static bool dynamic_affinity_used(void)
{
	return true;
}
#endif

/*
/*
 * Low utilization threshold for CPU
 * Low utilization threshold for CPU
 *
 *
@@ -7076,6 +7097,9 @@ int sysctl_sched_util_low_pct = 85;


static inline bool prefer_cpus_valid(struct task_struct *p)
static inline bool prefer_cpus_valid(struct task_struct *p)
{
{
	if (!dynamic_affinity_used())
		return false;

	return p->prefer_cpus &&
	return p->prefer_cpus &&
	       !cpumask_empty(p->prefer_cpus) &&
	       !cpumask_empty(p->prefer_cpus) &&
	       !cpumask_equal(p->prefer_cpus, p->cpus_ptr) &&
	       !cpumask_equal(p->prefer_cpus, p->cpus_ptr) &&