From: Santiago Carot-Nemesio <sancane@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Santiago Carot-Nemesio <sancane@gmail.com>
Subject: [PATCH 2/2] Remove magic numbers in MCAP CSP
Date: Wed, 22 Sep 2010 09:03:51 +0200 [thread overview]
Message-ID: <1285139031-1570-2-git-send-email-sancane@gmail.com> (raw)
In-Reply-To: <1285139031-1570-1-git-send-email-sancane@gmail.com>
---
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
next prev parent reply other threads:[~2010-09-22 7:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2010-09-22 7:59 ` [PATCH 2/2] Remove magic numbers in MCAP CSP Johan Hedberg
2010-09-22 7:59 ` [PATCH 1/2] Simplify logic to calculate the BT/system clock latency Johan Hedberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1285139031-1570-2-git-send-email-sancane@gmail.com \
--to=sancane@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).