History

lockdep: Refactor IRQ trace events fields into struct

Refactor the IRQ trace events fields, used for printing information about the IRQ trace events, into a separate struct 'irqtrace_events'. This improves readability by separating the information only used in reporting, as well as enables (simplified) storing/restoring of irqtrace_events snapshots. No functional change intended.

Marco Elver committed 6 years ago

Commit 0584df91 parent 859247d4 files · +50 −48Browse files

Unified · Split

4 files
  1. include/linux/irqflags.h +13 −0
  2. include/linux/sched.h +2 −9
  3. kernel/fork.c +5 −11
  4. kernel/locking/lockdep.c +30 −28
include/linux/irqflags.h+13−0
@@ -33,6 +33,19 @@ · 32 unmodified lines
3333
3434 #ifdef CONFIG_TRACE_IRQFLAGS
3535
36+/* Per-task IRQ trace events information. */
37+struct irqtrace_events {
38+ unsigned int irq_events;
39+ unsigned long hardirq_enable_ip;
40+ unsigned long hardirq_disable_ip;
41+ unsigned int hardirq_enable_event;
42+ unsigned int hardirq_disable_event;
43+ unsigned long softirq_disable_ip;
44+ unsigned long softirq_enable_ip;
45+ unsigned int softirq_disable_event;
46+ unsigned int softirq_enable_event;
47+};
48+
3649 DECLARE_PER_CPU(int, hardirqs_enabled);
3750 DECLARE_PER_CPU(int, hardirq_context);
3851
include/linux/sched.h+2−9
@@ -18,6 +18,7 @@ · 17 unmodified lines
1818 #include <linux/mutex.h>
1919 #include <linux/plist.h>
2020 #include <linux/hrtimer.h>
21+#include <linux/irqflags.h>
2122 #include <linux/seccomp.h>
2223 #include <linux/nodemask.h>
2324 #include <linux/rcupdate.h>
@@ -980,17 +981,9 @@ struct task_struct { · 956 unmodified lines
980981 #endif
981982
982983 #ifdef CONFIG_TRACE_IRQFLAGS
983− unsigned int irq_events;
984+ struct irqtrace_events irqtrace;
984985 unsigned int hardirq_threaded;
985− unsigned long hardirq_enable_ip;
986− unsigned long hardirq_disable_ip;
987− unsigned int hardirq_enable_event;
988− unsigned int hardirq_disable_event;
989986 u64 hardirq_chain_key;
990− unsigned long softirq_disable_ip;
991− unsigned long softirq_enable_ip;
992− unsigned int softirq_disable_event;
993− unsigned int softirq_enable_event;
994987 int softirqs_enabled;
995988 int softirq_context;
996989 int irq_config;
kernel/fork.c+5−11
@@ -2035,17 +2035,11 @@ static __latent_entropy struct task_struct *copy_process( · 2034 unmodified lines
20352035 seqcount_init(&p->mems_allowed_seq);
20362036 #endif
20372037 #ifdef CONFIG_TRACE_IRQFLAGS
2038− p->irq_events = 0;
2039− p->hardirq_enable_ip = 0;
2040− p->hardirq_enable_event = 0;
2041− p->hardirq_disable_ip = _THIS_IP_;
2042− p->hardirq_disable_event = 0;
2043− p->softirqs_enabled = 1;
2044− p->softirq_enable_ip = _THIS_IP_;
2045− p->softirq_enable_event = 0;
2046− p->softirq_disable_ip = 0;
2047− p->softirq_disable_event = 0;
2048− p->softirq_context = 0;
2038+ memset(&p->irqtrace, 0, sizeof(p->irqtrace));
2039+ p->irqtrace.hardirq_disable_ip = _THIS_IP_;
2040+ p->irqtrace.softirq_enable_ip = _THIS_IP_;
2041+ p->softirqs_enabled = 1;
2042+ p->softirq_context = 0;
20492043 #endif
20502044
20512045 p->pagefault_disabled = 0;
kernel/locking/lockdep.c+30−28
@@ -3484,19 +3484,21 @@ check_usage_backwards(struct task_struct *curr, struct held_lock *this, · 3483 unmodified lines
34843484
34853485 void print_irqtrace_events(struct task_struct *curr)
34863486 {
3487− printk("irq event stamp: %u\n", curr->irq_events);
3487+ const struct irqtrace_events *trace = &curr->irqtrace;
3488+
3489+ printk("irq event stamp: %u\n", trace->irq_events);
34883490 printk("hardirqs last enabled at (%u): [<%px>] %pS\n",
3489− curr->hardirq_enable_event, (void *)curr->hardirq_enable_ip,
3490− (void *)curr->hardirq_enable_ip);
3491+ trace->hardirq_enable_event, (void *)trace->hardirq_enable_ip,
3492+ (void *)trace->hardirq_enable_ip);
34913493 printk("hardirqs last disabled at (%u): [<%px>] %pS\n",
3492− curr->hardirq_disable_event, (void *)curr->hardirq_disable_ip,
3493− (void *)curr->hardirq_disable_ip);
3494+ trace->hardirq_disable_event, (void *)trace->hardirq_disable_ip,
3495+ (void *)trace->hardirq_disable_ip);
34943496 printk("softirqs last enabled at (%u): [<%px>] %pS\n",
3495− curr->softirq_enable_event, (void *)curr->softirq_enable_ip,
3496− (void *)curr->softirq_enable_ip);
3497+ trace->softirq_enable_event, (void *)trace->softirq_enable_ip,
3498+ (void *)trace->softirq_enable_ip);
34973499 printk("softirqs last disabled at (%u): [<%px>] %pS\n",
3498− curr->softirq_disable_event, (void *)curr->softirq_disable_ip,
3499− (void *)curr->softirq_disable_ip);
3500+ trace->softirq_disable_event, (void *)trace->softirq_disable_ip,
3501+ (void *)trace->softirq_disable_ip);
35003502 }
35013503
35023504 static int HARDIRQ_verbose(struct lock_class *class)
@@ -3699,7 +3701,7 @@ EXPORT_SYMBOL_GPL(lockdep_hardirqs_on_prepare); · 196 unmodified lines
36993701
37003702 void noinstr lockdep_hardirqs_on(unsigned long ip)
37013703 {
3702− struct task_struct *curr = current;
3704+ struct irqtrace_events *trace = &current->irqtrace;
37033705
37043706 if (unlikely(!debug_locks))
37053707 return;
@@ -3752,8 +3754,8 @@ void noinstr lockdep_hardirqs_on(unsigned long ip) · 46 unmodified lines
37523754 skip_checks:
37533755 /* we'll do an OFF -> ON transition: */
37543756 this_cpu_write(hardirqs_enabled, 1);
3755− curr->hardirq_enable_ip = ip;
3756− curr->hardirq_enable_event = ++curr->irq_events;
3757+ trace->hardirq_enable_ip = ip;
3758+ trace->hardirq_enable_event = ++trace->irq_events;
37573759 debug_atomic_inc(hardirqs_on_events);
37583760 }
37593761 EXPORT_SYMBOL_GPL(lockdep_hardirqs_on);
@@ -3763,8 +3765,6 @@ EXPORT_SYMBOL_GPL(lockdep_hardirqs_on); · 3 unmodified lines
37633765 */
37643766 void noinstr lockdep_hardirqs_off(unsigned long ip)
37653767 {
3766− struct task_struct *curr = current;
3767−
37683768 if (unlikely(!debug_locks))
37693769 return;
37703770
@@ -3784,12 +3784,14 @@ void noinstr lockdep_hardirqs_off(unsigned long ip) · 13 unmodified lines
37843784 return;
37853785
37863786 if (lockdep_hardirqs_enabled()) {
3787+ struct irqtrace_events *trace = &current->irqtrace;
3788+
37873789 /*
37883790 * We have done an ON -> OFF transition:
37893791 */
37903792 this_cpu_write(hardirqs_enabled, 0);
3791− curr->hardirq_disable_ip = ip;
3792− curr->hardirq_disable_event = ++curr->irq_events;
3793+ trace->hardirq_disable_ip = ip;
3794+ trace->hardirq_disable_event = ++trace->irq_events;
37933795 debug_atomic_inc(hardirqs_off_events);
37943796 } else {
37953797 debug_atomic_inc(redundant_hardirqs_off);
@@ -3802,7 +3804,7 @@ EXPORT_SYMBOL_GPL(lockdep_hardirqs_off); · 6 unmodified lines
38023804 */
38033805 void lockdep_softirqs_on(unsigned long ip)
38043806 {
3805− struct task_struct *curr = current;
3807+ struct irqtrace_events *trace = &current->irqtrace;
38063808
38073809 if (unlikely(!debug_locks || current->lockdep_recursion))
38083810 return;
@@ -3814,7 +3816,7 @@ void lockdep_softirqs_on(unsigned long ip) · 5 unmodified lines
38143816 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
38153817 return;
38163818
3817− if (curr->softirqs_enabled) {
3819+ if (current->softirqs_enabled) {
38183820 debug_atomic_inc(redundant_softirqs_on);
38193821 return;
38203822 }
@@ -3823,9 +3825,9 @@ void lockdep_softirqs_on(unsigned long ip) · 2 unmodified lines
38233825 /*
38243826 * We'll do an OFF -> ON transition:
38253827 */
3826− curr->softirqs_enabled = 1;
3827− curr->softirq_enable_ip = ip;
3828− curr->softirq_enable_event = ++curr->irq_events;
3828+ current->softirqs_enabled = 1;
3829+ trace->softirq_enable_ip = ip;
3830+ trace->softirq_enable_event = ++trace->irq_events;
38293831 debug_atomic_inc(softirqs_on_events);
38303832 /*
38313833 * We are going to turn softirqs on, so set the
@@ -3833,7 +3835,7 @@ void lockdep_softirqs_on(unsigned long ip) · 1 unmodified line
38333835 * enabled too:
38343836 */
38353837 if (lockdep_hardirqs_enabled())
3836− mark_held_locks(curr, LOCK_ENABLED_SOFTIRQ);
3838+ mark_held_locks(current, LOCK_ENABLED_SOFTIRQ);
38373839 lockdep_recursion_finish();
38383840 }
38393841
@@ -3842,8 +3844,6 @@ void lockdep_softirqs_on(unsigned long ip) · 2 unmodified lines
38423844 */
38433845 void lockdep_softirqs_off(unsigned long ip)
38443846 {
3845− struct task_struct *curr = current;
3846−
38473847 if (unlikely(!debug_locks || current->lockdep_recursion))
38483848 return;
38493849
@@ -3853,13 +3853,15 @@ void lockdep_softirqs_off(unsigned long ip) · 3 unmodified lines
38533853 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
38543854 return;
38553855
3856− if (curr->softirqs_enabled) {
3856+ if (current->softirqs_enabled) {
3857+ struct irqtrace_events *trace = &current->irqtrace;
3858+
38573859 /*
38583860 * We have done an ON -> OFF transition:
38593861 */
3860− curr->softirqs_enabled = 0;
3861− curr->softirq_disable_ip = ip;
3862− curr->softirq_disable_event = ++curr->irq_events;
3862+ current->softirqs_enabled = 0;
3863+ trace->softirq_disable_ip = ip;
3864+ trace->softirq_disable_event = ++trace->irq_events;
38633865 debug_atomic_inc(softirqs_off_events);
38643866 /*
38653867 * Whoops, we wanted softirqs off, so why aren't they?