Subversion Repositories shark

Rev

Rev 950 | Details | Compare with Previous | Last modification | View Log | RSS feed

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