UMS Scheduler

A UMS scheduler thread is a regular pthread that has entered the UMS scheduling mode.

Enter UMS scheduling mode

A regular pthread is converted into a UMS scheduler thread performing a ioctl call with IOCTL_ENTER_UMS request parameter; in particular the enter_ums_scheduling_mode() begins with:

src/lib/src/scheduler.c
13struct enter_ums_mode_args enter_args = {
14	.flags = ENTER_UMS_SCHED
15};
16struct ums_sched_event event;
17ums_activation_t scheduler_activation;
18
19if (!scheduler_startup_info) {
20	errno = EFAULT;
21	return -1;
22}
23
24enter_args.ums_complist = scheduler_startup_info->completion_list;
25
26if (enter_ums_mode(&enter_args))
27	return -1;

where the enter_ums_mode is defined at

src/lib/src/private.h
22static __always_inline int enter_ums_mode(struct enter_ums_mode_args *args)
23{
24	return ioctl(UMS_FILENO, IOCTL_ENTER_UMS, args);
25}

After a pthread has entered UMS scheduling mode it starts an infinite loop waiting for UMS scheduler events. All scheduling activities are passed from kernel space through ums_sched_event events and then proxied to the UMS ums_scheduler_entry_point_t.

src/lib/src/scheduler.c
29for (;;) {
30	if (dequeue_ums_sched_event(&event)) {
31		if (errno == EINTR) continue;
32		else return -1;
33	}
34
35	// proxies event to ums scheduler entry point
36	switch (event.type) {
37	case SCHEDULER_STARTUP:
38		scheduler_startup_info->ums_scheduler_entry_point(
39			UMS_SCHEDULER_STARTUP,
40			NULL,
41			scheduler_startup_info->scheduler_param
42		);
43		break;
44	case THREAD_YIELD:
45		scheduler_activation.context =
46					event.yield_params.context;
47
48		scheduler_startup_info->ums_scheduler_entry_point(
49			UMS_SCHEDULER_THREAD_YIELD,
50			&scheduler_activation,
51			event.yield_params.scheduler_params
52		);
53		break;
54	case THREAD_TERMINATED:
55		scheduler_activation.context =
56					event.end_params.context;
57
58		scheduler_startup_info->ums_scheduler_entry_point(
59			UMS_SCHEDULER_THREAD_END,
60			&scheduler_activation,
61			NULL
62		);
63		break;
64	default:
65		break;
66	}
67}

Execute UMS worker thread context

The execution of a worker thread context is implemented as follows:

src/lib/src/scheduler.c
72int execute_ums_thread(ums_context_t context)
73{
74	return ioctl(UMS_FILENO, IOCTL_EXEC_UMS_CTX, context);
75}