Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ functests:
hack/run-functests.sh

unittests:
# functests are marked with "// +build !unittests" and will be skipped
GOFLAGS=-mod=vendor go test -v --tags unittests ./...
#TODO - copy in unit tests
GOFLAGS=-mod=vendor go test -v ./pkg/...

gofmt:
@echo "Running gofmt"
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ FROM registry.access.redhat.com/ubi8/ubi-minimal

USER nobody

COPY assets /assets
ADD _output/bin/performance-addon-operators /usr/local/bin/performance-operator

123 changes: 123 additions & 0 deletions build/assets/scripts/pre-boot-tuning.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env bash

set -euo pipefail

non_iso_cpumask=""
cpu_affinity=""

get_reserved_cores() {
cores=()
while read part; do
if [[ $part =~ - ]]; then
cores+=($(seq ${part/-/ }))
elif [[ $part =~ , ]]; then
continue
else
cores+=($part)
fi
done < <( echo ${NON_ISOLATED_CPUS} | tr ',' '\n' )
}

# $1 - 0 for irq balance banned cpus masking , 1 for non isolated cpus masking
get_cpu_mask() {
if [ "$1" = "1" ]; then
mask=( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
else
mask=( 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 )
fi
get_reserved_cores
for core in ${cores[*]}; do
mask[$core]=$1
done
cpumaskBinary=`echo ${mask[@]}| rev`
cpumaskBinary=${cpumaskBinary//[[:space:]]/}
non_iso_cpumask=`printf '%08x\n' "$((2#$cpumaskBinary))"`
}

get_cpu_affinity() {
cpu_affinity=""
get_reserved_cores
for core in ${cores[*]}; do
cpu_affinity+=" $core"
done
echo "CPU Affinity set to $cpu_affinity"
}

# TODO - find a more robust approach than keeping the last timestamp
RHCOS_OSTREE_PATH=$(ls -td /boot/ostree/*/ | head -1)
RHCOS_OSTREE_BOOTLOADER_PATH=${RHCOS_OSTREE_PATH#"/boot"}
INITRD_GENERATION_DIR="/root/initrd"
INITRD_NEW_IMAGE="${RHCOS_OSTREE_PATH}/iso_initrd.img"

# TODO: improve check for applied configuration
if [ -f ${INITRD_NEW_IMAGE} ] && grep -qsR "iso_initrd.img" "/boot/loader/entries/"; then
echo "Pre boot tuning configuration already applied"
echo "Setting kernel rcuo* threads to the housekeeping cpus"
get_cpu_mask 1
pgrep rcuo* | while read line; do taskset -p $non_iso_cpumask $line || true; done
else
# Clean up
rm -rf ${INITRD_GENERATION_DIR}

# Create initrd image
mkdir ${INITRD_GENERATION_DIR}
mkdir -p ${INITRD_GENERATION_DIR}/usr/lib/dracut/hooks/pre-udev/
mkdir -p ${INITRD_GENERATION_DIR}/etc/systemd/
mkdir -p ${INITRD_GENERATION_DIR}/etc/sysconfig/
touch ${INITRD_GENERATION_DIR}/etc/systemd/system.conf
touch ${INITRD_GENERATION_DIR}/etc/sysconfig/irqbalance
touch ${INITRD_GENERATION_DIR}/usr/lib/dracut/hooks/pre-udev/00-tuned-pre-udev.sh
chmod +x ${INITRD_GENERATION_DIR}/usr/lib/dracut/hooks/pre-udev/00-tuned-pre-udev.sh

get_cpu_mask 1
echo '#!/bin/sh

type getargs >/dev/null 2>&1 || . /lib/dracut-lib.sh

#cpumask="$(getargs non_iso_cpumask)"
cpumask='$non_iso_cpumask'

log()
{
echo "tuned: $@" >> /dev/kmsg
}

if [ -n "$cpumask" ]; then
for file in /sys/devices/virtual/workqueue/cpumask /sys/bus/workqueue/devices/writeback/cpumask; do
log "setting $file CPU mask to $cpumask"
if ! echo $cpumask > $file 2>/dev/null; then
log "ERROR: could not write CPU mask for $file"
fi
done
fi' > ${INITRD_GENERATION_DIR}/usr/lib/dracut/hooks/pre-udev/00-tuned-pre-udev.sh

# Set CPU affinity according to NON_ISOLATED_CPUS
get_cpu_affinity
echo "[Manager]" >> ${INITRD_GENERATION_DIR}/etc/systemd/system.conf
echo "CPUAffinity=$cpu_affinity" >> ${INITRD_GENERATION_DIR}/etc/systemd/system.conf

# Set IRQ banned cpu according to NON_ISOLATED_CPUS
get_cpu_mask 0
echo "IRQBALANCE_BANNED_CPUS=$non_iso_cpumask" >> ${INITRD_GENERATION_DIR}/etc/sysconfig/irqbalance

find ${INITRD_GENERATION_DIR} | cpio -co >${INITRD_NEW_IMAGE}

# Get current ostree config file according to the latest version
current_ver=1
entry_file=$(ls -td /boot/loader/entries/* | head -1)
while read -r line ; do
ver=`awk '/version/ {print $2}' $line`
if [ "$ver" -gt "$current_ver" ]; then
current_ver=$ver
entry_file=$line
fi
done <<<$(egrep $(uname -r) -lr /boot/loader/entries/)

sed -i "s^initrd .*\$^& ${RHCOS_OSTREE_BOOTLOADER_PATH}iso_initrd.img^" $entry_file

#TODO - once RHCOS image contains the initrd content we can set parameters with rpm-ostree:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might actually be able to test that already with latest RHCOS changes , but ill do it in another PR

#rpm-ostree initramfs --enable --arg=-I --arg=/etc/systemd/system.conf
#rpm-ostree initramfs --enable --arg=-I --arg=/etc/sysconfig/irqbalance

touch /var/reboot
fi
9 changes: 9 additions & 0 deletions build/assets/scripts/reboot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -euo pipefail

if [[ -f /var/reboot ]]; then
rm -f /var/reboot
echo "File /var/reboot exists, initiate reboot"
systemctl reboot
fi
55 changes: 55 additions & 0 deletions build/assets/scripts/rt-kernel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

set -euo pipefail

REPO_DIR="/etc/yum.repos.d"
RT_REPO="${REPO_DIR}/rt-kernel.repo"

# Enable yum repo
if [[ -f $RT_REPO ]]
then
# The env var might have been changed, so always create new rt repo
rm $RT_REPO
fi

mkdir -p $REPO_DIR
cat > $RT_REPO <<EOF
[rt]
baseurl=${RT_REPO_URL}
gpgcheck=0
EOF

# update cache
rpm-ostree refresh-md -f

exit_handler () {
exit_code=$?
if [[ ${exit_code} -eq 77 ]]; then
echo "No update available, nothing to do";
exit 0;
elif [[ ${exit_code} -eq 100 ]]; then
echo "Initiate reboot, touch /var/reboot"
touch /var/reboot
exit 0;
else
exit ${exit_code}
fi
}

trap exit_handler EXIT

# Swap to RT kernel
kernel=$(uname -a)
if [[ $kernel =~ "PREEMPT RT" ]]
then
echo "RT kernel already installed, checking for updates"
# if no upgrade is available the script will exit with code 77, and we will trap it
rpm-ostree upgrade --unchanged-exit-77
echo "RT kernel updated"
exit 100
else
echo "Installing RT kernel"
rpm-ostree override remove kernel{,-core,-modules,-modules-extra} --install kernel-rt-core --install kernel-rt-modules --install kernel-rt-modules-extra
echo "RT kernel installed"
exit 100
fi
52 changes: 52 additions & 0 deletions build/assets/tuned/openshift-node-network-latency
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[main]
summary=Openshift node optimized for deterministic performance at the cost of increased power consumption, focused on low latency network performance
include=openshift-node

[cpu]
# https://github.com/redhat-performance/tuned/blob/master/profiles/latency-performance/tuned.conf
# https://github.com/redhat-performance/tuned/blob/master/profiles/network-latency/tuned.conf
force_latency=cstate.id:1|3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there might be an issue with this format of setting latency (using the OR operand) , investigating this but worth checking if tuned pod doesn't have any errors with that here .

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can fix it under the separate PR

governor=performance
energy_perf_bias=performance
min_perf_pct=100

[vm]
transparent_hugepages=never

[sysctl]
net.core.busy_read=50
net.core.busy_poll=50
net.ipv4.tcp_fastopen=3
kernel.numa_balancing=0

# ktune sysctl settings for rhel6 servers, maximizing i/o throughput
#
# Minimal preemption granularity for CPU-bound tasks:
# (default: 1 msec# (1 + ilog(ncpus)), units: nanoseconds)
kernel.sched_min_granularity_ns=10000000

# If a workload mostly uses anonymous memory and it hits this limit, the entire
# working set is buffered for I/O, and any more write buffering would require
# swapping, so it's time to throttle writes until I/O can catch up. Workloads
# that mostly use file mappings may be able to use even higher values.
#
# The generator of dirty data starts writeback at this percentage (system default
# is 20%)
vm.dirty_ratio=10

# Start background writeback (via writeback threads) at this percentage (system
# default is 10%)
vm.dirty_background_ratio=3

# The swappiness parameter controls the tendency of the kernel to move
# processes out of physical memory and onto the swap disk.
# 0 tells the kernel to avoid swapping processes out of physical memory
# for as long as possible
# 100 tells the kernel to aggressively swap processes out of physical memory
# and move them to swap cache
vm.swappiness=10

# The total time the scheduler will consider a migrated process
# "cache hot" and thus less likely to be re-migrated
# (system default is 500000, i.e. 0.5 ms)
kernel.sched_migration_cost_ns=5000000
22 changes: 22 additions & 0 deletions build/assets/tuned/openshift-node-real-time-kernel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[main]
summary=Optimize nodes running real time kernel
include=openshift-node-network-latency

[selinux]
avc_cache_threshold=8192

[net]
nf_conntrack_hashsize=131072

[sysctl]
kernel.hung_task_timeout_secs = 600
kernel.nmi_watchdog = 0
kernel.sched_rt_runtime_us = -1
vm.stat_interval = 10
kernel.timer_migration = 0

[sysfs]
/sys/devices/system/machinecheck/machinecheck*/ignore_ce = 1

[scheduler]
isolated_cores={{.IsolatedCpus}}
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ spec:
description: RealTimeKernel defines set of real time kernel related
parameters.
properties:
enabled:
description: Enabled enables real time kernel on relevant nodes.
type: boolean
repoURL:
description: RepoURL defines the URL to the repository with real
time kernel packages
type: string
type: object
type: object
status:
Expand Down
10 changes: 7 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ module github.com/openshift-kni/performance-addon-operators
go 1.13

require (
github.com/coreos/ignition v0.34.0 // indirect
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f
github.com/coreos/ignition v0.34.0
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/go-openapi/spec v0.19.4 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/onsi/ginkgo v1.10.3
github.com/onsi/gomega v1.7.0
github.com/openshift/client-go v0.0.0-20191001081553-3b0e988f8cb0
github.com/openshift/api v3.9.1-0.20191111211345-a27ff30ebf09+incompatible
github.com/openshift/client-go v0.0.0-20191022152013-2823239d2298
github.com/openshift/cluster-node-tuning-operator v0.0.0-00010101000000-000000000000
github.com/openshift/machine-config-operator v4.2.0-alpha.0.0.20190917115525-033375cbe820+incompatible
github.com/operator-framework/operator-sdk v0.13.0
github.com/spf13/pflag v1.0.5
Expand All @@ -21,8 +24,8 @@ require (
k8s.io/api v0.17.0
k8s.io/apimachinery v0.17.0
k8s.io/client-go v12.0.0+incompatible
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a
k8s.io/kubelet v0.0.0
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f
sigs.k8s.io/controller-runtime v0.4.0
)

Expand Down Expand Up @@ -58,6 +61,7 @@ replace (
github.com/go-log/log => github.com/go-log/log v0.1.0
github.com/openshift/api => github.com/openshift/api v0.0.0-20191220175332-378bec237e34 // release-4.4
github.com/openshift/client-go => github.com/openshift/client-go v0.0.0-20191205152420-9faca5198b4f // release-4.4
github.com/openshift/cluster-node-tuning-operator => github.com/openshift/cluster-node-tuning-operator v0.0.0-20191217222311-500135cb8754 // release-4.4
github.com/openshift/machine-config-operator => github.com/openshift/machine-config-operator v0.0.0-20191220033234-347a7a09e869 // release-4.4
golang.org/x/tools => golang.org/x/tools v0.0.0-20191206213732-070c9d21b343
)
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
github.com/karrick/godirwalk v1.7.5/go.mod h1:2c9FRhkDxdIbgkOnCEvnSWs71Bhugbl46shStcFDJ34=
github.com/karrick/godirwalk v1.10.12/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/kevinburke/go-bindata v3.16.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v0.0.0-20161130080628-0de1eaf82fa3/go.mod h1:jxZFDH7ILpTPQTk+E2s+z4CUas9lVNjIuKR4c5/zKgM=
Expand Down Expand Up @@ -684,9 +685,13 @@ github.com/openshift/client-go v0.0.0-20191205152420-9faca5198b4f h1:1ak9jgsR7+v
github.com/openshift/client-go v0.0.0-20191205152420-9faca5198b4f/go.mod h1:6rzn+JTr7+WYS2E1TExP4gByoABxMznR6y2SnUIkmxk=
github.com/openshift/cluster-api v0.0.0-20190923092624-4024de4fa64d/go.mod h1:mNsD1dsD4T57kV4/C6zTHke/Ro166xgnyyRZqkamiEU=
github.com/openshift/cluster-etcd-operator v0.0.0-alpha.0.0.20191025163650-5854b5c48ce4/go.mod h1:vcBAUefK8pQmTPQ3jlCemORXhnRnq3aTsfOSVeaWliY=
github.com/openshift/cluster-node-tuning-operator v0.0.0-20191217222311-500135cb8754 h1:3rqk/tZZahKAjuAhRyfDWZbjH9udCtfXnWc9sSOYuNs=
github.com/openshift/cluster-node-tuning-operator v0.0.0-20191217222311-500135cb8754/go.mod h1:vfr0XwZQai3/NJgHoHFWFXLo+qKboxg5AinYlyx0lZ4=
github.com/openshift/crd-schema-gen v1.0.0/go.mod h1:jTmSmtfJzK2emb3ucPkHqvoOe//PuNhR3aBiUBbg/rc=
github.com/openshift/imagebuilder v1.1.1/go.mod h1:9aJRczxCH0mvT6XQ+5STAQaPWz7OsWcU5/mRkt8IWeo=
github.com/openshift/library-go v0.0.0-20190619114638-6b58b672ee58/go.mod h1:NBttNjZpWwup/nthuLbPAPSYC8Qyo+BBK5bCtFoyYjo=
github.com/openshift/library-go v0.0.0-20191003152030-97c62d8a2901/go.mod h1:NBttNjZpWwup/nthuLbPAPSYC8Qyo+BBK5bCtFoyYjo=
github.com/openshift/library-go v0.0.0-20191024144423-664354b88b39/go.mod h1:NBttNjZpWwup/nthuLbPAPSYC8Qyo+BBK5bCtFoyYjo=
github.com/openshift/machine-config-operator v0.0.0-20191220033234-347a7a09e869 h1:CAPIebw+Q76kRPY0k4LXzJNTYgr6eYcH6MCynx7vB/c=
github.com/openshift/machine-config-operator v0.0.0-20191220033234-347a7a09e869/go.mod h1:0IIYHSoQ7nLsMoPB29Z/N9KMh/PpywcJMCdoWtRIY9E=
github.com/openshift/origin v0.0.0-20160503220234-8f127d736703/go.mod h1:0Rox5r9C8aQn6j1oAOQ0c1uC86mYbUFObzjBRvUKHII=
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/performance/v1alpha1/performanceprofile_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ type HugePages struct {
// HugePage defines the number of allocated huge pages of the specific size.
type HugePage struct {
// Size defines huge page size, maps to the 'hugepagesz' kernel boot parameter.
Size *HugePageSize `json:"size,omitempty"`
Size HugePageSize `json:"size,omitempty"`
// Count defines amount of huge pages, maps to the 'hugepages' kernel boot parameter.
Count *int32 `json:"count,omitempty"`
Count int32 `json:"count,omitempty"`
}

// RealTimeKernel defines the set of parameters relevant for the real time kernel.
type RealTimeKernel struct {
// Enabled enables real time kernel on relevant nodes.
Enabled *bool `json:"enabled,omitempty"`
// RepoURL defines the URL to the repository with real time kernel packages
RepoURL *string `json:"repoURL,omitempty"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this going to eventually turn back into a boolean soon?

}

// PerformanceProfileStatus defines the observed state of PerformanceProfile.
Expand Down
Loading