rt_wrapper.h 3.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.0  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

22
/*! \file rt_wrapper.h
knopp's avatar
knopp committed
23
* \brief provides a wrapper for the timing function for real-time opeartions. It also implements an API for the SCHED_DEADLINE kernel scheduler.
24
* \author F. Kaltenberger and Navid Nikaein
25
26
27
* \date 2013
* \version 0.1
* \company Eurecom
28
* \email: florian.kaltenberger@eurecom.fr, navid.nikaein@eurecom.fr
29
* \note
30
* \warning This code will be removed when a legacy libc API becomes available.
31
32
*/

33
34
#ifndef _RT_WRAPPER_H_
#define _RT_WRAPPER_H_
35

knopp's avatar
knopp committed
36
#define _GNU_SOURCE
37
38
#include <time.h>
#include <errno.h>
39
40
41
#include <stdint.h>
#include <sys/stat.h>
#include <fcntl.h>
42
#include <pthread.h>
43
44
#include <linux/kernel.h>
#include <linux/types.h>
45
46
#include <syscall.h>
#include <math.h>
knopp's avatar
knopp committed
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <sched.h> 
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sched.h>
#include <linux/sched.h>
#include <signal.h>
#include <execinfo.h>
#include <getopt.h>
#include <sys/sysinfo.h>

#include "UTIL/LOG/log_extern.h"
#include "msc.h"
60
61
62
63
64

#define RTIME long long int

#define rt_printk printf

knopp's avatar
knopp committed
65
66
void set_latency_target(void);

67
68
69
70
71
72
RTIME rt_get_time_ns (void);

int rt_sleep_ns (RTIME x);

void check_clock(void);

73
74
75
76
77
int fill_modeled_runtime_table(uint16_t runtime_phy_rx[29][6],uint16_t runtime_phy_tx[29][6]);

double get_runtime_tx(int tx_subframe, uint16_t runtime_phy_tx[29][6],uint32_t mcs, int N_RB_DL,double cpuf,int nb_tx_antenna);

double get_runtime_rx(int rx_subframe, uint16_t runtime_phy_rx[29][6], uint32_t mcs, int N_RB_DL,double cpuf,int nb_rx_antenna);
78
79
80
81
/**
 * 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/
 */
laurent's avatar
laurent committed
82
#ifdef DEADLINE_SCHEDULER
83
84
85

#define gettid() syscall(__NR_gettid)

86
#define SCHED_DEADLINE  6
87

88
/* XXX use the proper syscall numbers */
89
#ifdef __x86_64__
90
91
#define __NR_sched_setattr   314
#define __NR_sched_getattr   315
92
93
94
#endif

#ifdef __i386__
95
96
#define __NR_sched_setattr   351
#define __NR_sched_getattr   352
97
98
99
100
#endif

struct sched_attr {
  __u32 size;
101

102
103
  __u32 sched_policy;
  __u64 sched_flags;
104

105
106
  /* SCHED_NORMAL, SCHED_BATCH */
  __s32 sched_nice;
107

108
109
  /* SCHED_FIFO, SCHED_RR */
  __u32 sched_priority;
110

111
112
113
114
115
116
117
118
119
120
  /* 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);

121
#endif
122

123
124
#define gettid() syscall(__NR_gettid) // for gettid

125
#endif /* _RT_WRAPPER_H_ */