Skip to contentSkip to conversation

imx6q xenomai ipipe-3.0-imx6q

Xenomai 嵌入式工程师 2 participants 8 messages Apr 18, 2014 – Apr 23, 2014

lore
Share & tools
lore
#0 lore raw

I do the same on the imx53 with imx6 test, in the process of real-time task to run the same operation content, start the qt deform demo and copy large file to memory, in 250 us the latency on imx6 board began to accumulate, lost real-time, but latency on the imx53 only value within 20 us. I do not run anyother rt task on my below test:

#include <linux/module.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/cdev.h>
#include <linux/ioctl.h>
#include <linux/gpio.h>
#include <linux/mm.h>
#include <linux/errno.h>
#include <asm/uaccess.h>
#include <linux/slab.h>
#include <asm/io.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/kthread.h>
#include <linux/delay.h>
#include <linux/err.h>
#include <nucleus/module.h>
#include <linux/string.h>
#include <native/timer.h>
#include <native/alarm.h>
#include <native/task.h>
#include <native/sem.h>
#include <native/intr.h>
#include <native/heap.h>
#include <rtdm/rtdm_driver.h>
#include <native/pipe.h>
#include <linux/spinlock.h>
#include <linux/io.h>
#include <linux/ipipe.h>
#include <nucleus/timer.h>
#define TASK_PRIO 99 /* Highest RT priority */ #define TASK_MODE 0 /* No flags */
#define TASK_STKSZ 0 /* Stack size (use default one) */ RTIME now, previous;
RTIME pnow, pprevious;
rtdm_task_t t1,t2,t3;
//RT_SEM semt1,semt2,semt3,irq_sem; rtdm_sem_t semt1,semt2,semt3;
RT_HEAP heap_desc;
long * mem_spvm;
void *block;
//static xntimer_t rtimer;
static rtdm_timer_t rtimer;

static IPIPE_DEFINE_SPINLOCK(mem_lock);
#define CAT_IRQ IMX_GPIO_NR(5, 0)
MODULE_LICENSE("GPL");
int irq = -1;
#define HEARTBEAT_PERIOD250000 /* 100 ms */
static rtdm_task_t heartbeat_task,heartbeat_task1,heartbeat_task2;

static unsigned char logo[1024*10]={0};

long long tmp=0;
int irq_taskOne(int irq, void *device_id)
{
//rt_task_set_periodic(NULL,TM_NOW,250000);
//rt_sem_v(&irq_sem);
return RT_INTR_HANDLED;
}
long i;
long max,pmax;
int j;

void taskOne(void*arg)
{
previous = rt_timer_read();
pprevious=rt_timer_read();

while(1)
{
//rt_sem_p(&irq_sem,TM_INFINITE);
unsigned long flags;
pnow = rt_timer_read();
if(pmax<(long)(pnow - pprevious-tmp))
pmax=(long)(pnow - pprevious-tmp);
if(j<10000)
pmax=0;
if(i%20000==0){
rtdm_printk ("1task: %d.%06d ms\n",

     (int)(pnow - pprevious-tmp) / 1000000,
     (int)(pnow - previous-tmp) % 1000000);

rtdm_printk ("pmax: %ld.%06ld ms\n",(long)pmax/1000000,(long)pmax%1000000); }
//spin_lock_irqsave(&mem_lock, flags); memset(mem_spvm,0,sizeof(logo)); memcpy(mem_spvm,logo,sizeof(logo)); memset(mem_spvm,255,sizeof(logo)); memcpy(mem_spvm,logo,sizeof(logo)); memset(mem_spvm,0,sizeof(logo)); memcpy(mem_spvm,logo,sizeof(logo)); memset(mem_spvm,255,sizeof(logo)); memcpy(mem_spvm,logo,sizeof(logo)); memset(mem_spvm,0,sizeof(logo)); /*memcpy(mem_spvm,logo,sizeof(logo)); memset(mem_spvm,255,sizeof(logo)); memcpy(mem_spvm,logo,sizeof(logo)); memset(mem_spvm,0,sizeof(logo)); memcpy(mem_spvm,logo,sizeof(logo)); memset(mem_spvm,255,sizeof(logo)); memcpy(mem_spvm,logo,sizeof(logo)); memset(mem_spvm,0,sizeof(logo)); memcpy(mem_spvm,logo,sizeof(logo)); memset(mem_spvm,255,sizeof(logo)); memcpy(mem_spvm,logo,sizeof(logo)); memset(mem_spvm,0,sizeof(logo)); memcpy(mem_spvm,logo,sizeof(logo)); memset(mem_spvm,255,sizeof(logo)); memcpy(mem_spvm,logo,sizeof(logo));*/ //spin_unlock_irqrestore(&mem_lock, flags);
now = rt_timer_read();
if(max<(long)(now - previous-tmp))
max=(long)(now - previous-tmp);
if(j++<10000)
max=0;
if(i++%20000==0){
printk("1task: %d.%06d ms\n",

     (int)(now - previous-tmp) / 1000000,
     (int)(now - previous-tmp) % 1000000);

rtdm_printk ("1max: %ld.%06ld ms\n",(long)max/1000000,(long)max%1000000); rtdm_printk ("spvm6: %d \n",(char)mem_spvm[6]);
rtdm_printk ("spvm1: %d ",(char)mem_spvm[sizeof(logo)]);
}
tmp=tmp+250000;
rtdm_sem_up(&semt1);
//rt_sem_v(&semt2);
//rt_task_wait_period(NULL);
rtdm_task_wait_period();
}
}

void taskTwo(void*arg)
{
int i=0;
long max=0;
while(1)
{
//rt_sem_p(&semt2,TM_INFINITE); rtdm_sem_down(&semt1) ;
now = rt_timer_read(); memset(mem_spvm,255,sizeof(logo)); memcpy(mem_spvm,logo,sizeof(logo)); if(i++%20000==0){
rtdm_printk ("2spvm6: %d \n",(char)mem_spvm[6]); rtdm_printk ("2spvm1: %d\n",(char)mem_spvm[sizeof(logo)]); }

rtdm_sem_up(&semt2);
}
}

void taskThree(void*arg)
{

int i;
while(1)
{
rtdm_sem_down(&semt2) ; memset(mem_spvm,255,sizeof(logo)); memcpy(mem_spvm,logo,sizeof(logo)); if(i++%20000==0){
rtdm_printk ("3spvm6: %d \n",(char)mem_spvm[6]); rtdm_printk ("3spvm1: %d\n",(char)mem_spvm[sizeof(logo)]); }
}
}

#define HEAP_SIZE (15*1024*1024)

