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

smart_grid: introduce smart_grid cmdline

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


CVE: NA

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

We need a cmdline to decide whether smart_grid is enabled.

Need to add "smart_grid" string in kernel boot cmdline, if we want
to enable the feature.

Signed-off-by: default avatarYipeng Zou <zouyipeng@huawei.com>
parent 3ed783c8
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -2840,6 +2840,10 @@ static DEFINE_MUTEX(sg_zone_lock);

void cpufreq_smart_grid_start_sync(void)
{
	/* No need sync when smart grid disabled */
	if (!smart_grid_enabled())
		return;

	if (likely(sg_zone.is_init))
		irq_work_queue(&sg_zone.irq_work);
}
@@ -3038,6 +3042,10 @@ static int create_smart_grid_sysfs_file(void)
{
	int ret;

	/* No need init when smart grid disabled */
	if (!smart_grid_enabled())
		return 0;

	ret = sysfs_create_file(cpufreq_global_kobject, &smart_grid_governor.attr);
	if (ret)
		pr_err("%s: cannot register global smart_grid_governor sysfs file\n",
+6 −0
Original line number Diff line number Diff line
@@ -3323,6 +3323,9 @@ static int smart_grid_level_show(struct seq_file *m, void *v)
	struct inode *inode = m->private;
	struct task_struct *p;

	if (!smart_grid_enabled())
		return -EPERM;

	p = get_proc_task(inode);
	if (!p)
		return -ESRCH;
@@ -3350,6 +3353,9 @@ static ssize_t smart_grid_level_write(struct file *file, const char __user *buf,
	unsigned int level = SCHED_GRID_QOS_TASK_LEVEL_MAX;
	int ret = 0;

	if (!smart_grid_enabled())
		return -EPERM;

	memset(buffer, 0, sizeof(buffer));
	if (copy_from_user(buffer, buf, count > maxlen ? maxlen : count))
		return -EFAULT;
+14 −0
Original line number Diff line number Diff line
@@ -2545,8 +2545,22 @@ static inline bool dynamic_affinity_enabled(void)

#ifdef CONFIG_QOS_SCHED_SMART_GRID
extern struct static_key __smart_grid_used;
extern struct static_key_false __smart_grid_switch;

static inline bool smart_grid_enabled(void)
{
	/* smart grid need dynamic affinity enabled first */
	if (!static_branch_unlikely(&__dynamic_affinity_switch))
		return false;

	return static_branch_unlikely(&__smart_grid_switch);
}

static inline bool smart_grid_used(void)
{
	if (!smart_grid_enabled())
		return false;

	return static_key_false(&__smart_grid_used);
}
#else
+7 −4
Original line number Diff line number Diff line
@@ -633,6 +633,7 @@ void free_task(struct task_struct *tsk)
		sched_prefer_cpus_free(tsk);
#endif
#ifdef CONFIG_QOS_SCHED_SMART_GRID
	if (smart_grid_enabled())
		sched_grid_qos_free(tsk);
#endif
	free_task_struct(tsk);
@@ -2396,9 +2397,11 @@ __latent_entropy struct task_struct *copy_process(
	current->flags &= ~PF_NPROC_EXCEEDED;

#ifdef CONFIG_QOS_SCHED_SMART_GRID
	if (smart_grid_enabled()) {
		retval = sched_grid_qos_fork(p, current);
		if (retval)
			goto bad_fork_cleanup_count;
	}
#endif

	/*
+8 −8
Original line number Diff line number Diff line
@@ -11397,7 +11397,7 @@ static u64 cpu_affinity_mode_read_u64(struct cgroup_subsys_state *css,
{
	struct task_group *tg = css_tg(css);

	if (!dynamic_affinity_enabled())
	if (!smart_grid_enabled())
		return -EPERM;

	if (unlikely(!tg->auto_affinity))
@@ -11409,7 +11409,7 @@ static u64 cpu_affinity_mode_read_u64(struct cgroup_subsys_state *css,
static int cpu_affinity_mode_write_u64(struct cgroup_subsys_state *css,
				   struct cftype *cftype, u64 mode)
{
	if (!dynamic_affinity_enabled())
	if (!smart_grid_enabled())
		return -EPERM;

	return tg_set_dynamic_affinity_mode(css_tg(css), mode);
@@ -11440,7 +11440,7 @@ u64 tg_get_affinity_period(struct task_group *tg)
static int cpu_affinity_period_write_uint(struct cgroup_subsys_state *css,
					  struct cftype *cftype, u64 period)
{
	if (!dynamic_affinity_enabled())
	if (!smart_grid_enabled())
		return -EPERM;

	return tg_set_affinity_period(css_tg(css), period);
@@ -11449,7 +11449,7 @@ static int cpu_affinity_period_write_uint(struct cgroup_subsys_state *css,
static u64 cpu_affinity_period_read_uint(struct cgroup_subsys_state *css,
					 struct cftype *cft)
{
	if (!dynamic_affinity_enabled())
	if (!smart_grid_enabled())
		return -EPERM;

	return tg_get_affinity_period(css_tg(css));
@@ -11463,7 +11463,7 @@ static int cpu_affinity_domain_mask_write_u64(struct cgroup_subsys_state *css,
	struct affinity_domain *ad;
	u16 full;

	if (!dynamic_affinity_enabled())
	if (!smart_grid_enabled())
		return -EPERM;

	if (unlikely(!tg->auto_affinity))
@@ -11485,7 +11485,7 @@ static u64 cpu_affinity_domain_mask_read_u64(struct cgroup_subsys_state *css,
{
	struct task_group *tg = css_tg(css);

	if (!dynamic_affinity_enabled())
	if (!smart_grid_enabled())
		return -EPERM;

	if (unlikely(!tg->auto_affinity))
@@ -11501,8 +11501,8 @@ static int cpu_affinity_stat_show(struct seq_file *sf, void *v)
	struct affinity_domain *ad;
	int i;

	/* No stat when dynamic affinity disabled */
	if (!dynamic_affinity_enabled())
	/* No stat when smart grid disabled */
	if (!smart_grid_enabled())
		return -EPERM;

	if (unlikely(!auto_affi))
Loading