From 844a332f8de4ab74ec1c739c2ab6f41e8d957d53 Mon Sep 17 00:00:00 2001 From: Yotam Barnoy Date: Sun, 18 Jul 2010 06:59:25 +0000 Subject: PSP: forgot test files svn-id: r50981 --- backends/platform/psp/tests.cpp | 656 ++++++++++++++++++++++++++++++++++++++++ backends/platform/psp/tests.h | 26 ++ 2 files changed, 682 insertions(+) create mode 100644 backends/platform/psp/tests.cpp create mode 100644 backends/platform/psp/tests.h diff --git a/backends/platform/psp/tests.cpp b/backends/platform/psp/tests.cpp new file mode 100644 index 0000000000..25c07fd723 --- /dev/null +++ b/backends/platform/psp/tests.cpp @@ -0,0 +1,656 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.cpp $ + * $Id: osys_psp.cpp 46126 2009-11-24 14:18:46Z fingolfin $ + * + */ + +#include "common/scummsys.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "backends/platform/psp/rtc.h" +#include "backends/platform/psp/thread.h" +#include "backends/platform/psp/memory.h" + + +#define UNCACHED(x) ((byte *)(((uint32)(x)) | 0x40000000)) /* make an uncached access */ +#define CACHED(x) ((byte *)(((uint32)(x)) & 0xBFFFFFFF)) /* make an uncached access into a cached one */ + +//#define __PSP_DEBUG_FUNCS__ +//#define __PSP_DEBUG_PRINT__ + +// Results: (333Mhz/222Mhz) +// Getting a tick: 1-2 us +// Getting a time structure: 9/14us +// ie. using a tick and just dividing by 1000 saves us time. + +#include "backends/platform/psp/trace.h" + +void test_ticks() { + uint32 ticksPerSecond = sceRtcGetTickResolution(); + PSP_INFO_PRINT("ticksPerSecond[%d]\n", ticksPerSecond); + + uint32 currentTicks1[2]; + uint32 currentTicks2[2]; + + sceRtcGetCurrentTick((u64 *)currentTicks1); + sceRtcGetCurrentTick((u64 *)currentTicks2); + PSP_INFO_PRINT("current tick[%x %x][%u %u]\n", currentTicks1[0], currentTicks1[1], currentTicks1[0], currentTicks1[1]); + PSP_INFO_PRINT("current tick[%x %x][%u %u]\n", currentTicks2[0], currentTicks2[1], currentTicks2[0], currentTicks2[1]); + + pspTime time; + sceRtcSetTick(&time, (u64 *)currentTicks2); + PSP_INFO_PRINT("current tick in time, year[%d] month[%d] day[%d] hour[%d] minutes[%d] seconds[%d] us[%d]\n", time.year, time.month, time.day, time.hour, time.minutes, time.seconds, time.microseconds); + + pspTime time1; + pspTime time2; + sceRtcGetCurrentClockLocalTime(&time1); + sceRtcGetCurrentClockLocalTime(&time2); + PSP_INFO_PRINT("time1, year[%d] month[%d] day[%d] hour[%d] minutes[%d] seconds[%d] us[%d]\n", time1.year, time1.month, time1.day, time1.hour, time1.minutes, time1.seconds, time1.microseconds); + PSP_INFO_PRINT("time2, year[%d] month[%d] day[%d] hour[%d] minutes[%d] seconds[%d] us[%d]\n", time2.year, time2.month, time2.day, time2.hour, time2.minutes, time2.seconds, time2.microseconds); +} + +void test_getMicros() { + uint32 time1, time2, time3, time4; + time1 = PspRtc::instance().getMicros(); + time2 = PspRtc::instance().getMicros(); + time3 = PspRtc::instance().getMicros(); + time4 = PspRtc::instance().getMicros(); + + PSP_INFO_PRINT("getMicros() times: %d, %d, %d\n", time4-time3, time3-time2, time2-time1); +} + +void read_and_time(uint32 bytes, char *buffer, FILE *file) { + uint32 time1 = PspRtc::instance().getMicros(); + // test minimal read + fread(buffer, bytes, 1, file); + uint32 time2 = PspRtc::instance().getMicros(); + + PSP_INFO_PRINT("Reading %d byte takes %dus\n", bytes, time2-time1); +} + +/* + 333MHz/222MHz + Reading 1 byte takes 2590us / 3167 + Reading 10 byte takes 8us / 9 + Reading 50 byte takes 8us / 11 + Reading 100 byte takes 8us / 11 + Reading 1000 byte takes 915us / 1131 + Reading 1000 byte takes 911us + Reading 1000 byte takes 914us + Reading 1000 byte takes 943us + Reading 1000 byte takes 915us + Reading 1000 byte takes 923us + Reading 1000 byte takes 22us + Reading 1000 byte takes 916us + Reading 1000 byte takes 913us / 1,120 + Reading 1000 byte takes 909us / 1,122 + Reading 2000 byte takes 1806us / 2,284 + Reading 3000 byte takes 2697us / 3,374 + Reading 4000 byte takes 3652us / 4,592 + Reading 5000 byte takes 4551us / 5,544 + Reading 6000 byte takes 5356us / 6,676 + Reading 7000 byte takes 6800us / 8,358 + Reading 8000 byte takes 6794us / 8,454 + Reading 9000 byte takes 6782us / 8,563 + Reading 10000 byte takes 8497us / 10,631 + Reading 30000 byte takes 25995us / 32,473 + Reading 50000 byte takes 42467us / 52,893 + Reading 80000 byte takes 68457us / 85,291 + Reading 100000 byte takes 85103us / 106,163 + Reading 500000 byte takes 427337us / 531,679 + Reading 1000000 byte takes 854831us / 1,063,107 +*/ +// Function to test the impact of MS reads +// These tests can't be done from shell - the cache screws them up +void test_ms_reads() { + FILE *file; + file = fopen("ms0:/psp/music/track1.mp3", "r"); + + char *buffer = (char *)malloc(2 * 1024 * 1024); + + read_and_time(1, buffer, file); + read_and_time(10, buffer, file); + read_and_time(50, buffer, file); + read_and_time(100, buffer, file); + for (int i = 0; i< 10; i++) + read_and_time(1000, buffer, file); + read_and_time(2000, buffer, file); + read_and_time(3000, buffer, file); + read_and_time(4000, buffer, file); + read_and_time(5000, buffer, file); + read_and_time(6000, buffer, file); + read_and_time(7000, buffer, file); + read_and_time(8000, buffer, file); + read_and_time(9000, buffer, file); + read_and_time(10000, buffer, file); + read_and_time(30000, buffer, file); + read_and_time(50000, buffer, file); + read_and_time(80000, buffer, file); + read_and_time(100000, buffer, file); + read_and_time(500000, buffer, file); + read_and_time(1000000, buffer, file); + + fclose(file); + free(buffer); +} + +void seek_and_time(int bytes, int origin, FILE *file) { + char buffer[1000]; + + uint32 time1 = PspRtc::instance().getMicros(); + // test minimal read + fseek(file, bytes, origin); + uint32 time2 = PspRtc::instance().getMicros(); + + PSP_INFO_PRINT("Seeking %d byte from %d took %dus\n", bytes, origin, time2-time1); + + time1 = PspRtc::instance().getMicros(); + // test minimal read + fread(buffer, 1000, 1, file); + time2 = PspRtc::instance().getMicros(); + + PSP_INFO_PRINT("Reading 1000 bytes took %dus\n", time2-time1); +} + +/* +333MHz +Seeking 0 byte from 0 took 946us +Reading 1000 bytes took 1781us +Seeking 5 byte from 0 took 6us +Reading 1000 bytes took 19us +Seeking 1000 byte from 0 took 5us +Reading 1000 bytes took 913us +Seeking 100 byte from 0 took 955us +Reading 1000 bytes took 906us +Seeking 10000 byte from 0 took 963us +Reading 1000 bytes took 905us +Seeking -5 byte from 1 took 1022us +Reading 1000 bytes took 949us +Seeking -100 byte from 1 took 1040us +Reading 1000 bytes took 907us +Seeking 100 byte from 1 took 1044us +Reading 1000 bytes took 930us +Seeking 0 byte from 2 took 7211us +Reading 1000 bytes took 80us +Seeking 10000 byte from 2 took 3636us +Reading 1000 bytes took 110us +*/ + +void test_seeks() { + FILE *file; + file = fopen("ms0:/psp/music/track1.mp3", "r"); + + seek_and_time(0, SEEK_SET, file); + seek_and_time(5, SEEK_SET, file); + seek_and_time(1000, SEEK_SET, file); + seek_and_time(100, SEEK_SET, file); + seek_and_time(10000, SEEK_SET, file); + seek_and_time(-5, SEEK_CUR, file); + seek_and_time(-100, SEEK_CUR, file); + seek_and_time(100, SEEK_CUR, file); + seek_and_time(0, SEEK_END, file); + seek_and_time(-10000, SEEK_END, file); + + fclose(file); +} + +// 222: 5-7us +int testGetThreadId() { + uint32 time1 = PspRtc::instance().getMicros(); + int threadId = sceKernelGetThreadId(); + uint32 time2 = PspRtc::instance().getMicros(); + + PSP_INFO_PRINT("Getting thread ID %d took %dus\n", threadId, time2-time1); + + return threadId; +} + +// 222: 4-5us +void testGetPriority() { + uint32 time1 = PspRtc::instance().getMicros(); + int priority = sceKernelGetThreadCurrentPriority(); + uint32 time2 = PspRtc::instance().getMicros(); + + PSP_INFO_PRINT("Getting thread priority %d took %dus\n", priority, time2-time1); +} + +// 222: 9-10us +void testChangePriority(int id, int priority) { + uint32 time1 = PspRtc::instance().getMicros(); + sceKernelChangeThreadPriority(id, priority); + uint32 time2 = PspRtc::instance().getMicros(); + + PSP_INFO_PRINT("Changing thread priority to %d for id %d took %dus\n", priority, id, time2-time1); +} + +void test_thread() { + int id; + id = testGetThreadId(); + testGetThreadId(); + testGetPriority(); + testGetPriority(); + testChangePriority(id, 30); + testChangePriority(id, 35); + testChangePriority(id, 25); + + // test context switch time + for (int i=0; i<10; i++) { + uint time1 = PspRtc::instance().getMicros(); + PspThread::delayMicros(0); + uint time2 = PspRtc::instance().getMicros(); + PSP_INFO_PRINT("poll %d. context switch Time = %dus\n", i, time2-time1); // 10-15us + } +} + +int test_mem_read(uint32 words) { + uint32 __attribute__((aligned(64))) buffer[1024]; + register uint32 r = 0; + + // uncached + uint32 *pBuffer = (uint32 *)UNCACHED(buffer); + + uint32 time1 = PspRtc::instance().getMicros(); + + for (int i=0; i