]> git.saurik.com Git - apple/xnu.git/blob - tools/lldbmacros/scheduler.py
45370808328932721adf2b88daeb888f720021f2
[apple/xnu.git] / tools / lldbmacros / scheduler.py
1 from xnu import *
2 from utils import *
3 from process import *
4
5 # TODO: write scheduler related macros here
6
7 # Macro: showinterrupts
8 @lldb_command('showinterrupts')
9 def ShowInterrupts(cmd_args=None):
10 """ Prints IRQ, IPI and TMR counts for each CPU
11 """
12 bcdata = kern.GetValueFromAddress(kern.GetLoadAddressForSymbol('BootCpuData'), 'cpu_data_t *')
13 print "CPU 0 IRQ: {:d}\n".format(bcdata.cpu_stat.irq_ex_cnt)
14 print "CPU 0 IPI: {:d}\n".format(bcdata.cpu_stat.ipi_cnt)
15 print "CPU 0 TMR: {:d}\n".format(bcdata.cpu_stat.timer_cnt)
16 if (kern.globals.machine_info.physical_cpu == 2):
17 if kern.arch == 'arm':
18 cdentries = kern.GetValueFromAddress(kern.GetLoadAddressForSymbol('CpuDataEntries') + 20, 'uintptr_t *')
19 cpu_data_entry = Cast(dereference(cdentries), 'cpu_data_t *')
20 print "CPU 1 IRQ: {:d}\n".format(cpu_data_entry.cpu_stat.irq_ex_cnt)
21 print "CPU 1 IPI: {:d}\n".format(cpu_data_entry.cpu_stat.ipi_cnt)
22 print "CPU 1 TMR: {:d}\n".format(cpu_data_entry.cpu_stat.timer_cnt)
23 elif kern.arch == 'arm64':
24 cdentries = kern.GetValueFromAddress(kern.GetLoadAddressForSymbol('CpuDataEntries') + 24, 'uintptr_t *')
25 cpu_data_entry = Cast(dereference(cdentries), 'cpu_data_t *')
26 print "CPU 1 IRQ: {:d}\n".format(cpu_data_entry.cpu_stat.irq_ex_cnt)
27 print "CPU 1 IPI: {:d}\n".format(cpu_data_entry.cpu_stat.ipi_cnt)
28 print "CPU 1 TMR: {:d}\n".format(cpu_data_entry.cpu_stat.timer_cnt)
29
30 # EndMacro: showinterrupts
31
32 # Macro: showactiveinterrupts
33 @lldb_command('showactiveinterrupts')
34 def ShowActiveInterrupts(cmd_args=None):
35 """ Prints the interrupts that are unmasked & active with the Interrupt Controller
36 Usage: showactiveinterrupts <address of Interrupt Controller object>
37 """
38 if not cmd_args:
39 print "No arguments passed"
40 print ShowActiveInterrupts.__doc__
41 return False
42 aic = kern.GetValueFromAddress(cmd_args[0], 'AppleInterruptController *')
43 if not aic:
44 print "unknown arguments:", str(cmd_args)
45 return False
46
47 aic_base = unsigned(aic._aicBaseAddress)
48 current_interrupt = 0
49 aic_imc_base = aic_base + 0x4180
50 aic_him_offset = 0x80
51 current_pointer = aic_imc_base
52 unmasked = dereference(kern.GetValueFromAddress(current_pointer, 'uintptr_t *'))
53 active = dereference(kern.GetValueFromAddress(current_pointer + aic_him_offset, 'uintptr_t *'))
54 group_count = 0
55 mask = 1
56 while current_interrupt < 192:
57 if (((unmasked & mask) == 0) and (active & mask)):
58 print "Interrupt {:d} unmasked and active\n".format(current_interrupt)
59 current_interrupt = current_interrupt + 1
60 if (current_interrupt % 32 == 0):
61 mask = 1
62 group_count = group_count + 1
63 unmasked = dereference(kern.GetValueFromAddress(current_pointer + (4 * group_count), 'uintptr_t *'))
64 active = dereference(kern.GetValueFromAddress((current_pointer + aic_him_offset) + (4 * group_count), 'uintptr_t *'))
65 else:
66 mask = mask << 1
67
68 # EndMacro: showactiveinterrupts
69