Friday, September 30, 2016

Interrupts and CPU SMP Affinity

Interrupts:

Interrupts are signal that are sent across IRQ (Interrupt Request Line) by a hardware or software. Interrupts allow devices like keyboard, serial cards and parallel ports to indicate that it needs CPU attention.

On a Linux machine, the file /proc/interrupts contains information about the interrupts in use and how many times processor has been interrupted.

SMP_AFFINITY:

Symmetric multiprocessing is the processing of programs by multiple processors.

smp_affinity file holds interrupt affinity value for a IRQ number. The smp_affinity file associated with each IRQ number is stored in /proc/irq/IRQ_NUMBER/smp_affinity file. The value in the file is stored in hexadecimal bit-mask representing all CPU cores in the system. smp_affinity works for device that has IO-APIC enabled device drivers.

For example, smp_affinity entry for Ethernet driver is shown below:

root@test007:grep eth0 /proc/interrupts
            CPU0       CPU1       CPU2       CPU3       CPU4       CPU5       CPU6       CPU7

67:     0 23834931 0 0 0 0 0 0 IO-APIC-level eth0

IRQ number for eth0 is 67 and corresponding smp_affinity file will be located at:

root@test007: cat /proc/irq/67/smp_affinity
10

The decimal equivalent for hexadecimal value ‘10’ is ‘2’. ie All the interrupt related to Ethernet driver will be serviced by 2nd cpu (CPU1)

============

"10" is the hexadecimal representation for the decimal number 2
and the binary pattern of "0010".  Each of the places in the binary pattern
corresponds to a CPU in the server, which means we can use the following
chart to represent the CPU bit patterns:

            Binary       Hex
    CPU 0    0001         1
    CPU 1    0010         2
    CPU 2    0100         4
    CPU 3    1000         8

By combining these bit patterns (basically, just adding the Hex values), we
can address more than one processor at a time.   For example, if I wanted
to talk to both CPU0 and CPU2 at the same time, the result is:

            Binary       Hex
    CPU 0    0001         1
  + CPU 2    0100         4
    -----------------------
    both     0101         5

If I want to address all four of the processors at once, then the result is:

            Binary       Hex
    CPU 0    0001         1
    CPU 1    0010         2
    CPU 2    0100         4
  + CPU 3    1000         8
    -----------------------
    both     1111         f

Given that, we now know that if we have a eight processor system, we can
assign any different CPU combinations to an IRQ.

example:

echo "01" > /proc/irq/67/smp_affinity for 1st core
echo "03" > /proc/irq/67/smp_affinity for assign on 1st and 2nd core
echo "05" > /proc/irq/67/smp_affinity for assigning 1st and 3rd core
echo "f0" > /proc/irq/67/smp_affinity for assigning 5th to 8th core
====================
Note : If you are not good in hex to bin conversion, please use this site.

IRQ Balance

Irqbalance is a utility that distributes interrupts over the processor cores in your computer system. which helps to improve performance.

It's goal is to find a balance between power saving and optimal performance.

Irqbalance is especially useful on systems with multi-core processors, as interrupts will typically only be serviced by the first core.

Saturday, September 24, 2016

Run a program on specific CPU core

Run a particular process with cpu cores 4 and 5
taskset -cp 4,5 <process_id>

Example:
[root@masterDNS ~]# taskset 03 /usr/bin/watch -n1 w

Now check if it's really working

[root@masterDNS ~]# ps -ef | grep watch
root     14590 14365  0 20:00 pts/0    00:00:00 /usr/bin/watch -n1 w
root     14644 14609  0 20:00 pts/1    00:00:00 grep watch


[root@masterDNS ~]# taskset -p 14590
pid 14590's current affinity mask: 3


If We want to dedicate a whole CPU core to a particular program and no other then your process should use this core.
Then use "isolcpus" kernel parameter in grub option.

GRUB_CMDLINE_LINUX_DEFAULT="cpuidle.off=1 idle=poll isolcpus=5 nohz_full=5 maxcpus=6"

update-grub

