Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
VILLASframework
VILLAScommon
Commits
c2154f34
Commit
c2154f34
authored
Sep 11, 2020
by
Steffen Vogel
🎅🏼
Browse files
fix a lot of cppcheck warnings and errors
parent
6833c8c3
Changes
16
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
c2154f34
...
...
@@ -59,6 +59,7 @@ test:cppcheck:
--quiet
--inline-suppr
--enable=warning,performance,portability,information,missingInclude
--suppress=noValidConfiguration
--std=c++11
-I include
lib/
...
...
include/villas/buffer.hpp
View file @
c2154f34
...
...
@@ -24,6 +24,7 @@
#pragma once
#include
<cstdlib>
#include
<vector>
#include
<jansson.h>
...
...
@@ -34,14 +35,10 @@ namespace villas {
class
Buffer
{
public:
char
*
buf
;
size_t
len
;
size_t
size
;
std
::
vector
<
char
>
buf
;
Buffer
(
size_t
size
);
~
Buffer
();
void
clear
();
int
append
(
const
char
*
data
,
size_t
len
);
...
...
include/villas/dsp/pid.hpp
View file @
c2154f34
...
...
@@ -30,27 +30,27 @@ class PID {
protected:
double
dt
;
double
max
;
double
min
;
double
Kp
;
double
Kd
;
double
Ki
;
double
pre_error
;
double
integral
;
double
max
;
double
min
;
double
Kp
;
double
Kd
;
double
Ki
;
double
pre_error
;
double
integral
;
public:
/**
/**
* Kp - proportional gain
* Ki - Integral gain
* Kd - derivative gain
* dt - loop interval time
* max - maximum value of manipulated variable
* min - minimum value of manipulated variable
* Ki - Integral gain
* Kd - derivative gain
* dt - loop interval time
* max - maximum value of manipulated variable
* min - minimum value of manipulated variable
*/
PID
(
double
_dt
,
double
_max
,
double
_min
,
double
_Kp
,
double
_Kd
,
double
_Ki
);
PID
(
double
_dt
,
double
_max
,
double
_min
,
double
_Kp
,
double
_Kd
,
double
_Ki
);
/** Returns the manipulated variable given a setpoint and current process value */
double
calculate
(
double
setpoint
,
double
pv
);
/** Returns the manipulated variable given a setpoint and current process value */
double
calculate
(
double
setpoint
,
double
pv
);
};
}
/* namespace dsp */
...
...
include/villas/kernel/pci.hpp
View file @
c2154f34
...
...
@@ -50,9 +50,9 @@ public:
bool
operator
==
(
const
Id
&
i
);
int
vendor
;
int
device
;
int
class_code
;
unsigned
int
vendor
;
unsigned
int
device
;
unsigned
int
class_code
;
};
class
Slot
{
...
...
@@ -69,10 +69,10 @@ public:
bool
operator
==
(
const
Slot
&
s
);
int
domain
;
int
bus
;
int
device
;
int
function
;
unsigned
int
domain
;
unsigned
int
bus
;
unsigned
int
device
;
unsigned
int
function
;
};
struct
Region
{
...
...
include/villas/kernel/vfio.hpp
View file @
c2154f34
...
...
@@ -45,7 +45,11 @@ class Device {
friend
class
Container
;
public:
Device
(
const
std
::
string
&
name
,
Group
&
group
)
:
name
(
name
),
group
(
group
)
{}
name
(
name
),
fd
(
-
1
),
pci_device
(
nullptr
),
group
(
group
)
{
}
~
Device
();
...
...
@@ -97,7 +101,11 @@ class Group {
friend
class
Container
;
friend
Device
;
private:
Group
(
int
index
)
:
fd
(
-
1
),
index
(
index
)
{}
Group
(
int
index
)
:
fd
(
-
1
),
index
(
index
),
container
(
nullptr
)
{
}
public:
~
Group
();
...
...
include/villas/memory.hpp
View file @
c2154f34
...
...
@@ -133,7 +133,7 @@ class BaseAllocator {
public:
/// memoryAddrSpaceId: memory that is managed by this allocator
BaseAllocator
(
MemoryManager
::
AddressSpaceId
memoryAddrSpaceId
)
:
memoryAddrSpaceId
(
memoryAddrSpaceId
)
memoryAddrSpaceId
(
memoryAddrSpaceId
)
{
// CRTP
derivedAlloc
=
static_cast
<
DerivedAllocator
*>
(
this
);
...
...
@@ -150,9 +150,11 @@ public:
}
BaseAllocator
(
std
::
unique_ptr
<
MemoryBlock
,
MemoryBlock
::
deallocator_fn
>
mem
)
:
BaseAllocator
(
mem
->
getAddrSpaceId
())
BaseAllocator
(
mem
->
getAddrSpaceId
())
{
// cppcheck-suppress useInitializationList
memoryBlock
=
std
::
move
(
mem
);
derivedAlloc
=
nullptr
;
}
virtual
std
::
unique_ptr
<
MemoryBlock
,
MemoryBlock
::
deallocator_fn
>
...
...
include/villas/memory_manager.hpp
View file @
c2154f34
...
...
@@ -51,7 +51,10 @@ public:
* @param size Size of "memory window"
*/
MemoryTranslation
(
uintptr_t
src
,
uintptr_t
dst
,
size_t
size
)
:
src
(
src
),
dst
(
dst
),
size
(
size
)
{}
src
(
src
),
dst
(
dst
),
size
(
size
)
{
}
uintptr_t
getLocalAddr
(
uintptr_t
addrInForeignAddrSpace
)
const
;
...
...
@@ -96,10 +99,9 @@ class MemoryManager {
private:
// This is a singleton, so private constructor ...
MemoryManager
()
:
memoryGraph
(
"memory:graph"
)
memoryGraph
(
"memory:graph"
),
logger
(
logging
.
get
(
"memory:manager"
))
{
logger
=
logging
.
get
(
"memory:manager"
);
pathCheckFunc
=
[
&
](
const
MemoryGraph
::
Path
&
path
)
{
return
this
->
pathCheck
(
path
);
};
...
...
lib/advio.cpp
View file @
c2154f34
...
...
@@ -96,7 +96,7 @@ static char * advio_human_time(double t, char *buf, size_t len)
const
char
*
units
[]
=
{
"secs"
,
"mins"
,
"hrs"
,
"days"
,
"weeks"
,
"months"
,
"years"
};
int
divs
[]
=
{
60
,
60
,
24
,
7
,
4
,
12
};
while
(
t
>
divs
[
i
]
&&
i
<
ARRAY_LEN
(
divs
))
{
while
(
i
<
ARRAY_LEN
(
divs
)
&&
t
>
divs
[
i
]
)
{
t
/=
divs
[
i
];
i
++
;
}
...
...
lib/buffer.cpp
View file @
c2154f34
...
...
@@ -30,45 +30,24 @@
using
namespace
villas
;
Buffer
::
Buffer
(
size_t
sz
)
:
len
(
0
),
size
(
sz
)
{
buf
=
new
char
[
size
];
if
(
!
buf
)
throw
MemoryAllocationError
();
memset
(
buf
,
0
,
size
);
}
Buffer
::~
Buffer
()
{
delete
[]
buf
;
}
buf
(
sz
,
0
)
{
}
void
Buffer
::
clear
()
{
len
=
0
;
buf
.
clear
()
;
}
int
Buffer
::
append
(
const
char
*
data
,
size_t
l
)
{
if
(
len
+
l
>
size
)
{
size
=
len
+
l
;
buf
=
(
char
*
)
realloc
(
buf
,
size
);
if
(
!
buf
)
return
-
1
;
}
memcpy
(
buf
+
len
,
data
,
l
);
len
+=
l
;
buf
.
insert
(
buf
.
end
(),
data
,
data
+
l
);
return
0
;
}
int
Buffer
::
parseJson
(
json_t
**
j
)
{
*
j
=
json_loadb
(
buf
,
len
,
0
,
nullptr
);
*
j
=
json_loadb
(
buf
.
data
(),
buf
.
size
()
,
0
,
nullptr
);
if
(
!*
j
)
return
-
1
;
...
...
@@ -79,17 +58,11 @@ int Buffer::appendJson(json_t *j, int flags)
{
size_t
l
;
retry:
l
=
json_dumpb
(
j
,
buf
+
len
,
size
-
len
,
flags
);
if
(
size
<
len
+
l
)
{
buf
=
(
char
*
)
realloc
(
buf
,
len
+
l
);
if
(
!
buf
)
return
-
1
;
size
=
len
+
l
;
retry:
l
=
json_dumpb
(
j
,
buf
.
data
()
+
buf
.
size
(),
buf
.
capacity
()
-
buf
.
size
(),
flags
);
if
(
buf
.
capacity
()
<
buf
.
size
()
+
l
)
{
buf
.
reserve
(
buf
.
size
()
+
l
);
goto
retry
;
}
len
+=
l
;
return
0
;
}
lib/dsp/pid.cpp
View file @
c2154f34
...
...
@@ -33,7 +33,9 @@ PID::PID(double _dt, double _max, double _min, double _Kp, double _Kd, double _K
min
(
_min
),
Kp
(
_Kp
),
Kd
(
_Kd
),
Ki
(
_Ki
)
Ki
(
_Ki
),
pre_error
(
0
),
integral
(
0
)
{
}
double
PID
::
calculate
(
double
setpoint
,
double
pv
)
...
...
lib/hist.cpp
View file @
c2154f34
...
...
@@ -35,17 +35,20 @@ using namespace villas::utils;
namespace
villas
{
Hist
::
Hist
(
int
buckets
,
Hist
::
cnt_t
wu
)
:
warmup
(
wu
)
{
for
(
int
i
=
0
;
i
<
buckets
;
i
++
){
data
.
push_back
(
0
);
}
total
=
0
;
highest
=
0
;
lowest
=
DBL_MAX
;
higher
=
0
;
lower
=
0
;
}
resolution
(
0
),
high
(),
low
(),
highest
(
std
::
numeric_limits
<
double
>::
min
()),
lowest
(
std
::
numeric_limits
<
double
>::
max
()),
last
(),
total
(
0
),
warmup
(
wu
),
higher
(
0
),
lower
(
0
),
data
(
buckets
,
0
),
_m
{
0
,
0
},
_s
{
0
,
0
}
{
}
void
Hist
::
put
(
double
value
)
{
...
...
@@ -66,10 +69,10 @@ void Hist::put(double value)
high
=
getMean
()
+
3
*
getStddev
();
resolution
=
(
high
-
low
)
/
data
.
size
();
}
else
if
(
data
.
size
()
&&
(
total
==
warmup
)
&&
(
warmup
==
0
)){
// there is no warmup phase
// TODO resolution = ?
}
else
if
(
data
.
size
()
&&
(
total
==
warmup
)
&&
(
warmup
==
0
))
{
// there is no warmup phase
// TODO resolution = ?
}
else
{
idx_t
idx
=
std
::
round
((
value
-
low
)
/
resolution
);
...
...
@@ -99,7 +102,6 @@ void Hist::put(double value)
_m
[
1
]
=
_m
[
0
];
_s
[
1
]
=
_s
[
0
];
}
}
void
Hist
::
reset
()
...
...
lib/kernel/kernel.cpp
View file @
c2154f34
...
...
@@ -135,7 +135,7 @@ int villas::kernel::module_set_param(const char *module, const char *param, cons
snprintf
(
fn
,
sizeof
(
fn
),
"%s/module/%s/parameters/%s"
,
SYSFS_PATH
,
module
,
param
);
f
=
fopen
(
fn
,
"w"
);
if
(
!
f
)
se
rror
(
"Failed set parameter
%s
for kernel module
%s
to
%s
"
,
module
,
param
,
value
);
throw
RuntimeE
rror
(
"Failed set parameter
{}
for kernel module
{}
to
{}
"
,
module
,
param
,
value
);
debug
(
LOG_KERNEL
|
5
,
"Set parameter %s of kernel module %s to %s"
,
module
,
param
,
value
);
fprintf
(
f
,
"%s"
,
value
);
...
...
lib/kernel/pci.cpp
View file @
c2154f34
...
...
@@ -57,7 +57,7 @@ DeviceList::DeviceList()
Id
id
;
Slot
slot
;
struct
{
const
char
*
s
;
int
*
p
;
}
map
[]
=
{
struct
{
const
char
*
s
;
unsigned
int
*
p
;
}
map
[]
=
{
{
"vendor"
,
&
id
.
vendor
},
{
"device"
,
&
id
.
device
}
};
...
...
lib/kernel/vfio.cpp
View file @
c2154f34
...
...
@@ -718,7 +718,7 @@ Device::pciMsiFind(int nos[])
}
while
((
col
=
strtok
(
nullptr
,
" "
)));
ret
=
sscanf
(
last
,
"vfio-msi[%
u
](%12[0-9:])"
,
&
idx
,
name
);
ret
=
sscanf
(
last
,
"vfio-msi[%
d
](%12[0-9:])"
,
&
idx
,
name
);
if
(
ret
==
2
)
{
if
(
strstr
(
this
->
name
.
c_str
(),
name
)
==
this
->
name
.
c_str
())
nos
[
idx
]
=
irq
;
...
...
tests/unit/advio.cpp
View file @
c2154f34
...
...
@@ -227,8 +227,8 @@ Test(advio, append)
char
c
;
fseek
(
af
->
file
,
0
,
SEEK_SET
);
if
(
af
->
file
)
{
while
((
c
=
getc
(
af
->
file
))
!=
EOF
)
putchar
(
c
);
while
((
c
=
getc
(
af
->
file
))
!=
EOF
)
putchar
(
c
);
}
len
=
afwrite
(
append1
,
1
,
64
,
af
);
...
...
tests/unit/tsc.cpp
View file @
c2154f34
...
...
@@ -28,7 +28,6 @@
#define CNT (1 << 18)
// cppcheck-suppress unknownMacro
TestSuite
(
tsc
,
.
description
=
"Timestamp counters"
);
Test
(
tsc
,
increasing
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment