Skip to content

Commit

Permalink
-speed: print cpu model
Browse files Browse the repository at this point in the history
When somebody posts "gocryptfs -speed" results, they are
most helpful together with the CPU model. Add the cpu model
to the output.

Example:

$ ./gocryptfs -speed
gocryptfs v2.2.0-beta1-5-g52b0444-dirty; go-fuse v2.1.1-0.20210825171523-3ab5d95a30ae; 2021-09-14 go1.17.1 linux/amd64
cpu: Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz; with AES acceleration
AES-GCM-256-OpenSSL       	 862.79 MB/s
AES-GCM-256-Go            	 997.71 MB/s	(selected in auto mode)
AES-SIV-512-Go            	 159.58 MB/s
XChaCha20-Poly1305-OpenSSL	 729.65 MB/s
XChaCha20-Poly1305-Go     	 843.97 MB/s	(selected in auto mode)
  • Loading branch information
rfjakob committed Sep 14, 2021
1 parent 61e37b2 commit 2d0ba24
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,13 @@ Example for a CPU with AES-NI:

```
$ ./gocryptfs -speed
gocryptfs v2.2.0-beta1-4-gcdbc48f; go-fuse v2.1.1-0.20210825171523-3ab5d95a30ae; 2021-09-14 go1.17.1 linux/amd64
AES-GCM-256-OpenSSL 868.09 MB/s
AES-GCM-256-Go 997.97 MB/s (selected in auto mode)
AES-SIV-512-Go 160.72 MB/s
XChaCha20-Poly1305-OpenSSL 722.14 MB/s
XChaCha20-Poly1305-Go 841.89 MB/s (selected in auto mode)
gocryptfs v2.2.0-beta1-5-g52b0444-dirty; go-fuse v2.1.1-0.20210825171523-3ab5d95a30ae; 2021-09-14 go1.17.1 linux/amd64
cpu: Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz; with AES acceleration
AES-GCM-256-OpenSSL 862.79 MB/s
AES-GCM-256-Go 997.71 MB/s (selected in auto mode)
AES-SIV-512-Go 159.58 MB/s
XChaCha20-Poly1305-OpenSSL 729.65 MB/s
XChaCha20-Poly1305-Go 843.97 MB/s (selected in auto mode)
```

You can run `./benchmark.bash` to run gocryptfs' canonical set of
Expand Down
54 changes: 54 additions & 0 deletions internal/speed/cpuinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package speed

import (
"io/ioutil"
"os"
"runtime"
"strings"
)

// cpuModelName returns the "model name" acc. to /proc/cpuinfo, or ""
// on error.
//
// Examples: On my desktop PC:
//
// $ grep "model name" /proc/cpuinfo
// model name : Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz
//
// --> Returns "Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz".
//
// On a Raspberry Pi 4:
//
// $ grep "model name" /proc/cpuinfo
// (empty)
// $ grep Hardware /proc/cpuinfo
// Hardware : BCM2835
//
// --> Returns "BCM2835"
func cpuModelName() string {
if runtime.GOOS != "linux" {
return ""
}
f, err := os.Open("/proc/cpuinfo")
if err != nil {
return ""
}
content, err := ioutil.ReadAll(f)
if err != nil {
return ""
}
lines := strings.Split(string(content), "\n")
// Look for "model name", then for "Hardware" (arm devices don't have "model name")
for _, want := range []string{"model name", "Hardware"} {
for _, line := range lines {
if strings.HasPrefix(line, want) {
parts := strings.SplitN(line, ":", 2)
if len(parts) != 2 {
continue
}
return strings.TrimSpace(parts[1])
}
}
}
return ""
}
10 changes: 10 additions & 0 deletions internal/speed/speed.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ const blockSize = 4096

// Run - run the speed the test and print the results.
func Run() {
cpu := cpuModelName()
if cpu == "" {
cpu = "unknown"
}
aes := "; no AES acceleration"
if stupidgcm.CpuHasAES() {
aes = "; with AES acceleration"
}
fmt.Printf("cpu: %s%s\n", cpu, aes)

bTable := []struct {
name string
f func(*testing.B)
Expand Down

0 comments on commit 2d0ba24

Please sign in to comment.