From 4a61cf893ee0c699f0f12dfa8bfe5f3fba153c17 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 5 Dec 2018 02:11:32 +0100 Subject: bin/realtime-suggestions: Adding realtime-suggestions. --- bin/realtime-suggestions | 216 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100755 bin/realtime-suggestions (limited to 'bin') diff --git a/bin/realtime-suggestions b/bin/realtime-suggestions new file mode 100755 index 0000000..4ff8722 --- /dev/null +++ b/bin/realtime-suggestions @@ -0,0 +1,216 @@ +#!/usr/bin/env bash + +set -euo pipefail + +warning="WARNING:" +info="INFO:" +kernel_config="/proc/config.gz" +sysctl_ref="(see \`man 5 sysctl.conf\`, \`man 5 sysctl.d\` or \`man 8 sysctl\` for reference)" + +check_root() { + if [ "$(id -u)" -eq 0 ]; then + echo "Use this script as an unprivileged user." + exit 1 + fi +} + +check_filesystems() { + local mount_points=() + local mount_point_data=() + local what="" + local where="" + local type="" + local options="" + mapfile -t mount_points < <( mount |grep -E "^/dev" ) + for mount_point in "${mount_points[@]}"; do + mapfile -d " " -t mount_point_data < <( echo "${mount_point}" ) + what="${mount_point_data[0]}" + where="${mount_point_data[2]}" + type="${mount_point_data[4]}" + options="${mount_point_data[5]}" + if [[ "$options" != *relatime* ]] && [[ "$options" != *noatime* ]]; then + echo "$warning $what mounted on $where (type $type) should use the relatime mount option for performance." + fi + if [[ "$type" == *fuse* ]] || [[ "$type" == *reiserfs* ]] || [[ "$type" == *vfat* ]]; then + echo "$info $what mounted on $where (type $type) is not a good filesystem for large files or realtime use." + fi + done +} + +check_groups() { + local groups="" + groups=$(groups) + if [[ "$groups" != *audio* ]]; then + echo "$warning Add your user to the audio group. It's used for access to audio devices on most distros." + fi + if [[ "$groups" != *realtime* ]]; then + echo "$info Some distributions use the realtime group for elevated resource limits." + fi +} + +check_ulimits() { + local limits_ref="(see \`man limits.conf\` for reference)" + if [[ "$(ulimit -t)" != "unlimited" ]]; then + echo "$warning The CPU limit for your user is not unlimited $limits_ref." + fi + if [[ "$(ulimit -l)" != "unlimited" ]]; then + echo "$warning The locked-in-memory limit for your user is not unlimited $limits_ref." + fi + if [ "$(ulimit -r)" -le 50 ]; then + echo "$warning The maximum rt priority for your user ($(ulimit -r)) is very low. Consider increasing it up to 98 $limits_ref." + fi +} + +check_vm_swappiness() { + local minimum=10 + local proc_file="/proc/sys/vm/swappiness" + if [ "$(cat "$proc_file")" -gt $minimum ]; then + echo "$warning Consider decreasing 'vm.swappiness<=$minimum' to prevent early write to swap $sysctl_ref." + fi +} + +check_max_user_watches() { + local minimum=524288 + local proc_file="/proc/sys/fs/inotify/max_user_watches" + if [ "$(cat "$proc_file")" -lt $minimum ]; then + echo "$warning Consider increasing 'fs.inotify.max_user_watches>$minimum' - the maximum amount of files inotify can watch $sysctl_ref" + fi +} + +check_cpu_governor() { + local cpupower_ref="(see \`man cpupower\` for reference)" + local governor="" + local policy_no="" + local cpu_no="" + for governor_file in /sys/devices/system/cpu/cpufreq/policy*/scaling_governor; do + governor="$(cat "$governor_file")" + policy_no="$(echo "$governor_file"| cut -d'/' -f7)" + cpu_no="${policy_no//policy}" + if [[ "$governor" != "performance" ]]; then + echo "$warning CPU $cpu_no has governor $governor set. Set it to 'performance' $cpupower_ref." + fi + done +} + +check_config_high_res_timers() { + local config="CONFIG_HIGH_RES_TIMERS=y" + local config_ref="(see \`man 7 time\` for reference)" + if [ -e "${kernel_config}" ]; then + if ! zgrep -q "$config" "$kernel_config"; then + echo "$warning CONFIG_HIGH_RES_TIMERS needs to be activated for your kernel $config_ref." + fi + else + echo "$warning $kernel_config could not be found or accessed." + fi +} + +check_config_no_hz() { + local config1="CONFIG_NO_HZ_IDLE=y" + local config2="CONFIG_NO_HZ=y" + local config_ref="(see https://elinux.org/Kernel_Timer_Systems#Dynamic_ticks for reference)" + if [ -e "${kernel_config}" ]; then + if ! zgrep -q "$config1" "$kernel_config"; then + echo "$warning $config1 needs to be set for your kernel for 'dynamic ticks' support $config_ref." + fi + if ! zgrep -q "$config2" "$kernel_config"; then + echo "$warning $config2 needs to be set for your kernel for 'dynamic ticks' support $config_ref." + fi + else + echo "$warning $kernel_config could not be found or accessed." + fi +} + +check_config_preempt_rt() { + local config1="CONFIG_PREEMPT_RT=y" + local config2="CONFIG_PREEMPT_RT_FULL=y" + local config_ref="(see https://wiki.linuxfoundation.org/realtime for reference)" + if [ -e "${kernel_config}" ]; then + if ! zgrep -q "$config1" "$kernel_config" && ! zgrep -q "$config2" "$kernel_config"; then + echo "$warning The PREEMPT_RT patch set is not available on your kernel $config_ref." + fi + else + echo "$warning $kernel_config could not be found or accessed." + fi +} + +check_config_irq_forced_threading() { + local config1="CONFIG_PREEMPT=y" + local config2="CONFIG_IRQ_FORCED_THREADING=y" + local config_ref="(see https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html for reference)" + if [ -e "${kernel_config}" ]; then + if zgrep -q "$config2" "$kernel_config"; then + if ! zgrep -q "$config1" "$kernel_config" && ! grep -q "threadirqs" /proc/cmdline; then + echo "$warning Without $config1 on your kernel, you can still use the threadirqs kernel parameter $config_ref." + fi + else + echo "$warning Use a kernel with $config2 $config_ref." + fi + else + echo "$warning $kernel_config could not be found or accessed." + fi +} + +check_legacy_timers() { + local hpet_file="/dev/hpet" + local rtc_file="/dev/rtc0" + local hpet_ref="(see https://wiki.linuxaudio.org/wiki/system_configuration#timers for reference)" + if [ ! -w "$hpet_file" ]; then + echo "$info $hpet_file is not writable by your user. Some legacy software requires it $hpet_ref." + fi + if [ ! -w "$rtc_file" ]; then + echo "$info $rtc_file is not writable by your user. Some legacy software requires it $hpet_ref." + fi +} + +check_cpu_dma_latency() { + local dev_file="/dev/cpu_dma_latency" + if [ ! -w "$dev_file" ]; then + echo "$warning $dev_file needs to be writable by your user to prevent deep CPU sleep states." + fi +} + +check_coupled_interrupts() { + local interrupts=() + local interrupt_delim=", " + local interrupt_number="" + local interrupt_ref="(see \`cat /proc/interrupts\` for more and consider using rtirq)" + mapfile -t interrupts < <( cat /proc/interrupts ) + for interrupt_line in "${interrupts[@]}"; do + interrupt_number="$(echo "$interrupt_line"| cut -d':' -f1)" + if [[ "$interrupt_line" == *"$interrupt_delim"* ]]; then + echo "$warning IRQ$interrupt_number has coupled interrupts $interrupt_ref." + fi + done +} + +check_irqbalance() { + if pgrep -i irqbalance >/dev/null 2>&1; then + echo "$warning The irqbalance service is running on your system. It might interfere, so consider disabling it." + fi +} + +check_for_useful_tools() { + local tools=( cyclictest htop iostat iotop rtirq schedtool tuna ) + for tool in "${tools[@]}";do + if ! command -v "$tool" >/dev/null 2>&1; then + echo "$info Consider installing and using $tool." + fi + done +} + +check_root +check_filesystems +check_groups +check_ulimits +check_max_user_watches +check_legacy_timers +check_vm_swappiness +check_cpu_governor +check_cpu_dma_latency +check_config_high_res_timers +check_config_no_hz +check_config_preempt_rt +check_config_irq_forced_threading +check_coupled_interrupts +check_irqbalance +check_for_useful_tools -- cgit v1.2.3-70-g09d2 From cb40435a8285be6d023192c0bae8c184f1d37ed0 Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 5 Dec 2018 22:53:17 +0100 Subject: bin/realtime-suggestions: Ignoring /boot mount points (it's very unlikely to use that for anything but boot stuff). --- bin/realtime-suggestions | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'bin') diff --git a/bin/realtime-suggestions b/bin/realtime-suggestions index 4ff8722..2852476 100755 --- a/bin/realtime-suggestions +++ b/bin/realtime-suggestions @@ -28,11 +28,13 @@ check_filesystems() { where="${mount_point_data[2]}" type="${mount_point_data[4]}" options="${mount_point_data[5]}" - if [[ "$options" != *relatime* ]] && [[ "$options" != *noatime* ]]; then - echo "$warning $what mounted on $where (type $type) should use the relatime mount option for performance." - fi - if [[ "$type" == *fuse* ]] || [[ "$type" == *reiserfs* ]] || [[ "$type" == *vfat* ]]; then - echo "$info $what mounted on $where (type $type) is not a good filesystem for large files or realtime use." + if [[ "$where" != /boot* ]]; then + if [[ "$options" != *relatime* ]] && [[ "$options" != *noatime* ]]; then + echo "$warning $what mounted on $where (type $type) should use the relatime mount option for performance." + fi + if [[ "$type" == *fuse* ]] || [[ "$type" == *reiserfs* ]] || [[ "$type" == *vfat* ]]; then + echo "$info $what mounted on $where (type $type) is not a good filesystem for large files or realtime use." + fi fi done } -- cgit v1.2.3-70-g09d2 From 1bf046edd2f2798147c753deebdf283401b54aac Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 6 Dec 2018 20:49:42 +0100 Subject: bin/realtime-suggestions: Switching WARNING to CHANGE. Only checking for CONFIG_NO_HZ_{,COMMON,FULL}. --- bin/realtime-suggestions | 54 +++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) (limited to 'bin') diff --git a/bin/realtime-suggestions b/bin/realtime-suggestions index 2852476..632825a 100755 --- a/bin/realtime-suggestions +++ b/bin/realtime-suggestions @@ -2,7 +2,7 @@ set -euo pipefail -warning="WARNING:" +change="CHANGE:" info="INFO:" kernel_config="/proc/config.gz" sysctl_ref="(see \`man 5 sysctl.conf\`, \`man 5 sysctl.d\` or \`man 8 sysctl\` for reference)" @@ -30,7 +30,7 @@ check_filesystems() { options="${mount_point_data[5]}" if [[ "$where" != /boot* ]]; then if [[ "$options" != *relatime* ]] && [[ "$options" != *noatime* ]]; then - echo "$warning $what mounted on $where (type $type) should use the relatime mount option for performance." + echo "$change $what mounted on $where (type $type) should use the relatime mount option for performance." fi if [[ "$type" == *fuse* ]] || [[ "$type" == *reiserfs* ]] || [[ "$type" == *vfat* ]]; then echo "$info $what mounted on $where (type $type) is not a good filesystem for large files or realtime use." @@ -43,7 +43,7 @@ check_groups() { local groups="" groups=$(groups) if [[ "$groups" != *audio* ]]; then - echo "$warning Add your user to the audio group. It's used for access to audio devices on most distros." + echo "$change Add your user to the audio group. It's used for access to audio devices on most distros." fi if [[ "$groups" != *realtime* ]]; then echo "$info Some distributions use the realtime group for elevated resource limits." @@ -53,13 +53,13 @@ check_groups() { check_ulimits() { local limits_ref="(see \`man limits.conf\` for reference)" if [[ "$(ulimit -t)" != "unlimited" ]]; then - echo "$warning The CPU limit for your user is not unlimited $limits_ref." + echo "$change The CPU limit for your user is not unlimited $limits_ref." fi if [[ "$(ulimit -l)" != "unlimited" ]]; then - echo "$warning The locked-in-memory limit for your user is not unlimited $limits_ref." + echo "$change The locked-in-memory limit for your user is not unlimited $limits_ref." fi if [ "$(ulimit -r)" -le 50 ]; then - echo "$warning The maximum rt priority for your user ($(ulimit -r)) is very low. Consider increasing it up to 98 $limits_ref." + echo "$change The maximum rt priority for your user ($(ulimit -r)) is very low. Consider increasing it up to 98 $limits_ref." fi } @@ -67,7 +67,7 @@ check_vm_swappiness() { local minimum=10 local proc_file="/proc/sys/vm/swappiness" if [ "$(cat "$proc_file")" -gt $minimum ]; then - echo "$warning Consider decreasing 'vm.swappiness<=$minimum' to prevent early write to swap $sysctl_ref." + echo "$info Consider decreasing 'vm.swappiness<=$minimum' to prevent early write to swap $sysctl_ref." fi } @@ -75,7 +75,7 @@ check_max_user_watches() { local minimum=524288 local proc_file="/proc/sys/fs/inotify/max_user_watches" if [ "$(cat "$proc_file")" -lt $minimum ]; then - echo "$warning Consider increasing 'fs.inotify.max_user_watches>$minimum' - the maximum amount of files inotify can watch $sysctl_ref" + echo "$change Consider increasing 'fs.inotify.max_user_watches>$minimum' - the maximum amount of files inotify can watch $sysctl_ref" fi } @@ -89,7 +89,7 @@ check_cpu_governor() { policy_no="$(echo "$governor_file"| cut -d'/' -f7)" cpu_no="${policy_no//policy}" if [[ "$governor" != "performance" ]]; then - echo "$warning CPU $cpu_no has governor $governor set. Set it to 'performance' $cpupower_ref." + echo "$change CPU $cpu_no has governor $governor set. Set it to 'performance' $cpupower_ref." fi done } @@ -99,26 +99,24 @@ check_config_high_res_timers() { local config_ref="(see \`man 7 time\` for reference)" if [ -e "${kernel_config}" ]; then if ! zgrep -q "$config" "$kernel_config"; then - echo "$warning CONFIG_HIGH_RES_TIMERS needs to be activated for your kernel $config_ref." + echo "$change CONFIG_HIGH_RES_TIMERS needs to be activated for your kernel $config_ref." fi else - echo "$warning $kernel_config could not be found or accessed." + echo "$change $kernel_config could not be found or accessed." fi } check_config_no_hz() { - local config1="CONFIG_NO_HZ_IDLE=y" - local config2="CONFIG_NO_HZ=y" + local configs=( 'CONFIG_NO_HZ_COMMON=y' 'CONFIG_NO_HZ_FULL=y' 'CONFIG_NO_HZ=y') local config_ref="(see https://elinux.org/Kernel_Timer_Systems#Dynamic_ticks for reference)" if [ -e "${kernel_config}" ]; then - if ! zgrep -q "$config1" "$kernel_config"; then - echo "$warning $config1 needs to be set for your kernel for 'dynamic ticks' support $config_ref." - fi - if ! zgrep -q "$config2" "$kernel_config"; then - echo "$warning $config2 needs to be set for your kernel for 'dynamic ticks' support $config_ref." - fi + for config in "${configs[@]}"; do + if ! zgrep -q "$config" "$kernel_config"; then + echo "$change $config1 needs to be set for your kernel for 'dynamic ticks' support $config_ref." + fi + done else - echo "$warning $kernel_config could not be found or accessed." + echo "$change $kernel_config could not be found or accessed." fi } @@ -128,10 +126,10 @@ check_config_preempt_rt() { local config_ref="(see https://wiki.linuxfoundation.org/realtime for reference)" if [ -e "${kernel_config}" ]; then if ! zgrep -q "$config1" "$kernel_config" && ! zgrep -q "$config2" "$kernel_config"; then - echo "$warning The PREEMPT_RT patch set is not available on your kernel $config_ref." + echo "$change The PREEMPT_RT patch set is not available on your kernel $config_ref." fi else - echo "$warning $kernel_config could not be found or accessed." + echo "$change $kernel_config could not be found or accessed." fi } @@ -142,13 +140,13 @@ check_config_irq_forced_threading() { if [ -e "${kernel_config}" ]; then if zgrep -q "$config2" "$kernel_config"; then if ! zgrep -q "$config1" "$kernel_config" && ! grep -q "threadirqs" /proc/cmdline; then - echo "$warning Without $config1 on your kernel, you can still use the threadirqs kernel parameter $config_ref." + echo "$change Without $config1 on your kernel, you can still use the threadirqs kernel parameter $config_ref." fi else - echo "$warning Use a kernel with $config2 $config_ref." + echo "$change Use a kernel with $config2 $config_ref." fi else - echo "$warning $kernel_config could not be found or accessed." + echo "$change $kernel_config could not be found or accessed." fi } @@ -167,7 +165,7 @@ check_legacy_timers() { check_cpu_dma_latency() { local dev_file="/dev/cpu_dma_latency" if [ ! -w "$dev_file" ]; then - echo "$warning $dev_file needs to be writable by your user to prevent deep CPU sleep states." + echo "$change $dev_file needs to be writable by your user to prevent deep CPU sleep states." fi } @@ -180,14 +178,14 @@ check_coupled_interrupts() { for interrupt_line in "${interrupts[@]}"; do interrupt_number="$(echo "$interrupt_line"| cut -d':' -f1)" if [[ "$interrupt_line" == *"$interrupt_delim"* ]]; then - echo "$warning IRQ$interrupt_number has coupled interrupts $interrupt_ref." + echo "$change IRQ$interrupt_number has coupled interrupts $interrupt_ref." fi done } check_irqbalance() { if pgrep -i irqbalance >/dev/null 2>&1; then - echo "$warning The irqbalance service is running on your system. It might interfere, so consider disabling it." + echo "$change The irqbalance service is running on your system. It might interfere, so consider disabling it." fi } -- cgit v1.2.3-70-g09d2 From 54f7f1ccba1589099be01b02435a318ac2b0f018 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 8 Dec 2018 21:46:19 +0100 Subject: bin/realtime-suggestions: Adding check for Linux kernel. --- bin/realtime-suggestions | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'bin') diff --git a/bin/realtime-suggestions b/bin/realtime-suggestions index 632825a..232e17a 100755 --- a/bin/realtime-suggestions +++ b/bin/realtime-suggestions @@ -14,6 +14,13 @@ check_root() { fi } +check_kernel_name() { + if [[ "$(uname -s)" != *Linux* ]]; then + echo "This script needs to be run on a Linux system." + exit 1 + fi +} + check_filesystems() { local mount_points=() local mount_point_data=() @@ -198,6 +205,7 @@ check_for_useful_tools() { done } +check_kernel_name check_root check_filesystems check_groups -- cgit v1.2.3-70-g09d2 From c70c214bbc0ffde5b0f665acc8845fb3466c6c28 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 8 Dec 2018 21:47:33 +0100 Subject: bin/realtime-suggestions: Fixing unitialized variable in message printout. --- bin/realtime-suggestions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/realtime-suggestions b/bin/realtime-suggestions index 632825a..45a1fff 100755 --- a/bin/realtime-suggestions +++ b/bin/realtime-suggestions @@ -112,7 +112,7 @@ check_config_no_hz() { if [ -e "${kernel_config}" ]; then for config in "${configs[@]}"; do if ! zgrep -q "$config" "$kernel_config"; then - echo "$change $config1 needs to be set for your kernel for 'dynamic ticks' support $config_ref." + echo "$change $config needs to be set for your kernel for 'dynamic ticks' support $config_ref." fi done else -- cgit v1.2.3-70-g09d2 From e23ba59267423a3ca67747dcdfd8884c9d5f7de8 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 9 Dec 2018 13:27:35 +0100 Subject: bin/realtime-suggestions: Adding check for virtualization/containerization. --- bin/realtime-suggestions | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'bin') diff --git a/bin/realtime-suggestions b/bin/realtime-suggestions index cc552fe..c5e7355 100755 --- a/bin/realtime-suggestions +++ b/bin/realtime-suggestions @@ -2,6 +2,7 @@ set -euo pipefail +warning="WARNING:" change="CHANGE:" info="INFO:" kernel_config="/proc/config.gz" @@ -21,6 +22,20 @@ check_kernel_name() { fi } +check_virtualization() { + local virt_type="" + if command -v systemd-detect-virt >/dev/null 2>&1; then + set +e + virt_type=$(systemd-detect-virt) + set -e + if systemd-detect-virt -q; then + echo "$change Running in a virtual machine or container (type: ${virt_type}). This is not recommended!" + fi + else + echo "$warning Unable to detect if in a virtual machine." + fi +} + check_filesystems() { local mount_points=() local mount_point_data=() @@ -207,6 +222,7 @@ check_for_useful_tools() { check_kernel_name check_root +check_virtualization check_filesystems check_groups check_ulimits -- cgit v1.2.3-70-g09d2 From 99f06a2e3c2b6e040895ac7fe5963ae7ba8298d5 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 9 Dec 2018 13:38:50 +0100 Subject: bin/realtime-suggestions: Guarding against non-existing cpufreq dir in /sys, when running check_cpu_governor(). Mentioning default value in check_max_user_watches(). --- bin/realtime-suggestions | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'bin') diff --git a/bin/realtime-suggestions b/bin/realtime-suggestions index c5e7355..9235651 100755 --- a/bin/realtime-suggestions +++ b/bin/realtime-suggestions @@ -97,23 +97,28 @@ check_max_user_watches() { local minimum=524288 local proc_file="/proc/sys/fs/inotify/max_user_watches" if [ "$(cat "$proc_file")" -lt $minimum ]; then - echo "$change Consider increasing 'fs.inotify.max_user_watches>$minimum' - the maximum amount of files inotify can watch $sysctl_ref" + echo "$change Consider increasing 'fs.inotify.max_user_watches>$minimum' (default) - the maximum amount of files inotify can watch $sysctl_ref." fi } check_cpu_governor() { + local governor_dir="/sys/devices/system/cpu/cpufreq/" local cpupower_ref="(see \`man cpupower\` for reference)" local governor="" local policy_no="" local cpu_no="" - for governor_file in /sys/devices/system/cpu/cpufreq/policy*/scaling_governor; do - governor="$(cat "$governor_file")" - policy_no="$(echo "$governor_file"| cut -d'/' -f7)" - cpu_no="${policy_no//policy}" - if [[ "$governor" != "performance" ]]; then - echo "$change CPU $cpu_no has governor $governor set. Set it to 'performance' $cpupower_ref." - fi - done + if [ -d "${governor_dir}" ]; then + for governor_file in /sys/devices/system/cpu/cpufreq/policy*/scaling_governor; do + governor="$(cat "$governor_file")" + policy_no="$(echo "$governor_file"| cut -d'/' -f7)" + cpu_no="${policy_no//policy}" + if [[ "$governor" != "performance" ]]; then + echo "$change CPU $cpu_no has governor $governor set. Set it to 'performance' $cpupower_ref." + fi + done + else + echo "$warning Unable to detect any CPU governor on your machine. ${governor_dir} does not exist!" + fi } check_config_high_res_timers() { -- cgit v1.2.3-70-g09d2 From d5ebfe425f13b6b584bc0541a900aab1150d9e1f Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 9 Dec 2018 13:50:47 +0100 Subject: bin/realtime-suggestions: Changing check for policy directory in check_cpu_governor(), so that we fail if we don't at least find one policy dir. --- bin/realtime-suggestions | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'bin') diff --git a/bin/realtime-suggestions b/bin/realtime-suggestions index 9235651..cf5f599 100755 --- a/bin/realtime-suggestions +++ b/bin/realtime-suggestions @@ -102,12 +102,12 @@ check_max_user_watches() { } check_cpu_governor() { - local governor_dir="/sys/devices/system/cpu/cpufreq/" + local policy_dir="/sys/devices/system/cpu/cpufreq/" local cpupower_ref="(see \`man cpupower\` for reference)" local governor="" local policy_no="" local cpu_no="" - if [ -d "${governor_dir}" ]; then + if [ -d "${policy_dir}/policy0" ]; then for governor_file in /sys/devices/system/cpu/cpufreq/policy*/scaling_governor; do governor="$(cat "$governor_file")" policy_no="$(echo "$governor_file"| cut -d'/' -f7)" @@ -117,7 +117,7 @@ check_cpu_governor() { fi done else - echo "$warning Unable to detect any CPU governor on your machine. ${governor_dir} does not exist!" + echo "$warning Unable to detect any CPU governor on your machine. ${policy_dir} is empty!" fi } -- cgit v1.2.3-70-g09d2 From a45198d9c3dd8699dc03c5e06970c0512ff67776 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 9 Dec 2018 16:03:45 +0100 Subject: bin/realtime-suggestions: Switching the kernel_config location to somewhere below /boot, if the default below /proc/config.gz was not found. Rewriting all kernel config checks to use a unified function kernel_config_has() and cmdline checks to use kernel_cmdline_has(). --- bin/realtime-suggestions | 105 ++++++++++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 38 deletions(-) (limited to 'bin') diff --git a/bin/realtime-suggestions b/bin/realtime-suggestions index cf5f599..fa0c82e 100755 --- a/bin/realtime-suggestions +++ b/bin/realtime-suggestions @@ -5,7 +5,10 @@ set -euo pipefail warning="WARNING:" change="CHANGE:" info="INFO:" -kernel_config="/proc/config.gz" + +kernel_release="" +kernel_config="" + sysctl_ref="(see \`man 5 sysctl.conf\`, \`man 5 sysctl.d\` or \`man 8 sysctl\` for reference)" check_root() { @@ -22,6 +25,43 @@ check_kernel_name() { fi } +get_kernel_config_location() { + local default_location="/proc/config.gz" + local boot_location="/boot/config-${kernel_release}" + if [ -r "${default_location}" ]; then + echo "${default_location}" + return + elif [ -r "${boot_location}" ]; then + echo "${boot_location}" + return + else + echo "" + return + fi +} + +kernel_config_has() { + local config="$1" + local grep_cmd="zgrep" + if [[ "${kernel_config}" != *.gz ]]; then + grep_cmd="grep" + fi + if $grep_cmd -q "$config" "$kernel_config"; then + return 0 + else + return 1 + fi +} + +kernel_cmdline_has() { + local search="$1" + if ! grep -q "${search}" /proc/cmdline; then + return 1 + else + return 0 + fi +} + check_virtualization() { local virt_type="" if command -v systemd-detect-virt >/dev/null 2>&1; then @@ -124,56 +164,38 @@ check_cpu_governor() { check_config_high_res_timers() { local config="CONFIG_HIGH_RES_TIMERS=y" local config_ref="(see \`man 7 time\` for reference)" - if [ -e "${kernel_config}" ]; then - if ! zgrep -q "$config" "$kernel_config"; then - echo "$change CONFIG_HIGH_RES_TIMERS needs to be activated for your kernel $config_ref." - fi - else - echo "$change $kernel_config could not be found or accessed." + if ! kernel_config_has "$config"; then + echo "$change CONFIG_HIGH_RES_TIMERS needs to be activated for your kernel $config_ref." fi } check_config_no_hz() { local configs=( 'CONFIG_NO_HZ_COMMON=y' 'CONFIG_NO_HZ_FULL=y' 'CONFIG_NO_HZ=y') local config_ref="(see https://elinux.org/Kernel_Timer_Systems#Dynamic_ticks for reference)" - if [ -e "${kernel_config}" ]; then - for config in "${configs[@]}"; do - if ! zgrep -q "$config" "$kernel_config"; then - echo "$change $config needs to be set for your kernel for 'dynamic ticks' support $config_ref." - fi - done - else - echo "$change $kernel_config could not be found or accessed." - fi + for config in "${configs[@]}"; do + if ! kernel_config_has "$config"; then + echo "$change $config needs to be set for your kernel for 'dynamic ticks' support $config_ref." + fi + done } check_config_preempt_rt() { - local config1="CONFIG_PREEMPT_RT=y" - local config2="CONFIG_PREEMPT_RT_FULL=y" + local configs=( 'CONFIG_PREEMPT_RT=y' 'CONFIG_PREEMPT_RT_FULL=y' ) local config_ref="(see https://wiki.linuxfoundation.org/realtime for reference)" - if [ -e "${kernel_config}" ]; then - if ! zgrep -q "$config1" "$kernel_config" && ! zgrep -q "$config2" "$kernel_config"; then - echo "$change The PREEMPT_RT patch set is not available on your kernel $config_ref." - fi - else - echo "$change $kernel_config could not be found or accessed." + if ! kernel_config_has "${configs[0]}" && ! kernel_config_has "${configs[1]}"; then + echo "$change The PREEMPT_RT patch set (${configs[*]}) is not available on your kernel $config_ref." fi } check_config_irq_forced_threading() { - local config1="CONFIG_PREEMPT=y" - local config2="CONFIG_IRQ_FORCED_THREADING=y" + local configs=( 'CONFIG_IRQ_FORCED_THREADING=y' 'CONFIG_PREEMPT=y' ) local config_ref="(see https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html for reference)" - if [ -e "${kernel_config}" ]; then - if zgrep -q "$config2" "$kernel_config"; then - if ! zgrep -q "$config1" "$kernel_config" && ! grep -q "threadirqs" /proc/cmdline; then - echo "$change Without $config1 on your kernel, you can still use the threadirqs kernel parameter $config_ref." - fi + if ! kernel_config_has "${configs[0]}"; then + if kernel_config_has "${configs[1]}" && ! kernel_cmdline_has "threadirqs"; then + echo "$change Without ${configs[0]} but with ${configs[1]} support on your kernel, you can still use the threadirqs kernel parameter $config_ref." else - echo "$change Use a kernel with $config2 $config_ref." + echo "$change Your kernel neither supports ${configs[0]} nor ${configs[1]}." fi - else - echo "$change $kernel_config could not be found or accessed." fi } @@ -228,6 +250,17 @@ check_for_useful_tools() { check_kernel_name check_root check_virtualization +kernel_release=$(uname -r) +kernel_config=$(get_kernel_config_location) +if [ -n "${kernel_config}" ]; then + check_config_high_res_timers + check_config_no_hz + check_config_preempt_rt + check_config_irq_forced_threading +else + echo "$warning The kernel config could not be found or accessed (e.g. /proc/config.gz or below /boot/config-*)." +fi + check_filesystems check_groups check_ulimits @@ -236,10 +269,6 @@ check_legacy_timers check_vm_swappiness check_cpu_governor check_cpu_dma_latency -check_config_high_res_timers -check_config_no_hz -check_config_preempt_rt -check_config_irq_forced_threading check_coupled_interrupts check_irqbalance check_for_useful_tools -- cgit v1.2.3-70-g09d2 From 2b0fe3382e39c330c99333be34b8909175d69499 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 9 Dec 2018 16:09:11 +0100 Subject: bin/realtime-suggestions: Switching to info level for detection of audio group. --- bin/realtime-suggestions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/bin/realtime-suggestions b/bin/realtime-suggestions index fa0c82e..c26055d 100755 --- a/bin/realtime-suggestions +++ b/bin/realtime-suggestions @@ -105,10 +105,10 @@ check_groups() { local groups="" groups=$(groups) if [[ "$groups" != *audio* ]]; then - echo "$change Add your user to the audio group. It's used for access to audio devices on most distros." + echo "$info Consider adding your user to the audio group. On some distributions it's used for elevated resource limits." fi if [[ "$groups" != *realtime* ]]; then - echo "$info Some distributions use the realtime group for elevated resource limits." + echo "$info Consider adding your user to the realtime group. On some distributions it's used for elevated resource limits." fi } -- cgit v1.2.3-70-g09d2 From dff99a3114cde5920264459365015d6354bdefcb Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 17 Dec 2018 19:12:44 +0100 Subject: bin/xorg_autolock: Removing useless script. --- bin/xorg_autolock | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100755 bin/xorg_autolock (limited to 'bin') diff --git a/bin/xorg_autolock b/bin/xorg_autolock deleted file mode 100755 index 181548e..0000000 --- a/bin/xorg_autolock +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -lock=${XDG_RUNTIME_DIR}/xorg_autolock.lock -lock_block=${XDG_RUNTIME_DIR}/xorg_autolock_block -lock_cmd="$HOME/bin/xorg_lock" -lockafter=600000 - -rm -f "${lock}" "${lock_block}" - -while true; do - if [ ! -f "${lock}" ] && [ ! -f "${lock_block}" ];then - if [ -x "/usr/bin/xssstate" ]; then - if [ "$(xssstate -i)" -ge $lockafter ] && [ -x "$lock_cmd" ]; then - $lock_cmd - fi - else - echo "xssstate is note installed!" - exit 1 - fi - fi - - sleep 1 -done -- cgit v1.2.3-70-g09d2 From c87d5e3ec45f1d6b3ee5a72cb6a387186147cb2f Mon Sep 17 00:00:00 2001 From: David Runge Date: Wed, 19 Dec 2018 19:01:35 +0100 Subject: bin/realtime-suggestions: Now upstreamed ( https://github.com/linuxaudio/realtime-suggestions ). --- bin/realtime-suggestions | 274 ----------------------------------------------- 1 file changed, 274 deletions(-) delete mode 100755 bin/realtime-suggestions (limited to 'bin') diff --git a/bin/realtime-suggestions b/bin/realtime-suggestions deleted file mode 100755 index c26055d..0000000 --- a/bin/realtime-suggestions +++ /dev/null @@ -1,274 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -warning="WARNING:" -change="CHANGE:" -info="INFO:" - -kernel_release="" -kernel_config="" - -sysctl_ref="(see \`man 5 sysctl.conf\`, \`man 5 sysctl.d\` or \`man 8 sysctl\` for reference)" - -check_root() { - if [ "$(id -u)" -eq 0 ]; then - echo "Use this script as an unprivileged user." - exit 1 - fi -} - -check_kernel_name() { - if [[ "$(uname -s)" != *Linux* ]]; then - echo "This script needs to be run on a Linux system." - exit 1 - fi -} - -get_kernel_config_location() { - local default_location="/proc/config.gz" - local boot_location="/boot/config-${kernel_release}" - if [ -r "${default_location}" ]; then - echo "${default_location}" - return - elif [ -r "${boot_location}" ]; then - echo "${boot_location}" - return - else - echo "" - return - fi -} - -kernel_config_has() { - local config="$1" - local grep_cmd="zgrep" - if [[ "${kernel_config}" != *.gz ]]; then - grep_cmd="grep" - fi - if $grep_cmd -q "$config" "$kernel_config"; then - return 0 - else - return 1 - fi -} - -kernel_cmdline_has() { - local search="$1" - if ! grep -q "${search}" /proc/cmdline; then - return 1 - else - return 0 - fi -} - -check_virtualization() { - local virt_type="" - if command -v systemd-detect-virt >/dev/null 2>&1; then - set +e - virt_type=$(systemd-detect-virt) - set -e - if systemd-detect-virt -q; then - echo "$change Running in a virtual machine or container (type: ${virt_type}). This is not recommended!" - fi - else - echo "$warning Unable to detect if in a virtual machine." - fi -} - -check_filesystems() { - local mount_points=() - local mount_point_data=() - local what="" - local where="" - local type="" - local options="" - mapfile -t mount_points < <( mount |grep -E "^/dev" ) - for mount_point in "${mount_points[@]}"; do - mapfile -d " " -t mount_point_data < <( echo "${mount_point}" ) - what="${mount_point_data[0]}" - where="${mount_point_data[2]}" - type="${mount_point_data[4]}" - options="${mount_point_data[5]}" - if [[ "$where" != /boot* ]]; then - if [[ "$options" != *relatime* ]] && [[ "$options" != *noatime* ]]; then - echo "$change $what mounted on $where (type $type) should use the relatime mount option for performance." - fi - if [[ "$type" == *fuse* ]] || [[ "$type" == *reiserfs* ]] || [[ "$type" == *vfat* ]]; then - echo "$info $what mounted on $where (type $type) is not a good filesystem for large files or realtime use." - fi - fi - done -} - -check_groups() { - local groups="" - groups=$(groups) - if [[ "$groups" != *audio* ]]; then - echo "$info Consider adding your user to the audio group. On some distributions it's used for elevated resource limits." - fi - if [[ "$groups" != *realtime* ]]; then - echo "$info Consider adding your user to the realtime group. On some distributions it's used for elevated resource limits." - fi -} - -check_ulimits() { - local limits_ref="(see \`man limits.conf\` for reference)" - if [[ "$(ulimit -t)" != "unlimited" ]]; then - echo "$change The CPU limit for your user is not unlimited $limits_ref." - fi - if [[ "$(ulimit -l)" != "unlimited" ]]; then - echo "$change The locked-in-memory limit for your user is not unlimited $limits_ref." - fi - if [ "$(ulimit -r)" -le 50 ]; then - echo "$change The maximum rt priority for your user ($(ulimit -r)) is very low. Consider increasing it up to 98 $limits_ref." - fi -} - -check_vm_swappiness() { - local minimum=10 - local proc_file="/proc/sys/vm/swappiness" - if [ "$(cat "$proc_file")" -gt $minimum ]; then - echo "$info Consider decreasing 'vm.swappiness<=$minimum' to prevent early write to swap $sysctl_ref." - fi -} - -check_max_user_watches() { - local minimum=524288 - local proc_file="/proc/sys/fs/inotify/max_user_watches" - if [ "$(cat "$proc_file")" -lt $minimum ]; then - echo "$change Consider increasing 'fs.inotify.max_user_watches>$minimum' (default) - the maximum amount of files inotify can watch $sysctl_ref." - fi -} - -check_cpu_governor() { - local policy_dir="/sys/devices/system/cpu/cpufreq/" - local cpupower_ref="(see \`man cpupower\` for reference)" - local governor="" - local policy_no="" - local cpu_no="" - if [ -d "${policy_dir}/policy0" ]; then - for governor_file in /sys/devices/system/cpu/cpufreq/policy*/scaling_governor; do - governor="$(cat "$governor_file")" - policy_no="$(echo "$governor_file"| cut -d'/' -f7)" - cpu_no="${policy_no//policy}" - if [[ "$governor" != "performance" ]]; then - echo "$change CPU $cpu_no has governor $governor set. Set it to 'performance' $cpupower_ref." - fi - done - else - echo "$warning Unable to detect any CPU governor on your machine. ${policy_dir} is empty!" - fi -} - -check_config_high_res_timers() { - local config="CONFIG_HIGH_RES_TIMERS=y" - local config_ref="(see \`man 7 time\` for reference)" - if ! kernel_config_has "$config"; then - echo "$change CONFIG_HIGH_RES_TIMERS needs to be activated for your kernel $config_ref." - fi -} - -check_config_no_hz() { - local configs=( 'CONFIG_NO_HZ_COMMON=y' 'CONFIG_NO_HZ_FULL=y' 'CONFIG_NO_HZ=y') - local config_ref="(see https://elinux.org/Kernel_Timer_Systems#Dynamic_ticks for reference)" - for config in "${configs[@]}"; do - if ! kernel_config_has "$config"; then - echo "$change $config needs to be set for your kernel for 'dynamic ticks' support $config_ref." - fi - done -} - -check_config_preempt_rt() { - local configs=( 'CONFIG_PREEMPT_RT=y' 'CONFIG_PREEMPT_RT_FULL=y' ) - local config_ref="(see https://wiki.linuxfoundation.org/realtime for reference)" - if ! kernel_config_has "${configs[0]}" && ! kernel_config_has "${configs[1]}"; then - echo "$change The PREEMPT_RT patch set (${configs[*]}) is not available on your kernel $config_ref." - fi -} - -check_config_irq_forced_threading() { - local configs=( 'CONFIG_IRQ_FORCED_THREADING=y' 'CONFIG_PREEMPT=y' ) - local config_ref="(see https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html for reference)" - if ! kernel_config_has "${configs[0]}"; then - if kernel_config_has "${configs[1]}" && ! kernel_cmdline_has "threadirqs"; then - echo "$change Without ${configs[0]} but with ${configs[1]} support on your kernel, you can still use the threadirqs kernel parameter $config_ref." - else - echo "$change Your kernel neither supports ${configs[0]} nor ${configs[1]}." - fi - fi -} - -check_legacy_timers() { - local hpet_file="/dev/hpet" - local rtc_file="/dev/rtc0" - local hpet_ref="(see https://wiki.linuxaudio.org/wiki/system_configuration#timers for reference)" - if [ ! -w "$hpet_file" ]; then - echo "$info $hpet_file is not writable by your user. Some legacy software requires it $hpet_ref." - fi - if [ ! -w "$rtc_file" ]; then - echo "$info $rtc_file is not writable by your user. Some legacy software requires it $hpet_ref." - fi -} - -check_cpu_dma_latency() { - local dev_file="/dev/cpu_dma_latency" - if [ ! -w "$dev_file" ]; then - echo "$change $dev_file needs to be writable by your user to prevent deep CPU sleep states." - fi -} - -check_coupled_interrupts() { - local interrupts=() - local interrupt_delim=", " - local interrupt_number="" - local interrupt_ref="(see \`cat /proc/interrupts\` for more and consider using rtirq)" - mapfile -t interrupts < <( cat /proc/interrupts ) - for interrupt_line in "${interrupts[@]}"; do - interrupt_number="$(echo "$interrupt_line"| cut -d':' -f1)" - if [[ "$interrupt_line" == *"$interrupt_delim"* ]]; then - echo "$change IRQ$interrupt_number has coupled interrupts $interrupt_ref." - fi - done -} - -check_irqbalance() { - if pgrep -i irqbalance >/dev/null 2>&1; then - echo "$change The irqbalance service is running on your system. It might interfere, so consider disabling it." - fi -} - -check_for_useful_tools() { - local tools=( cyclictest htop iostat iotop rtirq schedtool tuna ) - for tool in "${tools[@]}";do - if ! command -v "$tool" >/dev/null 2>&1; then - echo "$info Consider installing and using $tool." - fi - done -} - -check_kernel_name -check_root -check_virtualization -kernel_release=$(uname -r) -kernel_config=$(get_kernel_config_location) -if [ -n "${kernel_config}" ]; then - check_config_high_res_timers - check_config_no_hz - check_config_preempt_rt - check_config_irq_forced_threading -else - echo "$warning The kernel config could not be found or accessed (e.g. /proc/config.gz or below /boot/config-*)." -fi - -check_filesystems -check_groups -check_ulimits -check_max_user_watches -check_legacy_timers -check_vm_swappiness -check_cpu_governor -check_cpu_dma_latency -check_coupled_interrupts -check_irqbalance -check_for_useful_tools -- cgit v1.2.3-70-g09d2 From 324e2d6adff3acc74098b5f1a19e94ba2171917b Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 1 Jan 2019 19:06:07 +0100 Subject: bin/backlight: Adding more thorough description. Adding better help printout. Only print help on -h. Print current brightness in percentage when not giving any parameter. --- bin/backlight | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'bin') diff --git a/bin/backlight b/bin/backlight index ac8a466..be0dadf 100755 --- a/bin/backlight +++ b/bin/backlight @@ -1,5 +1,9 @@ #!/usr/bin/env bash -# set backlight through sysfs +# +# Sets backlight through /sys/class/backlight/intel_backlight/brightness +# Note: This requires the file to be user-writable! +# Changes can be applied either by (positive or negative) relative increment +# [-i] or as an absolute value [-s] (in percentage). set -euo pipefail @@ -70,8 +74,8 @@ set_brightness() { } print_help() { - echo -e "Usage:\n $0 -d \n or $0 -i " - exit 1 + echo -e "Usage: $0 [-i ] [-s ]" + exit 0 } if [ ${#@} -gt 0 ]; then @@ -93,7 +97,8 @@ if [ ${#@} -gt 0 ]; then esac done else - print_help + echo "$current_brightness_percentage" + exit 0 fi set_brightness -- cgit v1.2.3-70-g09d2