diff --git a/linux-ramdump-parser-v2/debug_image_v2.py b/linux-ramdump-parser-v2/debug_image_v2.py index 5545f5015aaf60b5b82d63abb7462d7dc338a282..8d0e7b12a0dda3dbf16ee153041eaa6882df97c4 100755 --- a/linux-ramdump-parser-v2/debug_image_v2.py +++ b/linux-ramdump-parser-v2/debug_image_v2.py @@ -1,4 +1,4 @@ -# Copyright (c) 2012-2016, The Linux Foundation. All rights reserved. +# Copyright (c) 2012-2017, The Linux Foundation. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 and @@ -452,8 +452,7 @@ class DebugImage_v2(): 'msm_dump_table_ids', MAX_NUM_ENTRIES) self.dump_data_id_lookup_table = ram_dump.gdbmi.get_enum_lookup_table( 'msm_dump_data_ids', MAX_NUM_ENTRIES) - cpu_present_bits = ram_dump.read_word('cpu_present_bits') - cpus = bin(cpu_present_bits).count('1') + cpus = ram_dump.get_num_cpus() # per cpu entries for i in range(1, cpus): diff --git a/linux-ramdump-parser-v2/parsers/irqstate.py b/linux-ramdump-parser-v2/parsers/irqstate.py index b9f8d3e754e8a5683c688bde66651a3c531f3a14..3ef406340ad766f3dfa7e590ec790e6dc9636dc9 100755 --- a/linux-ramdump-parser-v2/parsers/irqstate.py +++ b/linux-ramdump-parser-v2/parsers/irqstate.py @@ -1,4 +1,4 @@ -# Copyright (c) 2012-2015, The Linux Foundation. All rights reserved. +# Copyright (c) 2012-2015, 2017 The Linux Foundation. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 and @@ -20,9 +20,7 @@ class IrqParse(RamParser): print_out_str( '=========================== IRQ STATE ===============================') per_cpu_offset_addr = ram_dump.address_of('__per_cpu_offset') - cpu_present_bits_addr = ram_dump.address_of('cpu_present_bits') - cpu_present_bits = ram_dump.read_word(cpu_present_bits_addr) - cpus = bin(cpu_present_bits).count('1') + cpus = ram_dump.get_num_cpus() irq_desc = ram_dump.address_of('irq_desc') foo, irq_desc_size = ram_dump.unwind_lookup(irq_desc, 1) h_irq_offset = ram_dump.field_offset('struct irq_desc', 'handle_irq') diff --git a/linux-ramdump-parser-v2/parsers/slabinfo.py b/linux-ramdump-parser-v2/parsers/slabinfo.py index 460c08ea5cc108e9dd060dc098c8a1d028180707..e65fb1504c95cc409ba78f931414868eff9a9fa1 100644 --- a/linux-ramdump-parser-v2/parsers/slabinfo.py +++ b/linux-ramdump-parser-v2/parsers/slabinfo.py @@ -1,4 +1,4 @@ -# Copyright (c) 2012-2016, The Linux Foundation. All rights reserved. +# Copyright (c) 2012-2017, The Linux Foundation. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 and @@ -284,9 +284,7 @@ class Slabinfo(RamParser): def validate_slab_cache(self, slab_out, input_slabname, map_fn): slab_name_found = False original_slab = self.ramdump.address_of('slab_caches') - cpu_present_bits_addr = self.ramdump.address_of('cpu_present_bits') - cpu_present_bits = self.ramdump.read_word(cpu_present_bits_addr) - cpus = bin(cpu_present_bits).count('1') + cpus = self.ramdump.get_num_cpus() offsetof = struct_member_offset(self.ramdump) self.initializeOffset() slab_list_offset = g_offsetof.kmemcache_list diff --git a/linux-ramdump-parser-v2/parsers/slabsummary.py b/linux-ramdump-parser-v2/parsers/slabsummary.py index 3ae63130771021a26153be71adea0f3f0a61c10d..abe47dc90570ab320d1e25775b6e0fa12163187a 100644 --- a/linux-ramdump-parser-v2/parsers/slabsummary.py +++ b/linux-ramdump-parser-v2/parsers/slabsummary.py @@ -1,4 +1,4 @@ -# Copyright (c) 2012-2016, The Linux Foundation. All rights reserved. +# Copyright (c) 2012-2017, The Linux Foundation. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 and @@ -58,9 +58,7 @@ class Slabinfo_summary(RamParser): slab_summary = {} nCounter = 0 original_slab = self.ramdump.address_of('slab_caches') - cpu_present_bits_addr = self.ramdump.address_of('cpu_present_bits') - cpu_present_bits = self.ramdump.read_word(cpu_present_bits_addr) - cpus = bin(cpu_present_bits).count('1') + cpus = self.ramdump.get_num_cpus() slab_list_offset = self.ramdump.field_offset( 'struct kmem_cache', 'list') slab_name_offset = self.ramdump.field_offset( diff --git a/linux-ramdump-parser-v2/parsers/workqueue.py b/linux-ramdump-parser-v2/parsers/workqueue.py index 21c7b920fb72f79a9c3aa65598684d2783e42331..86e23124cb24216a6877879e1893188088b2f040 100644 --- a/linux-ramdump-parser-v2/parsers/workqueue.py +++ b/linux-ramdump-parser-v2/parsers/workqueue.py @@ -1,4 +1,4 @@ -# Copyright (c) 2012-2015, The Linux Foundation. All rights reserved. +# Copyright (c) 2012-2015, 2017 The Linux Foundation. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 and @@ -212,9 +212,7 @@ class Workqueues(RamParser): worker_pool_size = ram_dump.sizeof('struct worker_pool') pending_work_offset = ram_dump.field_offset( 'struct worker_pool', 'worklist') - cpu_present_bits_addr = ram_dump.address_of('cpu_present_bits') - cpu_present_bits = ram_dump.read_word(cpu_present_bits_addr) - cpus = bin(cpu_present_bits).count('1') + cpus = ram_dump.get_num_cpus() s = '<' for a in range(0, 64): diff --git a/linux-ramdump-parser-v2/ramdump.py b/linux-ramdump-parser-v2/ramdump.py index 58b332f0770bcad040aa5014d27e9070e95bb98a..289b850cde1e491610f1cf7cf64e97879c37c92d 100755 --- a/linux-ramdump-parser-v2/ramdump.py +++ b/linux-ramdump-parser-v2/ramdump.py @@ -1,4 +1,4 @@ -# Copyright (c) 2012-2016, The Linux Foundation. All rights reserved. +# Copyright (c) 2012-2017, The Linux Foundation. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 and @@ -1399,8 +1399,14 @@ class RamDump(): def get_num_cpus(self): """Gets the number of CPUs in the system.""" + major, minor, patch = self.kernel_version cpu_present_bits_addr = self.address_of('cpu_present_bits') cpu_present_bits = self.read_word(cpu_present_bits_addr) + + if (major, minor) >= (4, 5): + cpu_present_bits_addr = self.address_of('__cpu_present_mask') + bits_offset = self.field_offset('struct cpumask', 'bits') + cpu_present_bits = self.read_word(cpu_present_bits_addr + bits_offset) return bin(cpu_present_bits).count('1') def iter_cpus(self):