jekyll-theme-gaeblogx 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +9 -0
  4. data/_includes/algolia.html +75 -0
  5. data/_includes/backToTop.html +5 -0
  6. data/_includes/category.html +19 -0
  7. data/_includes/comments.html +46 -0
  8. data/_includes/footer.html +33 -0
  9. data/_includes/head.html +58 -0
  10. data/_includes/header.html +34 -0
  11. data/_includes/previousAndNext.html +13 -0
  12. data/_includes/sidebar-search.html +25 -0
  13. data/_includes/tag.html +16 -0
  14. data/_layouts/default.html +26 -0
  15. data/_layouts/demo.html +10 -0
  16. data/_layouts/page.html +31 -0
  17. data/_layouts/post.html +107 -0
  18. data/_sass/_backToTop.scss +49 -0
  19. data/_sass/_demo.scss +65 -0
  20. data/_sass/_footer.scss +63 -0
  21. data/_sass/_header.scss +174 -0
  22. data/_sass/_index.scss +174 -0
  23. data/_sass/_layout.scss +242 -0
  24. data/_sass/_page.scss +238 -0
  25. data/_sass/_post-old.scss +109 -0
  26. data/_sass/_post.scss +83 -0
  27. data/_sass/_reset.scss +119 -0
  28. data/_sass/_scrollbar.scss +35 -0
  29. data/_sass/_syntax-highlighting.scss +99 -0
  30. data/assets/10.jpg +0 -0
  31. data/assets/AWS-Introduction-ec2.png +0 -0
  32. data/assets/Cache-Oblivious-Algorithms-FunnelSort.jpg +0 -0
  33. data/assets/Condition-Variables-fig1.png +0 -0
  34. data/assets/Dynamic-Compilation-adaptJVM.pdf +0 -0
  35. data/assets/Dynamic-Compilation-dyncomp.pdf +0 -0
  36. data/assets/Fibonacci-Heap-Fig3.png +0 -0
  37. data/assets/Fibonacci-Heap-Fig5.png +0 -0
  38. data/assets/Fibonacci-Heap-Fig6.png +0 -0
  39. data/assets/Fibonacci-Heap-Fig7.png +0 -0
  40. data/assets/File-System-bc.jpg +0 -0
  41. data/assets/File-System-filetable.rich.jpg +0 -0
  42. data/assets/GIL-Battle.png +0 -0
  43. data/assets/GIL-CPU.png +0 -0
  44. data/assets/GIL-Check.png +0 -0
  45. data/assets/GIL-IO.png +0 -0
  46. data/assets/GIL-Measure-1.png +0 -0
  47. data/assets/GIL-Measure-2.png +0 -0
  48. data/assets/GIL-Signal.png +0 -0
  49. data/assets/GIL-Tick.png +0 -0
  50. data/assets/Garbage-Collection-Slides-gc.pdf +0 -0
  51. data/assets/Garbage-Collection-copying-1.png +0 -0
  52. data/assets/Garbage-Collection-copying-2.png +0 -0
  53. data/assets/Garbage-Collection-free-list.png +0 -0
  54. data/assets/Garbage-Collection-generation-1.png +0 -0
  55. data/assets/Garbage-Collection-mark-sweep.png +0 -0
  56. data/assets/Garbage-Collection-nursery-1.png +0 -0
  57. data/assets/Garbage-Collection-nursery-2.png +0 -0
  58. data/assets/Garbage-Collection-nursery-3.png +0 -0
  59. data/assets/Garbage-Collection-nursery-4.png +0 -0
  60. data/assets/Garbage-Collection-nursery-5.png +0 -0
  61. data/assets/Garbage-Collection-process.png +0 -0
  62. data/assets/Garbage-Collection-ref-counting.png +0 -0
  63. data/assets/Interpreter-Optimization-interp.pdf +0 -0
  64. data/assets/Memory-Management-fig1.png +0 -0
  65. data/assets/Memory-Management-fig2.png +0 -0
  66. data/assets/Memory-Management-fig3.png +0 -0
  67. data/assets/Memory-Management-fig4.png +0 -0
  68. data/assets/Memory-Management-fig5.png +0 -0
  69. data/assets/Memory-Management-fig6.png +0 -0
  70. data/assets/Memory-Management-fig7.png +0 -0
  71. data/assets/Memory-Management-fig8.png +0 -0
  72. data/assets/Multicore-GIL-1.png +0 -0
  73. data/assets/Multicore-GIL-2.png +0 -0
  74. data/assets/My-Photo.JPG +0 -0
  75. data/assets/Operating-System-Virtualization-ept.png +0 -0
  76. data/assets/Operating-System-Virtualization-guest-page.png +0 -0
  77. data/assets/Operating-System-Virtualization-kvm-arch.png +0 -0
  78. data/assets/Operating-System-Virtualization-kvm-process.png +0 -0
  79. data/assets/Operating-System-Virtualization-kvm-qemu.png +0 -0
  80. data/assets/Operating-System-Virtualization-kvm-state.png +0 -0
  81. data/assets/Operating-System-Virtualization-vtx.png +0 -0
  82. data/assets/Operating-System-Virtualization-xen-arch.png +0 -0
  83. data/assets/Program-Profiling-profiling.pdf +0 -0
  84. data/assets/Programming-Language-Virtual-Machine-vm.pdf +0 -0
  85. data/assets/Remote-Shell-Session-Setup-1.png +0 -0
  86. data/assets/Signals-1.png +0 -0
  87. data/assets/Signals-2.png +0 -0
  88. data/assets/Signals-3.png +0 -0
  89. data/assets/Some-Slides-about-Containers-Kubernetes.pdf +0 -0
  90. data/assets/Some-Slides-about-Containers-UCSB-nurmi.pdf +0 -0
  91. data/assets/Some-Slides-about-PaaS-CS293B_CloudPlatforms.pdf +0 -0
  92. data/assets/avg-1thread.c +172 -0
  93. data/assets/avg-manythread.c +284 -0
  94. data/assets/avg-nothread.c +71 -0
  95. data/assets/file-create1.c +75 -0
  96. data/assets/file-create2.c +120 -0
  97. data/assets/file-fd1.c +56 -0
  98. data/assets/file-fd2.c +25 -0
  99. data/assets/file-fd3.c +23 -0
  100. data/assets/file-read1.c +62 -0
  101. data/assets/file-read2.c +66 -0
  102. data/assets/file-seek1.c +87 -0
  103. data/assets/fork-1.c +35 -0
  104. data/assets/fork-2.c +44 -0
  105. data/assets/fork-3.c +60 -0
  106. data/assets/fork-4.c +64 -0
  107. data/assets/joinall-1.c +163 -0
  108. data/assets/joinall-2.c +162 -0
  109. data/assets/market-kthreads.c +465 -0
  110. data/assets/market-semaphore.c +504 -0
  111. data/assets/market1.c +478 -0
  112. data/assets/market2.c +490 -0
  113. data/assets/market3.c +503 -0
  114. data/assets/market4.c +509 -0
  115. data/assets/my-cat.c +35 -0
  116. data/assets/pipe-1.c +45 -0
  117. data/assets/pipe-2.c +80 -0
  118. data/assets/pipe-3.c +83 -0
  119. data/assets/pipe-4.c +116 -0
  120. data/assets/race1.c +75 -0
  121. data/assets/race2.c +77 -0
  122. data/assets/race3.c +87 -0
  123. data/assets/race_ABC.c +144 -0
  124. data/assets/search-by-algolia.svg +1 -0
  125. data/assets/semaphore.book.ps +8827 -0
  126. data/assets/sys-call1.c +20 -0
  127. data/assets/sys-call2.c +16 -0
  128. data/assets//350/265/253/347/202/2161.PNG +0 -0
  129. data/feed.xml +30 -0
  130. data/index.html +164 -0
  131. data/js/jekyll-search.min.js +1 -0
  132. data/js/lunr.min.js +2977 -0
  133. data/js/main.js +57 -0
  134. data/js/masonry.pkgd.min.js +9 -0
  135. data/js/pageContent.js +166 -0
  136. data/js/search.js +17 -0
  137. data/js/smooth-scroll.min.js +2 -0
  138. data/js/waterfall.js +214 -0
  139. data/page/0archives.html +83 -0
  140. data/page/1category.html +62 -0
  141. data/page/2tags.html +64 -0
  142. data/page/3search.html +112 -0
  143. data/page/4about.md +34 -0
  144. metadata +270 -0
data/assets/market1.c ADDED
@@ -0,0 +1,478 @@
1
+ /*
2
+ * cs170 -- Rich Wolski
3
+ * producer-consumer example
4
+ * uses mutex locks only
5
+ */
6
+ #include <unistd.h>
7
+ #include <stdlib.h>
8
+ #include <stdio.h>
9
+ #include <pthread.h>
10
+ #include <string.h>
11
+
12
+ #include "c-timer.h"
13
+
14
+ #define RAND() (drand48())
15
+
16
+ struct order
17
+ {
18
+ int stock_id;
19
+ int quantity;
20
+ int action; /* buy or sell */
21
+ int fulfilled;
22
+ };
23
+
24
+ struct order_que
25
+ {
26
+ struct order **orders;
27
+ int size;
28
+ int head;
29
+ int tail;
30
+ pthread_mutex_t lock;
31
+ };
32
+
33
+ struct market
34
+ {
35
+ pthread_mutex_t lock;
36
+ int *stocks;
37
+ int count;
38
+ };
39
+
40
+ struct order *InitOrder(int id, int quantity, int action)
41
+ {
42
+ struct order *order;
43
+
44
+ order = (struct order *)malloc(sizeof(struct order));
45
+ if(order == NULL) {
46
+ return(NULL);
47
+ }
48
+ order->stock_id = id;
49
+ order->quantity = quantity;
50
+ order->action = action;
51
+ order->fulfilled = 0;
52
+ return(order);
53
+ }
54
+
55
+ void FreeOrder(struct order *order)
56
+ {
57
+ free(order);
58
+ }
59
+
60
+ struct order_que *InitOrderQue(int size)
61
+ {
62
+ struct order_que *oq;
63
+
64
+ oq = (struct order_que *)malloc(sizeof(struct order_que));
65
+ if(oq == NULL) {
66
+ return(NULL);
67
+ }
68
+ memset(oq,0,sizeof(struct order_que));
69
+
70
+ oq->size = size+1; /* empty condition burns a slot */
71
+ oq->orders = (struct order **)malloc(oq->size*sizeof(struct order *));
72
+ if(oq->orders == NULL) {
73
+ free(oq);
74
+ return(NULL);
75
+ }
76
+ memset(oq->orders,0,size*sizeof(struct order *));
77
+
78
+ pthread_mutex_init(&oq->lock,NULL);
79
+
80
+ return(oq);
81
+ }
82
+
83
+ void FreeOrderQue(struct order_que *oq)
84
+ {
85
+ while(oq->head != oq->tail) {
86
+ FreeOrder(oq->orders[oq->tail]);
87
+ oq->tail = (oq->tail + 1) % oq->size;
88
+ }
89
+
90
+ free(oq->orders);
91
+ free(oq);
92
+ return;
93
+ }
94
+
95
+ struct market *InitMarket(int stock_count, int init_quantity)
96
+ {
97
+ struct market *m;
98
+ int i;
99
+
100
+ m = (struct market *)malloc(sizeof(struct market));
101
+ if(m == NULL) {
102
+ return(NULL);
103
+ }
104
+ m->count = stock_count;
105
+
106
+ m->stocks = (int *)malloc(stock_count*sizeof(int));
107
+ if(m->stocks == NULL) {
108
+ free(m);
109
+ return(NULL);
110
+ }
111
+
112
+ for(i=0; i < stock_count; i++) {
113
+ m->stocks[i] = init_quantity;
114
+ }
115
+
116
+ pthread_mutex_init(&m->lock,NULL);
117
+
118
+ return(m);
119
+ }
120
+
121
+ void FreeMarket(struct market *m)
122
+ {
123
+ free(m->stocks);
124
+ free(m);
125
+ return;
126
+ }
127
+
128
+ void PrintMarket(struct market *m)
129
+ {
130
+ int i;
131
+ for(i=0; i < m->count; i++) {
132
+ printf("stock: %d, quantity: %d\n",
133
+ i,m->stocks[i]);
134
+ }
135
+
136
+ return;
137
+ }
138
+
139
+ struct client_arg
140
+ {
141
+ int id;
142
+ int order_count;
143
+ struct order_que *order_que;
144
+ int max_stock_id;
145
+ int max_quantity;
146
+ int verbose;
147
+ };
148
+
149
+ struct trader_arg
150
+ {
151
+ int id;
152
+ struct order_que *order_que;
153
+ struct market *market;
154
+ int *done;
155
+ int verbose;
156
+ };
157
+
158
+ void *ClientThread(void *arg)
159
+ {
160
+ struct client_arg *ca = (struct client_arg *)arg;
161
+ int i;
162
+ int next;
163
+ struct order *order;
164
+ int stock_id;
165
+ int quantity;
166
+ int action;
167
+ int queued;
168
+ double now;
169
+
170
+
171
+ for(i=0; i < ca->order_count; i++) {
172
+ /*
173
+ * create an order for a random stock
174
+ */
175
+ stock_id = (int)(RAND() * ca->max_stock_id);
176
+ quantity = (int)(RAND() * ca->max_quantity);
177
+ if(RAND() > 0.5) {
178
+ action = 0; /* 0 => buy */
179
+ } else {
180
+ action = 1; /* 1 => sell */
181
+ }
182
+ order = InitOrder(stock_id,quantity,action);
183
+ if(order == NULL) {
184
+ fprintf(stderr,"no space for order\n");
185
+ exit(1);
186
+ }
187
+ /*
188
+ * queue it for the traders
189
+ */
190
+ queued = 0;
191
+ while(queued == 0) {
192
+ pthread_mutex_lock(&(ca->order_que->lock));
193
+ next = (ca->order_que->head + 1) % ca->order_que->size;
194
+ /*
195
+ * is the queue full?
196
+ */
197
+ if(next == ca->order_que->tail) {
198
+ pthread_mutex_unlock(&(ca->order_que->lock));
199
+ continue;
200
+ }
201
+ /*
202
+ * there is space in the queue, add the order and bump
203
+ * the head
204
+ */
205
+ if(ca->verbose == 1) {
206
+ now = CTimer();
207
+ printf("%10.0f client %d: ",now,ca->id);
208
+ printf("queued stock %d, for %d, %s\n",
209
+ order->stock_id,
210
+ order->quantity,
211
+ (order->action ? "SELL" : "BUY"));
212
+ }
213
+ ca->order_que->orders[next] = order;
214
+ ca->order_que->head = next;
215
+ queued = 1;
216
+ pthread_mutex_unlock(&(ca->order_que->lock));
217
+
218
+ /*
219
+ * spin waiting until the order is fulfilled
220
+ */
221
+ while(order->fulfilled == 0);
222
+ /*
223
+ * done, free the order and repeat
224
+ */
225
+ FreeOrder(order);
226
+ }
227
+ }
228
+
229
+ return(NULL);
230
+ }
231
+
232
+ void *TraderThread(void *arg)
233
+ {
234
+ struct trader_arg *ta = (struct trader_arg *)arg;
235
+ int dequeued;
236
+ struct order *order;
237
+ int tail;
238
+ double now;
239
+ int next;
240
+
241
+ while(1) {
242
+ dequeued = 0;
243
+ while(dequeued == 0) {
244
+ pthread_mutex_lock(&(ta->order_que->lock));
245
+ /*
246
+ * is the queue empty?
247
+ */
248
+ if(ta->order_que->head == ta->order_que->tail) {
249
+ pthread_mutex_unlock(&(ta->order_que->lock));
250
+ /*
251
+ * if the queue is empty, are we done?
252
+ */
253
+ if(*(ta->done) == 1) {
254
+ pthread_exit(NULL);
255
+ }
256
+ continue;
257
+ }
258
+ /*
259
+ * get the next order
260
+ */
261
+ next = (ta->order_que->tail + 1) % ta->order_que->size;
262
+ order = ta->order_que->orders[next];
263
+ ta->order_que->tail = next;
264
+ pthread_mutex_unlock(&(ta->order_que->lock));
265
+ dequeued = 1;
266
+ }
267
+ /*
268
+ * have an order to process
269
+ */
270
+ pthread_mutex_lock(&(ta->market->lock));
271
+ if(order->action == 1) { /* BUY */
272
+ ta->market->stocks[order->stock_id] -= order->quantity;
273
+ if(ta->market->stocks[order->stock_id] < 0) {
274
+ ta->market->stocks[order->stock_id] = 0;
275
+ }
276
+ } else {
277
+ ta->market->stocks[order->stock_id] += order->quantity;
278
+ }
279
+ pthread_mutex_unlock(&(ta->market->lock));
280
+ if(ta->verbose == 1) {
281
+ now = CTimer();
282
+ printf("%10.0f trader: %d ",now,ta->id);
283
+ printf("fulfilled stock %d for %d\n",
284
+ order->stock_id,
285
+ order->quantity);
286
+ }
287
+ /*
288
+ * tell the client the order is done
289
+ */
290
+ order->fulfilled = 1;
291
+ }
292
+
293
+ return(NULL);
294
+ }
295
+
296
+ #define ARGS "c:t:o:q:s:V"
297
+ char *Usage = "market1 -c clients -t traders -o orders -q queue-size -s stock-count -V <verbose on>\n";
298
+
299
+ #define INIT_COUNT 5000
300
+
301
+ int main(int argc, char **argv)
302
+ {
303
+ int c;
304
+ int client_threads;
305
+ int trader_threads;
306
+ int orders_per_client;
307
+ int que_size;
308
+ int max_stock;
309
+ int verbose;
310
+ struct client_arg *ca;
311
+ struct trader_arg *ta;
312
+ pthread_t *client_ids;
313
+ pthread_t *trader_ids;
314
+ struct order_que *order_que;
315
+ struct market *market;
316
+ int i;
317
+ int done;
318
+ int err;
319
+ double start;
320
+ double end;
321
+
322
+
323
+ /*
324
+ * defaults
325
+ */
326
+ client_threads = 1;
327
+ trader_threads = 1;
328
+ orders_per_client = 1;
329
+ verbose = 0;
330
+ que_size = 1;
331
+ max_stock = 1;
332
+
333
+ while((c = getopt(argc,argv,ARGS)) != EOF) {
334
+ switch(c) {
335
+ case 'c':
336
+ client_threads = atoi(optarg);
337
+ break;
338
+ case 't':
339
+ trader_threads = atoi(optarg);
340
+ break;
341
+ case 'o':
342
+ orders_per_client = atoi(optarg);
343
+ break;
344
+ case 'q':
345
+ que_size = atoi(optarg);
346
+ break;
347
+ case 's':
348
+ max_stock = atoi(optarg);
349
+ break;
350
+ case 'V':
351
+ verbose = 1;
352
+ break;
353
+ default:
354
+ fprintf(stderr,
355
+ "unrecognized command %c\n",
356
+ (char)c);
357
+ fprintf(stderr,"usage: %s",Usage);
358
+ exit(1);
359
+ }
360
+ }
361
+
362
+ client_ids = (pthread_t *)malloc(client_threads*sizeof(pthread_t));
363
+ if(client_ids == NULL) {
364
+ exit(1);
365
+ }
366
+
367
+ ca = (struct client_arg *)malloc(client_threads*sizeof(struct client_arg));
368
+ if(ca == NULL) {
369
+ exit(1);
370
+ }
371
+
372
+ trader_ids = (pthread_t *)malloc(trader_threads*sizeof(pthread_t));
373
+ if(trader_ids == NULL) {
374
+ exit(1);
375
+ }
376
+
377
+ ta = (struct trader_arg *)malloc(trader_threads*sizeof(struct trader_arg));
378
+ if(ta == NULL) {
379
+ exit(1);
380
+ }
381
+
382
+ order_que = InitOrderQue(que_size);
383
+ if(order_que == NULL) {
384
+ exit(1);
385
+ }
386
+
387
+ market = InitMarket(max_stock,INIT_COUNT);
388
+ if(market == NULL) {
389
+ exit(1);
390
+ }
391
+
392
+ start = CTimer();
393
+ for(i=0; i < client_threads; i++) {
394
+ ca[i].id = i;
395
+ ca[i].order_count = orders_per_client;
396
+ ca[i].max_stock_id = max_stock;
397
+ ca[i].max_quantity = INIT_COUNT;
398
+ ca[i].order_que = order_que;
399
+ ca[i].verbose = verbose;
400
+ err = pthread_create(&client_ids[i],NULL,
401
+ ClientThread,(void *)&ca[i]);
402
+ if(err != 0) {
403
+ fprintf(stderr,"client thread create %d failed\n",i);
404
+ exit(1);
405
+ }
406
+ }
407
+
408
+ done = 0;
409
+ for(i=0; i < trader_threads; i++) {
410
+ ta[i].id = i;
411
+ ta[i].order_que = order_que;
412
+ ta[i].market = market;
413
+ ta[i].done = &done;
414
+ ta[i].verbose = verbose;
415
+ err = pthread_create(&trader_ids[i],NULL,
416
+ TraderThread,(void *)&ta[i]);
417
+ if(err != 0) {
418
+ fprintf(stderr,"trader thread create %d failed\n",i);
419
+ exit(1);
420
+ }
421
+ }
422
+
423
+ /*
424
+ * wait for the clients to finish
425
+ */
426
+ for(i=0; i < client_threads; i++) {
427
+ err = pthread_join(client_ids[i],NULL);
428
+ if(err != 0) {
429
+ fprintf(stderr,"client join %d failed\n",i);
430
+ exit(1);
431
+ }
432
+ }
433
+
434
+ /*
435
+ * tell the traders we are done
436
+ */
437
+ done = 1;
438
+
439
+ for(i=0; i < trader_threads; i++) {
440
+ err = pthread_join(trader_ids[i],NULL);
441
+ if(err != 0) {
442
+ fprintf(stderr,"trader join %d failed\n",i);
443
+ exit(1);
444
+ }
445
+ }
446
+ end = CTimer();
447
+
448
+ if(verbose == 1) {
449
+ PrintMarket(market);
450
+ }
451
+
452
+ printf("%f transactions / sec\n",
453
+ (double)(orders_per_client*client_threads) / (end-start));
454
+
455
+ free(ca);
456
+ free(ta);
457
+ free(client_ids);
458
+ free(trader_ids);
459
+ FreeMarket(market);
460
+ FreeOrderQue(order_que);
461
+
462
+ return(0);
463
+ }
464
+
465
+
466
+
467
+
468
+
469
+
470
+
471
+
472
+
473
+
474
+
475
+
476
+
477
+
478
+