SAMA5D3 XPLAINED - speed issue

Moderator: nferre

sama5d3_eval
Posts: 8
Joined: Tue Mar 29, 2016 3:52 pm

SAMA5D3 XPLAINED - speed issue

Wed Mar 30, 2016 2:30 pm

Hello,

I have been trying to configure 200Hz timer. Unfortunately the highest timer I was able to configure was 50Hz timer.

I use Linux4SAM Yocto / Poky and arm-linux-gnueabihf-gcc-4.8 compiler.

I started with the program from here: http://www.softprayog.in/tutorials/alar ... ion-timers - the lower one.

I run the program on my PC with Linux and as expected the output showed me 10 lines. The same code compilled for xplained board shows from one to two lines.

I also ran the following code I found in the net:

Code: Select all

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>

#define USECREQ 250
#define LOOPS   1000

void event_handler (int signum)
{
	static unsigned long cnt = 0;
	static struct timeval tsFirst;

	if (cnt == 0)
	{
		gettimeofday (&tsFirst, 0);
	}

	cnt ++;

	if (cnt >= LOOPS)
	{
		struct timeval tsNow;
		struct timeval diff;
		setitimer (ITIMER_REAL, NULL, NULL);
		gettimeofday (&tsNow, 0);
		timersub(&tsNow, &tsFirst, &diff);

		unsigned long long udiff = (diff.tv_sec * 1000000) + diff.tv_usec;
		double delta = (double)(udiff/cnt)/1000000;
		int hz = (unsigned)(1.0/delta);

		printf ("kernel timer interrupt frequency is approx. %d Hz", hz);

		if (hz >= (int) (1.0/((double)(USECREQ)/1000000)))
		{
			printf (" or higher");
		}

		printf ("\n");
		exit (0);
	}
}



int main (int argc, char **argv)
{
	struct sigaction sa;
	struct itimerval timer;

	memset (&sa, 0, sizeof (sa));
	sa.sa_handler = &event_handler;
	sigaction (SIGALRM, &sa, NULL);

	timer.it_value.tv_sec = 0;
	timer.it_value.tv_usec = USECREQ;
	timer.it_interval.tv_sec = 0;
	timer.it_interval.tv_usec = USECREQ;
	setitimer (ITIMER_REAL, &timer, NULL);

	while (1);
} 
On the Pc with linux the output is more than 1000Hz while the output from xplained board is about 75Hz.

It seems something slowing down the board.
All I did is uploaded the Yocto demo on the SD card and configured the network. I didn't touch anything else.


Hello,

I did another test. I ran the below program:

Code: Select all

#include <stdio.h>
#include <unistd.h>
#include <time.h>

#define TCNT 30
#define DELAY 1000

unsigned int wynik[TCNT];

float ToS( unsigned int c )
{
	return (((float)c)/1000000000.0f);
}

int main(void)
{
	const unsigned long long nano = 1000000000;
	unsigned int i , min=0 , max=0 , avg=0;
	unsigned long long t1, t2;
	struct timespec tm;
	for ( i = 0; i < TCNT; i++)
	{
		clock_gettime( CLOCK_REALTIME, &tm );
        t1 = tm.tv_nsec + tm.tv_sec * nano;
		usleep(DELAY);
		clock_gettime( CLOCK_REALTIME, &tm );
        t2 = tm.tv_nsec + tm.tv_sec * nano;
		wynik[i] = t2 - t1;
	};
	min = wynik[0];
	for ( i = 0; i < TCNT; i++)
	{
		unsigned int p;
		p = wynik[i];
		avg += p;
		if ( p < min ) min = p;
		if ( p > max ) max = p;
	};
	avg /= TCNT;
	printf("Delay = %f[s]\n",0.000001*DELAY);
	printf("AVG   = %f[s]\nMIN   = %f[s]\nMAX   = %f[s]\n",ToS(avg),ToS(min),ToS(max));
	return 0;
}
This program was ran on PC with Linux, my SAMA5D3 XPLAINED and some router with ARM procesor.

The program just sleep for 1ms and do a mesurement how long it was sleeping. The program do the test 30 times.
The AVG value on the PC with Linux and router with ARM procesor was as ecpected 0.001xx sec.
The the output from my SAMA5D3 XPLAINED was 0.01xx sec.
I compilled the program on my Linux and my coleque compilled it on his computer. The results were the same.
My SAMA5D3 XPLAINED works like 10 time slower.

