Advanced Programming in the Environment

Week 13, Segment 5: Processor Affinity and CPU Sets

Department of Computer Science Stevens Institute of Technology

Jan Schaumann [email protected] https://stevens.netmeister.org/631/ CS631 - Advanced Programming in the UNIX Environment

Processor Affinity and CPU Sets

sh- CPU1 CPU2 tar httpd ntpd sshd syslogd [system] CPU0 CPU3 init inetd worker1 worker2 worker3 worker4 2 Jan Schaumann 2020-12-02 CS631 - Advanced Programming in the UNIX Environment

Processor Affinity and CPU Sets

cp CPU1 CPU2 sh- find ls sshd worker1 worker2 ntpd

CPU0 CPU3 init [system] syslogd inetd httpd worker3 cron tar worker4

3 Jan Schaumann 2020-12-02 CS631 - Advanced Programming in the UNIX Environment

Processor Affinity and CPU Sets

CPU1 CPU2 ls sh- find cp sshd worker1 worker2 ntpd tar

CPU0 CPU3 init [system] syslogd inetd httpd cron worker3 worker4

4 Jan Schaumann 2020-12-02 CS631 - Advanced Programming in the UNIX Environment

Processor Affinity and CPU Sets

CPU1 CPU2 ls sh- find cp sshd worker1 worker2 ntpd tar

CPU0 CPU3 init [system] syslogd inetd httpd cron worker3 worker4

5 Jan Schaumann 2020-12-02 CS631 - Advanced Programming in the UNIX Environment

Processor Affinity and CPU Sets

CPU1 CPU2 ls sh- find cp sshd worker1 worker2 ntpd tar

CPU0 CPU3 init [system] syslogd inetd httpd cron worker3 worker4

6 Jan Schaumann 2020-12-02 CS631 - Advanced Programming in the UNIX Environment

Processor Affinity and CPU Sets

CPU1 CPU2 ls sh- find worker3 worker4 worker1 worker2 ntpd tar

CPU0 CPU3 init [system] syslogd inetd httpd cron sshd cp

7 Jan Schaumann 2020-12-02 CS631 - Advanced Programming in the UNIX Environment

Processor Affinity and CPU Sets

CPU1 CPU2 ls cron ntpd worker3 worker4 worker1 worker2 tar find CPU0 CPU3 init [system] syslogd inetd httpd sh- sshd cp

8 Jan Schaumann 2020-12-02

CS631 - Advanced Programming in the UNIX Environment

CPU Sets

sh- cpuset 1 ls cp CPU1 CPU2 find tar httpd ntpd sshd syslogd [system] CPU0 CPU3 init inetd cron worker1 worker2 worker3 default cpuset cpuset 2 worker4 10 Jan Schaumann 2020-12-02 CS631 - Advanced Programming in the UNIX Environment

CPU Sets

sh- cpuset 1 ls cp CPU1 CPU2 find tar httpd ntpd

CPU0 CPU3 init [system] inetd sshd cron syslogd worker1 worker2 worker3 default cpuset cpuset 2 worker4 11 Jan Schaumann 2020-12-02 CS631 - Advanced Programming in the UNIX Environment

CPU Sets

cpuset 1 ls cp CPU1 CPU2 find tar httpd ntpd

CPU0 CPU3 init [system] sh- inetd sshd cron syslogd worker1 worker2 worker3 default cpuset cpuset 2 worker4 12 Jan Schaumann 2020-12-02 CS631 - Advanced Programming in the UNIX Environment

CPU Sets

cpuset 1 cp CPU1 CPU2

httpd ntpd

CPU0 CPU3 init [system] sh- tar inetd sshd ls find cron syslogd worker1 worker2 worker3 default cpuset cpuset 2 worker4 13 Jan Schaumann 2020-12-02 CS631 - Advanced Programming in the UNIX Environment

CPU Sets

cpuset 1 cp CPU1 CPU2 worker1 worker3 httpd worker2 worker4 ntpd

CPU0 CPU3 init [system] sh- tar inetd sshd ls find cron syslogd

default cpuset cpuset 2

14 Jan Schaumann 2020-12-02 CS631 - Advanced Programming in the UNIX Environment

CPU Sets

cpuset 1

CPU1 CPU2 worker1 worker3 httpd worker2 worker4 ntpd

syslogd CPU0 CPU3 init [system] sh- tar sshd ls cp cron inetd find

default cpuset cpuset 2

15 Jan Schaumann 2020-12-02

CS631 - Advanced Programming in the UNIX Environment Processor Affinity and CPU Sets

• Pinning a process (group) to a CPU can improve performance by e.g., reducing CPU cache misses.

• “Processor Affinity” or “CPU pinning” lets you assign a process to a specific CPU, but other processes may still be placed on that CPU. • Processor Affinity is inherited by a child process from its parent, but changing a parents affinity does not affect running children.

• “CPU Sets” let you reserve CPUs for specific processes; no other processes can be placed on those CPUs. • Processor Affinity and CPU sets are not standardized; different OS implement them differently or using different tools.

17 Jan Schaumann 2020-12-02