|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
From 07a8062a47609a58c67692635e99ae6275207dee Mon Sep 17 00:00:00 2001
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
From: Vadim Fedorenko <vadfed@meta.com>
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
Date: Wed, 11 Jan 2023 06:58:36 -0800
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
Subject: [PATCH 2/2] filter: treat negative path_delay as a spike
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
There should be no negative path delay during normal operation. Let's
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
filter such values out. And with that fix there is no need to use
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
"best" frequency in case of holdover - just use the latest mean from
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
the filter.
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
---
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
clock.c | 4 ++--
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
mmedian.c | 21 ++++++++++++++++-----
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
2 files changed, 18 insertions(+), 7 deletions(-)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
diff --git a/clock.c b/clock.c
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
index 3787ec7..6c9c12c 100644
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
--- a/clock.c
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+++ b/clock.c
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
@@ -1973,9 +1973,9 @@ enum servo_state clock_synchronize(struct clock *c, tmv_t ingress, tmv_t origin)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
bool is_spike = llabs(offset) > llabs(max_func(c->max_offset_locked, c->min_offset_locked));
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
if (is_spike) {
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
- adj = c->min_offset_freq_mean;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+ adj = c->freq_mean;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
c->master_offset = nanoseconds_to_tmv(c->max_offset_locked);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
- pr_notice("spike detected => max_offset_locked: %ld, setting offset to min_offset_freq_mean: %lf", c->max_offset_locked, adj);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+ pr_notice("spike detected => max_offset_locked: %ld, setting freq to freq_mean: %lf", c->max_offset_locked, adj);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
clock_synchronize_locked(c, adj);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
if (c->offset_skipped_count < c->max_offset_skipped_count) {
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
c->offset_skipped_count++;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
diff --git a/mmedian.c b/mmedian.c
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
index 2383467..50d8b90 100644
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
--- a/mmedian.c
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+++ b/mmedian.c
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
@@ -21,6 +21,7 @@
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
#include "mmedian.h"
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
#include "filter_private.h"
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+#include "print.h"
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
struct mmedian {
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
struct filter filter;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
@@ -41,11 +42,25 @@ static void mmedian_destroy(struct filter *filter)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
free(m);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
}
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+static inline tmv_t mmedian_calc_pdelay(const struct mmedian *m)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+{
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+ if (m->cnt % 2)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+ return m->samples[m->order[m->cnt / 2]];
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+ else
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+ return tmv_div(tmv_add(m->samples[m->order[m->cnt / 2 - 1]],
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+ m->samples[m->order[m->cnt / 2]]), 2);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+}
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
static tmv_t mmedian_sample(struct filter *filter, tmv_t sample)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
{
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
struct mmedian *m = container_of(filter, struct mmedian, filter);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
int i;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+ if (m->cnt && tmv_to_nanoseconds(sample) < 2000) {
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+ pr_info("skipping path delay sample %ld", tmv_to_nanoseconds(sample));
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+ return mmedian_calc_pdelay(m);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+ }
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
m->samples[m->index] = sample;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
if (m->cnt < m->len) {
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
m->cnt++;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
@@ -69,11 +84,7 @@ static tmv_t mmedian_sample(struct filter *filter, tmv_t sample)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
m->index = (1 + m->index) % m->len;
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
- if (m->cnt % 2)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
- return m->samples[m->order[m->cnt / 2]];
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
- else
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
- return tmv_div(tmv_add(m->samples[m->order[m->cnt / 2 - 1]],
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
- m->samples[m->order[m->cnt / 2]]), 2);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
+ return mmedian_calc_pdelay(m);
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
}
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
static void mmedian_reset(struct filter *filter)
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
--
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
2.30.2
|
|
![](https://seccdn.libravatar.org/avatar/fd810b62950cc276bea6dfd556fddb46f443946a2cb6243830c798dc8682dd7c?s=16&d=retro) |
7a40ed |
|