void nested() { /* local variable definition */ sysClkRateSet(1000); sysTimestampEnable(); jiffies_per_tick = sysTimestampPeriod(); clock_frequency = sysTimestampFreq(); microseconds_per_tick = (jiffies_per_tick / clock_frequency)*1000000.0; microseconds_per_jiffy = microseconds_per_tick / jiffies_per_tick; int i, j, p; start_profiling(); for(i=2; i<100; i++) { start_profiling_in(); for(j=2; j <= (i/j); j++) if(!(i%j)) break; /* if factor found, not prime*/ stop_profiling_in(); if(j > (i/j)) p = i; } stop_profiling(); output_profiling("nested for outer loop including inner loop profiling"); start_profiling(); for(i=2; i<100; i++) { for(j=2; j <= (i/j); j++) if(!(i%j)) break; /* if factor found, not prime*/ if(j > (i/j)) p = i; } stop_profiling(); output_profiling("nested for outer loop without inner loop profiling"); }
/****************************************************************************** ** Function: CFE_PSP_GetTimerTicksPerSecond() ** ** Purpose: ** Provides the resolution of the least significant 32 bits of the 64 bit ** time stamp returned by CFE_PSP_Get_Timebase in timer ticks per second. ** The timer resolution for accuracy should not be any slower than 1000000 ** ticks per second or 1 us per tick ** ** Arguments: ** ** Return: ** The number of timer ticks per second of the time stamp returned ** by CFE_PSP_Get_Timebase */ uint32 CFE_PSP_GetTimerTicksPerSecond(void) { uint32 ticksPerSec = CFE_PSP_TIMER_TICKS_PER_SECOND; if(g_bTimerInitialized == TRUE) { ticksPerSec = sysTimestampFreq(); } return ticksPerSec; }
void taskDeleteCallback(WIND_TCB *pTcb) { long curTime = sysTimestamp(); char * self = (char *)taskName(taskIdSelf()); long execTime = pTcb->spare1 + curTime - pTcb->spare2; long microsecExecTime = 1000000 * (double)execTime / sysTimestampFreq(); if (strcmp(self, mqs) == 0 || strcmp(self, mbs) == 0 || strcmp(self, mns) == 0 || strcmp(self, sup) == 0) { printf("Task %s: no. of premptions: %d --- Execution time (microsec): %d.\n", self, pTcb->spare3, microsecExecTime); } if (strcmp(self, sup) == 0) { long elapsed = curTime - pTcb->spare4; long totalTime = 1000000 * (double)elapsed / sysTimestampFreq(); printf("Absolute execution time (microsec): %d.\n", totalTime); printf("System-wide total number of premptions: %d\n", premptionCounter); } return; }
void CFE_PSP_InitLocalTime(void) { /* Set the sys clock rate */ sysClkRateSet(200); /* ** Disable the Aux timer interrupt, and disable the Timestamp timer */ sysAuxClkDisable(); if(sysTimestampDisable() == ERROR) { OS_printf("CFE_PSP: Unable to disable the Timestamp timer!\n"); } /* ** Set the Aux timer */ if(sysAuxClkRateGet() != CFE_PSP_TIMER_AUX_TICK_PER_SEC) { if(sysAuxClkRateSet(CFE_PSP_TIMER_AUX_TICK_PER_SEC) == ERROR) { OS_printf("CFE_PSP: Unable to set Aux Clock Rate!\n"); } if(CFE_PSP_TIMER_PRINT_DBG == TRUE) { OS_printf("CFE_PSP: Aux Clock Rate %d.\n", sysAuxClkRateGet()); OS_printf("CFE_PSP: Timestamp Frequency %u.\n", sysTimestampFreq()); OS_printf("CFE_PSP: Timestamp Period %u.\n", sysTimestampPeriod()); } } }/* end CFE_PSP_InitLocalTime */
/****************************************************************************** ** Function: CFE_PSP_Get_Timebase() ** ** Purpose: ** Provides a common interface to system timebase. This routine ** is in the BSP because it is sometimes implemented in hardware and ** sometimes taken care of by the RTOS. ** ** Arguments: ** ** Return: ** Timebase register value */ void CFE_PSP_Get_Timebase(uint32 *Tbu, uint32* Tbl) { uint32 upper = 0; uint32 lower = 0; int32 key = 0; /* ** We don't want an interrupt to occur when the time requested. ** According to notes from vxWorks, intLock does not stop reschededuling ** of the calling task, so we have lock the task as well. ** ** sysTimestampLock() automatically blocks interrupts during execution. ** ** taskLock() is not valid on SMP systems and taskCpuLock (VxWorks 6.6+) ** should be used instead. */ if(g_bTimerInitialized == TRUE) { #if _WRS_VXWORKS_MINOR >= 6 if (taskCpuLock() == OK) #else if (taskLock() == OK) #endif { /* ** Tbu is the upper 32 bits of a 64 bit counter. ** Tbl is the lower 32 bits of a 64 bit counter. ** The resolution of our timer is given by: ** one timer tick = 1 / sysTimestampFreq() in seconds */ upper = g_nSecondsCount; lower = sysTimestampLock(); lower /= sysTimestampFreq() / 1000000UL; #if _WRS_VXWORKS_MINOR >= 6 taskCpuUnlock(); #else taskUnlock(); #endif } else { /* ** What if you can't lock the task */ OS_printf("CFE PSP Get Timebase: Unable to lock task!"); } } else { OS_printf("CFE PSP Get Timebase: Timer is not initialized!"); } if(Tbu != NULL) { *Tbu = upper; } if(Tbl != NULL) { *Tbl = lower; } }
void CFE_PSP_GetTime(OS_time_t *LocalTime) { uint32 nTimeStamp = 0; uint32 nFrequency = 0; uint32 nScaler = 0; unsigned long long ullTimeStamp = 0; if(LocalTime == NULL) { return; } else { if(g_bTimerInitialized == FALSE) { LocalTime->seconds = 0; LocalTime->microsecs = 0; return; } else { /* ** Get the time stamp */ /* Lock interrupts - really should be using this one, over * sysTimestamp(), according to * documentation on these function calls */ nTimeStamp = sysTimestampLock(); /* the default frequency is 9,375,000 Hz, which equals the PSP * ticks per second value * frequency = ticks per second for this counter */ nFrequency = sysTimestampFreq(); /* could use seconds = nTimeStamp / nFrequency if the timestamp counter * was a 64-bit counter, but being a 32-bit counter, running at * 9375000 Hz, it rolls over every 458.129 seconds or 7.63 minutes, * so we have to increment seconds using the aux clk ISR and get * the subseconds from the timestamp timer */ LocalTime->seconds = g_nSecondsCount; /* convert to micro sec - this conversion assumes that nTimeStamp * is always less than a second, which it should be, because it is * reset at the top of each second (when the seconds counter is * incremented) -- this comp has to be performed as an unsigned * long long, as the result of the multiply will not fit in a 32-bit * var. After dividing by the frequency(ticks per second), the result * can be stored in a 32-bit value */ ullTimeStamp = ((unsigned long long)nTimeStamp * 1000000ULL) / (unsigned long long) nFrequency; LocalTime->microsecs = (uint32)ullTimeStamp; /* logMsg("time: %u.%u ts: %u sc: %u\n", LocalTime->seconds,LocalTime->microsecs, nTimeStamp,g_nSecondsCount,0,0); */ } } }/* end CFE_PSP_GetTime */