Ubuntu16.04
sudo vim /etc/default/grub 后 更改grub配置如下
默认:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
更改:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash xenomai.smi=enabled"
sudo update-grub
sudo reboot
修改前的日志文档:
[ 0.405188] [Xenomai] scheduling class idle registered.
[ 0.405189] [Xenomai] scheduling class rt registered.
[ 0.405209] [Xenomai] disabling automatic C1E state promotion on Intel processor
[ 0.405218] [Xenomai] SMI-enabled chipset found, but SMI workaround disabled
(see xenomai.smi parameter). You might encounter
high latencies!
[ 0.405243] I-pipe: head domain Xenomai registered.
[ 0.405770] [Xenomai] Cobalt v3.1
修改后的日志文档:
[ 0.404752] [Xenomai] scheduling class idle registered.
[ 0.404754] [Xenomai] scheduling class rt registered.
[ 0.404772] [Xenomai] disabling automatic C1E state promotion on Intel processor
[ 0.404780] [Xenomai] SMI-enabled chipset found
[ 0.404786] [Xenomai] SMI workaround enabled
[ 0.404811] I-pipe: head domain Xenomai registered.
[ 0.405339] [Xenomai] Cobalt v3.1
xenomai系统抖动测试代码:
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sched.h>
#include <time.h>
#include <unistd.h>
#include <signal.h>
#include <rtdm/rtdm.h>
#include <trank/native/task.h>
#include <trank/native/sem.h>
#include <trank/native/mutex.h>
#include <trank/native/timer.h>
#include <pthread.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
RT_TASK my_task;
static int run = 1;
#ifndef ONE_BILLION
#define ONE_BILLION 1000000000
#endif
long long period_ns = 1000000;
int32_t minj, maxj, dt, overrun, sumj, value;
void my_task_proc(void *arg)
{
RTIME expected_ns, start_ns, fault_threshold, now_ns;
unsigned int old_relaxed = 0, new_relaxed;
int ret, count, nsamples, warmup = 1;
unsigned long ov;
start_ns = rt_timer_read() + period_ns; /* 1ms from now */
expected_ns = start_ns;
rt_task_set_periodic(NULL, start_ns, period_ns); // ns
while (run)
{
rt_task_wait_period(NULL);
now_ns = rt_timer_read();
dt = (int32_t)(now_ns - expected_ns);
value = dt > 0 ? dt: -dt;
expected_ns = now_ns + period_ns;
if (overrun != 0)
{
if (value > maxj)
maxj = value;
if (value < minj)
minj = value;
}
overrun++;
}
}
static void *display(void *cookie)
{
int iii = 0;
while(run)
{
printf("%d :: %d Max %dus\n", overrun, dt, maxj/1000);
usleep(period_ns / 1000);
}
return NULL;
}
void signal_handler(int sig)
{
run = 0;
}
int main(int argc, char *argv[])
{
int ret;
signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler);
mlockall(MCL_CURRENT | MCL_FUTURE);
pthread_t display_task;
pthread_create(&display_task, NULL, display, NULL);
ret = rt_task_create(&my_task, "my_task", 0, 80, T_FPU);
if (ret < 0)
{
fprintf(stderr, "Failed to create task: %s\n", strerror(-ret));
return -1;
}
printf("Starting my_task...\n");
ret = rt_task_start(&my_task, &my_task_proc, NULL);
if (ret < 0)
{
fprintf(stderr, "Failed to start task: %s\n", strerror(-ret));
return -1;
}
while (run)
{
sched_yield();
}
printf("Deleting realtime task...\n");
rt_task_delete(&my_task);
printf("End of Program\n");
return 0;
}
x86平台的最大抖动为8us,arm 平台(4核A53架构,比如iMX8系列,zynqmp系列)最大抖动是20us,性能相差较大