Skip to contentSkip to conversation

T_RRB

Xenomai-help Hubert Talbot 3 participants 5 messages Feb 11, 2008

lore
Share & tools
lore
#0 lore raw

Hi,

I'm new to Xenomai.

I am studying xenomai and I would like to kwow how to apply round-robin.

Specifically, what to do with (do I have to?):

	- the kernel configuration

		Real-time sub-system/Timing/Enable periodic timing ?

	- the timer configuration 

		rt_timer_set_mode(rt_timer_ns2ticks(???))  ?

	- the task configuration

		rt_task_set_periodic(???)  ?
		rt_task_set_mode(0, T_RRB, 0)    ?
		rt_task_slice(???)  ?

Thanks in advanced.

Hubert

#1 lore raw
Quoted 4 lines · Hubert Talbot

Hi,

I'm new to Xenomai.

Quoted 8 lines

I am studying xenomai and I would like to kwow how to apply round-robin.

Specifically, what to do with (do I have to?):

- the kernel configuration

Real-time sub-system/Timing/Enable periodic timing ?

Yes. Round-robin scheduling is only available with tick-based timing.

Quoted 4 lines
	- the timer configuration 

		rt_timer_set_mode(rt_timer_ns2ticks(???))  ?

rt_timer_set_mode(ns), to switch the default oneshot mode for the native API to tick-based.

Quoted 3 lines
	- the task configuration

		rt_task_set_periodic(???)  ?

Not this one; it controls whether your task follows a periodic timeline using the rt_task_wait_period() service. It's not related to RRB.

Quoted 1 line
		rt_task_set_mode(0, T_RRB, 0)    ?

Yes, this one is needed to switch on RRB for the calling task.

Quoted 2 lines
		rt_task_slice(???)  ?

And this one allows to set the time quantum alloted to the task (in ticks).

Quoted 12 lines

Thanks in advanced.

Hubert

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

Signature · 1 line
Philippe.
#2 lore raw
Quoted 7 lines · Philippe Gerum
Quoted 6 lines · Hubert Talbot

Hi,

I'm new to Xenomai.

I am studying xenomai and I would like to kwow how to apply round-robin.

Quoted 8 lines
Quoted 6 lines

Specifically, what to do with (do I have to?):

- the kernel configuration

Real-time sub-system/Timing/Enable periodic timing ?

Yes. Round-robin scheduling is only available with tick-based timing.

IMHO, this should finally be implemented for one-shot timebases as well. Setting up an additional time-slice timer for such tasks shouldn't be infeasible. Well, if I happen to have the time for this, one day... :)

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#3 lore raw

[Xenomai-help] Rép. : Re: T_RRB

In reply to Philippe Gerum

There is something I don't understand.

Does Xenomai really implement RRB?

Here is my code:

//**************************************************** #include <sys/mman.h>
#include <native/task.h>
#include <native/timer.h>
#include <native/sem.h>

#define NBTASK 2
#define NSEC 1
#define USEC 1000
#define MSEC 1000000
#define SEC 1000000000

RT_TASK tasks[NBTASK];
RT_SEM sem;

void my_sleep(int nSec)

{
	struct timeval tv_start, tv_current;
	
	gettimeofday(&tv_start, 0);
	
	do
	{
//		rt_task_wait_period(NULL);
		struct timeval;
		gettimeofday(&tv_current, 0);
	} while (tv_current.tv_sec - tv_start.tv_sec <= nSec);
}

void task(void *arg)

{
	int taskID = *((int *)arg);
	struct timeval tv_start, tv_end;
	
	rt_task_set_mode(0, T_RRB, 0); 
	rt_task_slice(NULL, rt_timer_ns2ticks(10 * MSEC)); 

	rt_sem_p(&sem, TM_INFINITE); 
   	printf("task %d start...\n", taskID);
	gettimeofday(&tv_start, 0);
//	sleep(1);
	my_sleep(1);

	gettimeofday(&tv_end, 0);
	printf("task %d end (%d sec)\n", taskID, tv_end.tv_sec - tv_start.tv_sec);
}

