1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2017 Intel Corporation 4# All rights reserved. 5# 6function configure_performance() { 7 echo -n "Placing all CPUs in performance mode..." 8 for governor in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do 9 echo -n performance > $governor 10 done 11 echo "Done" 12 13 if [ -f "/sys/devices/system/cpu/intel_pstate/no_turbo" ]; then 14 echo -n "Disabling Turbo Boost..." 15 echo -n 1 > /sys/devices/system/cpu/intel_pstate/no_turbo 16 echo "Done" 17 fi 18 19 echo -n "Disabling irqbalance service..." 20 service irqbalance stop 2> /dev/null 21 echo "Done" 22 23 echo -n "Moving all interrupts off of core 0..." 24 count=$(($(nproc) / 4)) 25 cpumask="e" 26 for ((i = 1; i < count; i++)); do 27 if [ $((i % 8)) -eq 0 ]; then 28 cpumask=",$cpumask" 29 fi 30 cpumask="f$cpumask" 31 done 32 for file in /proc/irq/*/smp_affinity; do 33 echo "$cpumask" > $file 2> /dev/null 34 done 35 echo "Done" 36 37 echo -n "Configuring kernel blk-mq for NVMe SSDs..." 38 for queue in /sys/block/nvme*n*/queue; do 39 if [ -f "$queue/nomerges" ]; then 40 echo "1" > $queue/nomerges 41 fi 42 43 if [ -f "$queue/io_poll" ]; then 44 echo "1" > $queue/io_poll 45 fi 46 47 if [ -f "$queue/io_poll_delay" ]; then 48 echo "-1" > $queue/io_poll_delay 49 fi 50 done 51 echo "Done" 52} 53 54function reset_performance() { 55 echo -n "Placing all CPUs in powersave mode..." 56 for governor in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do 57 echo -n powersave > $governor 58 done 59 echo "Done" 60 61 if [ -f "/sys/devices/system/cpu/intel_pstate/no_turbo" ]; then 62 echo -n "Enabling Turbo Boost..." 63 echo -n 0 > /sys/devices/system/cpu/intel_pstate/no_turbo 64 echo "Done" 65 fi 66 67 echo -n "Enabling irqbalance service..." 68 service irqbalance start 2> /dev/null 69 echo "Done" 70} 71 72if [ "$1" = "reset" ]; then 73 reset_performance 74else 75 configure_performance 76fi 77