Re: How to get a sustained read speed under OS X
Re: How to get a sustained read speed under OS X
- Subject: Re: How to get a sustained read speed under OS X
- From: William Stewart <email@hidden>
- Date: Thu, 3 Jun 2004 11:59:47 -0700
Its probably more to do with alignment issues than thread priorities if
all that you are doing in the read-thread is reading...
Alignment:
Read Buffer should start at a 4K boundary, and should be a 4K
boundary-sized buffer (ie. 4, 8, 12, 16K...)
File offset (where you read from in the file) should be at a 4K
boundary.
Priority
If you're doing more work than just reading in this thread, then the
thing to do is make sure the POLICY of the thread is round-robin
(fixed) - then it doesn't degrade...
The Audio File code in the SDK (new one in particular) does all of
these things for you
Bill
On 03/06/2004, at 10:21 AM, Marc Van Olmen wrote:
>
Hi,
>
>
Because it is realtime problem I'm having related to video/audio
>
stream I
>
hope I can ask you guys this question:
>
>
How do I get a sustained stream working under OS X, or does OS X
>
doesn't
>
provide a mechanism for this?
>
>
I thought it was a matter of getting the read thread the right
>
priority or
>
is it better that I use some async reading?
>
>
I need to get a sustained speed of 3.5MBytes/second, this is easy to
>
do but
>
as soon I start duplicate a file in the Finder on the same hard disk
>
I'm
>
trouble, my read speeds drops very low. On a G5 the problem was worse
>
then
>
on a G4 because maybe not so good harddisk.
>
>
I tried the following thread priority thricks but none of them solve
>
the
>
issue although I noticed a slight improvement with certain priority
>
but no
>
real solution.
>
>
Cheers,
>
>
Mvo
>
Ps the code snippets I used
>
>
Some code, this is the way I set my thread in my cocoa Application to
>
I
>
"assume" realtime priority:
>
>
>
>
- (void) setThreadPolicy;
>
{
>
// Increase this thread's priority, and turn off timesharing. See
>
the
>
notes at the top of this file.
>
>
kern_return_t error;
>
struct thread_time_constraint_policy constraintPolicy;
>
thread_precedence_policy_data_t precedencePolicy;
>
Float64 clockFrequency = AudioGetHostClockFrequency();
>
>
constraintPolicy.period = 0.010 * clockFrequency; // 10ms
>
constraintPolicy.computation = 0.001 * clockFrequency; // 1ms
>
constraintPolicy.constraint = 0.005 * clockFrequency; // 5ms
>
constraintPolicy.preemptible = true;
>
>
error = thread_policy_set(mach_thread_self(),
>
THREAD_TIME_CONSTRAINT_POLICY, (thread_policy_t)&constraintPolicy,
>
THREAD_TIME_CONSTRAINT_POLICY_COUNT);
>
if (error != KERN_SUCCESS) {
>
printf("Couldn't set feeder thread's TIME_CONSTRAINT policy
>
%d",
>
error);
>
>
}
>
}
>
>
>
Also used this technique:
>
>
>
kern_return_t error;
>
thread_extended_policy_data_t extendedPolicy;
>
thread_precedence_policy_data_t precedencePolicy;
>
>
extendedPolicy.timeshare = 0;
>
error = thread_policy_set(mach_thread_self(),
>
THREAD_EXTENDED_POLICY,
>
(thread_policy_t)&extendedPolicy, THREAD_EXTENDED_POLICY_COUNT);
>
if (error != KERN_SUCCESS) {
>
mach_error("Couldn't set feeder thread's extended policy",
>
error);
>
}
>
>
precedencePolicy.importance = 45;
>
error = thread_policy_set(mach_thread_self(),
>
THREAD_PRECEDENCE_POLICY,
>
(thread_policy_t)&precedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT);
>
if (error != KERN_SUCCESS) {
>
mach_error("Couldn't set feeder thread's precedence policy",
>
error);
>
}
>
>
>
>
Also gave my application the following prioirty
>
>
int set_my_task_policy(void) {
>
>
int ret;
>
>
struct task_category_policy tcatpolicy;
>
>
tcatpolicy.role = TASK_FOREGROUND_APPLICATION;
>
>
if ((ret=task_policy_set(mach_task_self(),
>
TASK_CATEGORY_POLICY, (int *)&tcatpolicy,
>
TASK_CATEGORY_POLICY_COUNT)) != KERN_SUCCESS) {
>
fprintf(stderr, 3set_my_task_policy() failed.\n2);
>
>
return 0;
>
}
>
_______________________________________________
>
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.
>
>
--
mailto:email@hidden
tel: +1 408 974 4056
________________________________________________________________________
__
Culture Ship Names:
Ravished By The Sheer Implausibility Of That Last Statement [GSV]
I said, I've Got A Big Stick [OU]
Inappropiate Response [OU]
Far Over The Borders Of Insanity And Still Accelerating [Eccentric]
________________________________________________________________________
__
_______________________________________________
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.