Note: below are meaning

cpuidle.off=1 (Do not make cpu idle)
isolcpus=5  (Isolate cpu core 5)
maxcpus=6 (Use only 6 core (out of 8 cores of system) for )
idle=poll (Poll forces a polling idle loop)

Thursday, August 25, 2016

Mac binding in DHCP along with mobile phone restriction

As we have setup TSIG along with master-slave of bind DNS. Now we are configuring dhcp setup.
Below are the steps.

[root@dlp ~]# yum -y install dhcp

[root@dlp ~]# vi /etc/dhcp/dhcpd.conf
================
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
#   see 'man 5 dhcpd.conf'
#
# atpl-subnet
ddns-updates on;
ddns-update-style interim;

set vendor-string = option vendor-class-identifier;

class "android" {
        match if substring (option vendor-class-identifier,0,6) = "dhcpcd";
        }

class "android-1" {
        match if substring (option vendor-class-identifier,0,7) = "android";
        }

class "BlackBerry" {
        match if substring (option vendor-class-identifier,0,10) = "BlackBerry";
        }

class "iPhones" {
        match if suffix (option host-name,6) = "iPhone";
        }
key rndc-key {
        algorithm hmac-md5;
        secret e511iZsuCmKS4BPfBje7hQ==;
};

allow client-updates;
authoritative;
#update-optimization off;

subnet 172.24.40.0 netmask 255.255.255.0 {
        interface eth0;
        pool {
        deny members of "android";
        deny members of "android-1";
        deny members of "BlackBerry";
        deny members of "iPhones";
        range 172.24.40.1 172.24.40.200;
        option broadcast-address 172.24.40.255;
        option subnet-mask 255.255.255.0;
        option routers 172.24.40.253;
        option domain-name "domain40.example.com";
        option domain-name-servers 172.24.40.100;
        default-lease-time 900;
        max-lease-time 900;
        }
        }

host station-x.domain40.example.com. {
        hardware ethernet 00:8e:f2:5d:07:17;
        fixed-address 172.24.40.100;
        }
host station-y.domain40.example.com. {
        hardware ethernet 00:26:b9:86:02:73;
        fixed-address 172.24.40.101;
        }
zone domain40.example.com. {
        primary localhost;
        key rndc-key;
        }
zone 40.24.192.in-addr.arpa. {
        primary localhost;
        key rndc-key;
        }
====================================

Bind with TSIG Transfer key

As we have configured master slave DNS on my previous link. Lets have replication with TSIG.

Step 1) On system-x
# cd /var/named/chroot/etc
# dnssec-keygen -a HMAC-MD5 -b 128 -n HOST station-x-station-y.

Now two files will be create

# cat  Kstation-x-station-y.+157+01233.private  (copy the key from here)

# cp -p rndc.key transfer.key
# vim transfer.key
key "station-x-station-y." {
        algorithm       hmac-md5;
        secret          "e511iZsuCmKS4BPfBje7hQ==";
};

# vim named.conf


include "/etc/transfer.key";
acl mylan {172.24.40.0/24;};

allow-transfer {key station-x-station-y.; };
        allow-query     { localhost; mylan; any; };
        allow-query-cache { localhost; mylan; any; };

(save)

#  ln -s transfer.key /etc/transfer.key
#service named restart
#named-checkconf named.conf

#scp transfer.key station-y:/var/named/chroot/etc/


# vi domain40.example.com.forward (add one more record)

secret-x.domain40.example.com.  IN A            172.24.40.100

(save)

# /etc/init.d/named restart

On system -y
# chgrp named transfer.key

# vim named.conf

include "/etc/transfer.key";
acl mylan {172.24.40.0/24;};
server 172.24.40.100 {
keys {station-x-station-y.; };
};


# rndc refresh domain40.example.com

# grep -i tsig /var/log/messages --color

# /etc/init.d/named restart

Renew k8s certificates

Check If certificate expires: amikum@~:03:06:54(⎈ |local-cluster:default):sudo kubeadm certs check-expiration CERTIFICATE                EXP...