ALSA: line6: hwdep: add support for poll and non-blocking read
cover ALSA: line6: hwdep: add support for poll and non-blocking read
This series adds support for polling and non-blocking read for hwdep interface. This allows apps to listen to HW events without using busy loop.
Example of app that uses hwdep interface for POD HD500 can be found
here: https://github.com/anarsoul/line6_hwdep_test
Vasily Khoruzhick (2):
ALSA: line6: hwdep: add support for O_NONBLOCK opening mode
ALSA: line6: Add poll callback for hwdep
sound/usb/line6/driver.c | 20 ++++++++++++++++++++ sound/usb/line6/driver.h | 1 + 2 files changed, 21 insertions(+)
Signature · 1 line
2.26.2
PATCH 1/2 ALSA: line6: hwdep: add support for O_NONBLOCK opening mode
Currently line6 hwdep interface ignores O_NONBLOCK flag when opening device and it renders it somewhat useless when using poll.
Check for O_NONBLOCK flag when opening device and don't block read() if it is set.
--- sound/usb/line6/driver.c | 4 ++++ sound/usb/line6/driver.h | 1 + 2 files changed, 5 insertions(+)
sound/usb/line6/driver.c +4 -0
@@ -550,6 +550,7 @@ static int line6_hwdep_open(struct snd_hwdep *hw, struct file *file)/* NOTE: hwdep layer provides atomicity here */ line6->messages.active =1 ; + line6->messages.nonblock = file->f_flags &O_NONBLOCK ?1 :0 ;return 0 ; }
@@ -579,6 +580,9 @@ line6_hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,while (kfifo_len (&line6->messages.fifo) ==0 ) {mutex_unlock (&line6->messages.read_lock); +if (line6->messages.nonblock) +return -EAGAIN ; + rv =wait_event_interruptible ( line6->messages.wait_queue,kfifo_len (&line6->messages.fifo) !=0 );
sound/usb/line6/driver.h +1 -0
@@ -163,6 +163,7 @@ struct usb_line6 {struct mutex read_lock;wait_queue_head_t wait_queue; unsigned int active:1; + unsigned int nonblock:1;STRUCT_KFIFO_REC_2 (LINE6_BUFSIZE_LISTEN *LINE6_RAW_MESSAGES_MAXCOUNT ) fifo; } messages;
Signature · 1 line
2.26.2
PATCH 2/2 ALSA: line6: Add poll callback for hwdep
In reply to Vasily KhoruzhickAt least POD HD500 uses message-based communication, both sides can send messages. Add poll callback so application can wait for device messages without using busy loop.
--- sound/usb/line6/driver.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
sound/usb/line6/driver.c +16 -0
@@ -630,11 +630,27 @@ line6_hwdep_write(struct snd_hwdep *hwdep, const char __user *data, long count,return rv; } +static __poll_t +line6_hwdep_poll (struct snd_hwdep *hwdep,struct file *file,poll_table *wait) +{ +__poll_t rv; +struct usb_line6 *line6 = hwdep->private_data; + +poll_wait (file, &line6->messages.wait_queue, wait); + +mutex_lock (&line6->messages.read_lock); + rv =kfifo_len (&line6->messages.fifo) ==0 ?0 :EPOLLIN |EPOLLRDNORM ; +mutex_unlock (&line6->messages.read_lock); + +return rv; +} +static const struct snd_hwdep_ops hwdep_ops = { .open = line6_hwdep_open, .release = line6_hwdep_release, .read = line6_hwdep_read, .write = line6_hwdep_write, + .poll = line6_hwdep_poll, };/* Insert into circular buffer */
Signature · 1 line
2.26.2
Quoted 11 lines · Vasily Khoruzhick
This series adds support for polling and non-blocking read for hwdep interface. This allows apps to listen to HW events without using busy loop.
Example of app that uses hwdep interface for POD HD500 can be found
here: https://github.com/anarsoul/line6_hwdep_testVasily Khoruzhick (2):
ALSA: line6: hwdep: add support forO_NONBLOCKopening mode
ALSA: line6: Add poll callback for hwdep
Looks like a nice extension. Applied both patches now to for-next branch.
thanks,
Takashi
Quoted 11 lines · Takashi Iwai
Quoted 8 lines · Vasily Khoruzhick
This series adds support for polling and non-blocking read for hwdep interface. This allows apps to listen to HW events without using busy loop.
Example of app that uses hwdep interface for POD HD500 can be found
here: https://github.com/anarsoul/line6_hwdep_test
Quoted 6 lines
Quoted 3 lines
Vasily Khoruzhick (2):
ALSA: line6: hwdep: add support forO_NONBLOCKopening mode
ALSA: line6: Add poll callback for hwdepLooks like a nice extension. Applied both patches now to for-next branch.
Thanks for such a prompt response!
Quoted 4 lines
thanks,
Takashi