KVM: selftests: Use __GLIBC__, not _GNU_SOURCE, to detect actual glibc
Sean Christopherson
reviewerPATCH 1/1 KVM: selftests: Use __GLIBC__, not _GNU_SOURCE, to detect actual glibc
Use __GLIBC__ in the hardware disable test to detect when selftests are being built/linked against glibc and thus pthread_attr_setaffinity_np() is (hopefully) available. As pointed out by Sashiko and Hisam, _GNU_SOURCE is effectively a "request" macro to enable functionality, whereas __GLIBC__ is an announcement of support and selftests' idiomatic way of guarding code that's specific to glibc.
--- tools/testing/selftests/kvm/hardware_disable_test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/kvm/hardware_disable_test.c +3 -3
@@ -37,7 +37,7 @@ static void *run_vcpu(void *arg)struct kvm_vcpu *vcpu = arg;struct kvm_run *run = vcpu->run; -#ifndef _GNU_SOURCE +#ifndef __GLIBC__kvm_sched_setaffinity (0 ,sizeof (cpu_set_t), &threads_cpu_set);#endif
@@ -51,7 +51,7 @@ static void *sleeping_thread(void *arg) {int fd; -#ifndef _GNU_SOURCE +#ifndef __GLIBC__kvm_sched_setaffinity (0 ,sizeof (cpu_set_t), &threads_cpu_set);#endif
@@ -71,7 +71,7 @@ static void run_test(u32 run)u32 i, j;TEST_ASSERT_EQ (pthread_attr_init (&attr),0 ); -#ifdef _GNU_SOURCE +#ifdef __GLIBC__TEST_ASSERT_EQ (pthread_attr_setaffinity_np (&attr,sizeof (cpu_set_t), &threads_cpu_set),0 );#endif
base-commit: 76671054f9a1ff6abb976583cd8da37650acdc97
Signature · 1 line
2.55.0.860.g4b6b3295ed-goog
Quoted 8 lines · Sean Christopherson
Use
__GLIBC__in the hardware disable test to detect when selftests are being built/linked against glibc and thuspthread_attr_setaffinity_np()is (hopefully) available. As pointed out by Sashiko and Hisam,_GNU_SOURCEis effectively a "request" macro to enable functionality, whereas__GLIBC__is an announcement of support and selftests' idiomatic way of guarding code that's specific to glibc.[...]
Applied to kvm-x86 fixes, thanks!
[1/1] KVM: selftests: Use __GLIBC__, not _GNU_SOURCE, to detect actual glibc
https://github.com/kvm-x86/linux/commit/f13368e0acff