Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/madvise/collect_batch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ while getopts "hd:p:" arg; do
done

# Configure IAA
./enable_kernel_iaa.sh 0 1 ${iaa_devices} 8 2 async
#./enable_kernel_iaa.sh 0 1 ${iaa_devices} 8 2 async
./enable_iaa.sh -d ${iaa_devices} -m async
# Configure zswap and zram.
./enable_zswap.sh
# swap disk can be used instead of zram. However, zram will avoid any disk access overheads
Expand Down
14 changes: 13 additions & 1 deletion tests/madvise/collect_bpftraces.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,19 @@ else
fi

echo ${DBATCH} > /proc/sys/vm/page-cluster || handle_error "Failed to set page-cluster"
sysctl vm.compress-batchsize=${CBATCH} || handle_error "Failed to set compress-batchsize"

# Note: This is a temporary solution as we transition the parameter names.
PARAM_VALUE=$(sysctl -n vm.compress-batchsize 2>/dev/null)
EXIT_CODE=$?
if [ ${EXIT_CODE} -eq 0 ]; then
sysctl vm.compress-batchsize=${CBATCH} || handle_error "Failed to set compress-batchsize"
fi

PARAM_VALUE=$(sysctl -n vm.reclaim-batchsize 2>/dev/null)
EXIT_CODE=$?
if [ ${EXIT_CODE} -eq 0 ]; then
sysctl vm.reclaim-batchsize=${CBATCH} || handle_error "Failed to set compress-batchsize"
fi

# Clear transparent huge pages configuration
echo 'never' > /sys/kernel/mm/transparent_hugepage/hugepages-2048kB/enabled || handle_error "Failed to clear hugepages-2048kB configuration"
Expand Down
121 changes: 93 additions & 28 deletions tests/madvise/collect_single_page.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
#!/usr/bin/bash
#!/bin/bash
#SPDX-License-Identifier: BSD-3-Clause
#Copyright (c) 2025, Intel Corporation
#Copyright (c) 2025, I# If QAT is available in kernel, enable it as well
QAT_ENABLED_IN_KERNEL=$(bpftrace -l 2>/dev/null | grep qat_comp_alg_compress | wc -l)
if [ ${QAT_ENABLED_IN_KERNEL} -gt 0 ]; then
echo "QAT detected in kernel, enabling..."
./enable_qat.sh || handle_error "Failed to enable QAT"
fi


comp_list=()
# Create the compression algorithm list. Keep the alphabetical order for easy reportingoration
#Description: Top level script to collect datapoints for single page (no batching)

# Error handling function
handle_error() {
echo "ERROR: $1" >&2
exit 1
}

# Initialize variables
iaa_devices=4
# Turn on this for preserving the intermediate results
Expand All @@ -27,39 +42,65 @@ done

echo "Number of IAA device: $iaa_devices"

# Check for root privileges
if [ "$(id -u)" -ne 0 ]; then
handle_error "This script requires root privileges. Please run with sudo."
fi

# Configure IAA devices
if [ ${iaa_devices} -gt 0 ]; then
./enable_kernel_iaa.sh 0 1 ${iaa_devices} 8 2 sync
echo "Configuring IAA with $iaa_devices device(s) per socket..."
#./enable_kernel_iaa.sh 0 1 ${iaa_devices} 8 2 sync
./enable_iaa.sh -d ${iaa_devices} -m sync || handle_error "Failed to configure IAA devices"
fi

# Configure zswap and zram.
./enable_zswap.sh
echo "Configuring zswap..."
./enable_zswap.sh || handle_error "Failed to configure zswap"

# swap disk can be used instead of zram. However, zram will avoid any disk access overheads
./enable_zram.sh
echo "Configuring zram..."
./enable_zram.sh || handle_error "Failed to configure zram"

