#include <ros/mman.h>
#include <ros/resource.h>
#include <ros/procdata.h>
-#include <ros/notification.h>
+#include <ros/event.h>
#include <ros/bcq.h>
#include <arch/arch.h>
-#include <rstdio.h>
+#include <stdio.h>
#include <vcore.h>
#include <mcs.h>
#include <timing.h>
#include <rassert.h>
-
-#ifdef __sparc_v8__
-# define udelay(x) udelay((x)/2000)
-#endif
+#include <event.h>
+#include <uthread.h>
mcs_barrier_t b;
__thread int temp;
void *core0_tls = 0;
+struct event_queue *indirect_q;
+static void handle_generic(struct event_msg *ev_msg, unsigned int ev_type,
+ void *data);
+
+void ghetto_vcore_entry(void);
+
+struct schedule_ops ghetto_sched_ops = {
+ .sched_entry = ghetto_vcore_entry,
+};
+struct schedule_ops *sched_ops = &ghetto_sched_ops;
+
+/* Extreme ghetto */
+static void __ros_syscall_spinon(struct syscall *sysc)
+{
+ while (!(atomic_read(&sysc->flags) & (SC_DONE | SC_PROGRESS)))
+ cpu_relax();
+}
+
+/* to trick uthread_create() */
int main(int argc, char** argv)
{
uint32_t vcoreid;
mcs_barrier_init(&b, max_vcores());
-/* begin: stuff userspace needs to do before switching to multi-mode */
- if (vcore_init())
- printf("vcore_init() failed, we're fucked!\n");
-
- /* tell the kernel where and how we want to receive notifications */
- struct notif_method *nm;
- for (int i = 0; i < MAX_NR_NOTIF; i++) {
- nm = &__procdata.notif_methods[i];
- nm->flags |= NOTIF_WANTED | NOTIF_MSG | NOTIF_IPI;
- nm->vcoreid = i % 2; // vcore0 or 1, keepin' it fresh.
- }
-
- /* Need to save this somewhere that you can find it again when restarting
- * core0 */
- core0_tls = get_tls_desc(0);
- /* Need to save our floating point state somewhere (like in the
- * user_thread_tcb so it can be restarted too */
-
- /* don't forget to enable notifs on vcore0 at some point */
- struct preempt_data *vcpd;
- vcpd = &__procdata.vcore_preempt_data[0];
- vcpd->notif_enabled = TRUE;
+ /* vcore_context test */
+ assert(!in_vcore_context());
-/* end: stuff userspace needs to do before switching to multi-mode */
+ /* prep indirect ev_q. Note we grab a big one */
+ indirect_q = get_big_event_q();
+ indirect_q->ev_flags = EVENT_IPI;
+ indirect_q->ev_vcore = 1; /* IPI core 1 */
+ indirect_q->ev_handler = 0;
+ printf("Registering %08p for event type %d\n", indirect_q,
+ EV_FREE_APPLE_PIE);
+ register_kevent_q(indirect_q, EV_FREE_APPLE_PIE);
+
+ /* handle events: just want to print out what we get. This is just a
+ * quick set of handlers, not a registration for a kevent. */
+ for (int i = 0; i < MAX_NR_EVENT; i++)
+ register_ev_handler(i, handle_generic, 0);
+ /* Want to use the default ev_ev (which we just overwrote) */
+ register_ev_handler(EV_EVENT, handle_ev_ev, 0);
+ /* vcore_init() done in vcore_request() now. */
+ /* Set up event reception. For example, this will allow us to receive an
+ * event and IPI for USER_IPIs on vcore 0. Check event.c for more stuff.
+ * Note you don't have to register for USER_IPIs to receive ones you send
+ * yourself with sys_self_notify(). */
+ enable_kevent(EV_USER_IPI, 0, EVENT_IPI | EVENT_VCORE_PRIVATE);
+ /* Receive pending preemption events. Can also get a MSG if you want. */
+ struct event_queue *ev_q = get_event_q();
+ ev_q->ev_flags = EVENT_IPI | EVENT_NOMSG | EVENT_VCORE_APPRO;
+ register_kevent_q(ev_q, EV_PREEMPT_PENDING);
+ /* We also receive preemption events, it is set up in uthread.c */
+
+ /* Inits a thread for us, though we won't use it. Just a hack to get into
+ * _M mode. Note this requests one vcore for us */
+ struct uthread dummy = {0};
+ uthread_lib_init(&dummy);
+ /* Reset the blockon to be the spinner... This is really shitty. Any
+ * blocking calls after we become an MCP and before this will fail. This is
+ * just mhello showing its warts due to trying to work outside uthread.c */
+ ros_syscall_blockon = __ros_syscall_spinon;
if ((vcoreid = vcore_id())) {
printf("Should never see me! (from vcore %d)\n", vcoreid);
printf("Hello from vcore %d with temp addr = %p and temp = %p\n",
vcoreid, &temp, temp);
printf("Multi-Goodbye, world, from PID: %d!\n", sys_getpid());
- //retval = sys_resource_req(RES_CORES, 2, 0);
- printf("Requesting %d vcores\n",max_vcores());
- retval = vcore_request(max_vcores());
+ printf("Requesting %d vcores\n", max_vcores() - 1);
+ retval = vcore_request(max_vcores() - 1); /* since we already have 1 */
//retval = vcore_request(5);
printf("This is vcore0, right after vcore_request, retval=%d\n", retval);
+ /* vcore_context test */
+ assert(!in_vcore_context());
}
-#if 0
+ //#if 0
/* test notifying my vcore2 */
udelay(5000000);
printf("Vcore 0 self-notifying vcore 2 with notif 4!\n");
- struct notif_event ne;
- ne.ne_type = 4;
- sys_self_notify(2, 4, &ne);
+ struct event_msg msg;
+ msg.ev_type = 4;
+ sys_self_notify(2, 4, &msg, TRUE);
udelay(5000000);
- printf("Vcore 0 notifying itself with notif 3!\n");
- ne.ne_type = 3;
- sys_notify(sys_getpid(), 3, &ne);
+ printf("Vcore 0 notifying itself with notif 6!\n");
+ msg.ev_type = 6;
+ sys_notify(sys_getpid(), 6, &msg);
udelay(1000000);
-#endif
+ //#endif
- /* test loop for restarting a notif_tf */
+ /* test loop for restarting a uthread_ctx */
if (vcoreid == 0) {
int ctr = 0;
while(1) {
printf("All Cores Done!\n", vcoreid);
while(1); // manually kill from the monitor
+ /* since everyone should cleanup their uthreads, even if they don't plan on
+ * calling their code or want uthreads in the first place. <3 */
+ uthread_cleanup(&dummy);
return 0;
}
-void vcore_entry(void)
+static void handle_generic(struct event_msg *ev_msg, unsigned int ev_type,
+ void *data)
+{
+ printf("Got event type %d on vcore %d\n", ev_type, vcore_id());
+}
+
+void ghetto_vcore_entry(void)
{
uint32_t vcoreid = vcore_id();
static bool first_time = TRUE;
temp = 0xcafebabe;
-/* begin: stuff userspace needs to do to handle notifications */
+ /* vcore_context test (don't need to do this anywhere) */
+ assert(in_vcore_context());
- struct vcore *vc = &__procinfo.vcoremap[vcoreid];
- struct preempt_data *vcpd;
- vcpd = &__procdata.vcore_preempt_data[vcoreid];
-
- /* here is how you receive a notif_event */
- struct notif_event ne = {0};
- bcq_dequeue(&vcpd->notif_evts, &ne, NR_PERCORE_EVENTS);
- printf("the queue is on vcore %d and has a ne with type %d\n", vcoreid,
- ne.ne_type);
- /* it might be in bitmask form too: */
- //printf("and the bitmask looks like: ");
- //PRINT_BITMASK(__procdata.vcore_preempt_data[vcoreid].notif_bmask, MAX_NR_NOTIF);
- /* can see how many messages had to be sent as bits */
- printf("Number of event overflows: %d\n", vcpd->event_overflows);
-
- if (vc->preempt_pending) {
- printf("Oh crap, vcore %d is being preempted! Yielding\n", vcoreid);
- sys_yield(TRUE);
- printf("After yield on vcore %d. I wasn't being preempted.\n", vcoreid);
+ /* old logic was moved to parlib code */
+ if (current_uthread) {
+ assert(vcoreid == 0);
+ run_current_uthread();
}
-
- /* Lets try to restart vcore0's context. Note this doesn't do anything to
- * set the appropriate TLS. On x86, this will involve changing the LDT
- * entry for this vcore to point to the TCB of the new user-thread. */
- if (vcoreid == 0) {
- /* // test for preempting a notif_handler. do it from the monitor
- int ctr = 0;
- while(ctr < 3) {
- printf("Vcore %d Spinning (%d), temp = %08x!\n", vcoreid, ctr++, temp);
- udelay(5000000);
- } */
- printf("restarting vcore0 from userspace\n");
- vcpd->notif_pending = 0;
- /* Do one last check for notifs after clearing pending */
- /* // testing for missing a notif
- if (first_time) {
- first_time = FALSE;
- printf("setting pending, trying to renotify etc\n");
- vcpd->notif_pending = 1;
- } */
- set_tls_desc(core0_tls, 0);
- /* Load silly state (Floating point) too */
- pop_ros_tf(&vcpd->notif_tf, vcoreid);
- panic("should never see me!");
- }
- /* unmask notifications once you can let go of the notif_tf and it is okay
- * to clobber the transition stack.
+ /* unmask notifications once you can let go of the uthread_ctx and it is
+ * okay to clobber the transition stack.
* Check Documentation/processes.txt: 4.2.4. In real code, you should be
* popping the tf of whatever user process you want (get off the x-stack) */
- vcpd->notif_enabled = TRUE;
-
+ enable_notifs(vcoreid);
+
/* end: stuff userspace needs to do to handle notifications */
printf("Hello from vcore_entry in vcore %d with temp addr %p and temp %p\n",
vcoreid, &temp, temp);
+
+ #if 0
+ /* Test sys change vcore. Need to manually preempt the pcore vcore4 is
+ * mapped to from the monitor */
+ udelay(20000000);
+ if (vcoreid == 1) {
+ disable_notifs(vcoreid);
+ printf("VC1 changing to VC4\n");
+ sys_change_vcore(4, TRUE); /* try both of these manually */
+ //sys_change_vcore(4, FALSE); /* try both of these manually */
+ printf("VC1 returned\n");
+ }
+ udelay(10000000);
+ #endif
+
vcore_request(1);
//mcs_barrier_wait(&b,vcore_id());
udelay(vcoreid * 10000000);
- exit(0);
+ //exit(0);
while(1);
}