Skip to content

Commit

Permalink
android,uv: relax number of cpus assumption
Browse files Browse the repository at this point in the history
Relaxes the assumption that number of CPUs will remain the same
during a uv_cpu_info call on Android. Some devices have a power
saving strategy of taking cores offline during execution. In those
cases, uv_cpu_info may return zero values for properties it couldn't
read.
Adds notes to the os.cpus documentation about the mobile quirks.
  • Loading branch information
jaimecbernardo committed Aug 27, 2018
1 parent 9e90dd8 commit ab46d30
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions deps/uv/src/unix/linux-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,11 @@ static int read_times(FILE* statfile_fp,
ts.irq = clock_ticks * irq;
ci[num++].cpu_times = ts;
}

/* On Android, the number of cores may change during run time. */
#ifndef __ANDROID__
assert(num == numcpus);
#endif

return 0;
}
Expand Down
7 changes: 7 additions & 0 deletions doc/api/os.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ For example:
*Note*: Because `nice` values are UNIX-specific, on Windows the `nice` values
of all processors are always 0.

*Note*: On iOS, CPU speed values are always 0.

*Note*: On Android, returns undefined since Android 8.0. On earlier Android
versions the CPU values can be inconsistent, since some devices can turn CPU
cores on and off as an energy saving strategy. Properties can be returned as
zero for cores that have been turned off while getting them.

## os.endianness()
<!-- YAML
added: v0.9.4
Expand Down

0 comments on commit ab46d30

Please sign in to comment.