Subversion Repositories shark

Rev

Rev 1394 | Rev 1524 | Go to most recent revision | 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
 
71
  dvs_status = CPU26_DVS_status();
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);
80
        printf_xy(0,13,WHITE,"Supported Frequencies [ %s: %d ]",dvs_frequencies,freq_number);
81
        cur_frequency = CPU26_get_cur_frequency();
82
        printf_xy(0,14,WHITE,"Current Frequency [ %10d ]",cur_frequency);
83
 
84
        for (i=0;i<freq_number;i++)
85
                if (cpu26_freqs[i] == cur_frequency) break;
86
        cur_freq_number = i;
87
 
88
  } else {
89
 
90
        printf_xy(0,11,WHITE,"Dynamic Frequency Scaling NOT Supported");
91
 
92
  }
93
 
1173 giacomo 94
  task_nopreempt();
95
 
96
  num_delay = tot_delay = mean_delay = 0;
97
 
98
  while (1) {
99
 
100
        if (clk_per_msec != 0) {
101
 
102
          rdtscll(start);
103
          sys_gettime(&actual_timer);
104
          rdtscll(end);
105
          res = end - start;
106
          rdtscll(start);
107
          rdtscll(end);
108
          res -= (end - start);
109
          s_test.tv_nsec = res * 1000000 / clk_per_msec;
110
 
111
 
112
        } else {
113
 
114
          sys_gettime(&startts);
115
          sys_gettime(&actual_timer);
116
          sys_gettime(&endts);
117
          SUBTIMESPEC(&endts,&startts,&s_test);
118
          sys_gettime(&startts);
119
          sys_gettime(&endts);
120
          SUBTIMESPEC(&endts,&startts,&endts);
121
          SUBTIMESPEC(&s_test,&endts,&s_test);
122
 
123
        }
124
 
125
        if (tot_delay < 1000000000) {
126
          tot_delay += s_test.tv_nsec;
127
          num_delay ++;
128
          mean_delay = tot_delay / num_delay;
129
        }
130
 
131
        nsec = actual_timer.tv_nsec;
132
        sec = actual_timer.tv_sec;
133
        min = sec / 60;
134
        sec %= 60;
135
        hrs = min / 60;
136
        min %= 60;
137
        day = hrs / 24;
138
        hrs %= 24;
139
 
1211 giacomo 140
        printf_xy(0,5,WHITE,"Actual CPU Clk/msec:  %12d",clk_per_msec);
141
        printf_xy(0,6,WHITE,"Actual APIC Clk/msec: %12d",apic_clk_per_msec);  
142
        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 143
 
1211 giacomo 144
        printf_xy(0,9,WHITE,"Timer Access Delay: %12ld ns",mean_delay);
1512 giacomo 145
 
146
        if (dvs_status > 0)
147
          printf_xy(0,14,WHITE,"Current Frequency [ %10d ]",CPU26_get_cur_frequency());
1173 giacomo 148
 
149
        task_endcycle();
150
 
151
  }
152
 
153
}
154
 
155
void set_screen()
156
{
157
 
1394 giacomo 158
        clear();
159
 
1173 giacomo 160
        printf_xy(20,0,WHITE,"          Advanced Timer Demo           ");
161
        printf_xy(20,1,WHITE,"Giacomo Guidi <giacomo@gandalf.sssup.it>");
162
        printf_xy(20,2,WHITE,"         Press Alt + c to exit          ");
163
 
164
}
1394 giacomo 165
 
166
void program_key_end(KEY_EVT* e)
167
{
168
        sys_end();
1512 giacomo 169
}
170
 
171
void up_freq(KEY_EVT* e)
172
{
173
 
174
        if (dvs_status > 0) {
175
          cur_freq_number++;
176
          if (cur_freq_number >= freq_number) cur_freq_number--;
177
          CPU26_set_frequency(cpu26_freqs[cur_freq_number],DVS_RELATION_H);
178
        }
179
}
180
 
181
void down_freq(KEY_EVT* e)
182
{
183
        if (dvs_status > 0) {
184
          cur_freq_number--;
185
          if (cur_freq_number < 0) cur_freq_number++;
186
          CPU26_set_frequency(cpu26_freqs[cur_freq_number],DVS_RELATION_L);
187
        }
188
}
1173 giacomo 189
 
190
int main(int argc, char **argv)
191
{
192
 
193
  HARD_TASK_MODEL   mp; //Show current setting
194
  PID               update;
195
  KEY_EVT           k;
1374 giacomo 196
 
1173 giacomo 197
  k.flag = ALTL_BIT;
198
  k.scan = KEY_C;
199
  k.ascii = 'c';
1360 giacomo 200
  k.status = KEY_PRESSED;
201
  keyb_hook(k,program_key_end,FALSE);
1173 giacomo 202
 
1512 giacomo 203
  k.flag = 0;
204
  k.scan = KEY_Q;
205
  k.ascii = 'q';
206
  k.status = KEY_PRESSED;
207
  keyb_hook(k,up_freq,FALSE);
208
 
209
  k.flag = 0;
210
  k.scan = KEY_A;
211
  k.ascii = 'a';
212
  k.status = KEY_PRESSED;
213
  keyb_hook(k,down_freq,FALSE);
214
 
1173 giacomo 215
  set_screen();
216
 
217
  hard_task_default_model(mp);
218
  hard_task_def_ctrl_jet(mp);
219
  hard_task_def_group(mp, 1);
220
  hard_task_def_wcet(mp,UPDATE_WCET);
221
  hard_task_def_mit(mp,UPDATE_PERIOD);
222
  hard_task_def_usemath(mp);
223
  update = task_create("Update", Update, &mp, NULL);
224
  if (update != NIL) task_activate(update);
225
 
226
  return 0;
227
 
228
}