#include <cfg/debug.h>
+/* Access to this list must be protected against the scheduler */
static List MonitorProcs;
{
proc->monitor.name = name;
- ADDTAIL(&MonitorProcs, &proc->monitor.link);
+ PROC_ATOMIC(ADDTAIL(&MonitorProcs, &proc->monitor.link));
}
void monitor_remove(Process *proc)
{
- REMOVE(&proc->monitor.link);
+ PROC_ATOMIC(REMOVE(&proc->monitor.link));
}
void monitor_rename(Process *proc, const char *name)
proc->monitor.name = name;
}
-/* TODO: use containerof() */
-#define MONITOR_NODE_TO_PROCESS(node) \
- (struct Process *)((intptr_t)(node) - offsetof(struct Process, monitor.link))
-
size_t monitor_checkStack(cpustack_t *stack_base, size_t stack_size)
{
cpustack_t *beg;
void monitor_report(void)
{
- struct Process* p;
+ Node *node;
int i;
- if (LIST_EMPTY(&MonitorProcs))
- {
- kputs("No stacks registered in the monitor\n");
- return;
- }
-
kprintf("%-24s%-8s%-8s%-8s%-8s\n", "Process name", "TCB", "SPbase", "SPsize", "SPfree");
- for (i=0;i<56;i++)
+ for (i = 0; i<56; i++)
kputchar('-');
kputchar('\n');
- for (p = MONITOR_NODE_TO_PROCESS(LIST_HEAD(&MonitorProcs));
- p->monitor.link.succ;
- p = MONITOR_NODE_TO_PROCESS(p->monitor.link.succ))
+ proc_forbid();
+ FOREACH_NODE(node, &MonitorProcs)
{
+ Process *p = containerof(node, Process, monitor.link);
size_t free = monitor_checkStack(p->stack_base, p->stack_size);
kprintf("%-24s%-8p%-8p%-8lu%-8lu\n",
p->monitor.name, p, p->stack_base, p->stack_size, free);
}
+ proc_permit();
}
static void NORETURN monitor(void)
{
- struct Process *p;
+ Process *p;
+ Node *node;
- while (1)
+ for (;;)
{
- for (p = MONITOR_NODE_TO_PROCESS(LIST_HEAD(&MonitorProcs));
- p->monitor.link.succ;
- p = MONITOR_NODE_TO_PROCESS(p->monitor.link.succ))
+ proc_forbid();
+ FOREACH_NODE(node, &MonitorProcs)
{
+ Process *p = containerof(node, Process, monitor.link);
size_t free = monitor_checkStack(p->stack_base, p->stack_size);
if (free < 0x20)
- kprintf("MONITOR: WARNING: Free stack for process '%s' is only %u chars\n",
+ kprintf("MONITOR: Free stack of process '%s' is only %u chars\n",
p->monitor.name, (unsigned int)free);
-
- timer_delay(500);
}
+ proc_permit();
+
+ /* Give some rest to the system */
+ timer_delay(500);
}
}
/**
* Proc scheduling test subthread 1
*/
-static void NORETURN proc_test_thread1(void)
+static void proc_test_thread1(void)
{
- for (;;)
+ for (int i = 0; i < 30; ++i)
{
kputs(">task 1\n");
timer_delay(50);
/**
* Proc scheduling test subthread 2
*/
-static void NORETURN proc_test_thread2(void)
+static void proc_test_thread2(void)
{
- for (;;)
+ for (int i = 0; i < 30; ++i)
{
kputs(">task 2\n");
timer_delay(75);
static cpustack_t proc_test_stack2[CONFIG_PROC_DEFSTACKSIZE / sizeof(cpustack_t)];
/**
- * Proc scheduling test
+ * Process scheduling test
*/
-void NORETURN proc_test(void)
+void proc_test(void)
{
proc_new(proc_test_thread1, NULL, sizeof(proc_test_stack1), proc_test_stack1);
proc_new(proc_test_thread2, NULL, sizeof(proc_test_stack2), proc_test_stack2);
// #warning FIXME
kdump(proc_test_stack2+sizeof(proc_test_stack1)-64, 64);
- for (;;)
+ for (int i = 0; i < 30; ++i)
{
kputs(">main task\n");
timer_delay(93);
proc_switch();
}
-
- ASSERT(false);
}