ulxbench.c 17.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
/*
 *  F i l e N a m e  :  U L X B E N C H . C
 *
 ****************************************************************************
 *                   (C) CopyRight ALPS Electric Co., Ltd. 1996
 ****************************************************************************
 *  Version
 *
 *  ver     Date
 *  ----  --------
 *  1.01  '96.04.05  Changed DISKTYPE 4 -> 7.
 *  1.00  '95.12.20  Initial revision .
 ****************************************************************************
*/
/*===========================================*/
/* レオドライブ用テストソフトのベンチマーク測定ルーチン         */
/*===========================================*/

#include <ultra64.h>
#include "ulxmain.h"
#include "ulxlib.h"
#include "ulxutil.h"

#include "leodrive.h"

#define RDBLOCKS    0x32

const static LEOCmdRead pm_read_base =
      { { LEO_COMMAND_READ,           /* COMMAND        */
          0x00,                       /* RESERVE        */
          0x00,                       /* CONTROL        */
          0x00,                       /* RESERVE        */
          0x00,                       /* STATUS         */
          0x00,                       /* SENSE          */
          0x00,                       /* RESERVE        */
          0x00,                       /* RESERVE        */
          0x00                        /* POST QUEUE     */
        },
          0x00,                       /* LBA            */
          RDBLOCKS,                   /* BLOCKS         */
          (u64 *)&RDB,                /* BUFFER POINTER */
          0x00,                       /* READ BYTES     */
      };

const static LEOCmdSeek pm_seek_base =
      { { LEO_COMMAND_SEEK,           /* COMMAND        */
          0x00,                       /* RESERVE        */
          0x00,                       /* CONTROL        */
          0x00,                       /* RESERVE        */
          0x00,                       /* STATUS         */
          0x00,                       /* SENSE          */
          0x00,                       /* RESERVE        */
          0x00,                       /* RESERVE        */
          0x00                        /* POST QUEUE     */
        },
          0x00                        /* LBA            */
      };

extern u16    LEOVZONE_TBL[DISK_TYPES][VZONES_PER_DRV];
extern u16    LEOBYTE_TBL2[ZONES_PER_DRV];
extern u8     LEOdisk_type;
extern OSMesg LEOcur_command;

/*==========================================================*/

