benchmarks/gem_syslatency: Guard setaffinity_np

pthread_setaffinity_np is a GNU extensions, so add some __USE_GNU
ifdeffry and hope for the best if unavailable.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson 2016-03-10 12:25:59 +00:00
parent 778f0796e8
commit 544ba6ca88

View File

@ -52,29 +52,14 @@ static volatile int done;
struct gem_busyspin {
pthread_t thread;
int cpu;
unsigned long count;
};
struct sys_wait {
pthread_t thread;
int cpu;
struct igt_mean mean;
};
static void bind_cpu(pthread_t thread, int cpu)
{
cpu_set_t mask;
if (cpu == -1)
return;
CPU_ZERO(&mask);
CPU_SET(cpu, &mask);
pthread_setaffinity_np(thread, sizeof(mask), &mask);
}
static void force_low_latency(void)
{
int32_t target = 0;
@ -115,8 +100,6 @@ static void *gem_busyspin(void *arg)
unsigned engine;
int fd;
bind_cpu(bs->thread, bs->cpu);
fd = drm_open_driver(DRIVER_INTEL);
nengine = 0;
@ -169,8 +152,6 @@ static void *sys_wait(void *arg)
struct timespec now;
#define SIG SIGRTMIN
bind_cpu(w->thread, w->cpu);
sigemptyset(&mask);
sigaddset(&mask, SIG);
sigprocmask(SIG_SETMASK, &mask, NULL);
@ -206,6 +187,21 @@ static void *sys_wait(void *arg)
return NULL;
}
static void bind_cpu(pthread_attr_t *attr, int cpu)
{
#ifdef __USE_GNU
cpu_set_t mask;
if (cpu == -1)
return;
CPU_ZERO(&mask);
CPU_SET(cpu, &mask);
pthread_attr_setaffinity_np(attr, sizeof(mask), &mask);
#endif
}
static void rtprio(pthread_attr_t *attr, int prio)
{
#ifdef PTHREAD_EXPLICIT_SCHED
@ -276,10 +272,11 @@ int main(int argc, char **argv)
min = min_measurement_error();
busy = calloc(ncpus, sizeof(*busy));
pthread_attr_init(&attr);
if (enable_gem_sysbusy) {
for (n = 0; n < ncpus; n++) {
busy[n].cpu = n;
pthread_create(&busy[n].thread, NULL,
bind_cpu(&attr, n);
pthread_create(&busy[n].thread, &attr,
gem_busyspin, &busy[n]);
}
}
@ -288,8 +285,8 @@ int main(int argc, char **argv)
pthread_attr_init(&attr);
rtprio(&attr, 99);
for (n = 0; n < ncpus; n++) {
wait[n].cpu = n;
igt_mean_init(&wait[n].mean);
bind_cpu(&attr, n);
pthread_create(&wait[n].thread, &attr, sys_wait, &wait[n]);
}