More uniform tests. Added possibility to test without cache poisoning

This commit is contained in:
Abramo Bagnara 2003-02-21 10:09:36 +00:00
parent 64811d79ca
commit a91efc0fe6

View file

@ -63,7 +63,7 @@ static inline void atomic_add(volatile int *dst, int v)
__asm__ __volatile__( __asm__ __volatile__(
LOCK_PREFIX "addl %1,%0" LOCK_PREFIX "addl %1,%0"
:"=m" (*dst) :"=m" (*dst)
:"ir" (v)); :"ir" (v), "m" (*dst));
} }
static double detect_cpu_clock() static double detect_cpu_clock()
@ -88,18 +88,18 @@ static double detect_cpu_clock()
void mix_areas_srv(unsigned int size, void mix_areas_srv(unsigned int size,
const s16 *src, const s16 *src,
volatile s32 *sum, volatile s32 *sum,
unsigned int src_step) unsigned int src_step, unsigned int sum_step)
{ {
while (size-- > 0) { while (size-- > 0) {
atomic_add(sum, *src); atomic_add(sum, *src);
((char*)src) += src_step; ((char*)src) += src_step;
sum++; ((char*)sum) += sum_step;
} }
} }
void saturate(unsigned int size, void saturate(unsigned int size,
s16 *dst, const s32 *sum, s16 *dst, const s32 *sum,
unsigned int dst_step) unsigned int dst_step, unsigned int sum_step)
{ {
while (size-- > 0) { while (size-- > 0) {
s32 sample = *sum; s32 sample = *sum;
@ -110,7 +110,7 @@ void saturate(unsigned int size,
else else
*dst = sample; *dst = sample;
((char*)dst) += dst_step; ((char*)dst) += dst_step;
sum++; ((char*)sum) += sum_step;
} }
} }
@ -385,7 +385,7 @@ void setscheduler(void)
printf("!!!Scheduler set to Round Robin with priority %i FAILED!!!\n", sched_param.sched_priority); printf("!!!Scheduler set to Round Robin with priority %i FAILED!!!\n", sched_param.sched_priority);
} }
#define CACHE_SIZE (1024*1024) int cache_size = 1024*1024;
void init(s16 *dst, s32 *sum, int size) void init(s16 *dst, s32 *sum, int size)
{ {
@ -396,8 +396,8 @@ void init(s16 *dst, s32 *sum, int size)
*sum++ = 0; *sum++ = 0;
for (count = size - 1; count >= 0; count--) for (count = size - 1; count >= 0; count--)
*dst++ = 0; *dst++ = 0;
a = malloc(CACHE_SIZE); a = malloc(cache_size);
for (count = CACHE_SIZE - 1; count >= 0; count--) { for (count = cache_size - 1; count >= 0; count--) {
a[count] = count & 0xff; a[count] = count & 0xff;
a[count] ^= 0x55; a[count] ^= 0x55;
a[count] ^= 0xaa; a[count] ^= 0xaa;
@ -419,11 +419,13 @@ int main(int argc, char **argv)
#else #else
printf("CPU clock: %fMhz (SMP)\n\n", cpu_clock / 10e5); printf("CPU clock: %fMhz (SMP)\n\n", cpu_clock / 10e5);
#endif #endif
if (argc == 4) { if (argc > 3) {
size = atoi(argv[1]); size = atoi(argv[1]);
n = atoi(argv[2]); n = atoi(argv[2]);
max = atoi(argv[3]); max = atoi(argv[3]);
} }
if (argc > 4)
cache_size = atoi(argv[4]) * 1024;
s16 *dst = malloc(sizeof(*dst) * size); s16 *dst = malloc(sizeof(*dst) * size);
s32 *sum = calloc(size, sizeof(*sum)); s32 *sum = calloc(size, sizeof(*sum));
s16 **srcs = malloc(sizeof(*srcs) * n); s16 **srcs = malloc(sizeof(*srcs) * n);
@ -440,9 +442,9 @@ int main(int argc, char **argv)
init(dst, sum, size); init(dst, sum, size);
rdtscll(begin); rdtscll(begin);
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
mix_areas_srv(size, srcs[i], sum, 2); mix_areas_srv(size, srcs[i], sum, 2, 4);
} }
saturate(size, dst, sum, 2); saturate(size, dst, sum, 2, 4);
rdtscll(end); rdtscll(end);
diff = end - begin; diff = end - begin;
if (diff < diffS) if (diff < diffS)