Отключение ядер процессора linux

disabling cpu cores on quad core processor on linux

I want to disable 3 CPU cores and run my processor on a single core. I have used command: maxcpus=1 . But after this I executed this command ls /sys/devices/system/cpu . It still shows cpu0,cpu1,cpu2,cpu3 . I also tried : echo 0 > /sys/devices/system/cpu3/online but I get the following error: no such file or directory .

It is unclear where you put the maxcpus=1 commmand? Did you put that string in grub.cfg as a boot option? (Please update your question instead of answering in comments).

I am using freescale IMx6 sabreauto board on linux OS.I executed the command on a terminal emulator «gtkterm»

With this command echo 0 > /sys/devices/system/cpu3/online I am able to see cpu3 shutdown. Now what I want know is, should I reboot the system for the changes to effect or I can continue without rebooting

AFAIK you should specify maxcpus=1 as a parameter to the kernel (i.e. when you are in grub). Edit ‘/etc/defaults/grub’ to add it to the kernel parameters, run ‘update-grub’ and reboot. That will make things persistent, i.e. with only one CPU on Linux startup.

@user3818847 what distro are you using? Modifying the boot parameters (to pass maxcpus=1 ) varies by distro. Also the /sys path you have is simply the wrong one, the correct path is /sys/devices/system/cpu/cpu3/online .

2 Answers 2

As Patrick has indicated in a comment, you got the path under /sys wrong.

echo 0 > /sys/devices/system/cpu/cpu3/online 

If you want to switch all CPUs off except cpu0 :

for x in /sys/devices/system/cpu/cpu2*/online; do echo 0 >"$x" done 

Typing maxcpus=1 at a shell prompt has no effect. More precisely, it sets the variable maxcpus to the value 1 in that shell, which doesn’t have any other effect. You can set the number of CPUs at boot time by passing maxcpus as a kernel parameter. For that, you have to change your bootloader configuration (e.g. to change the kernel command line in U-Boot).

This is at least somewhat kernel-specific. I’m running kernel 3.6.6, and there’s no such files; you instead use the single /sys/devices/system/cpu/online and ./offline files to control all the cores.

Читайте также:  Reading file line by line in linux

@ChetanArvindPatil Time it. I think the time would be dominated by RAM access if the code involved isn’t already in the L2 cache and by the time to switch the core off otherwise, but it very much depends on the CPU and OS.

@Xofo When the kernel switches off a core, that core is running kernel code, so no thread is scheduled on that particular core at that moment. After the core is off, threads are no longer scheduled on that core. I don’t know what happens if a thread’s affinity restricts it to a set of cores that are all off.

you do not necessarily turn off or disable cores.

you would use cpusets and taskset

A cpuset defines a list of CPUs and memory nodes.

The cpuset filesystem is a pseudo-filesystem interface to the kernel cpuset mechanism, which is used to control the processor placement and memory placement of processes. It is commonly mounted at /dev/cpuset.

On systems with kernels compiled with built in support for cpusets, all processes are attached to a cpuset, and cpusets are always present. If a system supports cpusets, then it will have the entry nodev cpuset in the file /proc/filesystems. By mounting the cpuset filesystem (see the EXAMPLE section below), the administrator can configure the cpusets on a system to control the processor and memory placement of processes on that system. By default, if the cpuset configuration on a system is not modified or if the cpuset filesystem is not even mounted, then the cpuset mechanism, though present, has no effect on the system’s behavior.

The CPUs of a system include all the logical processing units on which a process can execute, including, if present, multiple processor cores within a package and Hyper-Threads within a processor core. Memory nodes include all distinct banks of main memory; small and SMP systems typically have just one memory node that contains all the system’s main memory, while NUMA (non-uniform memory access) systems have multiple memory nodes.

In short, if you have 1 cpu having 6 cores you would configure cpusets and launch your process in a cpuset that is configured on just one core, say core #3 for example. If it was a parallel process it would all be confined to that one core such that if you launched 4 processes in a given cpuset having just one core defined, then each of the 4 processes would get 25% cpu utilization on core #3.

Читайте также:  Посмотреть свой айпи линукс

Building off of that, what typically happens is a cpuset is configured such that

  • in a 200+ core system for example, cpusetA is cores 0..60 wherever those might be located, cpusetB is cores 61..70; cpusetC is cores 71..80; and so on however an admin/architect chooses to configure.
  • cpusetA is allocated to certain users and/or specific software programs; cpusetB is allocated to different users/programs; and so on.
  • a user launches a job (process) which would request N cores. within a given cpuset, and now those multiple (parallel) processes are confined to that given cpuset. And for those N parallel confined to a given cpuset, each of those processes would/should make use of processor affinity or cpu affinity so those parallel processes do not thrash around on different cores within the cpuset.

Источник

Отключить/включить ядра CPU в Linux

В Linix вы можете временно включить или отключить ядра процессора без перезагрузки с помощью консольной утилиты chcpu.

Выведите информацию о доступных ядрах:

lscpu - информация о процессорах и ядрах в консоли linux

CPU(s): 3 On-line CPU(s) list: 0-2

В этом примере для гостевой ОС на виртуальной машине Linux доступны три ядра 0, 1 и 2.

В Linux вы можете отключить любые ядра процессора, кроме нулевого (CPU0).

Чтобы отключить ядра 1 и 2, выполните команду:

chcpu - отключить ядро в linux

CPU 1 disabled CPU 2 disabled

Проверьте теперь какие ядра доступны:

On-line CPU(s) list: 0 Off-line CPU(s) list: 1,2

Также можно вывести информацию о доступных процессорах так:

$ grep «processor» /proc/cpuinfo

Чтобы включить ядра процессора, выполните:

CPU 1 enabled CPU 2 enabled

Также вы можете отключить определенное ядро командой. В этом примере мы отключаем CPU1:

$ sudo echo 0 | sudo tee /sys/devices/system/cpu/cpu1/online

Проверьте сообщения в dmseg:

[ 2257.253801] smpboot: CPU 1 is now offline

Чтобы включить его, выполните:

$ sudo echo 1 | sudo tee /sys/devices/system/cpu/cpu1/online

Если вы хотите, чтобы Linux всегда загружалась с меньшим количество доступных ядер, нужно настроить параметр ядра maxcpus=N.

N в этом случае – это количество доступных ядер процессора, доступных в Linux.

Читайте также:  Alt linux минимальная установка

$ sudo mcedit /etc/default/grub

Измените строку следующим образом:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash maxcpu=2"

grub - ограничить количество доступных проессоров в linux

Вы можете использовать отключение ядер CPU в Linux, когда нужно уменьшить количество vCPU для виртуальной машины Linux и вы хотите протестировать, как работает операционная система и приложения с меньшим количеством доступных vCPU.

Также в Linux вы можете запускать приложения на определённых ядрах с помощью CPU affinity. Чтобы получить информацию о привязки определенного процесса к ядрам, выполните:

pid 894's current affinity mask: 3
pid 894's current affinity list: 0,1

taskset привязка процесса к ядрам cpu в linux

Этому процессу разрешено выполняться на ядрах 0 и 1.

Чтобы разрешить запушенному процессу выполняться только на CPU0, выполните:

pid 894's current affinity list: 0,1 pid 894's new affinity list: 0

Или, чтобы разрешить процессу firefox использовать ядра с 0 по 3:

$ sudo taskset -c 0-3 firefox

Источник

Как быстро и просто отключить ядра процессора в Linux с помощью #chcpu

В Linux можно быстро и просто отключать и включать ядра процессора с помощью команды chcpu . Доступны 4 ядра с 0 по 3, можно выключить любое количество ядер, кроме нулевого.

Для отключения ядер используется команда chcpu -d , после которой указываются номера ядер, которые нужно отключить. Например, для отключения ядер 2 и 3, нужно использовать команду:

В результате выполнения этой команды, вы увидите сообщение “CPU 2 disabled” и “CPU 3 disabled”.

Чтобы проверить состояние ядер, используйте команду lscpu . Если вы отключили ядра, вы увидите сообщение “On-line CPU(s) list”, в котором указаны номера доступных ядер, и “Off-line CPU(s) list”, в котором указаны номера отключенных ядер. Например:

Отключение ядер может быть полезным для тестирования производительности виртуальных машин, а также для экономии ресурсов. Однако, не следует злоупотреблять этой функцией, так как это может привести к снижению производительности системы.

Для включения ядер используйте команду chcpu -e , после которой указываются номера ядер, которые нужно включить. Например, для включения ядер 2 и 3, нужно использовать команду:

Таким образом, команда chcpu позволяет быстро и просто управлять количеством ядер процессора в Linux. Это может быть полезно для управления ресурсами и тестирования производительности системы. Но не следует злоупотреблять отключением ядер, так как это может сильно снизить производительность системы и ухудшить ее работу.

Источник

Оцените статью
Adblock
detector