3 #include <cyg/diagnosis/diagnosis.h>
4 #include <cyg/hal/plf_io.h>
6 #include CYGHWR_MEMORY_LAYOUT_H
9 static unsigned int pattern1, pattern2;
10 static unsigned int start;
14 local_cmd_entry("ram_rw",
15 "ram read/write accessing",
16 "-c iterators -b <base address> -l <length> "\
17 "-p pattern -m case [-s]\n",
22 local_cmd_entry("memcpybm",
23 "ram memory copy benchmarking",
24 "-c <loops> -s <start size KB> -e <end size KB> -a <source align Byte> -b <dest align Byte>\n",
29 static void raw_rw_case1(void)
31 unsigned int * current_write;
32 unsigned int * current_read;
34 diag_printf("RAM diagnostical pattern from David.Young of freescale\n");
35 diag_printf("burst is %s\n", burst?"enabled":"disabled");
36 while( (round++) < loops1) {
40 current_write = (unsigned int *)start;
41 memset(current_write, (pattern1 & 0xFF000000) >> 24, length);
43 for (current_write = (unsigned int *)start;
44 current_write < (unsigned int *)(start + length);
46 *current_write = ((unsigned int)current_write & 0x0000FFFF) |
47 (0xFFFF0000 & pattern1);
49 for (current_write = (unsigned int *)start + 1;
50 current_write < (unsigned int *)(start + length);
52 *current_write = ((unsigned int)current_write & 0x0000FFFF) |
53 (0xFFFF0000 & pattern2);
56 for (current_read = (unsigned int *)start;
57 current_read<(unsigned int *)(start + length);
60 if ((*current_read) != pattern2) {
61 diag_printf("\tround %d::[%p]=0x%08x:0x%08x\n", round,
62 current_read, pattern2, *current_read);
66 if((current_read - (unsigned int *)start) & 1) {
67 if(((*current_read)&0xFFFF0000) != (pattern2&0xFFFF0000)) {
68 diag_printf("\tround %d::[%p]=0x%08x:0x%08x\n", round,
69 current_read, (pattern2 & 0xFFFF0000) |
70 (((unsigned int)current_read) & 0xFFFF),
75 if(((*current_read)&0xFFFF0000) != (pattern1&0xFFFF0000)) {
76 diag_printf("\tround %d::[%p]=0x%08x:0x%08x\n", round,
77 current_read, (pattern1 & 0xFFFF0000) |
78 (((unsigned int)current_read) & 0xFFFF),
86 diag_printf("Diagnosis is successful!\n");
89 diag_printf("Diagnosis is failure !\n");
92 static void ram_rw_test(int argc, char * argv[])
95 struct option_info opts[6];
98 memset(opts_map, 0, sizeof(int)*6);
100 init_opts(&opts[0], 'c', true, OPTION_ARG_TYPE_NUM,
101 &loops1, &opts_map[0], "the rounds of test");
102 init_opts(&opts[1], 'b', true, OPTION_ARG_TYPE_NUM,
103 &start, &opts_map[1], "accessing start address");
104 init_opts(&opts[2], 'l', true, OPTION_ARG_TYPE_NUM,
105 &length, &opts_map[2], "accessing size(bytes)");
106 init_opts(&opts[3], 'p', true, OPTION_ARG_TYPE_NUM,
107 &pattern1, &opts_map[3], "High 16bit is valid");
108 init_opts(&opts[4], 'm', true, OPTION_ARG_TYPE_NUM,
109 &mode, &opts_map[4], "Test case number");
110 init_opts(&opts[5], 's', false, OPTION_ARG_TYPE_FLG,
111 &burst, NULL, "enable bust mode(based on memset)");
113 if (!scan_opts(argc, argv, 2, opts, 6, 0, 0, 0)) {
114 diagnosis_usage("invalid arguments");
131 pattern1 = 0x55550000;
135 mode = DIAGNOSIS_MEM_RAM_RD;
139 pattern2 = (pattern1&0xFF000000);
140 pattern2 |= pattern2>>8;
141 pattern2 |= pattern2>>16;
143 pattern2 = (~pattern1)&0xFFFF0000;
146 if(!valid_address((unsigned char *)start)) {
147 if (!verify_action("Specified address (%p) is not believed to be in RAM", (void*)start))
152 case DIAGNOSIS_MEM_RAM_RD:
156 diag_printf("Invalid memory diagnosis case!\n");
162 #define SIZE_4K (4*SIZE_1K)
163 #define SIZE_1M (1024*1024)
164 #define START_SIZE (2*SIZE_1K)
165 #define END_SIZE SIZE_1M
166 #define ALIGN SIZE_4K
167 #define START_LOOPS 200000
170 #define printf diag_printf
171 #define CLOCKS_PER_SEC 32768
172 extern unsigned int hal_timer_count(void);
173 #define clock() hal_timer_count()
175 //#define memcpy diagnosis_mem_copy_block
176 static void memcpybm(int argc, char * argv[])
178 int opts_map[OPT_SIZE];
179 struct option_info opts[OPT_SIZE];
180 int size = START_SIZE / SIZE_1K;
181 int end_size = END_SIZE / SIZE_1K;
184 int loops = START_LOOPS / 1000;
185 int src, dst, asrc, adst;
188 memset(opts_map, 0, sizeof(int)*OPT_SIZE);
190 init_opts(&opts[0], 'c', true, OPTION_ARG_TYPE_NUM,
191 &loops, &opts_map[0], "the rounds of test in thousands");
192 init_opts(&opts[1], 's', true, OPTION_ARG_TYPE_NUM,
193 &size, &opts_map[1], "start size in KB");
194 init_opts(&opts[2], 'e', true, OPTION_ARG_TYPE_NUM,
195 &end_size, &opts_map[2], "end size in KB");
196 init_opts(&opts[3], 'a', true, OPTION_ARG_TYPE_NUM,
197 &salign, &opts_map[3], "source align in byte");
198 init_opts(&opts[4], 'b', true, OPTION_ARG_TYPE_NUM,
199 &dalign, &opts_map[4], "destination align in byte");
201 if (!scan_opts(argc, argv, 2, opts, OPT_SIZE, 0, 0, 0)) {
202 diagnosis_usage("invalid arguments");
209 /* Allocate buffers */
210 if ((src = (int) malloc(end_size + salign + SIZE_4K)) == 0) {
211 printf("%s: insufficient memory\n", argv[0]);
214 memset((void*)src, 0xaa, end_size + salign + SIZE_4K);
215 if ((dst = (int) malloc(end_size + dalign + SIZE_4K)) == 0) {
217 printf("%s: insuficient memory\n", argv[0]);
220 memset((void*)dst, 0x55, end_size + dalign + SIZE_4K);
223 if (src % SIZE_4K == 0)
226 asrc = src + SIZE_4K - (src % SIZE_4K) + salign;
227 if (dst % SIZE_4K == 0)
230 adst = dst + SIZE_4K - (dst % SIZE_4K) + dalign;
233 printf("\nMEMCPY Benchmark\n\n");
234 printf("Src Buffer 0x%08x\n", asrc);
235 printf("Dst Buffer 0x%08x\n\n", adst);
236 printf("%10s %10s\n", "Cached", "Bandwidth");
237 printf("%10s %10s\n", "(KBytes)", "(MB/sec)");
239 /* Loop over copy sizes */
240 while (size <= end_size)
242 unsigned int start_time;
243 unsigned int elapsed_time;
245 unsigned long long sz;
247 printf("%10d", size / SIZE_1K);
250 start_time = clock();
251 for (loop = 0; loop < loops; loop++)
252 memcpy((void*)adst, (void*)asrc, size);
253 elapsed_time = (clock() - start_time);
255 sz = size *loops * 2;
256 printf(" %llu", sz * CLOCKS_PER_SEC / elapsed_time / SIZE_1M);
257 printf("\t elapsed=%u", elapsed_time);
258 printf("\tsize=%d, loops=%d, sz=%llu", size, loops, sz);
262 printf(" %10.0f\n", ((float)size*loops*2)/elapsed_time/SIZE_1M);
263 printf(" %d.%d.%d\n", elapsed_time / CLOCKS_PER_SEC,
264 (elapsed_time % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC,
265 (((elapsed_time % CLOCKS_PER_SEC) * 1000) % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
267 /* Adjust for next test */