From 3b773b24e67678aae79072c2d5b7783e7d5dc6a1 Mon Sep 17 00:00:00 2001 From: JianMin Liu Date: Mon, 10 Aug 2020 23:15:09 +0800 Subject: [PATCH] ANDROID: sched: add vendor hooks to handle scheduling priority Add hooks to collect scheduling information and apply vendor's tuning when task's scheduling priority is changed Bug: 163431711 Signed-off-by: JianMin Liu Change-Id: Ic85835852690d0060666107d9108560f5023496b --- drivers/android/vendor_hooks.c | 5 +++++ include/trace/hooks/sched.h | 25 +++++++++++++++++++++++++ kernel/sched/core.c | 9 +++++++++ 3 files changed, 39 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index cfbac73e4823..c0a6bcbdb2b0 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -19,6 +19,11 @@ * associated with them) to allow external modules to probe them. */ EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_select_task_rq_fair); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_rtmutex_prepare_setprio); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_prepare_prio_fork); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_finish_prio_fork); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_set_user_nice); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_setscheduler); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mutex_wait_start); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mutex_wait_finish); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rwsem_read_wait_start); diff --git a/include/trace/hooks/sched.h b/include/trace/hooks/sched.h index e4ef56686a76..372572a66d20 100644 --- a/include/trace/hooks/sched.h +++ b/include/trace/hooks/sched.h @@ -15,8 +15,33 @@ struct task_struct; DECLARE_RESTRICTED_HOOK(android_rvh_select_task_rq_fair, TP_PROTO(struct task_struct *p, int prev_cpu, int sd_flag, int wake_flags, int *new_cpu), TP_ARGS(p, prev_cpu, sd_flag, wake_flags, new_cpu), 1); + +DECLARE_RESTRICTED_HOOK(android_rvh_prepare_prio_fork, + TP_PROTO(struct task_struct *p), + TP_ARGS(p), 1); + +DECLARE_RESTRICTED_HOOK(android_rvh_finish_prio_fork, + TP_PROTO(struct task_struct *p), + TP_ARGS(p), 1); + +DECLARE_RESTRICTED_HOOK(android_rvh_rtmutex_prepare_setprio, + TP_PROTO(struct task_struct *p, struct task_struct *pi_task), + TP_ARGS(p, pi_task), 1); + +DECLARE_RESTRICTED_HOOK(android_rvh_set_user_nice, + TP_PROTO(struct task_struct *p, long *nice), + TP_ARGS(p, nice), 1); + +DECLARE_RESTRICTED_HOOK(android_rvh_setscheduler, + TP_PROTO(struct task_struct *p), + TP_ARGS(p), 1); #else #define trace_android_rvh_select_task_rq_fair(p, prev_cpu, sd_flag, wake_flags, new_cpu) +#define trace_android_rvh_prepare_prio_fork(p) +#define trace_android_rvh_finish_prio_fork(p) +#define trace_android_rvh_rtmutex_prepare_setprio(p, pi_task) +#define trace_android_rvh_set_user_nice(p, nice) +#define trace_android_rvh_setscheduler(p) #endif #endif /* _TRACE_HOOK_SCHED_H */ /* This part must be outside protection */ diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 51e0568fb08e..bb83e9a46af8 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -27,6 +27,9 @@ #undef CREATE_TRACE_POINTS #include +#undef CREATE_TRACE_POINTS +#include + /* * Export tracepoints that act as a bare tracehook (ie: have no trace event * associated with them) to allow external modules to probe them. @@ -2863,6 +2866,7 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p) * Make sure we do not leak PI boosting priority to the child. */ p->prio = current->normal_prio; + trace_android_rvh_prepare_prio_fork(p); uclamp_fork(p); @@ -2895,6 +2899,7 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p) p->sched_class = &fair_sched_class; init_entity_runnable_average(&p->se); + trace_android_rvh_finish_prio_fork(p); /* * The child is not yet in the pid-hash so no cgroup attach races, @@ -4392,6 +4397,7 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task) struct rq_flags rf; struct rq *rq; + trace_android_rvh_rtmutex_prepare_setprio(p, pi_task); /* XXX used to be waiter->prio, not waiter->task->prio */ prio = __rt_effective_prio(pi_task, p->normal_prio); @@ -4523,6 +4529,7 @@ void set_user_nice(struct task_struct *p, long nice) */ rq = task_rq_lock(p, &rf); update_rq_clock(rq); + trace_android_rvh_set_user_nice(p, &nice); /* * The RT priorities are set via sched_setscheduler(), but we still @@ -4746,6 +4753,8 @@ static void __setscheduler(struct rq *rq, struct task_struct *p, p->sched_class = &rt_sched_class; else p->sched_class = &fair_sched_class; + + trace_android_rvh_setscheduler(p); } /*