Configuration of kvm cpu Affinity Binding

Source: Internet
Author: User

1. CPU binding Configuration


Process affinity: processes are bound to one or more specific CPUs for execution, rather than being scheduled to other CPUs.

Physical CPU: indicates the actual number of CPUs.

Logical CPU: indicates that all units with a complete and real CPU function are equal to the sum of the core or hyper-threading number (HT technology) of all real CPUs.

Example: A single motherboard has cpu1, cpu2, and cpu1 dual-core without hyper-threading. A single CPU core has two hyper-threading threads, so it has two real CPUs, and 2 + (2*1 + 3) = 7 logical CPUs


Implementation:

(1) In grub. use "isolcpus = [num1], [num2]... "parameter, the CPU is isolated, so that after the system starts, common processes are not scheduled to be executed on the isolated CPU by default. (Note: num indicates the logical CPU number)

Example:

Title centos (3.2.84)

Root (hd0, 0) kernel/vmlinuz-3.2.84 Ro root =/dev/mapper/VolGroup-lv_root isolcups = 4,5 ← rd_no_md kernel = volgroup/lv_swap crashkernel = auto lang = en kernel = volgroup/lv_root keyboardtype = pc keytable = US rd_no_dm rhgb quiet

Initrd/initramfs-3.2.84.img

Note: isolcups must be followed by root and cannot be placed at the end (for personal testing, the specific reasons need to be identified)


(2) check whether the isolation is successful:

[[Email protected] ~] # Ps-elo psr, argS | awk '{if ($1 = 3) Print $0 }'

3 [kworker/u: 0]

3 [migration/3]

3 [kworker/3:0]

3 [ksoftirqd/3]

3 [watchdog/3]

3 [kworker/3:1]

3 auditd

3 rpcbind

[Flush-253: 0]

3/usr/sbin/modem-Manager

3 Hald-runner

3/usr/libexec/Postfix/Master

[[Email protected] ~] # Ps-elo psr, argS | awk '{if ($1 = 4) Print $0 }'

4 [migration/4]

4 [kworker/4: 0]

4 [ksoftirqd/4]

4 [watchdog/4]

4 [kworker/4:1]

[[Email protected] ~] # Ps-elo psr, argS | awk '{if ($1 = 5) Print $0 }'

5 [migration/5]

5 [kworker/5:0]

5 [ksoftirqd/5]

5 [watchdog/5]

5 [kworker/5:1]

[[Email protected] ~] # Ps-elo psr, argS | awk '{if ($1 = 2) Print $0 }'

2 [kthreadd]

2 [migration/2]

2 [kworker/2: 0]

2 [ksoftirqd/2]

2 [watchdog/2]

2 [khubd]

2 [kworker/2:1]

2 [kworker/2]

2/sbin/rsyslogd-I/var/run/syslogd. PID-C 5

2 pcscd

2/sbin/mingetty/dev/tty6


PS (Process status ):

-E: displays all processes.

-L: used to display the thread (lwp, Lightweight Process). (here I ignore this result)

-O: Output in user-defined format (the optional parameters include the SRS, PID, and ppid)

-O parameters:

This indicates the number of the processor currently allocated to the process.

ARGs: commands and parameters for Running Processes


Here we can see that process numbers 2 and 3 all have many processes, and 4 and 5 only have five system processes with the [] number, so the isolation is successful.


(3) Start the client

Qemu-system-x86_64-M 2048-SMP 2 rhel6u5. IMG &


(4) view vcpu threads

[[Email protected] kvm_vhost] # ps-elo pid, lwp, PSR, argS | grep qemu | grep-V grep

1612 1612 6 qemu-system-x86_64-M 2048-SMP 2 rhel6u5. img

1612 1614 1 qemu-system-x86_64-M 2048-SMP 2 rhel6u5. img

1612 1615 6 qemu-system-x86_64-M 2048-SMP 2 rhel6u5. img

1612 1617 11 qemu-system-x86_64-M 2048-SMP 2 rhel6u5. img


(5) bind the process representing the entire client so that it runs on cpu4

[[Email protected] kvm_vhost] # taskset-P 0x10 1612

PID 1612's current affinity mask: ffcf

PID 1612's New Affinity mask: 10

[[Email protected] kvm_vhost] # ps-elo pid, lwp, PSR, argS | grep qemu | grep-V grep

1612 1612 4 qemu-system-x86_64-M 2048-SMP 2 rhel6u5. img

1612 1614 3 qemu-system-x86_64-M 2048-SMP 2 rhel6u5. img

1612 1615 6 qemu-system-x86_64-M 2048-SMP 2 rhel6u5. img

1612 1617 11 qemu-system-x86_64-M 2048-SMP 2 rhel6u5. img

(6) bind the first vcpu thread to run on CPU 5.

[[Email protected] kvm_vhost] # taskset-P 0x20 1614

PID 1614's current affinity mask: ffcf

PID 1614's New Affinity mask: 10

[[Email protected] kvm_vhost] # ps-elo pid, lwp, PSR, argS | grep qemu | grep-V grep

1612 1612 4 qemu-system-x86_64-M 2048-SMP 2 rhel6u5. img

1612 1614 5 qemu-system-x86_64-M 2048-SMP 2 rhel6u5. img

1612 1615 6 qemu-system-x86_64-M 2048-SMP 2 rhel6u5. img

1612 1617 11 qemu-system-x86_64-M 2048-SMP 2 rhel6u5. img

 

Similarly, bind another vcpu. the syntax of taskset is taskset-P [mask] PID.

Mask is a mask number representing the affinity of the processor and is converted to binary. Its value ranges from the first bit to the highest bit, representing the first logical CPU to the last logical CPU.

0001, 0000 = 0x10

0010 0000 = 0x20

0011, 0000 = 0x30

Therefore, if taskset-P 0x30 1614 is used, the vcpu thread runs on CPU 4 and CPU 5.

PID indicates the thread ID. Here we have three threads. How do we know which one is the vcpu ID? The answer is to press CTRL + ALT + 2 to use info CPUs in qemu monitor for viewing.

650) This. width = 650; "src =" http://s4.51cto.com/wyfs02/M00/8A/ AB /wKiom1g2tdeCkj_CAAAQlf4_uzk411.png-wh_500x0-wm_3-wmp_4-s_710471765.png "Title =" iu0rs(o3%nfa_%%b2hn6%32.png "alt =" wKiom1g2tdeCkj_CAAAQlf4_uzk411.png-wh_50 "/>


(7) Check the threads running on CPU 4 after binding

[[Email protected] kvm_vhost] # ps-elo psr, argS | awk '{if ($1 = 4) Print $0 }'

4 [migration/4]

4 [kworker/4: 0]

4 [ksoftirqd/4]

4 [watchdog/4]

4 [kworker/4:1]

4 qemu-system-x86_64-M 2048-SMP 2 rhel6u5. img


We can see one more qemu process with only one user space. The binding is successful.



Configuration of kvm cpu Affinity Binding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.