Skip to content

Commit

Permalink
Add helper scripts in debug mode
Browse files Browse the repository at this point in the history
Signed-off-by: Samuli Leivo <samuli.leivo@unikie.com>
  • Loading branch information
leivos-unikie authored and brianmcgillion committed May 24, 2024
1 parent 39f59d6 commit 7546010
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 0 deletions.
12 changes: 12 additions & 0 deletions modules/common/development/debug-tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
...
}: let
cfg = config.ghaf.development.debug.tools;

rm-linux-bootmgrs = pkgs.callPackage ./scripts/rm_linux_bootmgr_entries.nix {};
perf-test-script = pkgs.callPackage ./scripts/perf_test_icicle_kit.nix {};
sysbench-test-script = pkgs.callPackage ./scripts/sysbench_test.nix {};
sysbench-fileio-test-script = pkgs.callPackage ./scripts/sysbench_fileio_test.nix {};
nvpmodel-check = pkgs.callPackage ./scripts/nvpmodel_check.nix {};

inherit (lib) mkEnableOption mkIf;
in {
options.ghaf.development.debug.tools = {
Expand Down Expand Up @@ -51,6 +58,11 @@ in {
# Match perf version with kernel.
[
config.boot.kernelPackages.perf
perf-test-script
sysbench-test-script
sysbench-fileio-test-script
nvpmodel-check
rm-linux-bootmgrs
]
# TODO Can this be changed to platformPkgs to filter ?
# LuaJIT (which is sysbench dependency) not available on RISC-V
Expand Down
41 changes: 41 additions & 0 deletions modules/common/development/scripts/nvpmodel_check.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{
writeShellApplication,
lib,
...
}:
writeShellApplication {
name = "nvpmodel-check";
text = ''
# Since performance depends heavily on power mode it should be checked before performance testing.
# This integer is given with the command, e.g. 'nvpmodel-check 3'
ExpectedPowerModeNo="''$1"
if hostname | grep -qw "ghaf-host"; then
if nvpmodel | grep -q "command not found"; then
echo -e "nvpmodel not available\ŋ"
else
echo -e "''$(nvpmodel -q)\n"
ModeNo=''$(nvpmodel -q | awk -F: 'NR==2 {print ''$1}')
if [ "''$ModeNo" -eq "''$ExpectedPowerModeNo" ]; then
echo "Power mode check ok: ''${ModeNo}"
exit 0
else
echo "Unexpected power mode detected: ''${ModeNo}"
fi
fi
else
echo -e "\nVirtual environment detected. Power mode cannot be checked."
fi
exit 1
'';
meta = with lib; {
description = "
Script for checking power mode of an Orin AGX/NX target.
If executed in correct environment (ghaf-host) it gives return code 0 when the power mode number is as expected.
Otherwise the return code is 1.
";
};
}
29 changes: 29 additions & 0 deletions modules/common/development/scripts/perf_test_icicle_kit.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{
writeShellApplication,
lib,
...
}:
writeShellApplication {
name = "perf-test-icicle-kit";
text = ''
time {
perf bench sched messaging;
perf bench sched pipe -l 50000;
perf bench syscall basic;
perf bench mem memcpy;
perf bench mem memset;
perf bench mem find_bit -i 5 -j 1000;
perf bench numa mem -p 1 -t 1 -P 1024 -C 0 -M 0 -s 5 -zZq --thp 1 --no-data_rand_walk;
perf bench futex all;
perf bench epoll wait;
perf bench epoll ctl;
perf bench internals synthesize -i 1000;
perf bench internals kallsyms-parse -i 10;
} | tee -a perf_results_YYYY-MM-DD_BUILDER-BuildID_SDorEMMC
'';
meta = with lib; {
description = "Perf test script customized for measuring ghaf performance on Microchip Icicle Kit target";
};
}
19 changes: 19 additions & 0 deletions modules/common/development/scripts/rm_linux_bootmgr_entries.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{
writeShellApplication,
lib,
...
}:
writeShellApplication {
name = "rm-linux-bootmgrs";
text = ''
for id in ''$(efibootmgr | grep Linux | awk 'NR > 0 {print ''$1}' | cut -c 5-8)
do
sudo efibootmgr -q -b "''${id}" -B
done
'';
meta = with lib; {
description = "Helper script for removing all Linux Boot Manager entries from UEFI Boot order list";
};
}
53 changes: 53 additions & 0 deletions modules/common/development/scripts/sysbench_fileio_test.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{
writeShellApplication,
lib,
...
}:
writeShellApplication {
name = "sysbench-fileio-test";
text = ''
# Test set to be run with sysbench
# These variable needs to be given on the command line. For example: sysbench-fileio-test 20
THREADS="''$1"
# Create a directory for the results
RESULT_DIR="sysbench_results"
echo -e "\nCreating directory for test results:\n./''$RESULT_DIR"
mkdir -p ''$RESULT_DIR
# Create test_info file with system information
echo -e "\nSaving information about test environment to ./''$RESULT_DIR/test_info\n"
echo -e "''$(lscpu)" "\n\n" "''$(free)" "\n\n" "''$(df)" "\n\n" >> ./''$RESULT_DIR/test_info
echo -e "\nHost: ''$(hostname)\n" | tee -a ./''$RESULT_DIR/test_info
# Calculate total memory in kB and set FILE_TOTAL_SIZE 4GB higher than the total memory
TOTAL_MEM_kB=''$(free | awk -F: 'NR==2 {print ''$2}' | awk '{print ''$1}')
FILE_TOTAL_SIZE_kB=''$((TOTAL_MEM_kB + 4000000))
# Read available disk space in kB and check for sufficient disk space
AVAILABLE_DISK_SPACE_kB=''$(df | grep -w "/" | awk '{print ''$4}')
if [ ''$((FILE_TOTAL_SIZE_kB + FILE_TOTAL_SIZE_kB / 10)) -gt "''$AVAILABLE_DISK_SPACE_kB" ]; then
echo -e "\nInsufficient disk space for fileio test." | tee -a ./''$RESULT_DIR/test_info
exit 1
fi
echo -e "\nDetected available total memory ''${TOTAL_MEM_kB} kB." | tee -a ./''$RESULT_DIR/test_info
echo -e "\nDetected available disk space ''${AVAILABLE_DISK_SPACE_kB} kB." | tee -a ./''$RESULT_DIR/test_info
echo -e "\nStarting fileio test with FILE_TOTAL_SIZE=''${FILE_TOTAL_SIZE_kB} kB." | tee -a ./''$RESULT_DIR/test_info
# Execute sysbench fileio tests if the checks passed
sysbench fileio --file-total-size=''${FILE_TOTAL_SIZE_kB}K --threads="''${THREADS}" --file-test-mode=seqrd prepare
sysbench fileio --file-total-size=''${FILE_TOTAL_SIZE_kB}K --threads="''${THREADS}" --file-test-mode=seqrd --time=30 run | tee ./''$RESULT_DIR/fileio_rd_report
sysbench fileio cleanup
sysbench fileio --file-total-size=''${FILE_TOTAL_SIZE_kB}K --threads="''${THREADS}" --file-test-mode=seqwr --time=30 run | tee ./''$RESULT_DIR/fileio_wr_report
sysbench fileio cleanup
echo -e "\nTest finished.\n"
'';
meta = with lib; {
description = "Script for sysbench fileio tests";
};
}
50 changes: 50 additions & 0 deletions modules/common/development/scripts/sysbench_test.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{
writeShellApplication,
lib,
...
}:
writeShellApplication {
name = "sysbench-test";
text = ''
# Threads variable needs to be given on the command line.
# For example: ./sysbench_simplified_test 20
THREADS="''$1"
# Create a directory for the results with a timestamp
RESULT_DIR="sysbench_results"
echo -e "\nCreating directory for test results:"
echo "./''$RESULT_DIR"
mkdir -p ''$RESULT_DIR
# Create test_info file with information about the run environment: lscpu, free, df
echo -e "\nSaving information about test environment to ./''$RESULT_DIR/test_info\n"
echo -e "''$(lscpu)" "\n\n" "''$(free)" "\n\n" "''$(df)" "\n\n" >> ./''$RESULT_DIR/test_info
echo -e "\nHost: ''$(hostname)\n" | tee -a ./''$RESULT_DIR/test_info
# cpu tests
echo -e "\nRunning CPU tests...\n"
sysbench cpu --time=10 --threads=1 --cpu-max-prime=20000 run | tee ./''$RESULT_DIR/cpu_1thread_report
if [ "''$THREADS" -gt 1 ]
then
sysbench cpu --time=10 --threads="''${THREADS}" --cpu-max-prime=20000 run | tee ./''$RESULT_DIR/cpu_report
fi
# memory tests
echo -e "\nRunning memory tests...\n"
sysbench memory --time=60 --memory-oper=read --threads=1 run | tee ./''$RESULT_DIR/memory_read_1thread_report
sysbench memory --time=60 --memory-oper=write --threads=1 run | tee ./''$RESULT_DIR/memory_write_1thread_report
if [ "''$THREADS" -gt 1 ]
then
sysbench memory --time=15 --memory-oper=read --threads="''${THREADS}" run | tee ./''$RESULT_DIR/memory_read_report
sysbench memory --time=30 --memory-oper=write --threads="''${THREADS}" run | tee ./''$RESULT_DIR/memory_write_report
fi
echo -e "\nTest finished.\n"
'';
meta = with lib; {
description = "Script for sysbench tests (excluding fileio)";
};
}

0 comments on commit 7546010

Please sign in to comment.