epicsMutexPriorityInversionTest.c: check __GLIBC_PREREQ(2,4) when compiling

(non-portable) CPU-affinity extensions only available in glibc 2.4 and
  higher.
This commit is contained in:
Straumann Till
2020-08-19 12:54:28 +02:00
committed by Dirk Zimoch
parent 90f1ac3676
commit 07c5ad5d5a

View File

@@ -1,6 +1,8 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <features.h>
#include <sched.h>
#include <epicsThread.h>
#include <epicsEvent.h>
@@ -16,6 +18,12 @@
#define SPIN_SECS 3000000
#if defined(__GLIBC__) && defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2,4)
#define HAVE_CPU_AFFINITY
#else
#undef HAVE_CPU_AFFINITY
#endif
typedef struct ThreadArg_ {
epicsEventId sync;
epicsEventId done;
@@ -39,11 +47,13 @@ struct timespec now;
*/
static void setThreadAffinity(int cpu)
{
#ifdef HAVE_CPU_AFFINITY
cpu_set_t cset;
CPU_ZERO( &cset );
CPU_SET( cpu, &cset );
testOk1 ( 0 == pthread_setaffinity_np( pthread_self(), sizeof(cset), &cset ) );
#endif
}
/*
@@ -51,6 +61,7 @@ cpu_set_t cset;
*/
static void checkAffinity(int cpu)
{
#ifdef HAVE_CPU_AFFINITY
cpu_set_t cset;
if ( pthread_getaffinity_np( pthread_self(), sizeof(cset), &cset) ) {
@@ -58,6 +69,7 @@ cpu_set_t cset;
return;
}
testOk ( 1 == CPU_COUNT( &cset ) && CPU_ISSET( cpu, &cset ), "Checking CPU affinity mask" );
#endif
}
@@ -212,6 +224,12 @@ struct sched_param p_pri;
testPlan(NUM_TESTS);
#ifndef HAVE_CPU_AFFINITY
#warning "glibc too old for this test: pthread_setaffinity_np() not available..."
testSkip( NUM_TESTS, "glibc too old for this test: pthread_setaffinity_np() not implemented!" );
return testDone();
#endif
p_pri.sched_priority = sched_get_priority_min( SCHED_FIFO );
if ( sched_setscheduler( 0, SCHED_FIFO, &p_pri ) ) {
testDiag("SCHED_FIFO not engaged - maybe you need to be root to run this test?");