Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dafe7914 authored by Srivatsa Vaddagiri's avatar Srivatsa Vaddagiri Committed by Syed Rameez Mustafa
Browse files

sched: window-stats: Code cleanup



Remove code duplication associated with update of various window-stats
related sysctl tunables

Change-Id: I64e29ac065172464ba371a03758937999c42a71f
Signed-off-by: default avatarSrivatsa Vaddagiri <vatsa@codeaurora.org>
parent 25d5c94d
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -104,13 +104,7 @@ extern int sched_hmp_proc_update_handler(struct ctl_table *table,
extern int sched_boost_handler(struct ctl_table *table, int write,
			void __user *buffer, size_t *lenp, loff_t *ppos);

extern int sched_acct_wait_time_update_handler(struct ctl_table *table,
		 int write, void __user *buffer, size_t *lenp, loff_t *ppos);

extern int sched_window_stats_policy_update_handler(struct ctl_table *table,
		 int write, void __user *buffer, size_t *lenp, loff_t *ppos);

extern int sched_ravg_hist_size_update_handler(struct ctl_table *table,
extern int sched_window_update_handler(struct ctl_table *table,
		 int write, void __user *buffer, size_t *lenp, loff_t *ppos);

#ifdef CONFIG_SCHED_DEBUG
+5 −16
Original line number Diff line number Diff line
@@ -1139,10 +1139,6 @@ __read_mostly unsigned int sched_ravg_window = 10000000;
/* Max window size (in ns) = 1s */
#define MAX_SCHED_RAVG_WINDOW 1000000000

#define WINDOW_STATS_USE_RECENT        0
#define WINDOW_STATS_USE_MAX   1
#define WINDOW_STATS_USE_AVG   2

__read_mostly unsigned int sysctl_sched_window_stats_policy =
	WINDOW_STATS_USE_AVG;

@@ -1647,9 +1643,7 @@ unsigned long sched_get_busy(int cpu)
}

/* Called with IRQs disabled */
void reset_all_window_stats(u64 window_start, unsigned int window_size,
				 int policy, int acct_wait_time,
				 unsigned int ravg_hist_size)
void reset_all_window_stats(u64 window_start, unsigned int window_size)
{
	int cpu;
	u64 wallclock;
@@ -1691,14 +1685,9 @@ void reset_all_window_stats(u64 window_start, unsigned int window_size,
		fixup_nr_big_small_task(cpu);
	}

	if (policy >= 0)
		sched_window_stats_policy = policy;

	if (acct_wait_time >= 0)
		sched_account_wait_time = acct_wait_time;

	if (ravg_hist_size > 0)
		sched_ravg_hist_size = ravg_hist_size;
	sched_window_stats_policy = sysctl_sched_window_stats_policy;
	sched_account_wait_time = sysctl_sched_account_wait_time;
	sched_ravg_hist_size = sysctl_sched_ravg_hist_size;

	for_each_online_cpu(cpu) {
		struct rq *rq = cpu_rq(cpu);
@@ -1739,7 +1728,7 @@ int sched_set_window(u64 window_start, unsigned int window_size)

	BUG_ON(sched_clock() < ws);

	reset_all_window_stats(ws, window_size, -1, -1, 0);
	reset_all_window_stats(ws, window_size);

	local_irq_restore(flags);

+14 −61
Original line number Diff line number Diff line
@@ -1888,39 +1888,24 @@ void post_big_small_task_count_change(void)

static DEFINE_MUTEX(policy_mutex);

int sched_acct_wait_time_update_handler(struct ctl_table *table, int write,
		void __user *buffer, size_t *lenp,
		loff_t *ppos)
static inline int invalid_value(unsigned int *data)
{
	int ret;
	unsigned int *data = (unsigned int *)table->data;
	unsigned int old_val;
	unsigned long flags;

	if (!sched_enable_hmp)
		return -EINVAL;

	mutex_lock(&policy_mutex);

	old_val = *data;

	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
	if (ret || !write || (write && old_val == *data))
		goto done;

	local_irq_save(flags);
	int val = *data;

	reset_all_window_stats(0, 0, -1, sysctl_sched_account_wait_time, 0);
	if (data == &sysctl_sched_ravg_hist_size)
		return (val < 2 || val > RAVG_HIST_SIZE_MAX);

	local_irq_restore(flags);

done:
	mutex_unlock(&policy_mutex);
	if (data == &sysctl_sched_window_stats_policy)
		return (val >= WINDOW_STATS_INVALID_POLICY);

	return ret;
	return 0;
}

int sched_ravg_hist_size_update_handler(struct ctl_table *table, int write,
/*
 * Handle "atomic" update of sysctl_sched_window_stats_policy,
 * sysctl_sched_ravg_hist_size and sysctl_sched_account_wait_time variables.
 */
int sched_window_update_handler(struct ctl_table *table, int write,
		void __user *buffer, size_t *lenp,
		loff_t *ppos)
{
@@ -1940,7 +1925,7 @@ int sched_ravg_hist_size_update_handler(struct ctl_table *table, int write,
	if (ret || !write || (write && (old_val == *data)))
		goto done;

	if (*data > RAVG_HIST_SIZE_MAX || *data < 1) {
	if (invalid_value(data)) {
		*data = old_val;
		ret = -EINVAL;
		goto done;
@@ -1948,39 +1933,7 @@ int sched_ravg_hist_size_update_handler(struct ctl_table *table, int write,

	local_irq_save(flags);

	reset_all_window_stats(0, 0, -1, -1, sysctl_sched_ravg_hist_size);

	local_irq_restore(flags);

done:
	mutex_unlock(&policy_mutex);

	return ret;
}

int sched_window_stats_policy_update_handler(struct ctl_table *table, int write,
		void __user *buffer, size_t *lenp,
		loff_t *ppos)
{
	int ret;
	unsigned int *data = (unsigned int *)table->data;
	unsigned int old_val;
	unsigned long flags;

	if (!sched_enable_hmp)
		return -EINVAL;

	mutex_lock(&policy_mutex);

	old_val = *data;

	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
	if (ret || !write || (write && old_val == *data))
		goto done;

	local_irq_save(flags);

	reset_all_window_stats(0, 0, sysctl_sched_window_stats_policy, -1, 0);
	reset_all_window_stats(0, 0);

	local_irq_restore(flags);

+6 −3
Original line number Diff line number Diff line
@@ -682,6 +682,11 @@ extern void init_new_task_load(struct task_struct *p);

#if defined(CONFIG_SCHED_FREQ_INPUT) || defined(CONFIG_SCHED_HMP)

#define WINDOW_STATS_USE_RECENT		0
#define WINDOW_STATS_USE_MAX		1
#define WINDOW_STATS_USE_AVG		2
#define WINDOW_STATS_INVALID_POLICY	3

extern unsigned int sched_ravg_window;
extern unsigned int sched_use_pelt;
extern unsigned int max_possible_freq;
@@ -797,9 +802,7 @@ extern void inc_nr_big_small_task(struct rq *rq, struct task_struct *p);
extern void dec_nr_big_small_task(struct rq *rq, struct task_struct *p);
extern void set_hmp_defaults(void);
extern unsigned int power_cost_at_freq(int cpu, unsigned int freq);
extern void reset_all_window_stats(u64 window_start, unsigned int window_size,
				 int policy, int acct_wait_time,
				 unsigned int ravg_hist_size);
extern void reset_all_window_stats(u64 window_start, unsigned int window_size);
extern void boost_kick(int cpu);

#else /* CONFIG_SCHED_HMP */
+3 −3
Original line number Diff line number Diff line
@@ -316,21 +316,21 @@ static struct ctl_table kern_table[] = {
		.data           = &sysctl_sched_account_wait_time,
		.maxlen         = sizeof(unsigned int),
		.mode           = 0644,
		.proc_handler   = sched_acct_wait_time_update_handler,
		.proc_handler   = sched_window_update_handler,
	},
	{
		.procname       = "sched_ravg_hist_size",
		.data           = &sysctl_sched_ravg_hist_size,
		.maxlen         = sizeof(unsigned int),
		.mode           = 0644,
		.proc_handler   = sched_ravg_hist_size_update_handler,
		.proc_handler   = sched_window_update_handler,
	},
	{
		.procname       = "sched_window_stats_policy",
		.data           = &sysctl_sched_window_stats_policy,
		.maxlen         = sizeof(unsigned int),
		.mode           = 0644,
		.proc_handler   = sched_window_stats_policy_update_handler,
		.proc_handler   = sched_window_update_handler,
	},
	{
		.procname	= "sched_wakeup_load_threshold",