* Returns number of CPUs on system that are useful for math. */
| 186 | * Returns number of CPUs on system that are useful for math. |
| 187 | */ |
| 188 | int32_t cpu_get_num_math() { |
| 189 | #if defined(__x86_64__) && defined(__linux__) && !defined(__ANDROID__) |
| 190 | int n_cpu = sysconf(_SC_NPROCESSORS_ONLN); |
| 191 | if (n_cpu < 1) { |
| 192 | return cpu_get_num_physical_cores(); |
| 193 | } |
| 194 | if (is_hybrid_cpu()) { |
| 195 | cpu_set_t affinity; |
| 196 | if (!pthread_getaffinity_np(pthread_self(), sizeof(affinity), &affinity)) { |
| 197 | int result = cpu_count_math_cpus(n_cpu); |
| 198 | pthread_setaffinity_np(pthread_self(), sizeof(affinity), &affinity); |
| 199 | if (result > 0) { |
| 200 | return result; |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | #endif |
| 205 | return cpu_get_num_physical_cores(); |
| 206 | } |
| 207 | |
| 208 | // Helper for setting process priority |
| 209 |
no test coverage detected