104 lines
3.9 KiB
Plaintext
104 lines
3.9 KiB
Plaintext
$OpenBSD: patch-lib_facter_physicalprocessorcount_rb,v 1.2 2012/05/05 19:29:49 robert Exp $
|
|
--- lib/facter/physicalprocessorcount.rb.orig Wed Apr 11 18:37:43 2012
|
|
+++ lib/facter/physicalprocessorcount.rb Sat May 5 21:24:32 2012
|
|
@@ -9,50 +9,62 @@
|
|
#
|
|
# Caveats:
|
|
#
|
|
-Facter.add('physicalprocessorcount') do
|
|
- confine :kernel => :linux
|
|
|
|
- setcode do
|
|
- sysfs_cpu_directory = '/sys/devices/system/cpu' # This should always be there ...
|
|
+if ["Linux", "GNU/kFreeBSD"].include? Facter.value(:kernel)
|
|
+ Facter.add('physicalprocessorcount') do
|
|
+ confine :kernel => :linux
|
|
|
|
- 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"
|
|
+ setcode do
|
|
+ sysfs_cpu_directory = '/sys/devices/system/cpu' # This should always be there ...
|
|
|
|
- Dir.glob(lookup_pattern).collect { |f| Facter::Util::Resolution.exec("cat #{f}")}.uniq.size
|
|
+ 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"
|
|
|
|
- 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 ...
|
|
- #
|
|
- str = Facter::Util::Resolution.exec("grep 'physical.\\+:' /proc/cpuinfo")
|
|
+ Dir.glob(lookup_pattern).collect { |f| Facter::Util::Resolution.exec("cat #{f}")}.uniq.size
|
|
|
|
- if str then str.scan(/\d+/).uniq.size; end
|
|
+ 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 ...
|
|
+ #
|
|
+ str = Facter::Util::Resolution.exec("grep 'physical.\\+:' /proc/cpuinfo")
|
|
+
|
|
+ if str then str.scan(/\d+/).uniq.size; end
|
|
+ end
|
|
end
|
|
end
|
|
+end
|
|
+
|
|
+if Facter.value(:kernel) == "OpenBSD"
|
|
+ Facter.add('physicalprocessorcount') do
|
|
+ confine :kernel => :openbsd
|
|
+ setcode do
|
|
+ Facter::Util::Resolution.exec("sysctl -n hw.ncpufound")
|
|
+ end
|
|
+ end
|
|
end
|
|
|
|
Facter.add('physicalprocessorcount') do
|