- VOID RTLX_AlarmThread ( VOID* pAlarmFunc )
- {
- ULONGLONG ullCurTime = 0;
- ULONG ulTimeOffset = ulCycleTime ? ulCycleTime : 2000000;
- INT iRet = 0;
- static RTLX_TIMESPEC rSleepTime;
- //, remainTime;
- clock_gettime(CLOCK_MONOTONIC, &rSleepTime);
- #if 0
- // Set sleep time (= check interval)
- rSleepTime.tv_nsec = RTOS_TIME_SHIFT_NIC_TIMED / 4;
- rSleepTime.tv_sec = 0;
- #endif
- // remainTime.tv_sec = 0;
- RTLX_VERBOSE(1, "Successfully started NIC-timed alarm thread\n");
- RTOS_SetThreadPriority(RTOS_THREAD_PRIORITY_TIMER); // was -2 !!!
- while(TRUE)
- {
- // Active wait for next cycle based on NIC timer:
- // poll NIC clock every rSleepTime until time reached
- // Not ideal in terms of CPU utilization and jitter
- // behavior, but simple and effective
- iRet = RTLX_ReadTimeNic(
- &(arIgbDev[0]),
- &ullCurTime
- );
- if (iRet != RTOS_RET_OK)
- {
- RTLX_VERBOSE(0, "Error reading time from NIC\n");
- }
- // sleep till next time stamp
- ulTimeOffset = ullCycleOffset - ullCurTime;
- rSleepTime.tv_nsec += ulTimeOffset;
- rSleepTime.tv_sec += rSleepTime.tv_nsec / NANOSEC_PER_SEC;
- rSleepTime.tv_nsec %= NANOSEC_PER_SEC;
- pNicAlarmFunc();
- do {
- iRet = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &rSleepTime, NULL);
- SystemTraceDebugMarker("sleep finish -RTLX_AlarmThread NIC ulTimeOffset= %lu", ulTimeOffset );
- } while (iRet == EINTR);
- // Time reached, so start cycle
- RTLX_SET_NIC_TIMED_OFFSET(ullCycleOffset, ulCycleTime);
- }
- }
|clock_nanosleep()| fires too early
Posted by Anonymous on Thu 17th Oct 2024 13:45
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.