-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathCpuAffinity.cpp
More file actions
91 lines (77 loc) · 2 KB
/
CpuAffinity.cpp
File metadata and controls
91 lines (77 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "Tactility/CpuAffinity.h"
#include <Tactility/Check.h>
namespace tt {
#ifdef ESP_PLATFORM
#if CONFIG_FREERTOS_NUMBER_OF_CORES == 2
static CpuAffinity getEspWifiAffinity() {
#ifdef CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0
return 0;
#elif defined(CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1)
return 1;
#else
return 0; // Default to core 0 if not specified
#endif
}
// Warning: Must watch ESP WiFi, as this task is used by WiFi
static CpuAffinity getEspMainSchedulerAffinity() {
#ifdef CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0
return 0;
#elif defined(CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1)
return 1;
#else
return 0; // Default to core 0 if not specified
#endif
}
#endif // CONFIG_FREERTOS_NUMBER_OF_CORES == 2
static CpuAffinity getFreeRtosTimerAffinity() {
#if defined(CONFIG_FREERTOS_TIMER_TASK_NO_AFFINITY)
return None;
#elif defined(CONFIG_FREERTOS_TIMER_TASK_AFFINITY_CPU0)
return 0;
#elif defined(CONFIG_FREERTOS_TIMER_TASK_AFFINITY_CPU1)
return 1;
#else
static_assert(false);
#endif
}
#if CONFIG_FREERTOS_NUMBER_OF_CORES == 1
static const CpuAffinityConfiguration esp = {
.system = 0,
.graphics = 0,
.wifi = 0,
.mainDispatcher = 0,
.apps = 0,
.timer = getFreeRtosTimerAffinity()
};
#elif CONFIG_FREERTOS_NUMBER_OF_CORES == 2
static const CpuAffinityConfiguration esp = {
.system = 0,
.graphics = 1,
.wifi = getEspWifiAffinity(),
.mainDispatcher = getEspMainSchedulerAffinity(),
.apps = 1,
.timer = getFreeRtosTimerAffinity()
};
#endif
#else
static const CpuAffinityConfiguration simulator = {
.system = None,
.graphics = None,
.wifi = None,
.mainDispatcher = 0,
.apps = None,
.timer = None
};
#endif
const CpuAffinityConfiguration& getCpuAffinityConfiguration() {
#ifdef ESP_PLATFORM
#if CONFIG_FREERTOS_NUMBER_OF_CORES == 2
// WiFi uses the main dispatcher to defer operations in the background
assert(esp.wifi == esp.mainDispatcher);
#endif // CORES
return esp;
#else
return simulator;
#endif
}
}