void    transfer_rate_test( void )
{
    u32    key;
    u32    test_lba, read_bytes;
    OSTime  cmd_time, tcount_pre,tcount_aft;
    u8     test_zone;
    volatile LEOCmdRead pm_read_cmd0;
    volatile LEOCmdRead pm_read_cmd1;
    volatile LEOCmdRead pm_read_cmd2;
    volatile LEOCmdRead pm_read_cmd3;
    volatile LEOCmdRead pm_read_cmd4;
    volatile LEOCmdSeek pm_seek_cmd;

    test_lba = (u32)0x00;

    ClrDisp();
    LEOcur_command = (OSMesg)&pm_read_cmd0;
    Disp_Ready(0, 1, CYAN);
    sprintf( STR, "TRANSFER RATE RESULT" );
    Disp_Fin();

    Disp_Ready(4,  4, WHITE);
    sprintf( STR, "TRANSFER RATE TESTING..        ");
    Disp_Fin();

    for (test_zone=0; test_zone<9; test_zone++)
    {
        /* test command set. */
        pm_read_cmd0 = pm_read_base;
        pm_read_cmd1 = pm_read_base;
        pm_read_cmd2 = pm_read_base;
        pm_read_cmd3 = pm_read_base;
        pm_read_cmd4 = pm_read_base;
        if (test_zone)
        {
            switch(LEOdisk_type)
            {
                case 0:
                    if (test_zone > 2)
                        test_lba = LEOVZONE_TBL[LEOdisk_type][test_zone + 1];
                    else
                        test_lba = LEOVZONE_TBL[LEOdisk_type][test_zone -1]; 
                    break;
                case 1:
                    if (test_zone > 3)
                        test_lba = LEOVZONE_TBL[LEOdisk_type][test_zone + 2];
                    else
                        test_lba = LEOVZONE_TBL[LEOdisk_type][test_zone -1]; 
                    break;
                case 2:
                    if (test_zone > 4)
                        test_lba = LEOVZONE_TBL[LEOdisk_type][test_zone + 3];
                    else
                        test_lba = LEOVZONE_TBL[LEOdisk_type][test_zone -1]; 
                    break;
                case 3:
                    if (test_zone > 5)
                        test_lba = LEOVZONE_TBL[LEOdisk_type][test_zone + 4];
                    else
                        test_lba = LEOVZONE_TBL[LEOdisk_type][test_zone -1]; 
                    break;
                case 4:
                    if (test_zone > 6)
                        test_lba = LEOVZONE_TBL[LEOdisk_type][test_zone + 5];
                    else
                        test_lba = LEOVZONE_TBL[LEOdisk_type][test_zone -1]; 
                    break;
                case 5:
                    if (test_zone > 7)
                        test_lba = LEOVZONE_TBL[LEOdisk_type][test_zone + 6];
                    else
                        test_lba = LEOVZONE_TBL[LEOdisk_type][test_zone -1]; 
                    break;
                case 6:
                    test_lba = LEOVZONE_TBL[LEOdisk_type][test_zone -1];
                default:
                    break;
            }
        }
        if (test_zone == 0)
            test_lba = (u32)0;
        else
            test_lba -= SYSTEM_LBAS;

        if (RezeroUnit() || SeekDrive(test_lba + (RDBLOCKS * 4)) || SeekDrive(test_lba) )
        {
            Disp_Ready(2, 13, WHITE);
            sprintf( STR, "STS:%02d  SC:%02d   ",Status,SCode);
            Disp_Fin();
            break;
        }

        pm_read_cmd0.lba = test_lba;
        pm_read_cmd1.lba = test_lba;
        pm_read_cmd2.lba = test_lba + RDBLOCKS;
        pm_read_cmd3.lba = test_lba + (RDBLOCKS * 2);
        pm_read_cmd4.lba = test_lba + (RDBLOCKS * 3);

        pm_read_cmd0.xfer_blks = 1;
        leoCommand( (void *)&pm_read_cmd0);
        do {} while (pm_read_cmd0.header.status == LEO_STATUS_BUSY);

        tcount_pre = osGetTime();  /* get start time */

        leoCommand( (void *)&pm_read_cmd1);  /* issue command */
        leoCommand( (void *)&pm_read_cmd2);
        leoCommand( (void *)&pm_read_cmd3);
        leoCommand( (void *)&pm_read_cmd4);

        if (InCtrlData() == CONT_B) goto abort_test;
        do {} while (pm_read_cmd1.header.status == LEO_STATUS_BUSY);
        if (InCtrlData() == CONT_B) goto abort_test;
        do {} while (pm_read_cmd2.header.status == LEO_STATUS_BUSY);
        if (InCtrlData() == CONT_B) goto abort_test;
        do {} while (pm_read_cmd3.header.status == LEO_STATUS_BUSY);
        if (InCtrlData() == CONT_B)
        {
abort_test:
            Disp_Ready(2, (6+test_zone), YELLOW);
            sprintf( STR, "   ABORT TEST            ");
            Disp_Fin();
            do {} while (pm_read_cmd4.header.status == LEO_STATUS_BUSY);
            goto test_end;
        }

        /* WAIT LAST READ COMMAND FINISH. */
        do {} while (pm_read_cmd4.header.status == LEO_STATUS_BUSY);

        tcount_aft = osGetTime();
        tcount_aft = (tcount_aft - tcount_pre);  /* calc test time */

        Disp_Ready(2,  3, GREEN);
        sprintf( STR, "ZONE   BYTE     mSEC    BYTE/SEC ");
        Disp_Fin();
        Disp_Ready(2,  4, GREEN);
        sprintf( STR, "-------------------------------- ");
        Disp_Fin();

        Disp_Ready(2, (5+test_zone), WHITE);

        if ((pm_read_cmd1.header.status == LEO_STATUS_GOOD) && (pm_read_cmd2.header.status == LEO_STATUS_GOOD) &&
            (pm_read_cmd3.header.status == LEO_STATUS_GOOD) && (pm_read_cmd4.header.status == LEO_STATUS_GOOD) &&
            (pm_read_cmd0.header.status == LEO_STATUS_GOOD) )
        {
            cmd_time = OS_CYCLES_TO_USEC(tcount_aft) / 1000;

            read_bytes = LEOBYTE_TBL2[test_zone] * RDBLOCKS * 4;
            sprintf( STR, " %X   %7d    %4Ld    %7Ld ",test_zone, read_bytes, cmd_time,((read_bytes * 1000)/cmd_time) );
        }
        else
        {
            if (pm_read_cmd4.header.status != LEO_STATUS_GOOD)
                sprintf( STR, " %X RD ERROR STS:%02d  SC:%02d ",test_zone,pm_read_cmd4.header.status,pm_read_cmd4.header.sense);
            if (pm_read_cmd3.header.status != LEO_STATUS_GOOD)
                sprintf( STR, " %X RD ERROR STS:%02d  SC:%02d ",test_zone,pm_read_cmd3.header.status,pm_read_cmd3.header.sense);
            if (pm_read_cmd2.header.status != LEO_STATUS_GOOD)
                sprintf( STR, " %X RD ERROR STS:%02d  SC:%02d ",test_zone,pm_read_cmd2.header.status,pm_read_cmd2.header.sense);
            if (pm_read_cmd1.header.status != LEO_STATUS_GOOD)
                sprintf( STR, " %X RD ERROR STS:%02d  SC:%02d ",test_zone,pm_read_cmd1.header.status,pm_read_cmd1.header.sense);
            if (pm_read_cmd0.header.status != LEO_STATUS_GOOD)
                sprintf( STR, " %X RD ERROR STS:%02d  SC:%02d ",test_zone,pm_read_cmd0.header.status,pm_read_cmd0.header.sense);
        }
        Disp_Fin();
#if 0
        key = InCtrlData();
        if ( key == CONT_B)
        {
            Disp_Ready(2, (6+test_zone), YELLOW);
            sprintf( STR, "   TEST IS ABORT         ");
            Disp_Fin();
            goto test_end;
        }
#endif
    }
test_end:
    Disp_Ready(1, 14, YELLOW);
    sprintf( STR, "Hit any key to return MENU");
    Disp_Fin();

    GetChr();

}

