trying out usb hotplugs
Hi,
usb hotplug works perfect if my usbmidi client isn't aconnected to another midi client. But the aconnected usb midi device still remains in the clients list, after hotpluging out. The next hotplug in of my usb device needs an aconnect -x before or I won't see my card in /proc/asound/cards again. But I haven't found a real problem during my tests of usb hotpluging. Thanks.
martin
-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
At Thu, 28 Nov 2002 01:27:02 +0100,
Quoted 9 lines · Martin Langer
Hi,
usb hotplug works perfect if my usbmidi client isn't aconnected to another midi client. But the aconnected usb midi device still remains in the clients list, after hotpluging out. The next hotplug in of my usb device needs an aconnect -x before or I won't see my card in
/proc/asound/cardsagain. But I haven't found a real problem during my tests of usb hotpluging. Thanks.
yep, when the connection exists, the connected devices (on both sides) are regarded as active.
i'll check at which stage this activity is checked and stalled.
Takashi
-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
Quoted 7 lines · Takashi Iwai
Quoted 3 lines · Martin Langer
usb hotplug works perfect if my usbmidi client isn't aconnected to another midi client. But the aconnected usb midi device still remains in the clients list, after hotpluging out.
yep, when the connection exists, the connected devices (on both sides) are regarded as active.
The sequencer design allows asynchronous removal of clients.
core/seq/seq_device.c renamed from core/seq/seq_device.c.orig +18 -0
@@ -92,6 +92,7 @@static int snd_seq_device_free (snd_seq_device_t *dev);static int snd_seq_device_dev_free (snd_device_t *device);static int snd_seq_device_dev_register (snd_device_t *device); +static int snd_seq_device_dev_disconnect (snd_device_t *device);static int snd_seq_device_dev_unregister (snd_device_t *device);static int init_device (snd_seq_device_t *dev,ops_list_t *ops);
@@ -166,6 +167,7 @@static snd_device_ops_t dops = { .dev_free = snd_seq_device_dev_free, .dev_register = snd_seq_device_dev_register, + .dev_disconnect = snd_seq_device_dev_disconnect, .dev_unregister = snd_seq_device_dev_unregister };
@@ -265,6 +267,22 @@init_device (dev, ops);unlock_driver (ops); +return 0 ; +} + +/* +* disconnect the device +*/ +static int snd_seq_device_dev_disconnect (snd_device_t *device) +{ +snd_seq_device_t *dev =snd_magic_cast (snd_seq_device_t, device->device_data, return -ENXIO ); +ops_list_t *ops; + + ops =find_driver (dev->id,0 ); +if (ops ==NULL ) +return -ENOENT ; + +free_device (dev, ops);return 0 ; }
-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
At Fri, 29 Nov 2002 08:52:43 +0100 (MET),
Quoted 11 lines · Clemens Ladisch
Quoted 7 lines · Takashi Iwai
Quoted 3 lines · Martin Langer
usb hotplug works perfect if my usbmidi client isn't aconnected to another midi client. But the aconnected usb midi device still remains in the clients list, after hotpluging out.
yep, when the connection exists, the connected devices (on both sides) are regarded as active.
The sequencer design allows asynchronous removal of clients.
yes, but this may still try to send some bytes to the unplugged rawmidi device at the disconnection. i'll change rawmidi code to ignore that.
thanks for your patch, anyway!
Takashi
-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
Quoted 9 lines · Takashi Iwai
At Fri, 29 Nov 2002 08:52:43 +0100 (MET),
Quoted 7 lines · Clemens Ladisch
Quoted 5 lines · Takashi Iwai
Quoted 3 lines · Martin Langer
usb hotplug works perfect if my usbmidi client isn't aconnected to another midi client. But the aconnected usb midi device still remains in the clients list, after hotpluging out.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
yep, when the connection exists, the connected devices (on both sides) are regarded as active.
The sequencer design allows asynchronous removal of clients.
yes, but this may still try to send some bytes to the unplugged rawmidi device at the disconnection. i'll change rawmidi code to ignore that.
Well, I'm trying to solve these "hotplug" problems. Unfortunately, it seems difficult to detect, if another task is in the middle of our callback. I think that we'll end up using mutexes.
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
At Fri, 29 Nov 2002 10:39:22 +0100 (CET),
Quoted 17 lines · Jaroslav
Quoted 14 lines · Takashi Iwai
At Fri, 29 Nov 2002 08:52:43 +0100 (MET),
Quoted 11 lines · Clemens Ladisch
Quoted 7 lines · Takashi Iwai
Quoted 3 lines · Martin Langer
usb hotplug works perfect if my usbmidi client isn't aconnected to another midi client. But the aconnected usb midi device still remains in the clients list, after hotpluging out.
yep, when the connection exists, the connected devices (on both sides) are regarded as active.
The sequencer design allows asynchronous removal of clients.
Quoted 7 lines
Quoted 3 lines
yes, but this may still try to send some bytes to the unplugged rawmidi device at the disconnection. i'll change rawmidi code to ignore that.
Well, I'm trying to solve these "hotplug" problems. Unfortunately, it seems difficult to detect, if another task is in the middle of our callback. I think that we'll end up using mutexes.
hmm, but mutex costs too much even for non-pluggable devices...
in the case of rawmidi and oss-mixer, we can put "disconnected" flag and ignore the access if the flag is on at the rawmidi and oss-mixer routines, so that the control doesn't reach to low-level functions.
at least, the sequencer connection problem seems ok. i'm checking now whether it can work for oss-mixer, too.
Takashi
-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
Quoted 27 lines · Takashi Iwai
At Fri, 29 Nov 2002 10:39:22 +0100 (CET),
Quoted 17 lines · Jaroslav
Quoted 14 lines · Takashi Iwai
At Fri, 29 Nov 2002 08:52:43 +0100 (MET),
Quoted 11 lines · Clemens Ladisch
Quoted 7 lines · Takashi Iwai
Quoted 3 lines · Martin Langer
usb hotplug works perfect if my usbmidi client isn't aconnected to another midi client. But the aconnected usb midi device still remains in the clients list, after hotpluging out.
yep, when the connection exists, the connected devices (on both sides) are regarded as active.
The sequencer design allows asynchronous removal of clients.
Quoted 7 lines
Quoted 3 lines
yes, but this may still try to send some bytes to the unplugged rawmidi device at the disconnection. i'll change rawmidi code to ignore that.
Well, I'm trying to solve these "hotplug" problems. Unfortunately, it seems difficult to detect, if another task is in the middle of our callback. I think that we'll end up using mutexes.
Quoted 5 lines
hmm, but mutex costs too much even for non-pluggable devices...
in the case of rawmidi and oss-mixer, we can put "disconnected" flag and ignore the access if the flag is on at the rawmidi and oss-mixer routines, so that the control doesn't reach to low-level functions.
Well, but if you check this flag at the beginning, then you don't know, if hardware is away in the middle of operation. The point is, that we have to finish the last operation and clean structures "when no task is inside". Perhaps, atomic_t helps us.
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
At Fri, 29 Nov 2002 12:24:50 +0100 (CET),
Quoted 32 lines · Jaroslav
Quoted 29 lines · Takashi Iwai
At Fri, 29 Nov 2002 10:39:22 +0100 (CET),
Quoted 17 lines · Jaroslav
Quoted 14 lines · Takashi Iwai
At Fri, 29 Nov 2002 08:52:43 +0100 (MET),
Quoted 11 lines · Clemens Ladisch
Quoted 7 lines · Takashi Iwai
Quoted 3 lines · Martin Langer
usb hotplug works perfect if my usbmidi client isn't aconnected to another midi client. But the aconnected usb midi device still remains in the clients list, after hotpluging out.
yep, when the connection exists, the connected devices (on both sides) are regarded as active.
The sequencer design allows asynchronous removal of clients.
Quoted 7 lines
Quoted 3 lines
yes, but this may still try to send some bytes to the unplugged rawmidi device at the disconnection. i'll change rawmidi code to ignore that.
Well, I'm trying to solve these "hotplug" problems. Unfortunately, it seems difficult to detect, if another task is in the middle of our callback. I think that we'll end up using mutexes.
hmm, but mutex costs too much even for non-pluggable devices...
Quoted 8 lines
Quoted 3 lines
in the case of rawmidi and oss-mixer, we can put "disconnected" flag and ignore the access if the flag is on at the rawmidi and oss-mixer routines, so that the control doesn't reach to low-level functions.
Well, but if you check this flag at the beginning, then you don't know, if hardware is away in the middle of operation. The point is, that we have to finish the last operation and clean structures "when no task is inside".
yes. the unplugging may happen at any time, since it's a physical action and cannot be locked by a kernel :)
this means, the invalid access in the middle of the code cannot be avoided by a program code unless all function is atomic. thus, the low-level stuff should take it into account if the card is pluggable, anyway, for example, avoiding a possible infinte loop, etc.
in the case of usb, the real critical part depends on the usb core and controller routine. i hope it's ok.
the "disconnection-check-and-ignore" method is not perfect, but, if the low level stuff doesn't go crazy even at the disconnected state, the result wouldn't be so critical.
btw, the oss-emulation problem seems to be on the different point. the oss-emulation accesses directly to the records without taking any reference counters. thus snd_*_can_unregister() passes the check even the control (or pcm) files are still open.
i'll keep on debugging this.
Takashi
-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
Hi,
the attached is my latest patch.
could you check it?
thanks,
Takashi
Quoted 4 lines · Takashi Iwai
Hi,
the attached is my latest patch.
could you check it?
Let's go and make things more complicated (like in my tree on disc):
1) waiting for time when all disconnected applications have closed all file descriptors is a bit problem, because no new/other USB devices can be connected/disconnected; in my tree, I use thread to postpone freeing of snd_card_t structure
2) replace file->f_op with fake operations which allows only original release() callback in snd_card_disconnect(); this point makes things more and more simple than your code (check all accesses), because we need to count only open/release calls
3) the unfinished problem is still: how to behave, if the disconnect event comes in the middle of some code; you're right at this point, the lowlevel driver must handle it
Please, remove from your code any checks from ioctl(), poll(), read() / write(). Then commit and I'll merge my tree with yours.
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
At Fri, 29 Nov 2002 15:05:21 +0100 (CET),
Quoted 8 lines · Jaroslav
Quoted 4 lines · Takashi Iwai
Hi,
the attached is my latest patch.
could you check it?
Quoted 6 lines
Let's go and make things more complicated (like in my tree on disc):
1) waiting for time when all disconnected applications have closed all file descriptors is a bit problem, because no new/other USB devices can be connected/disconnected; in my tree, I use thread to postpone freeing of
snd_card_tstructure
right. i didn't touch this part at all.
another possible solution is to put the pending card instance into a stale linked-list like in pcmcia drivers.
the pending objects are released at the time when a new device is registered and when the module is removed.
but if a kernel-thread can work well, it's better, because it will release the resources asap.
Quoted 4 lines
2) replace
file->f_opwith fake operations which allows only originalrelease()callback insnd_card_disconnect(); this point makes things more and more simple than your code (check all accesses), because we need to count only open/release calls
yes, that's a better solution.
Quoted 6 lines
3) the unfinished problem is still: how to behave, if the disconnect event comes in the middle of some code; you're right at this point, the lowlevel driver must handle it
Please, remove from your code any checks from
ioctl(),poll(),read()/write(). Then commit and I'll merge my tree with yours.
ok.
Takashi
-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
At Fri, 29 Nov 2002 15:14:28 +0100,
Quoted 5 lines · I wrote:
Quoted 3 lines
Please, remove from your code any checks from
ioctl(),poll(),read()/write(). Then commit and I'll merge my tree with yours.ok.
done. please merge your tree.
ciao,
Takashi
-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en