sched: Track average sleep time

Similar to tracking average burst length for tasks, average sleep time
indicates how much a task sleeps on an average before waking up to run.
Very low sleep and burst lengths indicates tasks that could be
sensitive to task-wake latencies and hence should not be packed.

Change-Id: Ife68a9a9a9e596246aab5029f60e41c5bad781e4
Signed-off-by: Srivatsa Vaddagiri <vatsa@codeaurora.org>
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
This commit is contained in:
Srivatsa Vaddagiri 2016-09-09 19:50:27 +05:30 committed by Pavankumar Kondeti
parent 0dee0d1411
commit 92dc28458c
5 changed files with 19 additions and 12 deletions

View file

@ -1362,7 +1362,7 @@ struct ravg {
u32 sum_history[RAVG_HIST_SIZE_MAX];
u32 *curr_window_cpu, *prev_window_cpu;
u32 curr_window, prev_window;
u64 curr_burst, avg_burst;
u64 curr_burst, avg_burst, avg_sleep_time;
u16 active_windows;
u32 pred_demand;
u8 busy_buckets[NUM_BUSY_BUCKETS];

View file

@ -135,6 +135,7 @@ TRACE_EVENT(sched_task_load,
__field( u64, latency )
__field( int, grp_id )
__field( u64, avg_burst )
__field( u64, avg_sleep )
),
TP_fast_assign(
@ -152,13 +153,15 @@ TRACE_EVENT(sched_task_load,
p->ravg.mark_start : 0;
__entry->grp_id = p->grp ? p->grp->id : 0;
__entry->avg_burst = p->ravg.avg_burst;
__entry->avg_sleep = p->ravg.avg_sleep_time;
),
TP_printk("%d (%s): demand=%u boost=%d reason=%d sync=%d need_idle=%d flags=%x grp=%d best_cpu=%d latency=%llu avg_burst=%llu",
TP_printk("%d (%s): demand=%u boost=%d reason=%d sync=%d need_idle=%d flags=%x grp=%d best_cpu=%d latency=%llu avg_burst=%llu avg_sleep=%llu",
__entry->pid, __entry->comm, __entry->demand,
__entry->boost, __entry->reason, __entry->sync,
__entry->need_idle, __entry->flags, __entry->grp_id,
__entry->best_cpu, __entry->latency, __entry->avg_burst)
__entry->best_cpu, __entry->latency, __entry->avg_burst,
__entry->avg_sleep)
);
TRACE_EVENT(sched_set_preferred_cluster,

View file

@ -2100,7 +2100,7 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
set_task_cpu(p, cpu);
}
set_task_last_wake(p, wallclock);
note_task_waking(p, wallclock);
#endif /* CONFIG_SMP */
ttwu_queue(p, cpu);
stat:
@ -2169,7 +2169,7 @@ static void try_to_wake_up_local(struct task_struct *p)
update_task_ravg(rq->curr, rq, TASK_UPDATE, wallclock, 0);
update_task_ravg(p, rq, TASK_WAKE, wallclock, 0);
ttwu_activate(rq, p, ENQUEUE_WAKEUP);
set_task_last_wake(p, wallclock);
note_task_waking(p, wallclock);
}
ttwu_do_wakeup(rq, p, 0);

View file

@ -74,11 +74,6 @@ inline void clear_ed_task(struct task_struct *p, struct rq *rq)
rq->ed_task = NULL;
}
inline void set_task_last_wake(struct task_struct *p, u64 wallclock)
{
p->last_wake_ts = wallclock;
}
inline void set_task_last_switch_out(struct task_struct *p, u64 wallclock)
{
p->last_switch_out_ts = wallclock;
@ -1567,6 +1562,7 @@ void init_new_task_load(struct task_struct *p, bool idle_task)
* the avg_burst to go below the threshold.
*/
p->ravg.avg_burst = 2 * (u64)sysctl_sched_short_burst;
p->ravg.avg_sleep_time = 0;
p->ravg.curr_window_cpu = kcalloc(nr_cpu_ids, sizeof(u32), GFP_KERNEL);
p->ravg.prev_window_cpu = kcalloc(nr_cpu_ids, sizeof(u32), GFP_KERNEL);
@ -4510,6 +4506,14 @@ void update_avg_burst(struct task_struct *p)
p->ravg.curr_burst = 0;
}
void note_task_waking(struct task_struct *p, u64 wallclock)
{
u64 sleep_time = wallclock - p->last_switch_out_ts;
p->last_wake_ts = wallclock;
update_avg(&p->ravg.avg_sleep_time, sleep_time);
}
#ifdef CONFIG_CGROUP_SCHED
u64 cpu_upmigrate_discourage_read_u64(struct cgroup_subsys_state *css,
struct cftype *cft)

View file

@ -1092,7 +1092,7 @@ extern void mark_task_starting(struct task_struct *p);
extern void set_window_start(struct rq *rq);
extern void migrate_sync_cpu(int cpu, int new_cpu);
extern void update_cluster_topology(void);
extern void set_task_last_wake(struct task_struct *p, u64 wallclock);
extern void note_task_waking(struct task_struct *p, u64 wallclock);
extern void set_task_last_switch_out(struct task_struct *p, u64 wallclock);
extern void init_clusters(void);
extern int __init set_sched_enable_hmp(char *str);
@ -1490,7 +1490,7 @@ static inline void set_window_start(struct rq *rq) { }
static inline void migrate_sync_cpu(int cpu, int new_cpu) {}
static inline void init_clusters(void) {}
static inline void update_cluster_topology(void) { }
static inline void set_task_last_wake(struct task_struct *p, u64 wallclock) { }
static inline void note_task_waking(struct task_struct *p, u64 wallclock) { }
static inline void set_task_last_switch_out(struct task_struct *p,
u64 wallclock) { }