1
Facter.add("physicalprocessorcount") do
2
confine :kernel => :linux
5
ppcount = Facter::Util::Resolution.exec('grep "physical id" /proc/cpuinfo|cut -d: -f 2|sort -u|wc -l')
1
# Fact: physicalprocessorcount
3
# Purpose: Return the number of physical processors.
7
# Attempts to use sysfs to get the physical IDs of the processors. Falls
8
# back to /proc/cpuinfo and "physical id" if sysfs is not available.
12
Facter.add('physicalprocessorcount') do
13
confine :kernel => :linux
16
sysfs_cpu_directory = '/sys/devices/system/cpu' # This should always be there ...
18
if File.exists?(sysfs_cpu_directory)
20
# We assume that the sysfs file system has the correct number of entries
21
# under the "/sys/device/system/cpu" directory and if so then we process
22
# content of the file "physical_package_id" located inside the "topology"
23
# directory in each of the per-CPU sub-directories.
25
# As per Linux Kernel documentation and the file "cputopology.txt" located
26
# inside the "/usr/src/linux/Documentation" directory we can find following
31
# 1) /sys/devices/system/cpu/cpuX/topology/physical_package_id:
33
# physical package id of cpuX. Typically corresponds to a physical
34
# socket number, but the actual value is architecture and platform
39
lookup_pattern = "#{sysfs_cpu_directory}" +
40
"/cpu*/topology/physical_package_id"
42
Dir.glob(lookup_pattern).collect { |f| Facter::Util::Resolution.exec("cat #{f}")}.uniq.size
46
# Try to count number of CPUs using the proc file system next ...
48
# We assume that /proc/cpuinfo has what we need and is so then we need
49
# to make sure that we only count unique entries ...
51
str = Facter::Util::Resolution.exec("grep 'physical.\\+:' /proc/cpuinfo")
53
if str then str.scan(/\d+/).uniq.size; end
58
Facter.add('physicalprocessorcount') do
59
confine :kernel => :windows
61
require 'facter/util/wmi'
62
Facter::Util::WMI.execquery("select Name from Win32_Processor").Count