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; current_write<(unsigned int *)(start + length); current_write += 2) {
44 *current_write = ((unsigned int)current_write & 0x0000FFFF)|(0xFFFF0000 & pattern1);
46 for(current_write=(unsigned int *)start + 1; current_write<(unsigned int *)(start + length); current_write += 2) {
47 *current_write = ((unsigned int)current_write & 0x0000FFFF)|(0xFFFF0000 & pattern2);
50 for(current_read=(unsigned int *)start; current_read<(unsigned int *)(start + length); current_read ++) {
52 if((*current_read) != pattern2) {
53 diag_printf("\tround %d::[0x%08x]=0x%08x:0x%08x\n", round, current_read, pattern2, *current_read);
57 if((current_read - (unsigned int *)start) & 1) {
58 if(((*current_read)&0xFFFF0000) != (pattern2&0xFFFF0000)) {
59 diag_printf("\tround %d::[0x%08x]=0x%08x:0x%08x\n", round, current_read, (pattern2&0xFFFF0000)|((unsigned int)current_read)&0xFFFF, *current_read);
63 if(((*current_read)&0xFFFF0000) != (pattern1&0xFFFF0000)) {
64 diag_printf("\tround %d::[0x%08x]=0x%08x:0x%08x\n", round, current_read, (pattern1&0xFFFF0000)|((unsigned int)current_read)&0xFFFF, *current_read);
71 diag_printf("Diagnosis is successful!\n");
74 diag_printf("Diagnosis is failure !\n");
77 static void ram_rw_test(int argc, char * argv[])
80 struct option_info opts[6];
83 memset(opts_map, 0, sizeof(int)*6);
85 init_opts(&opts[0], 'c', true, OPTION_ARG_TYPE_NUM,
86 (void *)&loops1, (bool *)&opts_map[0], "the rounds of test");
87 init_opts(&opts[1], 'b', true, OPTION_ARG_TYPE_NUM,
88 (void *)&start, (bool *)&opts_map[1], "accessing start address");
89 init_opts(&opts[2], 'l', true, OPTION_ARG_TYPE_NUM,
90 (void *)&length, (bool *)&opts_map[2], "accessing size(bytes)");
91 init_opts(&opts[3], 'p', true, OPTION_ARG_TYPE_NUM,
92 (void *)&pattern1, (bool *)&opts_map[3], "High 16bit is valid");
93 init_opts(&opts[4], 'm', true, OPTION_ARG_TYPE_NUM,
94 (void *)&mode, (bool *)&opts_map[4], "Test case number");
95 init_opts(&opts[5], 's', false, OPTION_ARG_TYPE_FLG,
96 (void *)&burst, (bool *)0, "enable bust mode(based on memset)");
98 if (!scan_opts(argc, argv, 2, opts, 6, 0, 0, 0)) {
99 diagnosis_usage("invalid arguments");
116 pattern1 = 0x55550000;
120 mode = DIAGNOSIS_MEM_RAM_RD;
124 pattern2 = (pattern1&0xFF000000);
125 pattern2 |= pattern2>>8;
126 pattern2 |= pattern2>>16;
128 pattern2 = (~pattern1)&0xFFFF0000;
131 if(!valid_address((unsigned char *)start)) {
132 if (!verify_action("Specified address (%p) is not believed to be in RAM", (void*)start))
137 case DIAGNOSIS_MEM_RAM_RD:
141 diag_printf("Invalid memory diagnosis case!\n");
147 #define SIZE_4K (4*SIZE_1K)
148 #define SIZE_1M (1024*1024)
149 #define START_SIZE (2*SIZE_1K)
150 #define END_SIZE SIZE_1M
151 #define ALIGN SIZE_4K
152 #define START_LOOPS 200000
155 #define printf diag_printf
156 #define CLOCKS_PER_SEC 32768
157 extern unsigned int hal_timer_count(void);
158 #define clock() hal_timer_count()
160 //#define memcpy diagnosis_mem_copy_block
161 static void memcpybm(int argc, char * argv[])
163 int opts_map[OPT_SIZE];
164 struct option_info opts[OPT_SIZE];
166 int size = START_SIZE / SIZE_1K;
167 int end_size = END_SIZE / SIZE_1K;
170 int loops = START_LOOPS / 1000;
171 int src, dst, asrc, adst;
174 memset(opts_map, 0, sizeof(int)*OPT_SIZE);
176 init_opts(&opts[0], 'c', true, OPTION_ARG_TYPE_NUM,
177 (void *)&loops, (bool *)&opts_map[0], "the rounds of test in thousands");
178 init_opts(&opts[1], 's', true, OPTION_ARG_TYPE_NUM,
179 (void *)&size, (bool *)&opts_map[1], "start size in KB");
180 init_opts(&opts[2], 'e', true, OPTION_ARG_TYPE_NUM,
181 (void *)&end_size, (bool *)&opts_map[2], "end size in KB");
182 init_opts(&opts[3], 'a', true, OPTION_ARG_TYPE_NUM,
183 (void *)&salign, (bool *)&opts_map[3], "source align in byte");
184 init_opts(&opts[4], 'b', true, OPTION_ARG_TYPE_NUM,
185 (void *)&dalign, (bool *)&opts_map[4], "destination align in byte");
187 if (!scan_opts(argc, argv, 2, opts, OPT_SIZE, 0, 0, 0)) {
188 diagnosis_usage("invalid arguments");
195 /* Allocate buffers */
196 if ((src = (int) malloc(end_size + salign + SIZE_4K)) == 0) {
197 printf("%s: insufficient memory\n", argv[0]);
200 memset((void*)src, 0xaa, end_size + salign + SIZE_4K);
201 if ((dst = (int) malloc(end_size + dalign + SIZE_4K)) == 0) {
203 printf("%s: insuficient memory\n", argv[0]);
206 memset((void*)dst, 0x55, end_size + dalign + SIZE_4K);
209 if (src % SIZE_4K == 0)
212 asrc = src + SIZE_4K - (src % SIZE_4K) + salign;
213 if (dst % SIZE_4K == 0)
216 adst = dst + SIZE_4K - (dst % SIZE_4K) + dalign;
219 printf("\nMEMCPY Benchmark\n\n");
220 printf("Src Buffer 0x%08x\n", asrc);
221 printf("Dst Buffer 0x%08x\n\n", adst);
222 printf("%10s %10s\n", "Cached", "Bandwidth");
223 printf("%10s %10s\n", "(KBytes)", "(MB/sec)");
225 /* Loop over copy sizes */
226 while (size <= end_size)
228 unsigned int start_time;
229 unsigned int elapsed_time;
231 unsigned long long sz;
233 printf("%10d", size / SIZE_1K);
236 start_time = clock();
237 for (loop = 0; loop < loops; loop++)
238 memcpy((void*)adst, (void*)asrc, size);
239 elapsed_time = (clock() - start_time);
241 sz = size *loops * 2;
242 printf(" %d", sz*CLOCKS_PER_SEC/elapsed_time/SIZE_1M);
243 printf("\t elapsed=%d", elapsed_time);
244 printf("\tsize=%d, loops=%d, sz=%d", size, loops, sz);
248 printf(" %10.0f\n", ((float)size*loops*2)/elapsed_time/SIZE_1M);
249 printf(" %d.%d.%d\n", elapsed_time / CLOCKS_PER_SEC,
250 (elapsed_time % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC,
251 (((elapsed_time % CLOCKS_PER_SEC) * 1000) % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
253 /* Adjust for next test */