From 40bd393ed017c3c3d930689cef044abf1cc1dd2d Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Sun, 28 Feb 2021 20:47:46 +0100 Subject: [PATCH] Fix sched_setscheduler undefined on kernel 5.9 sched_setscheduler is no more exported: https://lkml.org/lkml/2020/4/22/1071 --- master/master.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/master/master.c b/master/master.c index 7e7c3f3e..fe9b5946 100644 --- a/master/master.c +++ b/master/master.c @@ -1440,6 +1440,20 @@ void ec_master_nanosleep(const unsigned long nsecs) /*****************************************************************************/ +/* compatibility for priority changes */ +static inline void set_normal_priority(struct task_struct *p, int nice) +{ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0) + sched_set_normal(p, nice); +#else + struct sched_param param = { .sched_priority = 0 }; + sched_setscheduler(p, SCHED_NORMAL, ¶m); + set_user_nice(p, nice); +#endif +} + +/*****************************************************************************/ + /** Execute slave FSMs. */ void ec_master_exec_slave_fsms( @@ -1654,8 +1668,6 @@ static int ec_master_operation_thread(void *priv_data) */ void ec_master_eoe_start(ec_master_t *master /**< EtherCAT master */) { - struct sched_param param = { .sched_priority = 0 }; - if (master->eoe_thread) { EC_MASTER_WARN(master, "EoE already running!\n"); return; @@ -1682,8 +1694,7 @@ void ec_master_eoe_start(ec_master_t *master /**< EtherCAT master */) return; } - sched_setscheduler(master->eoe_thread, SCHED_NORMAL, ¶m); - set_user_nice(master->eoe_thread, 0); + set_normal_priority(master->eoe_thread, 0); } /*****************************************************************************/