📄 cache.c
字号:
/*
* Copyright 1999, 2000, 2001, 2002 Lucent Technologies Inc.
* All Rights Reserved.
* Information Sciences Research Center, Bell Labs.
*
* LUCENT TECHNOLOGIES DOES NOT CLAIM MERCHANTABILITY OF THIS SOFTWARE
* OR THE SUITABILITY OF THIS SOFTWARE FOR ANY PARTICULAR PURPOSE. The
* software is provided "as is" without expressed or implied warranty
* of any kind.
*
* These notices must be retained in any copies of any part of this
* software.
*
*/
/*
* Cache testing
*
* Runs in user mode with interrupts enabled.
*/
#include "pebble.h"
#include "string.h"
#include "machine/cpu.h"
#ifndef Cobalt
#include "sbd.h"
#include "rtc.h"
#else
#include "qube.h"
#endif
#include "mem.h"
#include "time.h"
#ifndef Cobalt /* !Cobalt */
#include "perfcount.h"
#define MEM_START 0
#define MEM_SIZE 4*1024*1024
#define SMALLEST_SIZE 8*1024
#define CACHE_LINE 32
/* driver initialization thread */
int main()
{
int x; /* debug */
volatile char *p, *end;
int i, ntimes;
int size, sum;
int perf_ix;
uint perf_count;
uvlong start_time, elapsed;
printf("cache test. asid=%d stack at %p\n", get_asid(), &x);
/* verify that we are running in user mode with interrupts enabled */
if (!check_psw(1,1)) {
printf("cache: invalid processor status: %08lx\n", get_psw());
task_exit(1);
}
for (size = SMALLEST_SIZE; size <= MEM_SIZE; size <<= 1) {
printf("=============\n");
printf("testing uncached memory scan of %d bytes area\n", size);
ntimes = MEM_SIZE / size;
sum = 0;
/* initial scan to fill the cache */
p = (volatile char *)(IO_BASE + MEM_START);
end = p + size;
for (; p < end; p += CACHE_LINE)
sum += *p;
for (perf_ix = 0; perf_vec[perf_ix].name != NULL; perf_ix++) {
set_perf_ctrl(perf_vec[perf_ix].ctrl);
start_time = hrtime();
for (i = 0; i < ntimes; i++) {
p = (volatile char *)(IO_BASE + MEM_START);
for (; p < end; p += CACHE_LINE)
sum += *p;
}
perf_count = get_perf_count();
elapsed = 2 * (hrtime() - start_time);
printf("%s: %d\telapsed time: %d cycles (%d cycles/access) sum=%d\n",
perf_vec[perf_ix].name, perf_count,
(int)elapsed,
(int)(elapsed / (MEM_SIZE/CACHE_LINE)),
sum);
}
}
/*
* return to initialization code.
* cannot just "return", since the startup code (crt0.S) calls
* exit when main routine terminates.
*/
call_portal(SYS_RTN_RPC);
return(1);
}
#else /* !Cobalt */
/* driver initialization thread */
int main()
{
/*
* return to initialization code.
* cannot just "return", since the startup code (crt0.S) calls
* exit when main routine terminates.
*/
call_portal(SYS_RTN_RPC);
return(1);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -