-
Notifications
You must be signed in to change notification settings - Fork 0
/
chronos_utils.h
executable file
·98 lines (79 loc) · 2.97 KB
/
chronos_utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/***************************************************************************
* Copyright (C) 2009-2012 Virginia Tech Real-Time Systems Lab *
* Written by Matthew Dellinger *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef CHRONOS_UTILS_H
#define CHRONOS_UTILS_H
#include <string.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <vector>
using namespace std;
#define BILLION 1000000000
#define MILLION 1000000
#define THOUSAND 1000
/* Read the timestamp counter. Throw mfence to prevent reordering */
#ifdef __i386__
#define DECLARE_ARGS(val, low, high) unsigned long long val
#define EAX_EDX_VAL(val, low, high) (val)
#define EAX_EDX_RET(val, low, high) "=A" (val)
#else
#define DECLARE_ARGS(val, low, high) unsigned low, high
#define EAX_EDX_VAL(val, low, high) ((low) | ((uint64_t)(high) << 32))
#define EAX_EDX_RET(val, low, high) "=a" (low), "=d" (high)
#endif
static inline unsigned long long RDTSC()
{
DECLARE_ARGS(val, low, high);
asm volatile( "mfence\n"
"rdtsc" : EAX_EDX_RET(val, low, high));
return EAX_EDX_VAL(val, low, high);
}
extern unsigned long long subtract_ts_mod(struct timespec *first, struct timespec *last);
template<typename T> void sum_vec(vector<T> *a1,vector<T> a2){
/*
* sums contents of two vectors, and modified results are stored in the first vector
*/
for(int i=0;i<a1->size();i++){
a1->at(i)+=a2[i];
}
}
void burn_cpu(long long exec_usec, double exec_slope);
void burn_cpu_abort(long long exec_usec, double exec_slope, char *abort);
#ifdef __cplusplus
extern "C" {
#endif
int deadline_met(struct timespec *end_time, struct timespec *deadline);
unsigned long subtract_ts(struct timespec *first, struct timespec *last);
/* Make periodic threads */
timer_t * make_periodic_threads(timer_t *timer,
void (*func)(union sigval),
void *arg,
struct timespec start_time,
struct timespec period,
pthread_attr_t *tattr);
int delete_periodic_thread(timer_t timer);
#ifdef __cplusplus
}
#endif
#endif