Subversion Repositories shark

Rev

Rev 950 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
949 trimarchi 1
#include <stdio.h>
2
#include <unistd.h>
3
 
4
#include <time.h>
5
#include <errno.h>
6
 
7
#include <pthread.h>
8
#include <sched.h>
9
//#include <tefses_stats.h>
10
 
11
#include "fsf.h"
12
#include "timespec_operations.h"
13
#include "fsf_os_compatibility.h"
14
 
15
 
16
/*
17
 
18
 * This is part of the common tests:
19
 
20
 ** Test for the calculus of the jitter
21
 
22
  -  Create a BOUNDED workload server, with 40ms minimum budget and 50ms
23
     as maximum and minimum period and also 50ms maximum budget,
24
     preemption level 4 and deadline equal to period. The server is
25
     bound to the main thread with fsf_negotiate_contract_for_myself.
26
 
27
  -  The test consist of a periodic activation at absolutes points in time,
28
     the first instruction after each activation is the measurement of the
29
     absolute real-time of activation. Minimum, maximum and average
30
     differences are stored. The test runs 500 times.
31
 
32
 
33
*/
34
 
35
#define LOCAL_ERROR(nn,ss) {if(errno==0) errno=(nn); perror(ss); return (nn);}
36
//#define ERROR(nn,ss) {if(errno==0) errno=(nn); perror(ss); exit (nn);}
37
 
38
struct timespec            instant_zero = {0,0};
39
int                        main_priority = 4;
40
struct timespec            last_time = {0,0};
41
fsf_server_id_t            server_A = 0;
42
 
43
extern int cal_cycles;
44
extern int calibrate_cycle(void);
45
extern void eat(TIME wait);
46
 
47
 
48
int
49
fsf_priority_map (unsigned long plevel)
50
{
51
  return plevel;
52
}
53
 
54
 