As I wrote it is brend new Kit.

Any idea what is wrong whith this code?
The Linux distribution has a bug?

Maybe sombody can compilled and run this progem od his SAMA5D3 XPLAINED?

Regards,
sama5d3_eval
Posts: 8
Joined: Tue Mar 29, 2016 3:52 pm

Re: SAMA5D3 XPLAINED - speed issue

Wed Mar 30, 2016 4:15 pm

Hello,

I ran the command: cat /proc/timer_list

The output is:
clock 1:
.base: c06bbf20
.index: 1
.resolution: 10000000 nsecs
.get_time: ktime_get_real
active timers:
clock 2:
.base: c06bbf58
.index: 2
.resolution: 10000000 nsecs
.get_time: ktime_get_boottime
active timers:
clock 3:
.base: c06bbf90
.index: 3
.resolution: 10000000 nsecs
.get_time: ktime_get_clocktai
active timers:

Tick Device: mode: 0
Per CPU device: 0
Clock Event Device: tc_clkevt
max_delta_ns: 1999976423
min_delta_ns: 30518
mult: 140737
shift: 32
mode: 2
next_event: 9223372036854775807 nsecs
set_next_event: tc_next_event
set_mode: tc_mode
event_handler: tick_handle_periodic
retries: 0
Why the resolution is 10000000 nsec????
It should be 1nsec.

Was the kernell compilled with wrong parameter?
What is the sens to have such slow colck?

Can someone run this cmd: "cat /proc/timer_list" on the SAMA5D3 XPLAINED???

Regards,
blue_z
Location: USA
Posts: 1978
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D3 XPLAINED - speed issue

Wed Mar 30, 2016 8:23 pm

The timer resolutions would explain the results you report.
You would need to enable the (optional) High Resolution Timers to get a resolution better than the default 10 milliseconds.
FWIW the Atmel Demo kernels are not configured for low-latency performance, as the builds tend to use default settings.

Regards
sama5d3_eval
Posts: 8
Joined: Tue Mar 29, 2016 3:52 pm

Re: SAMA5D3 XPLAINED - speed issue

Wed Mar 30, 2016 9:07 pm

Hello,

I checked the flag CONFIG_HIGH_RES_TIMERS in the kernel configuration and it is set to 'y'
CONFIG_HIGH_RES_TIMERS=y

so it seems the hight resolution timer is enabled however I found another flag CONFIG_HZ which is ste to 100
CONFIG=100, which means 10ms resolution.

I think I have to set this flag to 1000 an drecompile the kernel.

Regards
Last edited by sama5d3_eval on Thu Mar 31, 2016 2:45 pm, edited 1 time in total.
sama5d3_eval
Posts: 8
Joined: Tue Mar 29, 2016 3:52 pm

Re: SAMA5D3 XPLAINED - speed issue

Thu Mar 31, 2016 2:45 pm

Hello,

The problem is solved I recompiled the kernel as mentioned in previouse entry.

Regards,
micro1
Posts: 42
Joined: Sun Jun 08, 2014 11:55 am

Re: SAMA5D3 XPLAINED - speed issue

Thu Mar 31, 2016 6:47 pm

Yes with recompile the issue is fixed. With high res timer and 1000 Hz and also preempt model it shall work.

With cat timer_list resulution shall be 1 nsec after recompile
blue_z
Location: USA
Posts: 1978
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D3 XPLAINED - speed issue

Thu Mar 31, 2016 11:59 pm

sama5d3_eval wrote:I checked the flag CONFIG_HIGH_RES_TIMERS in the kernel configuration and it is set to 'y'
That may be true, but previously you wrote:
sama5d3_eval wrote:All I did is uploaded the Yocto demo on the SD card and configured the network. I didn't touch anything else,
So I wouldn't be surprised if that config file is for another kernel, i.e. not the one you're testing with.
I've inspected the sama5 kernel config in meta-atmel, and HiRes timers are not enabled.

From my experience all I need to do to get 1ns timer resolution is to enable HiRes timers in menuconfig. That's it; nothing else.

Regards

Return to “SAMA5-based”

Who is online

Users browsing this forum: No registered users and 3 guests