NT SYSTEM TASK
Normally, the SRMS scheduler runs at the second-to-highest priority level in the NT system, which is much higher than the priority of most NT kernel threads. Executing at this priority level allows the real-time task threads scheduled by the SRMS service to receive their guaranteed share of the CPU without getting preempted by non-real-time threads in the NT system. The problem with executing at such a high priority range for so long is that NT kernel and user processes are often preempted by the SRMS service and its real-time tasks. In order to service those starved non-real-time threads, the SRMS service provides a special task, called the NT system task, which yields its guaranteed processor time to all other threads in the NT operating system.
From the perspective of the SRMS scheduler, the NT system task is just like any other registered real-time task that has periodic work. To enable the task, the user opens the "System Task" dialog box from the Options menu of the service's GUI. After checking the "active" box, the user has the ability to modify the task's period, percent utilization (of the CPU), and minimum/desired quality of service values. After clicking "OK", the task then registers with the SRMS system and attempts QoS negotiation. If the system can provide the quality of service that the system task needs, then the task gets scheduled like any other real-time task.
The system task does no work other than yield its time to the rest of the system.
In its work function, the task calls Win32's SwitchToThread()
function, which forces the NT kernel to schedule the next ready thread at the same or
lower priority. Normally, this will give the kernel the opportunity to schedule any
starved system threads, followed by anything else it can schedule in the time yielded to
it by the system task.
The system task is child thread executing in the SRMS service's process space.
It is modeled according to the real-time task model and
just like any other real-time task, communicates to the SRMS service by using SRMS API
calls. All of the code for the task is found in the systask.c file. The task
thread begins execution at the SystemTaskProc() function and its worker
function is given below:
BOOL my_rt_work( VOID )
{
MSG msg;
DWORD start;
extern UINT WM_RTJobFailedMsg;
start = timeGetTime();
while ( (timeGetTime() < start + myExecTime) && (msg.message
!= WM_RTJobFailedMsg))
{
if (PeekMessage ( &msg, NULL, 0, 0,
PM_NOREMOVE))
TranslateMessage(
&msg );
SwitchToThread();
}
return TRUE;
}
Notice that the system task, like all other real-time tasks, must catch a job failed message from the SRMS scheduler and break out of its periodic loop if so. Also, the user can unregister the system task by unchecking the "active" checkbox in the "System Task" dialog and clicking "OK".