From 9ef399500b7d60c6c73d988d2c0e3dc77af2f75e Mon Sep 17 00:00:00 2001 From: daili Date: Wed, 1 Jun 2022 23:24:10 +0800 Subject: [PATCH] frame_aware_sched adapt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ohos inclusion category: feature issue: #I5AGB0 CVE: NA ---------------------------------------------- 1、move kernel node from /dev/sched_rtg_ctrl to /proc/self/sched_rtg_ctrl 2、Fix rtg prio bug happend in fling scene start Signed-off-by: Dai Li --- fs/proc/base.c | 16 ++++++++++++++++ include/linux/sched/frame_rtg.h | 1 + include/linux/sched/rtg_ctrl.h | 6 ++++++ kernel/sched/rtg/frame_rtg.c | 11 ++++++++--- kernel/sched/rtg/frame_rtg.h | 2 +- kernel/sched/rtg/rtg.c | 3 +-- kernel/sched/rtg/rtg_ctrl.c | 14 +++++++++----- kernel/sched/rtg/rtg_ctrl.h | 1 + 8 files changed, 43 insertions(+), 11 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 0d40f7a2cc4d..503fce587b67 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -89,6 +89,9 @@ #include #include #include +#ifdef CONFIG_SCHED_RTG +#include +#endif #include #include #include @@ -1499,6 +1502,16 @@ static const struct file_operations proc_pid_sched_operations = { #endif +#ifdef CONFIG_SCHED_RTG +static const struct file_operations proc_rtg_operations = { + .open = proc_rtg_open, + .unlocked_ioctl = proc_rtg_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = proc_rtg_compat_ioctl, +#endif +}; +#endif + #ifdef CONFIG_SCHED_RTG_DEBUG static int sched_group_id_show(struct seq_file *m, void *v) { @@ -3436,6 +3449,9 @@ static const struct pid_entry tgid_base_stuff[] = { #ifdef CONFIG_ACCESS_TOKENID ONE("tokenid", S_IRUSR, proc_token_operations), #endif +#ifdef CONFIG_SCHED_RTG + REG("sched_rtg_ctrl", S_IRUGO|S_IWUGO, proc_rtg_operations), +#endif #ifdef CONFIG_SCHED_RTG_DEBUG REG("sched_group_id", S_IRUGO|S_IWUGO, proc_pid_sched_group_id_operations), #endif diff --git a/include/linux/sched/frame_rtg.h b/include/linux/sched/frame_rtg.h index added0ed2c11..6713f6771c9a 100644 --- a/include/linux/sched/frame_rtg.h +++ b/include/linux/sched/frame_rtg.h @@ -25,6 +25,7 @@ struct frame_info { struct related_thread_group *rtg; int prio; struct task_struct *thread[MAX_TID_NUM]; + atomic_t thread_prio[MAX_TID_NUM]; int thread_num; unsigned int frame_rate; // frame rate u64 frame_time; diff --git a/include/linux/sched/rtg_ctrl.h b/include/linux/sched/rtg_ctrl.h index 0e346ff49fe4..b71dd74e7fc3 100644 --- a/include/linux/sched/rtg_ctrl.h +++ b/include/linux/sched/rtg_ctrl.h @@ -43,6 +43,12 @@ #define CMD_ID_GET_ENABLE \ _IOWR(RTG_SCHED_IPC_MAGIC, GET_ENABLE, struct rtg_enable_data) +int proc_rtg_open(struct inode *inode, struct file *filp); +long proc_rtg_ioctl(struct file *file, unsigned int cmd, unsigned long arg); +#ifdef CONFIG_COMPAT +long proc_rtg_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); +#endif + enum ioctl_abi_format { IOCTL_ABI_ARM32, IOCTL_ABI_AARCH64, diff --git a/kernel/sched/rtg/frame_rtg.c b/kernel/sched/rtg/frame_rtg.c index 3c25363a5b5c..62bfe2d13cb2 100644 --- a/kernel/sched/rtg/frame_rtg.c +++ b/kernel/sched/rtg/frame_rtg.c @@ -197,6 +197,7 @@ int alloc_multi_frame_info(void) { struct frame_info *frame_info = NULL; int id; + int i; id = alloc_rtg_id(); if (id < 0) @@ -211,6 +212,8 @@ int alloc_multi_frame_info(void) set_frame_rate(frame_info, DEFAULT_FRAME_RATE); atomic_set(&frame_info->curr_rt_thread_num, 0); atomic_set(&frame_info->max_rt_thread_num, DEFAULT_MAX_RT_THREAD); + for (i = 0; i < MAX_TID_NUM; i++) + atomic_set(&frame_info->thread_prio[i], 0); return id; } @@ -562,6 +565,7 @@ void update_frame_thread_info(struct frame_info *frame_info, old_prio = frame_info->prio; real_thread = 0; for (i = 0; i < thread_num; i++) { + atomic_set(&frame_info->thread_prio[i], 0); frame_info->thread[i] = update_frame_thread(frame_info, old_prio, prio, frame_thread_info->thread[i], frame_info->thread[i]); @@ -630,11 +634,12 @@ void set_frame_sched_state(struct frame_info *frame_info, bool enable) /* reset curr_rt_thread_num */ atomic_set(&frame_info->curr_rt_thread_num, 0); mutex_lock(&frame_info->lock); - prio = frame_info->prio; for (i = 0; i < MAX_TID_NUM; i++) { - if (frame_info->thread[i]) + if (frame_info->thread[i]) { + prio = atomic_read(&frame_info->thread_prio[i]); do_set_frame_sched_state(frame_info, frame_info->thread[i], enable, prio); + } } mutex_unlock(&frame_info->lock); @@ -932,7 +937,7 @@ int set_frame_margin(struct frame_info *frame_info, int margin) div_u64(frame_info->frame_time, NSEC_PER_MSEC) + frame_info->vload_margin; id = frame_info->rtg->id; - trace_rtg_frame_sched(id, "FRAME_MARGIN", margin); + trace_rtg_frame_sched(id, "FRAME_MARGIN", -margin); trace_rtg_frame_sched(id, "FRAME_MAX_TIME", frame_info->max_vload_time); return 0; diff --git a/kernel/sched/rtg/frame_rtg.h b/kernel/sched/rtg/frame_rtg.h index 049bd8865249..584304d01258 100644 --- a/kernel/sched/rtg/frame_rtg.h +++ b/kernel/sched/rtg/frame_rtg.h @@ -46,7 +46,7 @@ #define FRAME_DEFAULT_MIN_PREV_UTIL 0 #define FRAME_DEFAULT_MAX_PREV_UTIL SCHED_CAPACITY_SCALE -#define DEFAULT_MAX_RT_THREAD 2 +#define DEFAULT_MAX_RT_THREAD 5 #define RTG_MAX_RT_THREAD_NUM CONFIG_NR_CPUS #define INVALID_PREFERRED_CLUSTER 10 diff --git a/kernel/sched/rtg/rtg.c b/kernel/sched/rtg/rtg.c index 8db694d22f2c..168c6c3378b3 100644 --- a/kernel/sched/rtg/rtg.c +++ b/kernel/sched/rtg/rtg.c @@ -853,8 +853,7 @@ void sched_get_max_group_util(const struct cpumask *query_cpus, &grp->preferred_cluster->cpus) && !group_should_invalid_util(grp, now)) { - if (grp->ravg.normalized_util > max_grp_util && - valid_normalized_util(grp)) + if (grp->ravg.normalized_util > max_grp_util) max_grp_util = grp->ravg.normalized_util; } raw_spin_unlock_irqrestore(&grp->lock, flag); diff --git a/kernel/sched/rtg/rtg_ctrl.c b/kernel/sched/rtg/rtg_ctrl.c index 231aeaeb0507..d49e02899495 100644 --- a/kernel/sched/rtg/rtg_ctrl.c +++ b/kernel/sched/rtg/rtg_ctrl.c @@ -672,9 +672,9 @@ static int parse_create_rtg_grp(const struct rtg_grp_data *rs_data) init_frame_thread_info(&frame_thread_info, &proc_info); update_frame_thread_info(frame_info, &frame_thread_info); atomic_set(&frame_info->frame_sched_state, 1); - pr_info("[SCHED_RTG] %s rtgid=%d, type=%d, prio=%d, threadnum=%d\n", + pr_info("[SCHED_RTG] %s rtgid=%d, type=%d, prio=%d, threadnum=%d, rtnum=%d\n", __func__, proc_info.rtgid, rs_data->grp_type, - frame_thread_info.prio, frame_thread_info.thread_num); + frame_thread_info.prio, frame_thread_info.thread_num, proc_info.rtcnt); return proc_info.rtgid; } @@ -715,6 +715,7 @@ static int parse_add_rtg_thread(const struct rtg_grp_data *rs_data) rs_data->tids[i], frame_info->thread[add_index]); if (frame_info->thread[add_index]) { + atomic_set(&frame_info->thread_prio[add_index], prio); frame_info->thread_num++; add_index = frame_info->thread_num; } else { @@ -912,10 +913,13 @@ static long do_proc_rtg_ioctl(int abi, struct file *file, unsigned int cmd, unsi static void reset_frame_info(struct frame_info *frame_info) { + int i; clear_rtg_frame_thread(frame_info, true); atomic_set(&frame_info->frame_state, -1); atomic_set(&frame_info->curr_rt_thread_num, 0); atomic_set(&frame_info->max_rt_thread_num, DEFAULT_MAX_RT_THREAD); + for (i = 0; i < MAX_TID_NUM; i++) + atomic_set(&frame_info->thread_prio[i], 0); } static int do_init_proc_state(int rtgid, const int *config, int len) @@ -997,7 +1001,7 @@ static void deinit_proc_state(void) atomic_set(&g_rt_frame_num, 0); } -static int proc_rtg_open(struct inode *inode, struct file *filp) +int proc_rtg_open(struct inode *inode, struct file *filp) { return SUCC; } @@ -1007,13 +1011,13 @@ static int proc_rtg_release(struct inode *inode, struct file *filp) return SUCC; } -static long proc_rtg_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +long proc_rtg_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { return do_proc_rtg_ioctl(IOCTL_ABI_AARCH64, file, cmd, arg); } #ifdef CONFIG_COMPAT -static long proc_rtg_compat_ioctl(struct file *file, +long proc_rtg_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { return do_proc_rtg_ioctl(IOCTL_ABI_ARM32, file, cmd, diff --git a/kernel/sched/rtg/rtg_ctrl.h b/kernel/sched/rtg/rtg_ctrl.h index 8993700048be..6d405f589dab 100644 --- a/kernel/sched/rtg/rtg_ctrl.h +++ b/kernel/sched/rtg/rtg_ctrl.h @@ -83,4 +83,5 @@ struct rtg_proc_data { int thread[MAX_TID_NUM]; int rtcnt; }; + #endif -- Gitee