void seek_time_tk_test(u32 test_count,u32 slba )
{
    u32 elba;
    OSTime cmd_time;
    OSTime tcount_pre, tcount_aft;
    u32 cmd_count;
    volatile LEOCmdSeek pm_seek_cmd;

    cmd_count = 0;

    ClrDisp();
    LEOcur_command = (OSMesg)&pm_seek_cmd;

    elba = slba + 2;
    if (elba > MAX_L_LBA)
        elba = MAX_L_LBA;

    if (test_count == 0)
        test_count = 1;

    Disp_Ready(0, 1, CYAN);
    sprintf( STR, "TK-TK SEEK TIME (%u[times]) ",test_count);
    Disp_Fin();

    Disp_Ready(2,  4, WHITE);
    sprintf( STR, "TESTING..           ");
    Disp_Fin();

    if (RezeroUnit() || SeekDrive(0x341) || SeekDrive(0)
     || SeekDrive(elba) || SeekDrive(slba) )
    {
        Disp_Ready(2,  4, YELLOW);
        sprintf( STR, " SEEK NG. TEST ABORT. ");
        Disp_Fin();

        Disp_Ready(2, 6, WHITE);
        sprintf( STR, "STS:%02d  SC:%02d   ",Status,SCode);
        Disp_Fin();

        Disp_Ready(1, 14, YELLOW);
        sprintf( STR, "Hit any key to return MENU");
        Disp_Fin();

        GetChr();
        return;
    }
    /* test command set. */
    pm_seek_cmd     = pm_seek_base;
    pm_seek_cmd.lba = elba;

    tcount_pre = osGetTime();
    for (cmd_count=0; cmd_count<test_count; cmd_count++)
    {
        leoCommand( (void *)&pm_seek_cmd);

        if (pm_seek_cmd.lba == slba)
            pm_seek_cmd.lba = elba;
        else
            pm_seek_cmd.lba = slba;
        /* WAIT LAST READ COMMAND FINISH. */
        do {} while (pm_seek_cmd.header.status == LEO_STATUS_BUSY);
    }
    tcount_aft = osGetTime();

    cmd_time = OS_CYCLES_TO_USEC(tcount_aft-tcount_pre) / test_count;
    Disp_Ready(2, 4, WHITE);
    sprintf( STR, "AVE = %Ld [uSEC] ",cmd_time);
    Disp_Fin();

    Disp_Ready(2, 12, WHITE);
    sprintf( STR, "Include CMD Overhead.      ");
    Disp_Fin();

    Disp_Ready(1, 14, YELLOW);
    sprintf( STR, "Hit any key to return MENU");
    Disp_Fin();

    GetChr();
}

