common.c 968 Bytes
Newer Older
1
#include <stdio.h>
Andreas Schmidt's avatar
Andreas Schmidt committed
2
#include <stdlib.h>
3
#include <arpa/inet.h>
4

5 6
#include "common.h"

7
int print_buffer(const char *buf, const int length) {
8 9 10 11 12 13 14 15
    int i;
    for(i = 0; i < length; i++) {
        if(i % 4 == 0) {
            printf("|");
        }
        printf("%2x", buf[i]);
    }
    printf("\n");
16
	return 0;
17 18
}

19
void print_gf(const gf *start, const int len) {
20 21 22 23 24 25 26 27 28 29
    printf("GF: ");
    int i;
    for (i = 0; i < len; i++) {
        gf s = *(start + i);
        printf("%d", s);
        if(i != len-1) {
            printf(",");
        }
    }
    printf("\n");
30
}
31

Andreas Schmidt's avatar
Andreas Schmidt committed
32 33
#include "cpulist.h"
int pin_thread_to_core(pthread_attr_t *ap, int core)
34
{
Andreas Schmidt's avatar
Andreas Schmidt committed
35 36 37 38 39
    char *cpulist_conf = getenv("PRRT_CORES");
    if (cpulist_conf) {
        uint32_t cpulist = cpulist_parse(cpulist_conf);
        core = cpulist_get_cpu(cpulist, core);
    }
40 41 42
    cpu_set_t cpuset;
    CPU_ZERO(&cpuset);
    CPU_SET(core, &cpuset);
Andreas Schmidt's avatar
Andreas Schmidt committed
43
    return pthread_attr_setaffinity_np(ap, sizeof(cpu_set_t), &cpuset);
44
}
Andreas Schmidt's avatar
Andreas Schmidt committed
45