The following records ClockCycles() at time of interrupt and at time thread runs. By subtracting the two ClockCycle() values you get the scheduling latency.
You will have to figure out what the real meaning of the difference is using…
(~(uint64_t)0) / SYSPAGE_ENTRY(qtime)->cycles_per_sec
Also note, that in some architectures you must lock the isr and thread to the same core - otherwise the timer values may be meaningless. See the ClockCycles() doc.
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/neutrino.h>
#include <sys/syspage.h>
#include <pthread.h>
/*
timint.c
A handler is attached to the timer interrupt. main() will wait at InterruptWait()
to be awakened by the handler. Every MAX_COUNT ticks, a thread is awakened.
*/
#define TRUE 1
#define FALSE 0
#define HIGH_PRIO 250
#define MAX_COUNT 1000
// globals
int iid;
struct sigevent int_event; /* the SIGEV_INTR event used to awaken InterruptWait() */
unsigned intThrdCount = 0;
unsigned TIMER_INTERRUPT;
unsigned long long t0, t1;
/* handler isr_tmr **********************************************************/
// param passed is NULL, id passed is value iid
const struct sigevent *isr_tmr( void *param, int id )
{
// if necessary, reset intThrdCound
if ( intThrdCount == 0 )
intThrdCount = MAX_COUNT;
// time for thread?
if ( --intThrdCount == 0 )
{
// thread will be scheduled to run on non-NULL return!
// get current time
t0 = ClockCycles();
return &int_event;
}else
return NULL;
} /* isr_tmr */
/*************************************************************************/
int main(int argc, char **argv)
{
struct _clockperiod curclk;
int rc;
// bump priority for scheduling the thread event
rc = setprio( 0, HIGH_PRIO );
if ( rc == -1 )
printf( "priority not set %d\n", errno );
// enable i/o privilege for attaching to interrupt
ThreadCtl( _NTO_TCTL_IO, 0 );
// setup for starting a thread at random times to current context
SIGEV_INTR_INIT(&int_event);
// get timer interrupt number
TIMER_INTERRUPT = SYSPAGE_ENTRY(qtime)->intr;
// attach isr_tmr to TIMER_INTERRUPT
if ( iid = InterruptAttach( TIMER_INTERRUPT, isr_tmr,
NULL, 0, _NTO_INTR_FLAGS_TRK_MSK ) != -1 )
{
while ( TRUE )
{
// wait to be notified bi isr_timr
InterruptWait( 0, NULL );
t1 = ClockCycles();
printf( "intr-to-thread latency %lld\n", t1 - t0 );
}
}
return 0;
}