void seek_time_rand_test(u32 test_count, u32 slba, u32 elba )
{
    u32 lba ;
    OSTime cmd_time;
    OSTime tcount_pre, tcount_aft;
    u32 cmd_count;
    volatile LEOCmdSeek pm_seek_cmd;

    lba = cmd_count = 0;

    ClrDisp();
    LEOcur_command = (OSMesg)&pm_seek_cmd;

    /* Random Seek Mode.  */
    if (slba > elba)
    {
        lba  = elba;
        elba = slba;
        slba = lba;
    }

    if (test_count == 0)
        test_count = 0x01;

    Disp_Ready(0, 1, CYAN);
    sprintf( STR, "Rand. SEEK TIME  (%u[times]) ",test_count);
    Disp_Fin();

    Disp_Ready(2,  4, WHITE);
    sprintf( STR, "TESTING..           ");
    Disp_Fin();

    if (RezeroUnit() || SeekDrive(0x341) || SeekDrive(0)
     || SeekDrive(slba) || SeekDrive((u32)( Rand32() % (elba - slba + 1)) + slba) )
    {
        Disp_Ready(2,  4, YELLOW);
        sprintf( STR, " SEEK NG. TEST ABORT. ");
        Disp_Fin();

        Disp_Ready(2, 6, WHITE);
        sprintf( STR, "STS:%02d  SC:%02d   ",Status,SCode);
        Disp_Fin();

        Disp_Ready(1, 14, YELLOW);
        sprintf( STR, "Hit any key to return MENU");
        Disp_Fin();

        GetChr();

        return;
    }
    /* test command set. */
    pm_seek_cmd     = pm_seek_base;
    /*pm_seek_cmd.lba = slba;*/
    pm_seek_cmd.lba = (u32)( Rand32() % (elba - slba + 1)) + slba;

    tcount_pre = osGetTime();
    for (cmd_count=0; cmd_count<test_count; cmd_count++)
    {
        leoCommand( (void *)&pm_seek_cmd);

        pm_seek_cmd.lba = (u32)( Rand32() % (elba - slba + 1)) + slba;
        /* WAIT LAST READ COMMAND FINISH. */
        do {} while (pm_seek_cmd.header.status == LEO_STATUS_BUSY);
    }
    tcount_aft = osGetTime();

    cmd_time = OS_CYCLES_TO_USEC(tcount_aft-tcount_pre) / test_count;
    Disp_Ready(2, 4, WHITE);
    sprintf( STR, "AVE = %7Ld [uSEC] ",cmd_time);
    Disp_Fin();

    Disp_Ready(2, 12, WHITE);
    sprintf( STR, "Include CMD Overhead.      ");
    Disp_Fin();

    Disp_Ready(1, 14, YELLOW);
    sprintf( STR, "Hit any key to return MENU");
    Disp_Fin();

    GetChr();

}

