summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/test_mem.c161
1 files changed, 121 insertions, 40 deletions
diff --git a/apps/plugins/test_mem.c b/apps/plugins/test_mem.c
index f1c890e85c..e8f54c3ba6 100644
--- a/apps/plugins/test_mem.c
+++ b/apps/plugins/test_mem.c
@@ -7,7 +7,7 @@
7* \/ \/ \/ \/ \/ 7* \/ \/ \/ \/ \/
8* $Id$ 8* $Id$
9* 9*
10* Copyright (C) 2010 Thomas Martitz 10* Copyright (C) 2010 Thomas Martitz, Andree Buschmann
11* 11*
12* This program is free software; you can redistribute it and/or 12* This program is free software; you can redistribute it and/or
13* modify it under the terms of the GNU General Public License 13* modify it under the terms of the GNU General Public License
@@ -23,12 +23,111 @@
23 23
24PLUGIN_HEADER 24PLUGIN_HEADER
25 25
26#define BUF_SIZE ((PLUGIN_BUFFER_SIZE-(10<<10)) / (sizeof(int))) 26#define BUF_SIZE (1<<13) /* 32 KB = (1<<13)*sizeof(int) */
27#define LOOP_REPEAT 8 27
28static volatile int buf[BUF_SIZE]; 28#define LOOP_REPEAT_DRAM 256
29static volatile int buf_dram[BUF_SIZE];
30
31#if defined(PLUGIN_USE_IRAM)
32#define LOOP_REPEAT_IRAM 1024
33static volatile int buf_iram[BUF_SIZE] IBSS_ATTR;
34#endif
35
36/* (Byte per loop * loops)>>20 * ticks per s * 10 / ticks = dMB per s */
37#define dMB_PER_SEC(cnt, delta) ((((BUF_SIZE*sizeof(int)*cnt)>>20)*HZ*10)/delta)
38
39void write_test(volatile int *buf, int buf_size, int loop_cnt,
40 int line, char *ramtype)
41{
42 int delta, dMB;
43 int last_tick = *rb->current_tick;
44
45#if defined(CPU_ARM)
46 asm volatile (
47 "mov r0, #0 \n"
48 "mov r1, #1 \n"
49 "mov r2, #2 \n"
50 "mov r3, #3 \n"
51 "mov r6, %[loops] \n"
52 ".outer_loop_read: \n"
53 "mov r4, %[buf_p] \n"
54 "mov r5, %[size] \n"
55 ".inner_loop_read: \n"
56 "stmia r4!, {r0-r3} \n"
57 "stmia r4!, {r0-r3} \n"
58 "subs r5, r5, #8 \n"
59 "bgt .inner_loop_read \n"
60 "subs r6, r6, #1 \n"
61 "bgt .outer_loop_read \n"
62 :
63 : [loops] "r" (loop_cnt), [size] "r" (buf_size), [buf_p] "r" (buf)
64 : "r0", "r1", "r2", "r3", "r4", "r5", "r6"
65 );
66#else
67 int i, j;
68 for(i = 0; i < loop_cnt; i++)
69 {
70 for (j = 0; j < buf_size; j+=4)
71 {
72 buf[j ] = j;
73 buf[j+1] = j+1;
74 buf[j+2] = j+2;
75 buf[j+3] = j+3;
76 }
77 }
78#endif
79 delta = *rb->current_tick - last_tick;
80 delta = delta>0 ? delta : delta+1;
81 dMB = dMB_PER_SEC(loop_cnt, delta);
82 rb->screens[0]->putsf(0, line, "%s wr: %3d.%d MB/s (%2d ticks for %d MB)",
83 ramtype, dMB/10, dMB%10, delta,
84 (loop_cnt*BUF_SIZE*4)>>20);
85}
86
87void read_test(volatile int *buf, int buf_size, int loop_cnt,
88 int line, char *ramtype)
89{
90 int delta, dMB;
91 int last_tick = *rb->current_tick;
92
93#if defined(CPU_ARM)
94 asm volatile (
95 "mov r6, %[loops] \n"
96 ".outer_loop_write: \n"
97 "mov r4, %[buf_p] \n"
98 "mov r5, %[size] \n"
99 ".inner_loop_write: \n"
100 "ldmia r4!, {r0-r3} \n"
101 "ldmia r4!, {r0-r3} \n"
102 "subs r5, r5, #8 \n"
103 "bgt .inner_loop_write \n"
104 "subs r6, r6, #1 \n"
105 "bgt .outer_loop_write \n"
106 :
107 : [loops] "r" (loop_cnt), [size] "r" (buf_size), [buf_p] "r" (buf)
108 : "r0", "r1", "r2", "r3", "r4", "r5", "r6"
109 );
110#else
111 int i, j, x;
112 for(i = 0; i < loop_cnt; i++)
113 {
114 for(j = 0; j < buf_size; j+=4)
115 {
116 x = buf[j ];
117 x = buf[j+2];
118 x = buf[j+3];
119 x = buf[j+4];
120 }
121 }
122#endif
123 delta = *rb->current_tick - last_tick;
124 delta = delta>0 ? delta : delta+1;
125 dMB = dMB_PER_SEC(loop_cnt, delta);
126 rb->screens[0]->putsf(0, line, "%s rd: %3d.%d MB/s (%2d ticks for %d MB)",
127 ramtype, dMB/10, dMB%10, delta,
128 (loop_cnt*BUF_SIZE*4)>>20);
129}
29 130
30/* (Byte per loop * loops * ticks per s / ticks)>>10 = KB per s */
31#define KB_PER_SEC(delta) (((BUF_SIZE*sizeof(buf[0])*LOOP_REPEAT*HZ)/delta) >> 10)
32 131
33enum plugin_status plugin_start(const void* parameter) 132enum plugin_status plugin_start(const void* parameter)
34{ 133{
@@ -36,52 +135,34 @@ enum plugin_status plugin_start(const void* parameter)
36 bool done = false; 135 bool done = false;
37 bool boost = false; 136 bool boost = false;
38 int count = 0; 137 int count = 0;
39 int last_tick = 0;
40 138
41 rb->lcd_setfont(FONT_SYSFIXED); 139 rb->lcd_setfont(FONT_SYSFIXED);
140
141 rb->screens[0]->clear_display();
142 rb->screens[0]->putsf(0, 0, "patience, may take some seconds...");
143 rb->screens[0]->update();
42 144
43 while (!done) 145 while (!done)
44 { 146 {
45 unsigned i, j;
46 int line = 0; 147 int line = 0;
47 int x;
48 int delta;
49 last_tick = *rb->current_tick;
50 148
51 for(i = 0; i < LOOP_REPEAT; i++)
52 {
53 for (j = 0; j < BUF_SIZE; j+=4)
54 {
55 buf[j ] = j;
56 buf[j+1] = j+1;
57 buf[j+2] = j+2;
58 buf[j+3] = j+3;
59 }
60 }
61 delta = *rb->current_tick - last_tick;
62 rb->screens[0]->clear_display(); 149 rb->screens[0]->clear_display();
63 rb->screens[0]->putsf(0, line++, "%s", boost?"boosted":"unboosted"); 150 rb->screens[0]->putsf(0, line++, "%s", boost?"boosted":"unboosted");
64 rb->screens[0]->putsf(0, line++, "bufsize: %u", BUF_SIZE*sizeof(buf[0])); 151#ifndef SIMULATOR
152 rb->screens[0]->putsf(0, line++, "clock: %d Hz", *rb->cpu_frequency);
153#endif
65 rb->screens[0]->putsf(0, line++, "loop#: %d", ++count); 154 rb->screens[0]->putsf(0, line++, "loop#: %d", ++count);
66 rb->screens[0]->putsf(0, line++, "write ticks: %2d (%5d KB/s)", delta, 155
67 KB_PER_SEC(delta)); 156 read_test (buf_dram, BUF_SIZE, LOOP_REPEAT_DRAM, line++, "DRAM");
68 last_tick = *rb->current_tick; 157 write_test(buf_dram, BUF_SIZE, LOOP_REPEAT_DRAM, line++, "DRAM");
69 for(i = 0; i < LOOP_REPEAT; i++) 158#if defined(PLUGIN_USE_IRAM)
70 { 159 read_test (buf_iram, BUF_SIZE, LOOP_REPEAT_IRAM, line++, "IRAM");
71 for(j = 0; j < BUF_SIZE; j+=4) 160 write_test(buf_iram, BUF_SIZE, LOOP_REPEAT_IRAM, line++, "IRAM");
72 { 161#endif
73 x = buf[j ]; 162
74 x = buf[j+2];
75 x = buf[j+3];
76 x = buf[j+4];
77 }
78 }
79 delta = *rb->current_tick - last_tick;
80 rb->screens[0]->putsf(0, line++, "read ticks : %2d (%5d KB/s)", delta,
81 KB_PER_SEC(delta));
82 rb->screens[0]->update(); 163 rb->screens[0]->update();
83 164
84 switch (rb->get_action(CONTEXT_STD, TIMEOUT_NOBLOCK)) 165 switch (rb->get_action(CONTEXT_STD, HZ/5))
85 { 166 {
86#ifdef HAVE_ADJUSTABLE_CPU_FREQ 167#ifdef HAVE_ADJUSTABLE_CPU_FREQ
87 case ACTION_STD_PREV: 168 case ACTION_STD_PREV: