embox

Форк
0
/
core_main.c 
353 строки · 12.2 Кб
1
/*
2
Author : Shay Gal-On, EEMBC
3

4
This file is part of  EEMBC(R) and CoreMark(TM), which are Copyright (C) 2009 
5
All rights reserved.                            
6

7
EEMBC CoreMark Software is a product of EEMBC and is provided under the terms of the
8
CoreMark License that is distributed with the official EEMBC COREMARK Software release. 
9
If you received this EEMBC CoreMark Software without the accompanying CoreMark License, 
10
you must discontinue use and download the official release from www.coremark.org.  
11

12
Also, if you are publicly displaying scores generated from the EEMBC CoreMark software, 
13
make sure that you are in compliance with Run and Reporting rules specified in the accompanying readme.txt file.
14

15
EEMBC 
16
4354 Town Center Blvd. Suite 114-200
17
El Dorado Hills, CA, 95762 
18
*/ 
19
/* File: core_main.c
20
	This file contains the framework to acquire a block of memory, seed initial parameters, tun t he benchmark and report the results.
21
*/
22
#include "coremark.h"
23

24
/* Function: iterate
25
	Run the benchmark for a specified number of iterations.
26

27
	Operation:
28
	For each type of benchmarked algorithm:
29
		a - Initialize the data block for the algorithm.
30
		b - Execute the algorithm N times.
31

32
	Returns:
33
	NULL.
34
*/
35
static ee_u16 list_known_crc[]   =      {(ee_u16)0xd4b0,(ee_u16)0x3340,(ee_u16)0x6a79,(ee_u16)0xe714,(ee_u16)0xe3c1};
36
static ee_u16 matrix_known_crc[] =      {(ee_u16)0xbe52,(ee_u16)0x1199,(ee_u16)0x5608,(ee_u16)0x1fd7,(ee_u16)0x0747};
37
static ee_u16 state_known_crc[]  =      {(ee_u16)0x5e47,(ee_u16)0x39bf,(ee_u16)0xe5a4,(ee_u16)0x8e3a,(ee_u16)0x8d84};
38
void *iterate(void *pres) {
39
	ee_u32 i;
40
	ee_u16 crc;
41
	core_results *res=(core_results *)pres;
42
	ee_u32 iterations=res->iterations;
43
	res->crc=0;
44
	res->crclist=0;
45
	res->crcmatrix=0;
46
	res->crcstate=0;
47

48
	for (i=0; i<iterations; i++) {
49
		crc=core_bench_list(res,1);
50
		res->crc=crcu16(crc,res->crc);
51
		crc=core_bench_list(res,-1);
52
		res->crc=crcu16(crc,res->crc);
53
		if (i==0) res->crclist=res->crc;
54
	}
55
	return NULL;
56
}
57
#if (SEED_METHOD==SEED_ARG)
58
ee_s32 get_seed_args(int i, int argc, char *argv[]);
59
#define get_seed(x) (ee_s16)get_seed_args(x,argc,argv)
60
#define get_seed_32(x) get_seed_args(x,argc,argv)
61
#else /* via function or volatile */
62
ee_s32 get_seed_32(int i);
63
#define get_seed(x) (ee_s16)get_seed_32(x)
64
#endif
65

66
#if (MEM_METHOD==MEM_STATIC)
67
ee_u8 static_memblk[TOTAL_DATA_SIZE];
68
#endif
69
char *mem_name[3] = {"Static","Heap","Stack"};
70
/* Function: main
71
	Main entry routine for the benchmark.
72
	This function is responsible for the following steps:
73

74
	1 - Initialize input seeds from a source that cannot be determined at compile time.
75
	2 - Initialize memory block for use.
76
	3 - Run and time the benchmark.
77
	4 - Report results, testing the validity of the output if the seeds are known.
78

79
	Arguments:
80
	1 - first seed  : Any value
81
	2 - second seed : Must be identical to first for iterations to be identical
82
	3 - third seed  : Any value, should be at least an order of magnitude less then the input size, but bigger then 32.
83
	4 - Iterations  : Special, if set to 0, iterations will be automatically determined such that the benchmark will run between 10 to 100 secs
84

85
*/
86

