1010#define MODULE_NAME "opid"
1111
1212#include <trace/events/sched.h>
13- #include <trace/events/irq.h>
14- #include <trace/events/preemptirq.h>
1513#include <rv_trace.h>
1614#include <monitors/sched/sched.h>
1715
1816#define RV_MON_TYPE RV_MON_PER_CPU
1917#include "opid.h"
20- #include <rv/da_monitor .h>
18+ #include <rv/ha_monitor .h>
2119
22- #ifdef CONFIG_X86_LOCAL_APIC
23- #include <asm/trace/irq_vectors.h>
24-
25- static void handle_vector_irq_entry (void * data , int vector )
20+ static u64 ha_get_env (struct ha_monitor * ha_mon , enum envs_opid env , u64 time_ns )
2621{
27- da_handle_event ( irq_entry_opid );
28- }
29-
30- static void attach_vector_irq ( void )
31- {
32- rv_attach_trace_probe ( "opid" , local_timer_entry , handle_vector_irq_entry );
33- if ( IS_ENABLED ( CONFIG_IRQ_WORK ))
34- rv_attach_trace_probe ( "opid" , irq_work_entry , handle_vector_irq_entry );
35- if ( IS_ENABLED ( CONFIG_SMP )) {
36- rv_attach_trace_probe ( "opid" , reschedule_entry , handle_vector_irq_entry );
37- rv_attach_trace_probe ( "opid" , call_function_entry , handle_vector_irq_entry ) ;
38- rv_attach_trace_probe ( "opid" , call_function_single_entry , handle_vector_irq_entry ) ;
22+ if ( env == irq_off_opid )
23+ return irqs_disabled ();
24+ else if ( env == preempt_off_opid ) {
25+ /*
26+ * If CONFIG_PREEMPTION is enabled, then the tracepoint itself disables
27+ * preemption (adding one to the preempt_count). Since we are
28+ * interested in the preempt_count at the time the tracepoint was
29+ * hit, we consider 1 as still enabled.
30+ */
31+ if ( IS_ENABLED ( CONFIG_PREEMPTION ))
32+ return ( preempt_count () & PREEMPT_MASK ) > 1 ;
33+ return true ;
3934 }
35+ return ENV_INVALID_VALUE ;
4036}
4137
42- static void detach_vector_irq (void )
38+ static inline bool ha_verify_guards (struct ha_monitor * ha_mon ,
39+ enum states curr_state , enum events event ,
40+ enum states next_state , u64 time_ns )
4341{
44- rv_detach_trace_probe ( "opid" , local_timer_entry , handle_vector_irq_entry ) ;
45- if ( IS_ENABLED ( CONFIG_IRQ_WORK ))
46- rv_detach_trace_probe ( "opid" , irq_work_entry , handle_vector_irq_entry );
47- if ( IS_ENABLED ( CONFIG_SMP )) {
48- rv_detach_trace_probe ( "opid" , reschedule_entry , handle_vector_irq_entry );
49- rv_detach_trace_probe ( "opid" , call_function_entry , handle_vector_irq_entry );
50- rv_detach_trace_probe ( "opid" , call_function_single_entry , handle_vector_irq_entry ) ;
51- }
42+ bool res = true ;
43+
44+ if ( curr_state == any_opid && event == sched_need_resched_opid )
45+ res = ha_get_env ( ha_mon , irq_off_opid , time_ns ) == 1ull ;
46+ else if ( curr_state == any_opid && event == sched_waking_opid )
47+ res = ha_get_env ( ha_mon , irq_off_opid , time_ns ) == 1ull &&
48+ ha_get_env ( ha_mon , preempt_off_opid , time_ns ) == 1ull ;
49+ return res ;
5250}
5351
54- #else
55- /* We assume irq_entry tracepoints are sufficient on other architectures */
56- static void attach_vector_irq (void ) { }
57- static void detach_vector_irq (void ) { }
58- #endif
59-
60- static void handle_irq_disable (void * data , unsigned long ip , unsigned long parent_ip )
52+ static bool ha_verify_constraint (struct ha_monitor * ha_mon ,
53+ enum states curr_state , enum events event ,
54+ enum states next_state , u64 time_ns )
6155{
62- da_handle_event ( irq_disable_opid );
63- }
56+ if (! ha_verify_guards ( ha_mon , curr_state , event , next_state , time_ns ))
57+ return false;
6458
65- static void handle_irq_enable (void * data , unsigned long ip , unsigned long parent_ip )
66- {
67- da_handle_event (irq_enable_opid );
68- }
69-
70- static void handle_irq_entry (void * data , int irq , struct irqaction * action )
71- {
72- da_handle_event (irq_entry_opid );
73- }
74-
75- static void handle_preempt_disable (void * data , unsigned long ip , unsigned long parent_ip )
76- {
77- da_handle_event (preempt_disable_opid );
78- }
79-
80- static void handle_preempt_enable (void * data , unsigned long ip , unsigned long parent_ip )
81- {
82- da_handle_event (preempt_enable_opid );
59+ return true;
8360}
8461
8562static void handle_sched_need_resched (void * data , struct task_struct * tsk , int cpu , int tif )
8663{
87- /* The monitor's intitial state is not in_irq */
88- if (this_cpu_read (hardirq_context ))
89- da_handle_event (sched_need_resched_opid );
90- else
91- da_handle_start_event (sched_need_resched_opid );
64+ da_handle_start_run_event (sched_need_resched_opid );
9265}
9366
9467static void handle_sched_waking (void * data , struct task_struct * p )
9568{
96- /* The monitor's intitial state is not in_irq */
97- if (this_cpu_read (hardirq_context ))
98- da_handle_event (sched_waking_opid );
99- else
100- da_handle_start_event (sched_waking_opid );
69+ da_handle_start_run_event (sched_waking_opid );
10170}
10271
10372static int enable_opid (void )
@@ -108,14 +77,8 @@ static int enable_opid(void)
10877 if (retval )
10978 return retval ;
11079
111- rv_attach_trace_probe ("opid" , irq_disable , handle_irq_disable );
112- rv_attach_trace_probe ("opid" , irq_enable , handle_irq_enable );
113- rv_attach_trace_probe ("opid" , irq_handler_entry , handle_irq_entry );
114- rv_attach_trace_probe ("opid" , preempt_disable , handle_preempt_disable );
115- rv_attach_trace_probe ("opid" , preempt_enable , handle_preempt_enable );
11680 rv_attach_trace_probe ("opid" , sched_set_need_resched_tp , handle_sched_need_resched );
11781 rv_attach_trace_probe ("opid" , sched_waking , handle_sched_waking );
118- attach_vector_irq ();
11982
12083 return 0 ;
12184}
@@ -124,14 +87,8 @@ static void disable_opid(void)
12487{
12588 rv_this .enabled = 0 ;
12689
127- rv_detach_trace_probe ("opid" , irq_disable , handle_irq_disable );
128- rv_detach_trace_probe ("opid" , irq_enable , handle_irq_enable );
129- rv_detach_trace_probe ("opid" , irq_handler_entry , handle_irq_entry );
130- rv_detach_trace_probe ("opid" , preempt_disable , handle_preempt_disable );
131- rv_detach_trace_probe ("opid" , preempt_enable , handle_preempt_enable );
13290 rv_detach_trace_probe ("opid" , sched_set_need_resched_tp , handle_sched_need_resched );
13391 rv_detach_trace_probe ("opid" , sched_waking , handle_sched_waking );
134- detach_vector_irq ();
13592
13693 da_monitor_destroy ();
13794}
0 commit comments