freemyipod r34 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r33‎ | r34 | r35 >
Date:00:45, 6 August 2010
Author:theseven
Status:new
Tags:
Comment:
Add a monitor command to lock down thread execution to allow consistent dumping or manipulation of data structures
Modified paths:
  • /embios/trunk/thread.c (modified) (history)
  • /embios/trunk/thread.h (modified) (history)
  • /embios/trunk/usb/usb.c (modified) (history)

Diff [purge]

Index: embios/trunk/thread.c
@@ -31,6 +31,7 @@
3232 struct scheduler_thread scheduler_threads[MAX_THREADS] IBSS_ATTR;
3333 struct scheduler_thread* current_thread IBSS_ATTR;
3434 uint32_t last_tick IBSS_ATTR;
 35+bool scheduler_frozen IBSS_ATTR;
3536 extern struct wakeup dbgwakeup;
3637
3738
@@ -217,6 +218,7 @@
218219 void scheduler_init(void)
219220 {
220221 memset(scheduler_threads, 0, sizeof(scheduler_threads));
 222+ scheduler_frozen = false;
221223 last_tick = USEC_TIMER;
222224 current_thread = scheduler_threads;
223225 current_thread->state = THREAD_RUNNING;
@@ -226,6 +228,11 @@
227229 setup_tick();
228230 }
229231
 232+void scheduler_freeze(bool value)
 233+{
 234+ scheduler_frozen = value;
 235+}
 236+
230237 void scheduler_switch(int thread)
231238 {
232239 int i;
@@ -254,37 +261,41 @@
255262 }
256263 }
257264
258 - for (i = 0; i < MAX_THREADS; i++)
259 - if (scheduler_threads[i].state == THREAD_BLOCKED
260 - && scheduler_threads[i].timeout != -1
261 - && TIME_AFTER(usec, scheduler_threads[i].blocked_since
262 - + scheduler_threads[i].timeout))
263 - {
264 - if (scheduler_threads[i].block_type == THREAD_BLOCK_MUTEX)
265 - mutex_remove_from_queue((struct mutex*)scheduler_threads[i].blocked_by,
266 - &scheduler_threads[i]);
267 - scheduler_threads[i].state = THREAD_READY;
268 - scheduler_threads[i].block_type = THREAD_NOT_BLOCKED;
269 - scheduler_threads[i].blocked_by = NULL;
270 - scheduler_threads[i].timeout = 0;
271 - }
272 -
273 - if (thread >= 0 && thread < MAX_THREADS && scheduler_threads[thread].state == THREAD_READY)
274 - current_thread = &scheduler_threads[thread];
 265+ if (scheduler_frozen) thread = 0;
275266 else
276267 {
277 - thread = 0;
278 - best = 0xffffffff;
279268 for (i = 0; i < MAX_THREADS; i++)
280 - if (scheduler_threads[i].state == THREAD_READY && scheduler_threads[i].priority)
 269+ if (scheduler_threads[i].state == THREAD_BLOCKED
 270+ && scheduler_threads[i].timeout != -1
 271+ && TIME_AFTER(usec, scheduler_threads[i].blocked_since
 272+ + scheduler_threads[i].timeout))
281273 {
282 - score = scheduler_threads[i].cputime_current / scheduler_threads[i].priority;
283 - if (score < best)
 274+ if (scheduler_threads[i].block_type == THREAD_BLOCK_MUTEX)
 275+ mutex_remove_from_queue((struct mutex*)scheduler_threads[i].blocked_by,
 276+ &scheduler_threads[i]);
 277+ scheduler_threads[i].state = THREAD_READY;
 278+ scheduler_threads[i].block_type = THREAD_NOT_BLOCKED;
 279+ scheduler_threads[i].blocked_by = NULL;
 280+ scheduler_threads[i].timeout = 0;
 281+ }
 282+
 283+ if (thread >= 0 && thread < MAX_THREADS && scheduler_threads[thread].state == THREAD_READY)
 284+ current_thread = &scheduler_threads[thread];
 285+ else
 286+ {
 287+ thread = 0;
 288+ best = 0xffffffff;
 289+ for (i = 0; i < MAX_THREADS; i++)
 290+ if (scheduler_threads[i].state == THREAD_READY && scheduler_threads[i].priority)
284291 {
285 - best = score;
286 - thread = i;
 292+ score = scheduler_threads[i].cputime_current / scheduler_threads[i].priority;
 293+ if (score < best)
 294+ {
 295+ best = score;
 296+ thread = i;
 297+ }
287298 }
288 - }
 299+ }
289300 }
290301
291302 current_thread = &scheduler_threads[thread];
Index: embios/trunk/usb/usb.c
@@ -458,6 +458,11 @@
459459 memcpy(&dbgsendbuf[4], scheduler_threads, dbgrecvbuf[1]);
460460 size = dbgrecvbuf[1] + 16;
461461 break;
 462+ case 16: // FREEZE SCHEDULER
 463+ scheduler_freeze(dbgrecvbuf[1]);
 464+ dbgsendbuf[0] = 1;
 465+ size = 16;
 466+ break;
462467 default:
463468 dbgsendbuf[0] = 2;
464469 size = 16;
Index: embios/trunk/thread.h
@@ -106,6 +106,7 @@
107107
108108 void scheduler_init() INITCODE_ATTR;
109109 void scheduler_switch(int thread) ICODE_ATTR;
 110+void scheduler_freeze(bool value);
110111 int thread_create(const char* name, const void* code, void* stack,
111112 int stacksize, enum thread_type type, int priority, bool run);
112113 int thread_suspend(int thread);