Skip to content

Commit 5332f00

Browse files
committed
modifying and adding files adapter for esp32
1 parent d5fad6b commit 5332f00

File tree

4 files changed

+172
-4
lines changed

4 files changed

+172
-4
lines changed

CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
idf_component_register(SRCS
2+
"core_list_join.c"
3+
"core_main.c"
4+
"core_matrix.c"
5+
"core_state.c"
6+
"core_util.c"
7+
"posix/core_portme.c"
8+
INCLUDE_DIRS
9+
"."
10+
"posix")
11+
target_compile_options(${COMPONENT_LIB} PRIVATE ${CONFIG_OPTIMIZATION})

Kconfig.projbuild

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
menu "Example CoreMark Configuration"
2+
3+
# 编译优化等级参数
4+
choice COMPILER_FLAGS
5+
prompt "Compiler optimisation"
6+
default O3
7+
help
8+
Compiler optimization. For best CoreMark result select Turn on all.
9+
Pratically this is a choice between -O3 and -O0.
10+
11+
config O3
12+
bool "Turn on all(O3)"
13+
help
14+
Compile Coremark with -O3
15+
config O0
16+
bool "Turn off all(O0)"
17+
help
18+
Compile Coremark with -O0
19+
20+
endchoice
21+
22+
# 迭代次数
23+
config ITERATIONS
24+
int "Number of iterations"
25+
default 5000
26+
range 5000 50000
27+
help
28+
Select a number of iteration which enable the test to run for
29+
more than 10s.
30+
31+
# 启动核心数(单核 或 多核)
32+
config MULTI_THREADS
33+
bool "Multi-Threads"
34+
default n
35+
help
36+
Select the number of tasks to run in parallel.
37+
if you want to use multi-thread, you can select
38+
yes.
39+
40+
# CPU频率
41+
choice CPU_FREQUENCY
42+
prompt "cpu frequency"
43+
default ESP_DEFAULT_CPU_FREQ_MHZ_240
44+
help
45+
cpu frequency, 80MHz, 160MHz, 240MHz
46+
47+
config ESP_DEFAULT_CPU_FREQ_MHZ_80
48+
bool "80MHz"
49+
help
50+
80MHz
51+
52+
config ESP_DEFAULT_CPU_FREQ_MHZ_160
53+
bool "160MHz"
54+
help
55+
160MHz
56+
57+
config ESP_DEFAULT_CPU_FREQ_MHZ_240
58+
bool "240MHz"
59+
help
60+
240MHz
61+
62+
endchoice
63+
64+
config OPTIMIZATION
65+
string
66+
default "-O3" if O3
67+
default "-O0" if O0
68+
69+
endmenu

posix/core_portme.c

+69-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Original Author: Shay Gal-on
2323
#include <valgrind/callgrind.h>
2424
#endif
2525