#define HEAP_MODE 0 /* Local heap. */
RT_INTR intr_desc;
static int periode_us = 1000;
static int __init rtex_init(void){

int ret,err;
/*err = gpio_request(CAT_IRQ,NULL);
if(err < 0){
printk("gpio_request failure !\n");
return err;
}
err = gpio_direction_input(CAT_IRQ);
if(err < 0){
printk("gpio_direction_input failure !\n");
return err;
}
irq = gpio_to_irq(CAT_IRQ); irq_set_irq_type(irq,IRQ_TYPE_EDGE_RISING);
err = rt_intr_create(&intr_desc,"MyIrq",irq,irq_taskOne,NULL,I_SHARED|I_EDGE); if(err){
printk("rt_intr_create failure !\n");
return err;
}
printk("rt_intr_create irq=%d\n",irq); rt_intr_enable(&intr_desc);
printk("I have enable the irq\n");*/

/*err =rt_heap_create(&heap_desc,"MyHeapName1",HEAP_SIZE,HEAP_MODE); if (err)
printk("rt_heap_create wrong\n");
err = rt_heap_alloc(&heap_desc,1024*1024,TM_INFINITE,&block); if (err)
printk("rt_heap_alloc wrong\n");*/ block=(long*)rtdm_malloc(1024*11);
mem_spvm=(long*)block;
if(mem_spvm == NULL )

              printk("mem_spvm failed!\n"); 
        else 
              printk("mem_spvm successfully! \naddr = 0x%lx\n",(unsigned long)mem_spvm); 

/*rt_sem_create(&semt1,"",0,S_FIFO); rt_sem_create(&semt2,"",0,S_FIFO); rt_sem_create(&semt3,"",0,S_FIFO); rt_sem_create(&irq_sem,"",0,S_FIFO);*/ rtdm_sem_init(&semt1,0) ;
rtdm_sem_init(&semt2,0) ;
rtdm_sem_init(&semt3,0) ;
/*if(!rt_task_create(&t1, "task1", 4096, 99, T_FPU|T_CPU(0))) rt_task_start(&t1, taskOne, NULL);*/ /*if(!rt_task_create(&t2, "task2", 4096, 85, T_FPU|T_CPU(1))) rt_task_start(&t2, taskTwo, NULL); if(!rt_task_create(&t3, "task3", 4096, 80, T_FPU|T_CPU(2))) rt_task_start(&t3,taskThree, NULL);*/

printk("mem_spv ! \naddr = 0x%lx\n",(unsigned long)mem_spvm);
        rtdm_task_init(&heartbeat_task, "heartbeat", taskOne, NULL,
     99, HEARTBEAT_PERIOD);


     rtdm_task_set_period(&heartbeat_task,250000) ;

rtdm_task_set_priority(&heartbeat_task,99); rtdm_task_unblock(&heartbeat_task);
printk("mem_spvm successfully! \naddr = 0x%lx\n",(unsigned long)mem_spvm); rtdm_task_init(&heartbeat_task2, "heartbeat1", taskThree, NULL,

     80, HEARTBEAT_PERIOD);
rtdm_task_init(&heartbeat_task1, "heartbeat1", taskTwo, NULL,
     85, HEARTBEAT_PERIOD);

//xnticks_t now;
//now = xntbase_get_jiffies(&nktbase);
/*if ((err = rtdm_timer_init(& rtimer, taskOne, "Oscillateur")) != 0) {
return err;
}
if ((err = rtdm_timer_start(& rtimer, periode_us*250, periode_us*250, RTDM_TIMERMODE_RELATIVE)) != 0) { rtdm_timer_destroy(& rtimer);
return err;
}*/
/*xntbase_enabled_p(&nktbase);
xntimer_init(&rtimer, &nktbase, taskOne);

xntimer_set_priority(&rtimer, XNTIMER_HIPRIO); xntimer_start(&rtimer, 250000UL, 250000UL, XN_RELATIVE);*/

return ret;

}

static void __exit rtex_exit(void)
{

//rt_heap_free(&heap_desc,block);
//rt_heap_delete(&heap_desc);
rtdm_free(block);
rtdm_task_join_nrt(&heartbeat_task, 100);
//rt_task_delete(&t1);
rt_task_delete(&t2);
rt_task_delete(&t3);
printk("rtex_exit \n");
}
module_init(rtex_init);
module_exit(rtex_exit);

#1 lore raw
Quoted 8 lines · 嵌入式工程师

I do the same on the imx53 with imx6 test, in the process of real-time task to run the same operation content, start the qt deform demo and copy large file to memory, in 250 us the latency on imx6 board began to accumulate, lost real-time, but latency on the imx53 only value within 20 us. I do not run anyother rt task on my below test:

Looking at your code, it seems your problem (if I understand correctly), is that a series of memcpy and memset takes a long time to execute when non real-time activities are given an opportunity to thrash the cache.

Am I understanding correctly?

Signature · 1 line
                                                                Gilles.
author
#2 lore raw

So if my program use lots of memory operations for a long time it maybe gives non real-time activities opportunity to thrash the cache?

