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
33 33
34#ifdef CONFIG_TRACE_IRQFLAGS34#ifdef CONFIG_TRACE_IRQFLAGS
35 35
36/* Per-task IRQ trace events information. */
37struct 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
36DECLARE_PER_CPU(int, hardirqs_enabled);49DECLARE_PER_CPU(int, hardirqs_enabled);
37DECLARE_PER_CPU(int, hardirq_context);50DECLARE_PER_CPU(int, hardirq_context);
38 51
include/linux/sched.h+2−9
@@ -18,6 +18,7 @@ · 17 unmodified lines
18#include <linux/mutex.h>18#include <linux/mutex.h>
19#include <linux/plist.h>19#include <linux/plist.h>
20#include <linux/hrtimer.h>20#include <linux/hrtimer.h>
21#include <linux/irqflags.h>
21#include <linux/seccomp.h>22#include <linux/seccomp.h>
22#include <linux/nodemask.h>23#include <linux/nodemask.h>
23#include <linux/rcupdate.h>24#include <linux/rcupdate.h>
@@ -980,17 +981,9 @@ struct task_struct { · 956 unmodified lines
980#endif981#endif
981 982
982#ifdef CONFIG_TRACE_IRQFLAGS983#ifdef CONFIG_TRACE_IRQFLAGS
983 unsigned int irq_events;984 struct irqtrace_events irqtrace;
984 unsigned int hardirq_threaded;985 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;
989 u64 hardirq_chain_key;986 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;
994 int softirqs_enabled;987 int softirqs_enabled;
995 int softirq_context;988 int softirq_context;
996 int irq_config;989 int irq_config;
kernel/fork.c+5−11
@@ -2035,17 +2035,11 @@ static __latent_entropy struct task_struct *copy_process( · 2034 unmodified lines
2035 seqcount_init(&p->mems_allowed_seq);2035 seqcount_init(&p->mems_allowed_seq);
2036#endif2036#endif
2037#ifdef CONFIG_TRACE_IRQFLAGS2037#ifdef CONFIG_TRACE_IRQFLAGS
2038 p->irq_events = 0;2038 memset(&p->irqtrace, 0, sizeof(p->irqtrace));
2039 p->hardirq_enable_ip = 0;2039 p->irqtrace.hardirq_disable_ip = _THIS_IP_;
2040 p->hardirq_enable_event = 0;2040 p->irqtrace.softirq_enable_ip = _THIS_IP_;
2041 p->hardirq_disable_ip = _THIS_IP_;2041 p->softirqs_enabled = 1;
2042 p->hardirq_disable_event = 0;2042 p->softirq_context = 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;
2049#endif2043#endif
2050 2044
2051 p->pagefault_disabled = 0;2045 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
3484 3484
3485void print_irqtrace_events(struct task_struct *curr)3485void print_irqtrace_events(struct task_struct *curr)
3486{3486{
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);
3488 printk("hardirqs last enabled at (%u): [<%px>] %pS\n",3490 printk("hardirqs last enabled at (%u): [<%px>] %pS\n",
3489 curr->hardirq_enable_event, (void *)curr->hardirq_enable_ip,3491 trace->hardirq_enable_event, (void *)trace->hardirq_enable_ip,
3490 (void *)curr->hardirq_enable_ip);3492 (void *)trace->hardirq_enable_ip);
3491 printk("hardirqs last disabled at (%u): [<%px>] %pS\n",3493 printk("hardirqs last disabled at (%u): [<%px>] %pS\n",
3492 curr->hardirq_disable_event, (void *)curr->hardirq_disable_ip,3494 trace->hardirq_disable_event, (void *)trace->hardirq_disable_ip,
3493 (void *)curr->hardirq_disable_ip);3495 (void *)trace->hardirq_disable_ip);
3494 printk("softirqs last enabled at (%u): [<%px>] %pS\n",3496 printk("softirqs last enabled at (%u): [<%px>] %pS\n",
3495 curr->softirq_enable_event, (void *)curr->softirq_enable_ip,3497 trace->softirq_enable_event, (void *)trace->softirq_enable_ip,
3496 (void *)curr->softirq_enable_ip);3498 (void *)trace->softirq_enable_ip);
3497 printk("softirqs last disabled at (%u): [<%px>] %pS\n",3499 printk("softirqs last disabled at (%u): [<%px>] %pS\n",
3498 curr->softirq_disable_event, (void *)curr->softirq_disable_ip,3500 trace->softirq_disable_event, (void *)trace->softirq_disable_ip,
3499 (void *)curr->softirq_disable_ip);3501 (void *)trace->softirq_disable_ip);
3500}3502}
3501 3503
3502static int HARDIRQ_verbose(struct lock_class *class)3504static int HARDIRQ_verbose(struct lock_class *class)
@@ -3699,7 +3701,7 @@ EXPORT_SYMBOL_GPL(lockdep_hardirqs_on_prepare); · 196 unmodified lines
3699 3701
3700void noinstr lockdep_hardirqs_on(unsigned long ip)3702void noinstr lockdep_hardirqs_on(unsigned long ip)
3701{3703{
3702 struct task_struct *curr = current;3704 struct irqtrace_events *trace = &current->irqtrace;
3703 3705
3704 if (unlikely(!debug_locks))3706 if (unlikely(!debug_locks))
3705 return;3707 return;
@@ -3752,8 +3754,8 @@ void noinstr lockdep_hardirqs_on(unsigned long ip) · 46 unmodified lines
3752skip_checks:3754skip_checks:
3753 /* we'll do an OFF -> ON transition: */3755 /* we'll do an OFF -> ON transition: */
3754 this_cpu_write(hardirqs_enabled, 1);3756 this_cpu_write(hardirqs_enabled, 1);
3755 curr->hardirq_enable_ip = ip;3757 trace->hardirq_enable_ip = ip;
3756 curr->hardirq_enable_event = ++curr->irq_events;3758 trace->hardirq_enable_event = ++trace->irq_events;
3757 debug_atomic_inc(hardirqs_on_events);3759 debug_atomic_inc(hardirqs_on_events);
3758}3760}
3759EXPORT_SYMBOL_GPL(lockdep_hardirqs_on);3761EXPORT_SYMBOL_GPL(lockdep_hardirqs_on);
@@ -3763,8 +3765,6 @@ EXPORT_SYMBOL_GPL(lockdep_hardirqs_on); · 3 unmodified lines
3763 */3765 */
3764void noinstr lockdep_hardirqs_off(unsigned long ip)3766void noinstr lockdep_hardirqs_off(unsigned long ip)
3765{3767{
3766 struct task_struct *curr = current;
3767
3768 if (unlikely(!debug_locks))3768 if (unlikely(!debug_locks))
3769 return;3769 return;
3770 3770
@@ -3784,12 +3784,14 @@ void noinstr lockdep_hardirqs_off(unsigned long ip) · 13 unmodified lines
3784 return;3784 return;
3785 3785
3786 if (lockdep_hardirqs_enabled()) {3786 if (lockdep_hardirqs_enabled()) {
3787 struct irqtrace_events *trace = &current->irqtrace;
3788
3787 /*3789 /*
3788 * We have done an ON -> OFF transition:3790 * We have done an ON -> OFF transition:
3789 */3791 */
3790 this_cpu_write(hardirqs_enabled, 0);3792 this_cpu_write(hardirqs_enabled, 0);
3791 curr->hardirq_disable_ip = ip;3793 trace->hardirq_disable_ip = ip;
3792 curr->hardirq_disable_event = ++curr->irq_events;3794 trace->hardirq_disable_event = ++trace->irq_events;
3793 debug_atomic_inc(hardirqs_off_events);3795 debug_atomic_inc(hardirqs_off_events);
3794 } else {3796 } else {
3795 debug_atomic_inc(redundant_hardirqs_off);3797 debug_atomic_inc(redundant_hardirqs_off);
@@ -3802,7 +3804,7 @@ EXPORT_SYMBOL_GPL(lockdep_hardirqs_off); · 6 unmodified lines
3802 */3804 */
3803void lockdep_softirqs_on(unsigned long ip)3805void lockdep_softirqs_on(unsigned long ip)
3804{3806{
3805 struct task_struct *curr = current;3807 struct irqtrace_events *trace = &current->irqtrace;
3806 3808
3807 if (unlikely(!debug_locks || current->lockdep_recursion))3809 if (unlikely(!debug_locks || current->lockdep_recursion))
3808 return;3810 return;
@@ -3814,7 +3816,7 @@ void lockdep_softirqs_on(unsigned long ip) · 5 unmodified lines
3814 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))3816 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
3815 return;3817 return;
3816 3818
3817 if (curr->softirqs_enabled) {3819 if (current->softirqs_enabled) {
3818 debug_atomic_inc(redundant_softirqs_on);3820 debug_atomic_inc(redundant_softirqs_on);
3819 return;3821 return;
3820 }3822 }
@@ -3823,9 +3825,9 @@ void lockdep_softirqs_on(unsigned long ip) · 2 unmodified lines
3823 /*3825 /*
3824 * We'll do an OFF -> ON transition:3826 * We'll do an OFF -> ON transition:
3825 */3827 */
3826 curr->softirqs_enabled = 1;3828 current->softirqs_enabled = 1;
3827 curr->softirq_enable_ip = ip;3829 trace->softirq_enable_ip = ip;
3828 curr->softirq_enable_event = ++curr->irq_events;3830 trace->softirq_enable_event = ++trace->irq_events;
3829 debug_atomic_inc(softirqs_on_events);3831 debug_atomic_inc(softirqs_on_events);
3830 /*3832 /*
3831 * We are going to turn softirqs on, so set the3833 * We are going to turn softirqs on, so set the
@@ -3833,7 +3835,7 @@ void lockdep_softirqs_on(unsigned long ip) · 1 unmodified line
3833 * enabled too:3835 * enabled too:
3834 */3836 */
3835 if (lockdep_hardirqs_enabled())3837 if (lockdep_hardirqs_enabled())
3836 mark_held_locks(curr, LOCK_ENABLED_SOFTIRQ);3838 mark_held_locks(current, LOCK_ENABLED_SOFTIRQ);
3837 lockdep_recursion_finish();3839 lockdep_recursion_finish();
3838}3840}
3839 3841
@@ -3842,8 +3844,6 @@ void lockdep_softirqs_on(unsigned long ip) · 2 unmodified lines
3842 */3844 */
3843void lockdep_softirqs_off(unsigned long ip)3845void lockdep_softirqs_off(unsigned long ip)
3844{3846{
3845 struct task_struct *curr = current;
3846
3847 if (unlikely(!debug_locks || current->lockdep_recursion))3847 if (unlikely(!debug_locks || current->lockdep_recursion))
3848 return;3848 return;
3849 3849
@@ -3853,13 +3853,15 @@ void lockdep_softirqs_off(unsigned long ip) · 3 unmodified lines
3853 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))3853 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
3854 return;3854 return;
3855 3855
3856 if (curr->softirqs_enabled) {3856 if (current->softirqs_enabled) {
3857 struct irqtrace_events *trace = &current->irqtrace;
3858
3857 /*3859 /*
3858 * We have done an ON -> OFF transition:3860 * We have done an ON -> OFF transition:
3859 */3861 */
3860 curr->softirqs_enabled = 0;3862 current->softirqs_enabled = 0;
3861 curr->softirq_disable_ip = ip;3863 trace->softirq_disable_ip = ip;
3862 curr->softirq_disable_event = ++curr->irq_events;3864 trace->softirq_disable_event = ++trace->irq_events;
3863 debug_atomic_inc(softirqs_off_events);3865 debug_atomic_inc(softirqs_off_events);
3864 /*3866 /*
3865 * Whoops, we wanted softirqs off, so why aren't they?3867 * Whoops, we wanted softirqs off, so why aren't they?