int main(void)

{
	int rc;
	int i;
	struct timeval tv1, tv2;

	mlockall(MCL_CURRENT | MCL_FUTURE);
	
	rc = rt_timer_set_mode(1 * MSEC);
	if (rc != 0)
	{
		printf("failed to rt_timer_set_mode: %d\n", rc);
		return rc;
	}

	rt_sem_create(&sem, "sem", 0, S_FIFO);
	
	for (i = 0; i < NBTASK; i++)
	{
		char szTaskID[20];
		sprintf(szTaskID, "Task%02d", i);
		rt_task_create(&tasks[i],
				szTaskID,
				4096,
				99,
				T_JOINABLE);
	}

	gettimeofday(&tv1, 0);

	for (i = 0; i < NBTASK; i++)
	{
	   	RT_TASK_INFO info;
	
		rt_task_start(&tasks[i], &task, (void *)&i);
	}	
	
	rt_sem_broadcast(&sem);

	for (i = 0; i < NBTASK; i++)
	{
    		rt_task_join(&tasks[i]);
    	}

	gettimeofday(&tv2, 0);
	printf("****** total time: %d (sec)\n\n", tv2.tv_sec - tv1.tv_sec);

	rt_sem_delete(&sem);

	return 0;
}

//****************************************************

CASE 1
---------
In the task function, if I use my_sleep() the output is:

	task 0 start...
	task 0 end (2 sec)
	task 1 start...
	task 1 end (2 sec)
	****** total time: 4 (sec)

...not really RRB.

CASE 2
---------
If I use sleep() the output is:

	task 0 start...
	task 1 start...
	task 0 end (1 sec)
	task 1 end (1 sec)
	****** total time: 1 (sec)

...ok, RRB but why?

CASE 3
---------
In my_sleep(), if I uncomment

	// rt_task_wait_period(NULL);

The output is

	task 0 start...
	task 1 start...
	task 0 end (2 sec)
	task 1 end (2 sec)
	****** total time: 2 (sec)

It seems for me the the latter does not need RRB.

Sould output from CASE 1 be like CASE 2 (or at least like CASE 3) ?

Am I missing something?

Thanks in advance

Hubert

Quoted 1 line
Quoted 1 line
Quoted 1 line

Philippe Gerum <[email protected]> 2008-02-11 13:28 >>>

Quoted 4 lines · Hubert Talbot

Hi,

I'm new to Xenomai.

Quoted 8 lines

I am studying xenomai and I would like to kwow how to apply round-robin.

Specifically, what to do with (do I have to?):

- the kernel configuration

Real-time sub-system/Timing/Enable periodic timing ?

Yes. Round-robin scheduling is only available with tick-based timing.

Quoted 4 lines
	- the timer configuration 

		rt_timer_set_mode(rt_timer_ns2ticks(???))  ?

rt_timer_set_mode(ns), to switch the default oneshot mode for the native API to tick-based.

Quoted 3 lines
	- the task configuration

		rt_task_set_periodic(???)  ?

Not this one; it controls whether your task follows a periodic timeline using the rt_task_wait_period() service. It's not related to RRB.

Quoted 1 line
		rt_task_set_mode(0, T_RRB, 0)    ?

Yes, this one is needed to switch on RRB for the calling task.

Quoted 2 lines
		rt_task_slice(???)  ?

And this one allows to set the time quantum alloted to the task (in ticks).

Quoted 12 lines

Thanks in advanced.

Hubert

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

Signature · 1 line
Philippe.
#4 lore raw

Re: [Xenomai-help] Rép. : Re: T_RRB

Quoted 4 lines · Hubert Talbot

There is something I don't understand.

Does Xenomai really implement RRB?

