All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [dvbv5-scan] wait no more than timeout when scanning
@ 2016-07-22 17:54 Abylay Ospan
  2016-07-22 19:18 ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 5+ messages in thread
From: Abylay Ospan @ 2016-07-22 17:54 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, linux-media; +Cc: Abylay Ospan

some frontends (mentioned on lgdt3306a) wait timeout inside code like:
for (i = 20; i > 0; i--) {
  msleep(50);

If there is no-LOCK then dvbv5-scan spent a lot of time (doing 40x calls).
This patch introduce timeout which 4 sec * multiply. So we do not wait more
than 4 sec (or so) if no-LOCK.

Signed-off-by: Abylay Ospan <aospan@netup.ru>
---
 utils/dvb/dvbv5-scan.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/utils/dvb/dvbv5-scan.c b/utils/dvb/dvbv5-scan.c
index 689bc0b..1fc33d7 100644
--- a/utils/dvb/dvbv5-scan.c
+++ b/utils/dvb/dvbv5-scan.c
@@ -182,12 +182,23 @@ static int print_frontend_stats(struct arguments *args,
 	return 0;
 }
 
+/* return timestamp in msec */
+uint64_t get_timestamp()
+{
+	struct timeval now;
+	gettimeofday(&now, 0);
+	return now.tv_sec * 1000 + now.tv_usec/1000;
+}
+
 static int check_frontend(void *__args,
 			  struct dvb_v5_fe_parms *parms)
 {
 	struct arguments *args = __args;
 	int rc, i;
 	fe_status_t status;
+	uint64_t start = get_timestamp();
+	/* msec timeout by default 4 sec * multiply */ 
+	uint64_t timeout = args->timeout_multiply * 4 * 1000;
 
 	args->n_status_lines = 0;
 	for (i = 0; i < args->timeout_multiply * 40; i++) {
@@ -203,6 +214,10 @@ static int check_frontend(void *__args,
 		print_frontend_stats(args, parms);
 		if (status & FE_HAS_LOCK)
 			break;
+
+		if ((get_timestamp() - start) > timeout)
+			break;
+
 		usleep(100000);
 	};
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [PATCH] [dvbv5-scan] wait no more than timeout when scanning
@ 2016-07-25  3:35 Abylay Ospan
  0 siblings, 0 replies; 5+ messages in thread
From: Abylay Ospan @ 2016-07-25  3:35 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, linux-media; +Cc: Abylay Ospan

some frontends (mentioned on lgdt3306a) wait timeout inside code like:
for (i = 20; i > 0; i--) {
  msleep(50);

If there is no-LOCK then dvbv5-scan spent a lot of time (doing 40x calls).
This patch introduce timeout which 4 sec * multiply. So we do not wait more
than 4 sec (or so) if no-LOCK.
CLOCK_MONOTONIC is used so we don't care about timestamps "rollup"

Signed-off-by: Abylay Ospan <aospan@netup.ru>
---
 utils/dvb/dvbv5-scan.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/utils/dvb/dvbv5-scan.c b/utils/dvb/dvbv5-scan.c
index 689bc0b..f6bb3fc 100644
--- a/utils/dvb/dvbv5-scan.c
+++ b/utils/dvb/dvbv5-scan.c
@@ -182,12 +182,23 @@ static int print_frontend_stats(struct arguments *args,
 	return 0;
 }
 
+/* return timestamp in msec */
+uint64_t get_timestamp()
+{
+	struct timespec now;
+	clock_gettime(CLOCK_MONOTONIC, &now);
+	return now.tv_sec * 1000 + now.tv_nsec/1000000;
+}
+
 static int check_frontend(void *__args,
 			  struct dvb_v5_fe_parms *parms)
 {
 	struct arguments *args = __args;
 	int rc, i;
 	fe_status_t status;
+	uint64_t start = get_timestamp();
+	/* msec timeout by default 4 sec * multiply */ 
+	uint64_t timeout = args->timeout_multiply * 4 * 1000;
 
 	args->n_status_lines = 0;
 	for (i = 0; i < args->timeout_multiply * 40; i++) {
@@ -203,6 +214,10 @@ static int check_frontend(void *__args,
 		print_frontend_stats(args, parms);
 		if (status & FE_HAS_LOCK)
 			break;
+
+		if ((get_timestamp() - start) > timeout)
+			break;
+
 		usleep(100000);
 	};
 
-- 
2.7.4


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

end of thread, other threads:[~2016-07-25 18:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-22 17:54 [PATCH] [dvbv5-scan] wait no more than timeout when scanning Abylay Ospan
2016-07-22 19:18 ` Mauro Carvalho Chehab
2016-07-25  4:01   ` Abylay Ospan
2016-07-25 18:47   ` Abylay Ospan
2016-07-25  3:35 Abylay Ospan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.