Commit f37cb1d5 authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Thread pinning checks.

parent 1efe7ded
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -183,7 +183,7 @@ bool PrrtSocket_bind(PrrtSocket *s, const char *ipAddress, const uint16_t port)

    s->receiveDataThreadAttr = calloc(1, sizeof(pthread_attr_t));
    if(s->isThreadPinning) {
        pin_thread_to_core(s->receiveDataThreadAttr, 2);
        check(pin_thread_to_core(s->receiveDataThreadAttr, 2) == EXIT_SUCCESS, "Cannot pin receive-data thread to core 2.");
    }
    pthread_attr_init(s->receiveDataThreadAttr);
    check(pthread_create(&s->receiveDataThread, s->receiveDataThreadAttr, receive_data_loop,
@@ -203,7 +203,7 @@ bool PrrtSocket_connect(PrrtSocket *s, const char *host, const uint16_t port) {

    s->sendDataThreadAttr = calloc(1, sizeof(pthread_attr_t));
    if(s->isThreadPinning) {
        pin_thread_to_core(s->sendDataThreadAttr, 1);
        check(pin_thread_to_core(s->sendDataThreadAttr, 1) == EXIT_SUCCESS, "Cannot pin send-data thread to core 1.");
    }
    pthread_attr_init(s->sendDataThreadAttr);
    check(pthread_create(&s->sendDataThread, s->sendDataThreadAttr, send_data_loop,
+2 −2
Original line number Diff line number Diff line
@@ -28,10 +28,10 @@ void print_gf(const gf *start, const int len) {
    printf("\n");
}

void pin_thread_to_core(pthread_attr_t *ap, int core)
int pin_thread_to_core(pthread_attr_t *ap, int core)
{
    cpu_set_t cpuset;
    CPU_ZERO(&cpuset);
    CPU_SET(core, &cpuset);
    pthread_attr_setaffinity_np(ap, sizeof(cpu_set_t), &cpuset);
    return pthread_attr_setaffinity_np(ap, sizeof(cpu_set_t), &cpuset);
}
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@

int print_buffer(const char *buf, const int length);
void print_gf(const gf *start, const int len);
void pin_thread_to_core(pthread_attr_t *ap, int core);
int pin_thread_to_core(pthread_attr_t *ap, int core);

#define PERROR(fmt, args...) \
printf("PRRT ERROR (" __FILE__ ":%d)\n" fmt, __LINE__, ## args);