Skip to content

Commit 87fdb9b

Browse files
sanmutgratian
authored andcommitted
boot: add kernel boot parameters for kernel thread priorities
Add kernel boot parameters to specify the priorities for the following kernel threads: kthreadd, irq threads, ksoftirqd, posixcputmr. Also fix priority check issue introduced with original version of this commit. Signed-off-by: Sankara S Muthukrishnan <sankara.m@ni.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com> Acked-by: Scot Salmon <scot.salmon@ni.com> Acked-by: Josh Cartwright <josh.cartwright@ni.com> Acked-by: Jeff Westfahl <jeff.westfahl@ni.com> Natinst-CAR-ID: 376725 [gratian: drop the change for setting the posixcputmr thread priority; it was improperly migrated past nilrt/14.0.y/3.2 so it had no effect and is not currently in use by our kernel boot command line] Signed-off-by: Gratian Crisan <gratian.crisan@ni.com>
1 parent 852d911 commit 87fdb9b

3 files changed

Lines changed: 60 additions & 4 deletions

File tree

kernel/irq/manage.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ early_param("threadirqs", setup_forced_irqthreads);
3636
# endif
3737
#endif
3838

39+
static int irqthread_pri = MAX_USER_RT_PRIO/2;
40+
3941
static void __synchronize_hardirq(struct irq_desc *desc)
4042
{
4143
bool inprogress;
@@ -1076,6 +1078,18 @@ void irq_wake_thread(unsigned int irq, void *dev_id)
10761078
}
10771079
EXPORT_SYMBOL_GPL(irq_wake_thread);
10781080

1081+
static __init int set_irqthread_pri(char *str)
1082+
{
1083+
int pri;
1084+
1085+
get_option(&str, &pri);
1086+
if (pri > 0 && pri < MAX_USER_RT_PRIO)
1087+
irqthread_pri = pri;
1088+
return 0;
1089+
}
1090+
1091+
early_param("irqthread_pri", set_irqthread_pri);
1092+
10791093
static int irq_setup_forced_threading(struct irqaction *new)
10801094
{
10811095
if (!force_irqthreads)
@@ -1136,9 +1150,8 @@ static int
11361150
setup_irq_thread(struct irqaction *new, unsigned int irq, bool secondary)
11371151
{
11381152
struct task_struct *t;
1139-
struct sched_param param = {
1140-
.sched_priority = MAX_USER_RT_PRIO/2,
1141-
};
1153+
struct sched_param param;
1154+
param.sched_priority = irqthread_pri;
11421155

11431156
if (!secondary) {
11441157
t = kthread_create(irq_thread, new, "irq/%d-%s", irq,

kernel/kthread.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@
2323
#include <linux/cgroup.h>
2424
#include <trace/events/sched.h>
2525

26+
#ifdef CONFIG_PREEMPT_RT_FULL
27+
#include <linux/sched/rt.h>
28+
#endif
29+
2630
static DEFINE_SPINLOCK(kthread_create_lock);
2731
static LIST_HEAD(kthread_create_list);
2832
struct task_struct *kthreadd_task;
33+
static int kthreadd_pri = -1;
2934

3035
struct kthread_create_info
3136
{
@@ -546,6 +551,13 @@ int kthreadd(void *unused)
546551
set_cpus_allowed_ptr(tsk, cpu_all_mask);
547552
set_mems_allowed(node_states[N_MEMORY]);
548553

554+
if (kthreadd_pri != -1) {
555+
struct sched_param param;
556+
557+
param.sched_priority = kthreadd_pri;
558+
sched_setscheduler_nocheck(tsk, SCHED_FIFO, &param);
559+
}
560+
549561
current->flags |= PF_NOFREEZE;
550562
cgroup_init_kthreadd();
551563

@@ -574,6 +586,18 @@ int kthreadd(void *unused)
574586
return 0;
575587
}
576588

589+
static __init int set_kthreadd_pri(char *str)
590+
{
591+
int pri;
592+
593+
get_option(&str, &pri);
594+
if (pri > 0 && pri < MAX_USER_RT_PRIO)
595+
kthreadd_pri = pri;
596+
return 0;
597+
}
598+
599+
early_param("kthreadd_pri", set_kthreadd_pri);
600+
577601
void __kthread_init_worker(struct kthread_worker *worker,
578602
const char *name,
579603
struct lock_class_key *key)

kernel/softirq.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
#include <linux/irq.h>
3131
#include <linux/sched/types.h>
3232

33+
#ifdef CONFIG_PREEMPT_RT_FULL
34+
#include <linux/sched/rt.h>
35+
#endif
36+
3337
#define CREATE_TRACE_POINTS
3438
#include <trace/events/irq.h>
3539

@@ -511,6 +515,7 @@ static void ksoftirqd_set_sched_params(unsigned int cpu) { }
511515
* On RT we serialize softirq execution with a cpu local lock per softirq
512516
*/
513517
static DEFINE_PER_CPU(struct local_irq_lock [NR_SOFTIRQS], local_softirq_locks);
518+
static int ksoftirqd_pri = 1;
514519

515520
void __init softirq_early_init(void)
516521
{
@@ -754,7 +759,9 @@ static inline void ksoftirqd_set_sched_params(unsigned int cpu)
754759

755760
static inline void ktimer_softirqd_set_sched_params(unsigned int cpu)
756761
{
757-
struct sched_param param = { .sched_priority = 1 };
762+
struct sched_param param = {
763+
.sched_priority = ksoftirqd_pri
764+
};
758765

759766
sched_setscheduler(current, SCHED_FIFO, &param);
760767

@@ -777,6 +784,18 @@ static int ktimer_softirqd_should_run(unsigned int cpu)
777784
return current->softirqs_raised;
778785
}
779786

787+
static __init int set_ksoftirqd_pri(char *str)
788+
{
789+
int pri;
790+
791+
get_option(&str, &pri);
792+
if (pri > 0 && pri < MAX_USER_RT_PRIO)
793+
ksoftirqd_pri = pri;
794+
return 0;
795+
}
796+
797+
early_param("ksoftirqd_pri", set_ksoftirqd_pri);
798+
780799
#endif /* PREEMPT_RT_FULL */
781800
/*
782801
* Enter an interrupt context.

0 commit comments

Comments
 (0)