void seek_time_full_test(u32 test_count )
{
    u32 slba, elba;
    OSTime cmd_time;
    OSTime tcount_pre, tcount_aft;
    u32 cmd_count;
    volatile LEOCmdSeek pm_seek_cmd;

    cmd_count = 0;

    ClrDisp();
    LEOcur_command = (OSMesg)&pm_seek_cmd;

    /* Full Stroke Seek Mode. */
    slba = (u32)0;
    switch(LEOdisk_type)
    {
        case 0:
            elba = (u32)0xa9e;    /* ZONE7 LAST TRACK */
            break;
        case 1:
            elba = (u32)0xbb0;    /* ZONE7 LAST TRACK */
            break;
        case 2:
            elba = (u32)0xcc2;    /* ZONE7 LAST TRACK */
            break;
        case 3:
            elba = (u32)0xdd4;    /* ZONE7 LAST TRACK */
            break;
        case 4:
            elba = (u32)0xee6;    /* ZONE7 LAST TRACK */
            break;
        case 5:
            elba = (u32)0xff8;    /* ZONE7 LAST TRACK */
            break;
        case 6:
            elba = (u32)0x856;    /* ZONE7 LAST TRACK */
            break;
        default:
            break;
    }

    if (test_count == 0)
        test_count = 0x01;

    Disp_Ready(0, 1, CYAN);
    sprintf( STR, "FULL TK SEEK TIME (%u[times]) ",test_count);
    Disp_Fin();

    Disp_Ready(2,  4, WHITE);
    sprintf( STR, "TESTING..           ");
    Disp_Fin();

    if (RezeroUnit() || SeekDrive(elba) || SeekDrive(slba) )
    {
        Disp_Ready(2,  4, YELLOW);
        sprintf( STR, " SEEK NG. TEST ABORT. ");
        Disp_Fin();

        Disp_Ready(2, 6, WHITE);
        sprintf( STR, "STS:%02d  SC:%02d   ",Status,SCode);
        Disp_Fin();

        Disp_Ready(1, 14, YELLOW);
        sprintf( STR, "Hit any key to return MENU");
        Disp_Fin();

        GetChr();

        return;
    }
    /* test command set. */
    pm_seek_cmd     = pm_seek_base;
    pm_seek_cmd.lba = elba;

    tcount_pre = osGetTime();
    for (cmd_count=0; cmd_count<test_count; cmd_count++)
    {
        leoCommand( (void *)&pm_seek_cmd);

        if (pm_seek_cmd.lba == slba)
            pm_seek_cmd.lba = elba;
        else
            pm_seek_cmd.lba = slba;

        /* WAIT LAST READ COMMAND FINISH. */
        do {} while (pm_seek_cmd.header.status == LEO_STATUS_BUSY);
    }
    tcount_aft = osGetTime();

    cmd_time = OS_CYCLES_TO_USEC(tcount_aft-tcount_pre) / test_count;
    Disp_Ready(2, 4, WHITE);
    sprintf( STR, "AVE = %Ld [uSEC]",cmd_time);
    Disp_Fin();

    Disp_Ready(2, 12, WHITE);
    sprintf( STR, "Include CMD Overhead.      ");
    Disp_Fin();

    Disp_Ready(1, 14, YELLOW);
    sprintf( STR, "Hit any key to return MENU");
    Disp_Fin();

    GetChr();
}


void    bench_test( void )
{
    u32 num=1;
    u32 slba, elba;
    u32 test_count;
    u16 x_l=5, y_l=2, col_l=6;
    u8  *left_d[6] = {"TRANSFER RATE TEST     ",
                      "SEEK TIME(TK-TK ) TEST ",
                      "SEEK TIME(RANDOM) TEST ",
                      "SEEK TIME(FULL  ) TEST ",
                      "                       ",
                      "EXIT                   "
                     };

    slba = 0;
    elba = MAX_L_LBA;
    test_count = 1000;

    do
    {
        ClrDisp();
        Disp_Ready(0, 0, CYAN);
        sprintf( STR, "BENCHMARK TEST MENU " );
        Disp_Fin();

        ListDisp( x_l, y_l, col_l, left_d, 0, 0, 0, (void *)0, GREEN );
        num = SelStr1( x_l, y_l, col_l, left_d, num, GREEN );

        osSetTime((OSTime)0);

        switch( num )
        {
            case 1:
                transfer_rate_test() ;
                break;

            case 2:
                slba       = GetNum32( slba      , "Input START LBA ", 2, 13, YELLOW );
                test_count = GetNum32( test_count, "Input TEST COUNT    ", 2, 13, YELLOW );
                seek_time_tk_test(test_count, slba ) ;
                break;

            case 3:
                slba       = GetNum32( slba      , "Input MIN LBA ", 2, 13, YELLOW );
                elba       = GetNum32( elba      , "Input MAX LBA ", 2, 13, YELLOW );
                test_count = GetNum32( test_count, "Input TEST COUNT  ", 2, 13, YELLOW );
                seek_time_rand_test(test_count, slba, elba ) ;
                break;

            case 4:
                test_count = GetNum32( test_count, "Input TEST COUNT ", 2, 13, YELLOW );
                seek_time_full_test(test_count ) ;
                break;

            case 5:
                break;

            case 6:
                return;

            default:
                break;
        }

    } while( num != ESC );
}