Commit f7c232d3 authored by Yipeng Zou's avatar Yipeng Zou Committed by yanhaitao
Browse files

smart_grid: introduce smart_grid_strategy_ctrl sysctl

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I8WMOG


CVE: NA

----------------------------------------

Considering for inheritance of the pre-verion code.

We make all task to the highest qos_level (grid_qos_level = 0),when
smart_grid strategy was disabled.

Otherwise, When smart_grid strategy was enabled, we use the task's
actually grid_qos_level.

Default smart_grid strategy was disable (=0).

Signed-off-by: default avatarYipeng Zou <zouyipeng@huawei.com>
parent 983d4508
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -112,6 +112,7 @@ int sched_grid_zone_update(bool is_locked);
int sched_grid_zone_add_af(struct auto_affinity *af);
int sched_grid_zone_del_af(struct auto_affinity *af);
struct cpumask *sched_grid_zone_cpumask(enum sg_zone_type zone);
struct cpumask *sched_grid_prefer_cpus(struct task_struct *p);
#else
static inline int __init sched_grid_zone_init(void) { return 0; }

+0 −4
Original line number Diff line number Diff line
@@ -12,10 +12,6 @@ extern unsigned long sysctl_hung_task_timeout_secs;
enum { sysctl_hung_task_timeout_secs = 0 };
#endif

#ifdef CONFIG_QOS_SCHED_SMART_GRID
extern int sysctl_affinity_adjust_delay_ms;
#endif

enum sched_tunable_scaling {
	SCHED_TUNABLESCALING_NONE,
	SCHED_TUNABLESCALING_LOG,
+26 −6
Original line number Diff line number Diff line
@@ -209,6 +209,11 @@ static unsigned int sysctl_numa_balancing_promote_rate_limit = 65536;
int sysctl_sched_util_low_pct = 85;
#endif

#ifdef CONFIG_QOS_SCHED_SMART_GRID
extern unsigned int sysctl_smart_grid_strategy_ctrl;
static int sysctl_affinity_adjust_delay_ms = 5000;
#endif

#ifdef CONFIG_SYSCTL
static struct ctl_table sched_fair_sysctls[] = {
	{
@@ -288,6 +293,26 @@ static struct ctl_table sched_fair_sysctls[] = {
		.mode		= 0644,
		.proc_handler	= proc_dointvec,
	},
#endif
#ifdef CONFIG_QOS_SCHED_SMART_GRID
	{
		.procname	= "smart_grid_strategy_ctrl",
		.data		= &sysctl_smart_grid_strategy_ctrl,
		.maxlen		= sizeof(unsigned int),
		.mode		= 0644,
		.proc_handler   = proc_dointvec_minmax,
		.extra1         = SYSCTL_ZERO,
		.extra2		= SYSCTL_ONE,
	},
	{
		.procname	= "affinity_adjust_delay_ms",
		.data		= &sysctl_affinity_adjust_delay_ms,
		.maxlen		= sizeof(unsigned int),
		.mode		= 0644,
		.proc_handler   = proc_dointvec_minmax,
		.extra1         = SYSCTL_ZERO,
		.extra2		= &hundred_thousand,
	},
#endif
	{}
};
@@ -6789,8 +6814,6 @@ static int sched_idle_cpu(int cpu);
static unsigned long cpu_runnable(struct rq *rq);
static inline bool prefer_cpus_valid(struct task_struct *p);

int sysctl_affinity_adjust_delay_ms = 5000;

struct static_key __smart_grid_used;

static void smart_grid_usage_inc(void)
@@ -6805,16 +6828,13 @@ static void smart_grid_usage_dec(void)

static inline struct cpumask *task_prefer_cpus(struct task_struct *p)
{
	struct affinity_domain *ad;

	if (!smart_grid_used())
		return p->prefer_cpus;

	if (task_group(p)->auto_affinity->mode == 0)
		return (void *)p->cpus_ptr;

	ad = &task_group(p)->auto_affinity->ad;
	return ad->domains[ad->curr_level];
	return sched_grid_prefer_cpus(p);
}

static inline int dynamic_affinity_mode(struct task_struct *p)
+34 −0
Original line number Diff line number Diff line
@@ -242,3 +242,37 @@ struct cpumask *sched_grid_zone_cpumask(enum sg_zone_type zone)

	return &sg_zone.cpus[zone];
}

/*
 * Default smart_grid strategy was disable (=0).
 * But, considering for inheritance of the pre-verion code.
 * We make all the task to the highest qos_level (class_lvl = 0),
 * when smart_grid strategy was disabled.
 * Otherwise, When smart_grid strategy was enabled, we use the task's
 * actually class_lvl.
 */
unsigned int sysctl_smart_grid_strategy_ctrl;

struct cpumask *sched_grid_prefer_cpus(struct task_struct *p)
{
	struct affinity_domain *ad;
	enum sg_zone_type current_zone;

	ad = &task_group(p)->auto_affinity->ad;
	/*
	 * when smart_grid strategy was disabled,
	 * We make all the task to the highest qos_level (class_lvl = 0)
	 */
	if (sysctl_smart_grid_strategy_ctrl == 0)
		return ad->domains[ad->curr_level];

	/* Only place the highest level task into hot zone */
	current_zone = p->grid_qos->stat.class_lvl == SCHED_GRID_QOS_TASK_LEVEL_HIGHEST ?
		       SMART_GRID_ZONE_HOT : SMART_GRID_ZONE_WARM;

	/* Place the highest level task in current domain level itself */
	if (current_zone == SMART_GRID_ZONE_HOT)
		return ad->domains[ad->curr_level];

	return &sg_zone.cpus[current_zone];
}
+0 −14
Original line number Diff line number Diff line
@@ -91,9 +91,6 @@ EXPORT_SYMBOL_GPL(sysctl_long_vals);
#if defined(CONFIG_SYSCTL)

/* Constants used for minimum and maximum */
#ifdef CONFIG_QOS_SCHED_SMART_GRID
static int hundred_thousand = 100000;
#endif

#ifdef CONFIG_PERF_EVENTS
static const int six_hundred_forty_kb = 640 * 1024;
@@ -2047,17 +2044,6 @@ static struct ctl_table kern_table[] = {
		.extra1		= SYSCTL_ONE,
		.extra2		= SYSCTL_INT_MAX,
	},
#endif
#ifdef CONFIG_QOS_SCHED_SMART_GRID
	{
		.procname	= "affinity_adjust_delay_ms",
		.data		= &sysctl_affinity_adjust_delay_ms,
		.maxlen		= sizeof(unsigned int),
		.mode		= 0644,
		.proc_handler   = proc_dointvec_minmax,
		.extra1         = SYSCTL_ZERO,
		.extra2		= &hundred_thousand,
	},
#endif
	{ }
};