Re: More thread scheduling observations
Re: More thread scheduling observations
- Subject: Re: More thread scheduling observations
- From: Ian Ollmann <email@hidden>
- Date: Sat, 4 May 2002 23:40:57 -0700
james mccartney wrote:
>
On Sat, 4 May 2002, Andy Bull wrote:
>
>
> priority = 64; // 0 = low, 127 = highest ?
>
>
I've been told by one of the CoreAudio folks that the highest
>
priority you can get is 63 which is equal to but not above the
>
window server. When you ask what you got it tells you whatever you asked
>
for, not what you really have. That would seem to be a bug(?).
Yes. I think the pthread code does that to avoid causing bugs in code that
expects that when you set the priority to be X that it actually will be X.
You can double check through the mach API's to see what really happened.
What you will find is that you cant schedule a user level process at
higher priority than the window server, without resorting to the real time
scheduling policy. However most of the time consuming windowsever stuff is
running in a different thread at somewhat lower priority, so in principle
the high priority thread should not be getting in your way.
You may be having trouble either because the high priority thread still is
getting in your way, or your thread priority is degrading to the point
where you are below the window server worker thread.
Why dont you give this a try: Turn timesharing off so that you are
scheduled in a round robin fashion, among threads of equal priority. If
you set your priority equal to the window server, you should get the CPU
as often as the window server does. If you do this, you MUST release the
CPU regularly.
http://developer.apple.com/techpubs/macosx/Darwin/General/KernelProgramming/scheduler/Using_Mach__pplications.html
#include <mach/thread_policy.h>
//Polls a (non-realtime) thread to find out how it is scheduled
//Results are undefined of an error is returned. Otherwise, the
//priority is returned in the address pointed to by the priority
//parameter, and whether or not the thread uses timeshare scheduling
//is returned at the address pointed to by the isTimeShare parameter
kern_return_t GetStdThreadSchedule( mach_port_t machThread,
int *priority,
boolean_t *isTimeshare )
{
kern_return_t result = 0;
thread_extended_policy_data_t timeShareData;
thread_precedence_policy_data_t precidenceData;
mach_msg_type_number_t structItemCount;
boolean_t fetchDefaults = false;
memset( &timeShareData, 0, sizeof( thread_extended_policy_data_t ));
memset( &precidenceData, 0, sizeof( thread_precedence_policy_data_t ));
if( 0 == machThread )
machThread = mach_thread_self();
if( NULL != isTimeshare )
{
structItemCount = THREAD_EXTENDED_POLICY_COUNT;
result = thread_policy_get( machThread, THREAD_EXTENDED_POLICY,
&timeShareData, &structItemCount, &fetchDefaults );
*isTimeshare = timeShareData.timeshare;
if( 0 != result )
return result;
}
if( NULL != priority )
{
fetchDefaults = false;
structItemCount = THREAD_PRECEDENCE_POLICY_COUNT;
result = thread_policy_get( machThread, THREAD_PRECEDENCE_POLICY,
&precidenceData, &structItemCount, &fetchDefaults );
*priority = precidenceData.importance;
}
return result;
}
// Reschedules the indicated thread according to new parameters:
//
// machThread The mach thread id. Pass 0 for the current thread.
// newPriority The desired priority.
// isTimeShare false for round robin (fixed) priority,
// true for timeshare (normal) priority
//
// A standard new thread usually has a priority of 0 and uses the
// timeshare scheduling scheme. Use pthread_mach_thread_np() to
// to convert a pthread id to a mach thread id
kern_return_t RescheduleStdThread( mach_port_t machThread,
int newPriority,
boolean_t isTimeshare )
{
kern_return_t result = 0;
thread_extended_policy_data_t timeShareData;
thread_precedence_policy_data_t precidenceData;
//Set up some variables that we need for the task
precidenceData.importance = newPriority;
timeShareData.timeshare = isTimeshare;
if( 0 == machThread )
machThread = mach_thread_self();
//Set the scheduling flavor. We want to do this first, since doing so
//can alter the priority
result = thread_policy_set( machThread,
THREAD_EXTENDED_POLICY,
&timeShareData,
THREAD_EXTENDED_POLICY_COUNT );
if( 0 != result )
return result;
//Now set the priority
return thread_policy_set( machThread,
THREAD_PRECEDENCE_POLICY,
&precidenceData,
THREAD_PRECEDENCE_POLICY_COUNT );
}
---------------------------------------------------
Ian Ollmann, Ph.D. email@hidden
---------------------------------------------------
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.