|
Packit |
6c4009 |
/* Copyright (C) 2006-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
Contributed by Jakub Jelinek <jakub@redhat.com>, 2006.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
#include <pthread.h>
|
|
Packit |
6c4009 |
#include <sched.h>
|
|
Packit |
6c4009 |
#include <stdio.h>
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
#include <string.h>
|
|
Packit |
6c4009 |
#include <unistd.h>
|
|
Packit |
6c4009 |
#include <sys/syscall.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* This test is Linux specific. */
|
|
Packit |
6c4009 |
#define CHECK_TPP_PRIORITY(normal, boosted) \
|
|
Packit |
6c4009 |
do \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
pid_t tid = syscall (__NR_gettid); \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
struct sched_param cep_sp; \
|
|
Packit |
6c4009 |
int cep_policy; \
|
|
Packit |
6c4009 |
if (pthread_getschedparam (pthread_self (), &cep_policy, \
|
|
Packit |
6c4009 |
&cep_sp) != 0) \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
puts ("getschedparam failed"); \
|
|
Packit |
6c4009 |
ret = 1; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
else if (cep_sp.sched_priority != (normal)) \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
printf ("unexpected priority %d != %d\n", \
|
|
Packit |
6c4009 |
cep_sp.sched_priority, (normal)); \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
if (syscall (__NR_sched_getparam, tid, &cep_sp) == 0 \
|
|
Packit |
6c4009 |
&& cep_sp.sched_priority != (boosted)) \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
printf ("unexpected boosted priority %d != %d\n", \
|
|
Packit |
6c4009 |
cep_sp.sched_priority, (boosted)); \
|
|
Packit |
6c4009 |
ret = 1; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
while (0)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int fifo_min, fifo_max;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
void
|
|
Packit |
6c4009 |
init_tpp_test (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
fifo_min = sched_get_priority_min (SCHED_FIFO);
|
|
Packit |
6c4009 |
if (fifo_min < 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("couldn't get min priority for SCHED_FIFO: %m\n");
|
|
Packit |
6c4009 |
exit (1);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
fifo_max = sched_get_priority_max (SCHED_FIFO);
|
|
Packit |
6c4009 |
if (fifo_max < 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("couldn't get max priority for SCHED_FIFO: %m\n");
|
|
Packit |
6c4009 |
exit (1);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (fifo_min > 4 || fifo_max < 10)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("%d..%d SCHED_FIFO priority interval not suitable for this test\n",
|
|
Packit |
6c4009 |
fifo_min, fifo_max);
|
|
Packit |
6c4009 |
exit (0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
struct sched_param sp;
|
|
Packit |
6c4009 |
memset (&sp, 0, sizeof (sp));
|
|
Packit |
6c4009 |
sp.sched_priority = 4;
|
|
Packit |
6c4009 |
int e = pthread_setschedparam (pthread_self (), SCHED_FIFO, &sp);
|
|
Packit |
6c4009 |
if (e != 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
errno = e;
|
|
Packit |
6c4009 |
printf ("cannot set scheduling params: %m\n");
|
|
Packit |
6c4009 |
exit (0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|