From: Stephen Flowers <sflowers1@gmail.com>
To: yocto@yoctoproject.org
Subject: Yocto Realtime tests on beaglebone black
Date: Tue, 10 Feb 2015 13:06:32 +0000 [thread overview]
Message-ID: <54DA0258.9070108@gmail.com> (raw)
Hi All,
I have built the realtime kernel using Yocto and deployed on the
beaglebone black (specifically core-image-rt-sdk). I have written a
program to test the timer latency and interrupt latency of userspace
applications. For this I'm using a simple timerfd to generate a
periodic 10ms gpio toggle which itself acts as a gpio interrupt on
another gpio pin.
I find the latency is much worse on the preempt_rt kernel than the
standard one. RT kernel gives around 220us average with the standard
kernel about 80us. Testing with Xenomai gives about 60us. The response
times are measured with an external logic analyser, and taken with no
other load on the system. Kernel version is 3.14.
The difference between standard and RT kernel configs:
Preemption model: desktop vs. realtime kernel
Timer: 100Hz vs 1000Hz
High resolution timers disabled
I'm having a hard time figuring out why the RT kernel gives worse
latency. Anyone have any insight into this?
Included the source code below.
Thanks & Regards,
Steve
#include<sys/time.h>
#include<time.h>
#include<sys/types.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <sched.h>
#include <sys/mman.h>
#include "poll.h"
#include "fcntl.h"
#include "string.h"
#include "errno.h"
#include <sys/timerfd.h>
#define TIMER_OUT_PATH "/sys/class/gpio/gpio47"
#define LED_OUT_PATH "/sys/class/gpio/gpio26"
#define IRQ_IN_PATH "/sys/class/gpio/gpio46"
static int timer_toggle = 0;
static int output_toggle = 0;
void stack_prefault(void)
{
unsigned char dummy[8192];
memset(dummy, 0, 8192);
}
int main(int argc, char* argv[])
{
struct itimerspec itv;
unsigned long long timer_increment = 0;
clock_t prevClock;
int sigCnt = 0;
struct sigaction sa;
struct sched_param sp;
struct pollfd fdset[2];
int fd_in;
int action;
int fd_led;
int fd_timer_out;
int fd_timer_in;
char buf[2];
int len;
// setup gpio
if(system("echo 46 > /sys/class/gpio/export") == -1)
perror("unable to export gpio 46");
if(system("echo 47 > /sys/class/gpio/export") == -1)
perror("unable to export gpio 47");
if(system("echo 26 > /sys/class/gpio/export") == -1)
perror("unable to export gpio 26");
// timer out
if(system("echo out > /sys/class/gpio/gpio47/direction") == -1)
perror("unable to set 47 to output");
// led out
if(system("echo out > /sys/class/gpio/gpio26/direction") == -1)
perror("unable to set 26 to output");
// irq in
if(system("echo in > /sys/class/gpio/gpio46/direction") == -1)
perror("unable to set 46 to input");
if(system("echo both > /sys/class/gpio/gpio46/edge") == -1)
perror("unable to set 46 edge");
// set scheduling parameters
sp.sched_priority = sched_get_priority_max(SCHED_FIFO);
if(sched_setscheduler(0, SCHED_FIFO, &sp) == -1)
{
perror("setscheduler");
exit(-1);
}
// lock memory
if(mlockall(MCL_CURRENT|MCL_FUTURE) == -1)
perror("mlockall");
stack_prefault();
// Set up timer
fd_timer_in = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
printf("fd_timer:%d\n",fd_timer_in);
if(fd_timer_in < 0)
{
perror("timerfd_create()");
}
itv.it_value.tv_sec = 0;
itv.it_value.tv_nsec = 10000000;
itv.it_interval.tv_sec = 0;
itv.it_interval.tv_nsec = 10000000;
if(-1 == timerfd_settime(fd_timer_in, 0, &itv, NULL))
{
perror("settime()");
}
// setup file descriptor for poll()
fd_in = open(IRQ_IN_PATH "/value", O_RDONLY | O_NONBLOCK);
printf("fd irq input:%d\n",fd_in);
if(fd_in < 0)
{
perror("file open problem");
exit(0);
}
while(1)
{
memset((void*)fdset, 0, sizeof(fdset));
fdset[0].fd = fd_in;
fdset[0].events = POLLPRI | POLLERR;
fdset[0].revents = 0;
fdset[1].fd = fd_timer_in;
fdset[1].events = POLLIN | POLLERR;
fdset[1].revents = 0;
action = poll(fdset, 2, -1);
if(action < 0)
{
if(errno == EINTR)
{
// when signal interrupts poll, we poll again
continue;
}
else
{
perror("poll failed");
exit(0);
}
}
if(fdset[1].revents & POLLIN)
{
//len = read(fdset[1].fd, 0, SEEK_SET);
len = read(fdset[1].fd, &timer_increment,
sizeof(timer_increment));
fd_timer_out = open( TIMER_OUT_PATH "/value", O_WRONLY);
if(timer_toggle ^= 1)
{
write(fd_timer_out, "1", 2);
}
else
{
write(fd_timer_out, "0", 2);
}
close(fd_timer_out);
}
if(fdset[0].revents & POLLPRI)
{
lseek(fdset[0].fd, 0, SEEK_SET); // read from start of file
len = read(fdset[0].fd, buf, sizeof(buf));
fd_led = open( LED_OUT_PATH "/value", O_WRONLY | O_NONBLOCK);
if(buf[0] == '1')
{
write(fd_led, "1", 2);
}
else
{
write(fd_led, "0", 2);
}
close(fd_led);
}
}
close(fd_in);
close(fd_timer_in);
close(fd_led);
printf("finished\n");
return 0;
}
next reply other threads:[~2015-02-10 13:06 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-10 13:06 Stephen Flowers [this message]
2015-02-10 14:16 ` Yocto Realtime tests on beaglebone black Bruce Ashfield
2015-02-10 14:39 ` Stephen Flowers
2015-02-10 14:40 ` Bruce Ashfield
2015-02-10 14:43 ` Stephen Flowers
2015-02-10 22:23 ` Stephen Flowers
2015-02-11 4:41 ` Bruce Ashfield
2015-02-11 8:50 ` Stephen Flowers
2015-02-11 15:25 ` Bruce Ashfield
2015-02-12 0:35 ` William Mills
2015-02-12 0:35 ` [yocto] " William Mills
2015-02-12 3:50 ` Bruce Ashfield
2015-02-12 3:50 ` [yocto] " Bruce Ashfield
2015-02-12 22:05 ` Stephen Flowers
2015-02-12 22:05 ` [yocto] " Stephen Flowers
2015-02-13 0:20 ` William Mills
2015-02-13 0:20 ` [yocto] " William Mills
2015-02-13 5:08 ` Bruce Ashfield
2015-02-13 5:08 ` [yocto] " Bruce Ashfield
2015-02-17 22:57 ` Stephen Flowers
2015-02-17 22:57 ` [yocto] " Stephen Flowers
2015-02-18 14:57 ` Bruce Ashfield
2015-02-18 14:57 ` [yocto] " Bruce Ashfield
2015-02-18 15:19 ` Stephen Flowers
2015-02-18 15:19 ` [yocto] " Stephen Flowers
2015-02-18 18:43 ` Bruce Ashfield
2015-02-18 18:43 ` [yocto] " Bruce Ashfield
2015-04-13 13:24 ` Trevor Woerner
2015-04-13 13:24 ` [yocto] " Trevor Woerner
2015-04-13 13:37 ` Stephen Flowers
2015-04-13 13:38 ` [yocto] " Stephen Flowers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54DA0258.9070108@gmail.com \
--to=sflowers1@gmail.com \
--cc=yocto@yoctoproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.