fix: vec presence check
[deliverable/lttng-analyses.git] / lttnganalyses / linuxautomaton / irq.py
1 # The MIT License (MIT)
2 #
3 # Copyright (C) 2015 - Julien Desfossez <jdesfossez@efficios.com>
4 # 2015 - Antoine Busque <abusque@efficios.com>
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 # SOFTWARE.
23
24 from . import sp, sv
25
26
27 class IrqStateProvider(sp.StateProvider):
28 def __init__(self, state):
29 cbs = {
30 'irq_handler_entry': self._process_irq_handler_entry,
31 'irq_handler_exit': self._process_irq_handler_exit,
32 'softirq_raise': self._process_softirq_raise,
33 'softirq_entry': self._process_softirq_entry,
34 'softirq_exit': self._process_softirq_exit
35 }
36
37 super().__init__(state, cbs)
38
39 def _get_cpu(self, cpu_id):
40 if cpu_id not in self._state.cpus:
41 self._state.cpus[cpu_id] = sv.CPU(cpu_id)
42
43 return self._state.cpus[cpu_id]
44
45 # Hard IRQs
46 def _process_irq_handler_entry(self, event):
47 cpu = self._get_cpu(event['cpu_id'])
48 irq = sv.HardIRQ.new_from_irq_handler_entry(event)
49 cpu.current_hard_irq = irq
50
51 self._state.send_notification_cb('irq_handler_entry',
52 id=irq.id,
53 irq_name=event['name'])
54
55 def _process_irq_handler_exit(self, event):
56 cpu = self._get_cpu(event['cpu_id'])
57 if cpu.current_hard_irq is None or \
58 cpu.current_hard_irq.id != event['irq']:
59 cpu.current_hard_irq = None
60 return
61
62 cpu.current_hard_irq.end_ts = event.timestamp
63 cpu.current_hard_irq.ret = event['ret']
64
65 self._state.send_notification_cb('irq_handler_exit',
66 hard_irq=cpu.current_hard_irq)
67 cpu.current_hard_irq = None
68
69 # SoftIRQs
70 def _process_softirq_raise(self, event):
71 cpu = self._get_cpu(event['cpu_id'])
72 vec = event['vec']
73
74 if vec not in cpu.current_softirqs:
75 cpu.current_softirqs[vec] = []
76
77 # Don't append a SoftIRQ object if one has already been raised,
78 # because they are level-triggered. The only exception to this
79 # is if the first SoftIRQ object already had a begin_ts which
80 # means this raise was triggered after its entry, and will be
81 # handled in the following softirq_entry
82 if cpu.current_softirqs[vec] and \
83 cpu.current_softirqs[vec][0].begin_ts is None:
84 return
85
86 irq = sv.SoftIRQ.new_from_softirq_raise(event)
87 cpu.current_softirqs[vec].append(irq)
88
89 def _process_softirq_entry(self, event):
90 cpu = self._get_cpu(event['cpu_id'])
91 vec = event['vec']
92
93 if cpu.current_softirqs[vec]:
94 cpu.current_softirqs[vec][0].begin_ts = event.timestamp
95 else:
96 # SoftIRQ entry without a corresponding raise
97 irq = sv.SoftIRQ.new_from_softirq_entry(event)
98 cpu.current_softirqs[vec].append(irq)
99
100 def _process_softirq_exit(self, event):
101 cpu = self._get_cpu(event['cpu_id'])
102 vec = event['vec']
103
104 if vec not in cpu.current_softirqs:
105 return
106
107 cpu.current_softirqs[vec][0].end_ts = event.timestamp
108 self._state.send_notification_cb('softirq_exit',
109 softirq=cpu.current_softirqs[vec][0])
110 del cpu.current_softirqs[vec][0]
This page took 0.031943 seconds and 5 git commands to generate.