diff options
author | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2010-07-06 20:06:36 +0000 |
---|---|---|
committer | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2010-07-06 20:06:36 +0000 |
commit | 34bbfacafcb71253440a830bed3e6d1d937c3919 (patch) | |
tree | d725269d1c6e34c40408bab5da67989a7da06f4d /usr.bin/aucat | |
parent | a98a572668fcd29fe95b34ebeba73e67326189f1 (diff) |
Try to detect busy loops caused by misbehaving audio drivers
or hardware. If a busy loop is found, then close the device that
caused the loop.
Diffstat (limited to 'usr.bin/aucat')
-rw-r--r-- | usr.bin/aucat/file.c | 16 | ||||
-rw-r--r-- | usr.bin/aucat/file.h | 6 |
2 files changed, 20 insertions, 2 deletions
diff --git a/usr.bin/aucat/file.c b/usr.bin/aucat/file.c index c0c145b30a5..83d0c75c70d 100644 --- a/usr.bin/aucat/file.c +++ b/usr.bin/aucat/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.19 2010/05/02 10:43:30 ratchov Exp $ */ +/* $OpenBSD: file.c,v 1.20 2010/07/06 20:06:35 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -362,6 +362,16 @@ file_poll(void) continue; } revents = f->ops->revents(f, f->pfd); +#ifdef DEBUG + if (revents) { + f->cycles++; + if (f->cycles > FILE_MAXCYCLES) { + file_dbg(f); + dbg_puts(": busy loop, disconnecting\n"); + revents = POLLHUP; + } + } +#endif if (!(f->state & FILE_ZOMB) && (revents & POLLIN)) { revents &= ~POLLIN; #ifdef DEBUG @@ -570,6 +580,8 @@ file_read(struct file *f, unsigned char *data, unsigned count) #endif n = f->ops->read(f, data, count); #ifdef DEBUG + if (n > 0) + f->cycles = 0; clock_gettime(CLOCK_MONOTONIC, &ts1); us = 1000000L * (ts1.tv_sec - ts0.tv_sec); us += (ts1.tv_nsec - ts0.tv_nsec) / 1000; @@ -602,6 +614,8 @@ file_write(struct file *f, unsigned char *data, unsigned count) #endif n = f->ops->write(f, data, count); #ifdef DEBUG + if (n > 0) + f->cycles = 0; clock_gettime(CLOCK_MONOTONIC, &ts1); us = 1000000L * (ts1.tv_sec - ts0.tv_sec); us += (ts1.tv_nsec - ts0.tv_nsec) / 1000; diff --git a/usr.bin/aucat/file.h b/usr.bin/aucat/file.h index 4c7a1c1607b..5431025bd56 100644 --- a/usr.bin/aucat/file.h +++ b/usr.bin/aucat/file.h @@ -1,4 +1,4 @@ -/* $OpenBSD: file.h,v 1.9 2009/09/27 11:51:20 ratchov Exp $ */ +/* $OpenBSD: file.h,v 1.10 2010/07/06 20:06:35 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -56,6 +56,10 @@ struct file { #define FILE_RINUSE 0x20 /* inside rproc->ops->in() */ #define FILE_WINUSE 0x40 /* inside wproc->ops->out() */ unsigned state; /* one of above */ +#ifdef DEBUG +#define FILE_MAXCYCLES 20 + unsigned cycles; /* number of POLLIN/POLLOUT events */ +#endif char *name; /* for debug purposes */ struct aproc *rproc, *wproc; /* reader and/or writer */ LIST_ENTRY(file) entry; |