Skip to content

Commit f0e560c

Browse files
committed
confighz: Add command to build kernel with CONFIG_HZ=1000.
CONFIG_HZ in the kernel is set to 250 Hz by default, but setting it to 1000 Hz instead can resolve timing-related issues. For example, this has been reported by the Connections Museum to fix issues with dial pulsing when using wanpipe.
1 parent 8c959f9 commit f0e560c

3 files changed

Lines changed: 94 additions & 0 deletions

File tree

‎phreaknet.1‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ Generally this command does not need to be used.
7575
To install Asterisk with DAHDI, use the install command and provide the
7676
-d or --dahdi option instead.
7777
.TP
78+
\f[B]wanpipe\f[R]
79+
Install or upgrade wanpipe (only). Generally this command does not need to be used. To install Asterisk with DAHDI and wanpipe, use the install command and provide the -d or --dahdi option instead.
80+
.TP
81+
\f[B]confighz\f[R]
82+
Build kernel with CONFIG_HZ set to 1000 Hz (can resolve timing-related issues)
83+
.TP
7884
\f[B]odbc\f[R]
7985
Install ODBC (Open Database Connector) for MariaDB
8086
.TP

‎phreaknet.1.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ the best Asterisk and DAHDI experience.
7878
**wanpipe**
7979
: Install or upgrade wanpipe (only). Generally this command does not need to be used. To install Asterisk with DAHDI and wanpipe, use the install command and provide the -d or --dahdi option instead.
8080

81+
**confighz**
82+
: Build kernel with CONFIG_HZ set to 1000 Hz (can resolve timing-related issues)
83+
8184
**odbc**
8285
: Install ODBC (Open Database Connector) for MariaDB
8386

