Problems with Clockcycles

hello,

I have the following problem:
I wrote a test program, which permantly queries (with the help of
clockcycles() ) the 64-bit-counter of special values.
This procedure should trigger an other function, which should run e.g. every
1 ms (fixed step size).
I used scheduling policy FIFO and the application has the highest priority.
This is possible because I only want to use single tasking.

The next trigger point is the addition of the last trigger point plus the
fixed step size. Sometimes, when the program polls to this value, the
counter is just running over my next trigger point.
This problem repeats every 3,68 seconds.

So, hopefully someone can help me to solute this problem…

Stefan




#include <stdlib.h>
#include <sys/syspage.h>
#include <sched.h>

int main(void)
{

int flag = 0;
int firstRound = 0;
uint64_t cycle1 = 0;
uint64_t cycle2 = 0;
double StepSize = 0.001;
uint64_t counts;
uint64_t cps;
int i;
uint64_t array[10001];

struct sched_param sp;
sp.sched_priority = sched_get_priority_max(SCHED_FIFO);
sched_setscheduler(0,SCHED_FIFO,&sp);

cps = SYSPAGE_ENTRY(qtime)->cycles_per_sec;
counts = StepSize * cps;


for(i=0;i<10001;i++){
array_=0;
}

//##########################################################################
################

for(i=0;i<10000;i++) {
flag = 0;
do
{
cycle2 = ClockCycles();
if (((cycle2 - cycle1) >= counts) || (firstRound == 0))
{
if (firstRound == 1)
{
cycle1 += counts; array=(cycle2-cycle1);
}
else
{
cycle1 = ClockCycles();
firstRound = 1;
}
flag = 1;
}
}while (flag == 0);
}

//##########################################################################
####################

for(i=0;i<10000;i++)
{
if (array > 30)
printf("%i %lld\n",i,array);
}
}
\

===========================
Stefan Kehrein
Germany
ICQ: 112291216

mailto: mail@skehrein.de
mailto: kehrein@gmx.net
===========================_

Stefan,

All interrupt service routines on your system effectively have
higher priority than the highest-priority application-level
task. Some ISR is probably preventing your program from
getting the CPU as constantly as it would like.

You would probably be much better off using the system timer
as a trigger. On an x86, the timer has the highest priority of
all interrupts, because it is assigned to IRQ 0. In QNX, the
interrupt period happens to default to 1 ms (though it is easy
to change that) on all reasonably modern machines.

See the documentation on InterruptAttach() and InterruptWait()
(and also the section “Writing an Interrupt Handler” in the
Programmer’s Guide) for more details.

dB


“stefan” wrote ~ Sun, 1 Jun 2003 19:41:45 +0200:

hello,

I have the following problem:
I wrote a test program, which permantly queries (with the help of
clockcycles() ) the 64-bit-counter of special values.
This procedure should trigger an other function, which should run e.g. every
1 ms (fixed step size).
I used scheduling policy FIFO and the application has the highest priority.
This is possible because I only want to use single tasking.

The next trigger point is the addition of the last trigger point plus the
fixed step size. Sometimes, when the program polls to this value, the
counter is just running over my next trigger point.
This problem repeats every 3,68 seconds.

So, hopefully someone can help me to solute this problem…

Stefan




#include <stdlib.h
#include <sys/syspage.h
#include <sched.h

int main(void)
{

int flag = 0;
int firstRound = 0;
uint64_t cycle1 = 0;
uint64_t cycle2 = 0;
double StepSize = 0.001;
uint64_t counts;
uint64_t cps;
int i;
uint64_t array[10001];

struct sched_param sp;
sp.sched_priority = sched_get_priority_max(SCHED_FIFO);
sched_setscheduler(0,SCHED_FIFO,&sp);

cps = SYSPAGE_ENTRY(qtime)->cycles_per_sec;
counts = StepSize * cps;


for(i=0;i<10001;i++){
array> _=0;
}

//##########################################################################
################

for(i=0;i<10000;i++) {
flag = 0;
do
{
cycle2 = ClockCycles();
if (((cycle2 - cycle1) >= counts) || (firstRound == 0))
{
if (firstRound == 1)
{
cycle1 += counts; array> =(cycle2-cycle1);
}
else
{
cycle1 = ClockCycles();
firstRound = 1;
}
flag = 1;
}
}while (flag == 0);
}

//##########################################################################
####################

for(i=0;i<10000;i++)
{
if (array > > 30)
printf("%i %lld\n",i,array> );
}
}
\

===========================
Stefan Kehrein
Germany
ICQ: 112291216

mailto: > mail@skehrein.de
mailto: > kehrein@gmx.net
===========================_
\

David Bacon <dbacon@qnx.com> wrote in message
news:1054503617379.dB@nntp.qnx.com

All interrupt service routines on your system effectively have
higher priority than the highest-priority application-level
task. Some ISR is probably preventing your program from
getting the CPU as constantly as it would like.

You would probably be much better off using the system timer
as a trigger. On an x86, the timer has the highest priority of
all interrupts, because it is assigned to IRQ 0. In QNX, the
interrupt period happens to default to 1 ms (though it is easy
to change that) on all reasonably modern machines.

Actually IRQs are assigned a priority starting at IRQ3 down (cycling at
IRQ7 - 3,4,5,6,7,0,1,2) so IRQ3 is the highest by default.

-Adam