# Check for dataset
if [ ! -f "silesia.tar" ]; then
echo "Dataset silesia.tar not found. Attempting to download..."
wget --no-check-certificate http://wanos.co/assets/silesia.tar || handle_error "Failed to download silesia.tar"
fi

# Install bpftrace if it is not available
if [ ! -f /usr/bin/bpftrace ]; then
echo "Installing bpftrace..."
yum install bpftrace -y || handle_error "Failed to install bpftrace"
if command -v apt-get &> /dev/null; then
apt-get update && apt-get install -y bpftrace || handle_error "Failed to install bpftrace"
elif command -v yum &> /dev/null; then
yum install bpftrace -y || handle_error "Failed to install bpftrace"
else
handle_error "Package manager not found. Please install bpftrace manually."
fi
fi

# If QAT is avaialble in kernel, enable it as well
# If QAT is available in kernel, enable it as well
QAT_ENABLED_IN_KERNEL=`bpftrace -l | grep qat_comp_alg_compress | wc -l`
if [ ${QAT_ENABLED_IN_KERNEL} -gt 0 ]; then
./enable_qat.sh
fi


comp_list=()
# Create the compression algorihm list. Keep the alphabetical order for easy reporting
# Create the compression algorithm list. Keep the alphabetical order for easy reporting
if [ ${iaa_devices} -gt 0 ]; then
comp_list+=("deflate-iaa-canned" "deflate-iaa")
comp_list+=("deflate-iaa")
echo "Added deflate-iaa to compressor list"
fi
comp_list+=("lz4")
if [ ${QAT_ENABLED_IN_KERNEL} -gt 0 ]; then
comp_list+=("qat_deflate")
comp_list+=("qat_deflate")
echo "Added qat_deflate to compressor list"
fi
comp_list+=("zstd" )
comp_list+=("zstd")

echo "Final compressor list: ${comp_list[*]}"


# Other possible values for compressors
Expand All @@ -76,34 +117,56 @@ mthp_list=("4kB")
#mthp_list=("4kB" "16kB" "64kB" "16kB,32kB,64kB")

# clear old logs for a fresh start
echo "Clearing old logs..."
./clear_logs.sh

# Check if zswap module is loaded
if [ ! -d "/sys/module/zswap" ]; then
handle_error "zswap kernel module is not loaded"
fi

for freq in "${freq_list[@]}"; do
for dataset in "${dataset_list[@]}"; do
echo -e "\nData Corpus: ${dataset}\n"
for cbatch in "${cbatch_list[@]}"; do
for dbatch in "${dbatch_list[@]}"; do
for mthp in "${mthp_list[@]}"; do
rm -r run.log
# Remove old run log if it exists
[ -f run.log ] && rm -f run.log

for comp in "${comp_list[@]}"; do
echo "Removing ${comp}_output"
rm -f ${comp}_output
echo $comp > /sys/module/zswap/parameters/compressor
echo "Removing ${comp}_output if it exists"
[ -f "${comp}_output" ] && rm -f "${comp}_output"

echo "Setting compressor to $comp"
echo "$comp" > /sys/module/zswap/parameters/compressor || handle_error "Failed to set compressor to $comp"

echo "Collecting data for $comp at ${freq}MHz, cbatch ${cbatch}, dbatch ${dbatch}, mthp ${mthp}"
./collect_bpftraces.sh -f ${freq} -t ${dataset} -c ${cbatch} -d ${dbatch} -m ${mthp} | tee -a run.log
./collect_bpftraces.sh -f ${freq} -t ${dataset} -c ${cbatch} -d ${dbatch} -m ${mthp} | tee -a run.log ||
handle_error "Failed to collect bpftraces for $comp"
done
./process_bpftraces.py | tee -a run.log
./summarize_single_page.sh run.log | tee -a run.log
mthp_suffix=`echo ${mthp} | tr -d ' ' | tr ',' '_'`
result_dir="result_${freq}_${dataset}_c${cbatch}_d${dbatch}_${mthp_suffix}"
rm -rf ${result_dir}
echo "Processing bpftraces..."
./process_bpftraces.py | tee -a run.log || handle_error "Failed to process bpftraces"

echo "Summarizing results..."
./summarize_single_page.sh run.log | tee -a run.log || handle_error "Failed to summarize results"

mthp_suffix=$(echo ${mthp} | tr -d ' ' | tr ',' '_')
result_dir="result_${freq}_${dataset}_c${cbatch}_d${dbatch}_${mthp_suffix}"

echo "Creating results directory: ${result_dir}"
[ -d "${result_dir}" ] && rm -rf "${result_dir}"
mkdir -p "${result_dir}" || handle_error "Failed to create results directory"

echo "Copying results to ${result_dir}"
mkdir ${result_dir}
cp *_output ${result_dir}
cp *.html ${result_dir}
cp *.xlsx ${result_dir}
cp perf_* ${result_dir}
cp run.log ${result_dir}
# Use for loop to handle case where no files match pattern
for file in *_output *.html *.xlsx perf_* run.log; do
if [ -f "$file" ]; then
cp "$file" "${result_dir}/" || handle_error "Failed to copy $file to results directory"
fi
done

echo "Results saved to ${result_dir}"
done
done
done
Expand All @@ -114,10 +177,12 @@ done

# Clear intermediate logs as needed
if [ "${preserve_logs}" == "1" ]; then
echo "Saving temporary logs for debugging purposes"
echo "Saving temporary logs for debugging purposes"
else
echo "Removing all the temporary logs"
./clear_logs.sh
fi

echo "Collection completed successfully!"


168 changes: 168 additions & 0 deletions tests/madvise/enable_iaa.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#!/usr/bin/env bash
#SPDX-License-Identifier: BSD-3-Clause
#Copyright (c) 2025, Intel Corporation
#Description: Configure IAA devices

VERIFY_COMPRESS_PATH="/sys/bus/dsa/drivers/crypto/verify_compress"

iax_dev_id="0cfe"
num_iaa=$(lspci -d:${iax_dev_id} | wc -l)
sockets=$(lscpu | grep Socket | awk '{print $2}')
echo "Found ${num_iaa} instances in ${sockets} sockets(s)"

# The same number of devices will be configured in each socket, if there are more than one socket
# Normalize with respect to the number of sockets
device_num_per_socket=$(( num_iaa/sockets ))
num_iaa_per_socket=$(( num_iaa / sockets ))

iaa_wqs=2
verbose=0
iaa_engines=8
mode="dedicated"
wq_type="kernel"
iaa_crypto_mode="async"
verify_compress=0


# Function to handle errors
handle_error() {
echo "Error: $1"
exit 1
}

# Process arguments

while getopts "d:hm:q:vD" opt; do
case $opt in
d)
device_num_per_socket=$OPTARG
;;
m)
iaa_crypto_mode=$OPTARG
;;
q)
iaa_wqs=$OPTARG
;;
D)
verbose=1
;;
v)
verify_compress=1
;;
h)
echo "Usage: $0 [-d <device_count>][-q <wq_per_device>][-v]"
echo " -d - number of devices"
echo " -q - number of WQs per device"
echo " -v - verbose mode"
echo " -h - help"
exit
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit
;;
esac
done

LOG="configure_iaa.log"

# Update wq_size based on number of wqs
wq_size=$(( 128 / iaa_wqs ))

# Take care of the enumeration, if DSA is enabled.
dsa=`lspci | grep -c 0b25`
#set first,step counters to correctly enumerate iax devices based on whether running on guest or host with or without dsa
first=0
step=1
[[ $dsa -gt 0 && -d /sys/bus/dsa/devices/dsa0 ]] && first=1 && step=2
echo "first index: ${first}, step: ${step}"


