Skip to content

Commit

Permalink
[MonoDroid] Query hardware CPU count for Environment.ProcessorCount
Browse files Browse the repository at this point in the history
  • Loading branch information
garuma committed Nov 16, 2011
1 parent 55f3721 commit e211064
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion mono/utils/mono-proclib.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,20 @@ mono_process_get_data (gpointer pid, MonoProcessData data)
int
mono_cpu_count (void)
{
int count;
int count = 0;
#ifdef PLATFORM_ANDROID
/* Android tries really hard to save power by powering off CPUs on SMP phones which
* means the normal way to query cpu count returns a wrong value with userspace API.
* Instead we use /sys entries to query the actual hardware CPU count.
*/
char buffer[10] = {'\0'};
FILE* present = fopen ("/sys/devices/system/cpu/present", "r");
if (present != NULL && fread ((char*)buffer, 1, sizeof (buffer), present) > 3) {
count = atoi (((char*)buffer) + 2) + 1;
if (count > 0)
return count;
}
#endif
#ifdef _SC_NPROCESSORS_ONLN
count = sysconf (_SC_NPROCESSORS_ONLN);
if (count > 0)
Expand Down

0 comments on commit e211064

Please sign in to comment.