Experimentally, it seems like Android's scheduler is a very simple round robin scheduler that runs a single thread until it sleeps, then the next until it sleeps, and so on. If you are completely loading the processor to 100%, then there is no guarantee how long it will take to come back from a sleep call, because everything that is scheduled to process must run before you get back to the front of the line. I've seen sleep(1)s that take 5 seconds to return from.
Regards,
NIral
On Fri, Oct 8, 2010 at 4:36 PM, David Whittaker <dpwhi...@gmail.com> wrote:
> Experimentally, it seems like Android's scheduler is a very simple round
> robin scheduler that runs a single thread until it sleeps, then the next
> until it sleeps, and so on. If you are completely loading the processor to
> 100%, then there is no guarantee how long it will take to come back from a
> sleep call, because everything that is scheduled to process must run before
> you get back to the front of the line. I've seen sleep(1)s that take 5
> seconds to return from.
>
On Fri, Oct 8, 2010 at 11:37 PM, Dianne Hackborn <hac...@android.com> wrote:
> Um, no, it is the standard Linux scheduler.
>
> On Fri, Oct 8, 2010 at 4:06 AM, David Whittaker <dpwhi...@gmail.com>
> wrote:
>>
>> Experimentally, it seems like Android's scheduler is a very simple round
>> robin scheduler that runs a single thread until it sleeps, then the next
>> until it sleeps, and so on. If you are completely loading the processor to
>> 100%, then there is no guarantee how long it will take to come back from a
>> sleep call, because everything that is scheduled to process must run before
>> you get back to the front of the line. I've seen sleep(1)s that take 5
>> seconds to return from.
>>
No I am talking about android APIs thread_db.
Well, that was all from just experimenting with threading under a heavy load (decoding video). Maybe this is how the Linux kernel is supposed to schedule threads under load, but I noticed when I called sleep(1) from my audio decoding thread, it didn't return until my video decoding thread slept, even if that was 5 seconds later. Now, there's always the possibility of a bug in my code, but the test was just two timing calls with a sleep between them while the other thread decoded video, so there wasn't much room for bugs.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
http://linux.die.net/man/2/setpriority
Note that the terminology on the page (and in Linux) is reversed from
what you might expect: "Lower" priority values mean that it's a higher
priority. And the page notes that "Only the superuser may lower priorities."
Tim
I didn't know about that. That's very interesting. I'm currently doing some
usleep magic to prevent one of my threads from overloading the system. Setting
the priority would be smarter.
> u mean to say i will create thread using pthread in native and set
> priority using android.os.Process#setThreadPriority in native?
> is it what you meant?
I think the idea is:
- create a thread with pthread
- within this native thread, call Process.myTid() to obtain the thread id
- then call Process.setThreadPriority() with the said id and desired priority
Is this correct?
--
Olivier
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
Therefore I'd better use Process.setThreadPriority() than setpriority(), right?
You two seem to disagree.
Olivier
On 10/13/2010 03:30 AM, Dianne Hackborn wrote:
> Though again, setpriority() won't change the cgroup. To be polite, you
> really want to have the cgroup changed to background, so you can't
> interfere with foreground/UI threads. The Java API will do this;
> unfortunately there is no interface in the NDK for the native code it
> uses for its implementation.
>
> Also as far as who can do what -- security in Android is done at the
> process level. Java can't do anything more than native code, nor can
> native code do anything more than Java. The only differences between
> them are what APIs are available that provide functionality that the
> platform promises to support in the future and across different devices.
>
> On Tue, Oct 12, 2010 at 11:03 AM, fadden <fad...@android.com
> <mailto:fad...@android.com>> wrote:
>
> On Oct 12, 8:29 am, Olivier Guilyardi <l...@samalyse.com
> <mailto:l...@samalyse.com>> wrote:
> > I think the idea is:
> >
> > - create a thread with pthread
> > - within this native thread, call Process.myTid() to obtain the
> thread id
> > - then call Process.setThreadPriority() with the said id and
> desired priority
>
> Only if you like doing it the hard way. :-)
>
> As hackbod noted earlier:
>
> | You can just use the standard Unix function setpriority(). This is
> the same
> | thing that the Java APIs use for their implementation.
>
> The setpriority system call changes the "nice" value of the process.
> You can admire your work with "ps -p -t" on the device.
>
> As another poster mentioned, higher values are "more nice" and
> indicate lower priority.
>
> A thread that is spinning on the CPU will continue to spin and eat
> battery, even at a lower priority. It will just give up time to other
> threads more readily.
>
> --
> You received this message because you are subscribed to the Google
> Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com
> <mailto:andro...@googlegroups.com>.
> To unsubscribe from this group, send email to
> android-ndk...@googlegroups.com
> <mailto:android-ndk%2Bunsu...@googlegroups.com>.
> For more options, visit this group at
> http://groups.google.com/group/android-ndk?hl=en.
>
>
>
>
> --
> Dianne Hackborn
> Android framework engineer
> hac...@android.com <mailto:hac...@android.com>
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails. All such
> questions should be posted on public forums, where I and others can see
> and answer them.
>