LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to start Linux without kernel on one core (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-start-linux-without-kernel-on-one-core-4175604581/)

tanklau 04-25-2017 11:50 AM

How to start Linux without kernel on one core
 
Hi everyone! I am just wondering if this is possible. I have a 4 processor machine running Ubuntu. Is it possible to start up the system with the Linux kernel running on 3 of the processors only leaving one completely off? Then on the empty core, is it possible to access it and run a simple program (like an assembly program)?

linux4evr5581 04-25-2017 01:40 PM

In the Windows world I think what you're trying to do would be done through the msconfig utility. But in Linux you may need to use a distro like Gentoo which has more advanced customizable options like makeopts, which allows you to set the number of threads a program should use.. You most likely can do this with any flavor of Linux though (I personally don't know how), but I hear Gentoo tends to make doing these types of things easier.

273 04-25-2017 01:42 PM

Something similar may be possibe with virtual machines but the concept looks impossible.

jpollard 04-25-2017 05:55 PM

Quote:

Originally Posted by tanklau (Post 5701967)
Hi everyone! I am just wondering if this is possible. I have a 4 processor machine running Ubuntu. Is it possible to start up the system with the Linux kernel running on 3 of the processors only leaving one completely off? Then on the empty core, is it possible to access it and run a simple program (like an assembly program)?

Perhaps
https://unix.stackexchange.com/quest...essor-on-linux

But note: you don't use a CPU after it is disabled.

The problem is that the CPU has full access to main memory - and there is nothing managing that CPU to associate some use of the CPU with memory for that CPU.

That is the function of the kernel.

The only reason to disable a CPU is if you have traced a fault to a particular core, and wish to disable it so that it will not affect the rest of the system.

syg00 04-25-2017 09:21 PM

No.
cgroups gives the functionality you are probably looking for. You can limit even the interrupt handlers to not run on your "preferred" core, but certain kernel threads will always be candidates for dispatch on any core. Their effect should be negligible.
I use this approach when running benchmarks - I keep a core for my monitoring tasks, and my shell so I can get in if something runs amok.

jpollard 04-26-2017 06:55 AM

cgroups can not disable a CPU.

This is part of the hotplug support for hot replacement of CPUs in appropriate hardware.

A non-disabled CPU is actively running kernel code - even if it is only the idle process.

What the OP is requesting is partitioning... Not something an Intel (or ARM for that matter) can do.

A Power system might - if the partitioning is implemented and supported by the hardware and boot.

pan64 04-26-2017 07:02 AM

a program cannot run without kernel, that is more or less impossible. But you may associate one core with your app and in that case your app will use that core only (almost), see post #5

jpollard 04-26-2017 07:50 AM

Quote:

Originally Posted by pan64 (Post 5702360)
a program cannot run without kernel, that is more or less impossible. But you may associate one core with your app and in that case your app will use that core only (almost), see post #5

Yes, but that isn't what was requested.

And a program can run without a kernel. After all, that is what grub does, and what the bios/ufi do.

pan64 04-26-2017 08:46 AM

Quote:

Originally Posted by jpollard (Post 5702385)
Yes, but that isn't what was requested.

it was the title of the thread:
Quote:

How to start Linux without kernel on one core
Quote:

Originally Posted by jpollard (Post 5702385)
And a program can run without a kernel. After all, that is what grub does, and what the bios/ufi do.

Yes, a program can run without kernel on ZX81, on C64 too. But not on a system where a linux was booted (and running).

sundialsvcs 04-26-2017 09:15 AM

Quote:

Originally Posted by jpollard (Post 5702385)
Yes, but that isn't what was requested.
And a program can run without a kernel. After all, that is what grub does, and what the bios/ufi do.

Booting is a special case, intended only to load an operating system kernel.

Fundamentally, "the kernel controls everything," and every CPU/core will be running some amount of kernel code, even if that code puts it into a wait-state and keeps it there.

You might be asking for affinity controls: to specify that a particular program should be dedicated to a particular core(s) and vice-versa.

Here are some discussions of it – some quite old:

There is no advantage to having a core sitting idle, nor under-utilized. All cores should be as active as possible. But, as the first referenced article discusses at some length, there are legitimate purposes for specifying affinity.
Quote:

Originally Posted by Linux Journal article above:

Why One Needs CPU Affinity

Before we cover the new system calls, let's discuss why anyone would need such a feature. The first benefit of CPU affinity is optimizing cache performance. I said the O(1) scheduler tries hard to keep tasks on the same processor, and it does. But in some performance-critical situations—perhaps a large database or a highly threaded Java server—it makes sense to enforce the affinity as a hard requirement. Multiprocessing computers go through a lot of trouble to keep the processor caches valid. Data can be kept in only one processor's cache at a time. Otherwise, the processor's cache may grow out of sync, leading to the question, who has the data that is the most up-to-date copy of the main memory? Consequently, whenever a processor adds a line of data to its local cache, all the other processors in the system also caching it must invalidate that data. This invalidation is costly and unpleasant. But the real problem comes into play when processes bounce between processors: they constantly cause cache invalidations, and the data they want is never in the cache when they need it. Thus, cache miss rates grow very large. CPU affinity protects against this and improves cache performance.

