runtime: decrement default cpu amount in nr_jobs (#10841)

pull/10848/head
div72 2021-07-17 17:07:59 +03:00 committed by GitHub
parent 22fcbe70a2
commit d84ffbf73c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 25 deletions

View File

@ -1,15 +0,0 @@
// Copyright (c) 2019-2021 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module runtime
//$if linux {
fn C.sysconf(name int) i64
//}
//$if windows {
fn C.GetCurrentProcessorNumber() u32
//}

View File

@ -11,12 +11,15 @@ import os
// then `nr_jobs` will return that number instead.
// This is useful for runtime tweaking of e.g. threaded or concurrent code.
pub fn nr_jobs() int {
mut cpus := nr_cpus()
mut cpus := nr_cpus() - 1
// allow for overrides, for example using `VJOBS=32 ./v test .`
vjobs := os.getenv('VJOBS').int()
if vjobs > 0 {
cpus = vjobs
}
if cpus == 0 {
return 1
}
return cpus
}

View File

@ -1 +0,0 @@
module runtime

View File

@ -1 +0,0 @@
module runtime

View File

@ -1,14 +1,10 @@
module runtime
fn C.sysconf(name int) i64
// nr_cpus returns the number of virtual CPU cores found on the system.
pub fn nr_cpus() int {
$if linux {
return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
}
$if macos {
return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
}
$if solaris {
$if linux || macos || solaris {
return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
}
return 1