Re: [rtl] Threads or Tasks?

2000-06-08 Thread Gusa

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 10  /* ns, ahora esta en .1s */
#define THREAD_PERIOD2 7   /* ns, ahora esta en .07s */
#define THREAD_PERIOD3 5   /* ns, ahora esta en .05s */
#define DURACION_THREAD1 2
#define DURACION_THREAD2 3
#define DURACION_THREAD3 2



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 r

Re: [rtl] Threads or Tasks?

2000-06-08 Thread Gusa

Thanks Philip.

Then it isn´t possible that a high priority task interrupt the work is doing a
low priority task.??? I mean, without hardware interrupts.
So, the designer of the system must know at any moment what he want to do. There
is not any posibility of having an error in the design. If you miss something
your system may never recover.
I´m correct??

worm

Philip N Daly escribió:

 
  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.

 No, it's a fixed priority scheduler that is pre-emptive on the Linux kernel.
 The real-time executive is *not* pre-emptive ... once a task has the CPU
 (no matter what it's priority), it retains it until it suspends itself. At
 that point, the higher priority task will get the CPU and so on.

 Regards,

 +==+
  Phil Daly, NOAO/AURA, 950 N. Cherry Avenue, Tucson AZ 85719, U S A
  E-mail: [EMAIL PROTECTED]  V-mail: (520) 318 8438  Fax: (520) 318 8360

-- [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/




[rtl] Threads or Tasks?

2000-06-06 Thread WORM

Hi all

As you´d  realized, i´m a newbie rtlinux user.

I´ve been wondering during the last days, which are the differents
between using threads and using tasks. Sorry for bothering you, but I
can´t find the answer to this.
Besides, i would like to know the pros and cons of using each other.

Thanks, Worm



-- [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/




Re: [rtl] Threads or Tasks?

2000-06-06 Thread Bernhard Kuhn

WORM wrote:

 I´ve been wondering during the last days, which are the differents
 between using threads and using tasks. Sorry for bothering you, but I
 can´t find the answer to this.

The definition for both expression may vary, depending
in which "computing-world" you are living in :-)

So i will try this:

In general, a "task" can be any kind of computing job
(even an interrupt service routine), but with Linux,
"task" usualy means "(user-space-)process". Every process has
it´s own address-space and other processes can´t access
the data except when using shared memory.

Threads can (or with RTL do) run in the same address-space,
sharing data.


 Besides, i would like to know the pros and cons of using each other.

Processes are protected against each other, but this causes some
overhead when switching tasks since the MMU has to be reconfigured
and the TLB may has to be updated.

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).

Comments?

Bernhard
-- [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/