Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1173 giacomo 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Giacomo Guidi       <giacomo@gandalf.sssup.it>
10
 *
11
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
12
 *
13
 * http://www.sssup.it
14
 * http://retis.sssup.it
15
 * http://shark.sssup.it
16
 */
17
 
18
/*
19
 * This program is free software; you can redistribute it and/or modify
20
 * it under the terms of the GNU General Public License as published by
21
 * the Free Software Foundation; either version 2 of the License, or
22
 * (at your option) any later version.
23
 *
24
 * This program is distributed in the hope that it will be useful,
25
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
 * GNU General Public License for more details.
28
 *
29
 * You should have received a copy of the GNU General Public License
30
 * along with this program; if not, write to the Free Software
31
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
32
 */
33
 
34
/*
35
 * Advanced Timer Demo
36
 *
37
 */
38
 
39
#include "kernel/kern.h"
40
#include "ll/i386/cons.h"
41
#include "ll/i386/advtimer.h"
42
 
1360 giacomo 43
#include "drivers/shark_keyb26.h"
1512 giacomo 44
#include "drivers/shark_cpu26.h"
1173 giacomo 45
 
46
#define UPDATE_PERIOD   10000
47
#define UPDATE_WCET     1000
48
 
1211 giacomo 49
extern unsigned int clk_per_msec;
50
extern unsigned int apic_clk_per_msec;
1173 giacomo 51
 
1512 giacomo 52
int freq_number = 0;
53
int cur_frequency = 0;
54
int cur_freq_number = 0;
55
int dvs_status = 0;
56
 
1173 giacomo 57
TASK Update(void *arg)
58
{  
59
  struct timespec actual_timer;
60
 
61
  long nsec,sec,min,hrs,day;
62
  long mean_delay,tot_delay,num_delay;
63
 
64
  signed long long start,end,res;
65
  struct timespec s_test,startts,endts;
66
 
1512 giacomo 67
  /* Get the DVS status */
68
  int i;
69
  char dvs_frequencies[1000];
70
 
1537 giacomo 71
  dvs_status = CPU26_DVS_installed();
1512 giacomo 72
 
73
  if (dvs_status > 0) {
74
 
75
        printf_xy(0,11,WHITE,"Dynamic Frequency Scaling Supported");
76
        printf_xy(0,12,WHITE,"Press \"q\" to raise or \"a\" to lower CPU freq");
77
 
78
        CPU26_show_frequencies(dvs_frequencies);
79
        freq_number = CPU26_get_frequencies(cpu26_freqs);
1526 giacomo 80
        if (freq_number > 0) {
81
                printf_xy(0,13,WHITE,"Supported Frequencies [ %s: %d ]",dvs_frequencies,freq_number);
82
        } else {
83
                printf_xy(0,13,WHITE,"Not Pre-Defined Frequencies");
84
        }
1512 giacomo 85
        cur_frequency = CPU26_get_cur_frequency();
86
        printf_xy(0,14,WHITE,"Current Frequency [ %10d ]",cur_frequency);
87
 
88
        for (i=0;i<freq_number;i++)
89
                if (cpu26_freqs[i] == cur_frequency) break;
90
        cur_freq_number = i;
91
 
92
  } else {
93
 
94
        printf_xy(0,11,WHITE,"Dynamic Frequency Scaling NOT Supported");
95
 
96
  }
97
 
1173 giacomo 98
  task_nopreempt();
99
 
100
  num_delay = tot_delay = mean_delay = 0;
101
 
102
  while (1) {
103
 
104
        if (clk_per_msec != 0) {
105
 
106
          rdtscll(start);
107
          sys_gettime(&actual_timer);
108
          rdtscll(end);
109
          res = end - start;
110
          rdtscll(start);
111
          rdtscll(end);
112
          res -= (end - start);
113
          s_test.tv_nsec = res * 1000000 / clk_per_msec;
114
 
115
 
116
        } else {
117
 
118
          sys_gettime(&startts);
119
          sys_gettime(&actual_timer);
120
          sys_gettime(&endts);
121
          SUBTIMESPEC(&endts,&startts,&s_test);
122
          sys_gettime(&startts);
123
          sys_gettime(&endts);
124
          SUBTIMESPEC(&endts,&startts,&endts);
125
          SUBTIMESPEC(&s_test,&endts,&s_test);
126
 
127
        }
128
 
129
        if (tot_delay < 1000000000) {
130
          tot_delay += s_test.tv_nsec;
131
          num_delay ++;
132
          mean_delay = tot_delay / num_delay;
133
        }
134
 
135
        nsec = actual_timer.tv_nsec;
136
        sec = actual_timer.tv_sec;
137
        min = sec / 60;
138
        sec %= 60;
139
        hrs = min / 60;
140
        min %= 60;
141
        day = hrs / 24;
142
        hrs %= 24;
143
 
1211 giacomo 144
        printf_xy(0,5,WHITE,"Actual CPU Clk/msec:  %12d",clk_per_msec);
145
        printf_xy(0,6,WHITE,"Actual APIC Clk/msec: %12d",apic_clk_per_msec);  
146
        printf_xy(0,7,WHITE,"Actual Timer: %2ld d %2ld h %2ld m %2ld s %12ld ns",day,hrs,min,sec,(long)nsec);
1173 giacomo 147
 
1211 giacomo 148
        printf_xy(0,9,WHITE,"Timer Access Delay: %12ld ns",mean_delay);
1512 giacomo 149
 
150
        if (dvs_status > 0)
151
          printf_xy(0,14,WHITE,"Current Frequency [ %10d ]",CPU26_get_cur_frequency());
1173 giacomo 152
 
153
        task_endcycle();
154
 
155
  }
156
 
157
}
158
 