26+
#if (MULTITHREAD > 1)
27+
static EventGroupHandle_t task_iterate_event_group;
28+
#endif
29+
2630
#if (MEM_METHOD == MEM_MALLOC)
2731
/* Function: portable_malloc
2832
Provide malloc() functionality in a platform specific way.
@@ -216,6 +220,18 @@ portable_init(core_portable *p, int *argc, char *argv[])
216220
}
217221
#endif
218222

223+
#if (SEED_METHOD == SEED_VOLATILE)
224+
#if VALIDATION_RUN
225+
ee_printf("--> VALIDATION_RUN\n");
226+
#endif
227+
#if PERFORMANCE_RUN
228+
ee_printf("--> PERFORMANCE_RUN\n");
229+
#endif
230+
#if PROFILE_RUN
231+
ee_printf("--> PROFILE_RUN\n");
232+
#endif
233+
#endif
234+
219235
(void)argc; // prevent unused warning
220236
(void)argv; // prevent unused warning
221237

@@ -234,6 +250,10 @@ portable_init(core_portable *p, int *argc, char *argv[])
234250
"ERROR! Main has no argc, but SEED_METHOD defined to SEED_ARG!\n");
235251
#endif
236252

253+
#if (MULTITHREAD > 1)
254+
task_iterate_event_group = xEventGroupCreate();
255+
#endif
256+
237257
#if (MULTITHREAD > 1) && (SEED_METHOD == SEED_ARG)
238258
int nargs = *argc, i;
239259
if ((nargs > 1) && (*argv[1] == 'M'))
@@ -278,18 +298,63 @@ portable_fini(core_portable *p)
278298
MCAPI or other standards can easily be devised.
279299
*/
280300
#if USE_PTHREAD
301+
// ee_u8
302+
// core_start_parallel(core_results *res)
303+
// {
304+
// return (ee_u8)pthread_create(
305+
// &(res->port.thread), NULL, iterate, (void *)res);
306+
// }
307+
// ee_u8
308+
// core_stop_parallel(core_results *res)
309+
// {
310+
// void *retval;
311+
// return (ee_u8)pthread_join(res->port.thread, &retval);
312+
// }
313+
314+
315+
void iterate_task(void *param)
316+
{
317+
core_results *res = (core_results *)param;
318+
319+
iterate(res);
320+
321+
xEventGroupSetBits(*(res->port.event_group), res->port.event_bit);
322+
323+
vTaskDelete(NULL);
324+
}
325+
326+
#define SIZE_NAME 16
327+
281328
ee_u8
282329
core_start_parallel(core_results *res)
283330
{
284-
return (ee_u8)pthread_create(
285-
&(res->port.thread), NULL, iterate, (void *)res);
331+
static BaseType_t core = 0;
332+
char name[SIZE_NAME + 1] = {0};
333+
334+
snprintf(name, SIZE_NAME, "iterate-%d", core);
335+
336+
res->port.event_bit = (1 << core);
337+
res->port.event_group = &task_iterate_event_group;
338+
339+
xTaskCreatePinnedToCore(iterate_task, name, 8192, res, 1, NULL, core);
340+
341+
core += 1;
342+
343+
return 1;
286344
}
345+
287346
ee_u8
288347
core_stop_parallel(core_results *res)
289348
{
290-
void *retval;
291-
return (ee_u8)pthread_join(res->port.thread, &retval);
349+
xEventGroupWaitBits(*(res->port.event_group),
350+
res->port.event_bit,
351+
false,
352+
false,
353+
120000 / portTICK_PERIOD_MS);
354+
355+
return 1;
292356
}
357+
293358
#elif USE_FORK
294359
static int key_id = 0;
295360
ee_u8

posix/core_portme.h

+23
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ Original Author: Shay Gal-on
2424
#define CORE_PORTME_H
2525

2626
#include "core_portme_posix_overrides.h"
27+
#include "../../../build/config/sdkconfig.h"
28+
#define COMPILER_FLAGS CONFIG_OPTIMIZATION // 编译优化等级
29+
30+
#ifdef CONFIG_MULTI_THREADS
31+
#define MULTITHREAD 2
32+
#define USE_PTHREAD 1
33+
#endif
34+
35+
#define MAIN_HAS_NOARGC 1
36+
37+
#define ITERATIONS CONFIG_ITERATIONS
38+
#define SEED_METHOD SEED_VOLATILE
39+
40+
#if (MULTITHREAD > 1)
41+
#include "freertos/FreeRTOS.h"
42+
#include "freertos/task.h"
43+
#include "freertos/event_groups.h"
44+
#endif
2745

2846
/************************/
2947
/* Data types and settings */
@@ -284,6 +302,11 @@ typedef struct CORE_PORTABLE_S
284302
#if (MULTITHREAD > 1)
285303
#if USE_PTHREAD
286304
pthread_t thread;
305+
306+
TaskHandle_t handle;
307+
ee_u32 event_bit;
308+
EventGroupHandle_t *event_group;
309+
287310
#elif USE_FORK
288311
pid_t pid;
289312
int shmid;

0 commit comments

Comments
 (0)