0
votes

I am working on how dual core (especially in embedded systems) could be beneficial. I would like to compare two targets: one with ARM -cortex-A9 (925 MHz) dual core, and the other with ARM cortex-A8 single core. I have some ideas (please see below), but I am not sure, I will use the dual core features:

   My questions are: 

1-how to execute several threads on different cores (without OpenMP, because it didn't work on my target, and it isn't compatible with VxWorks)

2-How the kernel execute code on dual core with shared memory: how it allocate stack, heap, memory for global variable and static ones? 3-Is it possible to add C-flags in order to indicate number of CPU cores so we will be able to use dual core features. 4-How the kernel handle program execution (with a lot of threads) on dual core.

  Some tests to compare two architecture regarding OS and Dual core / single core  

  Dual core VS single core:

create three threads that execute some routines and depend on each results other (like matrix multiplication). Afterwards measure the time taken to on the dual core once and the on the single core (how is it possible without openMP)

   Ping pong:

One process sends a message to the other.two processes repeatedly pass a message back and forth. We should investigate how the time taken varies with the size of the message for each architecture.

   One to all: 

A process with rank 0 sends the same message to all other processes in the program and then receives a message of the same length from all other processes. How does the time taken varies with the size of the messages and with the number of processes?

1
You said, "because ... it isn't compatible with VxWorks," ,but you tagged the question "linux". So which is it? Are you asking about Linux? Are you asking about VxWorks? Or, are you asking about some other platform?Solomon Slow
While interesting, your Q is off-topic. StackOverflow is about helping people fix their programming code. Please read stackoverflow.com/help/how-to-ask , stackoverflow.com/help/dont-ask , stackoverflow.com/help/mcve and take the tour before posting more Qs here. Good luck.shellter
Dunno about VxWorks, though would recommend to look at Zephyr RTOS project.0andriy
I would like to develop these ideas in an APP (with OS abstraction). In our projects, we uses boards with linux and Vxworks, so potentially these Oses I am talking about, in the time beingsahbi.m

1 Answers

0
votes

Short answers wrt. Linux only:


how to execute several threads on different cores

Use multiple processes, or pthreads within a single process.


How the kernel execute code on dual core with shared memory: how it allocate stack, heap, memory for global variable and static ones?

In Linux, they all belong to the process. (You can declare thread-local variables, though, with for example the __thread keyword.)

In other words, if a thread allocates some memory, that memory is immediately visible to all other threads in the same process. Even if that thread exits, nothing happens to the memory. It is perfectly normal for some other thread to free the memory later on.

Each thread does get their own stack, which by default is quite large. (With pthreads, this is easy to control using a pthread_attr_t that specifies a smaller stack size.)

In general, there is no difference in memory handling or program execution, between a single-threaded and a multi-threaded process, on the kernel side. (Userspace code needs to use memory and threads properly, of course; the kernel does not try to stop stupid userspace code from shooting itself in the head, at all.)


Is it possible to add C-flags in order to indicate number of CPU cores so we will be able to use dual core features.

Yes, for example by examining the /proc/cpuinfo pseudofile.

However, it is much more common to leave such details for the system administrator. Services like Apache etc. let the administrator configure the number, either in a configuration file, or in the command line. Even make supports a -j JOBS parameter, allowing multiple compilation tasks to run in parallel.

I very warmly recommend you forget about any detection magic, and instead let the user specify the number of threads used. (If you insist, you could use detection magic for the default, but then only if the user/admin has not given you any hints about the number of threads to be used.)

It is also possible to set the CPU mask for each thread, specifying the set of cores that thread may run on. Other than in benchmarks, where this is done more for repeatability than anything else, or in dedicated processes designed to hog all the resources on a machine, it is very rare.


How the kernel handle program execution (with a lot of threads) on dual core.

The exact same way as it handles a lot of simultaneous processes.

There are some controls (control group stuff, cpu masks) and maybe resource accounting that are handled differently between separate processes and threads within the same process, but in general terms, separate threads in a single process are executed the same way as separate processes are.