Skip to contentSkip to conversation

Thread scheduling on mult-processor systems

Xenomai-help Rob Gubler 2 participants 2 messages Jun 16, 2008

lore
Share & tools
lore

Rob Gubler

author
#0 lore raw

Hello,

I am trying execute 2 threads on 2 separate processors. To do this I created 2 threads, each using the FIFO scheduler where both threads have the same priority defined by sched_get_priority_max(SCHED_FIFO). Each thread is initialized to run on a specific CPU with a call to pthread_setaffinity_np(...); Thread 1 on CPU 0, and Thread 2 on CPU 1. I verified each thread was assigned correctly by calling pthread_getaffinity_np(...), and also by looking at /proc/xenomai/sched, while the program was running.

For the purposes of testing, both threads do the same thing:

        for(unsigned long i = 0; i != 9000000; i++)
        {
                if(!(i % 50000))
                {
                        std::cout << "tick" << std::endl;
                }

                sched_yield();
        }

        std::cout << "elapsed time: " << [elapsed time];

My hope was that when these threads would execute simultaneously, they would truly run in parallel on their respective processor. But, what I am noticing is the elapsed time when both threads run is 12 seconds, while when only one thread runs is 6 seconds. So, I haven't seem to have bought any performance improvements by assigning the thread to run on a specific processor.

Where have I gone wrong in my line of thinking?

-Rob

#1 lore raw
Quoted 25 lines · Rob Gubler

Hello,

I am trying execute 2 threads on 2 separate processors. To do this I created 2 threads, each using the FIFO scheduler where both threads have the same priority defined by sched_get_priority_max(SCHED_FIFO). Each thread is initialized to run on a specific CPU with a call to pthread_setaffinity_np(...); Thread 1 on CPU 0, and Thread 2 on CPU 1. I verified each thread was assigned correctly by calling pthread_getaffinity_np(...), and also by looking at /proc/xenomai/sched, while the program was running.

For the purposes of testing, both threads do the same thing:

        for(unsigned long i = 0; i != 9000000; i++)
        {
                if(!(i % 50000))
                {
                        std::cout << "tick" << std::endl;
                }

                sched_yield();
        }

        std::cout << "elapsed time: " << [elapsed time];
Quoted 9 lines

My hope was that when these threads would execute simultaneously, they would truly run in parallel on their respective processor. But, what I am noticing is the elapsed time when both threads run is 12 seconds, while when only one thread runs is 6 seconds. So, I haven't seem to have bought any performance improvements by assigning the thread to run on a specific processor.

Where have I gone wrong in my line of thinking?

Most of the code executed in this loop involves serialization, hence the result.

Signature · 1 line
Philippe.