runtime: decrement default cpu amount in nr_jobs (#10841)
parent
22fcbe70a2
commit
d84ffbf73c
|
@ -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
|
|
||||||
|
|
||||||
//}
|
|
|
@ -11,12 +11,15 @@ import os
|
||||||
// then `nr_jobs` will return that number instead.
|
// then `nr_jobs` will return that number instead.
|
||||||
// This is useful for runtime tweaking of e.g. threaded or concurrent code.
|
// This is useful for runtime tweaking of e.g. threaded or concurrent code.
|
||||||
pub fn nr_jobs() int {
|
pub fn nr_jobs() int {
|
||||||
mut cpus := nr_cpus()
|
mut cpus := nr_cpus() - 1
|
||||||
// allow for overrides, for example using `VJOBS=32 ./v test .`
|
// allow for overrides, for example using `VJOBS=32 ./v test .`
|
||||||
vjobs := os.getenv('VJOBS').int()
|
vjobs := os.getenv('VJOBS').int()
|
||||||
if vjobs > 0 {
|
if vjobs > 0 {
|
||||||
cpus = vjobs
|
cpus = vjobs
|
||||||
}
|
}
|
||||||
|
if cpus == 0 {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
return cpus
|
return cpus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
module runtime
|
|
|
@ -1 +0,0 @@
|
||||||
module runtime
|
|
|
@ -1,14 +1,10 @@
|
||||||
module runtime
|
module runtime
|
||||||
|
|
||||||
|
fn C.sysconf(name int) i64
|
||||||
|
|
||||||
// nr_cpus returns the number of virtual CPU cores found on the system.
|
// nr_cpus returns the number of virtual CPU cores found on the system.
|
||||||
pub fn nr_cpus() int {
|
pub fn nr_cpus() int {
|
||||||
$if linux {
|
$if linux || macos || solaris {
|
||||||
return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
|
|
||||||
}
|
|
||||||
$if macos {
|
|
||||||
return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
|
|
||||||
}
|
|
||||||
$if solaris {
|
|
||||||
return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
|
return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
|
||||||
}
|
}
|
||||||
return 1
|
return 1
|
||||||
|
|
Loading…
Reference in New Issue