@@ -855,7 +855,10 @@ static RtapiApp *makeApp()
855855 }
856856 WithRoot r;
857857 void *dll = nullptr ;
858- if (detect_xenomai ()) {
858+ if (detect_xenomai_evl ()) {
859+ dll = dlopen (EMC2_HOME " /lib/libuspace-xenomai-evl.so.0" , RTLD_NOW);
860+ if (!dll) fprintf (stderr, " dlopen: %s\n " , dlerror ());
861+ }else if (detect_xenomai ()) {
859862 dll = dlopen (EMC2_HOME " /lib/libuspace-xenomai.so.0" , RTLD_NOW);
860863 if (!dll) fprintf (stderr, " dlopen: %s\n " , dlerror ());
861864 } else if (detect_rtai ()) {
@@ -918,6 +921,14 @@ int RtapiApp::prio_bound(int prio) const {
918921 return prio;
919922}
920923
924+ bool RtapiApp::prio_check (int prio) const {
925+ if (rtapi_prio_highest () > rtapi_prio_lowest ()) {
926+ return (prio <= rtapi_prio_highest ()) && (prio >= rtapi_prio_lowest ());
927+ } else {
928+ return (prio <= rtapi_prio_lowest ()) && (prio >= rtapi_prio_highest ());
929+ }
930+ }
931+
921932int RtapiApp::prio_next_higher (int prio) const
922933{
923934 prio = prio_bound (prio);
@@ -948,8 +959,10 @@ int RtapiApp::allocate_task_id()
948959int RtapiApp::task_new (void (*taskcode) (void *), void *arg,
949960 int prio, int owner, unsigned long int stacksize, int uses_fp) {
950961 /* check requested priority */
951- if ((prio > rtapi_prio_highest ()) || (prio < rtapi_prio_lowest () ))
962+ if (! prio_check (prio))
952963 {
964+ rtapi_print_msg (RTAPI_MSG_ERR," rtapi:task_new prio is not in bound lowest %i prio %i highest %i\n " ,
965+ rtapi_prio_lowest (), prio, rtapi_prio_highest ());
953966 return -EINVAL;
954967 }
955968
@@ -1010,48 +1023,72 @@ int Posix::task_delete(int id)
10101023 return 0 ;
10111024}
10121025
1013- static int find_rt_cpu_number () {
1026+ // parse_cpu_list from https://gitlab.com/Xenomai/xenomai4/libevl/-/blob/11e6a1fb183a315ae861762e7650fd5e10d83ff5/tests/helpers.c
1027+ // License: MIT
1028+ static void parse_cpu_list (const char *path, cpu_set_t *cpuset)
1029+ {
1030+ char *p, *range, *range_p = NULL , *id, *id_r;
1031+ int start, end, cpu;
1032+ char buf[BUFSIZ];
1033+ FILE *fp;
1034+
1035+ CPU_ZERO (cpuset);
1036+
1037+ fp = fopen (path, " r" );
1038+ if (fp == NULL )
1039+ return ;
1040+
1041+ if (!fgets (buf, sizeof (buf), fp))
1042+ goto out;
1043+
1044+ p = buf;
1045+ while ((range = strtok_r (p, " ," , &range_p)) != NULL ) {
1046+ if (*range == ' \0 ' || *range == ' \n ' )
1047+ goto next;
1048+ end = -1 ;
1049+ id = strtok_r (range, " -" , &id_r);
1050+ if (id) {
1051+ start = atoi (id);
1052+ id = strtok_r (NULL , " -" , &id_r);
1053+ if (id)
1054+ end = atoi (id);
1055+ else if (end < 0 )
1056+ end = start;
1057+ for (cpu = start; cpu <= end; cpu++)
1058+ CPU_SET (cpu, cpuset);
1059+ }
1060+ next:
1061+ p = NULL ;
1062+ }
1063+ out:
1064+ fclose (fp);
1065+ }
1066+
1067+ int find_rt_cpu_number () {
10141068 if (getenv (" RTAPI_CPU_NUMBER" )) return atoi (getenv (" RTAPI_CPU_NUMBER" ));
10151069
10161070#ifdef __linux__
1017- cpu_set_t cpuset_orig;
1018- int r = sched_getaffinity (getpid (), sizeof (cpuset_orig), &cpuset_orig);
1019- if (r < 0 )
1020- // if getaffinity fails, (it shouldn't be able to), just use CPU#0
1021- return 0 ;
1022-
1071+ const char * isolated_file=" /sys/devices/system/cpu/isolated" ;
10231072 cpu_set_t cpuset;
1024- CPU_ZERO (&cpuset);
1025- long top_probe = sysconf (_SC_NPROCESSORS_CONF);
1026- // in old glibc versions, it was an error to pass to sched_setaffinity bits
1027- // that are higher than an imagined/probed kernel-side CPU mask size.
1028- // this caused the message
1029- // sched_setaffinity: Invalid argument
1030- // to be printed at startup, and the probed CPU would not take into
1031- // account CPUs masked from this process by default (whether by
1032- // isolcpus or taskset). By only setting bits up to the "number of
1033- // processes configured", the call is successful on glibc versions such as
1034- // 2.19 and older.
1035- for (long i=0 ; i<top_probe && i<CPU_SETSIZE; i++) CPU_SET (i, &cpuset);
1036-
1037- r = sched_setaffinity (getpid (), sizeof (cpuset), &cpuset);
1038- if (r < 0 )
1039- // if setaffinity fails, (it shouldn't be able to), go on with
1040- // whatever the default CPUs were.
1041- perror (" sched_setaffinity" );
1042-
1043- r = sched_getaffinity (getpid (), sizeof (cpuset), &cpuset);
1044- if (r < 0 ) {
1045- // if getaffinity fails, (it shouldn't be able to), copy the
1046- // original affinity list in and use it
1047- perror (" sched_getaffinity" );
1048- CPU_AND (&cpuset, &cpuset_orig, &cpuset);
1073+
1074+ parse_cpu_list (isolated_file, &cpuset);
1075+
1076+ // Print list
1077+ rtapi_print_msg (RTAPI_MSG_INFO, " cpuset isolated " );
1078+ for (int i=0 ; i<CPU_SETSIZE; i++) {
1079+ if (CPU_ISSET (i, &cpuset)){
1080+ rtapi_print_msg (RTAPI_MSG_INFO, " %i " , i);
1081+ }
10491082 }
1083+ rtapi_print_msg (RTAPI_MSG_INFO, " \n " );
10501084
10511085 int top = -1 ;
10521086 for (int i=0 ; i<CPU_SETSIZE; i++) {
10531087 if (CPU_ISSET (i, &cpuset)) top = i;
10541088 }
1089+ if (top == -1 ){
1090+ rtapi_print_msg (RTAPI_MSG_ERR, " No isolated CPU's found, expect some latency or set RTAPI_CPU_NUMBER to select CPU\n " );
1091+ }
10551092 return top;
10561093#else
10571094 return (-1 );
@@ -1091,6 +1128,7 @@ int Posix::task_start(int task_id, unsigned long int period_nsec)
10911128 return -ret;
10921129 if (nprocs > 1 ) {
10931130 const static int rt_cpu_number = find_rt_cpu_number ();
1131+ rtapi_print_msg (RTAPI_MSG_INFO, " rt_cpu_number = %i\n " , rt_cpu_number);
10941132 if (rt_cpu_number != -1 ) {
10951133#ifdef __FreeBSD__
10961134 cpuset_t cpuset;
0 commit comments