mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
use C++ instead of C comment style
Signed-off-by: Steffen Vogel <steffen.vogel@opal-rt.com>
This commit is contained in:
parent
60dbd2c545
commit
5569eb67e2
28 changed files with 293 additions and 294 deletions
|
@ -19,7 +19,8 @@ namespace villas {
|
|||
class Buffer : public std::vector<char> {
|
||||
|
||||
protected:
|
||||
static int callback(const char *data, size_t len, void *ctx);
|
||||
static
|
||||
int callback(const char *data, size_t len, void *ctx);
|
||||
|
||||
public:
|
||||
Buffer(const char *buf, size_type len) :
|
||||
|
|
|
@ -28,11 +28,10 @@ enum class State {
|
|||
PREPARED = 13
|
||||
};
|
||||
|
||||
/** Callback to destroy list elements.
|
||||
*
|
||||
* @param data A pointer to the data which should be freed.
|
||||
*/
|
||||
// Callback to destroy list elements.
|
||||
//
|
||||
// @param data A pointer to the data which should be freed.
|
||||
typedef int (*dtor_cb_t)(void *);
|
||||
|
||||
/** Convert state enum to human readable string. */
|
||||
// Convert state enum to human readable string.
|
||||
std::string stateToString(enum State s);
|
||||
|
|
|
@ -30,20 +30,20 @@
|
|||
|
||||
#define HTTP_USER_AGENT PROJECT_NAME " (" PROJECT_BUILD_ID ")"
|
||||
|
||||
/* Hard-coded cache line size */
|
||||
// Hard-coded cache line size
|
||||
#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__)
|
||||
#define CACHELINE_SIZE 64
|
||||
#else
|
||||
#error "Unsupported architecture"
|
||||
#endif
|
||||
|
||||
/* Paths */
|
||||
// Paths
|
||||
#define PREFIX "@CMAKE_INSTALL_PREFIX@"
|
||||
#define PLUGIN_PATH "@CMAKE_INSTALL_PREFIX@/share/villas/node/plugins"
|
||||
#define SYSFS_PATH "/sys"
|
||||
#define PROCFS_PATH "/proc"
|
||||
|
||||
/** Width of log output in characters */
|
||||
// Width of log output in characters
|
||||
#define LOG_WIDTH 80
|
||||
#define LOG_HEIGHT 25
|
||||
|
||||
|
|
|
@ -40,21 +40,19 @@ public:
|
|||
zero();
|
||||
}
|
||||
|
||||
/** Parses string with list of CPU ranges.
|
||||
*
|
||||
* @param str Human readable representation of the set.
|
||||
*/
|
||||
// Parses string with list of CPU ranges.
|
||||
//
|
||||
// @param str Human readable representation of the set.
|
||||
CpuSet(const std::string &str);
|
||||
|
||||
CpuSet(const char *str);
|
||||
|
||||
/** Convert integer to cpu_set_t.
|
||||
*
|
||||
* @param set An integer number which is used as the mask
|
||||
*/
|
||||
// Convert integer to cpu_set_t.
|
||||
//
|
||||
// @param set An integer number which is used as the mask
|
||||
CpuSet(uintmax_t set);
|
||||
|
||||
/** Convert cpu_set_t to an integer. */
|
||||
// Convert cpu_set_t to an integer. */
|
||||
operator uintmax_t();
|
||||
|
||||
operator const cpu_set_t*()
|
||||
|
@ -62,10 +60,9 @@ public:
|
|||
return setp;
|
||||
}
|
||||
|
||||
/** Returns human readable representation of the cpuset.
|
||||
*
|
||||
* The output format is a list of CPUs with ranges (for example, "0,1,3-9").
|
||||
*/
|
||||
// Returns human readable representation of the cpuset.
|
||||
//
|
||||
// The output format is a list of CPUs with ranges (for example, "0,1,3-9").
|
||||
operator std::string();
|
||||
|
||||
~CpuSet()
|
||||
|
|
|
@ -24,17 +24,15 @@ protected:
|
|||
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
|
||||
*/
|
||||
// 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
|
||||
PID(double _dt, double _max, double _min, double _Kp, double _Kd, double _Ki);
|
||||
|
||||
/** Returns the manipulated variable given a setpoint and current process value */
|
||||
// Returns the manipulated variable given a setpoint and current process value
|
||||
double calculate(double setpoint, double pv);
|
||||
};
|
||||
|
||||
|
|
|
@ -69,7 +69,8 @@ public:
|
|||
error(e)
|
||||
{ }
|
||||
|
||||
virtual const char * what() const noexcept
|
||||
virtual
|
||||
const char * what() const noexcept
|
||||
{
|
||||
return fmt::format("{}: {} in {}:{}:{}",
|
||||
std::runtime_error::what(),
|
||||
|
@ -81,7 +82,7 @@ public:
|
|||
class ConfigError : public std::runtime_error {
|
||||
|
||||
protected:
|
||||
/** A setting-id referencing the setting. */
|
||||
// A setting-id referencing the setting.
|
||||
std::string id;
|
||||
json_t *setting;
|
||||
json_error_t error;
|
||||
|
@ -163,7 +164,8 @@ public:
|
|||
return baseUri + id;
|
||||
}
|
||||
|
||||
virtual const char * what() const noexcept
|
||||
virtual
|
||||
const char * what() const noexcept
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
|
|
|
@ -19,50 +19,49 @@
|
|||
|
||||
namespace villas {
|
||||
|
||||
/** Histogram structure used to collect statistics. */
|
||||
// Histogram structure used to collect statistics.
|
||||
class Hist {
|
||||
|
||||
public:
|
||||
using cnt_t = uintmax_t;
|
||||
using idx_t = std::vector<cnt_t>::difference_type;
|
||||
|
||||
/** Initialize struct Hist with supplied values and allocate memory for buckets. */
|
||||
// Initialize struct Hist with supplied values and allocate memory for buckets.
|
||||
Hist(int buckets = 0, cnt_t warmup = 0);
|
||||
|
||||
/** Reset all counters and values back to zero. */
|
||||
// Reset all counters and values back to zero.
|
||||
void reset();
|
||||
|
||||
/** Count a value within its corresponding bucket. */
|
||||
// Count a value within its corresponding bucket.
|
||||
void put(double value);
|
||||
|
||||
/** Calcluate the variance of all counted values. */
|
||||
// Calcluate the variance of all counted values.
|
||||
double getVar() const;
|
||||
|
||||
/** Calculate the mean average of all counted values. */
|
||||
// Calculate the mean average of all counted values.
|
||||
double getMean() const;
|
||||
|
||||
/** Calculate the standard derivation of all counted values. */
|
||||
// Calculate the standard derivation of all counted values.
|
||||
double getStddev() const;
|
||||
|
||||
/** Print all statistical properties of distribution including a graphilcal plot of the histogram. */
|
||||
// Print all statistical properties of distribution including a graphilcal plot of the histogram.
|
||||
void print(Logger logger, bool details) const;
|
||||
|
||||
/** Print ASCII style plot of histogram */
|
||||
// Print ASCII style plot of histogram.
|
||||
void plot(Logger logger) const;
|
||||
|
||||
/** Dump histogram data in Matlab format.
|
||||
*
|
||||
* @return The string containing the dump. The caller is responsible to free() the buffer.
|
||||
*/
|
||||
// Dump histogram data in Matlab format.
|
||||
//
|
||||
// @return The string containing the dump. The caller is responsible to free() the buffer.
|
||||
char * dump() const;
|
||||
|
||||
/** Prints Matlab struct containing all infos to file. */
|
||||
// Prints Matlab struct containing all infos to file.
|
||||
int dumpMatlab(FILE *f) const;
|
||||
|
||||
/** Write the histogram in JSON format to fiel \p f. */
|
||||
// Write the histogram in JSON format to fiel \p f.
|
||||
int dumpJson(FILE *f) const;
|
||||
|
||||
/** Build a libjansson / JSON object of the histogram. */
|
||||
// Build a libjansson / JSON object of the histogram.
|
||||
json_t * toJson() const;
|
||||
|
||||
double getHigh() const
|
||||
|
@ -96,25 +95,25 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
double resolution; /**< The distance between two adjacent buckets. */
|
||||
double resolution; // The distance between two adjacent buckets.
|
||||
|
||||
double high; /**< The value of the highest bucket. */
|
||||
double low; /**< The value of the lowest bucket. */
|
||||
double high; // The value of the highest bucket.
|
||||
double low; // The value of the lowest bucket.
|
||||
|
||||
double highest; /**< The highest value observed (may be higher than #high). */
|
||||
double lowest; /**< The lowest value observed (may be lower than #low). */
|
||||
double last; /**< The last value which has been put into the buckets */
|
||||
double highest; // The highest value observed (may be higher than #high).
|
||||
double lowest; // The lowest value observed (may be lower than #low).
|
||||
double last; // The last value which has been put into the buckets.
|
||||
|
||||
cnt_t total; /**< Total number of counted values. */
|
||||
cnt_t warmup; /**< Number of values which are used during warmup phase. */
|
||||
cnt_t total; // Total number of counted values.
|
||||
cnt_t warmup; // Number of values which are used during warmup phase.
|
||||
|
||||
cnt_t higher; /**< The number of values which are higher than #high. */
|
||||
cnt_t lower; /**< The number of values which are lower than #low. */
|
||||
cnt_t higher; // The number of values which are higher than #high.
|
||||
cnt_t lower; // The number of values which are lower than #low.
|
||||
|
||||
|
||||
std::vector<cnt_t> data; /**< Bucket counters. */
|
||||
std::vector<cnt_t> data; // Bucket counters.
|
||||
|
||||
double _m[2], _s[2]; /**< Private variables for online variance calculation */
|
||||
double _m[2], _s[2]; // Private variables for online variance calculation.
|
||||
};
|
||||
|
||||
} // namespace villas
|
||||
|
|
|
@ -35,12 +35,11 @@ int setNrHugepages(int nr);
|
|||
// @reval <>0 Kernel was not booted with parameter \p key
|
||||
int getCmdlineParam(const char *param, char *buf, size_t len);
|
||||
|
||||
/** Checks if a kernel module is loaded
|
||||
*
|
||||
* @param module the name of the module
|
||||
* @retval 0 Module is loaded.
|
||||
* @reval <>0 Module is not loaded.
|
||||
*/
|
||||
// Checks if a kernel module is loaded
|
||||
//
|
||||
// @param module the name of the module
|
||||
// @retval 0 Module is loaded.
|
||||
// @reval <>0 Module is not loaded.
|
||||
int isModuleLoaded(const char *module);
|
||||
|
||||
// Load kernel module via modprobe
|
||||
|
|
|
@ -59,7 +59,7 @@ public:
|
|||
// @return IOVA address, UINTPTR_MAX on failure
|
||||
uintptr_t memoryMap(uintptr_t virt, uintptr_t phys, size_t length);
|
||||
|
||||
/** munmap() a region which has been mapped by vfio_map_region() */
|
||||
// munmap() a region which has been mapped by vfio_map_region()
|
||||
bool memoryUnmap(uintptr_t phys, size_t length);
|
||||
|
||||
bool isIommuEnabled() const
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#define LIST_CHUNKSIZE 16
|
||||
|
||||
/** Static list initialization */
|
||||
// Static list initialization
|
||||
#define LIST_INIT_STATIC(l) \
|
||||
__attribute__((constructor(105))) static void UNIQUE(__ctor)() {\
|
||||
int ret __attribute__((unused)); \
|
||||
|
@ -50,69 +50,66 @@ typedef int (*cmp_cb_t)(const void *, const void *);
|
|||
|
||||
// The list data structure.
|
||||
struct List {
|
||||
enum State state; /**< The state of this list. */
|
||||
void **array; /**< Array of pointers to list elements */
|
||||
size_t capacity; /**< Size of list::array in elements */
|
||||
size_t length; /**< Number of elements of list::array which are in use */
|
||||
pthread_mutex_t lock; /**< A mutex to allow thread-safe accesses */
|
||||
enum State state; // The state of this list.
|
||||
void **array; // Array of pointers to list elements.
|
||||
size_t capacity; // Size of list::array in elements.
|
||||
size_t length; // Number of elements of list::array which are in use.
|
||||
pthread_mutex_t lock; // A mutex to allow thread-safe accesses.
|
||||
};
|
||||
|
||||
/** Initialize a list.
|
||||
*
|
||||
* @param l A pointer to the list data structure.
|
||||
*/
|
||||
// Initialize a list.
|
||||
//
|
||||
// @param l A pointer to the list data structure.
|
||||
int list_init(struct List *l) __attribute__ ((warn_unused_result));
|
||||
|
||||
/** Destroy a list and call destructors for all list elements
|
||||
*
|
||||
* @param free free() all list members during when calling list_destroy()
|
||||
* @param dtor A function pointer to a desctructor which will be called for every list item when the list is destroyed.
|
||||
* @param l A pointer to the list data structure.
|
||||
*/
|
||||
// Destroy a list and call destructors for all list elements
|
||||
//
|
||||
// @param free free() all list members during when calling list_destroy()
|
||||
// @param dtor A function pointer to a desctructor which will be called for every list item when the list is destroyed.
|
||||
// @param l A pointer to the list data structure.
|
||||
int list_destroy(struct List *l, dtor_cb_t dtor = nullptr, bool free = false) __attribute__ ((warn_unused_result));
|
||||
|
||||
/** Append an element to the end of the list */
|
||||
// Append an element to the end of the list.
|
||||
void list_push(struct List *l, void *p);
|
||||
|
||||
/** Clear list */
|
||||
// Clear list.
|
||||
void list_clear(struct List *l);
|
||||
|
||||
/** Remove all occurences of a list item */
|
||||
// Remove all occurences of a list item.
|
||||
void list_remove_all(struct List *l, void *p);
|
||||
|
||||
int list_remove(struct List *l, size_t idx);
|
||||
|
||||
int list_insert(struct List *l, size_t idx, void *p);
|
||||
|
||||
/** Return the first element of the list for which cmp returns zero */
|
||||
// Return the first element of the list for which cmp returns zero.
|
||||
void * list_search(struct List *l, cmp_cb_t cmp, const void *ctx);
|
||||
|
||||
/** Returns the number of occurences for which cmp returns zero when called on all list elements. */
|
||||
// Returns the number of occurences for which cmp returns zero when called on all list elements.
|
||||
int list_count(struct List *l, cmp_cb_t cmp, void *ctx);
|
||||
|
||||
/** Return 0 if list contains pointer p */
|
||||
// Return 0 if list contains pointer p.
|
||||
int list_contains(struct List *l, void *p);
|
||||
|
||||
/** Sort the list using the quicksort algorithm of libc */
|
||||
// Sort the list using the quicksort algorithm of libc.
|
||||
void list_sort(struct List *l, cmp_cb_t cmp);
|
||||
|
||||
/** Set single element in list */
|
||||
// Set single element in list.
|
||||
int list_set(struct List *l, unsigned index, void *value);
|
||||
|
||||
/** Return index in list for value.
|
||||
*
|
||||
* @retval <0 No list entry matching \p value was found.
|
||||
* @retval >=0 Entry \p value was found at returned index.
|
||||
*/
|
||||
// Return index in list for value.
|
||||
//
|
||||
// @retval <0 No list entry matching \p value was found.
|
||||
// @retval >=0 Entry \p value was found at returned index.
|
||||
ssize_t list_index(struct List *l, void *value);
|
||||
|
||||
/** Extend the list to the given length by filling new slots with given value. */
|
||||
// Extend the list to the given length by filling new slots with given value.
|
||||
void list_extend(struct List *l, size_t len, void *val);
|
||||
|
||||
/** Remove all elements for which the callback returns a non-zero return code. */
|
||||
// Remove all elements for which the callback returns a non-zero return code.
|
||||
void list_filter(struct List *l, dtor_cb_t cb);
|
||||
|
||||
/** Lookup an element from the list based on a name */
|
||||
// Lookup an element from the list based on a name.
|
||||
template<typename T>
|
||||
T * list_lookup_name(struct List *l, const std::string &name)
|
||||
{
|
||||
|
@ -124,7 +121,7 @@ T * list_lookup_name(struct List *l, const std::string &name)
|
|||
}, &name);
|
||||
}
|
||||
|
||||
/** Lookup index of list element based on name */
|
||||
// Lookup index of list element based on name.
|
||||
template<typename T>
|
||||
ssize_t list_lookup_index(struct List *l, const std::string &name)
|
||||
{
|
||||
|
|
|
@ -56,8 +56,8 @@ protected:
|
|||
|
||||
Level level;
|
||||
|
||||
std::string pattern; /**< Logging format. */
|
||||
std::string prefix; /**< Prefix each line with this string. */
|
||||
std::string pattern; // Logging format.
|
||||
std::string prefix; // Prefix each line with this string.
|
||||
|
||||
std::list<Expression> expressions;
|
||||
|
||||
|
@ -65,7 +65,7 @@ public:
|
|||
|
||||
Log(Level level = Level::info);
|
||||
|
||||
/**< Get the real usable log output width which fits into one line. */
|
||||
// Get the real usable log output width which fits into one line.
|
||||
int getWidth();
|
||||
|
||||
void parse(json_t *json);
|
||||
|
|
|
@ -16,12 +16,10 @@
|
|||
|
||||
namespace villas {
|
||||
|
||||
/**
|
||||
* @brief Basic memory block backed by an address space in the memory graph
|
||||
*
|
||||
* This is a generic representation of a chunk of memory in the system. It can
|
||||
* reside anywhere and represent different types of memory.
|
||||
*/
|
||||
// Basic memory block backed by an address space in the memory graph
|
||||
//
|
||||
// This is a generic representation of a chunk of memory in the system. It can
|
||||
// reside anywhere and represent different types of memory.
|
||||
class MemoryBlock {
|
||||
public:
|
||||
using deallocator_fn = std::function<void(MemoryBlock*)>;
|
||||
|
@ -54,17 +52,15 @@ protected:
|
|||
MemoryManager::AddressSpaceId addrSpaceId; // Identifier in memory graph
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Wrapper for a MemoryBlock to access the underlying memory directly
|
||||
*
|
||||
* The underlying memory block has to be accessible for the current process,
|
||||
* that means it has to be mapped accordingly and registered to the global
|
||||
* memory graph.
|
||||
* Furthermore, this wrapper can be owning the memory block when initialized
|
||||
* with a moved unique pointer. Otherwise, it just stores a reference to the
|
||||
* memory block and it's the users responsibility to take care that the memory
|
||||
* block is valid.
|
||||
*/
|
||||
// Wrapper for a MemoryBlock to access the underlying memory directly
|
||||
//
|
||||
// The underlying memory block has to be accessible for the current process,
|
||||
// that means it has to be mapped accordingly and registered to the global
|
||||
// memory graph.
|
||||
// Furthermore, this wrapper can be owning the memory block when initialized
|
||||
// with a moved unique pointer. Otherwise, it just stores a reference to the
|
||||
// memory block and it's the users responsibility to take care that the memory
|
||||
// block is valid.
|
||||
template<typename T>
|
||||
class MemoryAccessor {
|
||||
public:
|
||||
|
@ -120,14 +116,12 @@ private:
|
|||
std::unique_ptr<MemoryBlock, MemoryBlock::deallocator_fn> memoryBlock;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Base memory allocator
|
||||
*
|
||||
* Note the usage of CRTP idiom here to access methods of derived allocators.
|
||||
* The concept is explained here at [1].
|
||||
*
|
||||
* [1] https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
|
||||
*/
|
||||
// Base memory allocator
|
||||
//
|
||||
// Note the usage of CRTP idiom here to access methods of derived allocators.
|
||||
// The concept is explained here at [1].
|
||||
//
|
||||
// [1] https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
|
||||
template<typename DerivedAllocator>
|
||||
class BaseAllocator {
|
||||
public:
|
||||
|
@ -157,7 +151,9 @@ public:
|
|||
derivedAlloc = nullptr;
|
||||
}
|
||||
|
||||
virtual std::unique_ptr<MemoryBlock, MemoryBlock::deallocator_fn>
|
||||
virtual
|
||||
std::unique_ptr<MemoryBlock, MemoryBlock::deallocator_fn>
|
||||
|
||||
allocateBlock(size_t size) = 0;
|
||||
|
||||
template<typename T>
|
||||
|
@ -223,15 +219,13 @@ private:
|
|||
DerivedAllocator* derivedAlloc;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Linear memory allocator
|
||||
*
|
||||
* This is the simplest kind of allocator. The idea is to keep a pointer at the
|
||||
* first memory address of your memory chunk and move it every time an
|
||||
* allocation is done. Due to its simplicity, this allocator doesn't allow
|
||||
* specific positions of memory to be freed. Usually, all memory is freed
|
||||
* together.
|
||||
*/
|
||||
// Linear memory allocator
|
||||
//
|
||||
// This is the simplest kind of allocator. The idea is to keep a pointer at the
|
||||
// first memory address of your memory chunk and move it every time an
|
||||
// allocation is done. Due to its simplicity, this allocator doesn't allow
|
||||
// specific positions of memory to be freed. Usually, all memory is freed
|
||||
// together.
|
||||
class LinearAllocator : public BaseAllocator<LinearAllocator> {
|
||||
public:
|
||||
LinearAllocator(MemoryManager::AddressSpaceId memoryAddrSpaceId,
|
||||
|
@ -275,12 +269,10 @@ private:
|
|||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Wrapper around mmap() to create villas memory blocks
|
||||
*
|
||||
* This class simply wraps around mmap() and munmap() to allocate memory in the
|
||||
* host memory via the OS.
|
||||
*/
|
||||
// Wrapper around mmap() to create villas memory blocks
|
||||
//
|
||||
// This class simply wraps around mmap() and munmap() to allocate memory in the
|
||||
// host memory via the OS.
|
||||
class HostRam {
|
||||
public:
|
||||
class HostRamAllocator : public BaseAllocator<HostRamAllocator> {
|
||||
|
@ -313,7 +305,8 @@ public:
|
|||
public:
|
||||
HostDmaRamAllocator(int num);
|
||||
|
||||
virtual ~HostDmaRamAllocator();
|
||||
virtual
|
||||
~HostDmaRamAllocator();
|
||||
|
||||
std::string getName() const
|
||||
{
|
||||
|
|
|
@ -19,22 +19,18 @@
|
|||
|
||||
namespace villas {
|
||||
|
||||
/**
|
||||
* @brief Translation between a local (master) to a foreign (slave) address space
|
||||
*
|
||||
* Memory translations can be chained together using the `+=` operator which is
|
||||
* used internally by the MemoryManager to compute a translation through
|
||||
* multiple hops (memory mappings).
|
||||
*/
|
||||
// Translation between a local (master) to a foreign (slave) address space
|
||||
//
|
||||
// Memory translations can be chained together using the `+=` operator which is
|
||||
// used internally by the MemoryManager to compute a translation through
|
||||
// multiple hops (memory mappings).
|
||||
class MemoryTranslation {
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief MemoryTranslation
|
||||
* @param src Base address of local address space
|
||||
* @param dst Base address of foreign address space
|
||||
* @param size Size of "memory window"
|
||||
*/
|
||||
// MemoryTranslation
|
||||
// @param src Base address of local address space
|
||||
// @param dst Base address of foreign address space
|
||||
// @param size Size of "memory window"
|
||||
MemoryTranslation(uintptr_t src, uintptr_t dst, size_t size) :
|
||||
src(src),
|
||||
dst(dst),
|
||||
|
@ -70,15 +66,13 @@ private:
|
|||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Global memory manager to resolve addresses across address spaces
|
||||
*
|
||||
* Every entity in the system has to register its (master) address space and
|
||||
* create mappings to other (slave) address spaces that it can access. A
|
||||
* directed graph is then constructed which allows to traverse addresses spaces
|
||||
* through multiple mappings and resolve addresses through this "tunnel" of
|
||||
* memory mappings.
|
||||
*/
|
||||
// Global memory manager to resolve addresses across address spaces
|
||||
//
|
||||
// Every entity in the system has to register its (master) address space and
|
||||
// create mappings to other (slave) address spaces that it can access. A
|
||||
// directed graph is then constructed which allows to traverse addresses spaces
|
||||
// through multiple mappings and resolve addresses through this "tunnel" of
|
||||
// memory mappings.
|
||||
class MemoryManager {
|
||||
private:
|
||||
// This is a singleton, so private constructor ...
|
||||
|
@ -95,23 +89,21 @@ private:
|
|||
MemoryManager(const MemoryManager&) = delete;
|
||||
MemoryManager &operator=(const MemoryManager&) = delete;
|
||||
|
||||
/**
|
||||
* @brief Custom edge in memory graph representing a memory mapping
|
||||
*
|
||||
* A memory mapping maps from one address space into another and can only be
|
||||
* traversed in the forward direction which reflects the nature of real
|
||||
* memory mappings.
|
||||
*
|
||||
* Implementation Notes:
|
||||
* The member #src is the address in the "from" address space, where the
|
||||
* destination address space is mapped. The member #dest is the address in
|
||||
* the destination address space, where the mapping points to. Often, #dest
|
||||
* will be zero for mappings to hardware, but consider the example when
|
||||
* mapping FPGA to application memory:
|
||||
* The application allocates a block 1kB at address 0x843001000 in its
|
||||
* address space. The mapping would then have a #dest address of 0x843001000
|
||||
* and a #size of 1024.
|
||||
*/
|
||||
// Custom edge in memory graph representing a memory mapping
|
||||
//
|
||||
// A memory mapping maps from one address space into another and can only be
|
||||
// traversed in the forward direction which reflects the nature of real
|
||||
// memory mappings.
|
||||
//
|
||||
// Implementation Notes:
|
||||
// The member #src is the address in the "from" address space, where the
|
||||
// destination address space is mapped. The member #dest is the address in
|
||||
// the destination address space, where the mapping points to. Often, #dest
|
||||
// will be zero for mappings to hardware, but consider the example when
|
||||
// mapping FPGA to application memory:
|
||||
// The application allocates a block 1kB at address 0x843001000 in its
|
||||
// address space. The mapping would then have a #dest address of 0x843001000
|
||||
// and a #size of 1024.
|
||||
class Mapping : public graph::Edge {
|
||||
public:
|
||||
std::string name; // Human-readable name
|
||||
|
@ -133,13 +125,11 @@ private:
|
|||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Custom vertex in memory graph representing an address space
|
||||
*
|
||||
* Since most information in the memory graph is stored in the edges (memory
|
||||
* mappings), this is just a small extension to the default vertex. It only
|
||||
* associates an additional string #name for human-readability.
|
||||
*/
|
||||
// Custom vertex in memory graph representing an address space
|
||||
//
|
||||
// Since most information in the memory graph is stored in the edges (memory
|
||||
// mappings), this is just a small extension to the default vertex. It only
|
||||
// associates an additional string #name for human-readability.
|
||||
class AddressSpace : public graph::Vertex {
|
||||
public:
|
||||
std::string name; // Human-readable name
|
||||
|
@ -162,8 +152,8 @@ public:
|
|||
struct InvalidTranslation : public std::exception {};
|
||||
|
||||
// Get singleton instance
|
||||
static MemoryManager&
|
||||
get();
|
||||
static
|
||||
MemoryManager& get();
|
||||
|
||||
MemoryGraph & getGraph()
|
||||
{
|
||||
|
|
|
@ -161,7 +161,7 @@ public:
|
|||
return logger;
|
||||
}
|
||||
|
||||
/** Custom formatter for spdlog */
|
||||
// Custom formatter for spdlog
|
||||
template<typename OStream>
|
||||
friend OStream &operator<<(OStream &os, const class Plugin &p)
|
||||
{
|
||||
|
|
|
@ -28,9 +28,9 @@ public:
|
|||
};
|
||||
|
||||
protected:
|
||||
int _width; /**< The real width of this column. Calculated by Table::resize() */
|
||||
int _width; // The real width of this column. Calculated by Table::resize().
|
||||
|
||||
int width; /**< Width of the column. */
|
||||
int width; // Width of the column.
|
||||
|
||||
public:
|
||||
TableColumn(int w, enum Alignment a, const std::string &t, const std::string &f, const std::string &u = "") :
|
||||
|
@ -42,9 +42,9 @@ public:
|
|||
align(a)
|
||||
{ }
|
||||
|
||||
std::string title; /**< The title as shown in the table header. */
|
||||
std::string format; /**< The format which is used to print the table rows. */
|
||||
std::string unit; /**< An optional unit which will be shown in the table header. */
|
||||
std::string title; // The title as shown in the table header.
|
||||
std::string format; // The format which is used to print the table rows.
|
||||
std::string unit; // An optional unit which will be shown in the table header.
|
||||
|
||||
enum Alignment align;
|
||||
|
||||
|
@ -72,10 +72,10 @@ public:
|
|||
logger(log)
|
||||
{ }
|
||||
|
||||
/** Print a table header consisting of \p n columns. */
|
||||
// Print a table header consisting of \p n columns.
|
||||
void header();
|
||||
|
||||
/** Print table rows. */
|
||||
// Print table rows.
|
||||
void row(int count, ...);
|
||||
|
||||
int getWidth() const
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
#include <ctime>
|
||||
|
||||
/** We can choose between two periodic task implementations */
|
||||
// We can choose between two periodic task implementations
|
||||
//#define PERIODIC_TASK_IMPL NANOSLEEP
|
||||
#define TIMERFD 1
|
||||
#define CLOCK_NANOSLEEP 2
|
||||
|
@ -49,7 +49,7 @@ struct Task {
|
|||
struct Tsc tsc; // Initialized by tsc_init().
|
||||
#endif
|
||||
|
||||
/** Create a new task with the given rate. */
|
||||
// Create a new task with the given rate.
|
||||
Task(int clock = CLOCK_REALTIME);
|
||||
|
||||
~Task();
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace villas {
|
|||
class Terminal {
|
||||
|
||||
protected:
|
||||
struct winsize window; /**< Size of the terminal window. */
|
||||
struct winsize window; // Size of the terminal window.
|
||||
|
||||
bool isTty;
|
||||
|
||||
|
@ -27,10 +27,12 @@ protected:
|
|||
public:
|
||||
Terminal();
|
||||
|
||||
/** Signal handler for TIOCGWINSZ */
|
||||
static void resize(int signal, siginfo_t *sinfo, void *ctx);
|
||||
// Signal handler for TIOCGWINSZ
|
||||
static
|
||||
void resize(int signal, siginfo_t *sinfo, void *ctx);
|
||||
|
||||
static int getCols()
|
||||
static
|
||||
int getCols()
|
||||
{
|
||||
if (!current)
|
||||
current = new Terminal();
|
||||
|
@ -38,7 +40,8 @@ public:
|
|||
return current->window.ws_col;
|
||||
}
|
||||
|
||||
static int getRows()
|
||||
static
|
||||
int getRows()
|
||||
{
|
||||
if (!current)
|
||||
current = new Terminal();
|
||||
|
|
|
@ -13,23 +13,23 @@
|
|||
|
||||
#include <ctime>
|
||||
|
||||
/** Compare two timestamps. Return zero if they are equal */
|
||||
// Compare two timestamps. Return zero if they are equal.
|
||||
ssize_t time_cmp(const struct timespec *a, const struct timespec *b);
|
||||
|
||||
/** Get delta between two timespec structs */
|
||||
// Get delta between two timespec structs.
|
||||
struct timespec time_diff(const struct timespec *start, const struct timespec *end);
|
||||
|
||||
/** Get sum of two timespec structs */
|
||||
// Get sum of two timespec structs.
|
||||
struct timespec time_add(const struct timespec *start, const struct timespec *end);
|
||||
|
||||
/** Return current time as a struct timespec. */
|
||||
// Return current time as a struct timespec.
|
||||
struct timespec time_now();
|
||||
|
||||
/** Return the diffrence off two timestamps as double value in seconds. */
|
||||
// Return the diffrence off two timestamps as double value in seconds.
|
||||
double time_delta(const struct timespec *start, const struct timespec *end);
|
||||
|
||||
/** Convert timespec to double value representing seconds */
|
||||
// Convert timespec to double value representing seconds.
|
||||
double time_to_double(const struct timespec *ts);
|
||||
|
||||
/** Convert double containing seconds after 1970 to timespec. */
|
||||
// Convert double containing seconds after 1970 to timespec.
|
||||
struct timespec time_from_double(double secs);
|
||||
|
|
|
@ -26,32 +26,42 @@ protected:
|
|||
|
||||
std::string name;
|
||||
|
||||
static Tool *current_tool;
|
||||
static
|
||||
Tool *current_tool;
|
||||
|
||||
static void staticHandler(int signal, siginfo_t *sinfo, void *ctx);
|
||||
static
|
||||
void staticHandler(int signal, siginfo_t *sinfo, void *ctx);
|
||||
|
||||
virtual void handler(int, siginfo_t *, void *)
|
||||
virtual
|
||||
void handler(int, siginfo_t *, void *)
|
||||
{ }
|
||||
|
||||
std::list<int> handlerSignals;
|
||||
|
||||
static void printCopyright();
|
||||
static void printVersion();
|
||||
static
|
||||
void printCopyright();
|
||||
|
||||
static
|
||||
void printVersion();
|
||||
|
||||
public:
|
||||
Tool(int ac, char *av[], const std::string &name, const std::list<int> &sigs = { });
|
||||
|
||||
virtual int main()
|
||||
virtual
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual void usage()
|
||||
virtual
|
||||
void usage()
|
||||
{ }
|
||||
|
||||
virtual void parse()
|
||||
virtual
|
||||
void parse()
|
||||
{ }
|
||||
|
||||
virtual
|
||||
int run();
|
||||
};
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ struct Tsc {
|
|||
bool is_invariant;
|
||||
};
|
||||
|
||||
__attribute__((unused))
|
||||
static uint64_t tsc_now(struct Tsc *t)
|
||||
__attribute__((unused)) static
|
||||
uint64_t tsc_now(struct Tsc *t)
|
||||
{
|
||||
uint32_t tsc_aux;
|
||||
return t->rdtscp_supported
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#define UNLIKELY(x) (x)
|
||||
#endif
|
||||
|
||||
/** Check assertion and exit if failed. */
|
||||
// Check assertion and exit if failed.
|
||||
#ifndef assert
|
||||
#define assert(exp) do { \
|
||||
if (!EXPECT(exp, 0)) \
|
||||
|
@ -121,80 +121,77 @@ assertExcept(bool condition, const T &exception)
|
|||
throw exception;
|
||||
}
|
||||
|
||||
/** Register a exit callback for program termination: SIGINT, SIGKILL & SIGALRM. */
|
||||
// Register a exit callback for program termination: SIGINT, SIGKILL & SIGALRM.
|
||||
int signalsInit(void (*cb)(int signal, siginfo_t *sinfo, void *ctx), std::list<int> cbSignals = {}, std::list<int> ignoreSignals = { SIGCHLD }) __attribute__ ((warn_unused_result));
|
||||
|
||||
/** Fill buffer with random data */
|
||||
// Fill buffer with random data.
|
||||
ssize_t readRandom(char *buf, size_t len);
|
||||
|
||||
/** Remove ANSI control sequences for colored output. */
|
||||
// Remove ANSI control sequences for colored output.
|
||||
char * decolor(char *str);
|
||||
|
||||
/** Normal random variate generator using the Box-Muller method
|
||||
*
|
||||
* @param m Mean
|
||||
* @param s Standard deviation
|
||||
* @return Normal variate random variable (Gaussian)
|
||||
*/
|
||||
// Normal random variate generator using the Box-Muller method
|
||||
//
|
||||
// @param m Mean
|
||||
// @param s Standard deviation
|
||||
// @return Normal variate random variable (Gaussian)
|
||||
double boxMuller(float m, float s);
|
||||
|
||||
/** Double precission uniform random variable */
|
||||
// Double precission uniform random variable
|
||||
double randf();
|
||||
|
||||
/** Concat formatted string to an existing string.
|
||||
*
|
||||
* This function uses realloc() to resize the destination.
|
||||
* Please make sure to only on dynamic allocated destionations!!!
|
||||
*
|
||||
* @param dest A pointer to a malloc() allocated memory region
|
||||
* @param fmt A format string like for printf()
|
||||
* @param ... Optional parameters like for printf()
|
||||
* @retval The the new value of the dest buffer.
|
||||
*/
|
||||
// Concat formatted string to an existing string.
|
||||
//
|
||||
// This function uses realloc() to resize the destination.
|
||||
// Please make sure to only on dynamic allocated destionations!!!
|
||||
//
|
||||
// @param dest A pointer to a malloc() allocated memory region
|
||||
// @param fmt A format string like for printf()
|
||||
// @param ... Optional parameters like for printf()
|
||||
// @retval The the new value of the dest buffer.
|
||||
char * strcatf(char **dest, const char *fmt, ...)
|
||||
__attribute__ ((format(printf, 2, 3)));
|
||||
|
||||
/** Variadic version of strcatf() */
|
||||
// Variadic version of strcatf()
|
||||
char * vstrcatf(char **dest, const char *fmt, va_list va)
|
||||
__attribute__ ((format(printf, 2, 0)));
|
||||
|
||||
char * strf(const char *fmt, ...);
|
||||
char * vstrf(const char *fmt, va_list va);
|
||||
|
||||
/** Allocate and copy memory. */
|
||||
// Allocate and copy memory.
|
||||
void * memdup(const void *src, size_t bytes);
|
||||
|
||||
/** Call quit() in the main thread. */
|
||||
// Call quit() in the main thread.
|
||||
void die();
|
||||
|
||||
/** Get log2 of long long integers */
|
||||
// Get log2 of long long integers
|
||||
int log2i(long long x);
|
||||
|
||||
/** Send signal \p sig to main thread. */
|
||||
// Send signal \p sig to main thread.
|
||||
void killme(int sig);
|
||||
|
||||
pid_t spawn(const char *name, char *const argv[]);
|
||||
|
||||
/** Determines the string length as printed on the screen (ignores escable sequences). */
|
||||
// Determines the string length as printed on the screen (ignores escable sequences).
|
||||
size_t strlenp(const char *str);
|
||||
|
||||
/** Calculate SHA1 hash of complete file \p f and place it into \p sha1.
|
||||
*
|
||||
* @param sha1[out] Must be SHA_DIGEST_LENGTH (20) in size.
|
||||
* @retval 0 Everything was okay.
|
||||
*/
|
||||
// Calculate SHA1 hash of complete file \p f and place it into \p sha1.
|
||||
//
|
||||
// @param sha1[out] Must be SHA_DIGEST_LENGTH (20) in size.
|
||||
// @retval 0 Everything was okay.
|
||||
int sha1sum(FILE *f, unsigned char *sha1);
|
||||
|
||||
/** Check if process is running inside a Docker container */
|
||||
// Check if process is running inside a Docker container.
|
||||
bool isDocker();
|
||||
|
||||
/** Check if process is running inside a Kubernetes container */
|
||||
// Check if process is running inside a Kubernetes container.
|
||||
bool isKubernetes();
|
||||
|
||||
/** Check if process is running inside a containerized environment */
|
||||
// Check if process is running inside a containerized environment.
|
||||
bool isContainer();
|
||||
|
||||
/** Check if the process is running in a privileged environment (has SYS_ADMIN capability). */
|
||||
// Check if the process is running in a privileged environment (has SYS_ADMIN capability).
|
||||
bool isPrivileged();
|
||||
|
||||
namespace base64 {
|
||||
|
|
|
@ -16,16 +16,16 @@
|
|||
namespace villas {
|
||||
namespace uuid {
|
||||
|
||||
/** Generate an UUID by MD5 hashing the provided string */
|
||||
// Generate an UUID by MD5 hashing the provided string
|
||||
int generateFromString(uuid_t out, const std::string &data, const std::string &ns = "");
|
||||
|
||||
/** Generate an UUID by MD5 hashing the provided string */
|
||||
// Generate an UUID by MD5 hashing the provided string
|
||||
int generateFromString(uuid_t out, const std::string &data, const uuid_t ns);
|
||||
|
||||
/** Generate an UUID by MD5 hashing the serialized representation of the provided JSON object */
|
||||
// Generate an UUID by MD5 hashing the serialized representation of the provided JSON object
|
||||
void generateFromJson(uuid_t out, json_t *json, const std::string &ns = "");
|
||||
|
||||
/** Generate an UUID by MD5 hashing the serialized representation of the provided JSON object */
|
||||
// Generate an UUID by MD5 hashing the serialized representation of the provided JSON object
|
||||
int generateFromJson(uuid_t out, json_t *json, const uuid_t ns);
|
||||
|
||||
} // namespace uuid
|
||||
|
|
|
@ -18,35 +18,48 @@ class Version {
|
|||
protected:
|
||||
int components[3];
|
||||
|
||||
static int cmp(const Version &lhs, const Version &rhs);
|
||||
static
|
||||
int cmp(const Version &lhs, const Version &rhs);
|
||||
|
||||
public:
|
||||
/** Parse a dotted version string. */
|
||||
// Parse a dotted version string.
|
||||
Version(const std::string &s);
|
||||
|
||||
Version(int maj, int min = 0, int pat = 0);
|
||||
|
||||
inline bool operator==(const Version &rhs) {
|
||||
inline
|
||||
bool operator==(const Version &rhs)
|
||||
{
|
||||
return cmp(*this, rhs) == 0;
|
||||
}
|
||||
|
||||
inline bool operator!=(const Version &rhs) {
|
||||
inline
|
||||
bool operator!=(const Version &rhs)
|
||||
{
|
||||
return cmp(*this, rhs) != 0;
|
||||
}
|
||||
|
||||
inline bool operator< (const Version &rhs) {
|
||||
inline
|
||||
bool operator< (const Version &rhs)
|
||||
{
|
||||
return cmp(*this, rhs) < 0;
|
||||
}
|
||||
|
||||
inline bool operator> (const Version &rhs) {
|
||||
inline
|
||||
bool operator> (const Version &rhs)
|
||||
{
|
||||
return cmp(*this, rhs) > 0;
|
||||
}
|
||||
|
||||
inline bool operator<=(const Version &rhs) {
|
||||
inline
|
||||
bool operator<=(const Version &rhs)
|
||||
{
|
||||
return cmp(*this, rhs) <= 0;
|
||||
}
|
||||
|
||||
inline bool operator>=(const Version &rhs) {
|
||||
inline
|
||||
bool operator>=(const Version &rhs)
|
||||
{
|
||||
return cmp(*this, rhs) >= 0;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/** Common code.
|
||||
*
|
||||
* @author Steffen Vogel <post@steffenvogel.de>
|
||||
|
|
|
@ -30,7 +30,8 @@ size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags)
|
|||
return len;
|
||||
}
|
||||
|
||||
static size_t json_loadfd_callback(void *buffer, size_t buflen, void *data)
|
||||
static
|
||||
size_t json_loadfd_callback(void *buffer, size_t buflen, void *data)
|
||||
{
|
||||
int *fd = (int *) data;
|
||||
|
||||
|
@ -43,7 +44,8 @@ json_t *json_loadfd(int input, size_t flags, json_error_t *error)
|
|||
}
|
||||
|
||||
|
||||
static int json_dumpfd_callback(const char *buffer, size_t size, void *data)
|
||||
static
|
||||
int json_dumpfd_callback(const char *buffer, size_t size, void *data)
|
||||
{
|
||||
#ifdef HAVE_UNISTD_H
|
||||
int *dest = (int *)data;
|
||||
|
|
|
@ -20,18 +20,18 @@
|
|||
|
||||
using namespace villas;
|
||||
|
||||
/** The global log instance */
|
||||
// The global log instance
|
||||
Log villas::logging;
|
||||
|
||||
static std::map<spdlog::level::level_enum, std::string> levelNames = {
|
||||
{ spdlog::level::trace, "trc" },
|
||||
{ spdlog::level::debug, "dbg" },
|
||||
{ spdlog::level::info, "info" },
|
||||
{ spdlog::level::warn, "warn" },
|
||||
{ spdlog::level::err, "err" },
|
||||
{ spdlog::level::critical, "crit" },
|
||||
{ spdlog::level::off, "off" }
|
||||
};
|
||||
{ spdlog::level::trace, "trc" },
|
||||
{ spdlog::level::debug, "dbg" },
|
||||
{ spdlog::level::info, "info" },
|
||||
{ spdlog::level::warn, "warn" },
|
||||
{ spdlog::level::err, "err" },
|
||||
{ spdlog::level::critical, "crit" },
|
||||
{ spdlog::level::off, "off" }
|
||||
};
|
||||
|
||||
class CustomLevelFlag : public spdlog::custom_flag_formatter {
|
||||
|
||||
|
|
|
@ -14,22 +14,21 @@ int tsc_init(struct Tsc *t)
|
|||
{
|
||||
uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
|
||||
|
||||
/** Check if TSC is supported */
|
||||
// Check if TSC is supported
|
||||
__get_cpuid(0x1, &eax, &ebx, &ecx, &edx);
|
||||
if (!(edx & bit_TSC))
|
||||
return -2;
|
||||
|
||||
/** Check if RDTSCP instruction is supported */
|
||||
// Check if RDTSCP instruction is supported
|
||||
__get_cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
|
||||
t->rdtscp_supported = edx & bit_RDTSCP;
|
||||
|
||||
/** Check if TSC is invariant */
|
||||
// Check if TSC is invariant
|
||||
__get_cpuid(0x80000007, &eax, &ebx, &ecx, &edx);
|
||||
t->is_invariant = edx & bit_TSC_INVARIANT;
|
||||
|
||||
/** Intel SDM Vol 3, Section 18.7.3:
|
||||
* Nominal TSC frequency = CPUID.15H.ECX[31:0] * CPUID.15H.EBX[31:0] ) ÷ CPUID.15H.EAX[31:0]
|
||||
*/
|
||||
// Intel SDM Vol 3, Section 18.7.3:
|
||||
// Nominal TSC frequency = CPUID.15H.ECX[31:0] * CPUID.15H.EBX[31:0] ) ÷ CPUID.15H.EAX[31:0]
|
||||
__get_cpuid(0x15, &eax, &ebx, &ecx, &edx);
|
||||
|
||||
if (ecx != 0)
|
||||
|
|
|
@ -59,7 +59,8 @@ struct content {
|
|||
int destroyed;
|
||||
};
|
||||
|
||||
static int dtor(void *ptr)
|
||||
static
|
||||
int dtor(void *ptr)
|
||||
{
|
||||
struct content *elm = (struct content *) ptr;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue