callee.c 6.46 KB
Newer Older
Scotty Bauer's avatar
Scotty Bauer committed
1
#include <linux/random.h>
Michael Quigley's avatar
Michael Quigley committed
2
#include <linux/slab.h>
3
#include "rpc.h"
Michael Quigley's avatar
Michael Quigley committed
4
5
#include <lcd-domains/thc.h>
#include <lcd-domains/thcinternal.h>
6

7
static struct ttd_ring_channel *channel;
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
static unsigned long RDTSC_START(void)
{

	unsigned cycles_low, cycles_high;

	asm volatile ("CPUID\n\t"
		      "RDTSC\n\t"
		      "mov %%edx, %0\n\t"
		      "mov %%eax, %1\n\t": "=r" (cycles_high), "=r" (cycles_low)::
		      "%rax", "%rbx", "%rcx", "%rdx");
	return ((unsigned long) cycles_high << 32) | cycles_low;

}


static unsigned long RDTSCP(void)
{
	unsigned long tsc;
	__asm__ __volatile__(
        "rdtscp;"
        "shl $32, %%rdx;"
        "or %%rdx, %%rax"
        : "=a"(tsc)
        :
        : "%rcx", "%rdx");

	return tsc;
}

Scotty Bauer's avatar
Scotty Bauer committed
38
39
40
41
static unsigned long null_invocation(void)
{
	struct ipc_message *msg;
	unsigned long result;
42

Scotty Bauer's avatar
Scotty Bauer committed
43
44
45
46
47
48
49
50
	msg = get_send_slot(channel);
	msg->fn_type = NULL_INVOCATION;
	send(channel,msg);
	msg = recv(channel);
	result = msg->reg1;
	transaction_complete(msg);
	return result;
}
51

52
53
54
55
56
57
58
59
static unsigned long add_constant(unsigned long trans)
{
	struct ipc_message *msg;
	unsigned long result;

	msg = get_send_slot(channel);
	msg->fn_type = ADD_CONSTANT;
	msg->reg1 = trans;
60
	send(channel,msg);
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
	msg = recv(channel);
	result = msg->reg1;
	transaction_complete(msg);
	return result;
}

static unsigned long add_nums(unsigned long trans, unsigned long res1)
{
	struct ipc_message *msg;
	unsigned long result;

	msg = get_send_slot(channel);
	msg->fn_type = ADD_NUMS;
	msg->reg1 = trans;
	msg->reg2 = res1;
76
	send(channel,msg);
77
78
79
80
81
82
	msg = recv(channel);
	result = msg->reg1;
	transaction_complete(msg);
	return result;
}

Michael Quigley's avatar
Michael Quigley committed
83
84
85
static unsigned long add_nums_async(unsigned long trans, unsigned long res1, awe_t* awe)
{
	struct ipc_message *msg;
86
	//int i = 0;
Michael Quigley's avatar
Michael Quigley committed
87
88
89
90
91
92
93
94
95
96
	unsigned long result;
	unsigned long msg_id = (unsigned long)awe;
	
	pr_err("msg id = %lx\n", msg_id);
	msg = get_send_slot(channel);
	msg->fn_type = ADD_NUMS;
	msg->reg1    = trans;
	msg->reg2    = res1;
	msg->msg_id  = msg_id;
	send(channel,msg);
97
98
	//msg = recv(channel);
	msg = async_recv(channel, msg_id);
Michael Quigley's avatar
Michael Quigley committed
99
100
101
102
103
104
	result = msg->reg1;
	transaction_complete(msg);
	
	return result;
}

105
106
107
108
109
110
111
112
113
114
115
116
static unsigned long add_3_nums(unsigned long trans, unsigned long res1,
				unsigned long res2)
{

	struct ipc_message *msg;
	unsigned long result;

	msg = get_send_slot(channel);
	msg->fn_type = ADD_3_NUMS;
	msg->reg1 = trans;
	msg->reg2 = res1;
	msg->reg3 = res2;
117
	send(channel,msg);
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
	msg = recv(channel);
	result = msg->reg1;
	transaction_complete(msg);
	return result;
}
static unsigned long add_4_nums(unsigned long trans, unsigned long res1,
				unsigned long res2, unsigned long res3)
{

	struct ipc_message *msg;
	unsigned long result;

	msg = get_send_slot(channel);
	msg->fn_type = ADD_4_NUMS;
	msg->reg1 = trans;
	msg->reg2 = res1;
	msg->reg3 = res2;
	msg->reg4 = res3;
136
	send(channel,msg);
137
138
139
140
141
142
143
144
145
146
147
148
149
150
	msg = recv(channel);
	result = msg->reg1;
	transaction_complete(msg);
	return result;
}

static unsigned long add_5_nums(unsigned long trans, unsigned long res1,
				unsigned long res2, unsigned long res3,
				unsigned long res4)
{
	struct ipc_message *msg;
	unsigned long result;

	msg = get_send_slot(channel);
151
	msg->fn_type = ADD_5_NUMS;
152
153
154
155
156
	msg->reg1 = trans;
	msg->reg2 = res1;
	msg->reg3 = res2;
	msg->reg4 = res3;
	msg->reg5 = res4;
157
	send(channel,msg);
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
	msg = recv(channel);
	result = msg->reg1;
	transaction_complete(msg);
	return result;
}


