daves Posted August 23, 2012 Share Posted August 23, 2012 The timing/sleeping method advised to be used in C loops etc seems to have broken in the latest firmware. After a lot of investigation into freezing downloads and failed reboots I have narrowed the problem down to a repeatable example: int main(void) { struct timespec SecSleeper = {0}; // Initialize time structure SecSleeper.tv_sec = 1; // 1e9 nanoseconds, which equals 1 sec SecSleeper.tv_nsec = 0; // 1e9 nanoseconds, which equals 1 sec InitLibrary(); pshm->P[1] = 0; // Main loop just keeps us running while (1) { printf("Dummy\n"); pshm->P[1]++; pshm->P[2] = nanosleep(&SecSleeper, NULL); pshm->P[3] = errno; } CloseLibrary(); return 0; } Run capp1.out on v1.4.0.27 from a putty terminal and you see "Dummy" output once a second, looking in watch window shows P1 incrementing once a second. The return value P2=0 (success) and errno P3=0 (no error) Run capp1.out on v1.5.3.0 from putty terminal and you see "Dummy" output constantly, looking in watch window shows P1 incrementing almost 100,000 time a second. The return value P2=-1 (failure) and errno P3=1 (EPERM, operation not permitted) This looks like a Xenomai error saying the calls are coming from an invalid context. Reverting to 1.4.027 fixes the problem. I will have to do this as I have many C apps and CPLCs which rely on this method. Or is there a new method for timing in PPMAC? Can you confirm you see the same issue? The August IDE complains about the firmware now so please can I have instructions on how to downgrade the IDE cleanly? Link to comment Share on other sites More sharing options...
shansen Posted August 23, 2012 Share Posted August 23, 2012 If nanosleep returns EPERM that suggests that Xenomai thinks it is not in a real-time context. Are you sure that you have called pthread_setschedparam on the current thread? Link to comment Share on other sites More sharing options...
hbausley Posted August 23, 2012 Share Posted August 23, 2012 The timing/sleeping method advised to be used in C loops etc seems to have broken in the latest firmware. After a lot of investigation into freezing downloads and failed reboots I have narrowed the problem down to a repeatable example: int main(void) { struct timespec SecSleeper = {0}; // Initialize time structure SecSleeper.tv_sec = 1; // 1e9 nanoseconds, which equals 1 sec SecSleeper.tv_nsec = 0; // 1e9 nanoseconds, which equals 1 sec InitLibrary(); pshm->P[1] = 0; // Main loop just keeps us running while (1) { printf("Dummy\n"); pshm->P[1]++; pshm->P[2] = nanosleep(&SecSleeper, NULL); pshm->P[3] = errno; } CloseLibrary(); return 0; } Run capp1.out on v1.4.0.27 from a putty terminal and you see "Dummy" output once a second, looking in watch window shows P1 incrementing once a second. The return value P2=0 (success) and errno P3=0 (no error) Run capp1.out on v1.5.3.0 from putty terminal and you see "Dummy" output constantly, looking in watch window shows P1 incrementing almost 100,000 time a second. The return value P2=-1 (failure) and errno P3=1 (EPERM, operation not permitted) This looks like a Xenomai error saying the calls are coming from an invalid context. Reverting to 1.4.027 fixes the problem. I will have to do this as I have many C apps and CPLCs which rely on this method. Or is there a new method for timing in PPMAC? Can you confirm you see the same issue? The August IDE complains about the firmware now so please can I have instructions on how to downgrade the IDE cleanly? SHansen was on the right track. We added the call below to your example and it sleeps. param.__sched_priority = 1; pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m); nanosleep is reserved to xenomai threads. The rtos was compiled without the option that causes the main thread to be a xenomai thread. We recompiled the rtos with this option. We will post a powerpmac.deb version 1.5.4.0 with that option restored so it works without pthread_setschedparam as it did previously. As a rule for realtime code use nanosleep and for generic non realtime code use sleep or usleep. Link to comment Share on other sites More sharing options...
sponseld Posted September 24, 2012 Share Posted September 24, 2012 When can we expect that the powerpmac.deb version 1.5.4.0 with that option restored will be available? We also use nanosleep and hope to avoid having to put in the pthread_setschedparam fix. It has been over a month since the last post above, but the latest version in the File Depot is still 1.5.3.0. Link to comment Share on other sites More sharing options...
hbausley Posted September 25, 2012 Share Posted September 25, 2012 When can we expect that the powerpmac.deb version 1.5.4.0 with that option restored will be available? We also use nanosleep and hope to avoid having to put in the pthread_setschedparam fix. It has been over a month since the last post above, but the latest version in the File Depot is still 1.5.3.0. We will have a new version posted within a week. Link to comment Share on other sites More sharing options...
Recommended Posts