Commit 7099d1af authored by Andreas Schmidt's avatar Andreas Schmidt

Refactor windowed filter.

parent e8e952b8
......@@ -59,7 +59,6 @@ bool BBR_IsNextCyclePhase(BBR* bbr, prrtByteCount_t bytes_lost, prrtByteCount_t
return is_full_length && (bytes_lost > 0 || prior_inflight >= BBR_Inflight(bbr, bbr->pacing_gain));
bool is_max_length = (PrrtClock_get_current_time_us() - bbr->cycle_stamp) > 4 * bbr->rtprop;
return is_max_length || (prior_inflight <= BBR_Inflight(bbr, 1.0));
}
void BBR_AdvanceCyclePhase(BBR* bbr)
......@@ -306,7 +305,7 @@ BBR* BBR_Init(prrtByteCount_t maximum_payload_size)
bbr->min_pipe_cwnd = 4 * maximum_payload_size;
bbr->initial_cwnd = 4 * maximum_payload_size;
bbr->has_seen_rtt = false;
bbr->btlBwFilter = WindowedFilter_Init(true);
bbr->btlBwFilter = WindowedFilter_create(true, 10);
bbr->rtprop = Inf;
bbr->rtprop_stamp = PrrtClock_get_current_time_us();
bbr->probe_rtt_done_stamp = 0;
......
......@@ -3,12 +3,16 @@
#include "common.h"
WindowedFilter* WindowedFilter_Init(bool isMaxFilter)
WindowedFilter * WindowedFilter_create(bool isMaxFilter, uint32_t length)
{
WindowedFilter* filter = calloc(1, sizeof(WindowedFilter));
check_mem(filter);
filter->list = calloc(length, sizeof(uint32_t));
check_mem(filter->list);
filter->length = length;
filter->isMaxFilter = isMaxFilter;
filter->isInitialized = false;
filter->last = 9;
return filter;
......@@ -18,9 +22,13 @@ WindowedFilter* WindowedFilter_Init(bool isMaxFilter)
return NULL;
}
void WindowedFilter_destroy(WindowedFilter* filter)
bool WindowedFilter_destroy(WindowedFilter* filter)
{
if (filter->list != NULL) {
free(filter->list);
}
free(filter);
return true;
}
uint8_t WindowedFilter_findNewExtremum(WindowedFilter* filter)
......@@ -29,7 +37,7 @@ uint8_t WindowedFilter_findNewExtremum(WindowedFilter* filter)
uint8_t pos_extremum = 0;
if (filter->isMaxFilter) {
extremum = 0;
for (uint8_t i = 0; i < DefaultFilterLen; i++) {
for (uint8_t i = 0; i < filter->length; i++) {
if (extremum < filter->list[i]) {
extremum = filter->list[i];
pos_extremum = i;
......@@ -37,7 +45,7 @@ uint8_t WindowedFilter_findNewExtremum(WindowedFilter* filter)
}
} else {
extremum = UINT32_MAX;
for (uint8_t i = 0; i < DefaultFilterLen; i++) {
for (uint8_t i = 0; i < filter->length; i++) {
if (extremum > filter->list[i]) {
extremum = filter->list[i];
pos_extremum = i;
......@@ -49,7 +57,7 @@ uint8_t WindowedFilter_findNewExtremum(WindowedFilter* filter)
void WindowedFilter_print(WindowedFilter* filter)
{
for (int i = filter->first; i != filter->last; i = (i+1) % DefaultFilterLen) {
for (int i = filter->first; i != filter->last; i = (i+1) % filter->length) {
printf("%u,", filter->list[i]);
}
printf("%u", filter->list[filter->last]);
......@@ -58,11 +66,12 @@ void WindowedFilter_print(WindowedFilter* filter)
uint32_t WindowedFilter_push(WindowedFilter* filter, uint32_t value)
{
filter->isInitialized = true;
uint32_t extremum = WindowedFilter_getExtremum(filter);
uint8_t last_position = filter->last;
filter->list[filter->last] = value;
filter->first = (uint8_t )((filter->first + 1) % DefaultFilterLen);
filter->last = (uint8_t )((filter->last + 1) % DefaultFilterLen);
filter->first = (uint8_t )((filter->first + 1) % filter->length);
filter->last = (uint8_t )((filter->last + 1) % filter->length);
if (value > extremum) {
filter->pos_extremum = last_position;
return filter->list[last_position];
......
#ifndef PRRT_WINDOWEDFILTER_H
#define PRRT_WINDOWEDFILTER_H
#define DefaultFilterLen 10
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct windowedFilter {
uint32_t list[DefaultFilterLen];
uint32_t* list;
uint8_t first;
uint8_t last;
uint8_t pos_extremum;
bool isMaxFilter;
uint32_t length;
bool isInitialized;
} WindowedFilter;
WindowedFilter* WindowedFilter_Init(bool isMaxFilter);
void WindowedFilter_destroy(WindowedFilter* filter);
WindowedFilter* WindowedFilter_create(bool isMaxFilter, uint32_t length);
bool WindowedFilter_destroy(WindowedFilter* filter);
uint32_t WindowedFilter_push(WindowedFilter* filter, uint32_t value);
uint32_t WindowedFilter_getExtremum(WindowedFilter* filter);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment