Commit 0fea0527 authored by Dorel Coman's avatar Dorel Coman Committed by Oliver Horst
Browse files

memguard: removed unused ewma, we are using only ema() and was included in memguard.c

parent ac086ab1
......@@ -4,7 +4,6 @@ target_sources(
freertos-plus
#
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/ewma.c"
"${CMAKE_CURRENT_LIST_DIR}/memguard.c"
"${CMAKE_CURRENT_LIST_DIR}/perfmon.c"
)
/*
* Created by Dorel Coman on 02.01.18.
*
* This source code is licensed under the GNU General Public License,
* Version 2. See the file COPYING for more details.
*
* The original can be fond at the link:
* https://elixir.bootlin.com/linux/v4.2.8/source/lib/average.c
*
* The original code was discontinued from Linux v4.3
*/
#include "memguard/ewma.h"
#include <stdint-gcc.h>
inline int is_power_of_2(uint64_t n)
{
return (n != 0 && ((n & (n - 1)) == 0));
}
void ewma_init(struct ewma *avg, uint64_t factor, uint64_t weight)
{
// avg->weight = (uint64_t) ilog2(weight);
// avg->factor = (uint64_t) ilog2(factor);
avg->internal = 0;
}
/**
* ewma_add() - Exponentially weighted moving average (EWMA)
* @avg: Average structure
* @val: Current value
*
* Add a sample to the average.
*/
struct ewma *ewma_add(struct ewma *avg, uint64_t val)
{
uint64_t internal = ACCESS_ONCE(avg->internal);
ACCESS_ONCE(avg->internal) = internal ?
(((internal << avg->weight) - internal) +
(val << avg->factor)) >> avg->weight :
(val << avg->factor);
return avg;
}
uint32_t ema(uint32_t new_sample, uint32_t old_average, float alpha)
{
uint32_t new_average = (uint32_t)(alpha * new_sample) + (uint32_t)((1-alpha) * old_average);
return new_average;
}
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