Spin with cpu_relax_vc() in BCQs (XCC)
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 18 Aug 2015 20:02:40 +0000 (16:02 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 28 Sep 2015 19:14:00 +0000 (15:14 -0400)
The consumer (user) is spinning on another vcore, which could be
preempted.  Whenever we wait on the user in vcore context, we need to
use cpu_relax_vc().

Reinstall your kernel headers.

kern/include/ros/bcq.h

index b8e2e2e..10eed84 100644 (file)
  * will have to deal with the clobbering. */
 #ifdef ROS_KERNEL
 #include <atomic.h>
+/* dequeue uses relax_vc, which is user-only.  Some kernel tests call dequeue.*/
+#define cpu_relax_vc(x) cpu_relax()
 #else
 #include <parlib/arch/atomic.h>
+#include <parlib/vcore.h>
 #endif /* ROS_KERNEL */
 
 /* Bounded Concurrent Queues, untrusted consumer
@@ -82,9 +85,6 @@
  * They both return 0 on success, or some error code on failure.
  *
  * TODO later:
- * How about an atomic_add_return for the prod?  Now that we use powers of two,
- * CAS is probably overkill.
- *
  * Automatically round up.
  *
  * Watch out for ABA.  Could use ctrs in the top of the indexes.  Not really an
@@ -184,7 +184,7 @@ struct bcq_header {
                (_bcq)->wraps[__cons_pvt & ((_num_elems)-1)].rdy_for_cons = FALSE;     \
                /* wait til we're the cons_pub, then advance it by one */              \
                while ((_bcq)->hdr.cons_pub_idx != __cons_pvt)                         \
-                       cpu_relax();                                                       \
+                       cpu_relax_vc(vcore_id());                                          \
                (_bcq)->hdr.cons_pub_idx = __cons_pvt + 1;                             \
        }                                                                          \
        __retval;                                                                  \