I'm unable to use all cores I allocate with Slurm when running a multithreaded program (which uses POSIX threads).
I'd like to check whether my system (CentOS 7) supports POSIX threads.
Does anybody know how to do it?
Related
I am studying Solaris and Linux and am viewing Kernel Level Threads (KLTs) as the fundamental entity that can be scheduled and dispatched by the OS. I know that a multi-threaded OS must store thread execution context and provide mechanisms to schedule and dispatch KLTs, and that kernel level threads handle interrupts, system calls, and provide an interface to the CPU as a resource at the user-kernel interface. I am not clear on what services are necessary to support KLTs in a multi-threaded OS.
I cannot determine if there is a core kernel process that is necessary to support all KLTs, or if KLTs run interdependently as the base-level of computing. I would like to understand what minimum set of operations (resource allocation, scheduling) is necessary to support an OS with KLTs.
I have looked at Tanenbaums Tanenbaum's discussion of threads in his distributed systems book, Understanding the Linux Kernel, and MultiThreading the SunOS kernel but I cannot find an answer to my question.
I believe that answering the question -- What Operating System services are necessary to support kernel-level threads? -- will help me understand how KLTs are implemented.
If Erlang does its own process creation and scheduling, without utilizing OS threads, how does it make use of multiple CPU cores? My limited understanding is that the OS assigns the CPU cores to OS threads.
Erlang runs on a virtual machine called BEAM.
The Erlang process runs a separate BEAM VM on each core (using OS threads).
See this related SO question.
If, for example, there is a let's say embedded application which run on unicore CPU. And then that application would be ported on multi core CPU. Would that app run on single or multiple cores?
To be more specific I am interested in ARM CPU (but not only) and toolchain specifics e. g. standard C/C++ libraries.
The intention of this question is this: is it CPU's responsibility to "decide" to execute on multiple cores or compiler toolchain, developer and standard platfor specific libraries? And again, I am interested also in other systems' tendencies out there.
There are plenty of applications and RTOS (for example Linux) that run on different CPUs but the same architecture, so does that mean that they are compiled differently?
Generally speaking single-threaded code will always run on one core. To take advantage of multiple cores you need to have either multiple processes, multiple threads, or both.
There's nothing your compiler can do to help you here. This is an architectural consideration.
If you have multiple threads, for example, most multi-core systems will run them on whatever cores are available if the operating system you're running is properly compiled to support that. Running an OS that's been compiled single-core only will obviously limit your options here.
A single threaded program will run in one thread. It is theoretically possible for the thread to be scheduled to move to a different core, but the scheduler cannot turn a single thread into multiple threads and give you any parallel processing.
EDIT
I misunderstood your question. If there are multiple threads in the application, and that application is binary compatible with the new multicore CPU, the threads will indeed be scheduled to run on different CPUs, if the OS scheduler deems it appropriate.
Well it all depends on the software that if it wants to utilize other cores or not (if present). Lets take an example of Linux on ARM's cortexA53.
Initially a vendor provided boot loader runs on, FSBL (First state bootloader). It then passes control to Arm trusted firmware. ATF then runs uboot. All these run on a single core. Then uboot loads linux kernel and passes control to it. Linux then initializes some stuff and looks into some option, first in the bootargs for smp or nosmp flags. if smp it will get the number of CPUs assigned to it from dtb and then using SMC calls to ATF it will start other cores and then assign work to those cores to provide true feel of multiprocessing environment. This is normally called load balancing and in linux it is mostly done in fair.c file.
I'm trying to understand how Linux handles process scheduling and thread scheduling. I read that Linux can schedule both processes and threads.
Does Linux have a thread scheduler AND a process scheduler? If yes, how do they cooperate?
The Linux kernel scheduler is actually scheduling tasks, and these are either threads or (single-threaded) processes.
So a task (a task_struct inside the kernel), in the context of the scheduler, is the thing being scheduled, and can be some kernel thread like kworker or kswapd, some user thread of a multi-threaded process (like firefox), or the single-thread of a single-threaded process (like bash), identified with that single-threaded process.
A process is a non-empty finite set (sometimes a singleton) of threads sharing the same virtual address space (and other things like file descriptors, working directory, etc etc...). See also credentials(7), capabilities(7) etc....
Threads on Linux are kernel threads (in the sense of being managed by the kernel, which also creates its own threads), created by the Linux specific clone syscall (which can also be used to create processes on Linux). The pthread_create function is probably built (on Linux) above clone inside NPTL and Gnu Libc (which integrated NPTL on Linux) and musl-libc.
Kernel threads under Linux are implemented as processes that share resources. The scheduler does not differentiate between a thread and a process
See here for more information:
http://www.linuxquestions.org/linux/articles/Technical/Linux_Kernel_Thread
Under LINUX there is no concept of threads,to make LINUX POSIX complaint thread is nothing but another process.when you try to get a process id it would display the leader process id under any thread. For more details try to refer this book "Understanding LINUX kernel".Hope
We have an embedded MIPS 2-core processor running SMP Linux (2.6.18).
We are planning to assign the affinity of the main GUI threads to one of the two cores, and the other core used for driver/data path processing.
However, the questions has been asked of how do you tell which threads are on which core?
I can get the affinity mask fine, but is there any other way of telling (e.g. /proc system) which threads are on which core?
Thanks.
sched_getcpu - determine CPU on which the calling thread is running
man sched_getcpu()