159
void set_screen()
160
{
161
 
1526 giacomo 162
        clear();
1394 giacomo 163
 
1173 giacomo 164
        printf_xy(20,0,WHITE,"          Advanced Timer Demo           ");
165
        printf_xy(20,1,WHITE,"Giacomo Guidi <giacomo@gandalf.sssup.it>");
1576 tullio 166
        printf_xy(20,2,WHITE,"         Press Ctrl + C to exit          ");
1173 giacomo 167
 
168
}
1394 giacomo 169
 
170
void program_key_end(KEY_EVT* e)
171
{
1550 pj 172
        exit(1);
1512 giacomo 173
}
174
 
175
void up_freq(KEY_EVT* e)
176
{
177
 
1524 giacomo 178
        if (dvs_status > 0 && freq_number > 0) {
1512 giacomo 179
          cur_freq_number++;
180
          if (cur_freq_number >= freq_number) cur_freq_number--;
181
          CPU26_set_frequency(cpu26_freqs[cur_freq_number],DVS_RELATION_H);
182
        }
183
}
184
 
185
void down_freq(KEY_EVT* e)
186
{
1524 giacomo 187
        if (dvs_status > 0 && freq_number > 0) {
1512 giacomo 188
          cur_freq_number--;
189
          if (cur_freq_number < 0) cur_freq_number++;
190
          CPU26_set_frequency(cpu26_freqs[cur_freq_number],DVS_RELATION_L);
191
        }
192
}
1173 giacomo 193
 
194
int main(int argc, char **argv)
195
{
196
 
197
  HARD_TASK_MODEL   mp; //Show current setting
198
  PID               update;
199
  KEY_EVT           k;
1374 giacomo 200
 
1576 tullio 201
  k.flag = CNTL_BIT;
1173 giacomo 202
  k.scan = KEY_C;
203
  k.ascii = 'c';
1360 giacomo 204
  k.status = KEY_PRESSED;
205
  keyb_hook(k,program_key_end,FALSE);
1173 giacomo 206
 
1576 tullio 207
  k.flag = CNTR_BIT;
208
  k.status = KEY_PRESSED;
209
  keyb_hook(k,program_key_end,FALSE);
210
 
1512 giacomo 211
  k.flag = 0;
212
  k.scan = KEY_Q;
213
  k.ascii = 'q';
214
  k.status = KEY_PRESSED;
215
  keyb_hook(k,up_freq,FALSE);
216
 
217
  k.flag = 0;
218
  k.scan = KEY_A;
219
  k.ascii = 'a';
220
  k.status = KEY_PRESSED;
221
  keyb_hook(k,down_freq,FALSE);
222
 
1173 giacomo 223
  set_screen();
224
 
225
  hard_task_default_model(mp);
226
  hard_task_def_ctrl_jet(mp);
227
  hard_task_def_group(mp, 1);
228
  hard_task_def_wcet(mp,UPDATE_WCET);
229
  hard_task_def_mit(mp,UPDATE_PERIOD);
230
  hard_task_def_usemath(mp);
231
  update = task_create("Update", Update, &mp, NULL);
232
  if (update != NIL) task_activate(update);
233
 
234
  return 0;
235
 
236
}