‎phreaknet.sh‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ Commands:
555555
experimental Add experimental features to an existing Asterisk source
556556
dahdi Install or upgrade PhreakNet-enhanced DAHDI
557557
wanpipe Install wanpipe
558+
confighz Build kernel with CONFIG_HZ set to 1000 Hz (can resolve timing-related issues, e.g. dial pulsing esp. with wanpipe)
558559
g72x Add G.723.1/G.729 support to an existing installation
559560
odbc Install ODBC (MariaDB)
560561
installts Install Asterisk Test Suite
@@ -4435,6 +4436,90 @@ elif [ "$cmd" = "dahdi" ]; then
44354436
elif [ "$cmd" = "wanpipe" ]; then
44364437
assert_root
44374438
install_wanpipe
4439+
elif [ "$cmd" = "confighz" ]; then
4440+
# https://github.com/torvalds/linux/blob/master/kernel/Kconfig.hz
4441+
confighz=$( grep "^CONFIG_HZ" /boot/config-$(uname -r) | grep "HZ=" | cut -d'=' -f2 | tr -d '\n' )
4442+
if [ $confighz -eq 1000 ]; then
4443+
echog "CONFIG_HZ is currently set to $confighz"
4444+
else
4445+
printf "CONFIG_HZ is currently set to: %s\n" "$confighz"
4446+
echoerr "Rebuilding kernel to set CONFIG_HZ to 1000"
4447+
echoerr "Press ^C now to abort..."
4448+
sleep 5
4449+
if [ "$PAC_MAN" = "apt-get" ]; then
4450+
install_package "linux-source build-essential libncurses-dev bison flex libssl-dev libelf-dev"
4451+
else
4452+
echoerr "Unable to automatically install packages required to compile the kernel, operation may fail..."
4453+
fi
4454+
cd /usr/src
4455+
ksrcdir=$( ls -d */ | grep linux-source- | tail -1 ) # Get the most recent kernel source directory
4456+
if [ ! -d "$ksrcdir" ]; then
4457+
ksrcfile=$( ls linux-source-*.tar.xz | tail -1 )
4458+
if [ -f "$ksrcfile" ]; then
4459+
# It's a file that hasn't been extracted yet
4460+
tar -xvf "$ksrcfile"
4461+
ksrcdir=$( ls -d */ | grep linux-source- | tail -1 ) # Recheck, should have one now
4462+
fi
4463+
fi
4464+
if [ ! -d "$ksrcdir" ]; then
4465+
die "Couldn't find kernel source"
4466+
fi
4467+
cd "$ksrcdir"
4468+
if [ ! -f Kconfig ]; then
4469+
die "Thought $ksrcdir was the kernel source directory, but it's not?"
4470+
fi
4471+
cp /boot/config-$(uname -r) .config
4472+
4473+
# Edit config to change CONFIG_HZ to 1000 Hz.
4474+
# 250 Hz is the default, but it could be something else:
4475+
./scripts/config --file .config --disable "CONFIG_HZ_${confighz}"
4476+
./scripts/config --file .config --enable "CONFIG_HZ_1000"
4477+
./scripts/config --file .config --set-val CONFIG_HZ 1000
4478+
4479+
./scripts/config --file .config --set-str CONFIG_LOCALVERSION "-hz1000"
4480+
./scripts/config --file .config --disable LOCALVERSION_AUTO
4481+
4482+
make olddefconfig # Set new symbols to their default value to avoid interactive prompts
4483+
4484+
newhz=$( grep "^CONFIG_HZ" .config | grep "HZ=" | cut -d'=' -f2 | tr -d '\n' )
4485+
if [ "$newhz" != "1000" ]; then
4486+
die "Failed to set CONFIG_HZ=1000 in .config (still $newhz)"
4487+
fi
4488+
4489+
make -j$(nproc) bindeb-pkg
4490+
4491+
newversion=$( make -s kernelrelease )
4492+
printf "Building kernel version: %s\n" "$newversion"
4493+
kpkg=$( ls -t ../linux-image-${newversion}_*.deb 2>/dev/null | head -1 )
4494+
if [ -z "$kpkg" ]; then
4495+
die "Missing linux-image-${newversion}_*.deb"
4496+
fi
4497+
4498+
# Recompile DAHDI Linux for the new kernel
4499+
DAHDI_LIN_SRC_DIR=`tar -tzf $DAHLIN_SRC_NAME | head -1 | cut -f1 -d"/"`
4500+
if [ -d $AST_SOURCE_PARENT_DIR/$DAHDI_LIN_SRC_DIR ]; then
4501+
cd $AST_SOURCE_PARENT_DIR/$DAHDI_LIN_SRC_DIR
4502+
$AST_MAKE && $AST_MAKE install
4503+
cd "$ksrcdir"
4504+
fi
4505+
4506+
dpkg -i "$kpkg"
4507+
4508+
grubtitle="Advanced options for Debian GNU/Linux>Debian GNU/Linux, with Linux ${newversion}"
4509+
if grep -q "^GRUB_DEFAULT=" /etc/default/grub; then
4510+
sed -i "s|^GRUB_DEFAULT=.*|GRUB_DEFAULT=\"${grubtitle}\"|" /etc/default/grub
4511+
else
4512+
printf 'GRUB_DEFAULT="%s"\n' "$grubtitle" >> /etc/default/grub
4513+
fi
4514+
grub-mkconfig -o /boot/grub/grub.cfg
4515+
printf "Set permanent GRUB default to: %s\n" "$grubtitle"
4516+
4517+
printf "New kernel version: %s\n" "$newversion"
4518+
4519+
builthz=$( grep "^CONFIG_HZ=" /boot/config-${newversion} | cut -d'=' -f2 | tr -d '\n' )
4520+
printf "CONFIG_HZ in the newly installed kernel (%s) is: %s\n" "$newversion" "$builthz"
4521+
echog "Kernel rebuild completed, reboot and rerun 'phreaknet confighz' to verify completion"
4522+
fi
44384523
elif [ "$cmd" = "odbc" ]; then
44394524
assert_root
44404525
install_odbc

0 commit comments

Comments
 (0)