From: Krzysztof Wilczynski <krzysztof.wilczyn...@linux.com>
Signed-off-by: Adrien Thebo <adr...@puppetlabs.com> --- Local-branch: tickets/next/5135 lib/facter/physicalprocessorcount.rb | 41 ++++++++++++++++++++++++++++++--- 1 files changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/facter/physicalprocessorcount.rb b/lib/facter/physicalprocessorcount.rb index 8fe643e..d6fca6e 100644 --- a/lib/facter/physicalprocessorcount.rb +++ b/lib/facter/physicalprocessorcount.rb @@ -1,7 +1,40 @@ -Facter.add("physicalprocessorcount") do - confine :kernel => :linux +Facter.add('physicalprocessorcount') do + confine :kernel => :linux - setcode do - ppcount = Facter::Util::Resolution.exec('grep "physical id" /proc/cpuinfo|cut -d: -f 2|sort -u|wc -l') + setcode do + sysfs_cpu_directory = '/sys/devices/system/cpu' # This should always be there ... + + if File.exists?(sysfs_cpu_directory) + # + # We assume that the sysfs file system has the correct number of entries + # under the "/sys/device/system/cpu" directory and if so then we process + # content of the file "physical_package_id" located inside the "topology" + # directory in each of the per-CPU sub-directories. + # + # As per Linux Kernel documentation and the file "cputopology.txt" located + # inside the "/usr/src/linux/Documentation" directory we can find following + # short explanation: + # + # (...) + # + # 1) /sys/devices/system/cpu/cpuX/topology/physical_package_id: + # + # physical package id of cpuX. Typically corresponds to a physical + # socket number, but the actual value is architecture and platform + # dependent. + # + # (...) + # + lookup_pattern = "#{sysfs_cpu_directory}/cpu*/topology/physical_package_id" + Dir[lookup_pattern].map { |i| File.read(i).strip }.uniq.size + else + # + # Try to count number of CPUs using the proc file system next ... + # + # We assume that /proc/cpuinfo has what we need and is so then we need + # to make sure that we only count unique entries ... + # + File.read('/proc/cpuinfo').scan(/physical.+:\s(\d+)/).uniq.size end + end end -- 1.7.4.1 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to puppet-dev@googlegroups.com. To unsubscribe from this group, send email to puppet-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.