Support for hotplug cpu cases in percpu array sizing
authorBrenden Blanco <bblanco@gmail.com>
Fri, 20 Jan 2017 23:34:36 +0000 (15:34 -0800)
committerBrenden Blanco <bblanco@gmail.com>
Sat, 21 Jan 2017 06:09:23 +0000 (22:09 -0800)
The kernel uses number of possible cpus to size the leaf, not the num of
online cpus. Fixup the python side appropriately.
Update: use num_possible_cpus() helper instead

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
src/python/bcc/table.py

index 70f7fec..b6feff2 100644 (file)
@@ -21,6 +21,7 @@ import os
 from .libbcc import lib, _RAW_CB_TYPE
 from .perf import Perf
 from .utils import get_online_cpus
+from .utils import get_possible_cpus
 from subprocess import check_output
 
 BPF_MAP_TYPE_HASH = 1
@@ -561,7 +562,7 @@ class PerCpuHash(HashTable):
         self.reducer = kwargs.pop("reducer", None)
         super(PerCpuHash, self).__init__(*args, **kwargs)
         self.sLeaf = self.Leaf
-        self.total_cpu = multiprocessing.cpu_count()
+        self.total_cpu = len(get_possible_cpus())
         # This needs to be 8 as hard coded into the linux kernel.
         self.alignment = ct.sizeof(self.sLeaf) % 8
         if self.alignment is 0:
@@ -617,7 +618,7 @@ class PerCpuArray(ArrayBase):
         self.reducer = kwargs.pop("reducer", None)
         super(PerCpuArray, self).__init__(*args, **kwargs)
         self.sLeaf = self.Leaf
-        self.total_cpu = multiprocessing.cpu_count()
+        self.total_cpu = len(get_possible_cpus())
         # This needs to be 8 as hard coded into the linux kernel.
         self.alignment = ct.sizeof(self.sLeaf) % 8
         if self.alignment is 0: