* [ECOS] Thread related queries
@ 2001-08-25 4:09 Jaiprakash
2001-08-27 8:04 ` Trenton D. Adams
2001-09-06 13:08 ` Jonathan Larmour
0 siblings, 2 replies; 5+ messages in thread
From: Jaiprakash @ 2001-08-25 4:09 UTC (permalink / raw)
To: ecos-discuss
Hello,
I have the following queries regarding implementation of threading in
ecos:
1. Does ecos consider main() as a running thread or is it just an entry
point to the system.
2. What is Cyg_Idle_thread used for? its functionality is not clear.
3. I was trying to compare following piece of code on linux 6.2 and
ecos running on my board.
#include <pthread.h>
#include <signal.h>
#define NUM_THREADS 3
void *PrintThreadid(void *threadid)
{
int i;
for(;;){
printf("\nthread %d\n",threadid);
i = sleep(1);
if(i) {
printf("return value from sleep() %d", i);
}
}
}
int main()
{
pthread_t threads[NUM_THREADS];
int rc, t,i,j;
int *thread_return;
pthread_attr_t attr;
rc = pthread_attr_init(&attr);
if(rc){
printf("ERROR: return code from pthread_attr_init %d", rc);
}
printf("\n creating threads\n");
for(t=0;t < NUM_THREADS;t++){
rc = pthread_create(&threads[t], &attr, PrintThreadid, (void *)
t);
if (rc){
printf("ERROR; return code from pthread_create()%d ", rc);
}
}
printf("\n running main thread\n");
pthread_attr_destroy(&attr);
for(t=0;t < NUM_THREADS;t++){
rc = pthread_join(threads[t], (void *)&thread_return);
if(rc){
printf("ERROR: return code from pthread_join %d", rc);
}
printf("Completed join with thread %d thread_return = %d\n",t,
thread_return );
}
while(1) ;
}
On linux the control goes to main() once, later the threads keep
running continuously. But in ecos the main() seems to get more
timeslice (15 - 20 times more) than the three threads. My basic clock
tick is 0.5 secs and timeslicing is 2 ticks. can you give me some
inputs regarding the difference of behaviour eventhough i am using
pthread calls.
There is not much documentation regarding implementation of threading
in ecos.
Thanking you in advance.
Jaiprakash N
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [ECOS] Thread related queries
2001-08-25 4:09 [ECOS] Thread related queries Jaiprakash
@ 2001-08-27 8:04 ` Trenton D. Adams
2001-09-06 13:08 ` Jonathan Larmour
1 sibling, 0 replies; 5+ messages in thread
From: Trenton D. Adams @ 2001-08-27 8:04 UTC (permalink / raw)
To: jaiprakash, ecos-discuss
See "Thread Operations" in the eCos Reference guide. Then take a look
at "ecos/examples/twothreads.c" one directory below the root of your
repository. That is to say the directory with "packages", and "host"
directories in it.
-----Original Message-----
From: ecos-discuss-owner@sources.redhat.com
[ mailto:ecos-discuss-owner@sources.redhat.com ] On Behalf Of Jaiprakash
Sent: Saturday, August 25, 2001 5:35 AM
To: ecos-discuss@sources.redhat.com
Subject: [ECOS] Thread related queries
Hello,
I have the following queries regarding implementation of threading in
ecos:
1. Does ecos consider main() as a running thread or is it just an entry
point to the system.
2. What is Cyg_Idle_thread used for? its functionality is not clear.
3. I was trying to compare following piece of code on linux 6.2 and
ecos running on my board.
#include <pthread.h>
#include <signal.h>
#define NUM_THREADS 3
void *PrintThreadid(void *threadid)
{
int i;
for(;;){
printf("\nthread %d\n",threadid);
i = sleep(1);
if(i) {
printf("return value from sleep() %d", i);
}
}
}
int main()
{
pthread_t threads[NUM_THREADS];
int rc, t,i,j;
int *thread_return;
pthread_attr_t attr;
rc = pthread_attr_init(&attr);
if(rc){
printf("ERROR: return code from pthread_attr_init %d", rc);
}
printf("\n creating threads\n");
for(t=0;t < NUM_THREADS;t++){
rc = pthread_create(&threads[t], &attr, PrintThreadid, (void *)
t);
if (rc){
printf("ERROR; return code from pthread_create()%d ", rc);
}
}
printf("\n running main thread\n");
pthread_attr_destroy(&attr);
for(t=0;t < NUM_THREADS;t++){
rc = pthread_join(threads[t], (void *)&thread_return);
if(rc){
printf("ERROR: return code from pthread_join %d", rc);
}
printf("Completed join with thread %d thread_return = %d\n",t,
thread_return );
}
while(1) ;
}
On linux the control goes to main() once, later the threads keep
running continuously. But in ecos the main() seems to get more
timeslice (15 - 20 times more) than the three threads. My basic clock
tick is 0.5 secs and timeslicing is 2 ticks. can you give me some
inputs regarding the difference of behaviour eventhough i am using
pthread calls.
There is not much documentation regarding implementation of threading
in ecos.
Thanking you in advance.
Jaiprakash N
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [ECOS] Thread related queries
2001-08-25 4:09 [ECOS] Thread related queries Jaiprakash
2001-08-27 8:04 ` Trenton D. Adams
@ 2001-09-06 13:08 ` Jonathan Larmour
2001-09-07 2:34 ` Nick Garnett
1 sibling, 1 reply; 5+ messages in thread
From: Jonathan Larmour @ 2001-09-06 13:08 UTC (permalink / raw)
To: jaiprakash; +Cc: ecos-discuss, Nick Garnett
Jaiprakash wrote:
> On linux the control goes to main() once, later the threads keep
> running continuously. But in ecos the main() seems to get more
> timeslice (15 - 20 times more) than the three threads. My basic clock
> tick is 0.5 secs and timeslicing is 2 ticks. can you give me some
> inputs regarding the difference of behaviour eventhough i am using
> pthread calls.
eCos is a real-time system (which Linux is not), which means you have to be
concerned about the thread priorities. A higher priority thread will get
all the CPU, unless it has been blocked for some reason. main()'s (eCos)
priority is set with the configuration variable
CYGNUM_POSIX_MAIN_DEFAULT_PRIORITY, and defaults to 30.
Unfortunately, a POSIX thread has a default POSIX priority of 0, which
translates to an ECOS_PRIORITY of (CYG_THREAD_MIN_PRIORITY-priority) i.e.
31. Not only is this less than main's, it is the same as the idle thread,
meaning it will be timeslicing with it.
I think instead sched_priority in pthread_attr_init() should default to 1.
Nick, know any reason why not?
Jifl
--
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [ECOS] Thread related queries
2001-09-06 13:08 ` Jonathan Larmour
@ 2001-09-07 2:34 ` Nick Garnett
2001-09-07 12:41 ` Jonathan Larmour
0 siblings, 1 reply; 5+ messages in thread
From: Nick Garnett @ 2001-09-07 2:34 UTC (permalink / raw)
To: Jonathan Larmour; +Cc: jaiprakash, ecos-discuss
Jonathan Larmour <jlarmour@redhat.com> writes:
> Jaiprakash wrote:
> > On linux the control goes to main() once, later the threads keep
> > running continuously. But in ecos the main() seems to get more
> > timeslice (15 - 20 times more) than the three threads. My basic clock
> > tick is 0.5 secs and timeslicing is 2 ticks. can you give me some
> > inputs regarding the difference of behaviour eventhough i am using
> > pthread calls.
>
> eCos is a real-time system (which Linux is not), which means you have to be
> concerned about the thread priorities. A higher priority thread will get
> all the CPU, unless it has been blocked for some reason. main()'s (eCos)
> priority is set with the configuration variable
> CYGNUM_POSIX_MAIN_DEFAULT_PRIORITY, and defaults to 30.
>
> Unfortunately, a POSIX thread has a default POSIX priority of 0, which
> translates to an ECOS_PRIORITY of (CYG_THREAD_MIN_PRIORITY-priority) i.e.
> 31. Not only is this less than main's, it is the same as the idle thread,
> meaning it will be timeslicing with it.
>
> I think instead sched_priority in pthread_attr_init() should default to 1.
> Nick, know any reason why not?
>
It is actually irrelevant, since the inherit attribute is set to
PTHREAD_INHERIT_SCHED the default is for all threads to inherit the
priority of their creator.
Without looking at Jaiprakash's program, it is difficult to know what
is actually happening.
--
Nick Garnett, eCos Kernel Architect
Red Hat, Cambridge, UK
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [ECOS] Thread related queries
2001-09-07 2:34 ` Nick Garnett
@ 2001-09-07 12:41 ` Jonathan Larmour
0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Larmour @ 2001-09-07 12:41 UTC (permalink / raw)
To: Nick Garnett; +Cc: jaiprakash, ecos-discuss
Nick Garnett wrote:
> It is actually irrelevant, since the inherit attribute is set to
> PTHREAD_INHERIT_SCHED the default is for all threads to inherit the
> priority of their creator.
True, I missed that aspect.
> Without looking at Jaiprakash's program, it is difficult to know what
> is actually happening.
It's here: http://sources.redhat.com/ml/ecos-discuss/2001-08/msg00846.html
but I don't see anything suspect.
Jaiprakash should try to debug it. In particular, in GDB set a breakpoint
and do "info threads" to see what the thread priorities _really_ are.
Jifl
--
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2001-09-07 12:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-25 4:09 [ECOS] Thread related queries Jaiprakash
2001-08-27 8:04 ` Trenton D. Adams
2001-09-06 13:08 ` Jonathan Larmour
2001-09-07 2:34 ` Nick Garnett
2001-09-07 12:41 ` Jonathan Larmour
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).