7 # TODO: write scheduler related macros here
9 # Macro: showallprocrunqcount
11 @lldb_command('showallprocrunqcount')
12 def ShowAllProcRunQCount(cmd_args
=None):
13 """ Prints out the runq count for all processors
15 out_str
= "Processor\t# Runnable\n"
16 processor_itr
= kern
.globals.processor_list
18 out_str
+= "{:d}\t\t{:d}\n".format(processor_itr
.cpu_id
, processor_itr
.runq
.count
)
19 processor_itr
= processor_itr
.processor_list
20 # out_str += "RT:\t\t{:d}\n".format(kern.globals.rt_runq.count)
23 # EndMacro: showallprocrunqcount
25 # Macro: showinterrupts
27 @lldb_command('showinterrupts')
28 def ShowInterrupts(cmd_args
=None):
29 """ Prints IRQ, IPI and TMR counts for each CPU
32 if not kern
.arch
.startswith('arm'):
33 print "showinterrupts is only supported on arm/arm64"
36 base_address
= kern
.GetLoadAddressForSymbol('CpuDataEntries')
40 while x
< unsigned(kern
.globals.machine_info
.physical_cpu
):
41 element
= kern
.GetValueFromAddress(base_address
+ (y
* struct_size
), 'uintptr_t *')[1]
43 cpu_data_entry
= Cast(element
, 'cpu_data_t *')
44 print "CPU {} IRQ: {:d}\n".format(y
, cpu_data_entry
.cpu_stat
.irq_ex_cnt
)
45 print "CPU {} IPI: {:d}\n".format(y
, cpu_data_entry
.cpu_stat
.ipi_cnt
)
46 print "CPU {} PMI: {:d}\n".format(y
, cpu_data_entry
.cpu_monotonic
.mtc_npmis
)
47 print "CPU {} TMR: {:d}\n".format(y
, cpu_data_entry
.cpu_stat
.timer_cnt
)
51 # EndMacro: showinterrupts
53 # Macro: showactiveinterrupts
55 @lldb_command('showactiveinterrupts')
56 def ShowActiveInterrupts(cmd_args
=None):
57 """ Prints the interrupts that are unmasked & active with the Interrupt Controller
58 Usage: showactiveinterrupts <address of Interrupt Controller object>
61 print "No arguments passed"
62 print ShowActiveInterrupts
.__doc
__
64 aic
= kern
.GetValueFromAddress(cmd_args
[0], 'AppleInterruptController *')
66 print "unknown arguments:", str(cmd_args
)
69 aic_base
= unsigned(aic
._aicBaseAddress
)
71 aic_imc_base
= aic_base
+ 0x4180
73 current_pointer
= aic_imc_base
74 unmasked
= dereference(kern
.GetValueFromAddress(current_pointer
, 'uintptr_t *'))
75 active
= dereference(kern
.GetValueFromAddress(current_pointer
+ aic_him_offset
, 'uintptr_t *'))
78 while current_interrupt
< 192:
79 if (((unmasked
& mask
) == 0) and (active
& mask
)):
80 print "Interrupt {:d} unmasked and active\n".format(current_interrupt
)
81 current_interrupt
= current_interrupt
+ 1
82 if (current_interrupt
% 32 == 0):
84 group_count
= group_count
+ 1
85 unmasked
= dereference(kern
.GetValueFromAddress(current_pointer
+ (4 * group_count
), 'uintptr_t *'))
86 active
= dereference(kern
.GetValueFromAddress((current_pointer
+ aic_him_offset
) + (4 * group_count
), 'uintptr_t *'))
89 # EndMacro: showactiveinterrupts
91 # Macro: showirqbyipitimerratio
92 @lldb_command('showirqbyipitimerratio')
93 def ShowIrqByIpiTimerRatio(cmd_args
=None):
94 """ Prints the ratio of IRQ by sum of IPI & TMR counts for each CPU
96 if kern
.arch
== "x86_64":
97 print "This macro is not supported on x86_64 architecture"
100 out_str
= "IRQ-IT Ratio: "
101 base_address
= kern
.GetLoadAddressForSymbol('CpuDataEntries')
105 while x
< unsigned(kern
.globals.machine_info
.physical_cpu
):
106 element
= kern
.GetValueFromAddress(base_address
+ (y
* struct_size
), 'uintptr_t *')[1]
108 cpu_data_entry
= Cast(element
, 'cpu_data_t *')
109 out_str
+= " CPU {} [{:.2f}]".format(y
, float(cpu_data_entry
.cpu_stat
.irq_ex_cnt
)/(cpu_data_entry
.cpu_stat
.ipi_cnt
+ cpu_data_entry
.cpu_stat
.timer_cnt
))
114 # EndMacro: showirqbyipitimerratio
116 #Macro: showinterruptsourceinfo
117 @lldb_command('showinterruptsourceinfo')
118 def showinterruptsourceinfo(cmd_args
= None):
119 """ Extract information of interrupt source causing interrupt storms.
122 print "No arguments passed"
124 #Dump IOInterruptVector object
125 print "--- Dumping IOInterruptVector object ---\n"
126 object_info
= lldb_run_command("dumpobject {:s} IOInterruptVector".format(cmd_args
[0]))
128 print "--- Dumping IOFilterInterruptEventSource object ---\n"
129 #Dump the IOFilterInterruptEventSource object.
130 target_info
=re
.search('target =\s+(.*)',object_info
)
131 target
= target_info
.group()
132 target
= target
.split()
133 #Dump the Object pointer of the source who is triggering the Interrupts.
134 vector_info
=lldb_run_command("dumpobject {:s} ".format(target
[2]))
136 owner_info
= re
.search('owner =\s+(.*)',vector_info
)
137 owner
= owner_info
.group()
140 out
=lldb_run_command(" dumpobject {:s}".format(owner
[2]))
143 # EndMacro: showinterruptsourceinfo
145 @lldb_command('showcurrentabstime')
146 def ShowCurremtAbsTime(cmd_args
=None):
147 """ Routine to print latest absolute time known to system before being stopped.
148 Usage: showcurrentabstime
150 pset
= addressof(kern
.globals.pset0
)
151 processor_array
= kern
.globals.processor_array
154 while unsigned(pset
) != 0:
155 cpu_bitmap
= int(pset
.cpu_bitmask
)
156 for cpuid
in IterateBitmap(cpu_bitmap
):
157 processor
= processor_array
[cpuid
]
158 if unsigned(processor
.last_dispatch
) > cur_abstime
:
159 cur_abstime
= unsigned(processor
.last_dispatch
)
161 pset
= pset
.pset_list
163 print "Last dispatch time known: %d MATUs" % cur_abstime
165 bucketStr
= ["", "FIXPRI (>UI)", "TIMESHARE_FG", "TIMESHARE_IN", "TIMESHARE_DF", "TIMESHARE_UT", "TIMESHARE_BG"]
167 @header(" {:>18s} | {:>20s} | {:>20s} | {:>10s} | {:>10s}".format('Thread Group', 'Interactivity Score', 'Last Timeshare Tick', 'pri_shift', 'highq'))
168 def GetSchedClutchBucketSummary(clutch_bucket
):
169 return " 0x{:>16x} | {:>20d} | {:>20d} | {:>10d} | {:>10d}".format(clutch_bucket
.scb_clutch
.sc_tg
, clutch_bucket
.scb_interactivity_score
, clutch_bucket
.scb_timeshare_tick
, clutch_bucket
.scb_pri_shift
, clutch_bucket
.scb_runq
.highq
)
171 def ShowSchedClutchForPset(pset
):
172 root_clutch
= pset
.pset_clutch_root
173 print "\n{:s} : {:d}\n\n".format("Current Timestamp", GetRecentTimestamp())
174 print "{:>10s} | {:>20s} | {:>30s} | {:>18s} | {:>10s} | {:>10s} | {:>30s} | {:>30s} | {:>15s} | ".format("Root", "Root Buckets", "Clutch Buckets", "Address", "Priority", "Count", "CPU Usage (MATUs)", "CPU Blocked (MATUs)", "Deadline (abs)") + GetSchedClutchBucketSummary
.header
176 print "{:>10s} | {:>20s} | {:>30s} | 0x{:16x} | {:>10d} | {:>10d} | {:>30s} | {:>30s} | {:>15s} | ".format("Root", "*", "*", addressof(root_clutch
), root_clutch
.scr_priority
, root_clutch
.scr_thr_count
, "*", "*", "*")
179 for i
in range(1, 7):
180 root_bucket
= root_clutch
.scr_buckets
[i
]
181 print "{:>10s} | {:>20s} | {:>30s} | 0x{:16x} | {:>10s} | {:>10s} | {:>30s} | {:>30s} | {:>15d} | ".format("*", bucketStr
[i
], "*", addressof(root_bucket
), "*", "*", "*", "*", root_bucket
.scrb_deadline
)
182 prioq
= root_bucket
.scrb_clutch_buckets
183 clutch_bucket_list
= []
184 for clutch_bucket
in IteratePriorityQueue(prioq
, 'struct sched_clutch_bucket', 'scb_pqlink'):
185 clutch_bucket_list
.append(clutch_bucket
)
186 if len(clutch_bucket_list
) > 0:
187 clutch_bucket_list
.sort(key
=lambda x
: x
.scb_priority
, reverse
=True)
188 for clutch_bucket
in clutch_bucket_list
:
189 cpu_used
= clutch_bucket
.scb_cpu_data
.cpu_data
.scbcd_cpu_used
190 cpu_blocked
= clutch_bucket
.scb_cpu_data
.cpu_data
.scbcd_cpu_blocked
191 print "{:>10s} | {:>20s} | {:>30s} | 0x{:16x} | {:>10d} | {:>10d} | {:>30d} | {:>30d} | {:>15s} | ".format("*", "*", clutch_bucket
.scb_clutch
.sc_tg
.tg_name
, clutch_bucket
, clutch_bucket
.scb_priority
, clutch_bucket
.scb_thr_count
, cpu_used
, cpu_blocked
, "*") + GetSchedClutchBucketSummary(clutch_bucket
)
194 @lldb_command('showschedclutch')
195 def ShowSchedClutch(cmd_args
=[]):
196 """ Routine to print the clutch scheduler hierarchy.
197 Usage: showschedclutch <pset>
200 raise ArgumentError("Invalid argument")
201 pset
= kern
.GetValueFromAddress(cmd_args
[0], "processor_set_t")
202 ShowSchedClutchForPset(pset
)
204 @lldb_command('showschedclutchroot')
205 def ShowSchedClutchRoot(cmd_args
=[]):
206 """ show information about the root of the sched clutch hierarchy
207 Usage: showschedclutchroot <root>
210 raise ArgumentError("Invalid argument")
211 root
= kern
.GetValueFromAddress(cmd_args
[0], "struct sched_clutch_root *")
213 print "unknown arguments:", str(cmd_args
)
215 print "{:>30s} : 0x{:16x}".format("Root", root
)
216 print "{:>30s} : 0x{:16x}".format("Pset", root
.scr_pset
)
217 print "{:>30s} : {:d}".format("Priority", root
.scr_priority
)
218 print "{:>30s} : {:d}".format("Urgency", root
.scr_urgency
)
219 print "{:>30s} : {:d}".format("Threads", root
.scr_thr_count
)
220 print "{:>30s} : {:d}".format("Current Timestamp", GetRecentTimestamp())
221 print "{:>30s} : {:b} (BG/UT/DF/IN/FG/FIX/NULL)".format("Runnable Root Buckets Bitmap", int(root
.scr_runnable_bitmap
[0]))
223 @lldb_command('showschedclutchrootbucket')
224 def ShowSchedClutchRootBucket(cmd_args
=[]):
225 """ show information about a root bucket in the sched clutch hierarchy
226 Usage: showschedclutchrootbucket <root_bucket>
229 raise ArgumentError("Invalid argument")
230 root_bucket
= kern
.GetValueFromAddress(cmd_args
[0], "struct sched_clutch_root_bucket *")
232 print "unknown arguments:", str(cmd_args
)
234 print "{:<30s} : 0x{:16x}".format("Root Bucket", root_bucket
)
235 print "{:<30s} : {:s}".format("Bucket Name", bucketStr
[int(root_bucket
.scrb_bucket
)])
236 print "{:<30s} : {:d}".format("Deadline", root_bucket
.scrb_deadline
)
237 print "{:<30s} : {:d}".format("Current Timestamp", GetRecentTimestamp())
239 prioq
= root_bucket
.scrb_clutch_buckets
240 clutch_bucket_list
= []
241 for clutch_bucket
in IteratePriorityQueue(prioq
, 'struct sched_clutch_bucket', 'scb_pqlink'):
242 clutch_bucket_list
.append(clutch_bucket
)
243 if len(clutch_bucket_list
) > 0:
245 print "{:>30s} | {:>18s} | {:>20s} | {:>20s} | ".format("Name", "Clutch Bucket", "Priority", "Count") + GetSchedClutchBucketSummary
.header
247 clutch_bucket_list
.sort(key
=lambda x
: x
.scb_priority
, reverse
=True)
248 for clutch_bucket
in clutch_bucket_list
:
249 print "{:>30s} | 0x{:16x} | {:>20d} | {:>20d} | ".format(clutch_bucket
.scb_clutch
.sc_tg
.tg_name
, clutch_bucket
, clutch_bucket
.scb_priority
, clutch_bucket
.scb_thr_count
) + GetSchedClutchBucketSummary(clutch_bucket
)
251 @lldb_command('showschedclutchbucket')
252 def ShowSchedClutchBucket(cmd_args
=[]):
253 """ show information about a clutch bucket in the sched clutch hierarchy
254 Usage: showschedclutchbucket <clutch_bucket>
257 raise ArgumentError("Invalid argument")
258 clutch_bucket
= kern
.GetValueFromAddress(cmd_args
[0], "struct sched_clutch_bucket *")
259 if not clutch_bucket
:
260 print "unknown arguments:", str(cmd_args
)
262 print "{:<30s} : 0x{:16x}".format("Clutch Bucket", clutch_bucket
)
263 print "{:<30s} : {:s}".format("TG Name", clutch_bucket
.scb_clutch
.sc_tg
.tg_name
)
264 print "{:<30s} : {:d}".format("Priority", clutch_bucket
.scb_priority
)
265 print "{:<30s} : {:d}".format("Thread Count", clutch_bucket
.scb_thr_count
)
266 print "{:<30s} : 0x{:16x}".format("Thread Group", clutch_bucket
.scb_clutch
.sc_tg
)
267 cpu_used
= clutch_bucket
.scb_cpu_data
.cpu_data
.scbcd_cpu_used
268 cpu_blocked
= clutch_bucket
.scb_cpu_data
.cpu_data
.scbcd_cpu_blocked
269 print "{:<30s} : {:d}".format("CPU Used (MATUs)", cpu_used
)
270 print "{:<30s} : {:d}".format("CPU Blocked (MATUs)", cpu_blocked
)
271 print "{:<30s} : {:d}".format("Interactivity Score", clutch_bucket
.scb_interactivity_score
)
272 print "{:<30s} : {:d}".format("Last Timeshare Update Tick", clutch_bucket
.scb_timeshare_tick
)
273 print "{:<30s} : {:d}".format("Priority Shift", clutch_bucket
.scb_pri_shift
)
275 runq
= clutch_bucket
.scb_clutchpri_prioq
277 for thread
in IteratePriorityQueue(runq
, 'struct thread', 'sched_clutchpri_link'):
278 thread_list
.append(thread
)
279 if len(thread_list
) > 0:
281 print GetThreadSummary
.header
+ "{:s}".format("Process Name")
283 for thread
in thread_list
:
284 proc
= Cast(thread
.task
.bsd_info
, 'proc *')
285 print GetThreadSummary(thread
) + "{:s}".format(str(proc
.p_comm
))
287 @lldb_command('abs2nano')
288 def ShowAbstimeToNanoTime(cmd_args
=[]):
289 """ convert mach_absolute_time units to nano seconds
290 Usage: (lldb) abs2nano <timestamp in MATUs>
293 raise ArgumentError("Invalid argument")
294 timedata
= ArgumentStringToInt(cmd_args
[0])
295 ns
= kern
.GetNanotimeFromAbstime(timedata
)
296 us
= float(ns
) / 1000
305 print "{:d} ns, {:f} us, {:f} ms, {:f} s, {:f} m, {:f} h, {:f} d".format(ns
, us
, ms
, s
, m
, h
, d
)
307 print "{:d} ns, {:f} us, {:f} ms, {:f} s".format(ns
, us
, ms
, s
)
309 # Macro: showschedhistory
311 def GetRecentTimestamp():
313 Return a recent timestamp.
314 TODO: on x86, if not in the debugger, then look at the scheduler
316 if kern
.arch
== 'x86_64':
317 return kern
.globals.debugger_entry_time
319 return GetSchedMostRecentDispatch(False)
321 def GetSchedMostRecentDispatch(show_processor_details
=False):
322 """ Return the most recent dispatch on the system, printing processor
323 details if argument is true.
325 processor_list
= kern
.globals.processor_list
327 most_recent_dispatch
= 0
328 current_processor
= processor_list
330 while unsigned(current_processor
) > 0:
331 active_thread
= current_processor
.active_thread
332 if unsigned(active_thread
) != 0 :
333 task_val
= active_thread
.task
334 proc_val
= Cast(task_val
.bsd_info
, 'proc *')
335 proc_name
= "<unknown>" if unsigned(proc_val
) == 0 else str(proc_val
.p_name
)
337 last_dispatch
= unsigned(current_processor
.last_dispatch
)
339 if kern
.arch
== 'x86_64':
340 cpu_data
= kern
.globals.cpu_data_ptr
[current_processor
.cpu_id
]
342 cpu_debugger_time
= max(cpu_data
.debugger_entry_time
, cpu_data
.debugger_ipi_time
)
343 time_since_dispatch
= unsigned(cpu_debugger_time
- last_dispatch
)
344 time_since_dispatch_us
= kern
.GetNanotimeFromAbstime(time_since_dispatch
) / 1000.0
345 time_since_debugger
= unsigned(cpu_debugger_time
- kern
.globals.debugger_entry_time
)
346 time_since_debugger_us
= kern
.GetNanotimeFromAbstime(time_since_debugger
) / 1000.0
348 if show_processor_details
:
349 print "Processor last dispatch: {:16d} Entered debugger: {:16d} ({:8.3f} us after dispatch, {:8.3f} us after debugger) Active thread: 0x{t:<16x} 0x{t.thread_id:<8x} {proc_name:s}".format(last_dispatch
, cpu_debugger_time
,
350 time_since_dispatch_us
, time_since_debugger_us
, t
=active_thread
, proc_name
=proc_name
)
352 if show_processor_details
:
353 print "Processor last dispatch: {:16d} Active thread: 0x{t:<16x} 0x{t.thread_id:<8x} {proc_name:s}".format(last_dispatch
, t
=active_thread
, proc_name
=proc_name
)
355 if last_dispatch
> most_recent_dispatch
:
356 most_recent_dispatch
= last_dispatch
358 current_processor
= current_processor
.processor_list
360 return most_recent_dispatch
362 @header("{:<18s} {:<10s} {:>16s} {:>16s} {:>16s} {:>16s} {:>18s} {:>16s} {:>16s} {:>16s} {:>16s} {:2s} {:2s} {:2s} {:>2s} {:<19s} {:<9s} {:>10s} {:>10s} {:>10s} {:>10s} {:>10s} {:>11s} {:>8s}".format("thread", "id", "on-core", "off-core", "runnable", "prichange", "last-duration (us)", "since-off (us)", "since-on (us)", "pending (us)", "pri-change (us)", "BP", "SP", "TP", "MP", "sched-mode", "state", "cpu-usage", "delta", "sch-usage", "stamp", "shift", "task", "thread-name"))
363 def ShowThreadSchedHistory(thread
, most_recent_dispatch
):
364 """ Given a thread and the most recent dispatch time of a thread on the
365 system, print out details about scheduler history for the thread.
370 if unsigned(thread
.uthread
) != 0:
371 uthread
= Cast(thread
.uthread
, 'uthread *')
372 # Doing the straightforward thing blows up weirdly, so use some indirections to get back on track
373 if unsigned(uthread
.pth_name
) != 0 :
374 thread_name
= str(kern
.GetValueFromAddress(unsigned(uthread
.pth_name
), 'char*'))
377 task_name
= "unknown"
378 if task
and unsigned(task
.bsd_info
):
379 p
= Cast(task
.bsd_info
, 'proc *')
380 task_name
= str(p
.p_name
)
384 mode
= str(thread
.sched_mode
)
385 if "TIMESHARE" in mode
:
386 sched_mode
+="timeshare"
387 elif "FIXED" in mode
:
389 elif "REALTIME" in mode
:
390 sched_mode
+="realtime"
392 if (unsigned(thread
.bound_processor
) != 0):
396 if (unsigned(thread
.sched_flags
) & 0x0004):
401 thread_state_chars
= {0x0:'', 0x1:'W', 0x2:'S', 0x4:'R', 0x8:'U', 0x10:'H', 0x20:'A', 0x40:'P', 0x80:'I'}
405 state_str
+= thread_state_chars
[int(state
& mask
)]
408 last_on
= thread
.computation_epoch
409 last_off
= thread
.last_run_time
410 last_runnable
= thread
.last_made_runnable_time
411 last_prichange
= thread
.last_basepri_change_time
413 if int(last_runnable
) == 18446744073709551615 :
416 if int(last_prichange
) == 18446744073709551615 :
419 time_on_abs
= unsigned(last_off
- last_on
)
420 time_on_us
= kern
.GetNanotimeFromAbstime(time_on_abs
) / 1000.0
422 time_pending_abs
= unsigned(most_recent_dispatch
- last_runnable
)
423 time_pending_us
= kern
.GetNanotimeFromAbstime(time_pending_abs
) / 1000.0
425 if int(last_runnable
) == 0 :
428 last_prichange_abs
= unsigned(most_recent_dispatch
- last_prichange
)
429 last_prichange_us
= kern
.GetNanotimeFromAbstime(last_prichange_abs
) / 1000.0
431 if int(last_prichange
) == 0 :
432 last_prichange_us
= 0
434 time_since_off_abs
= unsigned(most_recent_dispatch
- last_off
)
435 time_since_off_us
= kern
.GetNanotimeFromAbstime(time_since_off_abs
) / 1000.0
436 time_since_on_abs
= unsigned(most_recent_dispatch
- last_on
)
437 time_since_on_us
= kern
.GetNanotimeFromAbstime(time_since_on_abs
) / 1000.0
439 fmt
= "0x{t:<16x} 0x{t.thread_id:<8x} {t.computation_epoch:16d} {t.last_run_time:16d} {last_runnable:16d} {last_prichange:16d} {time_on_us:18.3f} {time_since_off_us:16.3f} {time_since_on_us:16.3f} {time_pending_us:16.3f} {last_prichange_us:16.3f}"
440 fmt2
= " {t.base_pri:2d} {t.sched_pri:2d} {t.task_priority:2d} {t.max_priority:2d} {sched_mode:19s}"
441 fmt3
= " {state:9s} {t.cpu_usage:10d} {t.cpu_delta:10d} {t.sched_usage:10d} {t.sched_stamp:10d} {t.pri_shift:10d} {name:s} {thread_name:s}"
443 out_str
= fmt
.format(t
=thread
, time_on_us
=time_on_us
, time_since_off_us
=time_since_off_us
, time_since_on_us
=time_since_on_us
, last_runnable
=last_runnable
, time_pending_us
=time_pending_us
, last_prichange
=last_prichange
, last_prichange_us
=last_prichange_us
)
444 out_str
+= fmt2
.format(t
=thread
, sched_mode
=sched_mode
)
445 out_str
+= fmt3
.format(t
=thread
, state
=state_str
, name
=task_name
, thread_name
=thread_name
)
449 def SortThreads(threads
, column
):
450 if column
!= 'on-core' and column
!= 'off-core' and column
!= 'last-duration':
451 raise ArgumentError("unsupported sort column")
452 if column
== 'on-core':
453 threads
.sort(key
=lambda t
: t
.computation_epoch
)
454 elif column
== 'off-core':
455 threads
.sort(key
=lambda t
: t
.last_run_time
)
457 threads
.sort(key
=lambda t
: t
.last_run_time
- t
.computation_epoch
)
459 @lldb_command('showschedhistory', 'S:')
460 def ShowSchedHistory(cmd_args
=None, cmd_options
=None):
461 """ Routine to print out thread scheduling history, optionally sorted by a
464 Usage: showschedhistory [-S on-core|off-core|last-duration] [<thread-ptr> ...]
468 if '-S' in cmd_options
:
469 sort_column
= cmd_options
['-S']
472 most_recent_dispatch
= GetSchedMostRecentDispatch(False)
474 print ShowThreadSchedHistory
.header
478 for thread_ptr
in cmd_args
:
479 threads
.append(kern
.GetValueFromAddress(ArgumentStringToInt(thread_ptr
), 'thread *'))
481 SortThreads(threads
, sort_column
)
483 for thread
in threads
:
484 ShowThreadSchedHistory(thread
, most_recent_dispatch
)
486 for thread_ptr
in cmd_args
:
487 thread
= kern
.GetValueFromAddress(ArgumentStringToInt(thread_ptr
), 'thread *')
488 ShowThreadSchedHistory(thread
, most_recent_dispatch
)
492 run_buckets
= kern
.globals.sched_run_buckets
494 run_count
= run_buckets
[GetEnumValue('sched_bucket_t::TH_BUCKET_RUN')]
495 fixpri_count
= run_buckets
[GetEnumValue('sched_bucket_t::TH_BUCKET_FIXPRI')]
496 share_fg_count
= run_buckets
[GetEnumValue('sched_bucket_t::TH_BUCKET_SHARE_FG')]
497 share_df_count
= run_buckets
[GetEnumValue('sched_bucket_t::TH_BUCKET_SHARE_DF')]
498 share_ut_count
= run_buckets
[GetEnumValue('sched_bucket_t::TH_BUCKET_SHARE_UT')]
499 share_bg_count
= run_buckets
[GetEnumValue('sched_bucket_t::TH_BUCKET_SHARE_BG')]
501 sched_pri_shifts
= kern
.globals.sched_run_buckets
503 share_fg_shift
= sched_pri_shifts
[GetEnumValue('sched_bucket_t::TH_BUCKET_SHARE_FG')]
504 share_df_shift
= sched_pri_shifts
[GetEnumValue('sched_bucket_t::TH_BUCKET_SHARE_DF')]
505 share_ut_shift
= sched_pri_shifts
[GetEnumValue('sched_bucket_t::TH_BUCKET_SHARE_UT')]
506 share_bg_shift
= sched_pri_shifts
[GetEnumValue('sched_bucket_t::TH_BUCKET_SHARE_BG')]
509 print "Processors: {g.processor_avail_count:d} Runnable threads: {:d} Fixpri threads: {:d}\n".format(run_count
, fixpri_count
, g
=kern
.globals)
510 print "FG Timeshare threads: {:d} DF Timeshare threads: {:d} UT Timeshare threads: {:d} BG Timeshare threads: {:d}\n".format(share_fg_count
, share_df_count
, share_ut_count
, share_bg_count
)
511 print "Mach factor: {g.sched_mach_factor:d} Load factor: {g.sched_load_average:d} Sched tick: {g.sched_tick:d} timestamp: {g.sched_tick_last_abstime:d} interval:{g.sched_tick_interval:d}\n".format(g
=kern
.globals)
512 print "Fixed shift: {g.sched_fixed_shift:d} FG shift: {:d} DF shift: {:d} UT shift: {:d} BG shift: {:d}\n".format(share_fg_shift
, share_df_shift
, share_ut_shift
, share_bg_shift
, g
=kern
.globals)
513 print "sched_pri_decay_band_limit: {g.sched_pri_decay_band_limit:d} sched_decay_usage_age_factor: {g.sched_decay_usage_age_factor:d}\n".format(g
=kern
.globals)
515 if kern
.arch
== 'x86_64':
516 print "debugger_entry_time: {g.debugger_entry_time:d}\n".format(g
=kern
.globals)
518 most_recent_dispatch
= GetSchedMostRecentDispatch(True)
519 print "Most recent dispatch: " + str(most_recent_dispatch
)
521 print ShowThreadSchedHistory
.header
524 threads
= [t
for t
in IterateQueue(kern
.globals.threads
, 'thread *', 'threads')]
526 SortThreads(threads
, sort_column
)
528 for thread
in threads
:
529 ShowThreadSchedHistory(thread
, most_recent_dispatch
)
531 for thread
in IterateQueue(kern
.globals.threads
, 'thread *', 'threads'):
532 ShowThreadSchedHistory(thread
, most_recent_dispatch
)
535 # EndMacro: showschedhistory
539 return (n ^
0x80000000) - 0x80000000
541 # Macro: showallprocessors
543 def ShowGroupSetSummary(runq
, task_map
):
544 """ Internal function to print summary of group run queue
545 params: runq - value representing struct run_queue *
548 print " runq: count {: <10d} highq: {: <10d} urgency {: <10d}\n".format(runq
.count
, int32(runq
.highq
), runq
.urgency
)
551 runq_queue_count
= sizeof(runq
.queues
)/sizeof(runq
.queues
[0])
553 for runq_queue_i
in xrange(runq_queue_count
) :
554 runq_queue_head
= addressof(runq
.queues
[runq_queue_i
])
555 runq_queue_p
= runq_queue_head
.next
557 if unsigned(runq_queue_p
) != unsigned(runq_queue_head
):
558 runq_queue_this_count
= 0
560 for entry
in ParanoidIterateLinkageChain(runq_queue_head
, "sched_entry_t", "entry_links", circleQueue
=True):
561 runq_queue_this_count
+= 1
563 print " Queue [{: <#012x}] Priority {: <3d} count {:d}\n".format(runq_queue_head
, runq_queue_i
, runq_queue_this_count
)
564 for entry
in ParanoidIterateLinkageChain(runq_queue_head
, "sched_entry_t", "entry_links", circleQueue
=True):
565 group_addr
= unsigned(entry
) - (sizeof(dereference(entry
)) * unsigned(entry
.sched_pri
))
566 group
= kern
.GetValueFromAddress(unsigned(group_addr
), 'sched_group_t')
567 task
= task_map
.get(unsigned(group
), 0x0)
569 print "Cannot find task for group: {: <#012x}".format(group
)
570 print "\tEntry [{: <#012x}] Priority {: <3d} Group {: <#012x} Task {: <#012x}\n".format(unsigned(entry
), entry
.sched_pri
, unsigned(group
), unsigned(task
))
572 @lldb_command('showrunq')
573 def ShowRunq(cmd_args
=None):
574 """ Routine to print information of a runq
575 Usage: showrunq <runq>
579 print "No arguments passed"
580 print ShowRunq
.__doc
__
583 runq
= kern
.GetValueFromAddress(cmd_args
[0], 'struct run_queue *')
584 ShowRunQSummary(runq
)
586 def ShowRunQSummary(runq
):
587 """ Internal function to print summary of run_queue
588 params: runq - value representing struct run_queue *
591 print " runq: count {: <10d} highq: {: <10d} urgency {: <10d}\n".format(runq
.count
, int32(runq
.highq
), runq
.urgency
)
594 runq_queue_count
= sizeof(runq
.queues
)/sizeof(runq
.queues
[0])
596 for runq_queue_i
in xrange(runq_queue_count
) :
597 runq_queue_head
= addressof(runq
.queues
[runq_queue_i
])
598 runq_queue_p
= runq_queue_head
.head
600 if unsigned(runq_queue_p
):
601 runq_queue_this_count
= 0
603 for thread
in ParanoidIterateLinkageChain(runq_queue_head
, "thread_t", "runq_links", circleQueue
=True):
604 runq_queue_this_count
+= 1
606 print " Queue [{: <#012x}] Priority {: <3d} count {:d}\n".format(runq_queue_head
, runq_queue_i
, runq_queue_this_count
)
607 print "\t" + GetThreadSummary
.header
+ "\n"
608 for thread
in ParanoidIterateLinkageChain(runq_queue_head
, "thread_t", "runq_links", circleQueue
=True):
609 print "\t" + GetThreadSummary(thread
) + "\n"
610 if config
['verbosity'] > vHUMAN
:
611 print "\t" + GetThreadBackTrace(thread
, prefix
="\t\t") + "\n"
613 def ShowRTRunQSummary(rt_runq
):
614 if (hex(rt_runq
.count
) == hex(0xfdfdfdfd)) :
615 print " Realtime Queue ({:<#012x}) uninitialized\n".format(addressof(rt_runq
.queue
))
617 print " Realtime Queue ({:<#012x}) Count {:d}\n".format(addressof(rt_runq
.queue
), rt_runq
.count
)
618 if rt_runq
.count
!= 0:
619 print "\t" + GetThreadSummary
.header
+ "\n"
620 for rt_runq_thread
in ParanoidIterateLinkageChain(rt_runq
.queue
, "thread_t", "runq_links", circleQueue
=True):
621 print "\t" + GetThreadSummary(rt_runq_thread
) + "\n"
623 def ShowGrrrSummary(grrr_runq
):
624 """ Internal function to print summary of grrr_run_queue
625 params: grrr_runq - value representing struct grrr_run_queue *
627 print " GRRR Info: Count {: <10d} Weight {: <10d} Current Group {: <#012x}\n".format(grrr_runq
.count
,
628 grrr_runq
.weight
, grrr_runq
.current_group
)
630 grrr_group_count
= sizeof(grrr_runq
.groups
)/sizeof(grrr_runq
.groups
[0])
631 for grrr_group_i
in xrange(grrr_group_count
) :
632 grrr_group
= addressof(grrr_runq
.groups
[grrr_group_i
])
633 if grrr_group
.count
> 0:
634 print " Group {: <3d} [{: <#012x}] ".format(grrr_group
.index
, grrr_group
)
635 print "Count {:d} Weight {:d}\n".format(grrr_group
.count
, grrr_group
.weight
)
636 grrr_group_client_head
= addressof(grrr_group
.clients
)
637 print GetThreadSummary
.header
638 for thread
in ParanoidIterateLinkageChain(grrr_group_client_head
, "thread_t", "runq_links", circleQueue
=True):
639 print "\t" + GetThreadSummary(thread
) + "\n"
640 if config
['verbosity'] > vHUMAN
:
641 print "\t" + GetThreadBackTrace(thread
, prefix
="\t\t") + "\n"
643 def ShowActiveThread(processor
):
644 if (processor
.active_thread
!= 0) :
645 print "\t" + GetThreadSummary
.header
+ "\n"
646 print "\t" + GetThreadSummary(processor
.active_thread
) + "\n"
648 @lldb_command('showallprocessors')
649 @lldb_command('showscheduler')
650 def ShowScheduler(cmd_args
=None):
651 """ Routine to print information of all psets and processors
654 node
= addressof(kern
.globals.pset_node0
)
656 show_priority_runq
= 0
657 show_priority_pset_runq
= 0
658 show_group_pset_runq
= 0
660 sched_string
= str(kern
.globals.sched_string
)
662 if sched_string
== "traditional":
663 show_priority_runq
= 1
664 elif sched_string
== "traditional_with_pset_runqueue":
665 show_priority_pset_runq
= 1
666 elif sched_string
== "grrr":
668 elif sched_string
== "multiq":
669 show_priority_runq
= 1
670 show_group_pset_runq
= 1
671 elif sched_string
== "dualq":
672 show_priority_pset_runq
= 1
673 show_priority_runq
= 1
674 elif sched_string
== "amp":
675 show_priority_pset_runq
= 1
676 show_priority_runq
= 1
677 elif sched_string
== "clutch":
680 print "Unknown sched_string {:s}".format(sched_string
)
682 print "Scheduler: {:s}\n".format(sched_string
)
685 run_buckets
= kern
.globals.sched_run_buckets
686 run_count
= run_buckets
[GetEnumValue('sched_bucket_t::TH_BUCKET_RUN')]
687 fixpri_count
= run_buckets
[GetEnumValue('sched_bucket_t::TH_BUCKET_FIXPRI')]
688 share_fg_count
= run_buckets
[GetEnumValue('sched_bucket_t::TH_BUCKET_SHARE_FG')]
689 share_df_count
= run_buckets
[GetEnumValue('sched_bucket_t::TH_BUCKET_SHARE_DF')]
690 share_ut_count
= run_buckets
[GetEnumValue('sched_bucket_t::TH_BUCKET_SHARE_UT')]
691 share_bg_count
= run_buckets
[GetEnumValue('sched_bucket_t::TH_BUCKET_SHARE_BG')]
692 print "Processors: {g.processor_avail_count:d} Runnable threads: {:d} Fixpri threads: {:d}\n".format(run_count
, fixpri_count
, g
=kern
.globals)
693 print "FG Timeshare threads: {:d} DF Timeshare threads: {:d} UT Timeshare threads: {:d} BG Timeshare threads: {:d}\n".format(share_fg_count
, share_df_count
, share_ut_count
, share_bg_count
)
695 processor_offline
= GetEnumValue('processor_state_t::PROCESSOR_OFF_LINE')
696 processor_idle
= GetEnumValue('processor_state_t::PROCESSOR_IDLE')
697 processor_dispatching
= GetEnumValue('processor_state_t::PROCESSOR_DISPATCHING')
698 processor_running
= GetEnumValue('processor_state_t::PROCESSOR_RUNNING')
700 if show_group_pset_runq
:
701 if hasattr(kern
.globals, "multiq_sanity_check"):
702 print "multiq scheduler config: deep-drain {g.deep_drain:d}, ceiling {g.drain_ceiling:d}, depth limit {g.drain_depth_limit:d}, band limit {g.drain_band_limit:d}, sanity check {g.multiq_sanity_check:d}\n".format(g
=kern
.globals)
704 print "multiq scheduler config: deep-drain {g.deep_drain:d}, ceiling {g.drain_ceiling:d}, depth limit {g.drain_depth_limit:d}, band limit {g.drain_band_limit:d}\n".format(g
=kern
.globals)
706 # Create a group->task mapping
708 for task
in kern
.tasks
:
709 task_map
[unsigned(task
.sched_group
)] = task
710 for task
in kern
.terminated_tasks
:
711 task_map
[unsigned(task
.sched_group
)] = task
717 pset
= kern
.GetValueFromAddress(unsigned(pset
), 'struct processor_set *')
720 print "Processor Set {: <#012x} Count {:d} (cpu_id {:<#x}-{:<#x})\n".format(pset
,
721 unsigned(pset
.cpu_set_count
), pset
.cpu_set_low
, pset
.cpu_set_hi
)
723 rt_runq
= kern
.GetValueFromAddress(unsigned(addressof(pset
.rt_runq
)), 'struct rt_queue *')
724 ShowRTRunQSummary(rt_runq
)
726 if show_priority_pset_runq
:
727 runq
= kern
.GetValueFromAddress(unsigned(addressof(pset
.pset_runq
)), 'struct run_queue *')
728 ShowRunQSummary(runq
)
730 if show_group_pset_runq
:
732 runq
= kern
.GetValueFromAddress(unsigned(addressof(pset
.pset_runq
)), 'struct run_queue *')
733 ShowGroupSetSummary(runq
, task_map
)
734 print "All Groups:\n"
735 # TODO: Possibly output task header for each group
736 for group
in IterateQueue(kern
.globals.sched_groups
, "sched_group_t", "sched_groups"):
737 if (group
.runq
.count
!= 0) :
738 task
= task_map
.get(unsigned(group
), "Unknown task!")
739 print "Group {: <#012x} Task {: <#012x}\n".format(unsigned(group
), unsigned(task
))
740 ShowRunQSummary(group
.runq
)
743 processor_array
= kern
.globals.processor_array
745 print "Active Processors:\n"
746 active_bitmap
= int(pset
.cpu_state_map
[processor_dispatching
]) |
int(pset
.cpu_state_map
[processor_running
])
747 for cpuid
in IterateBitmap(active_bitmap
):
748 processor
= processor_array
[cpuid
]
750 print " " + GetProcessorSummary(processor
)
751 ShowActiveThread(processor
)
753 if show_priority_runq
:
754 runq
= processor
.runq
755 ShowRunQSummary(runq
)
757 grrr_runq
= processor
.grrr_runq
758 ShowGrrrSummary(grrr_runq
)
762 print "Idle Processors:\n"
763 idle_bitmap
= int(pset
.cpu_state_map
[processor_idle
]) & int(pset
.primary_map
)
764 for cpuid
in IterateBitmap(idle_bitmap
):
765 processor
= processor_array
[cpuid
]
767 print " " + GetProcessorSummary(processor
)
768 ShowActiveThread(processor
)
770 if show_priority_runq
:
771 ShowRunQSummary(processor
.runq
)
775 print "Idle Secondary Processors:\n"
776 idle_bitmap
= int(pset
.cpu_state_map
[processor_idle
]) & ~
(int(pset
.primary_map
))
777 for cpuid
in IterateBitmap(idle_bitmap
):
778 processor
= processor_array
[cpuid
]
780 print " " + GetProcessorSummary(processor
)
781 ShowActiveThread(processor
)
783 if show_priority_runq
:
784 print ShowRunQSummary(processor
.runq
)
788 print "Other Processors:\n"
790 for i
in range(processor_offline
, processor_idle
):
791 other_bitmap |
= int(pset
.cpu_state_map
[i
])
792 other_bitmap
&= int(pset
.cpu_bitmask
)
793 for cpuid
in IterateBitmap(other_bitmap
):
794 processor
= processor_array
[cpuid
]
796 print " " + GetProcessorSummary(processor
)
797 ShowActiveThread(processor
)
799 if show_priority_runq
:
800 ShowRunQSummary(processor
.runq
)
804 print "=== Clutch Scheduler Hierarchy ===\n\n"
805 ShowSchedClutchForPset(pset
)
807 pset
= pset
.pset_list
809 node
= node
.node_list
811 print "\nCrashed Threads Queue: ({:<#012x})\n".format(addressof(kern
.globals.crashed_threads_queue
))
813 for thread
in ParanoidIterateLinkageChain(kern
.globals.crashed_threads_queue
, "thread_t", "runq_links"):
815 print "\t" + GetThreadSummary
.header
817 print "\t" + GetThreadSummary(thread
)
819 def dump_mpsc_thread_queue(name
, head
):
820 head
= addressof(head
)
821 print "\n{:s}: ({:<#012x})\n".format(name
, head
)
823 for thread
in IterateMPSCQueue(head
.mpd_queue
, 'struct thread', 'mpsc_links'):
825 print "\t" + GetThreadSummary
.header
827 print "\t" + GetThreadSummary(thread
)
829 dump_mpsc_thread_queue("Terminate Queue", kern
.globals.thread_terminate_queue
)
830 dump_mpsc_thread_queue("Waiting For Kernel Stacks Queue", kern
.globals.thread_stack_queue
)
831 dump_mpsc_thread_queue("Thread Exception Queue", kern
.globals.thread_exception_queue
)
832 dump_mpsc_thread_queue("Thread Deallocate Queue", kern
.globals.thread_deallocate_queue
)
838 # EndMacro: showallprocessors
841 def ParanoidIterateLinkageChain(queue_head
, element_type
, field_name
, field_ofst
=0, circleQueue
=False):
842 """ Iterate over a Linkage Chain queue in kernel of type queue_head_t or circle_queue_head_t. (osfmk/kern/queue.h method 1 or circle_queue.h)
843 This is equivalent to the qe_foreach_element() macro
844 Blows up aggressively and descriptively when something goes wrong iterating a queue.
845 Prints correctness errors, and throws exceptions on 'cannot proceed' errors
846 If this is annoying, set the global 'enable_paranoia' to false.
849 queue_head - value : Value object for queue_head.
850 element_type - lldb.SBType : pointer type of the element which contains the queue_chain_t. Typically its structs like thread, task etc..
851 - str : OR a string describing the type. ex. 'task *'
852 field_name - str : Name of the field (in element) which holds a queue_chain_t
853 field_ofst - int : offset from the 'field_name' (in element) which holds a queue_chain_t
854 This is mostly useful if a particular element contains an array of queue_chain_t
856 A generator does not return. It is used for iterating.
857 value : An object thats of type (element_type). Always a pointer object
859 for thread in IterateQueue(kern.globals.threads, 'thread *', 'threads'):
860 print thread.thread_id
863 if type(element_type
) is str:
864 element_type
= gettype(element_type
)
866 # Some ways of constructing a queue head seem to end up with the
867 # struct object as the value and not a pointer to the struct head
868 # In that case, addressof will give us a pointer to the struct, which is what we need
869 if not queue_head
.GetSBValue().GetType().IsPointerType() :
870 queue_head
= addressof(queue_head
)
873 # Mosh the value into a brand new value, to really get rid of its old cvalue history
874 queue_head
= kern
.GetValueFromAddress(unsigned(queue_head
), 'struct circle_queue_head *').head
876 # Mosh the value into a brand new value, to really get rid of its old cvalue history
877 queue_head
= kern
.GetValueFromAddress(unsigned(queue_head
), 'struct queue_entry *')
879 if unsigned(queue_head
) == 0:
880 if not circleQueue
and ParanoidIterateLinkageChain
.enable_paranoia
:
881 print "bad queue_head_t: {:s}".format(queue_head
)
884 if element_type
.IsPointerType():
885 struct_type
= element_type
.GetPointeeType()
887 struct_type
= element_type
889 elem_ofst
= getfieldoffset(struct_type
, field_name
) + field_ofst
892 link
= queue_head
.next
893 last_link
= queue_head
894 try_read_next
= unsigned(queue_head
.next
)
896 print "Exception while looking at queue_head: {:>#18x}".format(unsigned(queue_head
))
899 if ParanoidIterateLinkageChain
.enable_paranoia
:
900 if unsigned(queue_head
.next
) == 0:
901 raise ValueError("NULL next pointer on head: queue_head {:>#18x} next: {:>#18x} prev: {:>#18x}".format(queue_head
, queue_head
.next
, queue_head
.prev
))
902 if unsigned(queue_head
.prev
) == 0:
903 print "NULL prev pointer on head: queue_head {:>#18x} next: {:>#18x} prev: {:>#18x}".format(queue_head
, queue_head
.next
, queue_head
.prev
)
904 if unsigned(queue_head
.next
) == unsigned(queue_head
) and unsigned(queue_head
.prev
) != unsigned(queue_head
):
905 print "corrupt queue_head {:>#18x} next: {:>#18x} prev: {:>#18x}".format(queue_head
, queue_head
.next
, queue_head
.prev
)
907 if ParanoidIterateLinkageChain
.enable_debug
:
908 print "starting at queue_head {:>#18x} next: {:>#18x} prev: {:>#18x}".format(queue_head
, queue_head
.next
, queue_head
.prev
)
915 if not circleQueue
and unsigned(queue_head
) == unsigned(link
):
917 if ParanoidIterateLinkageChain
.enable_paranoia
:
918 if unsigned(link
.next
) == 0:
919 raise ValueError("NULL next pointer: queue_head {:>#18x} link: {:>#18x} next: {:>#18x} prev: {:>#18x}".format(queue_head
, link
, link
.next
, link
.prev
))
920 if unsigned(link
.prev
) == 0:
921 print "NULL prev pointer: queue_head {:>#18x} link: {:>#18x} next: {:>#18x} prev: {:>#18x}".format(queue_head
, link
, link
.next
, link
.prev
)
922 if unsigned(last_link
) != unsigned(link
.prev
):
923 print "Corrupt prev pointer: queue_head {:>#18x} link: {:>#18x} next: {:>#18x} prev: {:>#18x} prev link: {:>#18x} ".format(
924 queue_head
, link
, link
.next
, link
.prev
, last_link
)
926 addr
= unsigned(link
) - unsigned(elem_ofst
);
927 obj
= kern
.GetValueFromAddress(addr
, element_type
)
928 if ParanoidIterateLinkageChain
.enable_debug
:
929 print "yielding link: {:>#18x} next: {:>#18x} prev: {:>#18x} addr: {:>#18x} obj: {:>#18x}".format(link
, link
.next
, link
.prev
, addr
, obj
)
933 if circleQueue
and unsigned(queue_head
) == unsigned(link
):
936 exc_info
= sys
.exc_info()
938 print "Exception while iterating queue: {:>#18x} link: {:>#18x} addr: {:>#18x} obj: {:>#18x} last link: {:>#18x}".format(queue_head
, link
, addr
, obj
, last_link
)
941 traceback
.print_exc()
942 raise exc_info
[0], exc_info
[1], exc_info
[2]
944 ParanoidIterateLinkageChain
.enable_paranoia
= True
945 ParanoidIterateLinkageChain
.enable_debug
= False
947 def bit_first(bitmap
):
948 return bitmap
.bit_length() - 1
950 def lsb_first(bitmap
):
951 bitmap
= bitmap
& -bitmap
952 return bit_first(bitmap
)
954 def IterateBitmap(bitmap
):
955 """ Iterate over a bitmap, returning the index of set bits starting from 0
958 bitmap - value : bitmap
960 A generator does not return. It is used for iterating.
961 value : index of a set bit
963 for cpuid in IterateBitmap(running_bitmap):
964 print processor_array[cpuid]
966 i
= lsb_first(bitmap
)
969 bitmap
= bitmap
& ~
((1 << (i
+ 1)) - 1)
970 i
= lsb_first(bitmap
)
973 # Macro: showallcallouts
975 def ShowThreadCall(prefix
, call
):
977 Print a description of a thread_call_t and its relationship to its expected fire time
979 func
= call
.tc_call
.func
980 param0
= call
.tc_call
.param0
981 param1
= call
.tc_call
.param1
984 iotes_callout
= kern
.GetLoadAddressForSymbol("_ZN18IOTimerEventSource17timeoutAndReleaseEPvS0_")
985 iotes_callout2
= kern
.GetLoadAddressForSymbol("_ZN18IOTimerEventSource15timeoutSignaledEPvS0_")
987 if (unsigned(func
) == unsigned(iotes_callout
) or
988 unsigned(func
) == unsigned(iotes_callout2
)) :
989 iotes
= Cast(call
.tc_call
.param0
, 'IOTimerEventSource*')
992 param1
= unsigned(iotes
)
994 func_name
= kern
.Symbolicate(func
)
995 if (func_name
== "") :
996 func_name
= FindKmodNameForAddr(func
)
998 call_entry
= call
.tc_call
1000 recent_timestamp
= GetRecentTimestamp()
1002 # THREAD_CALL_CONTINUOUS 0x100
1003 kern
.globals.mach_absolutetime_asleep
1004 if (call
.tc_flags
& 0x100) :
1005 timer_fire
= call_entry
.deadline
- (recent_timestamp
+ kern
.globals.mach_absolutetime_asleep
)
1007 timer_fire
= call_entry
.deadline
- recent_timestamp
1009 timer_fire_s
= kern
.GetNanotimeFromAbstime(timer_fire
) / 1000000000.0
1011 ttd_s
= kern
.GetNanotimeFromAbstime(call
.tc_ttd
) / 1000000000.0
1013 print "{:s}{:#018x}: {:18d} {:18d} {:03.06f} {:03.06f} {:#018x}({:#018x},{:#018x}) ({:s})".format(prefix
,
1014 unsigned(call
), call_entry
.deadline
, call
.tc_soft_deadline
, ttd_s
, timer_fire_s
,
1015 func
, param0
, param1
, func_name
)
1017 @lldb_command('showallcallouts')
1018 def ShowAllCallouts(cmd_args
=None):
1019 """ Prints out the pending and delayed thread calls for the thread call groups
1022 index_max
= GetEnumValue('thread_call_index_t::THREAD_CALL_INDEX_MAX')
1024 for i
in range (0, index_max
) :
1025 group
= kern
.globals.thread_call_groups
[i
]
1027 print "Group {i:d}: {g.tcg_name:s} ({:>#18x})".format(addressof(group
), i
=i
, g
=group
)
1028 print "\t" +"Active: {g.active_count:d} Idle: {g.idle_count:d}\n".format(g
=group
)
1029 print "\t" +"Blocked: {g.blocked_count:d} Pending: {g.pending_count:d}\n".format(g
=group
)
1030 print "\t" +"Target: {g.target_thread_count:d}\n".format(g
=group
)
1032 print "\t" +"Pending Queue: ({:>#18x})\n".format(addressof(group
.pending_queue
))
1033 for call
in ParanoidIterateLinkageChain(group
.pending_queue
, "thread_call_t", "tc_call.q_link"):
1034 ShowThreadCall("\t\t", call
)
1036 print "\t" +"Delayed Queue (Absolute Time): ({:>#18x}) timer: ({:>#18x})\n".format(
1037 addressof(group
.delayed_queues
[0]), addressof(group
.delayed_timers
[0]))
1038 for call
in ParanoidIterateLinkageChain(group
.delayed_queues
[0], "thread_call_t", "tc_call.q_link"):
1039 ShowThreadCall("\t\t", call
)
1041 print "\t" +"Delayed Queue (Continuous Time): ({:>#18x}) timer: ({:>#18x})\n".format(
1042 addressof(group
.delayed_queues
[1]), addressof(group
.delayed_timers
[1]))
1043 for call
in ParanoidIterateLinkageChain(group
.delayed_queues
[1], "thread_call_t", "tc_call.q_link"):
1044 ShowThreadCall("\t\t", call
)
1046 # EndMacro: showallcallouts