Bug 101 - Environment.ProcessorCount value incorrect for Android
Summary: Environment.ProcessorCount value incorrect for Android
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 1.0
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Rodrigo Kumpera
Depends on:
Reported: 2011-07-28 14:49 UTC by Jérémie Laval
Modified: 2011-08-12 11:47 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Jérémie Laval 2011-07-28 14:49:34 UTC
Environment.ProcessorCount is probably hitting the default path for mono_cpu_count (i.e. return 1;) which was fine but since we now have multicore Android phones/tablets, components such as ParallelFx needs that value to be correct for best performances.
Comment 1 Jonathan Pryor 2011-08-08 15:19:07 UTC
I'm afraid I don't quite follow; as per: 

mono_cpu_count() first has a #ifdef for _SC_NPROCESSORS_ONLN:

	count = sysconf (_SC_NPROCESSORS_ONLN);
	if (count > 0)
		return count;

There's no online NDK installation for me to point you to, but for my Android NDK r5b, platforms/android-4/arch-arm/usr/include/sys/sysconf.h does contain:

    #define _SC_NPROCESSORS_ONLN            0x0061

Consequently, this _should_ already work, and in fact it does: If I run an app on the Motorola Xoom, System.Environment.ProcessorCount is 2.
Comment 2 Jérémie Laval 2011-08-11 07:12:54 UTC
Weird, this is occuring on my LG Optimus 2x phone which like the Motorola Xoom is Tegra 2-based. Maybe the sysconf stuff isn't compiled in my kernel flavor.

I'll wait on a 2.3 update (phone is currently on 2.2.2) and follow-up there.
Comment 3 Jonathan Pryor 2011-08-12 11:47:09 UTC
Are you running a Debug or Release binary? :-)

The DebugRuntime package includes libmonosgen-2.0.so for both armeabi and armeabi-v7a, and the app I was testing was a debug app. (When multiple native libraries are present in a .apk, Android extracts the "best" library for the device, which would be armeabi-v7a on the Xoom.)

However, by default Release apps include the armeabi runtime, _not_ the armeabi-v7a runtime. (You can control this in Project Properties > Application tab > Supported architectures.)

Thus, if you're running a Release app and you haven't changed the Supported architectures field, you'll be running the armeabi (ARMv5) runtime, and ARMv5 doesn't support multiple processors; see also Bug #281.

You may want to adjust your project properties to either exclusively use armeabi-v7a or include both.