sched: optimize prio for kernel RT thread and kworker

In some cases, there are too much userspace high priority RT threads, which
cause kernel RT threads or kworkers block too long time. This config separate
kernel and userspace RT threads into two priority regions, priority 0~49 for
kernel and priority 50~99 for userspace, so that kernel RT threads is always
higher priority than userspace. This config also set RT policy for kworkers.

Change-Id: I87e03915dc0dd03cbcd91d211d2ef56c301451f9
Signed-off-by: Liang Chen <cl@rock-chips.com>
This commit is contained in:
Liang Chen
2022-07-28 09:35:51 +08:00
committed by Tao Huang
parent ed97e50c65
commit cf8b87bbec
3 changed files with 28 additions and 0 deletions

View File

@@ -91,6 +91,16 @@ config ROCKCHIP_OPP
help
Say y here to enable rockchip OPP support.
config ROCKCHIP_OPTIMIZE_RT_PRIO
bool "Rockchip optimize prio for kernel RT thread and kworker"
depends on NO_GKI
help
In some cases, there are too much userspace high priority RT threads, which
cause kernel RT threads or kworkers block too long time. This config separate
kernel and userspace RT threads into two priority regions, priority 0~49 for
kernel and priority 50~99 for userspace, so that kernel RT threads is always
higher priority than userspace. This config also set RT policy for kworkers.
config ROCKCHIP_PERFORMANCE
bool "Rockchip performance configuration support"
depends on NO_GKI

View File

@@ -5738,6 +5738,14 @@ static int _sched_setscheduler(struct task_struct *p, int policy,
.sched_nice = PRIO_TO_NICE(p->static_prio),
};
if (IS_ENABLED(CONFIG_ROCKCHIP_OPTIMIZE_RT_PRIO) &&
((policy == SCHED_FIFO) || (policy == SCHED_RR))) {
attr.sched_priority /= 2;
if (!check)
attr.sched_priority += MAX_RT_PRIO / 2;
if (!attr.sched_priority)
attr.sched_priority = 1;
}
/* Fixup the legacy SCHED_RESET_ON_FORK hack. */
if ((policy != SETPARAM_POLICY) && (policy & SCHED_RESET_ON_FORK)) {
attr.sched_flags |= SCHED_FLAG_RESET_ON_FORK;

View File

@@ -51,6 +51,7 @@
#include <linux/sched/isolation.h>
#include <linux/nmi.h>
#include <linux/kvm_para.h>
#include <uapi/linux/sched/types.h>
#include "workqueue_internal.h"
@@ -1959,6 +1960,15 @@ static struct worker *create_worker(struct worker_pool *pool)
goto fail;
set_user_nice(worker->task, pool->attrs->nice);
if (IS_ENABLED(CONFIG_ROCKCHIP_OPTIMIZE_RT_PRIO)) {
struct sched_param param;
if (pool->attrs->nice == 0)
param.sched_priority = MAX_RT_PRIO / 2 - 4;
else
param.sched_priority = MAX_RT_PRIO / 2 - 2;
sched_setscheduler_nocheck(worker->task, SCHED_RR, &param);
}
kthread_bind_mask(worker->task, pool->attrs->cpumask);
/* successful, attach the worker to the pool */