-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpcm-memory.cpp
More file actions
4583 lines (3900 loc) · 205 KB
/
pcm-memory.cpp
File metadata and controls
4583 lines (3900 loc) · 205 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// written by Hosein Mohammadi Makrani
// George Mason University
/*!
\implementation of a simple performance counter monitoring utility
*/
#define HACK_TO_REMOVE_DUPLICATE_ERROR
#include <iostream>
#ifdef _MSC_VER
#pragma warning(disable : 4996) // for sprintf
#include <windows.h>
#include "../PCM_Win/windriver.h"
#else
#include <unistd.h>
#include <sys/time.h> // for gettimeofday()
#endif
#include <fstream>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <cstring>
#include <sstream>
#include <assert.h>
#include <bitset>
#include "cpucounters.h"
#include "utils.h"
/*Edited by Devang*/
#include<cstdlib>
#include<sys/wait.h>
#include<sys/types.h>
#define VM_ADDRESS hduser@192.168.56.101
#define DELAY 1000 //Delay of 1000 ms while running experiments
//--------------------------------------------
/*Select Environment for running experiments*/
// Env-type ENV_SELECT ENV
// HOST MACHINE --> 1 --> HOST
// VIRTUAL MACHINE --> 2 --> VM
// DOCKER --> 3 --> DOCKER
#define HOST 1
#define VM 2
#define DOCKER 3
#define ENV VM //
/*
ENV HOST ---> will select HOST while running the experiments
ENV VM ---> will select VM while running the experiments
ENV DOCKER ---> will select DOCKER while running the experiments
*/ /*If to select the Environment: By default it will set as HOST*/
//--------------------------------------------
/*Control variables to activate/deactivate different Benchmarks of BIGDATABENCH*/
#define HADOOP 1
#define SPARK 0
#define FLINK 0
#if HADOOP
#define HADOOP_WORDCOUNT 0
#define HADOOP_GREP 0
#define HADOOP_PAGERANK 1
#define HADOOP_NAIVEBAYES 0
/*HADOOP_NAVEBAYES has issue running so it cannot be automated. Need to run it manually*/
#else
#define HADOOP_WORDCOUNT 0
#define HADOOP_GREP 0
#define HADOOP_PAGERANK 0
#define HADOOP_NAIVEBAYES 0
#endif
#if SPARK
#define SPARK_WORDCOUNT 1
#define SPARK_GREP 1
#define SPARK_PAGERANK 1
#define SPARK_KMEANS 1
#define SPARK_BFS 1
#define SPARK_CC 1
#define SPARK_NAIVEBAYES 0
#else
#define SPARK_WORDCOUNT 0
#define SPARK_GREP 0
#define SPARK_PAGERANK 0
#define SPARK_KMEANS 0
#define SPARK_BFS 0
#define SPARK_CC 0
#define SPARK_NAIVEBAYES 0
#endif
#if FLINK
#define FLINK_WORDCOUNT 1
#define FLINK_GREP 1
#define FLINK_PAGERANK 1
#define FLINK_KMEANS 1
#define FLINK_BFS 1
#define FLINK_CC 1
#define FLINK_NAIVEBAYES 0
#else
#define FLINK_WORDCOUNT 0
#define FLINK_GREP 0
#define FLINK_PAGERANK 0
#define FLINK_KMEANS 0
#define FLINK_BFS 0
#define FLINK_CC 0
#define FLINK_NAIVEBAYES 0
#endif
/*End of Control Variables for BIGDATABENCH*/
/*Edit by Devang--*/
#define SIZE (10000000)
#define PCM_DELAY_DEFAULT 1.0 // in seconds
#define PCM_DELAY_MIN 0.015 // 15 milliseconds is practical on most modern CPUs
#define PCM_CALIBRATION_INTERVAL 50 // calibrate clock only every 50th iteration
#define MAX_CORES 4096
//Programmable iMC counter
#define READ 0
#define WRITE 1
#define READ_RANK_A 0
#define WRITE_RANK_A 1
#define READ_RANK_B 2
#define WRITE_RANK_B 3
#define PARTIAL 2
#define DEFAULT_DISPLAY_COLUMNS 2
//-------------- General file
using namespace std;
template <class IntType>
double float_format(IntType n)
{
return double(n) / 1024 / 1024;
}
std::string temp_format(int32 t)
{
char buffer[1024];
if (t == PCM_INVALID_THERMAL_HEADROOM)
return "N/A";
sprintf(buffer, "%2d", t);
return buffer;
}
std::string l3cache_occ_format(uint64 o)
{
char buffer[1024];
if (o == PCM_INVALID_QOS_MONITORING_DATA)
return "N/A";
sprintf(buffer, "%6d", (uint32) o);
return buffer;
}
///////////////////////////////////////////////////////////////////////////////////// pcm-memory
void printSocketBWHeader(uint32 no_columns, uint32 skt)
{
for (uint32 i=skt; i<(no_columns+skt); ++i) {
cout << "|---------------------------------------|";
}
cout << endl;
for (uint32 i=skt; i<(no_columns+skt); ++i) {
cout << "|-- Socket "<<setw(2)<<i<<" --|";
}
cout << endl;
for (uint32 i=skt; i<(no_columns+skt); ++i) {
cout << "|---------------------------------------|";
}
cout << endl;
for (uint32 i=skt; i<(no_columns+skt); ++i) {
cout << "|-- Memory Channel Monitoring --|";
}
cout << endl;
for (uint32 i=skt; i<(no_columns+skt); ++i) {
cout << "|---------------------------------------|";
}
cout << endl;
}
///////////////////////////////////////////////////////////////////////////////////// pcm-memory
void printSocketRankBWHeader(uint32 no_columns, uint32 skt)
{
for (uint32 i=skt; i<(no_columns+skt); ++i) {
cout << "|-------------------------------------------|";
}
cout << endl;
for (uint32 i=skt; i<(no_columns+skt); ++i) {
cout << "|-- Socket "<<setw(2)<<i<<" --|";
}
cout << endl;
for (uint32 i=skt; i<(no_columns+skt); ++i) {
cout << "|-------------------------------------------|";
}
cout << endl;
for (uint32 i=skt; i<(no_columns+skt); ++i) {
cout << "|-- DIMM Rank Monitoring --|";
}
cout << endl;
for (uint32 i=skt; i<(no_columns+skt); ++i) {
cout << "|-------------------------------------------|";
}
cout << endl;
}
///////////////////////////////////////////////////////////////////////////////////// pcm-memory
void printSocketChannelBW(uint32 no_columns, uint32 skt, uint32 num_imc_channels, float* iMC_Rd_socket_chan, float* iMC_Wr_socket_chan)
{
for (uint32 channel = 0; channel < num_imc_channels; ++channel) {
// check all the sockets for bad channel "channel"
unsigned bad_channels = 0;
for (uint32 i=skt; i<(skt+no_columns); ++i) {
if (iMC_Rd_socket_chan[i*num_imc_channels + channel] < 0.0 || iMC_Wr_socket_chan[i*num_imc_channels + channel] < 0.0) //If the channel read neg. value, the channel is not working; skip it.
++bad_channels;
}
if (bad_channels == no_columns) { // the channel is missing on all sockets in the row
continue;
}
for (uint32 i=skt; i<(skt+no_columns); ++i) {
cout << "|-- Mem Ch "<<setw(2)<<channel<<": Reads (MB/s): "<<setw(8)<<iMC_Rd_socket_chan[i*num_imc_channels+channel]<<" --|";
}
cout << endl;
for (uint32 i=skt; i<(skt+no_columns); ++i) {
cout << "|-- Writes(MB/s): "<<setw(8)<<iMC_Wr_socket_chan[i*num_imc_channels+channel]<<" --|";
}
cout << endl;
}
}
///////////////////////////////////////////////////////////////////////////////////// pcm-memory
void printSocketChannelBW(uint32 no_columns, uint32 skt, uint32 num_imc_channels, const ServerUncorePowerState * uncState1, const ServerUncorePowerState * uncState2, uint64 elapsedTime, int rankA, int rankB)
{
for (uint32 channel = 0; channel < num_imc_channels; ++channel) {
if(rankA >= 0) {
for (uint32 i=skt; i<(skt+no_columns); ++i) {
cout << "|-- Mem Ch "<<setw(2)<<channel<<" R " << setw(1) << rankA <<": Reads (MB/s): "<<setw(8)<<(float) (getMCCounter(channel,READ_RANK_A,uncState1[i],uncState2[i]) * 64 / 1000000.0 / (elapsedTime/1000.0))<<" --|";
}
cout << endl;
for (uint32 i=skt; i<(skt+no_columns); ++i) {
cout << "|-- Writes(MB/s): "<<setw(8)<<(float) (getMCCounter(channel,WRITE_RANK_A,uncState1[i],uncState2[i]) * 64 / 1000000.0 / (elapsedTime/1000.0))<<" --|";
}
cout << endl;
}
if(rankB >= 0) {
for (uint32 i=skt; i<(skt+no_columns); ++i) {
cout << "|-- Mem Ch "<<setw(2) << channel<<" R " << setw(1) << rankB <<": Reads (MB/s): "<<setw(8)<<(float) (getMCCounter(channel,READ_RANK_B,uncState1[i],uncState2[i]) * 64 / 1000000.0 / (elapsedTime/1000.0))<<" --|";
}
cout << endl;
for (uint32 i=skt; i<(skt+no_columns); ++i) {
cout << "|-- Writes(MB/s): "<<setw(8)<<(float) (getMCCounter(channel,WRITE_RANK_B,uncState1[i],uncState2[i]) * 64 / 1000000.0 / (elapsedTime/1000.0))<<" --|";
}
cout << endl;
}
}
}
///////////////////////////////////////////////////////////////////////////////////// pcm-memory
void printSocketBWFooter(uint32 no_columns, uint32 skt, float* iMC_Rd_socket, float* iMC_Wr_socket, uint64* partial_write)
{
for (uint32 i=skt; i<(skt+no_columns); ++i) {
cout << "|-- NODE"<<setw(2)<<i<<" Mem Read (MB/s) : "<<setw(8)<<iMC_Rd_socket[i]<<" --|";
}
cout << endl;
for (uint32 i=skt; i<(skt+no_columns); ++i) {
cout << "|-- NODE"<<setw(2)<<i<<" Mem Write(MB/s) : "<<setw(8)<<iMC_Wr_socket[i]<<" --|";
}
cout << endl;
for (uint32 i=skt; i<(skt+no_columns); ++i) {
cout << "|-- NODE"<<setw(2)<<i<<" P. Write (T/s): "<<dec<<setw(10)<<partial_write[i]<<" --|";
}
cout << endl;
for (uint32 i=skt; i<(skt+no_columns); ++i) {
cout << "|-- NODE"<<setw(2)<<i<<" Memory (MB/s): "<<setw(11)<<std::right<<iMC_Rd_socket[i]+iMC_Wr_socket[i]<<" --|";
}
cout << endl;
for (uint32 i=skt; i<(no_columns+skt); ++i) {
cout << "|---------------------------------------|";
}
cout << endl;
}
///////////////////////////////////////////////////////////////////////////////////// pcm-memory
float display_bandwidth(float *iMC_Rd_socket_chan, float *iMC_Wr_socket_chan, float *iMC_Rd_socket, float *iMC_Wr_socket, uint32 numSockets, uint32 num_imc_channels, uint64 *partial_write, uint32 no_columns )
{
float sysRead = 0.0, sysWrite = 0.0;
uint32 skt = 0;
cout.setf(ios::fixed);
cout.precision(2);
while(skt < numSockets)
{
// Full row
if ( (skt+no_columns) <= numSockets )
{
printSocketBWHeader (no_columns, skt);
printSocketChannelBW(no_columns, skt, num_imc_channels, iMC_Rd_socket_chan, iMC_Wr_socket_chan);
printSocketBWFooter (no_columns, skt, iMC_Rd_socket, iMC_Wr_socket, partial_write);
for (uint32 i=skt; i<(skt+no_columns); i++) {
sysRead += iMC_Rd_socket[i];
sysWrite += iMC_Wr_socket[i];
}
skt += no_columns;
}
else //Display one socket in this row
{
cout << "\
\r|---------------------------------------|\n\
\r|-- Socket "<<skt<<" --|\n\
\r|---------------------------------------|\n\
\r|-- Memory Channel Monitoring --|\n\
\r|---------------------------------------|\n\
\r";
for(uint64 channel = 0; channel < num_imc_channels; ++channel)
{
if(iMC_Rd_socket_chan[skt*num_imc_channels+channel] < 0.0 && iMC_Wr_socket_chan[skt*num_imc_channels+channel] < 0.0) //If the channel read neg. value, the channel is not working; skip it.
continue;
cout << "|-- Mem Ch "
<<channel
<<": Reads (MB/s):"
<<setw(8)
<<iMC_Rd_socket_chan[skt*num_imc_channels+channel]
<<" --|\n|-- Writes(MB/s):"
<<setw(8)
<<iMC_Wr_socket_chan[skt*num_imc_channels+channel]
<<" --|\n";
}
cout << "\
\r|-- NODE"<<skt<<" Mem Read (MB/s): "<<setw(8)<<iMC_Rd_socket[skt]<<" --|\n\
\r|-- NODE"<<skt<<" Mem Write (MB/s) :"<<setw(8)<<iMC_Wr_socket[skt]<<" --|\n\
\r|-- NODE"<<skt<<" P. Write (T/s) :"<<setw(10)<<dec<<partial_write[skt]<<" --|\n\
\r|-- NODE"<<skt<<" Memory (MB/s): "<<setw(8)<<iMC_Rd_socket[skt]+iMC_Wr_socket[skt]<<" --|\n\
\r|---------------------------------------|\n\
\r";
sysRead += iMC_Rd_socket[skt];
sysWrite += iMC_Wr_socket[skt];
skt += 1;
}
}
cout << "\
\r|---------------------------------------||---------------------------------------|\n\
\r|-- System Read Throughput(MB/s):"<<setw(10)<<sysRead<<" --|\n\
\r|-- System Write Throughput(MB/s):"<<setw(10)<<sysWrite<<" --|\n\
\r|-- System Memory Throughput(MB/s):"<<setw(10)<<sysRead+sysWrite<<" --|\n\
\r|---------------------------------------||---------------------------------------|" << endl;
return (sysRead+sysWrite);
}
const uint32 max_sockets = 256;
const uint32 max_imc_channels = 8;
///////////////////////////////////////////////////////////////////////////////////// pcm-memory
float calculate_bandwidth(PCM *m, const ServerUncorePowerState uncState1[], const ServerUncorePowerState uncState2[], uint64 elapsedTime, bool csv, bool & csvheader, uint32 no_columns)
{
//const uint32 num_imc_channels = m->getMCChannelsPerSocket();
float iMC_Rd_socket_chan[max_sockets][max_imc_channels];
float iMC_Wr_socket_chan[max_sockets][max_imc_channels];
float iMC_Rd_socket[max_sockets];
float iMC_Wr_socket[max_sockets];
uint64 partial_write[max_sockets];
for(uint32 skt = 0; skt < m->getNumSockets(); ++skt)
{
iMC_Rd_socket[skt] = 0.0;
iMC_Wr_socket[skt] = 0.0;
partial_write[skt] = 0;
for(uint32 channel = 0; channel < max_imc_channels; ++channel)
{
if(getMCCounter(channel,READ,uncState1[skt],uncState2[skt]) == 0.0 && getMCCounter(channel,WRITE,uncState1[skt],uncState2[skt]) == 0.0) //In case of JKT-EN, there are only three channels. Skip one and continue.
{
iMC_Rd_socket_chan[skt][channel] = -1.0;
iMC_Wr_socket_chan[skt][channel] = -1.0;
continue;
}
iMC_Rd_socket_chan[skt][channel] = (float) (getMCCounter(channel,READ,uncState1[skt],uncState2[skt]) * 64 / 1000000.0 / (elapsedTime/1000.0));
iMC_Wr_socket_chan[skt][channel] = (float) (getMCCounter(channel,WRITE,uncState1[skt],uncState2[skt]) * 64 / 1000000.0 / (elapsedTime/1000.0));
iMC_Rd_socket[skt] += iMC_Rd_socket_chan[skt][channel];
iMC_Wr_socket[skt] += iMC_Wr_socket_chan[skt][channel];
partial_write[skt] += (uint64) (getMCCounter(channel,PARTIAL,uncState1[skt],uncState2[skt]) / (elapsedTime/1000.0));
}
}
float bw=0.0;
bw=display_bandwidth(iMC_Rd_socket_chan[0], iMC_Wr_socket_chan[0], iMC_Rd_socket, iMC_Wr_socket, m->getNumSockets(), max_imc_channels, partial_write, no_columns);
return bw;
}
int main(int argc, char * argv[])
{
int memfrq=0, memch=0, memcap=0,maxf=0,numcore=0,insize=0;
memcap = atoi(argv[1]);
memfrq = atoi(argv[2]);
memch = atoi(argv[3]);
maxf = atoi(argv[4]);
numcore = atoi(argv[5]);
insize = atoi(argv[6]);
/*Edited by Devang*/
int pid_status=-100;
pid_t pid,pid_result;
uint32 count=0;
ofstream myfile;
float mbw = 0.0;
cout << "mem freq is:" << memfrq << " channel is: " << memch << " dram capacity is: " << memcap << "core count is:" << numcore << "input size is:" << insize;
#ifdef PCM_FORCE_SILENT
null_stream nullStream1, nullStream2;
std::cout.rdbuf(&nullStream1);
std::cerr.rdbuf(&nullStream2);
#endif
cerr << endl;
// cerr << " Intel(r) Performance Counter Monitor " << INTEL_PCM_VERSION << endl;
cerr << " Intel(r) Performance Counter Monitor " << endl;
cerr << endl;
// cerr << INTEL_PCM_COPYRIGHT << endl;
cerr << endl;
// if delay is not specified: use either default (1 second),
// or only read counters before or after PCM started: keep PCM blocked
double delay = -1.0;
char *sysCmd = NULL;
char **sysArgv = NULL;
bool show_core_output = true;
bool show_partial_core_output = false;
bool show_socket_output = true;
bool show_system_output = true;
bool csv_output = false;
bool reset_pmu = false;
long diff_usec = 0; // deviation of clock is useconds between measurements
int calibrated = PCM_CALIBRATION_INTERVAL - 2; // keeps track is the clock calibration needed
unsigned int numberOfIterations = 0; // number of iterations
std::bitset<MAX_CORES> ycores;
bool csv = false;
bool csvheader=false;
uint32 no_columns = DEFAULT_DISPLAY_COLUMNS; // Default number of columns is 2
int rankA = -1, rankB = -1; // memory
int imc_profile = 0; // power
string program = string(argv[0]);
PCM * m = PCM::getInstance();
if (true)
{
// cerr << "\n Resetting PMU configuration" << endl;
// m->resetPMU();
}
// program() creates common semaphore for the singleton, so ideally to be called before any other references to PCM
PCM::ErrorCode status = m->program();
switch (status)
{
case PCM::Success:
break;
case PCM::MSRAccessDenied:
cerr << "Access to Intel(r) Performance Counter Monitor has denied (no MSR or PCI CFG space access)." << endl;
exit(EXIT_FAILURE);
case PCM::PMUBusy:
cerr << "Access to Intel(r) Performance Counter Monitor has denied (Performance Monitoring Unit is occupied by other application). Try to stop the application that uses PMU." << endl;
cerr << "Alternatively you can try running Intel PCM with option -r to reset PMU configuration at your own risk." << endl;
exit(EXIT_FAILURE);
default:
cerr << "Access to Intel(r) Performance Counter Monitor has denied (Unknown error)." << endl;
exit(EXIT_FAILURE);
}
cerr << "\nDetected " << m->getCPUBrandString() << " \"Intel(r) microarchitecture codename " << m->getUArchCodename() << "\"" << endl;
ServerUncorePowerState * BeforeState = new ServerUncorePowerState[m->getNumSockets()];
ServerUncorePowerState * AfterState = new ServerUncorePowerState[m->getNumSockets()];
uint64 BeforeTime = 0, AfterTime = 0;
std::vector<CoreCounterState> cstates1, cstates2;
std::vector<SocketCounterState> sktstate1, sktstate2;
SystemCounterState sstate1, sstate2;
const int cpu_model = m->getCPUModel();
uint64 TimeAfterSleep = 0;
PCM_UNUSED(TimeAfterSleep);
delay = PCM_DELAY_DEFAULT;
m->setBlocked(false);
int fr = maxf; // for 3 different core frrequency
//int fr = 0;
//for(fr = 0 ; fr < maxf ; fr++)
for( ; fr == maxf ; fr++)
{
cout << " Start to run Benchmarks...\n";
if(fr==0)
{
system("cpupower frequency-set -f 2100000");
}
else if(fr==1)
{
system("cpupower frequency-set -f 1900000");
}
else
{
system("cpupower frequency-set -f 1200000");
}
/*
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// Framework:Hadoop Application: wordcount
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// Open report
myfile.open("hibench.csv",fstream::app);
// Clear DRAM
system("sync && echo 3 | sudo tee /proc/sys/vm/drop_caches");
//----------------------------------------------------------------
// Call the program
//system("/usr/local/hadoop/bin/hadoop jar /usr/local/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.0.jar wordcount randtext28g hwcout");
//Edit by Devang/
pid= fork();
if (pid==0)
{
cout<<"This is child process";
//execl("/bin/su", "hoseinmmm", "-c", "ssh dev@192.168.56.102 -i /home/hoseinmmm/.ssh/id_rsa /home/dev/project/HiBench-master/bin/workloads/micro/wordcount/hadoop/run.sh", NULL);
//execl("/usr/bin/ssh", "ssh","dev@192.168.56.102","/home/dev/project/HiBench-master/bin/workloads/micro/wordcount/hadoop/run.sh", NULL);
//execl("/bin/su hduser -c \"ssh hduser@192.168.56.101 -i /home/hduser/.ssh/id_rsa /home/dev/project/HiBench-master/bin/workloads/micro/wordcount/hadoop/run.sh\" ", "run.sh",NULL);
//Activate this for running on VM/
//execl( "/bin/su", "hduser", "-c", "ssh hduser@192.168.56.101 -i /home/hduser/.ssh/id_rsa /home/dev/project/HiBench-master/bin/workloads/micro/wordcount/hadoop/run.sh", NULL);
//Activate this for running on Server Machine/
execl("/home/hosein/project/HiBench-master/bin/workloads/micro/wordcount/hadoop/run.sh","run.sh", NULL);
_exit(1);
}
else if (pid > 0)
{
//int status=300;
//std::cout<<"Status_before: "<<status<<"\n";
//waitpid(pid,&status,0);
//std::cout<<"Status_after: "<<status<<"\n";
//std::cout<<"Process: "<<getpid()<<" with child "<<pid<<"\n";
}
// system("/home/hoseinmmm/project/HiBench-master/bin/workloads/micro/wordcount/hadoop/run.sh");
for(count=0; pid_status<0 ; count++) {
//---------------------------------------------------------------
// Reading states and time befor running
m->getAllCounterStates(sstate1, sktstate1, cstates1);
BeforeTime = m->getTickCount();
for(uint32 i=0; i<m->getNumSockets(); ++i)
BeforeState[i] = m->getServerUncorePowerState(i);
if (sysCmd != NULL)
{
MySystem(sysCmd, sysArgv);
}
//-----Delay-----/
MySleepMs(DELAY);
//-----Delay-----/
pid_result=waitpid(pid,&pid_status,WNOHANG);
std::cout<<"This loop is running with current count: "<<count<<"\n";
std::cout<<"Status of Child: "<< pid_status;
std::cout<<"Return value of WAITPID:"<<pid_result;
//---------------------------------------------------------------
// Reading states and time after running
m->getAllCounterStates(sstate2, sktstate2, cstates2);
AfterTime = m->getTickCount();
for(uint32 i=0; i<m->getNumSockets(); ++i)
AfterState[i] = m->getServerUncorePowerState(i);
//---------------------------------------------------------------
// Remove output file
//system("/usr/local/hadoop/bin/hdfs dfs -rmr -skipTrash hwcout");
//---------------------------------------------------------------
// Writing information to report
myfile << "wordcount," << "hadoop," << memcap<<","<<memfrq<<","<<memch;
if(fr==0){
myfile <<",2.1";}
else if(fr==1){
myfile <<",1.9";}
else{
myfile <<",1.2";}
myfile << "," << numcore << "," << insize;
myfile << ","<<(double(AfterTime-BeforeTime)/1000)<<","<<getCoreIPC(sstate1, sstate2)<<","<<getL3CacheHitRatio(sstate1, sstate2)<<","<<getL2CacheHitRatio(sstate1, sstate2);
myfile << ","<<(getCoreCStateResidency(0, sstate1, sstate2)*100.)<<","<<getConsumedJoules(sktstate1[0], sktstate2[0])<<","<<getDRAMConsumedJoules(sktstate1[0], sktstate2[0]);
myfile << ","<< (((getConsumedJoules(sktstate1[0], sktstate2[0]))+(getDRAMConsumedJoules(sktstate1[0], sktstate2[0])))*(double(AfterTime-BeforeTime)/(1000*1000)));
myfile << ","<<((getConsumedJoules(sktstate1[0], sktstate2[0]))/(double(AfterTime-BeforeTime)/1000));
myfile << ","<<((getDRAMConsumedJoules(sktstate1[0], sktstate2[0]))/(double(AfterTime-BeforeTime)/1000));
// pcm-memory to calculate BW
mbw = calculate_bandwidth(m,BeforeState,AfterState,AfterTime-BeforeTime,csv,csvheader, no_columns);
myfile <<","<<mbw<< "\n";
}
std::cout<<"Application_count --> Hadoop:Wordcount --> "<<count<<"\n";
pid_status = -100; //To re-initialize value for the next application/
//---------------------------------------------------------------
// Closing report
myfile.close();
// Clear DRAM
system("sync && echo 3 | sudo tee /proc/sys/vm/drop_caches");
//-----------------------------------------------------------------
///////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// Framework:spark Application: wordcount
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// Open report
myfile.open("hibench.csv",fstream::app);
// Clear DRAM
system("sync && echo 3 | sudo tee /proc/sys/vm/drop_caches");
//---------------------------------------------------------------
//----------------------------------------------------------------
// Call the program
//system("/usr/local/hadoop/bin/hadoop jar /usr/local/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.0.jar wordcount randtext28g hwcout");
// system("/home/hoseinmmm/project/HiBench-master/bin/workloads/micro/wordcount/spark/run.sh");
//pid_t pid,pid_result;
pid= fork();
if (pid==0)
{
cout<<"This is child process";
//execl("/usr/bin/ssh", "ssh","dev@192.168.56.102","/home/dev/project/HiBench-master/bin/workloads/micro/wordcount/spark/run.sh", NULL);
//execl("/bin/su", "hoseinmmm", "-c", "ssh dev@192.168.56.102 -i /home/hoseinmmm/.ssh/id_rsa /home/dev/project/HiBench-master/bin/workloads/micro/wordcount/spark/run.sh", NULL);
//Activate this for running on VM/
//execl("/bin/su", "hduser", "-c", "ssh hduser@192.168.56.101 -i /home/hduser/.ssh/id_rsa /home/dev/project/HiBench-master/bin/workloads/micro/wordcount/spark/run.sh", NULL);
//Activate this for running on Server Machine/
execl("/home/hosein/project/HiBench-master/bin/workloads/micro/wordcount/spark/run.sh","run.sh", NULL);
_exit(1);
}
else if (pid > 0)
{
//int status=300;
//std::cout<<"Status_before: "<<status<<"\n";
//waitpid(pid,&status,0);
//std::cout<<"Status_after: "<<status<<"\n";
//std::cout<<"Process: "<<getpid()<<" with child "<<pid<<"\n";
}
for(count=0; pid_status<0 ; count++) {
//-----------------------------------------------------------------
// Reading states and time befor running
m->getAllCounterStates(sstate1, sktstate1, cstates1);
BeforeTime = m->getTickCount();
for(uint32 i=0; i<m->getNumSockets(); ++i)
BeforeState[i] = m->getServerUncorePowerState(i);
if (sysCmd != NULL)
{
MySystem(sysCmd, sysArgv);
}
//-----Delay-----//
MySleepMs(DELAY);
//-----Delay-----//
pid_result=waitpid(pid,&pid_status,WNOHANG);
std::cout<<"This loop is running with current count: "<<count<<"\n";
std::cout<<"Status of Child: "<< pid_status;
std::cout<<"Return value of WAITPID:"<<pid_result;
//---------------------------------------------------------------
// Reading states and time befor running
m->getAllCounterStates(sstate2, sktstate2, cstates2);
AfterTime = m->getTickCount();
for(uint32 i=0; i<m->getNumSockets(); ++i)
AfterState[i] = m->getServerUncorePowerState(i);
//---------------------------------------------------------------
// Remove output file
//system("/usr/local/hadoop/bin/hdfs dfs -rmr -skipTrash hwcout");
//---------------------------------------------------------------
// Writing information to report
myfile << "wordcount," << "spark," << memcap<<","<<memfrq<<","<<memch;
if(fr==0){
myfile <<",2.1";}
else if(fr==1){
myfile <<",1.9";}
else{
myfile <<",1.2";}
myfile << "," << numcore << "," << insize;
myfile << ","<<(double(AfterTime-BeforeTime)/1000)<<","<<getCoreIPC(sstate1, sstate2)<<","<<getL3CacheHitRatio(sstate1, sstate2)<<","<<getL2CacheHitRatio(sstate1, sstate2);
myfile << ","<<(getCoreCStateResidency(0, sstate1, sstate2)*100.)<<","<<getConsumedJoules(sktstate1[0], sktstate2[0])<<","<<getDRAMConsumedJoules(sktstate1[0], sktstate2[0]);
myfile << ","<< (((getConsumedJoules(sktstate1[0], sktstate2[0]))+(getDRAMConsumedJoules(sktstate1[0], sktstate2[0])))*(double(AfterTime-BeforeTime)/(1000*1000)));
myfile << ","<<((getConsumedJoules(sktstate1[0], sktstate2[0]))/(double(AfterTime-BeforeTime)/1000));
myfile << ","<<((getDRAMConsumedJoules(sktstate1[0], sktstate2[0]))/(double(AfterTime-BeforeTime)/1000));
// pcm-memory to calculate BW
mbw = calculate_bandwidth(m,BeforeState,AfterState,AfterTime-BeforeTime,csv,csvheader, no_columns);
myfile <<","<<mbw<< "\n";
}
std::cout<<"Application_count --> Spark:Wordcount --> "<<count<<"\n";
pid_status = -100; //To re-initialize value for the next application/
//---------------------------------------------------------------
// Closing report
myfile.close();
// Clear DRAM
system("sync && echo 3 | sudo tee /proc/sys/vm/drop_caches");
//-----------------------------------------------------------------
///////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------
*/
/*
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// Framework:Hadoop Application: sort
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// Open report
myfile.open("hibench.csv",fstream::app);
// Clear DRAM
system("sync && echo 3 | sudo tee /proc/sys/vm/drop_caches");
//---------------------------------------------------------------
//----------------------------------------------------------------
// Call the program
//system("/usr/local/hadoop/bin/hadoop jar /usr/local/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.0.jar wordcount randtext28g hwcout");
// system("/home/hoseinmmm/project/HiBench-master/bin/workloads/micro/sort/hadoop/run.sh");
//pid_t pid,pid_result;
pid= fork();
if (pid==0)
{
cout<<"This is child process";
//execl("/usr/bin/ssh", "ssh","dev@192.168.56.102","/home/dev/project/HiBench-master/bin/workloads/micro/sort/hadoop/run.sh", NULL);
//execl("/bin/su", "hoseinmmm", "-c", "ssh dev@192.168.56.102 -i /home/hoseinmmm/.ssh/id_rsa /home/dev/project/HiBench-master/bin/workloads/micro/sort/hadoop/run.sh", NULL);
//Activate this for running on VM/
//execl("/bin/su", "hduser", "-c", "ssh hduser@192.168.56.101 -i /home/hduser/.ssh/id_rsa /home/dev/project/HiBench-master/bin/workloads/micro/sort/hadoop/run.sh", NULL);
//Activate this for running on Server Machine/
execl("/home/hosein/project/HiBench-master/bin/workloads/micro/sort/hadoop/run.sh","run.sh", NULL);
_exit(1);
}
else if (pid > 0)
{
//int status=300;
//std::cout<<"Status_before: "<<status<<"\n";
//waitpid(pid,&status,0);
//std::cout<<"Status_after: "<<status<<"\n";
//std::cout<<"Process: "<<getpid()<<" with child "<<pid<<"\n";
}
for(count=0; pid_status<0 ; count++) {
//----------------------------------------------------------------
// Reading states and time befor running
m->getAllCounterStates(sstate1, sktstate1, cstates1);
BeforeTime = m->getTickCount();
for(uint32 i=0; i<m->getNumSockets(); ++i)
BeforeState[i] = m->getServerUncorePowerState(i);
if (sysCmd != NULL)
{
MySystem(sysCmd, sysArgv);
}
//-----Delay-----/
MySleepMs(DELAY);
//-----Delay-----/
pid_result=waitpid(pid,&pid_status,WNOHANG);
std::cout<<"This loop is running with current count: "<<count<<"\n";
std::cout<<"Status of Child: "<< pid_status;
std::cout<<"Return value of WAITPID:"<<pid_result;
//---------------------------------------------------------------
// Reading states and time after running
m->getAllCounterStates(sstate2, sktstate2, cstates2);
AfterTime = m->getTickCount();
for(uint32 i=0; i<m->getNumSockets(); ++i)
AfterState[i] = m->getServerUncorePowerState(i);
//---------------------------------------------------------------
// Remove output file
//system("/usr/local/hadoop/bin/hdfs dfs -rmr -skipTrash hwcout");
//---------------------------------------------------------------
// Writing information to report
myfile << "sort," << "hadoop," << memcap<<","<<memfrq<<","<<memch;
if(fr==0){
myfile <<",2.1";}
else if(fr==1){
myfile <<",1.9";}
else{
myfile <<",1.2";}
myfile << "," << numcore << "," << insize;
myfile << ","<<(double(AfterTime-BeforeTime)/1000)<<","<<getCoreIPC(sstate1, sstate2)<<","<<getL3CacheHitRatio(sstate1, sstate2)<<","<<getL2CacheHitRatio(sstate1, sstate2);
myfile << ","<<(getCoreCStateResidency(0, sstate1, sstate2)*100.)<<","<<getConsumedJoules(sktstate1[0], sktstate2[0])<<","<<getDRAMConsumedJoules(sktstate1[0], sktstate2[0]);
myfile << ","<< (((getConsumedJoules(sktstate1[0], sktstate2[0]))+(getDRAMConsumedJoules(sktstate1[0], sktstate2[0])))*(double(AfterTime-BeforeTime)/(1000*1000)));
myfile << ","<<((getConsumedJoules(sktstate1[0], sktstate2[0]))/(double(AfterTime-BeforeTime)/1000));
myfile << ","<<((getDRAMConsumedJoules(sktstate1[0], sktstate2[0]))/(double(AfterTime-BeforeTime)/1000));
// pcm-memory to calculate BW
mbw = calculate_bandwidth(m,BeforeState,AfterState,AfterTime-BeforeTime,csv,csvheader, no_columns);
myfile <<","<<mbw<< "\n";
}
std::cout<<"Application_count --> Hadoop:Sort --> "<<count<<"\n";
pid_status = -100; //To re-initialize value for the next application/
//---------------------------------------------------------------
// Closing report
myfile.close();
// Clear DRAM
system("sync && echo 3 | sudo tee /proc/sys/vm/drop_caches");
//-----------------------------------------------------------------
///////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------
*/
/*
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// Framework:spark Application: sort
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// Open report
myfile.open("hibench.csv",fstream::app);
// Clear DRAM
system("sync && echo 3 | sudo tee /proc/sys/vm/drop_caches");
//---------------------------------------------------------------
//----------------------------------------------------------------
// Call the program
//system("/usr/local/hadoop/bin/hadoop jar /usr/local/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.0.jar wordcount randtext28g hwcout");
// system("/home/hoseinmmm/project/HiBench-master/bin/workloads/micro/sort/spark/run.sh");
pid= fork();
if (pid==0)
{
cout<<"This is child process";
//execl("/usr/bin/ssh", "ssh","dev@192.168.56.102","/home/dev/project/HiBench-master/bin/workloads/micro/sort/spark/run.sh", NULL);
//execl("/bin/su", "hoseinmmm", "-c", "ssh dev@192.168.56.102 -i /home/hoseinmmm/.ssh/id_rsa /home/dev/project/HiBench-master/bin/workloads/micro/sort/spark/run.sh", NULL);
//Activate this for running on VM/
//execl("/bin/su", "hduser", "-c", "ssh hduser@192.168.56.101 -i /home/hduser/.ssh/id_rsa /home/dev/project/HiBench-master/bin/workloads/micro/sort/spark/run.sh", NULL);
//Activate this for running on Server Machine/
execl("/home/hosein/project/HiBench-master/bin/workloads/micro/sort/spark/run.sh","run.sh", NULL);
_exit(1);
}
else if (pid > 0)
{
//int status=300;
//std::cout<<"Status_before: "<<status<<"\n";
//waitpid(pid,&status,0);
//std::cout<<"Status_after: "<<status<<"\n";
//std::cout<<"Process: "<<getpid()<<" with child "<<pid<<"\n";
}
for(count=0; pid_status<0 ; count++) {
//---------------------------------------------------------------
// Reading states and time befor running
m->getAllCounterStates(sstate1, sktstate1, cstates1);
BeforeTime = m->getTickCount();
for(uint32 i=0; i<m->getNumSockets(); ++i)
BeforeState[i] = m->getServerUncorePowerState(i);
if (sysCmd != NULL)
{
MySystem(sysCmd, sysArgv);
}
//-----Delay-----/
MySleepMs(DELAY);
//-----Delay-----/
pid_result=waitpid(pid,&pid_status,WNOHANG);
std::cout<<"This loop is running with current count: "<<count<<"\n";
std::cout<<"Status of Child: "<< pid_status;
std::cout<<"Return value of WAITPID:"<<pid_result;
//---------------------------------------------------------------
// Reading states and time after running
m->getAllCounterStates(sstate2, sktstate2, cstates2);
AfterTime = m->getTickCount();
for(uint32 i=0; i<m->getNumSockets(); ++i)
AfterState[i] = m->getServerUncorePowerState(i);
//---------------------------------------------------------------
// Remove output file
//system("/usr/local/hadoop/bin/hdfs dfs -rmr -skipTrash hwcout");
//---------------------------------------------------------------
// Writing information to report
myfile << "sort," << "spark," << memcap<<","<<memfrq<<","<<memch;
if(fr==0){
myfile <<",2.1";}
else if(fr==1){
myfile <<",1.9";}
else{
myfile <<",1.2";}
myfile << "," << numcore << "," << insize;
myfile << ","<<(double(AfterTime-BeforeTime)/1000)<<","<<getCoreIPC(sstate1, sstate2)<<","<<getL3CacheHitRatio(sstate1, sstate2)<<","<<getL2CacheHitRatio(sstate1, sstate2);
myfile << ","<<(getCoreCStateResidency(0, sstate1, sstate2)*100.)<<","<<getConsumedJoules(sktstate1[0], sktstate2[0])<<","<<getDRAMConsumedJoules(sktstate1[0], sktstate2[0]);
myfile << ","<< (((getConsumedJoules(sktstate1[0], sktstate2[0]))+(getDRAMConsumedJoules(sktstate1[0], sktstate2[0])))*(double(AfterTime-BeforeTime)/(1000*1000)));
myfile << ","<<((getConsumedJoules(sktstate1[0], sktstate2[0]))/(double(AfterTime-BeforeTime)/1000));
myfile << ","<<((getDRAMConsumedJoules(sktstate1[0], sktstate2[0]))/(double(AfterTime-BeforeTime)/1000));
// pcm-memory to calculate BW
mbw = calculate_bandwidth(m,BeforeState,AfterState,AfterTime-BeforeTime,csv,csvheader, no_columns);
myfile <<","<<mbw<< "\n";
}
std::cout<<"Application_count --> Spark:Sort --> "<<count<<"\n";
pid_status=-100;
//---------------------------------------------------------------
// Closing report
myfile.close();
// Clear DRAM
system("sync && echo 3 | sudo tee /proc/sys/vm/drop_caches");
//-----------------------------------------------------------------
///////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------
*/
/*
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// Framework:Hadoop Application: terasort
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// Open report
myfile.open("hibench.csv",fstream::app);
// Clear DRAM
system("sync && echo 3 | sudo tee /proc/sys/vm/drop_caches");
//---------------------------------------------------------------
//----------------------------------------------------------------
// Call the program
//system("/usr/local/hadoop/bin/hadoop jar /usr/local/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.0.jar wordcount randtext28g hwcout");
// system("/home/hoseinmmm/project/HiBench-master/bin/workloads/micro/terasort/hadoop/run.sh");
//pid_t pid,pid_result;
pid= fork();
if (pid==0)
{
cout<<"This is child process";
//execl("/bin/su", "hoseinmmm", "-c", "ssh dev@192.168.56.102 -i /home/hoseinmmm/.ssh/id_rsa /home/dev/project/HiBench-master/bin/workloads/micro/terasort/hadoop/run.sh", NULL);
//execl("/usr/bin/ssh", "ssh","dev@192.168.56.102","/home/dev/project/HiBench-master/bin/workloads/micro/terasort/hadoop/run.sh", NULL);