#
# Switch to software compressors and disable IAAs to have a clean start
#
COMPRESSOR=/sys/module/zswap/parameters/compressor
last_comp=`cat ${COMPRESSOR}`
echo lzo > ${COMPRESSOR}

echo "Disable IAA devices before configuring"

for ((i = ${first}; i < ${step} * ${num_iaa}; i += ${step})); do
for ((j = 0; j < ${iaa_wqs}; j += 1)); do
cmd="accel-config disable-wq iax${i}/wq${i}.${j} >& /dev/null"
[[ $verbose == 1 ]] && echo $cmd; eval $cmd
done
cmd="accel-config disable-device iax${i} >& /dev/null"
[[ $verbose == 1 ]] && echo $cmd; eval $cmd
done

rmmod iaa_crypto
modprobe iaa_crypto

# apply crypto parameters
echo $verify_compress > ${VERIFY_COMPRESS_PATH} || handle_error "did not change verify_compress"
# Note: This is a temporary solution for during the kernel transition.
if [ -f /sys/bus/dsa/drivers/crypto/g_comp_wqs_per_iaa ];then
echo 1 > /sys/bus/dsa/drivers/crypto/g_comp_wqs_per_iaa || handle_error "did not set g_comp_wqs_per_iaa"
elif [ -f /sys/bus/dsa/drivers/crypto/g_wqs_per_iaa ];then
echo 1 > /sys/bus/dsa/drivers/crypto/g_wqs_per_iaa || handle_error "did not set g_wqs_per_iaa"
fi
if [ -f /sys/bus/dsa/drivers/crypto/g_consec_descs_per_gwq ];then
echo 1 > /sys/bus/dsa/drivers/crypto/g_consec_descs_per_gwq || handle_error "did not set g_consec_descs_per_gwq"
fi
echo ${iaa_crypto_mode} > /sys/bus/dsa/drivers/crypto/sync_mode || handle_error "could not set sync_mode"



echo "Configuring ${device_num_per_socket} device(s) out of $num_iaa_per_socket per socket"
if [ "${device_num_per_socket}" -le "${num_iaa_per_socket}" ]; then
echo "Configuring all devices"
start=${first}
end=$(( ${step} * ${device_num_per_socket} ))
else
echo "ERROR: Not enough devices"
exit
fi


#
# enable all iax devices and wqs
#
for (( socket = 0; socket < ${sockets}; socket += 1 )); do
for ((i = ${start}; i < ${end}; i += ${step})); do

echo "Configuring iaa$i on socket ${socket}"

for ((j = 0; j < ${iaa_engines}; j += 1)); do
cmd="accel-config config-engine iax${i}/engine${i}.${j} --group-id=0"
[[ $verbose == 1 ]] && echo $cmd; eval $cmd
done

# Config WQs
for ((j = 0; j < ${iaa_wqs}; j += 1)); do
# Config WQ: group 0, priority=10, mode=shared, type = kernel name=kernel, driver_name=crypto
cmd="accel-config config-wq iax${i}/wq${i}.${j} -g 0 -s ${wq_size} -p 10 -m ${mode} -y ${wq_type} -n iaa_crypto${i}${j} -d crypto"
[[ $verbose == 1 ]] && echo $cmd; eval $cmd
done

# Enable Device and WQs
cmd="accel-config enable-device iax${i}"
[[ $verbose == 1 ]] && echo $cmd; eval $cmd

for ((j = 0; j < ${iaa_wqs}; j += 1)); do
cmd="accel-config enable-wq iax${i}/wq${i}.${j}"
[[ $verbose == 1 ]] && echo $cmd; eval $cmd
done

done
start=$(( start + ${step} * ${num_iaa_per_socket} ))
end=$(( start + (${step} * ${device_num_per_socket}) ))
done

# Restore the last compressor
echo "$last_comp" > ${COMPRESSOR}

# Check if the configuration is correct
echo "Configured IAA devices:"
accel-config list | grep iax

Loading