tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh
Source file repositories/reference/linux-study-clean/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh- Extension
.sh- Size
- 4234 bytes
- Lines
- 226
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
SYSFS=
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
retval=0
prerequisite()
{
msg="skip all tests:"
if [ $UID != 0 ]; then
echo $msg must be run as root >&2
exit $ksft_skip
fi
taskset -p 01 $$
SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
if [ ! -d "$SYSFS" ]; then
echo $msg sysfs is not mounted >&2
exit $ksft_skip
fi
if ! ls $SYSFS/devices/system/cpu/cpu*/online > /dev/null 2>&1; then
echo $msg cpu hotplug is not supported >&2
exit $ksft_skip
fi
echo "CPU online/offline summary:"
online_cpus=`cat $SYSFS/devices/system/cpu/online`
online_max=${online_cpus##*-}
if [[ "$online_cpus" = "$online_max" ]]; then
echo "$msg: since there is only one cpu: $online_cpus"
exit $ksft_skip
fi
present_cpus=`cat $SYSFS/devices/system/cpu/present`
present_max=${present_cpus##*-}
echo "present_cpus = $present_cpus present_max = $present_max"
echo -e "\t Cpus in online state: $online_cpus"
offline_cpus=`cat $SYSFS/devices/system/cpu/offline`
if [[ "a$offline_cpus" = "a" ]]; then
offline_cpus=0
else
offline_max=${offline_cpus##*-}
fi
echo -e "\t Cpus in offline state: $offline_cpus"
}
#
# list all hot-pluggable CPUs
#
hotpluggable_cpus()
{
local state=${1:-.\*}
for cpu in $SYSFS/devices/system/cpu/cpu*; do
if [ -f $cpu/online ] && grep -q $state $cpu/online; then
echo ${cpu##/*/cpu}
fi
done
}
hotpluggable_offline_cpus()
Annotation
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.