-
Notifications
You must be signed in to change notification settings - Fork 1
/
worker.c
97 lines (97 loc) · 2.54 KB
/
worker.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
///*
// * worker.c
// *
// * Created on: Jun 2, 2017
// * Author: pnookala
// */
//
//#include <unistd.h>
//#include <pthread.h>
//#include <sys/types.h>
//#include <time.h>
//#include <string.h>
//#include "worker.h"
//
//#ifdef spsctest
//struct task_desc *execute_task(struct task_desc *task) {
// if(task)
// {
// switch(task->task_type)
// {
// case 0:
// sleep(0);
// break;
// case 1:
// __asm__ __volatile__("nop;");
// break;
// default:
// break;
// }
// }
// sleep(0);
//
// return 0;
//}
//
//void *worker_handler(void *data) {
// struct thread_local_data *d = (struct thread_local_data *) data;
// struct mproc_state *mps = d->mps;
// int cpuID = d->cpuID;
// struct task_desc *task;
//
// cpu_set_t set;
// CPU_ZERO(&set);
// CPU_SET(cpuID, &set);
//
// pthread_setaffinity_np(pthread_self(), sizeof (set), &set);
// printf("Thread on CPU %d\n", sched_getcpu());
//
// int NUM_SAMPLES_PER_THREAD = (NUM_SAMPLES / WORKERS);
//#ifdef LATENCY
// ticks start_tick, end_tick;
// ticks *timestamp;
// timestamp = (ticks *) malloc(sizeof (ticks) * NUM_SAMPLES_PER_THREAD);
// for (int i = 0; i < NUM_SAMPLES_PER_THREAD; i++) {
// timestamp[i] = (ticks) 0;
// }
//#endif
// pthread_barrier_wait(&mps->barrier);
//#ifdef THROUGHPUT
//// double diff = 0.0;
// struct timespec tstart, tend;
// clock_gettime(CLOCK_MONOTONIC, &tstart);
//#endif
// //while(!(*(mps->kill_master))) {
// for (int count = 0; count < NUM_SAMPLES_PER_THREAD; count++) {
//#ifdef LATENCY
// start_tick = getticks();
//#endif
// task = DEQUEUE();
// execute_task(task);
// ENQUEUE_RESULT(task);
//#ifdef LATENCY
// end_tick = getticks();
// timestamp[count] = end_tick - start_tick;
//#endif
// }
//#ifdef LATENCY
// pthread_mutex_lock(&lock);
// memcpy(mps->timestamps + mps->totalsamples, timestamp, NUM_SAMPLES_PER_THREAD * sizeof (ticks));
// mps->totalsamples += NUM_SAMPLES_PER_THREAD;
// pthread_mutex_unlock(&lock);
//#endif
//#ifdef THROUGHPUT
// clock_gettime(CLOCK_MONOTONIC, &tend);
// pthread_mutex_lock(&lock);
// double elapsed = (tend.tv_sec - tstart.tv_sec) + ((tend.tv_nsec - tstart.tv_nsec) / 1E9);
// printf("elapsed time: %lf\n", elapsed);
// mps->throughput += ((NUM_SAMPLES_PER_THREAD * 1.0) / elapsed);
// pthread_mutex_unlock(&lock);
//#endif
//
// return NULL;
//}
//
//#endif
//
//