Skip to content

Commit

Permalink
Fix vagrant cpu count on linux.
Browse files Browse the repository at this point in the history
Corrects error in kubernetes@19224de on linux cpus with hyperthreading (we need to pass the results of `cat /proc/cpuinfo | grep 'core id'` through uniq before counting the lines).
Also checks that we found more than 0 lines (cores) and defaults to the result of nproc in case we didn't (necessary for processors without the core id field, so far only observed on a raspberry pi).
  • Loading branch information
BenTheElder committed May 12, 2015
1 parent a98770e commit e6b6813
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ host = RbConfig::CONFIG['host_os']
if host =~ /darwin/
$vm_cpus = `sysctl -n hw.physicalcpu`.to_i
elsif host =~ /linux/
$vm_cpus = `cat /proc/cpuinfo | grep 'core id' | wc -l`.to_i
#This should work on most processors, however it will fail on ones without the core id field.
#So far i have only seen this on a raspberry pi. which you probably don't want to run vagrant on anyhow...
#But just in case we'll default to the result of nproc if we get 0 just to be safe.
$vm_cpus = `cat /proc/cpuinfo | grep 'core id' | uniq | wc -l`.to_i
if $vm_cpus < 1
$vm_cpus = `nproc`.to_i
end
else # sorry Windows folks, I can't help you
$vm_cpus = 2
end
Expand Down

0 comments on commit e6b6813

Please sign in to comment.