--- zzzz-none-000/linux-3.10.107/kernel/kthread.c 2017-06-27 09:49:32.000000000 +0000 +++ vr9-7490-729/linux-3.10.107/kernel/kthread.c 2021-11-10 11:53:56.000000000 +0000 @@ -288,6 +288,46 @@ } EXPORT_SYMBOL(kthread_create_on_node); +/** + * kthread_create_with_prio - create and wake a kthread with defined prio. + * @threadfn: the function to run until signal_pending(current). + * @data: data ptr for @threadfn. + * @namefmt: printf-style name for the thread. + * @sched_policy: new policy. + * @sched_priority: new RT priority. + * + * Description: Convenient wrapper to create and wake a kthread with defined + * prio. + * + * Returns the kthread or 0. + */ +struct task_struct *kthread_create_with_prio(int (*threadfn)(void *data), + void *data, + const char namefmt[], + int sched_policy, + int sched_priority) +{ + struct task_struct *p; + struct sched_param param; + + p = kthread_create((void *)threadfn, data, namefmt); + if (IS_ERR(p)) { + printk(KERN_ERR "kthread_create_with_prio: unable to start kthread\n"); + return 0; + } + + param.sched_priority = sched_priority; + if (sched_setscheduler_nocheck(p, sched_policy, ¶m)) { + printk(KERN_ERR "kthread_create_with_prio: Could not set priority!\n"); + return 0; + } + + wake_up_process(p); + + return p; +} +EXPORT_SYMBOL(kthread_create_with_prio); + static void __kthread_bind(struct task_struct *p, unsigned int cpu, long state) { /* Must have done schedule() in kthread() before we set_task_cpu */