* [PATCH TINYCOMPRESS 7/14] compress: Remove hardcoded limit on length of poll() wait
@ 2013-02-10 0:13 Richard Fitzgerald
2013-02-11 6:45 ` Vinod Koul
2013-02-22 16:03 ` [PATCH TINYCOMPRESS 7/14 v2] " Richard Fitzgerald
0 siblings, 2 replies; 3+ messages in thread
From: Richard Fitzgerald @ 2013-02-10 0:13 UTC (permalink / raw)
To: vinod.koul; +Cc: alsa-devel
For best power-saving we want to sleep on poll() for as long as
possible, we don't want to wake unnecessarily for arbitrary time
limits. Adds function compress_set_max_poll_wait() so that
client can configure the poll() timeout.
diff --git a/compress.c b/compress.c
index 5235ea4..b706f8b 100644
--- a/compress.c
+++ b/compress.c
@@ -77,12 +77,16 @@
#define COMPR_ERR_MAX 32
+/* Default maximum time we will wait in a poll() - 20 seconds */
+#define DEFAULT_MAX_POLL_WAIT_MS 20000
+
struct compress {
int fd;
unsigned int flags;
char error[COMPR_ERR_MAX];
struct compr_config config;
int running;
+ int max_poll_wait_ms;
};
static int oops(struct compress *compress, int e, const char *fmt, ...)
@@ -214,6 +218,8 @@ struct compress *compress_open(unsigned int card, unsigned int device,
snprintf(fn, sizeof(fn), "/dev/snd/comprC%uD%u", card, device);
+ compress->max_poll_wait_ms = DEFAULT_MAX_POLL_WAIT_MS;
+
compress->flags = flags;
if (!((flags & COMPRESS_OUT) || (flags & COMPRESS_IN))) {
oops(compress, -EINVAL, "can't deduce device direction from given flags\n");
@@ -321,8 +327,8 @@ int compress_write(struct compress *compress, const void *buf, unsigned int size
/* we will write only when avail > fragment size */
if (avail.avail < compress->config.fragment_size) {
- /* nothing to write so wait for 10secs */
- ret = poll(&fds, 1, 1000000);
+ /* nothing to write so wait */
+ ret = poll(&fds, 1, compress->max_poll_wait_ms);
if (ret < 0)
return oops(compress, errno, "poll error");
if (ret == 0)
@@ -432,3 +438,8 @@ bool is_codec_supported(unsigned int card, unsigned int device,
return ret;
}
+void compress_set_max_poll_wait(struct compress *compress, int milliseconds)
+{
+ compress->max_poll_wait_ms = milliseconds;
+}
+
diff --git a/include/tinycompress/tinycompress.h b/include/tinycompress/tinycompress.h
index e285bd4..1ab53c6 100644
--- a/include/tinycompress/tinycompress.h
+++ b/include/tinycompress/tinycompress.h
@@ -189,6 +189,16 @@ int compress_drain(struct compress *compress);
bool is_codec_supported(unsigned int card, unsigned int device,
unsigned int flags, struct snd_codec *codec);
+/*
+ * compress_set_max_poll_wait: set the maximum time tinycompress
+ * will wait for driver to signal a poll(). Interval is in
+ * milliseconds.
+ * Pass interval of -1 to disable timeout and make poll() wait
+ * until driver signals.
+ * If this function is not used the timeout defaults to 20 seconds.
+ */
+void compress_set_max_poll_wait(struct compress *compress, int milliseconds);
+
int is_compress_running(struct compress *compress);
int is_compress_ready(struct compress *compress);
--
1.7.2.5
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH TINYCOMPRESS 7/14] compress: Remove hardcoded limit on length of poll() wait
2013-02-10 0:13 [PATCH TINYCOMPRESS 7/14] compress: Remove hardcoded limit on length of poll() wait Richard Fitzgerald
@ 2013-02-11 6:45 ` Vinod Koul
2013-02-22 16:03 ` [PATCH TINYCOMPRESS 7/14 v2] " Richard Fitzgerald
1 sibling, 0 replies; 3+ messages in thread
From: Vinod Koul @ 2013-02-11 6:45 UTC (permalink / raw)
To: Richard Fitzgerald; +Cc: alsa-devel
On Sun, Feb 10, 2013 at 12:13:08AM +0000, Richard Fitzgerald wrote:
> For best power-saving we want to sleep on poll() for as long as
> possible, we don't want to wake unnecessarily for arbitrary time
> limits. Adds function compress_set_max_poll_wait() so that
> client can configure the poll() timeout.
Looks okay, but shouldnt this be part of compress_config and if not initialized
we switch to default value.
--
~Vinod
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH TINYCOMPRESS 7/14 v2] compress: Remove hardcoded limit on length of poll() wait
2013-02-10 0:13 [PATCH TINYCOMPRESS 7/14] compress: Remove hardcoded limit on length of poll() wait Richard Fitzgerald
2013-02-11 6:45 ` Vinod Koul
@ 2013-02-22 16:03 ` Richard Fitzgerald
1 sibling, 0 replies; 3+ messages in thread
From: Richard Fitzgerald @ 2013-02-22 16:03 UTC (permalink / raw)
To: vinod.koul; +Cc: alsa-devel
For best power-saving we want to sleep on poll() for as long as
possible, we don't want to wake unnecessarily for arbitrary time
limits. Adds function compress_set_max_poll_wait() so that
client can configure the poll() timeout.
---
compress.c | 17 ++++++++++++++---
include/tinycompress/tinycompress.h | 10 ++++++++++
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/compress.c b/compress.c
index 801f055..478652a 100644
--- a/compress.c
+++ b/compress.c
@@ -77,12 +77,16 @@
#define COMPR_ERR_MAX 128
+/* Default maximum time we will wait in a poll() - 20 seconds */
+#define DEFAULT_MAX_POLL_WAIT_MS 20000
+
struct compress {
int fd;
unsigned int flags;
char error[COMPR_ERR_MAX];
struct compr_config *config;
int running;
+ int max_poll_wait_ms;
};
static int oops(struct compress *compress, int e, const char *fmt, ...)
@@ -217,6 +221,8 @@ struct compress *compress_open(unsigned int card, unsigned int device,
snprintf(fn, sizeof(fn), "/dev/snd/comprC%uD%u", card, device);
+ compress->max_poll_wait_ms = DEFAULT_MAX_POLL_WAIT_MS;
+
compress->flags = flags;
if (!((flags & COMPRESS_OUT) || (flags & COMPRESS_IN))) {
oops(&bad_compress, -EINVAL, "can't deduce device direction from given flags");
@@ -331,9 +337,9 @@ int compress_write(struct compress *compress, const void *buf, unsigned int size
return oops(compress, errno, "cannot get avail");
/* we will write only when avail > fragment size */
- if (avail.avail < compress->config->fragment_size) {
- /* nothing to write so wait for 10secs */
- ret = poll(&fds, 1, 1000000);
+ if (avail.avail < compress->config.fragment_size) {
+ /* nothing to write so wait */
+ ret = poll(&fds, 1, compress->max_poll_wait_ms);
if (ret < 0)
return oops(compress, errno, "poll error");
if (ret == 0)
@@ -441,3 +447,8 @@ bool is_codec_supported(unsigned int card, unsigned int device,
return ret;
}
+void compress_set_max_poll_wait(struct compress *compress, int milliseconds)
+{
+ compress->max_poll_wait_ms = milliseconds;
+}
+
diff --git a/include/tinycompress/tinycompress.h b/include/tinycompress/tinycompress.h
index 49c0ff2..982ff6b 100644
--- a/include/tinycompress/tinycompress.h
+++ b/include/tinycompress/tinycompress.h
@@ -190,6 +190,16 @@ int compress_drain(struct compress *compress);
bool is_codec_supported(unsigned int card, unsigned int device,
unsigned int flags, struct snd_codec *codec);
+/*
+ * compress_set_max_poll_wait: set the maximum time tinycompress
+ * will wait for driver to signal a poll(). Interval is in
+ * milliseconds.
+ * Pass interval of -1 to disable timeout and make poll() wait
+ * until driver signals.
+ * If this function is not used the timeout defaults to 20 seconds.
+ */
+void compress_set_max_poll_wait(struct compress *compress, int milliseconds);
+
int is_compress_running(struct compress *compress);
int is_compress_ready(struct compress *compress);
--
1.7.2.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-02-22 16:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-10 0:13 [PATCH TINYCOMPRESS 7/14] compress: Remove hardcoded limit on length of poll() wait Richard Fitzgerald
2013-02-11 6:45 ` Vinod Koul
2013-02-22 16:03 ` [PATCH TINYCOMPRESS 7/14 v2] " Richard Fitzgerald
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).