A second benefit of CPU affinity is a corollary to the first. If multiple threads are accessing the same data, it might make sense to bind them all to the same processor. Doing so guarantees that the threads do not contend over data and cause cache misses. This does diminish the performance gained from multithreading on SMP. If the threads are inherently serialized, however, the improved cache hit rate may be worth it.

The third and final benefit is found in real-time or otherwise time-sensitive applications. In this approach, all the system processes are bound to a subset of the processors on the system. The specialized application then is bound to the remaining processors. Commonly, in a dual-processor system, the specialized application is bound to one processor, and all other processes are bound to the other. This ensures that the specialized application receives the full attention of the processor.

Note that some comments made in the aforementioned article assume much-earlier versions of the Linux scheduler – which of course were contemporary at that time. Much development attention has been given to these issues since the article was written.

jpollard 04-26-2017 09:45 AM

All of which is true - but not what was asked.

"Hi everyone! I am just wondering if this is possible. I have a 4 processor machine running Ubuntu. Is it possible to start up the system with the Linux kernel running on 3 of the processors only leaving one completely off? Then on the empty core, is it possible to access it and run a simple program (like an assembly program)?"

And that has nothing to do with CPU affinity, or VMs, or anything but disabling a CPU and then using it for bare bones assembly.

Disabling a CPU is possible, and sometimes necessary as I indicated.

Using it for something else... I've only seen that on Power - and not the cheap ones either.

273 04-26-2017 01:42 PM

Quote:

Originally Posted by jpollard (Post 5702459)
All of which is true - but not what was asked.

"Hi everyone! I am just wondering if this is possible. I have a 4 processor machine running Ubuntu. Is it possible to start up the system with the Linux kernel running on 3 of the processors only leaving one completely off? Then on the empty core, is it possible to access it and run a simple program (like an assembly program)?"

And that has nothing to do with CPU affinity, or VMs, or anything but disabling a CPU and then using it for bare bones assembly.

Disabling a CPU is possible, and sometimes necessary as I indicated.

Using it for something else... I've only seen that on Power - and not the cheap ones either.

That is how I read it also. My mention of VMs was because, for all I know, it may be possible to give a host 4 cores and divide them up if, for whatever reason, that's needed for experimental purposes.

sundialsvcs 04-26-2017 02:45 PM

In Linux, at least, I'm confident that the answer is "no." The kernel identifies and then controls everything. You can designate that work is to be done on this-or-that core, and that this-or-that core is to do nothing else, but the kernel is still dispatching the work on the system; still maintaining the overall execution environment.

You can prevent Linux from using all of the cores that it detects, but so far as I know you cannot $ VARY OFF CPU3. (This isn't MVS, folks.)

jpollard 04-26-2017 09:08 PM

Quote:

Originally Posted by sundialsvcs (Post 5702565)
In Linux, at least, I'm confident that the answer is "no." The kernel identifies and then controls everything. You can designate that work is to be done on this-or-that core, and that this-or-that core is to do nothing else, but the kernel is still dispatching the work on the system; still maintaining the overall execution environment.

You can prevent Linux from using all of the cores that it detects, but so far as I know you cannot $ VARY OFF CPU3. (This isn't MVS, folks.)

Well... yes you can. All you do is send "echo 0 >/sys/devices/system/cpu/cpu3/online" and that disables the kernels use of CPU3.

https://www.kernel.org/doc/Documenta...ces-system-cpu
https://www.kernel.org/doc/html/late...u_hotplug.html

In those systems with the capability, you are supposed to be able to remove the CPU, insert a new one, and tell the kernel to start using it.

Of course, this requires the hardware support the capability. As far as I know, no motherboards have the capability to remove a CPU without first powering down the entire system.

BTW, Linux does run on mainframes with this capability.

sundialsvcs 04-26-2017 10:12 PM

Quote:

Originally Posted by jpollard (Post 5702728)
Well... yes you can. All you do is send "echo 0 >/sys/devices/system/cpu/cpu3/online" and that disables the kernels use of CPU3.

In those systems with the capability, you are supposed to be able to remove the CPU, insert a new one, and tell the kernel to start using it.

Of course, this requires the hardware support the capability. As far as I know, no motherboards have the capability to remove a CPU without first powering down the entire system.

BTW, Linux does run on mainframes with this capability.

I graciously yield to your greater knowledge on the subject, and thank you for informing me.

The last time I had the chance to run a Unix-like system on a mainframe was back when I worked for Amdahl Corporation at my first "Silicon Valley" job – running their UTS® system on Amdahl's copy of "big iron." (And, "woo, hoo!" To witness what such hardware could actually do, without MVS® in the way! For a little while, I got to play with "a most-improbable PC!") :D

(Koff, koff ... guess the kids don't have kucking-floo what we're on about ...) ;) ... (tough luck, kids, you missed it, that's all ...)

Nevertheless – this still basically seems to be VARY OFF situation: instructing the operating system not to use a particular hardware resource. Which is not the same thing as "then sneaking-off somewhere and 'playing hooky' with it," as the OP's question implies. So far as I know, "you simply can't cut the operating system entirely out of the picture."


All times are GMT -5. The time now is 10:23 PM.