--
发自我的网易邮箱平板适配版
<br/><br/><br/>

----- Original Message -----
From: "Gilles Chanteperdrix" <[email protected]>
To: "嵌入式工程师" <[email protected]>
Cc: "[email protected]" <[email protected]>, [email protected], [email protected]
Sent: Fri, 18 Apr 2014 13:47:15 +0200
Subject: Re: imx6q xenomai ipipe-3.0-imx6q

Quoted 8 lines · 嵌入式工程师

I do the same on the imx53 with imx6 test, in the process of real-time task to run the same operation content, start the qt deform demo and copy large file to memory, in 250 us the latency on imx6 board began to accumulate, lost real-time, but latency on the imx53 only value within 20 us. I do not run anyother rt task on my below test:

Looking at your code, it seems your problem (if I understand correctly), is that a series of memcpy and memset takes a long time to execute when non real-time activities are given an opportunity to thrash the cache.

Am I understanding correctly?

Signature · 1 line
                                                                Gilles.
#3 lore raw
Quoted 2 lines · eric

So if my program use lots of memory operations for a long time it maybe gives non real-time activities opportunity to thrash the cache?

It is unrelated, but on a multi-core processor even when one core is running a real-time task, other cores can thrash the cache at will, or slow down the real-time task by using a shared ressource (for instance DDR) and starving the core where the real-time task runs. By default the L2 cache is shared between all cores, you can try and reserve parts of the cache for each core (check the l2x0 registers documentation to see how), I tried this on omap4, but it results on worse latencies, situation may be different on imx6 though. Another problem is that since the L1 cache is per-core, I believe, and we disable L2 write allocate, reading on one core memory written on another core results in accesses at the DDR speed, and not at the cache speed.

All this to say that Xenomai focuses on trying to schedule your driver interrupts and application threads in a deterministic fashion but it is your job to make sure that these interrupts and threads do not take too long a time to execute, because if they do, yes, your application will not meet its deadlines, but it is not Xenomai's fault.

Signature · 1 line
Gilles.
#4 lore raw
Quoted 16 lines · Gilles Chanteperdrix
Quoted 2 lines · eric

So if my program use lots of memory operations for a long time it maybe gives non real-time activities opportunity to thrash the cache?

It is unrelated, but on a multi-core processor even when one core is running a real-time task, other cores can thrash the cache at will, or slow down the real-time task by using a shared ressource (for instance DDR) and starving the core where the real-time task runs. By default the L2 cache is shared between all cores, you can try and reserve parts of the cache for each core (check the l2x0 registers documentation to see how), I tried this on omap4, but it results on worse latencies, situation may be different on imx6 though. Another problem is that since the L1 cache is per-core, I believe, and we disable L2 write allocate, reading on one core memory written on another core results in accesses at the DDR speed, and not at the cache speed.

Quoted 5 lines

All this to say that Xenomai focuses on trying to schedule your driver interrupts and application threads in a deterministic fashion but it is your job to make sure that these interrupts and threads do not take too long a time to execute, because if they do, yes, your application will not meet its deadlines, but it is not Xenomai's fault.

I do not mean to say that you do not have a problem with Xenomai on imx6q, but so far, I have not understood what this problem was.

Signature · 1 line
Gilles.
author
#5 lore raw

OK thank you for the information
在 2014-04-20 17:23:19,"Gilles Chanteperdrix" <[email protected]> 写道:

Quoted 16 lines · Gilles Chanteperdrix
Quoted 2 lines · eric

So if my program use lots of memory operations for a long time it maybe gives non real-time activities opportunity to thrash the cache?

It is unrelated, but on a multi-core processor even when one core is running a real-time task, other cores can thrash the cache at will, or slow down the real-time task by using a shared ressource (for instance DDR) and starving the core where the real-time task runs. By default the L2 cache is shared between all cores, you can try and reserve parts of the cache for each core (check the l2x0 registers documentation to see how), I tried this on omap4, but it results on worse latencies, situation may be different on imx6 though. Another problem is that since the L1 cache is per-core, I believe, and we disable L2 write allocate, reading on one core memory written on another core results in accesses at the DDR speed, and not at the cache speed.

