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 ( ...@@ -6,8 +6,8 @@ import (
"fmt" "fmt"
"os" "os"
"flag" "flag"
"runtime"
) )
func main() { func main() {
// Scans the arg list and sets up flags // Scans the arg list and sets up flags
debug := flag.Bool("debug", false, "print debugging messages.") debug := flag.Bool("debug", false, "print debugging messages.")
...@@ -27,7 +27,11 @@ func main() { ...@@ -27,7 +27,11 @@ func main() {
mountPoint := flag.Arg(1) mountPoint := flag.Arg(1)
state.Mount(mountPoint) state.Mount(mountPoint)
cpus := fuse.CountCpus()
fmt.Printf("Mounted %s on %s (threaded=%v, debug=%v)\n", orig, mountPoint, *threaded, *debug) if cpus > 1 {
runtime.GOMAXPROCS(cpus)
}
fmt.Printf("Mounted %s on %s (threaded=%v, debug=%v, cpus=%v)\n", orig, mountPoint, *threaded, *debug, cpus)
state.Loop(*threaded) state.Loop(*threaded)
} }
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"fmt" "fmt"
"path" "path"
"math" "math"
"regexp"
"syscall" "syscall"
"unsafe" "unsafe"
) )
...@@ -268,3 +269,17 @@ func Writev(fd int, packet [][]byte) (n int, err os.Error) { ...@@ -268,3 +269,17 @@ func Writev(fd int, packet [][]byte) (n int, err os.Error) {
} }
return 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