16
16
#include <rtdbg.h>
17
17
18
18
#include <drivers/pic.h>
19
+ #include <ktime.h>
19
20
20
21
struct irq_traps
21
22
{
@@ -44,6 +45,7 @@ static struct rt_pic_irq _pirq_hash[MAX_HANDLERS] =
44
45
.mode = RT_IRQ_MODE_NONE ,
45
46
.priority = RT_UINT32_MAX ,
46
47
.rw_lock = { },
48
+ .stat .min_irq_time_ns = ~(0UL ),
47
49
}
48
50
};
49
51
@@ -504,10 +506,19 @@ rt_err_t rt_pic_handle_isr(struct rt_pic_irq *pirq)
504
506
rt_err_t err = - RT_EEMPTY ;
505
507
rt_list_t * handler_nodes ;
506
508
struct rt_irq_desc * action ;
509
+ #ifdef RT_USING_PIC_STATISTICS
510
+ struct timespec ts ;
511
+ rt_ubase_t irq_time_ns ;
512
+ #endif
507
513
508
514
RT_ASSERT (pirq != RT_NULL );
509
515
RT_ASSERT (pirq -> pic != RT_NULL );
510
516
517
+ #ifdef RT_USING_PIC_STATISTICS
518
+ RT_ASSERT (rt_ktime_boottime_get_ns (& ts ) == RT_EOK );
519
+ pirq -> stat .current_irq_begin [rt_hw_cpu_id ()] = ts .tv_sec * (1000UL * 1000 * 1000 ) + ts .tv_nsec ;
520
+ #endif
521
+
511
522
/* Corrected irq affinity */
512
523
rt_bitmap_set_bit (pirq -> affinity , rt_hw_cpu_id ());
513
524
@@ -561,6 +572,20 @@ rt_err_t rt_pic_handle_isr(struct rt_pic_irq *pirq)
561
572
err = RT_EOK ;
562
573
}
563
574
575
+ #ifdef RT_USING_PIC_STATISTICS
576
+ RT_ASSERT (rt_ktime_boottime_get_ns (& ts ) == RT_EOK );
577
+ irq_time_ns = ts .tv_sec * (1000UL * 1000 * 1000 ) + ts .tv_nsec - pirq -> stat .current_irq_begin [rt_hw_cpu_id ()];
578
+ pirq -> stat .sum_irq_time_ns += irq_time_ns ;
579
+ if (irq_time_ns < pirq -> stat .min_irq_time_ns )
580
+ {
581
+ pirq -> stat .min_irq_time_ns = irq_time_ns ;
582
+ }
583
+ if (irq_time_ns > pirq -> stat .max_irq_time_ns )
584
+ {
585
+ pirq -> stat .max_irq_time_ns = irq_time_ns ;
586
+ }
587
+ #endif
588
+
564
589
return err ;
565
590
}
566
591
@@ -1022,7 +1047,6 @@ rt_err_t rt_pic_init(void)
1022
1047
#if defined(RT_USING_CONSOLE ) && defined(RT_USING_MSH )
1023
1048
static int list_irq (int argc , char * * argv )
1024
1049
{
1025
- rt_ubase_t level ;
1026
1050
rt_size_t irq_nr = 0 ;
1027
1051
rt_bool_t dump_all = RT_FALSE ;
1028
1052
const char * const irq_modes [] =
@@ -1074,6 +1098,10 @@ static int list_irq(int argc, char**argv)
1074
1098
}
1075
1099
#endif
1076
1100
1101
+ #ifdef RT_USING_PIC_STATISTICS
1102
+ rt_kprintf (" max/ns avg/ns min/ns" );
1103
+ #endif
1104
+
1077
1105
rt_kputs ("\n" );
1078
1106
1079
1107
for (int i = 0 ; i < RT_ARRAY_SIZE (_pirq_hash ); ++ i )
@@ -1117,6 +1145,9 @@ static int list_irq(int argc, char**argv)
1117
1145
{
1118
1146
rt_kprintf (" %-10d" , pirq -> isr .action .cpu_counter [cpuid ]);
1119
1147
}
1148
+ #endif
1149
+ #ifdef RT_USING_PIC_STATISTICS
1150
+ rt_kprintf (" %-10d %-10d %-10d" , pirq -> stat .max_irq_time_ns , pirq -> stat .sum_irq_time_ns /pirq -> isr .action .counter , pirq -> stat .min_irq_time_ns );
1120
1151
#endif
1121
1152
rt_kputs ("\n" );
1122
1153
@@ -1137,6 +1168,9 @@ static int list_irq(int argc, char**argv)
1137
1168
{
1138
1169
rt_kprintf (" %-10d" , repeat_isr -> action .cpu_counter [cpuid ]);
1139
1170
}
1171
+ #endif
1172
+ #ifdef RT_USING_PIC_STATISTICS
1173
+ rt_kprintf (" --- --- ---" );
1140
1174
#endif
1141
1175
rt_kputs ("\n" );
1142
1176
}
0 commit comments