NDK5 performances

446 views
Skip to first unread message

teknoraver

unread,
Jan 4, 2011, 8:39:51 PM1/4/11
to android-ndk
Hi,

I have installed the new NDK 5 as the changelog states: "Includes a
new toolchain (based on GCC 4.4.3), which generates better code"
but I did a benchmark and there is a _huge_ performance loss,
something like 25% in the popular dhrystone benchmark.

This is the benchmark source: http://homepages.cwi.nl/~steven/dry.c

and here the results:


# gcc-4.4.0
/data # ./dry-440

Dhrystone Benchmark, Version C, Version 2.2
Microseconds for one run through Dhrystone: 0.4
Dhrystones per Second: 2293578


# gcc-4.4.3
/data # ./dry-443

Dhrystone Benchmark, Version C, Version 2.2
Microseconds for one run through Dhrystone: 0.6
Dhrystones per Second: 1754386


Obviously I'm using the same compiler options: "-mcpu=cortex-a8 -
mfloat-abi=softfp -mfpu=neon" for both programs.
I run another well known benchmark, flops (src: http://home.iae.nl/users/mhx/flops.c)
and in some tests I lose something like 10%.

I tried some other compiler flags like -mfpu=vfp and/or -march=armv7-a
but no luck, still bad results :(

Doug Kwan (關振德)

unread,
Jan 5, 2011, 1:21:06 PM1/5/11
to andro...@googlegroups.com
Hi,

Thanks for reporting this. We are starting to look at that.

-Doug

> --
> 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.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
>
>

Doug Kwan (關振德)

unread,
Jan 6, 2011, 9:52:36 PM1/6/11
to andro...@googlegroups.com
Hi,

Can you do an experiment for me? Please try adding -fpic to CFLAGS
with NDK4 and -fno-pic to CFLAGS with NDK5 and see if these make a
difference and how.

-Doug

David Turner

unread,
Jan 8, 2011, 9:04:19 AM1/8/11
to andro...@googlegroups.com
Ok, just to clarify a few things, we ran our own tests and found the root cause of the problem.
Briefly, we can say that:

- This does not affect anyone using the NDK build system, only people who want to use the toolchain in standalone mode.
- If you use the standalone toolchain, just use the -fpic flag to build your object files and get rid of the problem.

The root cause of the problem is that the arm-linux-androideabi configuration forces -fPIC by default, which generates slower code in certain conditions met by 
the benchmark's loop. The reason for this is historical, and the C compiler team has agreed that using  -fpic by default for this config makes sense.

NOTE: The Android platform and NDK build scripts always enforce the -fpic flag at compile time, which is why this went undetected, and why typical NDK users should not be concerned about this.

I have uploaded this patch: https://review.source.android.com/#change,20276 to change the default.

I can't guarantee that updated compiler binaries will make it to the upcoming NDK update, due to QA milestones. If not, try placing the patch under build/tools/toolchain-patches/gcc/ then rebuild the binaries manually (see docs/DEVELOPMENT.html), or simply use -fpic in your CFLAGS.

- David

teknoraver

unread,
Jan 10, 2011, 10:57:24 AM1/10/11
to android-ndk
On 8 Gen, 15:04, David Turner <di...@android.com> wrote:
> Ok, just to clarify a few things, we ran our own tests and found the root
> cause of the problem.
> Briefly, we can say that:
>
> - This does not affect anyone using the NDK build system, only people who
> want to use the toolchain in standalone mode.
> - If you use the standalone toolchain, just use the -fpic flag to build your
> object files and get rid of the problem.
>
> The root cause of the problem is that the arm-linux-androideabi
> configuration forces -fPIC by default, which generates slower code in
> certain conditions met by
> the benchmark's loop. The reason for this is historical, and the C compiler
> team has agreed that using -fpic by default for this config makes sense.
>
> NOTE: The Android platform and NDK build scripts always enforce the -fpic
> flag at compile time, which is why this went undetected, and why typical NDK
> users should not be concerned about this.
>
> I have uploaded this patch:https://review.source.android.com/#change,20276to
> change the default.
>
> I can't guarantee that updated compiler binaries will make it to the
> upcoming NDK update, due to QA milestones. If not, try placing the patch
> under build/tools/toolchain-patches/gcc/ then rebuild the binaries manually
> (see docs/DEVELOPMENT.html), or simply use -fpic in your CFLAGS.
>
> - David
>
> On Fri, Jan 7, 2011 at 3:52 AM, Doug Kwan (關振德) <dougk...@google.com> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > Can you do an experiment for me? Please try adding -fpic to CFLAGS
> > with NDK4 and -fno-pic to CFLAGS with NDK5 and see if these make a
> > difference and how.
>
> > -Doug
>
> > On Wed, Jan 5, 2011 at 10:21 AM, Doug Kwan (關振德) <dougk...@google.com>
> > wrote:
> > > Hi,
>
> > > Thanks for reporting this. We are starting to look at that.
>
> > > -Doug
>
> > > On Tue, Jan 4, 2011 at 5:39 PM, teknoraver <technobo...@gmail.com>
> > android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr oups.com>
> > .
> > >> For more options, visit this group at
> >http://groups.google.com/group/android-ndk?hl=en.
>
> > --
> > 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<android-ndk%2Bunsubscribe@googlegr oups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/android-ndk?hl=en.

Yes adding -fno-pic to the NDK5 gives very good performances, better
than the old NDK4:

~ # /data/dry-443 2>/dev/null
Dhrystone Benchmark, Version C, Version 2.2
Microseconds for one run through Dhrystone: 0.4
Dhrystones per Second: 2427184


It's almost as fast as the OpenWrt/CodeSourcery toolchain which
actually is the best available:

~ # /data/dry-cs 2>/dev/null
Dhrystone Benchmark, Version C, Version 2.2
Microseconds for one run through Dhrystone: 0.4
Dhrystones per Second: 2612330

Cheers
Reply all
Reply to author
Forward
0 new messages