blob: e1109406dd030e9d3aa2cf3ef491f3091f678495 [file] [log] [blame]
/* tests/msr_dumb_while.c
*
* This requests the max_vcores in the system, then just while loops in a
* userthread. The pthread code will nicely yield if it detects an incoming
* preemption. */
#include <stdlib.h>
#include <parlib/vcore.h>
#include <pthread.h>
#include <parlib/assert.h>
#include <parlib/event.h>
#include <parlib/uthread.h>
void *while_thread(void *arg)
{
while (1);
}
int main(int argc, char** argv)
{
pthread_t *my_threads = malloc(sizeof(pthread_t) * max_vcores());
/* set up to receive the PREEMPT_PENDING event. EVENT_VCORE_APPRO tells the
* kernel to send the msg to whichever vcore is appropriate. Pthread code
* will see the preemption and yield. */
struct event_queue *ev_q = get_eventq_vcpd(0, EVENT_VCORE_PRIVATE);
ev_q->ev_flags = EVENT_IPI | EVENT_VCORE_APPRO;
register_kevent_q(ev_q, EV_PREEMPT_PENDING);
/* actually only need one less, since the _S will be pthread 0 */
for (int i = 0; i < max_vcores() - 1; i++)
pthread_create(&my_threads[i], NULL, &while_thread, NULL);
assert(num_vcores() == max_vcores());
while (1);
/* should never make it here */
return -1;
}