Commit 44a6271c authored by Jens Korinth's avatar Jens Korinth

Fix most whitespace errors

parent 1914aec8
......@@ -193,7 +193,7 @@ struct Tapasco {
tapasco_device_release_job_id(dev_ctx, j_id);
return res;
}
/**
* Launches a job on the device and returns a future to the result.
* @param f_id Kernel ID.
......@@ -206,7 +206,7 @@ struct Tapasco {
{
return async(std::launch::async, [=, &ret]{ return launch(f_id, ret, args...); });
}
/**
* Launches a job on the device without return value.
* @param f_id Kernel ID.
......@@ -428,7 +428,7 @@ private:
tapasco_device_free(dev_ctx, h, TAPASCO_DEVICE_ALLOC_FLAGS_NONE);
return TAPASCO_SUCCESS;
}
/** Gets a single const pointer argument (dealloc only). **/
template<typename T>
tapasco_res_t get_args(tapasco_job_id_t const j_id, uint32_t const arg_idx, T const* t) const noexcept
......@@ -474,7 +474,7 @@ private:
return get_args(j_id, arg_idx + 1, args...);
}
#endif
bool _ok { false };
tapasco_ctx_t* ctx { nullptr };
tapasco_dev_ctx_t* dev_ctx { nullptr };
......
......@@ -114,7 +114,7 @@ void tapasco_functions_setup_system(tapasco_dev_ctx_t *dev_ctx, tapasco_function
++funcs;
++slot_id;
}
}
inline static int reserve_func(tapasco_func_t *f, tapasco_func_id_t const f_id) {
......
......@@ -200,7 +200,7 @@ int main(int argc, char *argv[])
printf("Average throughput: %10.1f logs/s\n", logs / (time_diff / 1000000.0));
printf("Thread throughput: %10.1f logs/s\n",
logs / (time_diff / 1000000.0) / (double)thrdcnt);
free(_rnd_data);
printf("Finished the test.\n");
tapasco_logging_exit();
......
......@@ -56,7 +56,7 @@ START_TEST (tapasco_functions_check_counts)
fail_if (unavail >= 0);
tapasco_functions_release(funcs, slot_id);
}
tapasco_functions_deinit(funcs);
}
END_TEST
......
......@@ -98,7 +98,7 @@ void gq_enqueue(struct gq_t *q, void *v)
atomic_compare_exchange_strong(&q->tail, &tail, new);
}
}
}
TAGGED_PTR(n) = { .ptr = nd, .tag = tail.tag + 1 };
atomic_compare_exchange_strong(&q->tail, &tail, n);
......@@ -131,7 +131,7 @@ void *gq_dequeue(struct gq_t *q)
TAGGED_PTR(new) = { .ptr = next.ptr, head.tag + 1 };
if (atomic_compare_exchange_strong(&q->head, &head, new))
break;
}
}
}
......
......@@ -151,7 +151,7 @@ int main(int argc, char **argv)
std::vector<ff_node *> f;
for (int i = 0; i < sysconf(_SC_NPROCESSORS_CONF); ++i)
f.push_back(new Worker);
Emitter e;
Collector c;
ff_farm<> farm(f, &e, &c);
......
......@@ -81,17 +81,17 @@ static void *runTest(void *p)
// allocate mem on device and copy array part
tapasco_handle_t h = tapasco_device_alloc(dev, SZ * sizeof(int), 0);
check(h != 0);
// get a job id and set argument to handle
tapasco_job_id_t j_id = tapasco_device_acquire_job_id(dev, 11,
TAPASCO_ACQUIRE_JOB_ID_BLOCKING);
printf("run %ld: j_id = %d\n", run, j_id);
check(j_id > 0);
check_tapasco(tapasco_device_job_set_arg(dev, j_id, 0, sizeof(h), &h));
// shoot me to the moon!
check_tapasco(tapasco_device_job_launch(dev, j_id, TAPASCO_JOB_LAUNCH_BLOCKING));
// get the result
check_tapasco(tapasco_device_copy_from(dev, h, &arr[SZ * run],
SZ * sizeof(int), TAPASCO_COPY_BLOCKING));
......
......@@ -140,7 +140,7 @@ int main(int argc, char **argv)
std::vector<ff_node *> f;
for (int i = 0; i < sysconf(_SC_NPROCESSORS_CONF); ++i)
f.push_back(new Worker);
Emitter e;
Collector c;
ff_farm<> farm(f, &e, &c);
......
......@@ -156,7 +156,7 @@ int main(int argc, char **argv)
arr = (int *)malloc(SZ * RUNS * sizeof(int));
check(arr != NULL);
init_array(arr, SZ * RUNS);
golden_arr = (int *)malloc(SZ * RUNS * sizeof(int));
check(golden_arr != NULL);
init_array(golden_arr, SZ * RUNS);
......@@ -165,7 +165,7 @@ int main(int argc, char **argv)
std::vector<ff_node *> f;
for (int i = 0; i < sysconf(_SC_NPROCESSORS_CONF); ++i)
f.push_back(new Worker);
Emitter e;
Collector c;
ff_farm<> farm(f, &e, &c);
......
......@@ -81,23 +81,23 @@ static void *runTest(void *p) {
// golden run
int golden = warraw(&golden_arr[SZ * run]);
printf("Golden output for run %ld: %d\n", run, golden);
// allocate mem on device and copy array part
tapasco_handle_t h = tapasco_device_alloc(dev, SZ * sizeof(int), 0);
check(h != 0);
check_tapasco(tapasco_device_copy_to(dev, &arr[SZ * run], h,
SZ * sizeof(int), TAPASCO_COPY_BLOCKING));
// get a job id and set argument to handle
tapasco_job_id_t j_id = tapasco_device_acquire_job_id(dev, 12,
TAPASCO_ACQUIRE_JOB_ID_BLOCKING);
printf("run %ld: j_id = %d\n", run, j_id);
check(j_id > 0);
check_tapasco(tapasco_device_job_set_arg(dev, j_id, 0, sizeof(h), &h));
// shoot me to the moon!
check_tapasco(tapasco_device_job_launch(dev, j_id, TAPASCO_JOB_LAUNCH_BLOCKING));
// get the result
int32_t r = 0;
check_tapasco(tapasco_device_job_get_return(dev, j_id, sizeof(r), &r));
......@@ -127,7 +127,7 @@ int main(int argc, char **argv) {
arr = (int *)malloc(SZ * RUNS * sizeof(int));
check(arr != NULL);
init_array(arr, SZ * RUNS);
golden_arr = (int *)malloc(SZ * RUNS * sizeof(int));
check(golden_arr != NULL);
init_array(golden_arr, SZ * RUNS);
......
......@@ -114,7 +114,7 @@ int main(int argc, char *argv[])
long thrdcnt {sysconf(_SC_NPROCESSORS_CONF)};
int c {2};
int const mode {argc > 2 && argv[1][0] == 'f'};
if (argc < 3) {
cerr << "Usage: sudoku_mt <cpu|fgpa> [<number of threads>] <filename1> <filename2> ..." << endl;
exit(EXIT_FAILURE);
......
......@@ -30,7 +30,7 @@ int main(int argc, char **argv)
int data[SZ], i, ret = 0, s = 0;
for (i = 0; i < SZ; ++i)
data[i] = i + 1;
s = warraw(data);
for (i = 0; i < SZ; ++i) {
......
......@@ -221,7 +221,7 @@ static int runtest(long const which)
for (long t = 0; t < thrdcnt; ++t)
pthread_join(threads[t], NULL);
platform_deinit();
return errors + terrors;
}
......
......@@ -104,7 +104,7 @@ int main(int argc, char **argv)
cfg.slot_id = strtoul(argv[1], NULL, 0);
else
cfg.slot_id = -1;
if (argc > 2)
cfg.delay = strtoul(argv[2], NULL, 0);
else
......@@ -116,7 +116,7 @@ int main(int argc, char **argv)
cfg.iterations = 1;
cfg.mt = cfg.all_slots && argc > 4;
printf("Starting: all_slots = %ld, slot_id = %ld, delay = %ld, iterations = %ld\n",
cfg.all_slots, cfg.slot_id, cfg.delay, cfg.iterations);
......
......@@ -144,9 +144,9 @@ int main(int argc, char **argv)
pthread_create(&threads[t], NULL, stress, (void *)runs);
for (t = 0; t < thread_count; ++t)
pthread_join(threads[t], NULL);
platform_deinit();
if (! stop)
printf("Test successful.\n");
else
......
......@@ -19,20 +19,20 @@
#include "buddy_allocator.hpp"
buddy_allocator::buddy_allocator(uint32_t _address, uint_fast32_t _size, uint_fast32_t _min_order, uint_fast32_t _max_order){
log(logDEBUG2) << "Calculate init values for buddy_tree";
min_order = _min_order;
max_order = _max_order;
uint32_t address = calc_Address(_address);
uint_fast32_t size = calc_Size(_size, address - _address);
log(logDEBUG2) << "Set init values for buddy_tree (size: " << size << ") vs. " << calc_Size(_size, address - _address);
bt = new buddy_tree(address,size);
//bt->print_Tree(bt->get_Root());
if(!check_Tree(bt->get_Root())) {
build_Tree(bt->get_Root());
error = 0;
......@@ -40,13 +40,13 @@ buddy_allocator::buddy_allocator(uint32_t _address, uint_fast32_t _size, uint_fa
log(logWARNING) << "Tree could not be built completely";
error = -EINVAL;
}
//bt->print_Tree(bt->get_Root());
}
buddy_allocator::~buddy_allocator() {
log(logDEBUG2) << "Delete buddy_tree";
delete(bt);
}
......@@ -56,41 +56,41 @@ void buddy_allocator::print_Tree(void) {
}
uint_fast32_t buddy_allocator::dealloc_Mem(uint32_t address) {
if(error)
return -EINVAL;
node_t *n = find_Node(address);
if(!n) {
log(logWARNING) << "Node for address " << hex << address << " not found" << dec;
return -EINVAL;
}
//bt->print_Node(n);
node_t *sibling = find_Sibling(n);
if(bt->dealloc_Leaf(n)) {
log(logWARNING) << "Failure in deallocation";
return -EINVAL;
}
while(sibling && sibling->usage == nodeFree && n->size < (uint_fast32_t)(1 << max_order)) {
log(logDEBUG2) << "can merge nodes";
node_t *parent = n->parent;
if(bt->merge_Node(parent)) {
log(logWARNING) << "Merging gone wrong";
}
n = parent;
sibling = find_Sibling(n);
}
return 0;
}
node_t * buddy_allocator::find_Sibling(node_t * n) {
if(n->parent) {
if(n->parent->l_child == n)
return n->parent->r_child;
......@@ -104,84 +104,84 @@ node_t * buddy_allocator::find_Sibling(node_t * n) {
node_t * buddy_allocator::find_Node(uint32_t address) {
node_t *n = bt->get_Root();
log(logDEBUG2) << "Search node with matching address " << hex << address << dec;
//bt->print_Node(n);
while(n != NULL && (n->usage != nodeAlloc || n->address != address)) {
n = bt->search_Node(n, address);
//bt->print_Node(n);
}
return n;
}
uint32_t buddy_allocator::alloc_Mem(uint_fast32_t _size) {
if(error)
return 0;
uint_fast32_t size = fit_Order(_size);
if(!size) {
log(logINFO) << "Can't find matching order";
return 0;
}
node_t *n = find_Free(size);
if(!n) {
log(logINFO) << "Can't find matching node";
return 0;
}
//bt->print_Node(n);
n = split_Till_Fit(n, size);
//bt->print_Node(n);
if(bt->alloc_Leaf(n)) {
log(logWARNING) << "Allocation gone wrong";
return 0;
}
//bt->print_Tree(bt->get_Root());
return n->address;
}
node_t * buddy_allocator::split_Till_Fit(node_t *_n, uint_fast32_t size) {
node_t *n = _n;
while(n->size > size) {
if(!bt->split_Node(n)) {
n = n->l_child;
} else {
log(logWARNING) << "Splitting gone wrong";
}
}
return n;
}
node_t * buddy_allocator::find_Free(uint_fast32_t size) {
node_t *n = bt->get_Root();
bt->init_Search();
log(logDEBUG2) << "Search node with size >= " << size;
//bt->print_Node(n);
while(n != NULL && (n->usage != nodeFree || n->size < size)) {
n = bt->search_Node(n);
//bt->print_Node(n);
}
return n;
}
uint_fast32_t buddy_allocator::fit_Order(uint_fast32_t _size) {
log(logDEBUG2) << "Check if size smaller than max";
if(_size > (uint_fast32_t)(1 << max_order)) {
log(logWARNING) << "Requested size (" << _size << ") too large (" << (1 << max_order) << ")";
......@@ -191,28 +191,28 @@ uint_fast32_t buddy_allocator::fit_Order(uint_fast32_t _size) {
log(logWARNING) << "Zero memory request";
return 0;
}
uint_fast32_t size = 1;
while(size < _size) {
size = size << 1;
}
if(size < (uint_fast32_t)(1 << min_order)) {
size = 1 << min_order;
}
log(logDEBUG2) << "New Size: " << size;
return size;
}
uint_fast32_t buddy_allocator::build_Tree(node_t *n) {
if(n->size > (uint_fast32_t)(1 << max_order)) {
log(logDEBUG1) << "Has to be split";
if(!bt->split_Node(n)) {
log(logDEBUG2) << "success - do it recursivly";
build_Tree(n->l_child);
......@@ -220,47 +220,47 @@ uint_fast32_t buddy_allocator::build_Tree(node_t *n) {
} else
log(logWARNING) << "something went wrong";
}
return 0;
}
uint_fast32_t buddy_allocator::check_Tree(node_t *n) {
log(logDEBUG2) << "Check if address wraparounds with size offset";
if(n->size + n->address < n->address) {
log(logERROR) << "Size is too large for address";
return -EINVAL;
}
log(logDEBUG2) << "Check min and max order values";
if(max_order < min_order) {
log(logERROR) << "Min_Order larger than Max_Order";
return -EINVAL;
}
log(logDEBUG2) << "Check min and max order values upper bounds";
if(min_order > 31 || max_order > 31) {
log(logERROR) << "Orders too large for 32 bit space";
return -EINVAL;
}
log(logDEBUG2) << "Check min and max order values under bounds";
if(min_order == 0 || max_order == 0) {
log(logERROR) << "Order is Zero";
return -EINVAL;
}
log(logDEBUG2) << "Check if at least one chunk can be built";
if(n->size < (uint_fast32_t)(1 << min_order)) {
log(logERROR) << "Size too small for requested Min_Order";
return -EINVAL;
}
return 0;
}
uint32_t buddy_allocator::calc_Address(uint32_t a) {
if((a & (ALIGNMENT-1)) != 0) {
log(logDEBUG2) << hex << (a & ~(ALIGNMENT-1)) + ALIGNMENT << dec;
return (a & ~(ALIGNMENT-1)) + ALIGNMENT;
......@@ -271,19 +271,19 @@ uint32_t buddy_allocator::calc_Address(uint32_t a) {
}
uint_fast32_t buddy_allocator::calc_Size(uint_fast32_t s, uint32_t diff) {
log(logDEBUG2) << dec << "Old Size: " << s << " Diff: " << diff;
uint_fast32_t order = 1;
uint_fast32_t size = s - diff;
while(order <= size) {
order = order << 1;
}
if(size == 0 || order == 1) {
log(logWARNING) << " No bytes left for Allocator";
}
return order >> 1;
}
......@@ -34,24 +34,24 @@ class buddy_allocator
public:
buddy_allocator(uint32_t, uint_fast32_t, uint_fast32_t, uint_fast32_t);
~buddy_allocator();
uint32_t alloc_Mem(uint_fast32_t);
uint_fast32_t dealloc_Mem(uint32_t);
void print_Tree(void);
private:
buddy_tree *bt;
uint_fast32_t min_order;
uint_fast32_t max_order;
uint_fast32_t error;
uint32_t calc_Address(uint32_t);
uint_fast32_t calc_Size(uint_fast32_t, uint32_t);
uint_fast32_t build_Tree(node_t *);
uint_fast32_t check_Tree(node_t *);
node_t * find_Free(uint_fast32_t);
node_t * find_Node(uint32_t);
node_t * find_Sibling(node_t *);
......
......@@ -19,75 +19,75 @@
#include "buddy_tree.hpp"
buddy_tree::buddy_tree(uint32_t _address, uint_fast32_t _size){
log(logDEBUG2) << "Set init values for root (size: " << _size << ")";
root = new node_t(_address,_size,NULL);
search_last = NULL;
search_direction = nodeLeft;
nodes = leaves = 1;
}
buddy_tree::~buddy_tree() {
log(logDEBUG2) << "Delete root node";
delete(root);
}
uint_fast32_t buddy_tree::split_Node(node_t *n) {
log(logDEBUG2) << "Check if it has any childs";
if(n->l_child != NULL || n->r_child != NULL) {
// redundant check, if node->usage is correctly used
log(logERROR) << "Contains childs - stop";
return -EINVAL;
}
log(logDEBUG2) << "Check if it is really free";
if(n->usage != nodeFree) {
log(logERROR) << "In use - stop";
return -EINVAL;
}
n->l_child = new node_t(n->address,n->size/2,n);
n->r_child = new node_t(n->address+n->size/2,n->size/2,n);
n->usage = nodeMiddle;
nodes += 2;
leaves++;
log(logDEBUG1) << "Count nodes: " << nodes << " leaves: " << leaves;
return 0;
}
uint_fast32_t buddy_tree::merge_Node(node_t *n) {
log(logDEBUG2) << "Check if it has any childs";
if(n->l_child == NULL || n->r_child == NULL) {
// redundant check, if node->usage is correctly used
log(logERROR) << "Contains no childs - stop";
return -EINVAL;
}
log(logDEBUG2) << "Check if childs are free";
if(n->l_child->usage != nodeFree || n->r_child->usage != nodeFree) {
log(logERROR) << "In use - stop";
return -EINVAL;
}
delete(n->l_child);
delete(n->r_child);
n->l_child = n->r_child = NULL;
n->usage = nodeFree;
nodes -= 2;
leaves--;
log(logDEBUG1) << "Count nodes: " << nodes << " leaves: " << leaves;
return 0;
}
......@@ -97,7 +97,7 @@ void buddy_tree::init_Search(void) {
}
node_t * buddy_tree::search_Node(node_t *n) {
if(has_Childs(n) && search_direction == nodeLeft) {
return n->l_child;
}
......@@ -116,7 +116,7 @@ node_t * buddy_tree::search_Node(node_t *n) {
}
node_t * buddy_tree::search_Node(node_t *n, uint32_t address) {
if(has_Childs(n) && address < n->r_child->address) {
return n->l_child;
}
......@@ -129,19 +129,19 @@ node_t * buddy_tree::search_Node(node_t *n, uint32_t address) {
}
void buddy_tree::print_Tree(node_t *n) {
node_t *last = NULL;
node_t *current = n;
node_position_e direction = nodeLeft;
uint_fast32_t depth = 0;
log(logINFO) << "Count nodes: " << nodes << " leaves: " << leaves;
print_Node(current);
while(current != NULL) {
log(logDEBUG3) << "Current: " << hex << current << " Last: " << last << dec << " Depth: " << depth;