Yes it does, and it even happens to work, provided it is used properly.

Quoted 18 lines

Here is my code:

//**************************************************** #include <sys/mman.h>
#include <native/task.h>
#include <native/timer.h>
#include <native/sem.h>

#define NBTASK 2
#define NSEC 1
#define USEC 1000
#define MSEC 1000000
#define SEC 1000000000

RT_TASK tasks[NBTASK];
RT_SEM sem;

void my_sleep(int nSec)

Quoted 13 lines
{
	struct timeval tv_start, tv_current;
	
	gettimeofday(&tv_start, 0);
	
	do
	{
//		rt_task_wait_period(NULL);
		struct timeval;
		gettimeofday(&tv_current, 0);
	} while (tv_current.tv_sec - tv_start.tv_sec <= nSec);
}

Xenomai RRB will work for tasks controlled by the Xenomai scheduler. By calling gettimeofday(), your tasks switch to a runtime mode where they depend on the Linux scheduler, so there is no way for the round-robin swap to take place properly at Xenomai level. Your tasks will just run in FIFO order due to Linux scheduling.

The code below will exhibit RRB scheduling controlled by the Xenomai core; the point is to use the real-time API to perform the busy-wait, and never call into any Linux service in the meantime:

#include <stdio.h>
#include <sys/mman.h>
#include <native/task.h>
#include <native/timer.h>
#include <native/sem.h>

#define NBTASK 2
#define NSEC 1
#define USEC 1000
#define MSEC 1000000
#define SEC 1000000000
#define PERIOD (10 * MSEC)

RT_TASK tasks[NBTASK];
RT_SEM sem;

static inline unsigned tick_delta(RTIME t0, RTIME t1)

{
	return ((unsigned)(t1 - t0) * PERIOD) / SEC;
}

void my_sleep(int nSec)

{
	RTIME start_ticks, wait_ticks;
	
	wait_ticks = (nSec * SEC) / PERIOD;
	start_ticks = rt_timer_read();

	while (rt_timer_read() - start_ticks <= wait_ticks)
		;
}

void task(void *arg)

{
	int taskID = (int)(long)arg;
	RTIME start_date, end_date;
	
	rt_sem_p(&sem, TM_INFINITE);

printf("task %d start...\n", taskID);

	rt_task_slice(NULL, rt_timer_ns2ticks(PERIOD));
	rt_task_set_mode(0, T_RRB, 0);

	start_date = rt_timer_read();
	my_sleep(1);
	end_date = rt_timer_read();

	printf("task %d end (%u sec)\n", taskID, tick_delta(start_date, end_date));
}

int main(void)

{
	int rc;
	int i;
	RTIME tv1, tv2;

	mlockall(MCL_CURRENT | MCL_FUTURE);
	
	rc = rt_timer_set_mode(1 * MSEC);
	if (rc != 0)
	{
		printf("failed to rt_timer_set_mode: %d\n", rc);
		return rc;
	}

	rt_sem_create(&sem, "sem", 0, S_FIFO);
	
	for (i = 0; i < NBTASK; i++)
	{
		char szTaskID[20];
		sprintf(szTaskID, "Task%02d", i);
		rt_task_create(&tasks[i],
				szTaskID,
				4096,
				99,
				T_JOINABLE);
	}

	tv1 = rt_timer_read();

	for (i = 0; i < NBTASK; i++)
	{
	   	RT_TASK_INFO info;
	
		rt_task_start(&tasks[i], &task, (void *)(long)i);
	}	
	
	rt_sem_broadcast(&sem);

	for (i = 0; i < NBTASK; i++)
	{
    		rt_task_join(&tasks[i]);
    	}

	tv2 = rt_timer_read();

	printf("****** total time: %u (sec)\n\n", tick_delta(tv1, tv2));

	rt_sem_delete(&sem);

	return 0;
}
Signature · 1 line
Philippe.