Add is_cpu_online() utility function: a wrapper for "/sys/devices/system/cpu/cpu%d/online". Signed-off-by: Ricardo Koller <ricarkol@xxxxxxxxxx> --- tools/testing/selftests/kvm/include/test_util.h | 2 ++ tools/testing/selftests/kvm/lib/test_util.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h index 99e0dcdc923f..14084dc4e152 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -143,4 +143,6 @@ static inline void *align_ptr_up(void *x, size_t size) return (void *)align_up((unsigned long)x, size); } +bool is_cpu_online(int pcpu); + #endif /* SELFTEST_KVM_TEST_UTIL_H */ diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c index 6d23878bbfe1..81950e6b6d10 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -334,3 +334,19 @@ long get_run_delay(void) return val[1]; } + +bool is_cpu_online(int pcpu) +{ + char p[128]; + FILE *fp; + int ret; + + snprintf(p, sizeof(p), "/sys/devices/system/cpu/cpu%d/online", pcpu); + fp = fopen(p, "r"); + if (!fp) + return false; + assert(fscanf(fp, "%d ", &ret) == 1); + fclose(fp); + + return !!ret; +} -- 2.35.1.894.gb6a874cedc-goog