aboutsummaryrefslogtreecommitdiff
path: root/internal/prefer_openssl
diff options
context:
space:
mode:
Diffstat (limited to 'internal/prefer_openssl')
-rw-r--r--internal/prefer_openssl/cpuinfo.pentium_g630.txt54
-rw-r--r--internal/prefer_openssl/cpuinfo.xeon_e312xx.txt52
-rw-r--r--internal/prefer_openssl/prefer.go29
-rw-r--r--internal/prefer_openssl/prefer_go1.5.go9
-rw-r--r--internal/prefer_openssl/prefer_go1.6.go13
-rw-r--r--internal/prefer_openssl/prefer_test.go23
6 files changed, 180 insertions, 0 deletions
diff --git a/internal/prefer_openssl/cpuinfo.pentium_g630.txt b/internal/prefer_openssl/cpuinfo.pentium_g630.txt
new file mode 100644
index 0000000..b6d7811
--- /dev/null
+++ b/internal/prefer_openssl/cpuinfo.pentium_g630.txt
@@ -0,0 +1,54 @@
+processor : 0
+vendor_id : GenuineIntel
+cpu family : 6
+model : 42
+model name : Intel(R) Pentium(R) CPU G630 @ 2.70GHz
+stepping : 7
+microcode : 0x29
+cpu MHz : 2700.000
+cache size : 3072 KB
+physical id : 0
+siblings : 2
+core id : 0
+cpu cores : 2
+apicid : 0
+initial apicid : 0
+fpu : yes
+fpu_exception : yes
+cpuid level : 13
+wp : yes
+flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 popcnt tsc_deadline_timer xsave lahf_lm arat epb pln pts dtherm tpr_shadow vnmi flexpriority ept vpid xsaveopt
+bugs :
+bogomips : 5387.85
+clflush size : 64
+cache_alignment : 64
+address sizes : 36 bits physical, 48 bits virtual
+power management:
+
+processor : 1
+vendor_id : GenuineIntel
+cpu family : 6
+model : 42
+model name : Intel(R) Pentium(R) CPU G630 @ 2.70GHz
+stepping : 7
+microcode : 0x29
+cpu MHz : 2700.000
+cache size : 3072 KB
+physical id : 0
+siblings : 2
+core id : 1
+cpu cores : 2
+apicid : 2
+initial apicid : 2
+fpu : yes
+fpu_exception : yes
+cpuid level : 13
+wp : yes
+flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 popcnt tsc_deadline_timer xsave lahf_lm arat epb pln pts dtherm tpr_shadow vnmi flexpriority ept vpid xsaveopt
+bugs :
+bogomips : 5387.85
+clflush size : 64
+cache_alignment : 64
+address sizes : 36 bits physical, 48 bits virtual
+power management:
+
diff --git a/internal/prefer_openssl/cpuinfo.xeon_e312xx.txt b/internal/prefer_openssl/cpuinfo.xeon_e312xx.txt
new file mode 100644
index 0000000..efad8c3
--- /dev/null
+++ b/internal/prefer_openssl/cpuinfo.xeon_e312xx.txt
@@ -0,0 +1,52 @@
+processor : 0
+vendor_id : GenuineIntel
+cpu family : 6
+model : 42
+model name : Intel Xeon E312xx (Sandy Bridge)
+stepping : 1
+microcode : 0x1
+cpu MHz : 3300.022
+cache size : 4096 KB
+physical id : 0
+siblings : 1
+core id : 0
+cpu cores : 1
+apicid : 0
+initial apicid : 0
+fpu : yes
+fpu_exception : yes
+cpuid level : 13
+wp : yes
+flags : fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm xsaveopt
+bogomips : 6600.04
+clflush size : 64
+cache_alignment : 64
+address sizes : 40 bits physical, 48 bits virtual
+power management:
+
+processor : 1
+vendor_id : GenuineIntel
+cpu family : 6
+model : 42
+model name : Intel Xeon E312xx (Sandy Bridge)
+stepping : 1
+microcode : 0x1
+cpu MHz : 3300.022
+cache size : 4096 KB
+physical id : 1
+siblings : 1
+core id : 0
+cpu cores : 1
+apicid : 1
+initial apicid : 1
+fpu : yes
+fpu_exception : yes
+cpuid level : 13
+wp : yes
+flags : fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm xsaveopt
+bogomips : 6600.04
+clflush size : 64
+cache_alignment : 64
+address sizes : 40 bits physical, 48 bits virtual
+power management:
+
diff --git a/internal/prefer_openssl/prefer.go b/internal/prefer_openssl/prefer.go
new file mode 100644
index 0000000..16788e0
--- /dev/null
+++ b/internal/prefer_openssl/prefer.go
@@ -0,0 +1,29 @@
+package prefer_openssl
+
+import (
+ "fmt"
+ "io/ioutil"
+ "regexp"
+)
+
+// filePreferOpenSSL tells us if OpenSSL is faster than Go GCM on this machine.
+// Go GCM is fastern when the CPU has AES instructions and Go is v1.6 or higher.
+//
+// See https://github.com/rfjakob/gocryptfs/issues/23#issuecomment-218286502
+// for benchmarks.
+//
+// filePreferOpenSSL takes an explicit filename so it can be tested with saved
+// cpuinfo files instead of /proc/cpuinfo.
+func filePreferOpenSSL(file string) bool {
+ ci, err := ioutil.ReadFile(file)
+ if err != nil {
+ fmt.Println(err)
+ return true
+ }
+ haveAes, err := regexp.Match(`(?m)^flags.*\baes\b`, ci)
+ if err != nil {
+ fmt.Println(err)
+ return true
+ }
+ return !haveAes
+}
diff --git a/internal/prefer_openssl/prefer_go1.5.go b/internal/prefer_openssl/prefer_go1.5.go
new file mode 100644
index 0000000..4b681e7
--- /dev/null
+++ b/internal/prefer_openssl/prefer_go1.5.go
@@ -0,0 +1,9 @@
+// +build !go1.6
+// = go 1.5 or lower
+
+package prefer_openssl
+
+func PreferOpenSSL() bool {
+ // OpenSSL is always faster than Go GCM on old Go versions.
+ return true
+}
diff --git a/internal/prefer_openssl/prefer_go1.6.go b/internal/prefer_openssl/prefer_go1.6.go
new file mode 100644
index 0000000..5d0f426
--- /dev/null
+++ b/internal/prefer_openssl/prefer_go1.6.go
@@ -0,0 +1,13 @@
+// +build go1.6
+// = go 1.6 or higher
+
+package prefer_openssl
+
+// PreferOpenSSL tells us if OpenSSL is faster than Go GCM on this machine.
+// Go GCM is fastern when the CPU has AES instructions and Go is v1.6 or higher.
+//
+// See https://github.com/rfjakob/gocryptfs/issues/23#issuecomment-218286502
+// for benchmarks.
+func PreferOpenSSL() bool {
+ return filePreferOpenSSL("/proc/cpuinfo")
+}
diff --git a/internal/prefer_openssl/prefer_test.go b/internal/prefer_openssl/prefer_test.go
new file mode 100644
index 0000000..a2ed737
--- /dev/null
+++ b/internal/prefer_openssl/prefer_test.go
@@ -0,0 +1,23 @@
+package prefer_openssl
+
+import (
+ "testing"
+)
+
+func TestCurrentCPU(t *testing.T) {
+ t.Logf("PreferOpenSSL=%v", PreferOpenSSL())
+}
+
+// Has AES instructions
+func TestXeonE312xx(t *testing.T) {
+ if filePreferOpenSSL("cpuinfo.xeon_e312xx.txt") == true {
+ t.Fail()
+ }
+}
+
+// Pentium G do not have AES instructions
+func TestPentiumG630(t *testing.T) {
+ if filePreferOpenSSL("cpuinfo.pentium_g630.txt") == false {
+ t.Fail()
+ }
+}