linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] Simplify logic to calculate the BT/system clock latency
@ 2010-09-22  7:03 Santiago Carot-Nemesio
  2010-09-22  7:03 ` [PATCH 2/2] Remove magic numbers in MCAP CSP Santiago Carot-Nemesio
  2010-09-22  7:59 ` [PATCH 1/2] Simplify logic to calculate the BT/system clock latency Johan Hedberg
  0 siblings, 2 replies; 4+ messages in thread
From: Santiago Carot-Nemesio @ 2010-09-22  7:03 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Santiago Carot-Nemesio

This is only a cosmetic change. Using a while loop
we avoid direct manipulation of counter loop variable
when error happens reading the BT clock.
---
 health/mcap_sync.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/health/mcap_sync.c b/health/mcap_sync.c
index 670260b..3d54936 100644
--- a/health/mcap_sync.c
+++ b/health/mcap_sync.c
@@ -384,12 +384,12 @@ static gboolean initialize_caps(struct mcap_mcl *mcl)
 
 	/* Do clock read a number of times and measure latency */
 	avg = 0;
+	i = 0;
 	retries = 10;
-	for (i = 0; i < 20 && retries > 0; ++i) {
+	while ((i < 20) && (retries > 0)) {
 		clock_gettime(CLK, &t1);
 		if (!read_btclock(mcl, &btclock, &btaccuracy)) {
-			--i;
-			--retries;
+			retries--;
 			continue;
 		}
 		clock_gettime(CLK, &t2);
@@ -397,6 +397,7 @@ static gboolean initialize_caps(struct mcap_mcl *mcl)
 		latency = time_us(&t2) - time_us(&t1);
 		latencies[i] = latency;
 		avg += latency;
+		i++;
 	}
 
 	if (retries <= 0)
-- 
1.7.0.4


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

* [PATCH 2/2] Remove magic numbers in MCAP CSP
  2010-09-22  7:03 [PATCH 1/2] Simplify logic to calculate the BT/system clock latency Santiago Carot-Nemesio
@ 2010-09-22  7:03 ` Santiago Carot-Nemesio
  2010-09-22  7:59   ` Johan Hedberg
  2010-09-22  7:59 ` [PATCH 1/2] Simplify logic to calculate the BT/system clock latency Johan Hedberg
  1 sibling, 1 reply; 4+ messages in thread
From: Santiago Carot-Nemesio @ 2010-09-22  7:03 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Santiago Carot-Nemesio

---
 health/mcap_sync.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/health/mcap_sync.c b/health/mcap_sync.c
index 3d54936..b9f2a65 100644
--- a/health/mcap_sync.c
+++ b/health/mcap_sync.c
@@ -48,6 +48,8 @@
 #define CLK CLOCK_MONOTONIC
 
 #define MCAP_CSP_ERROR g_quark_from_static_string("mcap-csp-error-quark")
+#define MAX_RETRIES	10
+#define SAMPLE_COUNT	20
 
 struct mcap_csp {
 	uint64_t	base_tmstamp;	/* CSP base timestamp */
@@ -363,7 +365,7 @@ uint32_t mcap_get_btclock(struct mcap_mcl *mcl)
 static gboolean initialize_caps(struct mcap_mcl *mcl)
 {
 	struct timespec t1, t2;
-	int latencies[20];
+	int latencies[SAMPLE_COUNT];
 	int latency, avg, dev;
 	uint32_t btclock;
 	uint16_t btaccuracy;
@@ -385,8 +387,8 @@ static gboolean initialize_caps(struct mcap_mcl *mcl)
 	/* Do clock read a number of times and measure latency */
 	avg = 0;
 	i = 0;
-	retries = 10;
-	while ((i < 20) && (retries > 0)) {
+	retries = MAX_RETRIES;
+	while ((i < SAMPLE_COUNT) && (retries > 0)) {
 		clock_gettime(CLK, &t1);
 		if (!read_btclock(mcl, &btclock, &btaccuracy)) {
 			retries--;
@@ -404,21 +406,21 @@ static gboolean initialize_caps(struct mcap_mcl *mcl)
 		return FALSE;
 
 	/* Calculate average and deviation */
-	avg /= 20;
+	avg /= SAMPLE_COUNT;
 	dev = 0;
-	for (i = 0; i < 20; ++i)
+	for (i = 0; i < SAMPLE_COUNT; ++i)
 		dev += abs(latencies[i] - avg);
-	dev /= 20;
+	dev /= SAMPLE_COUNT;
 
 	/* Calculate corrected average, without 'freak' latencies */
 	latency = 0;
-	for (i = 0; i < 20; ++i) {
+	for (i = 0; i < SAMPLE_COUNT; ++i) {
 		if (latencies[i] > (avg + dev * 6))
 			latency += avg;
 		else
 			latency += latencies[i];
 	}
-	latency /= 20;
+	latency /= SAMPLE_COUNT;
 
 	_caps.latency = latency;
 	_caps.preempt_thresh = latency * 4;
-- 
1.7.0.4


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

* Re: [PATCH 1/2] Simplify logic to calculate the BT/system clock latency
  2010-09-22  7:03 [PATCH 1/2] Simplify logic to calculate the BT/system clock latency Santiago Carot-Nemesio
  2010-09-22  7:03 ` [PATCH 2/2] Remove magic numbers in MCAP CSP Santiago Carot-Nemesio
@ 2010-09-22  7:59 ` Johan Hedberg
  1 sibling, 0 replies; 4+ messages in thread
From: Johan Hedberg @ 2010-09-22  7:59 UTC (permalink / raw)
  To: Santiago Carot-Nemesio; +Cc: linux-bluetooth

Hi,

On Wed, Sep 22, 2010, Santiago Carot-Nemesio wrote:
> This is only a cosmetic change. Using a while loop
> we avoid direct manipulation of counter loop variable
> when error happens reading the BT clock.
> ---
>  health/mcap_sync.c |    7 ++++---
>  1 files changed, 4 insertions(+), 3 deletions(-)

Thanks. The patch has been pushed upstream.

> +	while ((i < 20) && (retries > 0)) {

The extra parentheses around the comparisons are unnecessary. I fixed
that in a subsequent cleanup commit. Usually we only add these extra
parentheses for binary bitwise operations such as & and | for clarity.

Johan

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

* Re: [PATCH 2/2] Remove magic numbers in MCAP CSP
  2010-09-22  7:03 ` [PATCH 2/2] Remove magic numbers in MCAP CSP Santiago Carot-Nemesio
@ 2010-09-22  7:59   ` Johan Hedberg
  0 siblings, 0 replies; 4+ messages in thread
From: Johan Hedberg @ 2010-09-22  7:59 UTC (permalink / raw)
  To: Santiago Carot-Nemesio; +Cc: linux-bluetooth

Hi,

On Wed, Sep 22, 2010, Santiago Carot-Nemesio wrote:
> ---
>  health/mcap_sync.c |   18 ++++++++++--------
>  1 files changed, 10 insertions(+), 8 deletions(-)

Thanks. This patch is now also in the upstream tree.

Johan

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

end of thread, other threads:[~2010-09-22  7:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-22  7:03 [PATCH 1/2] Simplify logic to calculate the BT/system clock latency Santiago Carot-Nemesio
2010-09-22  7:03 ` [PATCH 2/2] Remove magic numbers in MCAP CSP Santiago Carot-Nemesio
2010-09-22  7:59   ` Johan Hedberg
2010-09-22  7:59 ` [PATCH 1/2] Simplify logic to calculate the BT/system clock latency Johan Hedberg

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).