Quoted 5 lines

All this to say that Xenomai focuses on trying to schedule your driver interrupts and application threads in a deterministic fashion but it is your job to make sure that these interrupts and threads do not take too long a time to execute, because if they do, yes, your application will not meet its deadlines, but it is not Xenomai's fault.

I do not mean to say that you do not have a problem with Xenomai on imx6q, but so far, I have not understood what this problem was.

Signature · 1 line
Gilles.
author
#6 lore raw
Quoted 18 lines · 在 2014-04-20 18:46:21,eric <[email protected]> 写道:

在 2014-04-20 17:23:19,"Gilles Chanteperdrix" <[email protected]> 写道:

Quoted 16 lines · Gilles Chanteperdrix
Quoted 2 lines · eric

So if my program use lots of memory operations for a long time it maybe gives non real-time activities opportunity to thrash the cache?

It is unrelated, but on a multi-core processor even when one core is running a real-time task, other cores can thrash the cache at will, or slow down the real-time task by using a shared ressource (for instance DDR) and starving the core where the real-time task runs. By default the L2 cache is shared between all cores, you can try and reserve parts of the cache for each core (check the l2x0 registers documentation to see how), I tried this on omap4, but it results on worse latencies, situation may be different on imx6 though. Another problem is that since the L1 cache is per-core, I believe, and we disable L2 write allocate, reading on one core memory written on another core results in accesses at the DDR speed, and not at the cache speed.

Quoted 12 lines
Quoted 5 lines

All this to say that Xenomai focuses on trying to schedule your driver interrupts and application threads in a deterministic fashion but it is your job to make sure that these interrupts and threads do not take too long a time to execute, because if they do, yes, your application will not meet its deadlines, but it is not Xenomai's fault.

I do not mean to say that you do not have a problem with Xenomai on imx6q, but so far, I have not understood what this problem was.

Signature · 1 line
Gilles.

Hello Gilles I found the same test on x86 double cores and enble smp with rtai will not have the max delay ,it is just 50us latencies ,this is my test with rtai , the multi-core processor with shared cache can be thrashed just appears on imx6 and omap4 or all arm with multi-core has the same problems? thank you #include <linux/module.h>
#include <rtai.h>
#include <rtai_sched.h>
#include <asm/timex.h>
#define LPT1_BASE 0x378
#define STACK_SIZE 4096
#define TIMERTICKS 1000000

static RT_TASK tasks;
char logo[40*1024]={0};
char mem_spvm[40*1024];
RTIME previous,pprevious,now,pnow,pmax;
long long tmp=0;
long i=0;
unsigned long start,stop,task_max;
static void task(int t)

{
	previous = rt_get_time_ns();
	while(1){
	rt_task_wait_period();
	start=get_cycles();
	
	memset(mem_spvm,0,sizeof(logo));
		memcpy(mem_spvm,logo,sizeof(logo));
		memset(mem_spvm,127,sizeof(logo));
		memcpy(mem_spvm,logo,sizeof(logo));
		memset(mem_spvm,0,sizeof(logo));
		memcpy(mem_spvm,logo,sizeof(logo));
		memset(mem_spvm,127,sizeof(logo));
		memcpy(mem_spvm,logo,sizeof(logo));
		memset(mem_spvm,0,sizeof(logo));
		memcpy(mem_spvm,logo,sizeof(logo));
		memset(mem_spvm,127,sizeof(logo));
		memcpy(mem_spvm,logo,sizeof(logo));
		memset(mem_spvm,0,sizeof(logo));
		memcpy(mem_spvm,logo,sizeof(logo));
		memset(mem_spvm,127,sizeof(logo));
		memcpy(mem_spvm,logo,sizeof(logo));
		memset(mem_spvm,0,sizeof(logo));
		memcpy(mem_spvm,logo,sizeof(logo));
		memset(mem_spvm,127,sizeof(logo));
		memcpy(mem_spvm,logo,sizeof(logo));
		memset(mem_spvm,0,sizeof(logo));
		memcpy(mem_spvm,logo,sizeof(logo));
		memset(mem_spvm,127,sizeof(logo));
		memcpy(mem_spvm,logo,sizeof(logo));
		memset(mem_spvm,127,sizeof(logo));
		memset(mem_spvm,0,sizeof(logo));
		memcpy(mem_spvm,logo,sizeof(logo));
		memset(mem_spvm,127,sizeof(logo));
		memcpy(mem_spvm,logo,sizeof(logo));
	
		pnow=rt_get_time_ns();
		stop=get_cycles();
		pmax=(pnow-previous);
		pmax=pmax<0?-pmax:pmax;
		if(task_max<(stop-start))
		task_max=stop-start;
		if(i++<10000)
		task_max=0;
		printk("otime: %ld.%06ld ms\n",(long)pmax/1000000,(long)pmax%1000000);//the max delay about 154 us
		printk("stime: %ld.%06ld ms\n",(long)task_max/1000000,(long)task_max%1000000);//the max delay about 154 us
		//previous=pnow;
		previous=previous+1000000;
	
	}
}

int init_module(void)

{
	RTIME tick_period, now;

	rt_set_periodic_mode();
        rt_task_init(&task, task, 0, STACK_SIZE, 0, 0, 0);


	tick_period = start_rt_timer(nano2count (TIMERTICKS));
	now = rt_get_time();
	rt_task_make_periodic(&tasks, now + tick_period, tick_period);
	return 0;
}

void cleanup_module(void)

{
	stop_rt_timer();
	rt_busy_sleep(10000000);

	rt_task_delete(&tasks[0]);
	rt_task_delete(&tasks[1]);

}

#7 lore raw
Quoted 49 lines · eric
Quoted 28 lines · 在 2014-04-20 18:46:21,eric <[email protected]> 写道:
Quoted 18 lines · Gilles Chanteperdrix
Quoted 3 lines · eric

So if my program use lots of memory operations for a long time it maybe gives non real-time activities opportunity to thrash the cache?

It is unrelated, but on a multi-core processor even when one core is running a real-time task, other cores can thrash the cache at will, or slow down the real-time task by using a shared ressource (for instance DDR) and starving the core where the real-time task runs. By default the L2 cache is shared between all cores, you can try and reserve parts of the cache for each core (check the l2x0 registers documentation to see how), I tried this on omap4, but it results on worse latencies, situation may be different on imx6 though. Another problem is that since the L1 cache is per-core, I believe, and we disable L2 write allocate, reading on one core memory written on another core results in accesses at the DDR speed, and not at the cache speed.

Quoted 6 lines

All this to say that Xenomai focuses on trying to schedule your driver interrupts and application threads in a deterministic fashion but it is your job to make sure that these interrupts and threads do not take too long a time to execute, because if they do, yes, your application will not meet its deadlines, but it is not Xenomai's fault.

Quoted 5 lines

I do not mean to say that you do not have a problem with Xenomai on imx6q, but so far, I have not understood what this problem was.

-- Gilles.

Quoted 5 lines

Hello Gilles I found the same test on x86 double cores and enble smp with rtai will not have the max delay ,it is just 50us latencies ,this is my test with rtai , the multi-core processor with shared cache can be thrashed just appears on imx6 and omap4 or all arm with multi-core has the same problems? thank you

Yes, the behaviour of cache is highly dependent on the processor you are using. Besides, disabling L2 write allocate may be bad for you use case, you may want to re-enable it to see if it leads to better throughput in your case.

Signature · 1 line
                                                                Gilles.