All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christophe Carton <christophe.carton@ixblue.com>
To: xenomai@xenomai.org
Subject: [Xenomai] Round robin scheduling seem not working in a specific case...
Date: Tue, 04 Nov 2014 11:34:47 +0100	[thread overview]
Message-ID: <5458ABC7.2080201@ixblue.com> (raw)

Hello,

I am currently working with Xenomai 2.6.4 with native skin and with a 
Linux kernel 3.14.17.
The linux and the xenomai have been taken from the following Git 
repositories :
* http://git.xenomai.org/xenomai-2.6.git - tag v2.6.4
* http://git.xenomai.org/ipipe.git - tag ipipe-core-3.14.17-x86-4

I am encountering a problem to enable the Round Robin scheduler in a 
specific case :
* Two tasks ("rr task 1" and "rr task 2") of priority 10 are launched by 
a task ("init task") of priority 90.
* All 3 of them are configured with a RR scheduler via "rt_task_slice" 
API before they are started.
In this case the FIFO scheduling seems to be applied (could be seen via 
rt_printf logs).

I have found a thread on the mailing list that gives an example 
demonstrating the good behavior of the RR scheduler.
http://www.xenomai.org/pipermail/xenomai/2011-November/024897.html
http://www.xenomai.org/pipermail/xenomai/2011-November/024899.html
This example implies that the tasks are locked via a semaphore at 
startup and that this semaphore is unlocked by the main when all threads 
have been started.
This is necessary in this case due to the fact that the main function is 
no an RT task.

This implementation (with the semaphore) applied to my test works. Why 
is the semaphore needed in my case?
The 2 RT lower priority ("rr task 1" and "rr task 2") runs when my high 
priority task ("init task") is waiting on the "rt_task_join". They are 
are so launched at the "same time" with a RR scheduling. But the FIFO 
scheduling seems to be taken into account when I look at the logs...
Were am I wrong?

You could find attached my source code.

Best regards,

-- 

*Christophe Carton *



-------------- next part --------------
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <math.h>
#include <assert.h>

#include <xenomai/native/timer.h>
#include <xenomai/native/task.h>
#include <xenomai/native/sem.h>

#include <rtdk.h>

#define NB_TASKS (2UL)

#define EXECTIME_NS (100e6) // 100 ms
#define WORKTIME_NS (100e3) // 100 µs
#define CPU_ID (1)
RT_SEM synchro_sem;

RTIME slice = 2; //rt_timer_ns2ticks(20000);

static void task(void *)
{
/*
	int err;
	err = rt_sem_p(&synchro_sem, TM_INFINITE);
	if ( err )
	{
		rt_fprintf(stderr, "%s-rt_sem_p error %d\n", __FUNCTION__, err);
		return;
	}
*/
	RT_TASK_INFO curtaskinfo;
	RT_TASK *curtask = nullptr;
	rt_task_inquire(curtask, &curtaskinfo);
	for(  ; curtaskinfo.exectime < EXECTIME_NS ;  )
	{
		rt_timer_spin(WORKTIME_NS);
		// dummy average processing
		rt_task_inquire(curtask, &curtaskinfo);
		RTIME timepoint = rt_timer_read();
		rt_printf(
				"%lu Running [%s] priority [%d] at : [%lu ns]\n",
				timepoint,
				curtaskinfo.name,
				curtaskinfo.cprio,
				curtaskinfo.exectime);
	}
}

