Warning: That file was not part of the compilation database. It may have many parsing errors.

1/* Copyright (C) 2006-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 2006.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#include <errno.h>
20#include <pthread.h>
21#include <sched.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <unistd.h>
26#include <sys/syscall.h>
27
28/* This test is Linux specific. */
29#define CHECK_TPP_PRIORITY(normal, boosted) \
30 do \
31 { \
32 pid_t tid = syscall (__NR_gettid); \
33 \
34 struct sched_param cep_sp; \
35 int cep_policy; \
36 if (pthread_getschedparam (pthread_self (), &cep_policy, \
37 &cep_sp) != 0) \
38 { \
39 puts ("getschedparam failed"); \
40 ret = 1; \
41 } \
42 else if (cep_sp.sched_priority != (normal)) \
43 { \
44 printf ("unexpected priority %d != %d\n", \
45 cep_sp.sched_priority, (normal)); \
46 } \
47 if (syscall (__NR_sched_getparam, tid, &cep_sp) == 0 \
48 && cep_sp.sched_priority != (boosted)) \
49 { \
50 printf ("unexpected boosted priority %d != %d\n", \
51 cep_sp.sched_priority, (boosted)); \
52 ret = 1; \
53 } \
54 } \
55 while (0)
56
57int fifo_min, fifo_max;
58
59void
60init_tpp_test (void)
61{
62 fifo_min = sched_get_priority_min (SCHED_FIFO);
63 if (fifo_min < 0)
64 {
65 printf ("couldn't get min priority for SCHED_FIFO: %m\n");
66 exit (1);
67 }
68
69 fifo_max = sched_get_priority_max (SCHED_FIFO);
70 if (fifo_max < 0)
71 {
72 printf ("couldn't get max priority for SCHED_FIFO: %m\n");
73 exit (1);
74 }
75
76 if (fifo_min > 4 || fifo_max < 10)
77 {
78 printf ("%d..%d SCHED_FIFO priority interval not suitable for this test\n",
79 fifo_min, fifo_max);
80 exit (0);
81 }
82
83 struct sched_param sp;
84 memset (&sp, 0, sizeof (sp));
85 sp.sched_priority = 4;
86 int e = pthread_setschedparam (pthread_self (), SCHED_FIFO, &sp);
87 if (e != 0)
88 {
89 errno = e;
90 printf ("cannot set scheduling params: %m\n");
91 exit (0);
92 }
93}
94

Warning: That file was not part of the compilation database. It may have many parsing errors.