static unsigned long add_6_nums(unsigned long trans, unsigned long res1,
				unsigned long res2, unsigned long res3,
				unsigned long res4, unsigned long res5)
{
	struct ipc_message *msg;
	unsigned long result;

	msg = get_send_slot(channel);
173
	msg->fn_type = ADD_6_NUMS;
174
175
176
177
178
179
	msg->reg1 = trans;
	msg->reg2 = res1;
	msg->reg3 = res2;
	msg->reg4 = res3;
	msg->reg5 = res4;
	msg->reg6 = res5;
180
	send(channel,msg);
181
	msg = recv(channel);
182
183
	if (msg->fn_type != ADD_6_NUMS)
		pr_err("Response was not ADD_6_NUMS");
184
185
186
187
188
189

	result = msg->reg1;
	transaction_complete(msg);
	return result;
}

Michael Quigley's avatar
Michael Quigley committed
190
191


192
static void test_async_ipc(void* chan)
Michael Quigley's avatar
Michael Quigley committed
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
{
	unsigned long num_transactions = 0;
	unsigned long res1, res2, res3, res4, res5, res6;
	unsigned long start,end;

	channel = chan;
	
	current->ptstate = kzalloc(sizeof(struct ptstate_t), GFP_KERNEL);
	thc_latch_init(&(current->ptstate->latch));
	thc_init();

	get_random_bytes(&res1, sizeof(res1));
	res2 = res1+res1;
	res3 = res1 + res2;
	res4 = res3 + res2;
	res5 = res4 + res3;
	DO_FINISH(
210
//	while (num_transactions < ASYNC_TRANSACTIONS) {
Michael Quigley's avatar
Michael Quigley committed
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
//		start = RDTSC_START();
		ASYNC(add_nums_async(num_transactions, res1, awe););
//		printk(KERN_ERR "middle of async");
//		ASYNC(add_nums_async(num_transactions + 1, res1, awe););
//		end = RDTSCP();
//		pr_err("%lu\n", end-start);
//		num_transactions++;
//	});
	);
	pr_err("Complete\n");
	printk(KERN_ERR "lcd async exiting module and deleting ptstate");
	thc_done();
	kfree(current->ptstate);
}

226
static void test_sync_ipc(void* chan)
227
228
229
{
	unsigned long num_transactions = 0;
	unsigned long res1, res2, res3, res4, res5, res6;
230
	unsigned long start,end;
231
	channel = chan;
Scotty Bauer's avatar
Scotty Bauer committed
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246

	get_random_bytes(&res1, sizeof(res1));
	res2 = res1+res1;
	res3 = res1 + res2;
	res4 = res3 + res2;
	res5 = res4 + res3;

	while (num_transactions < TRANSACTIONS/2) {
		start = RDTSC_START();
		null_invocation();
		end = RDTSCP();
		pr_err("%lu\n", end-start);
		num_transactions++;
	}
	pr_err("6 regis\n");
Michael Quigley's avatar
Michael Quigley committed
247

248
	while (num_transactions < TRANSACTIONS) {
249
		start = RDTSC_START();
250
		res6 = add_6_nums(num_transactions,res1,res2,res3,res4,res5);
251
252
		end = RDTSCP();
		pr_err("%lu\n", end-start);
Scotty Bauer's avatar
Scotty Bauer committed
253
		num_transactions++;
254
	}
255
	pr_err("Complete\n");
256
        return 1;
257
}
Michael Quigley's avatar
Michael Quigley committed
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280

void foo3(void);
void foo4(void);

noinline void foo3(void) {
	printk(KERN_ERR "lcd async entering foo1\n");
	printk(KERN_ERR "lcd async yielding to foo2\n");
	int count = 0;
	while (count < 2) {
	 printk(KERN_ERR "lcd async Yielding\n");
	 THCYield();	
	 count++;
	}
	printk(KERN_ERR "lcd async foo3 complete\n");
}

noinline void foo4(void) {
	printk(KERN_ERR "lcd async entering foo2\n");
	printk(KERN_ERR "lcd async foo2 Complete\n");
}



Michael Quigley's avatar
Michael Quigley committed
281
int callee(void *chan)
Michael Quigley's avatar
Michael Quigley committed
282
{
283
//	test_async_ipc(chan);
Michael Quigley's avatar
Michael Quigley committed
284

285
	test_sync_ipc(chan);
Michael Quigley's avatar
Michael Quigley committed
286
287
288
289
290
291
292
293
294
295
296
/*
	current->ptstate = kzalloc(sizeof(struct ptstate_t), GFP_KERNEL);
	thc_latch_init(&(current->ptstate->latch));
	thc_init();
    //assert((PTS() == NULL) && "PTS already initialized");
	printk(KERN_ERR "lcd async entering module ptstate allocated");
	DO_FINISH(ASYNC(foo3();); printk(KERN_ERR "lcd async apit_init coming back\n"); ASYNC(foo4();););
    printk(KERN_ERR "lcd async end of DO_FINISH");
	printk(KERN_ERR "lcd async exiting module and deleting ptstate");
	thc_done();
	kfree(current->ptstate);*/
Michael Quigley's avatar
Michael Quigley committed
297
	return 1;
Michael Quigley's avatar
Michael Quigley committed
298
}