static void init_task(void *)
{
	RT_TASK task_desc_1, task_desc_2;
	int err;

	err = rt_task_slice( nullptr, slice );
	if ( err )
	{
		rt_fprintf(stderr, "%s-rt_task_slice error %d\n", __FUNCTION__, err);
		return;
	}

	err = rt_task_create ( &task_desc_1, "rr task 1", 0, 10, T_JOINABLE | T_CPU(CPU_ID) );
	if ( err )
	{
		rt_fprintf(stderr, "%s-rt_task_create error %d\n", __FUNCTION__, err);
		return;
	}

	err = rt_task_create ( &task_desc_2, "rr task 2", 0, 10, T_JOINABLE | T_CPU(CPU_ID) );
	if ( err )
	{
		rt_fprintf(stderr, "%s-rt_task_create error %d\n", __FUNCTION__, err);
		return;
	}

	rt_printf("slice ticks = %lu\n", slice);
	err = rt_task_slice( &task_desc_1, slice );
	if ( err )
	{
		rt_fprintf(stderr, "%s-rt_task_slice error %d\n", __FUNCTION__, err);
		return;
	}

	err = rt_task_slice( &task_desc_2, slice );
	if ( err )
	{
		rt_fprintf(stderr, "%s-rt_task_slice error %d\n", __FUNCTION__, err);
		return;
	}

	err = rt_task_start( &task_desc_1, &task, nullptr );
	if ( err )
	{
		rt_fprintf(stderr, "%s-rt_task_start error %d\n", __FUNCTION__, err);
		return;
	}

	err = rt_task_start( &task_desc_2, &task, nullptr );
	if ( err )
	{
		rt_fprintf(stderr, "%s-rt_task_start error %d\n", __FUNCTION__, err);
		return;
	}

	rt_printf("Launch!!!\n");
	err = rt_sem_broadcast(&synchro_sem);
	if ( err )
	{
		rt_fprintf(stderr, "%s-rt_sem_broadcast error %d\n", __FUNCTION__, err);
		return;
	}
	rt_printf("Launched!!!\n");

	rt_task_join( &task_desc_1 );
	rt_task_join( &task_desc_2 );
}

int main (int argc, char* argv[])
{
	(void)argc;
	(void)argv;
	RT_TASK init_task_desc;
	
	int err=0;

	err = mlockall( MCL_CURRENT | MCL_FUTURE );
	if( err < 0 )
	{
		perror("mlockall");
		return EXIT_FAILURE;
	}

	rt_print_auto_init(1);

	// semaphore to sync task startup on
	err = rt_sem_create(&synchro_sem, "Synchro sem", 0, S_FIFO);
	if ( err )
	{
		rt_fprintf(stderr, "%s-rt_sem_create error %d\n", __FUNCTION__, err);
		return 1;
	}

	err = rt_task_shadow( nullptr, "main", 95, T_CPU(1) );
	if ( err )
	{
		rt_fprintf(stderr, "%s-rt_task_shadow error %d\n", __FUNCTION__, err);
		return 1;
	}
	err = rt_task_set_mode(0, T_CONFORMING, nullptr);
	if ( err )
	{
		rt_fprintf(stderr, "%s-rt_task_set_mode error %d\n", __FUNCTION__, err);
		return 1;
	}

	err = rt_task_create ( &init_task_desc, "init task", 0, 90, T_JOINABLE | T_CPU(CPU_ID) );
	if ( err )
	{
		rt_fprintf(stderr, "%s-rt_task_create error %d\n", __FUNCTION__, err);
		return 1;
	}

	err = rt_task_slice( &init_task_desc, slice );
	if ( err )
	{
		rt_fprintf(stderr, "%s-rt_task_slice error %d\n", __FUNCTION__, err);
		return 1;
	}

	err = rt_task_start( &init_task_desc, &init_task, nullptr );
	if ( err )
	{
		rt_fprintf(stderr, "%s-rt_task_start error %d\n", __FUNCTION__, err);
		return 1;
	}

	rt_task_join( &init_task_desc );
	err = rt_sem_delete(&synchro_sem);
	if ( err )
	{
		rt_fprintf(stderr, "%s-rt_sem_delete error %d\n", __FUNCTION__, err);
		return 1;
	}

	return EXIT_SUCCESS;
}

             reply	other threads:[~2014-11-04 10:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-04 10:34 Christophe Carton [this message]
2014-11-04 10:41 ` [Xenomai] Round robin scheduling seem not working in a specific case Gilles Chanteperdrix
2014-11-04 10:59   ` Christophe Carton
2014-11-04 11:43 ` Philippe Gerum
2014-11-04 11:46   ` Gilles Chanteperdrix
2014-11-04 13:22     ` Philippe Gerum
2014-11-04 13:49       ` Christophe Carton
2014-11-04 14:05         ` Philippe Gerum
2014-11-04 14:09           ` Christophe Carton
2014-11-05 11:25             ` Christophe Carton
2014-11-05 13:33               ` Philippe Gerum
2014-11-05 14:11                 ` Christophe Carton
2014-11-05 14:36                   ` Philippe Gerum
2014-11-05 14:36                     ` Gilles Chanteperdrix
2014-11-05 15:13                     ` Christophe Carton

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=5458ABC7.2080201@ixblue.com \
    --to=christophe.carton@ixblue.com \
    --cc=xenomai@xenomai.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.