Occasionally I see thread execution hiccups on my Motorola Droid
(currently running 2.1 but I saw it with 2.0.1, too).  Normally my
dummy thread (full tilt, foreground, not doing *anything* else) runs
in about 5-6mS.  However, I see a second hump around 13-14mS and
stragglers anywhere out to 80mS (typically around 35mS, though).

What is going on?  Why is this scheduling so non-deterministically?
What is the solution?

I could deal with a couple mS slower if it would get rid of those
stragglers that exist the whole way out to 50-80mS.

Thanks.


If I run a single thread full tilt, I see execution times like the
following (milliseconds:number of times seen):

04-09 00:40:06.450: VERBOSE/*****(7177): Run ended ... dumping...
04-09 00:40:06.450: VERBOSE/CalcDelta:(7177):   5: 3915
04-09 00:40:06.457: VERBOSE/CalcDelta:(7177):   6: 6221
04-09 00:40:06.457: VERBOSE/CalcDelta:(7177):   7: 63
04-09 00:40:06.465: VERBOSE/CalcDelta:(7177):   8: 47
04-09 00:40:06.465: VERBOSE/CalcDelta:(7177):   9: 4
04-09 00:40:06.473: VERBOSE/CalcDelta:(7177):  10: 9
04-09 00:40:06.473: VERBOSE/CalcDelta:(7177):  11: 7
04-09 00:40:06.481: VERBOSE/CalcDelta:(7177):  12: 7
04-09 00:40:06.489: VERBOSE/CalcDelta:(7177):  13: 22
04-09 00:40:06.489: VERBOSE/CalcDelta:(7177):  14: 26
04-09 00:40:06.496: VERBOSE/CalcDelta:(7177):  15: 8
04-09 00:40:06.496: VERBOSE/CalcDelta:(7177):  16: 7
04-09 00:40:06.504: VERBOSE/CalcDelta:(7177):  17: 4
04-09 00:40:06.504: VERBOSE/CalcDelta:(7177):  18: 3
04-09 00:40:06.512: VERBOSE/CalcDelta:(7177):  19: 5
04-09 00:40:06.512: VERBOSE/CalcDelta:(7177):  21: 11
04-09 00:40:06.520: VERBOSE/CalcDelta:(7177):  22: 1
04-09 00:40:06.520: VERBOSE/CalcDelta:(7177):  23: 2
04-09 00:40:06.528: VERBOSE/CalcDelta:(7177):  25: 1
04-09 00:40:06.528: VERBOSE/CalcDelta:(7177):  26: 1
04-09 00:40:06.536: VERBOSE/CalcDelta:(7177):  27: 1
04-09 00:40:06.536: VERBOSE/CalcDelta:(7177):  29: 4
04-09 00:40:06.543: VERBOSE/CalcDelta:(7177):  30: 1
04-09 00:40:06.543: VERBOSE/CalcDelta:(7177):  36: 1
04-09 00:40:06.551: VERBOSE/CalcDelta:(7177):  37: 1
04-09 00:40:06.551: VERBOSE/CalcDelta:(7177):  40: 1
04-09 00:40:06.559: VERBOSE/CalcDelta:(7177):  45: 2
04-09 00:40:06.559: VERBOSE/CalcDelta:(7177):  47: 1
04-09 00:40:06.567: VERBOSE/CalcDelta:(7177):  53: 1

<code>

import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;

public class Run extends Activity {
        private long entryMillis = SystemClock.uptimeMillis();
        private long exitMillis = SystemClock.uptimeMillis();
        private long startMillis = SystemClock.uptimeMillis();

        long calcDeltaMillis[] = new long[1000];
        long funcDeltaMillis[] = new long[1000];

        long randomTime = 0;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
        }

        @Override
        protected void onResume() {
                super.onResume();
        Thread t = new Thread() {
            public void run() {
                doTimingThread();
            }
        };
        t.start();
        }

        void doTimingThread() {
                Random rg = new Random();

                Log.v("*****", "Entering timing thread...");
                startMillis = SystemClock.uptimeMillis();
                while(true) {
                        entryMillis = SystemClock.uptimeMillis();
                        for(int ii=0; ii<4000; ++ii) {
                                randomTime += rg.nextInt();
                        }
                        exitMillis = SystemClock.uptimeMillis();
                        calcDeltaMillis[(int)(exitMillis-entryMillis)] += 1;

                        if (SystemClock.uptimeMillis() >= startMillis + 60000) {
                                dumpAndEraseTables();
                                startMillis = SystemClock.uptimeMillis();
                        }
                }
        }


        public void dumpAndEraseTables() {
                Log.v("*****", "Run ended ... dumping...");
                for(int ii=0; ii<1000; ++ii) {
                        if (calcDeltaMillis[ii] != 0) {
                                Log.v("CalcDelta:", String.format("%3d: %d", ii,
calcDeltaMillis[ii]));
                                calcDeltaMillis[ii] = 0;
                        }
                }
        }

        @Override
        protected void onPause() {
                super.onPause();
        }
}
</code>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe, reply using "remove me" as the subject.

Reply via email to