diff options
Diffstat (limited to 'firmware/system.c')
-rw-r--r-- | firmware/system.c | 74 |
1 files changed, 63 insertions, 11 deletions
diff --git a/firmware/system.c b/firmware/system.c index 6ff0dbb5d1..0b5ae1719e 100644 --- a/firmware/system.c +++ b/firmware/system.c | |||
@@ -35,6 +35,13 @@ long cpu_frequency NOCACHEBSS_ATTR = CPU_FREQ; | |||
35 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 35 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
36 | static int boost_counter NOCACHEBSS_ATTR = 0; | 36 | static int boost_counter NOCACHEBSS_ATTR = 0; |
37 | static bool cpu_idle NOCACHEBSS_ATTR = false; | 37 | static bool cpu_idle NOCACHEBSS_ATTR = false; |
38 | #if NUM_CORES > 1 | ||
39 | struct spinlock boostctrl_spin NOCACHEBSS_ATTR; | ||
40 | void cpu_boost_init(void) | ||
41 | { | ||
42 | spinlock_init(&boostctrl_spin, SPINLOCK_NO_TASK_SWITCH); | ||
43 | } | ||
44 | #endif | ||
38 | 45 | ||
39 | int get_cpu_boost_counter(void) | 46 | int get_cpu_boost_counter(void) |
40 | { | 47 | { |
@@ -52,25 +59,51 @@ int cpu_boost_log_getcount(void) | |||
52 | } | 59 | } |
53 | char * cpu_boost_log_getlog_first(void) | 60 | char * cpu_boost_log_getlog_first(void) |
54 | { | 61 | { |
62 | char *first; | ||
63 | #if NUM_CORES > 1 | ||
64 | spinlock_lock(&boostctrl_spin); | ||
65 | #endif | ||
66 | |||
67 | first = NULL; | ||
68 | |||
55 | if (cpu_boost_calls_count) | 69 | if (cpu_boost_calls_count) |
56 | { | 70 | { |
57 | cpu_boost_track_message = 1; | 71 | cpu_boost_track_message = 1; |
58 | return cpu_boost_calls[cpu_boost_first]; | 72 | first = cpu_boost_calls[cpu_boost_first]; |
59 | } | 73 | } |
60 | else return NULL; | 74 | |
75 | #if NUM_CORES > 1 | ||
76 | spinlock_unlock(&boostctrl_spin); | ||
77 | #endif | ||
61 | } | 78 | } |
62 | char * cpu_boost_log_getlog_next(void) | 79 | char * cpu_boost_log_getlog_next(void) |
63 | { | 80 | { |
64 | int message = (cpu_boost_track_message+cpu_boost_first)%MAX_BOOST_LOG; | 81 | int message; |
82 | char *next; | ||
83 | |||
84 | #if NUM_CORES > 1 | ||
85 | spinlock_lock(&boostctrl_spin); | ||
86 | #endif | ||
87 | |||
88 | message = (cpu_boost_track_message+cpu_boost_first)%MAX_BOOST_LOG; | ||
89 | next = NULL; | ||
90 | |||
65 | if (cpu_boost_track_message < cpu_boost_calls_count) | 91 | if (cpu_boost_track_message < cpu_boost_calls_count) |
66 | { | 92 | { |
67 | cpu_boost_track_message++; | 93 | cpu_boost_track_message++; |
68 | return cpu_boost_calls[message]; | 94 | next = cpu_boost_calls[message]; |
69 | } | 95 | } |
70 | else return NULL; | 96 | |
97 | #if NUM_CORES > 1 | ||
98 | spinlock_unlock(&boostctrl_spin); | ||
99 | #endif | ||
71 | } | 100 | } |
72 | void cpu_boost_(bool on_off, char* location, int line) | 101 | void cpu_boost_(bool on_off, char* location, int line) |
73 | { | 102 | { |
103 | #if NUM_CORES > 1 | ||
104 | spinlock_lock(&boostctrl_spin); | ||
105 | #endif | ||
106 | |||
74 | if (cpu_boost_calls_count == MAX_BOOST_LOG) | 107 | if (cpu_boost_calls_count == MAX_BOOST_LOG) |
75 | { | 108 | { |
76 | cpu_boost_first = (cpu_boost_first+1)%MAX_BOOST_LOG; | 109 | cpu_boost_first = (cpu_boost_first+1)%MAX_BOOST_LOG; |
@@ -88,32 +121,46 @@ void cpu_boost_(bool on_off, char* location, int line) | |||
88 | #else | 121 | #else |
89 | void cpu_boost(bool on_off) | 122 | void cpu_boost(bool on_off) |
90 | { | 123 | { |
124 | #if NUM_CORES > 1 | ||
125 | spinlock_lock(&boostctrl_spin); | ||
91 | #endif | 126 | #endif |
127 | |||
128 | #endif /* CPU_BOOST_LOGGING */ | ||
92 | if(on_off) | 129 | if(on_off) |
93 | { | 130 | { |
94 | /* Boost the frequency if not already boosted */ | 131 | /* Boost the frequency if not already boosted */ |
95 | if(boost_counter++ == 0) | 132 | if(++boost_counter == 1) |
96 | set_cpu_frequency(CPUFREQ_MAX); | 133 | set_cpu_frequency(CPUFREQ_MAX); |
97 | } | 134 | } |
98 | else | 135 | else |
99 | { | 136 | { |
100 | /* Lower the frequency if the counter reaches 0 */ | 137 | /* Lower the frequency if the counter reaches 0 */ |
101 | if(--boost_counter == 0) | 138 | if(--boost_counter <= 0) |
102 | { | 139 | { |
103 | if(cpu_idle) | 140 | if(cpu_idle) |
104 | set_cpu_frequency(CPUFREQ_DEFAULT); | 141 | set_cpu_frequency(CPUFREQ_DEFAULT); |
105 | else | 142 | else |
106 | set_cpu_frequency(CPUFREQ_NORMAL); | 143 | set_cpu_frequency(CPUFREQ_NORMAL); |
107 | } | ||
108 | 144 | ||
109 | /* Safety measure */ | 145 | /* Safety measure */ |
110 | if(boost_counter < 0) | 146 | if (boost_counter < 0) |
111 | boost_counter = 0; | 147 | { |
148 | boost_counter = 0; | ||
149 | } | ||
150 | } | ||
112 | } | 151 | } |
152 | |||
153 | #if NUM_CORES > 1 | ||
154 | spinlock_unlock(&boostctrl_spin); | ||
155 | #endif | ||
113 | } | 156 | } |
114 | 157 | ||
115 | void cpu_idle_mode(bool on_off) | 158 | void cpu_idle_mode(bool on_off) |
116 | { | 159 | { |
160 | #if NUM_CORES > 1 | ||
161 | spinlock_lock(&boostctrl_spin); | ||
162 | #endif | ||
163 | |||
117 | cpu_idle = on_off; | 164 | cpu_idle = on_off; |
118 | 165 | ||
119 | /* We need to adjust the frequency immediately if the CPU | 166 | /* We need to adjust the frequency immediately if the CPU |
@@ -125,6 +172,10 @@ void cpu_idle_mode(bool on_off) | |||
125 | else | 172 | else |
126 | set_cpu_frequency(CPUFREQ_NORMAL); | 173 | set_cpu_frequency(CPUFREQ_NORMAL); |
127 | } | 174 | } |
175 | |||
176 | #if NUM_CORES > 1 | ||
177 | spinlock_unlock(&boostctrl_spin); | ||
178 | #endif | ||
128 | } | 179 | } |
129 | #endif /* HAVE_ADJUSTABLE_CPU_FREQ */ | 180 | #endif /* HAVE_ADJUSTABLE_CPU_FREQ */ |
130 | 181 | ||
@@ -199,6 +250,7 @@ void UIE(unsigned int pc, unsigned int num) | |||
199 | /* TODO: perhaps add button handling in here when we get a polling | 250 | /* TODO: perhaps add button handling in here when we get a polling |
200 | driver some day. | 251 | driver some day. |
201 | */ | 252 | */ |
253 | core_idle(); | ||
202 | } | 254 | } |
203 | } | 255 | } |
204 | 256 | ||