Re: Linux-next Alsa hda_intel events/0 high CPU usage, bisected

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Takashi Iwai
Date: Monday, June 9, 2008 - 4:13 am

At Mon, 09 Jun 2008 13:11:43 +0200,
I wrote:

Doh forgot the patch.  Here it is.


thanks,

Takashi


diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index dc68709..c0ae0e8 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -917,6 +917,26 @@ static void azx_init_pci(struct azx *chip)
 }
 
 
+static struct timespec irq_pending_time;
+static long max_delay, avg_delay, avg_count;
+
+static void check_latency(void)
+{
+	struct timespec end_time;
+	long delay;
+
+	getnstimeofday(&end_time);
+	delay = end_time.tv_sec - irq_pending_time.tv_sec;
+	delay *= 1000000000L;
+	delay += end_time.tv_nsec - irq_pending_time.tv_nsec;
+	if (delay > max_delay) {
+		max_delay = delay;
+		printk(KERN_DEBUG "XXX hda: max_delay=%ld ns\n", max_delay);
+	}
+	avg_delay += delay / 1000;
+	avg_count++;
+}
+
 static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev);
 
 /*
@@ -952,6 +972,7 @@ static irqreturn_t azx_interrupt(int irq, void *dev_id)
 			} else {
 				/* bogus IRQ, process it later */
 				azx_dev->irq_pending = 1;
+				getnstimeofday(&irq_pending_time);
 				schedule_work(&chip->irq_pending_work);
 			}
 		}
@@ -1288,6 +1309,13 @@ static int azx_pcm_close(struct snd_pcm_substream *substream)
 	hinfo->ops.close(hinfo, apcm->codec, substream);
 	snd_hda_power_down(apcm->codec);
 	mutex_unlock(&chip->open_mutex);
+	if (avg_count) {
+		printk(KERN_DEBUG "XXX hda: avg_delay=%ld us\n",
+		       avg_delay / avg_count);
+		avg_count = 0;
+		avg_delay = 0;
+		max_delay = 0;
+	}
 	return 0;
 }
 
@@ -1521,6 +1549,7 @@ static void azx_irq_pending_work(struct work_struct *work)
 				azx_dev->irq_pending = 0;
 				spin_unlock(&chip->reg_lock);
 				snd_pcm_period_elapsed(azx_dev->substream);
+				check_latency();
 				spin_lock(&chip->reg_lock);
 			} else
 				pending++;
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Linux-next Alsa hda_intel events/0 high CPU usage, bisected, Benjamin Kidwell, (Fri Jun 6, 2:07 pm)
Re: Linux-next Alsa hda_intel events/0 high CPU usage, bis ..., Takashi Iwai, (Mon Jun 9, 4:13 am)