Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1663 pj 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
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/**
20
 ------------
21
 CVS :        $Id: tune.c,v 1.1 2004-07-05 14:17:16 pj Exp $
22
 
23
 File:        $File$
24
 Revision:    $Revision: 1.1 $
25
 Last update: $Date: 2004-07-05 14:17:16 $
26
 ------------
27
**/
28
 
29
/*
30
 * Copyright (C) 2001 Paolo Gai
31
 *
32
 * This program is free software; you can redistribute it and/or modify
33
 * it under the terms of the GNU General Public License as published by
34
 * the Free Software Foundation; either version 2 of the License, or
35
 * (at your option) any later version.
36
 *
37
 * This program is distributed in the hope that it will be useful,
38
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40
 * GNU General Public License for more details.
41
 *
42
 * You should have received a copy of the GNU General Public License
43
 * along with this program; if not, write to the Free Software
44
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
45
 *
46
 */
47
 
48
#include "kernel/kern.h"
49
 
50
/*
51
 *
52
 * Tuning the speed of the dummy loop for the value tasks...
53
 *
54
 */
55
 
56
 
57
#define TUNE_THRESHOLD 80
58
 
59
int tune_CPU_speed(int len)
60
{
61
  int x, y, j;
62
  TIME bef, aft;
63
  char s[2] = { 'X', 0 };
64
  char buf[20];
65
 
66
  int load;
67
 
68
//  cprintf("\n\n\n\nlen=%d                ",len);
69
//  return 1;
70
 
71
  load = 100000;
72
 
73
  x=10; y=10; // x and y positions
74
 
75
  for (;;) {
76
 
77
 
78
    bef = sys_gettime(NULL);
79
    for (j=0; j<load; j++) {
80
          s[0] = '*' + rand() % 100;
81
          puts_xy(x,y,rand()%15+1,s);
82
    }
83
    aft = sys_gettime(NULL);
84
 
85
    sprintf(buf,"%10d",(int)(aft-bef));
86
    puts_xy(10,11,WHITE,buf);
87
    //cprintf("Tuning idle cycles: load=%d , time=%d ...\n", load, (int)(aft-bef));
88
 
89
    if ((int)(aft-bef-len) < 0 &&
90
        (int)(aft-bef-len) > -TUNE_THRESHOLD)
91
       return load;
92
 
93
    load = (int)(((double)(max(0,len-TUNE_THRESHOLD/2))*(double)load)/(double)(aft-bef));
94
  }
95
 
96
}
97
 
98
// top number of iterations
99
// less than 4 sec on my portable PC (pentium 2 400 Mhz) (!)
100
//#define TUNE_TOP 5000000
101
 
102
// 1.8 sec max
103
#define TUNE_TOP 2500000
104
 
105
int tune_CPU_speed2(int len)
106
{
107
  int x, y, j;
108
  TIME bef, aft;
109
  char s[2] = { 'X', 0 };
110
 
111
  int bottom, top, load;
112
 
113
  bottom = 0;
114
  load = TUNE_TOP/2;
115
  top = TUNE_TOP;
116
 
117
 
118
  x=10; y=10; // x and y positions
119
 
120
  for (;;) {
121
 
122
 
123
    bef = sys_gettime(NULL);
124
    for (j=0; j<load; j++) {
125
          s[0] = '*' + rand() % 100;
126
          puts_xy(x,y,rand()%15+1,s);
127
    }
128
    aft = sys_gettime(NULL);
129
 
130
    cprintf("Tuning idle cycles: load=%d , time=%d ...\n", load, (int)(aft-bef));
131
 
132
    if (load > TUNE_TOP-10) {
133
       cprintf("This PC is too fast: please increase the TUNE_TOP define!\n");
134
       sys_end();
135
       return load;
136
    }
137
 
138
    if ((int)(aft-bef-len) < 20 && (int)(aft-bef-len) > -20)
139
       return load;
140
 
141
    if (aft-bef > len) {
142
       top = load;
143
       load = (top+bottom)/2;
144
    }
145
    else {
146
       bottom = load;
147
       load = (top+bottom)/2;
148
    }
149
  }
150
 
151
}