alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* MIDI issue with RME HDSPM MADI
@ 2011-06-01 17:27 Jörn Nettingsmeier
  2011-06-03 16:08 ` Takashi Iwai
  0 siblings, 1 reply; 6+ messages in thread
From: Jörn Nettingsmeier @ 2011-06-01 17:27 UTC (permalink / raw)
  To: alsa-devel, Adrian Knoth

[-- Attachment #1: Type: text/plain, Size: 1931 bytes --]

Hi *!


The HDSPM MADI driver seems to have an issue with its MIDI 
implementation. It is rock-solid for audio under Jack at 64 
frames/period, but as soon as I start using the MIDI over MADI interface 
(to remote-control my Micstasy preamps), I'm getting xruns every ten 
seconds or so.

I've tried to debug the issue with the help of faberman, and he came up 
with a midi drain() implementation for the driver, but it didn't help 
with the xrun issue. It did help with busy MIDI programs in that they 
are no longer stuck in D state almost all the time, but sleeping, like 
any good program should.

This is a 2.6.39-rc7 kernel, and faberman has confirmed the issue with .39.

The attached test program rawmiditest.c (build with -lasound) will 
reproducibly cause xruns as soon as there is a mictasy on the MADI ring 
so that there's actual traffic. With no-one listening, there will be no 
xruns. (Might that be a hint that the problem is at the receiving end?)

This is really totally over my head, but I found one place in the driver 
(snd_hdspm_midi_input_trigger) where a midi routine locks the entire 
hdspm structure. it's flushing the midi input with the hdspm spinlock 
held - could this be taking so long as to cause xruns?

I'm waiting for a MIDI cable to arrive so that I can test if the same 
problem occurs when using the normal MIDI interfaces of the card (i.e. 
not the MIDI over MADI one)...

For the record, faberman suspected that there is a bit too much locking 
going on wrt the hmidi struct. OTOH, when we removed all hmidi 
spinlocks, I was able to lock up the machine twice... maybe there is 
some middle ground?

Meanwhile, any insights would be appreciated.


Best,


Jörn



-- 
Jörn Nettingsmeier
Lortzingstr. 11, 45128 Essen, Tel. +49 177 7937487

Meister für Veranstaltungstechnik (Bühne/Studio)
Tonmeister (VDT)

http://stackingdwarves.net

[-- Attachment #2: rawmiditest.c --]
[-- Type: text/x-csrc, Size: 994 bytes --]


#include <stdio.h>
#include <pthread.h>
#include <strings.h>
#include <alsa/asoundlib.h>

snd_rawmidi_t *in, *out;


void midi_open(char *rawmidi_device) {
	int err;

	err = snd_rawmidi_open(&in, &out, rawmidi_device, SND_RAWMIDI_NONBLOCK);
	if (err < 0) {
		fprintf(stderr, "snd_rawmidi_open %s failed: %d\n", rawmidi_device, err);
		exit(EXIT_FAILURE);
	}

}



int main() {
	int cnt, err;
	unsigned char c;
	unsigned char cmd[8] = {0xF0, 0x00, 0x20, 0x0D, 0x68, 0x02, 0x10, 0xF7};

	midi_open("hw:1,2");

	for (;;) {
		cnt++;
		err = snd_rawmidi_write(out, &cmd, 8);
		if (err < 0) {
			fprintf(stderr,"snd_rawmidi_write failed: %d\n", err);
			exit(EXIT_FAILURE);
		}

		snd_rawmidi_drain(out);

		for (;;) {
			err = snd_rawmidi_read(in, &c, 1);
			if (err < 0) {
				if (err==-11) {
					printf("\n");
					break;
				}
				fprintf(stderr,"snd_rawmidi_read failed: %d\n", err);
				exit(EXIT_FAILURE);
			} else {
				printf(" 0x%02x", c);
			}
		}
		

		
		printf("\r%d", cnt);
	}

	
}

[-- Attachment #3: hdspm-locks+drain.diff --]
[-- Type: text/x-patch, Size: 1436 bytes --]

--- sound/pci/rme9652/hdspm.c.orig	2011-05-15 17:56:25.819000813 +0200
+++ sound/pci/rme9652/hdspm.c	2011-06-01 19:05:06.402951169 +0200
@@ -1621,6 +1621,8 @@
 
 	spin_lock_irqsave (&hmidi->lock, flags);
 	n_pending = snd_hdspm_midi_input_available (hmidi->hdspm, hmidi->id);
+	spin_unlock_irqrestore(&hmidi->lock, flags);
+	
 	if (n_pending > 0) {
 		if (hmidi->input) {
 			if (n_pending > (int)sizeof (buf))
@@ -1639,12 +1641,12 @@
 		}
 	}
 	hmidi->pending = 0;
-
+	
+	spin_lock_irqsave (&hmidi->hdspm->lock, flags);
 	hmidi->hdspm->control_register |= hmidi->ie;
 	hdspm_write(hmidi->hdspm, HDSPM_controlRegister,
 		    hmidi->hdspm->control_register);
-
-	spin_unlock_irqrestore (&hmidi->lock, flags);
+	spin_unlock_irqrestore(&hmidi->hdspm->lock, flags);
 	return snd_hdspm_midi_output_write (hmidi);
 }
 
@@ -1773,11 +1775,25 @@
 	return 0;
 }
 
+static void snd_hdspm_midi_output_drain(struct snd_rawmidi_substream *substream)
+{
+	struct hdspm *hdspm;
+	struct hdspm_midi *hmidi;
+	
+	hmidi = substream->rmidi->private_data;
+	hdspm = hmidi->hdspm;
+	
+	while (128 != snd_hdspm_midi_output_possible(hdspm, hmidi->id)) {
+		mdelay(2);
+	}
+}
+
 static struct snd_rawmidi_ops snd_hdspm_midi_output =
 {
 	.open =		snd_hdspm_midi_output_open,
 	.close =	snd_hdspm_midi_output_close,
 	.trigger =	snd_hdspm_midi_output_trigger,
+	.drain = 	snd_hdspm_midi_output_drain,
 };
 
 static struct snd_rawmidi_ops snd_hdspm_midi_input =

[-- Attachment #4: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-06-07 13:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-01 17:27 MIDI issue with RME HDSPM MADI Jörn Nettingsmeier
2011-06-03 16:08 ` Takashi Iwai
2011-06-05 12:34   ` Jörn Nettingsmeier
2011-06-07 13:06     ` Jörn Nettingsmeier
2011-06-07 13:18       ` Jörn Nettingsmeier
2011-06-07 14:03         ` Jörn Nettingsmeier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).