87
#if MAIN_HAS_NOARGC
88
MAIN_RETURN_TYPE main(void) {
89
	int argc=0;
90
	char *argv[1];
91
#else
92
MAIN_RETURN_TYPE main(int argc, char *argv[]) {
93
#endif
94
	ee_u16 i,j=0,num_algorithms=0;
95
	ee_s16 known_id=-1,total_errors=0;
96
	ee_u16 seedcrc=0;
97
	CORE_TICKS total_time;
98
	core_results results[MULTITHREAD];
99
#if (MEM_METHOD==MEM_STACK)
100
	ee_u8 stack_memblock[TOTAL_DATA_SIZE*MULTITHREAD];
101
#endif
102
	/* first call any initializations needed */
103
	portable_init(&(results[0].port), &argc, argv);
104
	/* First some checks to make sure benchmark will run ok */
105
	if (sizeof(struct list_head_s)>128) {
106
		ee_printf("list_head structure too big for comparable data!\n");
107
		return MAIN_RETURN_VAL;
108
	}
109
	results[0].seed1=get_seed(1);
110
	results[0].seed2=get_seed(2);
111
	results[0].seed3=get_seed(3);
112
	results[0].iterations=get_seed_32(4);
113
#ifdef CORE_DEBUG
114
	results[0].iterations=1;
115
#endif
116
	results[0].execs=get_seed_32(5);
117
	if (results[0].execs==0) { /* if not supplied, execute all algorithms */
118
		results[0].execs=ALL_ALGORITHMS_MASK;
119
	}
120
		/* put in some default values based on one seed only for easy testing */
121
	if ((results[0].seed1==0) && (results[0].seed2==0) && (results[0].seed3==0)) { /* validation run */
122
		results[0].seed1=0;
123
		results[0].seed2=0;
124
		results[0].seed3=0x66;
125
	}
126
	if ((results[0].seed1==1) && (results[0].seed2==0) && (results[0].seed3==0)) { /* perfromance run */
127
		results[0].seed1=0x3415;
128
		results[0].seed2=0x3415;
129
		results[0].seed3=0x66;
130
	}
131
#if (MEM_METHOD==MEM_STATIC)
132
	results[0].memblock[0]=(void *)static_memblk;
133
	results[0].size=TOTAL_DATA_SIZE;
134
	results[0].err=0;
135
	#if (MULTITHREAD>1)
136
	#error "Cannot use a static data area with multiple contexts!"
137
	#endif
138
#elif (MEM_METHOD==MEM_MALLOC)
139
	for (i=0 ; i<MULTITHREAD; i++) {
140
		ee_s32 malloc_override=get_seed(7);
141
		if (malloc_override != 0) 
142
			results[i].size=malloc_override;
143
		else
144
			results[i].size=TOTAL_DATA_SIZE;
145
		results[i].memblock[0]=portable_malloc(results[i].size);
146
		results[i].seed1=results[0].seed1;
147
		results[i].seed2=results[0].seed2;
148
		results[i].seed3=results[0].seed3;
149
		results[i].err=0;
150
		results[i].execs=results[0].execs;
151
	}
152
#elif (MEM_METHOD==MEM_STACK)
153
	for (i=0 ; i<MULTITHREAD; i++) {
154
		results[i].memblock[0]=stack_memblock+i*TOTAL_DATA_SIZE;
155
		results[i].size=TOTAL_DATA_SIZE;
156
		results[i].seed1=results[0].seed1;
157
		results[i].seed2=results[0].seed2;
158
		results[i].seed3=results[0].seed3;
159
		results[i].err=0;
160
		results[i].execs=results[0].execs;
161
	}
162
#else
163
#error "Please define a way to initialize a memory block."
164
#endif
165
	/* Data init */ 
166
	/* Find out how space much we have based on number of algorithms */
167
	for (i=0; i<NUM_ALGORITHMS; i++) {
168
		if ((1<<(ee_u32)i) & results[0].execs)
169
			num_algorithms++;
170
	}
171
	for (i=0 ; i<MULTITHREAD; i++) 
172
		results[i].size=results[i].size/num_algorithms;
173
	/* Assign pointers */
174
	for (i=0; i<NUM_ALGORITHMS; i++) {
175
		ee_u32 ctx;
176
		if ((1<<(ee_u32)i) & results[0].execs) {
177
			for (ctx=0 ; ctx<MULTITHREAD; ctx++)
178
				results[ctx].memblock[i+1]=(char *)(results[ctx].memblock[0])+results[0].size*j;
179
			j++;
180
		}
181
	}
182
	/* call inits */
183
	for (i=0 ; i<MULTITHREAD; i++) {
184
		if (results[i].execs & ID_LIST) {
185
			results[i].list=core_list_init(results[0].size,results[i].memblock[1],results[i].seed1);
186
		}
187
		if (results[i].execs & ID_MATRIX) {
188
			core_init_matrix(results[0].size, results[i].memblock[2], (ee_s32)results[i].seed1 | (((ee_s32)results[i].seed2) << 16), &(results[i].mat) );
189
		}
190
		if (results[i].execs & ID_STATE) {
191
			core_init_state(results[0].size,results[i].seed1,results[i].memblock[3]);
192
		}
193
	}
194
	
195
	/* automatically determine number of iterations if not set */
196
	if (results[0].iterations==0) { 
197
		secs_ret secs_passed=0;
198
		ee_u32 divisor;
199
		results[0].iterations=1;
200
		while (secs_passed < (secs_ret)1) {
201
			results[0].iterations*=10;
202
			start_time();
203
			iterate(&results[0]);
204
			stop_time();
205
			secs_passed=time_in_secs(get_time());
206
		}
207
		/* now we know it executes for at least 1 sec, set actual run time at about 10 secs */
208
		divisor=(ee_u32)secs_passed;
209
		if (divisor==0) /* some machines cast float to int as 0 since this conversion is not defined by ANSI, but we know at least one second passed */
210
			divisor=1;
211
		results[0].iterations*=1+10/divisor;
212
	}
213
	/* perform actual benchmark */
214
	start_time();
215
#if (MULTITHREAD>1)
216
	if (default_num_contexts>MULTITHREAD) {
217
		default_num_contexts=MULTITHREAD;
218
	}
219
	for (i=0 ; i<default_num_contexts; i++) {
220
		results[i].iterations=results[0].iterations;
221
		results[i].execs=results[0].execs;
222
		core_start_parallel(&results[i]);
223
	}
224
	for (i=0 ; i<default_num_contexts; i++) {
225
		core_stop_parallel(&results[i]);
226
	}
227
#else
228
	iterate(&results[0]);
229
#endif
230
	stop_time();
231
	total_time=get_time();
232
	/* get a function of the input to report */
233
	seedcrc=crc16(results[0].seed1,seedcrc);
234
	seedcrc=crc16(results[0].seed2,seedcrc);
235
	seedcrc=crc16(results[0].seed3,seedcrc);
236
	seedcrc=crc16(results[0].size,seedcrc);
237
	
238
	switch (seedcrc) { /* test known output for common seeds */
239
		case 0x8a02: /* seed1=0, seed2=0, seed3=0x66, size 2000 per algorithm */
240
			known_id=0;
241
			ee_printf("6k performance run parameters for coremark.\n");
242
			break;
243
		case 0x7b05: /*  seed1=0x3415, seed2=0x3415, seed3=0x66, size 2000 per algorithm */
244
			known_id=1;
245
			ee_printf("6k validation run parameters for coremark.\n");
246
			break;
247
		case 0x4eaf: /* seed1=0x8, seed2=0x8, seed3=0x8, size 400 per algorithm */
248
			known_id=2;
249
			ee_printf("Profile generation run parameters for coremark.\n");
250
			break;
251
		case 0xe9f5: /* seed1=0, seed2=0, seed3=0x66, size 666 per algorithm */
252
			known_id=3;
253
			ee_printf("2K performance run parameters for coremark.\n");
254
			break;
255
		case 0x18f2: /*  seed1=0x3415, seed2=0x3415, seed3=0x66, size 666 per algorithm */
256
			known_id=4;
257
			ee_printf("2K validation run parameters for coremark.\n");
258
			break;
259
		default:
260
			total_errors=-1;
261
			break;
262
	}
263
	if (known_id>=0) {
264
		for (i=0 ; i<default_num_contexts; i++) {
265
			results[i].err=0;
266
			if ((results[i].execs & ID_LIST) && 
267
				(results[i].crclist!=list_known_crc[known_id])) {
268
				ee_printf("[%u]ERROR! list crc 0x%04x - should be 0x%04x\n",i,results[i].crclist,list_known_crc[known_id]);
269
				results[i].err++;
270
			}
271
			if ((results[i].execs & ID_MATRIX) &&
272
				(results[i].crcmatrix!=matrix_known_crc[known_id])) {
273
				ee_printf("[%u]ERROR! matrix crc 0x%04x - should be 0x%04x\n",i,results[i].crcmatrix,matrix_known_crc[known_id]);
274
				results[i].err++;
275
			}
276
			if ((results[i].execs & ID_STATE) &&
277
				(results[i].crcstate!=state_known_crc[known_id])) {
278
				ee_printf("[%u]ERROR! state crc 0x%04x - should be 0x%04x\n",i,results[i].crcstate,state_known_crc[known_id]);
279
				results[i].err++;
280
			}
281
			total_errors+=results[i].err;
282
		}
283
	}
284
	total_errors+=check_data_types();
285
	/* and report results */
286
	ee_printf("CoreMark Size    : %lu\n",(ee_u32)results[0].size);
287
	ee_printf("Total ticks      : %lu\n",(ee_u32)total_time);
288
#if HAS_FLOAT
289
	ee_printf("Total time (secs): %f\n",time_in_secs(total_time));
290
	if (time_in_secs(total_time) > 0)
291
		ee_printf("Iterations/Sec   : %f\n",default_num_contexts*results[0].iterations/time_in_secs(total_time));
292
#else 
293
	ee_printf("Total time (secs): %d\n",time_in_secs(total_time));
294
	if (time_in_secs(total_time) > 0)
295
		ee_printf("Iterations/Sec   : %d\n",default_num_contexts*results[0].iterations/time_in_secs(total_time));
296
#endif
297
	if (time_in_secs(total_time) < 10) {
298
		ee_printf("ERROR! Must execute for at least 10 secs for a valid result!\n");
299
		total_errors++;
300
	}
301

302
	ee_printf("Iterations       : %lu\n",(ee_u32)default_num_contexts*results[0].iterations);
303
	ee_printf("Compiler version : %s\n",COMPILER_VERSION);
304
	ee_printf("Compiler flags   : %s\n",COMPILER_FLAGS);
305
#if (MULTITHREAD>1)
306
	ee_printf("Parallel %s : %d\n",PARALLEL_METHOD,default_num_contexts);
307
#endif
308
	ee_printf("Memory location  : %s\n",MEM_LOCATION);
309
	/* output for verification */
310
	ee_printf("seedcrc          : 0x%04x\n",seedcrc);
311
	if (results[0].execs & ID_LIST)
312
		for (i=0 ; i<default_num_contexts; i++) 
313
			ee_printf("[%d]crclist       : 0x%04x\n",i,results[i].crclist);
314
	if (results[0].execs & ID_MATRIX) 
315
		for (i=0 ; i<default_num_contexts; i++) 
316
			ee_printf("[%d]crcmatrix     : 0x%04x\n",i,results[i].crcmatrix);
317
	if (results[0].execs & ID_STATE)
318
		for (i=0 ; i<default_num_contexts; i++) 
319
			ee_printf("[%d]crcstate      : 0x%04x\n",i,results[i].crcstate);
320
	for (i=0 ; i<default_num_contexts; i++) 
321
		ee_printf("[%d]crcfinal      : 0x%04x\n",i,results[i].crc);
322
	if (total_errors==0) {
323
		ee_printf("Correct operation validated. See readme.txt for run and reporting rules.\n");
324
#if HAS_FLOAT
325
		if (known_id==3) {
326
			ee_printf("CoreMark 1.0 : %f / %s %s",default_num_contexts*results[0].iterations/time_in_secs(total_time),COMPILER_VERSION,COMPILER_FLAGS);
327
#if defined(MEM_LOCATION) && !defined(MEM_LOCATION_UNSPEC)
328
			ee_printf(" / %s",MEM_LOCATION);
329
#else
330
			ee_printf(" / %s",mem_name[MEM_METHOD]);
331
#endif
332

333
#if (MULTITHREAD>1)
334
			ee_printf(" / %d:%s",default_num_contexts,PARALLEL_METHOD);
335
#endif
336
			ee_printf("\n");
337
		}
338
#endif
339
	}
340
	if (total_errors>0)
341
		ee_printf("Errors detected\n");
342
	if (total_errors<0)
343
		ee_printf("Cannot validate operation for these seed values, please compare with results on a known platform.\n");
344

345
#if (MEM_METHOD==MEM_MALLOC)
346
	for (i=0 ; i<MULTITHREAD; i++) 
347
		portable_free(results[i].memblock[0]);
348
#endif
349
	/* And last call any target specific code for finalizing */
350
	portable_fini(&(results[0].port));
351

352
	return MAIN_RETURN_VAL;	
353
}
354

355

356

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.