Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed

/*
 * Project: S.Ha.R.K.
 *
 * Coordinators:
 *   Giorgio Buttazzo    <giorgio@sssup.it>
 *   Paolo Gai           <pj@gandalf.sssup.it>
 *
 * Authors     :
 *   Paolo Gai           <pj@gandalf.sssup.it>
 *   (see the web pages for full authors list)
 *
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
 *
 * http://www.sssup.it
 * http://retis.sssup.it
 * http://shark.sssup.it
 */


/**
 ------------
 CVS :        $Id: tune.c,v 1.1 2004-07-05 14:17:16 pj Exp $

 File:        $File$
 Revision:    $Revision: 1.1 $
 Last update: $Date: 2004-07-05 14:17:16 $
 ------------
**/


/*
 * Copyright (C) 2001 Paolo Gai
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


#include "kernel/kern.h"

/*
 *
 * Tuning the speed of the dummy loop for the value tasks...
 *
 */



#define TUNE_THRESHOLD 80

int tune_CPU_speed(int len)
{
  int x, y, j;
  TIME bef, aft;
  char s[2] = { 'X', 0 };
  char buf[20];

  int load;

//  cprintf("\n\n\n\nlen=%d                ",len);
//  return 1;

  load = 100000;

  x=10; y=10; // x and y positions

  for (;;) {


    bef = sys_gettime(NULL);
    for (j=0; j<load; j++) {
          s[0] = '*' + rand() % 100;
          puts_xy(x,y,rand()%15+1,s);
    }
    aft = sys_gettime(NULL);

    sprintf(buf,"%10d",(int)(aft-bef));
    puts_xy(10,11,WHITE,buf);
    //cprintf("Tuning idle cycles: load=%d , time=%d ...\n", load, (int)(aft-bef));

    if ((int)(aft-bef-len) < 0 &&
        (int)(aft-bef-len) > -TUNE_THRESHOLD)
       return load;

    load = (int)(((double)(max(0,len-TUNE_THRESHOLD/2))*(double)load)/(double)(aft-bef));
  }

}

// top number of iterations
// less than 4 sec on my portable PC (pentium 2 400 Mhz) (!)
//#define TUNE_TOP 5000000

// 1.8 sec max
#define TUNE_TOP 2500000

int tune_CPU_speed2(int len)
{
  int x, y, j;
  TIME bef, aft;
  char s[2] = { 'X', 0 };

  int bottom, top, load;

  bottom = 0;
  load = TUNE_TOP/2;
  top = TUNE_TOP;


  x=10; y=10; // x and y positions

  for (;;) {


    bef = sys_gettime(NULL);
    for (j=0; j<load; j++) {
          s[0] = '*' + rand() % 100;
          puts_xy(x,y,rand()%15+1,s);
    }
    aft = sys_gettime(NULL);

    cprintf("Tuning idle cycles: load=%d , time=%d ...\n", load, (int)(aft-bef));

    if (load > TUNE_TOP-10) {
       cprintf("This PC is too fast: please increase the TUNE_TOP define!\n");
       sys_end();
       return load;
    }

    if ((int)(aft-bef-len) < 20 && (int)(aft-bef-len) > -20)
       return load;

    if (aft-bef > len) {
       top = load;
       load = (top+bottom)/2;
    }
    else {
       bottom = load;
       load = (top+bottom)/2;
    }
  }

}