Commit 0892090d authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Automatically set the number of CPUs.

parent 94244f10
......@@ -6,8 +6,8 @@ import (
"fmt"
"os"
"flag"
"runtime"
)
func main() {
// Scans the arg list and sets up flags
debug := flag.Bool("debug", false, "print debugging messages.")
......@@ -27,7 +27,11 @@ func main() {
mountPoint := flag.Arg(1)
state.Mount(mountPoint)
cpus := fuse.CountCpus()
if cpus > 1 {
runtime.GOMAXPROCS(cpus)
}
fmt.Printf("Mounted %s on %s (threaded=%v, debug=%v)\n", orig, mountPoint, *threaded, *debug)
fmt.Printf("Mounted %s on %s (threaded=%v, debug=%v, cpus=%v)\n", orig, mountPoint, *threaded, *debug, cpus)
state.Loop(*threaded)
}
......@@ -11,6 +11,7 @@ import (
"fmt"
"path"
"math"
"regexp"
"syscall"
"unsafe"
)
......@@ -268,3 +269,17 @@ func Writev(fd int, packet [][]byte) (n int, err os.Error) {
}
return
}
func CountCpus() int {
var contents [10240]byte
f, err := os.Open("/proc/stat", os.O_RDONLY, 0)
defer f.Close()
if err != nil {
return 1
}
n, _ := f.Read(contents[:])
re, _ := regexp.Compile("\ncpu[0-9]")
return len(re.FindAllString(string(contents[:n]), 100))
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment