Linux Kernel
3.7.1
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
lib
average.c
Go to the documentation of this file.
1
/*
2
* lib/average.c
3
*
4
* This source code is licensed under the GNU General Public License,
5
* Version 2. See the file COPYING for more details.
6
*/
7
8
#include <linux/export.h>
9
#include <
linux/average.h
>
10
#include <linux/kernel.h>
11
#include <
linux/bug.h
>
12
#include <
linux/log2.h
>
13
37
void
ewma_init
(
struct
ewma
*
avg
,
unsigned
long
factor,
unsigned
long
weight
)
38
{
39
WARN_ON
(!
is_power_of_2
(weight) || !
is_power_of_2
(factor));
40
41
avg->
weight
=
ilog2
(weight);
42
avg->
factor
=
ilog2
(factor);
43
avg->
internal
= 0;
44
}
45
EXPORT_SYMBOL
(
ewma_init
);
46
54
struct
ewma
*
ewma_add
(
struct
ewma
*
avg
,
unsigned
long
val
)
55
{
56
avg->
internal
= avg->
internal
?
57
(((avg->
internal
<< avg->
weight
) - avg->
internal
) +
58
(val << avg->
factor
)) >> avg->
weight
:
59
(val << avg->
factor
);
60
return
avg
;
61
}
62
EXPORT_SYMBOL
(
ewma_add
);
Generated on Thu Jan 10 2013 14:55:22 for Linux Kernel by
1.8.2