Sorted out proc refcounting with ARCs
[akaros.git] / kern / src / smp.c
index dd3fca1..8ccb931 100644 (file)
@@ -11,7 +11,7 @@
 #include <arch/arch.h>
 #include <atomic.h>
 #include <smp.h>
-#include <ros/error.h>
+#include <error.h>
 #include <stdio.h>
 #include <string.h>
 #include <assert.h>
@@ -33,21 +33,31 @@ atomic_t outstanding_calls = 0;
  *   queue, then halt again.
  *
  * TODO: think about resetting the stack pointer at the beginning for worker
- * cores.
+ * cores. (keeps the stack from growing if we never go back to userspace).
  * TODO: think about unifying the manager into a workqueue function, so we don't
  * need to check mgmt_core in here.  it gets a little ugly, since there are
  * other places where we check for mgmt and might not smp_idle / call manager.
  */
 void smp_idle(void)
 {
+       int8_t state = 0;
+       per_cpu_info_t *myinfo = &per_cpu_info[core_id()];
+
        if (!management_core()) {
                enable_irq();
                while (1) {
-                       process_workqueue();
-                       // consider races with work added after we started leaving the last func
+                       process_routine_kmsg();
                        cpu_halt();
                }
        } else {
+               /* techincally, this check is arch dependent.  i want to know if it
+                * happens.  the enabling/disabling could be interesting. */
+               enable_irqsave(&state);
+               if (!STAILQ_EMPTY(&myinfo->immed_amsgs) ||
+                       !STAILQ_EMPTY(&myinfo->routine_amsgs)) 
+                       printk("[kernel] kmsgs in smp_idle() on a management core.\n");
+               process_routine_kmsg();
+               disable_irqsave(&state);
                manager();
        }
        assert(0);