Skip to content

Instantly share code, notes, and snippets.

@iKrishneel
Last active August 25, 2022 01:18
Show Gist options
  • Save iKrishneel/d10013959d5d8ed57488e74ddf627ae8 to your computer and use it in GitHub Desktop.
Save iKrishneel/d10013959d5d8ed57488e74ddf627ae8 to your computer and use it in GitHub Desktop.
realtime_kernal
#/usr/bin/env bash
VERSION=5.13
cd $HOME/ && mkdir rt_kernel && cd rt_kernel
wget -m -np https://cdn.kernel.org/pub/linux/kernel/projects/rt/$VERSION/
cd cdn.kernel.org/pub/linux/kernel/projects/rt/$VERSION/linux-$VERSION
wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-$VERSION.tar.xz
wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-$VERSION.tar.gz
wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-$VERSION.tar.sign
tar -xzf linux-$VERSION.tar.gz
gunzip patch-$VERSION-rt1.patch.gz
cd linux-$VERSION
patch -p < ../patch-$VERSION-rt1.patch
# copy the current boot config (please check the version manually in case of different config)
cp -r /boot/config-$(uname -r) .config
# fix the dep-src
sudo sed -i 's/# deb-src/deb-src/' /etc/apt/sources.list && apt update
sudo apt-get build-dep linux -y
sudo apt-get install -y libncurses-dev flex bison openssl libssl-dev dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf fakeroot
yes '' | make oldconfig
make menuconfig # manual interaction is required here
# check to ensure the config is same in the comment.
make -j `nproc` deb-pkg
sudo dpkg -i ../*.deb
@iKrishneel
Copy link
Author

Check that the setting when running make menuconfig has the following config

# Enable CONFIG_PREEMPT_RT
 -> General Setup
  -> Preemption Model (Fully Preemptible Kernel (Real-Time))
   (X) Fully Preemptible Kernel (Real-Time)

# Enable CONFIG_HIGH_RES_TIMERS
 -> General setup
  -> Timers subsystem
   [*] High Resolution Timer Support

# Enable CONFIG_NO_HZ_FULL
 -> General setup
  -> Timers subsystem
   -> Timer tick handling (Full dynticks system (tickless))
    (X) Full dynticks system (tickless)

# Set CONFIG_HZ_1000 (note: this is no longer in the General Setup menu, go back twice)
 -> Processor type and features
  -> Timer frequency (1000 HZ)
   (X) 1000 HZ

# Set CPU_FREQ_DEFAULT_GOV_PERFORMANCE [=y]
 ->  Power management and ACPI options
  -> CPU Frequency scaling
   -> CPU Frequency scaling (CPU_FREQ [=y])
    -> Default CPUFreq governor (<choice> [=y])
     (X) performance

@yusukeurakami
Copy link

yusukeurakami commented Aug 24, 2022

 #/usr/bin/env bash
 
 VERSION=5.13
 
 function downloadIfNotExists {
     if [ ! -f $1 ]; then
         wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/$1
     fi
     }
 
 if [ ! -d "$HOME/rt_kernel" ]; then
     mkdir $HOME/rt_kernel
 fi
 cd $HOME/rt_kernel
 
 if [ ! -d "cdn.kernel.org" ]; then
     wget -m -np https://cdn.kernel.org/pub/linux/kernel/projects/rt/$VERSION/
 fi
 cd cdn.kernel.org/pub/linux/kernel/projects/rt/$VERSION/
 
 downloadIfNotExists linux-$VERSION.tar.xz
 downloadIfNotExists linux-$VERSION.tar.gz
 downloadIfNotExists linux-$VERSION.tar.sign
 
 tar -xzf linux-$VERSION.tar.gz
 gunzip -f -k patch-$VERSION-rt1.patch.gz
 cd linux-$VERSION
 patch -p1 < ../patch-$VERSION-rt1.patch
 
 # copy the current boot config (please check the version manually in case of different config)
 cp -r /boot/config-$(uname -r) .config
 
 # fix the dep-src
 sudo sed -i 's/# deb-src/deb-src/' /etc/apt/sources.list
 
 sudo apt update && sudo apt-get build-dep linux -y
 sudo apt-get install -y libncurses-dev flex bison openssl libssl-dev dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf fakeroot
 
 yes '' | make oldconfig
 
 # set the ARCH_SUPPORTS_RT default to 'yes' to add the realtime option.
 sed -i '1079s/bool/def_bool\ y/' arch/Kconfig
 
 make menuconfig  # manual interaction is required here
 # check to ensure the config is same in the comment.
 
 yes '' | make -j `nproc` deb-pkg
 
 sudo dpkg -i ../*.deb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment