2013-03-17 13:30:12 -05:00
|
|
|
module LinuxCPUs
|
2014-06-04 16:12:20 +02:00
|
|
|
OPTIMIZATION_FLAGS = {
|
|
|
|
:penryn => '-march=core2 -msse4.1',
|
|
|
|
:core2 => '-march=core2',
|
|
|
|
:core => '-march=prescott',
|
|
|
|
}.freeze
|
2013-06-13 11:57:13 -05:00
|
|
|
def optimization_flags; OPTIMIZATION_FLAGS; end
|
2013-03-17 13:30:12 -05:00
|
|
|
|
2013-08-14 20:05:54 -07:00
|
|
|
# Linux supports x86 only, and universal archs do not apply
|
|
|
|
def arch_32_bit; :i386; end
|
|
|
|
def arch_64_bit; :x86_64; end
|
2013-08-29 16:50:11 -07:00
|
|
|
def universal_archs; [].extend ArchitectureListExtension; end
|
2013-08-14 20:05:54 -07:00
|
|
|
|
2014-06-05 11:05:48 +02:00
|
|
|
def cpuinfo
|
|
|
|
@cpuinfo ||= File.read("/proc/cpuinfo")
|
|
|
|
end
|
|
|
|
|
2013-03-17 13:30:12 -05:00
|
|
|
def type
|
2014-06-05 11:05:48 +02:00
|
|
|
@type ||= if cpuinfo =~ /Intel|AMD/
|
|
|
|
:intel
|
|
|
|
else
|
|
|
|
:dunno
|
|
|
|
end
|
2013-03-10 17:33:06 +00:00
|
|
|
end
|
|
|
|
|
2013-03-17 13:30:12 -05:00
|
|
|
def family
|
2014-06-05 11:05:48 +02:00
|
|
|
cpuinfo[/^cpu family\s*: ([0-9]+)/, 1].to_i
|
2013-03-10 17:33:06 +00:00
|
|
|
end
|
2013-03-23 20:15:51 +01:00
|
|
|
alias_method :intel_family, :family
|
2013-03-10 17:33:06 +00:00
|
|
|
|
2013-03-17 13:30:12 -05:00
|
|
|
def cores
|
2014-06-05 11:05:48 +02:00
|
|
|
cpuinfo.scan(/^processor/).size
|
2013-03-10 17:33:06 +00:00
|
|
|
end
|
|
|
|
|
2014-06-05 11:05:48 +02:00
|
|
|
def flags
|
|
|
|
@flags ||= cpuinfo[/^flags.*/, 0].split
|
2013-03-17 13:30:12 -05:00
|
|
|
end
|
|
|
|
|
2014-06-05 11:05:48 +02:00
|
|
|
%w[aes altivec avx avx2 lm sse3 ssse3 sse4 sse4_2].each { |flag|
|
|
|
|
define_method(flag + "?") { flags.include? flag }
|
|
|
|
}
|
|
|
|
alias_method :is_64_bit?, :lm?
|
|
|
|
|
|
|
|
def bits
|
|
|
|
is_64_bit? ? 64 : 32
|
2013-03-10 17:33:06 +00:00
|
|
|
end
|
|
|
|
end
|