3 #include <ros/resource.h>
4 #include <ros/procdata.h>
17 # define udelay(x) udelay((x)/2000)
25 struct event_queue *indirect_q;
26 static void handle_generic(struct event_msg *ev_msg, unsigned int ev_type);
28 void ghetto_vcore_entry(void);
30 struct schedule_ops ghetto_sched_ops = {
31 .sched_entry = ghetto_vcore_entry,
33 struct schedule_ops *sched_ops = &ghetto_sched_ops;
36 static void __ros_syscall_spinon(struct syscall *sysc)
38 while (!(atomic_read(&sysc->flags) & (SC_DONE | SC_PROGRESS)))
42 /* to trick uthread_create() */
43 int main(int argc, char** argv)
48 mcs_barrier_init(&b, max_vcores());
50 /* vcore_context test */
51 assert(!in_vcore_context());
53 /* prep indirect ev_q. Note we grab a big one */
54 indirect_q = get_big_event_q();
55 indirect_q->ev_flags = EVENT_IPI;
56 indirect_q->ev_vcore = 1; /* IPI core 1 */
57 indirect_q->ev_handler = 0;
58 printf("Registering %08p for event type %d\n", indirect_q,
60 register_kevent_q(indirect_q, EV_FREE_APPLE_PIE);
62 /* handle events: just want to print out what we get. This is just a
63 * quick set of handlers, not a registration for a kevent. */
64 for (int i = 0; i < MAX_NR_EVENT; i++)
65 ev_handlers[i] = handle_generic;
66 /* Want to use the default ev_ev (which we just overwrote) */
67 ev_handlers[EV_EVENT] = handle_ev_ev;
68 /* vcore_init() done in vcore_request() now. */
69 /* Set up event reception. For example, this will allow us to receive an
70 * event and IPI for USER_IPIs on vcore 0. Check event.c for more stuff.
71 * Note you don't have to register for USER_IPIs to receive ones you send
72 * yourself with sys_self_notify(). */
73 enable_kevent(EV_USER_IPI, 0, EVENT_IPI | EVENT_VCORE_PRIVATE);
74 /* Receive pending preemption events. Can also get a MSG if you want. */
75 struct event_queue *ev_q = get_event_q();
76 ev_q->ev_flags = EVENT_IPI | EVENT_NOMSG | EVENT_VCORE_APPRO;
77 register_kevent_q(ev_q, EV_PREEMPT_PENDING);
78 /* We also receive preemption events, it is set up in uthread.c */
80 /* Inits a thread for us, though we won't use it. Just a hack to get into
81 * _M mode. Note this requests one vcore for us */
82 struct uthread dummy = {0};
83 uthread_lib_init(&dummy);
84 /* Reset the blockon to be the spinner... This is really shitty. Any
85 * blocking calls after we become an MCP and before this will fail. This is
86 * just mhello showing its warts due to trying to work outside uthread.c */
87 ros_syscall_blockon = __ros_syscall_spinon;
89 if ((vcoreid = vcore_id())) {
90 printf("Should never see me! (from vcore %d)\n", vcoreid);
93 printf("Hello from vcore %d with temp addr = %p and temp = %p\n",
94 vcoreid, &temp, temp);
95 printf("Multi-Goodbye, world, from PID: %d!\n", sys_getpid());
96 printf("Requesting %d vcores\n", max_vcores() - 1);
97 retval = vcore_request(max_vcores() - 1); /* since we already have 1 */
98 //retval = vcore_request(5);
99 printf("This is vcore0, right after vcore_request, retval=%d\n", retval);
100 /* vcore_context test */
101 assert(!in_vcore_context());
105 /* test notifying my vcore2 */
107 printf("Vcore 0 self-notifying vcore 2 with notif 4!\n");
108 struct event_msg msg;
110 sys_self_notify(2, 4, &msg, TRUE);
112 printf("Vcore 0 notifying itself with notif 6!\n");
114 sys_notify(sys_getpid(), 6, &msg);
118 /* test loop for restarting a notif_tf */
122 printf("Vcore %d Spinning (%d), temp = %08x!\n", vcoreid, ctr++, temp);
128 printf("Vcore %d Done!\n", vcoreid);
129 //mcs_barrier_wait(&b,vcore_id());
131 printf("All Cores Done!\n", vcoreid);
132 while(1); // manually kill from the monitor
133 /* since everyone should cleanup their uthreads, even if they don't plan on
134 * calling their code or want uthreads in the first place. <3 */
135 uthread_cleanup(&dummy);
139 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 notif_tf and it is okay
159 * 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);