rt_wrapper.h 3.02 KB
Newer Older
1
/*******************************************************************************
2
    OpenAirInterface
3
    Copyright(c) 1999 - 2014 Eurecom
4

5
6
7
8
    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
9
10


11
12
13
14
    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
15

16
    You should have received a copy of the GNU General Public License
17
18
    along with OpenAirInterface.The full GNU General Public License is
    included in this distribution in the file called "COPYING". If not,
19
    see <http://www.gnu.org/licenses/>.
20

21
22
23
24
   Contact Information
   OpenAirInterface Admin: openair_admin@eurecom.fr
   OpenAirInterface Tech : openair_tech@eurecom.fr
   OpenAirInterface Dev  : openair4g-devel@eurecom.fr
25

26
   Address      : Eurecom, Compus SophiaTech 450, route des chappes, 06451 Biot, France.
27

28
 *******************************************************************************/
29
30

/*! \file rt_wrapper.h
31
32
* \brief provides a wrapper for the timing function for real-time opeartions depending on weather RTAI is used or not. It also implements an API for the SCHED_DEADLINE kernel scheduler.
* \author F. Kaltenberger and Navid Nikaein
33
34
35
* \date 2013
* \version 0.1
* \company Eurecom
36
* \email: florian.kaltenberger@eurecom.fr, navid.nikaein@eurecom.fr
37
* \note
38
* \warning This code will be removed when a legacy libc API becomes available.
39
40
41
42
43
44
*/

#ifndef RTAI
#include <time.h>
#include <errno.h>
#include <stdio.h>
45
#include <pthread.h>
46
47
#include <linux/kernel.h>
#include <linux/types.h>
48
49
50
51
52
53
54
55
56
57
58

#define RTIME long long int

#define rt_printk printf

RTIME rt_get_time_ns (void);

int rt_sleep_ns (RTIME x);

void check_clock(void);

59
60
61
62
63
64
65
66
/**
 * see https://www.kernel.org/doc/Documentation/scheduler/sched-deadline.txt  or
 * http://www.blaess.fr/christophe/2014/04/05/utiliser-un-appel-systeme-inconnu-de-la-libc/
 */
#ifdef LOWLATENCY

#define gettid() syscall(__NR_gettid)

67
#define SCHED_DEADLINE  6
68

69
/* XXX use the proper syscall numbers */
70
#ifdef __x86_64__
71
72
#define __NR_sched_setattr   314
#define __NR_sched_getattr   315
73
74
75
#endif

#ifdef __i386__
76
77
#define __NR_sched_setattr   351
#define __NR_sched_getattr   352
78
79
80
81
#endif

struct sched_attr {
  __u32 size;
82

83
84
  __u32 sched_policy;
  __u64 sched_flags;
85

86
87
  /* SCHED_NORMAL, SCHED_BATCH */
  __s32 sched_nice;
88

89
90
  /* SCHED_FIFO, SCHED_RR */
  __u32 sched_priority;
91

92
93
94
95
96
97
98
99
100
101
  /* SCHED_DEADLINE (nsec) */
  __u64 sched_runtime;
  __u64 sched_deadline;
  __u64 sched_period;
};

int sched_setattr(pid_t pid, const struct sched_attr *attr, unsigned int flags);

int sched_getattr(pid_t pid,struct sched_attr *attr,unsigned int size, unsigned int flags);

102
#endif
103

104
#else
Anne Ambe's avatar
   
Anne Ambe committed
105
#include <rtai_hal.h>
106
107
108
109
110
111
112
#include <rtai_lxrt.h>
#include <rtai_sem.h>
#include <rtai_msg.h>

int rt_sleep_ns(RTIME x);

#endif