Hi everybody
Thanks Bernhard
It�s clear. You said
With RTL, "real time tasks" have more in common with "threads"
than with "processes" since they run in the same address space.
(as like "kernel-threads" a running in the same address space
as the kernel itself).
This answer my question, but ...
i�m doing some experiences in programming rtlinux modules, and make myself
familiar with the api.
I want to test the scheduler. I understood that it�s fixed priorities. So,
i run a module that create three threads with diferents priorities, say 1,
2 and 3.
I �ve done the questions about the differents between threads and tasks,
because i want to know what happen with the priorities in tasks and
threads.
Supose i want to do three things in a periodic form. I assign each of
them to a thread with different priority. Let�s say priorities 1, 2 and
3.
I unsdestood, reading docs and mailing list, that the scheduler in
rtlinux is a priority one. Let�s say, that if i run the three threads in
a periodic form, the one with priority executes first, then the one with
priority 2 and so on. If, during the execution of thread 2, thread 1
need the cpu because of its period, the scheduler should interrupt the
execution of thread 2 and start executes thread 1, because it priority.
The same things happen if it�s running thread 3 and thread 2 need to
run.
Is it true? I don�t know if i�m wrong. I did a code with three threads
that is not working as i�ve just described.
Then i wondered if the best way to make things work like i �ve just
described is using threads or using rtl tasks??
Perhaps threads don�t support priorities and tasks do.
Well, all your comments are wellcome.
I don�t need that you explain me the different between thread and
process, i know them. My doubts are rtl especific. I try to make things
work in a manner that may be is incorrect.
Thanks everybody.
worm
I attach the code ......
#include <rtl.h>
#include <rtl_fifo.h>
#include <rtl_sync.h>
#include <time.h>
#include <pthread.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/errno.h>
#include <rtl_sched.h>
#define TIME_FIFO 1
#define FIFO_SIZE 1024*20
#define THREAD_PERIOD1 100000 /* ns, ahora esta en .1s */
#define THREAD_PERIOD2 70000 /* ns, ahora esta en .07s */
#define THREAD_PERIOD3 50000 /* ns, ahora esta en .05s */
#define DURACION_THREAD1 20000
#define DURACION_THREAD2 30000
#define DURACION_THREAD3 20000
pthread_t thread1,thread2,thread3;
struct datos {
int threadnumber;
long num;
hrtime_t tiempo;
};
/*-----------------------------------------------------------------------*/
/*
thread_code1
*/
/*-----------------------------------------------------------------------*/
/* Esta rutina la ejecuta el thread1 */
void * thread_code1(void *arg)
{
struct datos to_fifo1;
hrtime_t t_entrada,tiempo,diferencia;
int i;
struct sched_param p1;
p1 . sched_priority = 1;
pthread_setschedparam (pthread_self(), SCHED_FIFO, &p1);
pthread_make_periodic_np (pthread_self(), gethrtime(),
THREAD_PERIOD1);
for (i=1;i<=200;i++)
{
t_entrada=gethrtime();
diferencia=t_entrada - t_entrada;
rtl_printf("Ejecutando thread 1 en %d \n",t_entrada);
while (diferencia<=DURACION_THREAD1)
{
tiempo=gethrtime();
to_fifo1.threadnumber = 1;
to_fifo1.num = i;
to_fifo1.tiempo = tiempo;
rtf_put(TIME_FIFO, (char *)&to_fifo1, sizeof(to_fifo1));
diferencia = tiempo - t_entrada;
}
pthread_wait_np();
}
return 0;
}
/*-----------------------------------------------------------------------*/
/*
thread_code2
*/
/*-----------------------------------------------------------------------*/
/* Esta rutina la ejecuta el thread2 */
void * thread_code2(void *arg)
{
struct datos to_fifo2;
hrtime_t t_entrada,tiempo,diferencia;
int i;
struct sched_param p2; /* Parametros del threads, en principio solo nos
importa la prioridad. Por mas detalles ver el
tutorial de Posix thredas. */
p2 . sched_priority = 2;
pthread_setschedparam (pthread_self(), SCHED_FIFO, &p2);
pthread_make_periodic_np (pthread_self(), gethrtime(),
THREAD_PERIOD2);
for (i=1;i<=200;i++)
{
t_entrada=gethrtime();
diferencia=0;
rtl_printf("Ejecutando thread 2 en %d \n",t_entrada);
while (diferencia<=DURACION_THREAD2)
{
tiempo=gethrtime();
to_fifo2.threadnumber = 2;
to_fifo2.num = i;
to_fifo2.tiempo = tiempo;
rtf_put(TIME_FIFO, (char *)&to_fifo2, sizeof(to_fifo2));
diferencia=tiempo - t_entrada;
}
pthread_wait_np();
}
return 0;
}
/*-----------------------------------------------------------------------*/
/*
thread_code3
*/
/*-----------------------------------------------------------------------*/
/* Esta rutina la ejecuta el thread3 */
void * thread_code3(void *arg)
{
struct datos to_fifo3;
hrtime_t t_entrada,tiempo,diferencia;
int i;
struct sched_param p3; /* Parametros del threads, en principio solo nos
importa la prioridad. Por mas detalles ver el
tutorial de Posix thredas. */
p3 . sched_priority = 3;
pthread_setschedparam (pthread_self(), SCHED_FIFO, &p3);
pthread_make_periodic_np (pthread_self(), gethrtime(),
THREAD_PERIOD3);
for (i=1;i<=200;i++)
{
t_entrada=gethrtime();
diferencia=0;
rtl_printf("Ejecutando thread 3 en %d \n",t_entrada);
while (diferencia<=DURACION_THREAD3)
{
tiempo=gethrtime();
to_fifo3.threadnumber = 3;
to_fifo3.num = i;
to_fifo3.tiempo = tiempo;
rtf_put(TIME_FIFO, (char *)&to_fifo3, sizeof(to_fifo3));
diferencia = tiempo - t_entrada;
}
pthread_wait_np();
}
return 0;
}
/*-----------------------------------------------------------------------*/
/* init_module
*/
/*-----------------------------------------------------------------------*/
int init_module(void) {
rtf_create(TIME_FIFO,FIFO_SIZE);
pthread_create (&thread1, NULL, thread_code1, 0);
pthread_create (&thread2, NULL, thread_code2, 0);
pthread_create (&thread3, NULL, thread_code3, 0);
return 0;
}
/*-----------------------------------------------------------------------*/
/* cleanup_module
*/
/*-----------------------------------------------------------------------*/
void cleanup_module(void) { /* Descarga el modulo y deja las cosas
como estaban.*/
rtf_destroy(TIME_FIFO);
pthread_delete_np (thread1);
pthread_delete_np (thread2);
pthread_delete_np (thread3);
}
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/