55
int main()
56
{
57
   struct sched_param   param;
58
   //struct timespec      half_second={0,500000000};
59
   struct timespec      tmp = {0,0};
60
   int                  terror = 0;
61
 
62
  fsf_contract_parameters_t  contract;
63
  struct timespec    budget_min = {0,30000000};
64
  struct timespec    period_max = {0,50000000};
65
  struct timespec    budget_max = {0,50000000};
66
  struct timespec    period_min = {0,50000000};
67
  fsf_workload_t     workload = FSF_BOUNDED;
68
 
69
  bool               d_equals_t = true;
70
  struct timespec    deadline = {0,50000000};
71
  int                budget_overrun_sig_notify = FSF_NULL_SIGNAL;   // 0
72
  union sigval       budget_overrun_sig_value = {0};
73
  int                deadline_miss_sig_notify = FSF_NULL_SIGNAL;    // 0
74
  union sigval       deadline_miss_sig_value = {0};
75
 
76
  fsf_granularity_t      granularity = FSF_DEFAULT_GRANULARITY;       // CONTINUOUS
77
  fsf_utilization_set_t *utilization_set = FSF_NULL_UTILIZATION_SET;  // NULL
78
  int                    quality = 1;
79
  int                    importance = FSF_DEFAULT_IMPORTANCE;         // 1
80
 
81
  fsf_preemption_level_t   preemption_level = (fsf_preemption_level_t) main_priority;
82
  fsf_critical_sections_t *critical_sections = NULL;
83
 
84
  struct timespec  max_jitter={0,0};
85
  struct timespec  min_jitter={100000000,0};
86
  struct timespec  avg_jitter={0,0};
87
  int              my_counter = 0;
88
/*
89
  struct timespec  next_budget;
90
  struct timespec  next_period;
91
  bool             was_deadline_missed = 0;
92
  bool             was_budget_overran = 0;
93
*/
94
  //pthread_t                task_in_b;
95
  calibrate_cycle();
96
  fsf_init();
97
  SERIAL_CONSOLE_INIT; //marte1.26i+
98
 
99
   param.sched_priority = main_priority;
100
   if ((terror=pthread_setschedparam (pthread_self (), SCHED_FIFO, &param)))
101
     LOCAL_ERROR(terror,"pthread_setschedparam");
102
 
103
   instant_zero.tv_sec = 10000000;
104
   instant_zero.tv_nsec = 10000000;
105
   clock_settime(CLOCK_REALTIME,&instant_zero);
106
   clock_gettime(CLOCK_REALTIME,&instant_zero);
107
   last_time = instant_zero;
108
//   put_time(&instant_zero, "instant_zero");
109
//   put_time(NULL, "printing point 1");
110
//   put_time(NULL, "printing point 2");
111
 
112
 
113
   // Adjust the time eater (in load.c)
114
   //adjust ();
115
 
116
 
117
  if ((terror=fsf_initialize_contract(&contract)))
118
  {
119
     printf(" Initialize fail for server A\n");
120
     LOCAL_ERROR(terror,"fsf_initialize_contract failed");
121
  }
122
 
123
  if ((terror=fsf_set_contract_basic_parameters (&contract,
124
                                    &budget_min,
125
                                    &period_max,
126
                                    workload)))
127
  {
128
     printf("Set_Basic_Parameters failed for server A\n");
129
     LOCAL_ERROR(terror,"set_contract_basic_parameters failed");
130
  }
131
 
132
  if ((terror=fsf_set_contract_timing_requirements (&contract,
133
                                                    d_equals_t,
134
                                                    (d_equals_t?NULL:&deadline),
135
                                                    budget_overrun_sig_notify,
136
                                                    budget_overrun_sig_value,
137
                                                    deadline_miss_sig_notify,
138
                                                    deadline_miss_sig_value)))
139
  {
140
     printf("Set_Timing_Requirements failed for server A\n");
141
     LOCAL_ERROR(terror,"fsf_set_contract_timing_requirements failed");
142
  }
143
 
144
  if ((terror=fsf_set_contract_reclamation_parameters (&contract,
145
                                                       &budget_max,
146
                                                       &period_min,
147
                                                       granularity,
148
                                                       utilization_set,
149
                                                       quality,
150
                                                       importance)))
151
  {
152
     printf("Set_Reclamation_Parameters failed for server A\n");
153
     LOCAL_ERROR(terror,"fsf_set_contract_reclamation_parameters failed");
154
  }
155
 
156
  //preemption_level = (fsf_preemption_level_t) param.sched_priority;
157
  if ((terror=fsf_set_contract_synchronization_parameters (&contract,                                          
158
                                                           critical_sections)))
159
  {
160
     printf("Set_Synchronization_Parameters failed for server A\n");
161
     LOCAL_ERROR(terror,"fsf_set_contract_synchronization_parameters failed");
162
  }
163
 
164
  terror = fsf_negotiate_contract_for_myself(&contract, &server_A);
165
  if (terror)
166
  {
167
    printf("Negotiate_Contract failed for server A\n");
168
    ERROR(terror,"fsf_negotiate_contract_for_myself failed");
169
  }
170
 
171
  { /* Bounded workload task block  */
172
    struct timespec  next_budget;
173
    struct timespec  next_period;
174
    bool             was_deadline_missed = 0;
175
    bool             was_budget_overran = 0;
176
    struct timespec  at_absolute_time;
177
    struct timespec  my_period = {0,53000000}; // 53 miliseconds
178
    struct timespec  ahora;
179
    int              i;
180
 
181
    if ((terror=clock_gettime(CLOCK_REALTIME,&at_absolute_time)))
182
      LOCAL_ERROR(terror,"clock_gettime failed");
183
 
184
    for (i=0;i<500;i++) {
185
 
186
      incr_timespec(&at_absolute_time, &my_period);
187
 
188
      if ((terror=fsf_schedule_timed_job (
189
                                       &at_absolute_time,
190
                                       &next_budget,
191
                                       &next_period,
192
                                       &was_deadline_missed,
193
                                       &was_budget_overran)))
194
      {
195
         ERROR(terror,"fsf_bounded_server: a call to fsf_schedule_next_timed_job failed");
196
      }
197
 
198
 
199
      //printf("\ndebug: now es-> (%d,%d)\n", now.tv_sec, now.tv_nsec);
200
      if ((terror=clock_gettime(CLOCK_REALTIME,&ahora)))
201
        LOCAL_ERROR(terror,"ahora clock_gettime failed");
202
 
203
      //printf("\ndebug: y ahora es-> (%d,%d)\n", ahora.tv_sec, ahora.tv_nsec);
204
      decr_timespec(&ahora, &at_absolute_time);
205
 
206
      if ( smaller_timespec(&ahora, &min_jitter) )
207
        min_jitter = ahora;
208
 
209
      if ( smaller_timespec(&max_jitter, &ahora) )
210
        max_jitter = ahora;
211
 
212
      incr_timespec(&avg_jitter, &ahora);
213
 
214
      my_counter++;
215
    }  
216
    printf("\n\n        minimum jitter is: %8d\n", min_jitter.tv_nsec+ min_jitter.tv_sec*1000000000);
217
    printf("        maximum jitter is: %8d\n", max_jitter.tv_nsec+ max_jitter.tv_sec*1000000000);
218
    printf("        average jitter is: %8d\n\n", (avg_jitter.tv_nsec+ avg_jitter.tv_sec*1000000000)/my_counter);
219
 
220
  } /* End of bounded workload task block  */
221
 
222
 
223
  STANDARD_CONSOLE_INIT; //marte1.26i+
224
 
225
  printf("\n\n        minimum jitter is: %8d\n", min_jitter.tv_nsec+ min_jitter.tv_sec*1000000000);
226
  printf("        maximum jitter is: %8d\n", max_jitter.tv_nsec+ max_jitter.tv_sec*1000000000);
227
  printf("        average jitter is: %8d\n\n", (avg_jitter.tv_nsec+ avg_jitter.tv_sec*1000000000)/my_counter);
228
 
229
  //printf("\nThe end.\n");
230
 
231
  //stop_scheduler = 1;
232
  exit(0);
233
  return 0;
234
} /* End of main */