net/sched/sch_generic: Measure the time between watchdog runs
Subsystems (4)
RFC PATCH 1/5 net/sched/sch_generic: Measure the time between watchdog runs
---
The output looks like that:
[36452.934159] dev_watchdog: cpu(6) jiffies(4331120128) jd(5072) ct(36452934152782) ctd(5119999) [36458.054164] dev_watchdog: cpu(6) jiffies(4331125248) jd(5120) ct(36458054156389) ctd(5120003) [36464.198155] dev_watchdog: cpu(6) jiffies(4331131392) jd(6144) ct(36464198148371) ctd(6143991) [36469.830161] dev_watchdog: cpu(6) jiffies(4331137024) jd(5584) ct(36469830153958) ctd(5632005) [36474.950166] dev_watchdog: cpu(6) jiffies(4331142144) jd(5105) ct(36474950159329) ctd(5120005) [36480.070154] dev_watchdog: cpu(6) jiffies(4331147264) jd(5120) ct(36480070147773) ctd(5119988) [36486.214156] dev_watchdog: cpu(6) jiffies(4331153408) jd(6097) ct(36486214149032) ctd(6144001) [36491.846164] dev_watchdog: cpu(6) jiffies(4331159040) jd(5632) ct(36491846157376) ctd(5632008)
The timer seems quite unstable on that machine. Even with CONFIG_IRQ_PIPELINE=n the values are the same.
Is there a mistake in the time measurement code?
The timeout configured by that timer is 5*HZ, so 5 seconds. According to the values above I see up to 6,14 seconds...
Both systems I saw similar problems on are using jiffies for time calculations. The global variable "jiffies" is incremented by the timer interrupt. So I started thinking of delayed timer IRQs or timer IRQs that are "merged" when being posted into the IRQ log. Merging should not be a problem for real device IRQs, but timer IRQs might be "counting".
net/sched/sch_generic.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
net/sched/sch_generic.c +21 -0
@@ -439,6 +439,20 @@ static void dev_watchdog(struct timer_list *t) {struct net_device *dev =from_timer (dev, t, watchdog_timer); +static unsigned long jiffies_prev =0 ; +unsigned long jiffies_diff = jiffies - jiffies_prev; + +static u64 core_time_prev =0 ; +u64 core_time =local_clock (); +u64 core_time_diff = (core_time - core_time_prev) /1000 ;/* in us */ + +printk ("dev_watchdog: cpu(%d) jiffies(%lu) jd(%lu) ct(%llu) ctd(%llu)\n" , +smp_processor_id (), jiffies, jiffies_diff, core_time, + core_time_diff); + + jiffies_prev = jiffies; + core_time_prev = core_time; +netif_tx_lock (dev);if (!qdisc_tx_is_noop (dev)) { if (netif_device_present(dev) &&
@@ -464,6 +478,13 @@ static void dev_watchdog(struct timer_list *t)if (some_queue_timedout) {trace_net_dev_xmit_timeout (dev, i); + +printk ("dev_watchdog: trigger: cpu(%d) jiffies(%lu) to(%lu) diff(%lu)\n" , +smp_processor_id (), jiffies, + trans_start + dev->watchdog_timeo, + jiffies - (trans_start + + dev->watchdog_timeo)); +WARN_ONCE (1 ,KERN_INFO "NETDEV WATCHDOG: %s (%s): transmit queue %u timed out\n" , dev->name,netdev_drivername (dev), i); dev->netdev_ops->ndo_tx_timeout (dev, i);
Signature · 1 line
2.30.2
RFC PATCH 2/5 kernel/irq/irqdesc: Extend struct irq_desc with a few cpu specific members
Extend the struct and make sure all members are initialized / cleaned up properly. All new members will be used by the following patches.
--- include/linux/irqdesc.h | 11 +++++++++++ kernel/irq/irqdesc.c | 24 ++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-)
include/linux/irqdesc.h +11 -0
@@ -17,6 +17,15 @@ struct irq_desc;struct irq_domain ;struct pt_regs ; +struct pipe_stats { +u64 post_time; +u64 pull_time; +u64 max_log_time; +unsigned int post_cnt; +unsigned int pull_cnt; +unsigned int post_merge_cnt; +}; +/** * struct irq_desc - interrupt descriptor * @irq_common_data: per irq and chip data passed down to chip functions
@@ -102,6 +111,8 @@ struct irq_desc {int parent_irq;struct module *owner;const char *name; +struct pipe_stats __percpu *oob_stats; +struct pipe_stats __percpu *ib_stats; }____cacheline_internodealigned_in_smp ;#ifdef CONFIG_SPARSE_IRQ
kernel/irq/irqdesc.c +22 -2
@@ -101,6 +101,16 @@ static inline void desc_smp_init(struct irq_desc *desc, int node, const struct cpumask *affinity) { }#endif +static void desc_pipe_stats_init (struct pipe_stats *ps) +{ + ps->post_time =0 ; + ps->pull_time =0 ; + ps->max_log_time =0 ; + ps->post_cnt =0 ; + ps->pull_cnt =0 ; + ps->post_merge_cnt =0 ; +} +static void desc_set_defaults (unsigned int irq,struct irq_desc *desc,int node,const struct cpumask *affinity,struct module *owner) {
@@ -123,8 +133,11 @@ static void desc_set_defaults(unsigned int irq, struct irq_desc *desc, int node, desc->tot_count =0 ; desc->name =NULL ; desc->owner = owner; -for_each_possible_cpu (cpu) +for_each_possible_cpu (cpu) { *per_cpu_ptr (desc->kstat_irqs, cpu) =0 ; +desc_pipe_stats_init (per_cpu_ptr (desc->ib_stats, cpu)); +desc_pipe_stats_init (per_cpu_ptr (desc->oob_stats, cpu)); + }desc_smp_init (desc, node, affinity); }
@@ -396,7 +409,10 @@ static struct irq_desc *alloc_desc(int irq, int node, unsigned int flags,return NULL ;/* allocate based on nr_cpu_ids */ desc->kstat_irqs = alloc_percpu(unsigned int); -if (!desc->kstat_irqs) + desc->oob_stats = alloc_percpu(struct pipe_stats); + desc->ib_stats = alloc_percpu(struct pipe_stats); + +if (!desc->kstat_irqs || !desc->oob_stats || !desc->ib_stats) goto err_desc;if (alloc_masks (desc, node))
@@ -415,6 +431,8 @@ static struct irq_desc *alloc_desc(int irq, int node, unsigned int flags, err_kstat:free_percpu (desc->kstat_irqs); +free_percpu (desc->oob_stats); +free_percpu (desc->ib_stats); err_desc:kfree (desc);return NULL ;
@@ -426,6 +444,8 @@ static void irq_kobj_release(struct kobject *kobj)free_masks (desc);free_percpu (desc->kstat_irqs); +free_percpu (desc->oob_stats); +free_percpu (desc->ib_stats);kfree (desc); }
Signature · 1 line
2.30.2
RFC PATCH 3/5 kernel/irq/pipeline: Instrument irq_post_stage and pull_next_irq
In reply to Florian Bezdeka - Remember how often an IRQ was posted into and pulled from the IRQ log
- Measure the time between push and pull
- Count how often we merge IRQs
(multiple post events before pulling again)
--- kernel/irq/pipeline.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
kernel/irq/pipeline.c +34 -0
@@ -592,10 +592,18 @@ static inline bool irq_post_check(struct irq_stage *stage, unsigned int irq)#if __IRQ_STAGE_MAP_LEVELS ==4 +static inline struct pipe_stats __percpu *get_stage_stats (struct irq_stage *s, +struct irq_desc *desc) +{ +return this_cpu_ptr (s->index ==0 ? desc->ib_stats : desc->oob_stats); +} +/* Must be called hard irqs off. */ void irq_post_stage (struct irq_stage *stage,unsigned int irq) {struct irq_stage_data *p =this_staged (stage); +struct irq_desc *desc =irq_to_cached_desc (irq); +struct pipe_stats __percpu *stats =get_stage_stats (stage, desc);int l0b, l1b, l2b;if (irq_post_check (stage, irq))
@@ -605,10 +613,20 @@ void irq_post_stage(struct irq_stage *stage, unsigned int irq) l1b = irq / (BITS_PER_LONG *BITS_PER_LONG ); l2b = irq /BITS_PER_LONG ; +if (test_bit (irq, p->log.map->flat) + &&test_bit (l2b, p->log.map->index_2) + &&test_bit (l1b, p->log.map->index_1) + &&test_bit (l0b, &p->log.index_0)) + stats->post_merge_cnt++; +else + stats->post_time =local_clock (); +__set_bit (irq, p->log.map->flat);__set_bit (l2b, p->log.map->index_2);__set_bit (l1b, p->log.map->index_1);__set_bit (l0b, &p->log.index_0); + + stats->post_cnt++; }EXPORT_SYMBOL_GPL (irq_post_stage);
@@ -619,6 +637,9 @@ EXPORT_SYMBOL_GPL(irq_post_stage);static inline int pull_next_irq (struct irq_stage_data *p) {unsigned long l0m, l1m, l2m, l3m; +struct irq_desc *desc; +struct pipe_stats __percpu *stats; +u64 core_time, max_log_time, diff;int l0b, l1b, l2b, l3b;unsigned int irq;
@@ -660,6 +681,19 @@ static inline int pull_next_irq(struct irq_stage_data *p) } } + desc =irq_to_cached_desc (irq); + stats =get_stage_stats (p->stage, desc); + + core_time =local_clock (); + stats->pull_time = core_time; + stats->pull_cnt++; + + max_log_time = stats->max_log_time; + diff = core_time - stats->post_time; + +if (diff > max_log_time) + stats->max_log_time = diff; +return irq; }
Signature · 1 line
2.30.2
RFC PATCH 4/5 kernel/irq/proc: Integrate post/pull/merge counters into /proc/interrupts
In reply to Florian BezdekaFor each CPU the following IRQ information will be shown:
- inband post counter
- inband pull counter
- inband merge counter
- Linux accounting (unmodified)
- out of band post counter
- out of band pull counter
- out of band merge counter
---
The cover letter has an example attached. As expected the out-of-band values are always 0. Only IRQ 61 was merged once.
When booting up with idle=poll the problem is gone, but I can see that many timer IRQs (IRQ0) are merged.
The number of "Local timer interrupts" matches the number of "Out-of-band LAPIC timer interrupt"
kernel/irq/proc.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
kernel/irq/proc.c +16 -4
@@ -465,6 +465,7 @@ int show_interrupts(struct seq_file *p, void *v)int i = *(loff_t *) v, j;struct irqaction *action;struct irq_desc *desc; +struct pipe_stats *oob_stats, *ib_stats;if (i >ACTUAL_NR_IRQS )return 0 ;
@@ -479,7 +480,7 @@ int show_interrupts(struct seq_file *p, void *v)seq_printf (p,"%*s" , prec +8 ,"" );for_each_online_cpu (j) -seq_printf (p,"CPU%-8d" , j); +seq_printf (p,"CPU%-12d" , j);seq_putc (p,'\n' ); }
@@ -496,9 +497,20 @@ int show_interrupts(struct seq_file *p, void *v) goto outsparse;seq_printf (p,"%*d: " , prec, i); -for_each_online_cpu (j) -seq_printf (p,"%10u " , desc->kstat_irqs ? - *per_cpu_ptr (desc->kstat_irqs, j) :0 ); +for_each_online_cpu (j) { + ib_stats =per_cpu_ptr (desc->ib_stats, j); + oob_stats =per_cpu_ptr (desc->oob_stats, j); +seq_printf (p,"%u/%u/%u-%u-%u/%u/%u " , + ib_stats ? ib_stats->post_cnt :0 , + ib_stats ? ib_stats->pull_cnt :0 , + ib_stats ? ib_stats->post_merge_cnt :0 , + desc->kstat_irqs ? + *per_cpu_ptr (desc->kstat_irqs, j) : +0 , + oob_stats ? oob_stats->post_cnt :0 , + oob_stats ? oob_stats->pull_cnt :0 , + oob_stats ? oob_stats->post_merge_cnt :0 ); + }raw_spin_lock_irqsave (&desc->lock, flags);if (desc->irq_data.chip) {
Signature · 1 line
2.30.2
RFC PATCH 5/5 kernel/irq/proc: Implement /proc/interrupt_log_times
In reply to Florian BezdekaShow the maximum time an interrupt stayed in the IRQ log on each CPU. Heavily inspired by show_interrupts().
Both logs (inband as well as out of band) are taken into account and are visible now.
---
The coverletter has an example of how this file looks like on the affected machine.
Especially the timing values for the "Out-of-band LAPIC timer interrupt" IRQ have significant values. I already tried to trace that, but as already written in the cover-letter: The problem disappears once tracing is enabled.
Any ideas?
fs/proc/interrupts.c | 8 ++++++ include/linux/interrupt.h | 1 + kernel/irq/proc.c | 53 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+)
fs/proc/interrupts.c +8 -0
@@ -34,9 +34,17 @@ static const struct seq_operations int_seq_ops = { .show = show_interrupts }; +static const struct seq_operations int_logtime_seq_ops = { + .start = int_seq_start, + .next = int_seq_next, + .stop = int_seq_stop, + .show = show_pipeline_log_times +}; +static int __init proc_interrupts_init (void ) {proc_create_seq ("interrupts" ,0 ,NULL , &int_seq_ops); +proc_create_seq ("interrupt_log_times" ,0 ,NULL , &int_logtime_seq_ops);return 0 ; }fs_initcall (proc_interrupts_init);
include/linux/interrupt.h +1 -0
@@ -809,6 +809,7 @@ u64 irq_timings_next_event(u64 now);struct seq_file ;int show_interrupts (struct seq_file *p,void *v); +int show_pipeline_log_times (struct seq_file *p,void *v);int arch_show_interrupts (struct seq_file *p,int prec);extern int early_irq_init (void );
kernel/irq/proc.c +53 -0
59 lines not on this page · raw message
Signature · 1 line
2.30.2