1 #include <parlib/parlib.h>
3 #include <ros/resource.h>
4 #include <ros/procdata.h>
7 #include <parlib/arch/arch.h>
10 #include <parlib/vcore.h>
11 #include <parlib/mcs.h>
12 #include <parlib/timing.h>
13 #include <parlib/assert.h>
14 #include <parlib/event.h>
15 #include <parlib/uthread.h>
22 struct event_queue *indirect_q;
23 static void handle_generic(struct event_msg *ev_msg, unsigned int ev_type,
26 void ghetto_vcore_entry(void);
28 struct schedule_ops ghetto_sched_ops = {
29 .sched_entry = ghetto_vcore_entry,
33 static void __ros_syscall_spinon(struct syscall *sysc)
35 while (!(atomic_read(&sysc->flags) & (SC_DONE | SC_PROGRESS)))
39 /* to trick uthread_create() */
40 int main(int argc, char** argv)
45 /* Initialize our barrier. */
46 mcs_barrier_init(&b, max_vcores());
48 /* vcore_context test */
49 assert(!in_vcore_context());
51 /* prep indirect ev_q. Note we grab a big one */
52 indirect_q = get_eventq(EV_MBOX_UCQ);
53 indirect_q->ev_flags = EVENT_IPI;
54 indirect_q->ev_vcore = 1; /* IPI core 1 */
55 indirect_q->ev_handler = 0;
56 printf("Registering %08p for event type %d\n", indirect_q,
58 register_kevent_q(indirect_q, EV_FREE_APPLE_PIE);
60 /* handle events: just want to print out what we get. This is just a
61 * quick set of handlers, not a registration for a kevent. */
62 for (int i = 0; i < MAX_NR_EVENT; i++)
63 register_ev_handler(i, handle_generic, 0);
64 /* Want to use the default ev_ev (which we just overwrote) */
65 register_ev_handler(EV_EVENT, handle_ev_ev, 0);
66 /* vcore_lib_init() done in vcore_request() now. */
67 /* Set up event reception. For example, this will allow us to receive an
68 * event and IPI for USER_IPIs on vcore 0. Check event.c for more stuff.
69 * Note you don't have to register for USER_IPIs to receive ones you send
70 * yourself with sys_self_notify(). */
71 enable_kevent(EV_USER_IPI, 0, EVENT_IPI | EVENT_VCORE_PRIVATE);
72 /* Receive pending preemption events. (though there's no PP handler) */
73 struct event_queue *ev_q = get_eventq_vcpd(0, EVENT_VCORE_PRIVATE);
74 ev_q->ev_flags = EVENT_IPI | EVENT_VCORE_APPRO;
75 register_kevent_q(ev_q, EV_PREEMPT_PENDING);
76 /* We also receive preemption events, it is set up in uthread.c */
78 /* Inits a thread for us, though we won't use it. Just a hack to get into
79 * _M mode. Note this requests one vcore for us */
80 struct uthread dummy = {0};
81 uthread_2ls_init(&dummy, &ghetto_sched_ops);
83 /* Reset the blockon to be the spinner... This is really shitty. Any
84 * blocking calls after we become an MCP and before this will fail. This is
85 * just mhello showing its warts due to trying to work outside uthread.c */
86 ros_syscall_blockon = __ros_syscall_spinon;
88 if ((vcoreid = vcore_id())) {
89 printf("Should never see me! (from vcore %d)\n", vcoreid);
92 printf("Hello from vcore %d with temp addr = %p and temp = %p\n",
93 vcoreid, &temp, temp);
94 printf("Multi-Goodbye, world, from PID: %d!\n", sys_getpid());
95 printf("Requesting %d vcores\n", max_vcores() - 1);
96 retval = vcore_request(max_vcores() - 1); /* since we already have 1 */
97 //retval = vcore_request(5);
98 printf("This is vcore0, right after vcore_request, retval=%d\n", retval);
99 /* vcore_context test */
100 assert(!in_vcore_context());
104 /* test notifying my vcore2 */
106 printf("Vcore 0 self-notifying vcore 2 with notif 4!\n");
107 struct event_msg msg;
109 sys_self_notify(2, 4, &msg, TRUE);
111 printf("Vcore 0 notifying itself with notif 6!\n");
113 sys_notify(sys_getpid(), 6, &msg);
117 /* test loop for restarting a uthread_ctx */
121 printf("Vcore %d Spinning (%d), temp = %08x!\n", vcoreid, ctr++, temp);
127 printf("Vcore %d Done!\n", vcoreid);
128 //mcs_barrier_wait(&b,vcore_id());
130 printf("All Cores Done!\n", vcoreid);
131 while(1); // manually kill from the monitor
132 /* since everyone should cleanup their uthreads, even if they don't plan on
133 * calling their code or want uthreads in the first place. <3 */
134 uthread_cleanup(&dummy);
138 static void handle_generic(struct event_msg *ev_msg, unsigned int ev_type,
141 printf("Got event type %d on vcore %d\n", ev_type, vcore_id());
144 void ghetto_vcore_entry(void)
146 uint32_t vcoreid = vcore_id();
147 static bool first_time = TRUE;
150 /* vcore_context test (don't need to do this anywhere) */
151 assert(in_vcore_context());
153 /* old logic was moved to parlib code */
154 if (current_uthread) {
155 assert(vcoreid == 0);
156 run_current_uthread();
158 /* unmask notifications once you can let go of the uthread_ctx and it is
159 * okay to clobber the transition stack.
160 * Check Documentation/processes.txt: 4.2.4. In real code, you should be
161 * popping the tf of whatever user process you want (get off the x-stack) */
162 enable_notifs(vcoreid);
164 /* end: stuff userspace needs to do to handle notifications */
166 printf("Hello from vcore_entry in vcore %d with temp addr %p and temp %p\n",
167 vcoreid, &temp, temp);
170 /* Test sys change vcore. Need to manually preempt the pcore vcore4 is
171 * mapped to from the monitor */
174 disable_notifs(vcoreid);
175 printf("VC1 changing to VC4\n");
176 sys_change_vcore(4, TRUE); /* try both of these manually */
177 //sys_change_vcore(4, FALSE); /* try both of these manually */
178 printf("VC1 returned\n");
184 //mcs_barrier_wait(&b,vcore_id());
185 udelay(vcoreid * 10000000);