Mitesh G
Mitesh G

Reputation: 79

Can we run the linux kernel on specific cores in a Multi-core CPU?

I'm making a brainwave detection device. I'll be taking an Octa-Core ARM processor for the software processing. For the management of CPU cores, can I code Linux Kernel to strictly run on a specific set of cores? Let's say core 1, 2, and 3. But it should not be too strict as I also need to spawn the device driver on a separate core (let's take core 4). So is it possible to do so?

Upvotes: 2

Views: 4482

Answers (2)

bazza
bazza

Reputation: 8434

It's not entirely clear what you are asking for.

Leaving Cores Unused?

Whilst you might be able to get Linux to boot using only a subset of the cores in a machine, there's no point doing so. It begs the question, what are the unused cores going to be doing? They're not going to be available to software (application or driver code) you are running on Linux, because the Linux you've booted isn't using them.

Bear in mind that a core is simply a CPU that happens to be in the same memory address space as other cores. It has to run something, and it's normal to have chunks of OS running on it. There has to be something running on the core managing it (scheduling what's running on it). You can't just dump an application thread on to a CPU without there being something to provide OS services to it.

Core Affinity?

If you're interested in taking control of core affinity, there's functions for controlling which of your threads are running on which cores. Though I caution against them - it's a ton of work to do for each CPU model you wish to support, and you'll really struggle to beat what the Linux kernel does anyway. I've tried, and made only a tiny improvement over what Linux accomplished automatically. It wasn't worth it.

Real Time Scheduling?

Are you really looking for some real time performance? The best you can do with Linux is something like the PREEMPT_RT patch set (becoming more mainstream I think).

With this version of Linux, device drivers become threads, and are therefore pre-emptable just like anything else. So if you give the application / driver thread a high real time priority, it will (nearly) always win the "what's going to be scheduled next" decision that the kernel is going to make. PREEMPT_RT will also solve priority inversion, so if your thread gets blocked by a lower priority thread contending for the same resource, the kernel will do its best to sort things out.

If PREEMPT_RT's latency is not low enough for you, Linux is the wrong choice. VxWorks springs to mind.

Upvotes: 1

Leos313
Leos313

Reputation: 5647

One of the ways of doing it is to use the device-tree. As you know the kernel knows nothing about hardware so, at boot time, it retrieves info from the device tree where the hardware is described. Here, you can find some basic information. However, in the device tree, there should be a section like this:

/dts-v1/;

/ {
    compatible = "acme,coyotes-revenge";

    cpus {
        cpu@0 {
            compatible = "arm,cortex-a9";
        };
        cpu@1 {
            compatible = "arm,cortex-a9";
        };
    };
};

Try to describe your hardware to be used by adding/deleting the nodes in the device tree.

Upvotes: 2

Related Questions