mirror of
https://github.com/ebrandi/FDD-book.git
synced 2026-12-06 00:23:30 +00:00
Organize companion code and materials by book part: part-01/ Foundations part-02/ Kernel & driver fundamentals part-03/ Character & block devices part-04/ Networking & storage part-05/ Buses & advanced topics part-06/ Debugging & performance part-07/ Real-world drivers appendices/ Supplementary material README.md Overview and build instructions
57 lines
1.5 KiB
Bash
Executable file
57 lines
1.5 KiB
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# run_tc_bench.sh - rotate kern.timecounter.hardware through every
|
|
# available source and run tc_bench under each.
|
|
#
|
|
# Must be run as root. Restores the original timecounter selection
|
|
# on exit.
|
|
#
|
|
# Companion to Appendix F of "FreeBSD Device Drivers: From First
|
|
# Steps to Kernel Mastery".
|
|
|
|
set -eu
|
|
|
|
if [ "$(id -u)" -ne 0 ]; then
|
|
echo "error: must run as root (kern.timecounter.hardware is root-writable)" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -x ./tc_bench ]; then
|
|
echo "error: ./tc_bench not found; run 'make' first" >&2
|
|
exit 1
|
|
fi
|
|
|
|
original=$(sysctl -n kern.timecounter.hardware)
|
|
choices=$(sysctl -n kern.timecounter.choice)
|
|
|
|
cleanup() {
|
|
sysctl "kern.timecounter.hardware=${original}" >/dev/null 2>&1 || true
|
|
}
|
|
trap cleanup EXIT INT TERM
|
|
|
|
echo "# host: $(hostname)"
|
|
echo "# uname: $(uname -rmp)"
|
|
echo "# kern.timecounter.choice: ${choices}"
|
|
echo "# original kern.timecounter.hardware: ${original}"
|
|
echo ""
|
|
|
|
# kern.timecounter.choice is a space-separated list of "name(quality)"
|
|
# entries. Extract just the names.
|
|
for entry in ${choices}; do
|
|
name=$(echo "${entry}" | sed 's/(.*//')
|
|
|
|
# Try to select this timecounter; if the kernel refuses (because
|
|
# the hardware is not actually usable right now), skip it.
|
|
if ! sysctl "kern.timecounter.hardware=${name}" >/dev/null 2>&1; then
|
|
echo "# ${name}: could not select, skipping"
|
|
continue
|
|
fi
|
|
|
|
# Give the kernel a moment to settle.
|
|
sleep 1
|
|
echo "=== timecounter: ${name} ==="
|
|
./tc_bench
|
|
echo ""
|
|
done
|
|
|
|
echo "# restored kern.timecounter.hardware to ${original}"
|