Commit 12dd7583 authored by Priyal Suneja's avatar Priyal Suneja
Browse files

created msr.c for signal stuff

parent 11225974
......@@ -3,7 +3,9 @@ BUILDDIR = build
#all: tlb_msr l2_msr l1_msr ins_msr ins l2 tlb l1 l1_populate l2_populate \
# tlb_populate
all: tlb_msr l1_msr l2_msr qs_msr
#all: tlb_msr l1_msr l2_msr qs_msr mm_msr mm_signal
all: mm_signal
l1_msr: l1_msr.c utils.c msr.c
gcc -O0 -Wall -o $(BUILDDIR)/l1_msr l1_msr.c utils.c msr.c -lm
......@@ -32,6 +34,9 @@ qs_msr: qs_msr.c msr.c utils.c
mm_msr: mm_msr.c msr.c utils.c
gcc -O0 -g -Wall -o $(BUILDDIR)/mm_msr mm_msr.c utils.c msr.c -lm
mm_signal: mm_signal.c msr.c utils.c
gcc -O0 -g -Wall -o $(BUILDDIR)/mm_signal mm_signal.c utils.c msr.c -lm
ins: ins.c msr.c utils.c
gcc -O0 -Wall -o $(BUILDDIR)/ins ins.c msr.c utils.c -lm
......
......@@ -32,14 +32,7 @@ int measure_msr(int cpu_model, int cpu_info[3], double energy_units[2],
long long result;
double package_before,package_after;
double dram_before,dram_after;
int one[MM_SIZE][MM_SIZE], two[MM_SIZE][MM_SIZE], res[MM_SIZE][MM_SIZE];
for(int i = 0; i < MM_SIZE; i++) {
for(int j = 0; j < MM_SIZE; j++) {
one[i][j] = i*j;
two[i][j] = i+j;
}
}
// int one[MM_SIZE][MM_SIZE], two[MM_SIZE][MM_SIZE], res[MM_SIZE][MM_SIZE];
fd=open_msr(0); // todo: add package detection + map and stuff
......@@ -58,7 +51,23 @@ int measure_msr(int cpu_model, int cpu_info[3], double energy_units[2],
close(fd);
for(int i = 0; i < ITERATIONS_PER_RUN; i++) {
int **one = malloc(MM_SIZE*sizeof(int*));
int **two = malloc(MM_SIZE*sizeof(int*));
int **res = malloc(MM_SIZE*sizeof(int*));
for(int i = 0; i < MM_SIZE; i++) {
one[i] = malloc(MM_SIZE*sizeof(int));
two[i] = malloc(MM_SIZE*sizeof(int));
res[i] = malloc(MM_SIZE*sizeof(int));
}
for(int i = 0; i < MM_SIZE; i++) {
for(int j = 0; j < MM_SIZE; j++) {
one[i][j] = i*j;
two[i][j] = i+j;
}
}
for(int i = 0; i < ITERATIONS_PER_RUN2; i++) {
matrix_multiply(one, two, res);
}
......
/*
* author: Priyal Suneja ; suneja@cs.washington.edu
*
* to run: sudo ./build/mm_msr
*/
#include "msr.h"
// int cpu_info[3]; // 0 -> pp0, 1-> pp1, 2-> dram
// double energy_units[2]; // 0 -> cpu, 1 -> dram
// extern int errno;
// double readings[1000000];
// double reading;
// FILE *fptr;
// unsigned int count = 0;
// void sig_handler(int signum) {
// int fd=open_msr(0); // todo: add package detection + map and stuff
//
// /* Package Energy */
// long long result = read_msr(fd,MSR_PKG_ENERGY_STATUS);
//
// close(fd);
//
// reading = (double)result*energy_units[0];
// fprintf(fptr, "%f\n", reading);
//
// }
void matrix_multiply(int **one, int **two, int **result) {
int rows1 = MM_SIZE;
int cols2 = MM_SIZE;
int common = MM_SIZE; //cols of 1 and rows of 2
for(int rr = 0; rr < rows1; rr++) {
for(int rc = 0; rc < cols2; rc++) {
result[rr][rc] = 0;
}
}
for(int i = 0; i < rows1; i++) {
for(int j=0; j < cols2; j++) {
for(int k = 0; k < common; k++) {
result[i][j] += one[i][k]*two[k][j];
}
}
}
}
void matrix_multiply_measure() {
int **one = malloc(MM_SIZE*sizeof(int*));
int **two = malloc(MM_SIZE*sizeof(int*));
int **res = malloc(MM_SIZE*sizeof(int*));
for(int i = 0; i < MM_SIZE; i++) {
one[i] = malloc(MM_SIZE*sizeof(int));
two[i] = malloc(MM_SIZE*sizeof(int));
res[i] = malloc(MM_SIZE*sizeof(int));
}
for(int i = 0; i < MM_SIZE; i++) {
for(int j = 0; j < MM_SIZE; j++) {
one[i][j] = i*j;
two[i][j] = i+j;
}
}
for(int i = 0; i < 100; i++) {
matrix_multiply(one, two, res);
}
for(int i = 0; i < MM_SIZE; i++) {
free(one[i]);
free(two[i]);
free(res[i]);
}
free(one);
free(two);
free(res);
return;
}
int main (int argc, char* argv[]) {
// fptr = fopen("mm_signal_out", "w+");
//
// if(!fptr) {
// printf("errno: %d ", errno);
// printf("err string: %s\n", strerror(errno));
// return 0;
// }
//
// signal(SIGALRM, sig_handler);
//
// ualarm(500*1000,500*1000); // 1000 us = 1 ms; 0.5s = 500 ms
// // ualarm(500,500);
//
// get_cpu_info(CPU_HASWELL_EP, cpu_info, energy_units);
//
// measure_msr();
//
// // fclose(fptr);
printf("%s\n", strcat(argv[0], "_out"));
measure_msr("mm_signal_out", &matrix_multiply_measure);
return 0;
}
......@@ -3,6 +3,8 @@
*/
#include "msr.h"
extern int errno;
int open_msr(int core) {
char msr_filename[BUFSIZ];
......@@ -42,7 +44,6 @@
int get_cpu_info(int cpu_model, int cpu_info[3], double energy_units[2]) {
int fd, result;
// double power_units,time_units;
double cpu_energy_units,dram_energy_units;
/** indices to cpu_info **/
......@@ -110,32 +111,48 @@ int get_cpu_info(int cpu_model, int cpu_info[3], double energy_units[2]) {
}
// printf("\tListing paramaters for package #0\n");
fd=open_msr(0); // todo: add package detection + map and stuff
/* Calculate the units used */
result=read_msr(fd,MSR_RAPL_POWER_UNIT);
// power_units=pow(0.5,(double)(result&0xf));
cpu_energy_units=pow(0.5,(double)((result>>8)&0x1f));
// time_units=pow(0.5,(double)((result>>16)&0xf));
/* On Haswell EP and Knights Landing */
/* The DRAM units differ from the CPU ones */
dram_energy_units=pow(0.5,(double)16); // we know we're on haswell
// so this is ok
// printf("DRAM: Using %lf instead of %lf\n",
// dram_energy_units,cpu_energy_units);
//
// printf("\t\tPower units = %.3fW\n",power_units);
// printf("\t\tCPU Energy units = %.8fJ\n",cpu_energy_units);
// printf("\t\tDRAM Energy units = %.8fJ\n",dram_energy_units);
// printf("\t\tTime units = %.8fs\n",time_units);
energy_units[0] = cpu_energy_units;
energy_units[1] = dram_energy_units;
// printf("\n");
return 0;
}
void sig_handler(int signum) {
int fd = open_msr(0);
long long result = read_msr(fd, MSR_PKG_ENERGY_STATUS);
close(fd);
reading = (double)result*energy_units[0];
fprintf(fptr, "%f\n", reading);
}
void measure_msr(char* filename, void (*func_ptr)()) {
fptr = fopen(filename, "w+");
if(!fptr) {
printf("errno: %d, err_string: %s\n", errno, strerror(errno));
return;
}
signal(SIGALRM, sig_handler);
ualarm(500*1000, 500*1000); // 1000 us = 1ms,; 0.5s = 500 ms
get_cpu_info(CPU_HASWELL_EP, cpu_info, energy_units);
func_ptr();
}
......@@ -2,6 +2,7 @@
* author: Priyal Suneja ; suneja@cs.washington.edu
*/
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
......@@ -15,7 +16,8 @@
#include "utils.h"
#define RUNS 1
#define ITERATIONS_PER_RUN 1000
// #define ITERATIONS_PER_RUN 1000
#define ITERATIONS_PER_RUN 100
#define L1_SIZE 32*1024
#define L2_SIZE 256*1024
#define PAGE_SIZE 4*1024
......@@ -24,7 +26,8 @@
#define L1_LL_SIZE 5*5*L1_SIZE
#define L2_LL_SIZE 5*5*L2_SIZE
#define TLB_LL_SIZE TLB_ASSOC*TLB_ENTRIES*8*10
#define MM_SIZE L1_SIZE/4
// #define MM_SIZE L1_SIZE/4
#define MM_SIZE 1024
#define MSR_RAPL_POWER_UNIT 0x606
......@@ -98,4 +101,11 @@
int open_msr(int core);
long long read_msr(int fd, int which);
void sig_handler(int signum);
int get_cpu_info(int cpu_model, int cpu_info[3], double energy_units[2]);
void measure_msr(char* filename, void (*funcptr)());
int cpu_info[3];
double energy_units[2];
double reading;
FILE *fptr;
This diff is collapsed.
********* bc *********
energy consumed: 16.270386
energy consumed: 16.436829
Performance counter stats for '/homes/sys/suneja/treehouse/single-server-etrace/benchmarks/gapbs/build/bc -g 10 -n 1':
1,317,513 L1-icache-load-misses (39.97%)
5,748,132,504 cycles (53.00%)
3,780,595,818 cycle_activity.cycles_no_execute (54.40%)
2,265,984,682 instructions # 0.39 insn per cycle (67.12%)
1,140,725 l2_rqsts.miss (68.55%)
336,691 dTLB-load-misses (70.03%)
2,343,901 L1-dcache-load-misses (70.20%)
33,524 iTLB-load-misses (55.95%)
2,264 LLC-load-misses (40.90%)
1,699,080 L1-icache-load-misses (40.78%)
5,699,354,075 cycles (54.08%)
3,761,727,166 cycle_activity.cycles_no_execute (54.64%)
2,260,994,450 instructions # 0.40 insn per cycle (66.34%)
1,212,829 l2_rqsts.miss (67.88%)
200,202 dTLB-load-misses (69.65%)
2,368,903 L1-dcache-load-misses (70.10%)
27,156 iTLB-load-misses (55.16%)
1,860 LLC-load-misses (41.78%)
0.164407234 seconds time elapsed
0.166086945 seconds time elapsed
********* bfs *********
energy consumed: 13.098206
energy consumed: 12.690674
Performance counter stats for '/homes/sys/suneja/treehouse/single-server-etrace/benchmarks/gapbs/build/bfs -g 10 -n 1':
986,953 L1-icache-load-misses (40.44%)
4,462,342,907 cycles (51.92%)
2,945,300,555 cycle_activity.cycles_no_execute (54.24%)
1,765,950,369 instructions # 0.40 insn per cycle (65.56%)
986,530 l2_rqsts.miss (67.86%)
241,789 dTLB-load-misses (70.71%)
1,680,535 L1-dcache-load-misses (70.15%)
25,836 iTLB-load-misses (55.53%)
728 LLC-load-misses (41.07%)
1,107,304 L1-icache-load-misses (37.56%)
4,348,369,194 cycles (51.31%)
2,854,498,298 cycle_activity.cycles_no_execute (53.85%)
1,724,011,274 instructions # 0.40 insn per cycle (66.89%)
961,015 l2_rqsts.miss (67.71%)
157,857 dTLB-load-misses (70.31%)
1,537,067 L1-dcache-load-misses (72.64%)
19,757 iTLB-load-misses (56.62%)
1,692 LLC-load-misses (41.31%)
0.135875754 seconds time elapsed
0.130066105 seconds time elapsed
********* cc *********
energy consumed: 10.851562
energy consumed: 11.344421
Performance counter stats for '/homes/sys/suneja/treehouse/single-server-etrace/benchmarks/gapbs/build/cc -g 10 -n 1':
521,830 L1-icache-load-misses (33.96%)
3,943,950,262 cycles (46.02%)
2,571,714,158 cycle_activity.cycles_no_execute (50.22%)
1,548,869,904 instructions # 0.39 insn per cycle (64.54%)
703,233 l2_rqsts.miss (69.13%)
159,765 dTLB-load-misses (73.63%)
1,146,086 L1-dcache-load-misses (75.84%)
13,230 iTLB-load-misses (58.71%)
2,052 LLC-load-misses (38.51%)
1,190,583 L1-icache-load-misses (38.62%)
3,946,377,568 cycles (51.91%)
2,625,438,509 cycle_activity.cycles_no_execute (54.85%)
1,570,912,417 instructions # 0.40 insn per cycle (67.29%)
896,155 l2_rqsts.miss (71.48%)
148,057 dTLB-load-misses (72.99%)
1,657,101 L1-dcache-load-misses (70.98%)
19,642 iTLB-load-misses (54.30%)
231 LLC-load-misses (36.77%)
0.111131435 seconds time elapsed
0.116891287 seconds time elapsed
********* cc_sv *********
energy consumed: 12.536682
energy consumed: 12.314270
Performance counter stats for '/homes/sys/suneja/treehouse/single-server-etrace/benchmarks/gapbs/build/cc_sv -g 10 -n 1':
822,402 L1-icache-load-misses (40.98%)
4,297,061,655 cycles (53.90%)
2,844,930,438 cycle_activity.cycles_no_execute (55.68%)
1,712,174,504 instructions # 0.40 insn per cycle (68.32%)
872,453 l2_rqsts.miss (69.21%)
168,385 dTLB-load-misses (70.41%)
1,247,252 L1-dcache-load-misses (69.08%)
17,790 iTLB-load-misses (54.15%)
1,500 LLC-load-misses (40.48%)
1,033,315 L1-icache-load-misses (41.40%)
4,290,480,362 cycles (53.54%)
2,815,212,359 cycle_activity.cycles_no_execute (55.04%)
1,697,645,725 instructions # 0.40 insn per cycle (65.90%)
962,305 l2_rqsts.miss (66.54%)
220,918 dTLB-load-misses (67.76%)
1,669,248 L1-dcache-load-misses (70.57%)
25,839 iTLB-load-misses (55.69%)
449 LLC-load-misses (43.00%)
0.128010521 seconds time elapsed
0.126721249 seconds time elapsed
********* graph500 *********
energy consumed: 11592.145508
energy consumed: 7315.767639
Performance counter stats for 'mpirun --allow-run-as-root --mca orte_base_help_aggregate 0 /homes/sys/suneja/treehouse/single-server-etrace/benchmarks/graph500/build/err_bfs 10':
98,699,460 L1-icache-load-misses (44.44%)
2,332,035,353,759 cycles (55.55%)
1,152,715,011,364 cycle_activity.cycles_no_execute (55.55%)
1,850,752,817,861 instructions # 0.79 insn per cycle (66.67%)
98,191,039 l2_rqsts.miss (66.67%)
7,238,790 dTLB-load-misses (66.67%)
258,107,081 L1-dcache-load-misses (66.67%)
4,242,931 iTLB-load-misses (55.55%)
491,002 LLC-load-misses (44.44%)
68,218,274 L1-icache-load-misses (44.44%)
1,474,840,161,372 cycles (55.54%)
728,056,171,420 cycle_activity.cycles_no_execute (55.53%)
1,181,545,305,536 instructions # 0.80 insn per cycle (66.65%)
74,692,596 l2_rqsts.miss (66.66%)
5,435,322 dTLB-load-misses (66.67%)
162,300,961 L1-dcache-load-misses (66.68%)
2,923,076 iTLB-load-misses (55.57%)
661,043 LLC-load-misses (44.45%)
111.573353900 seconds time elapsed
70.666371126 seconds time elapsed
********* graph500 *********
energy consumed: 6648.644470
energy consumed: -261653.963745
Performance counter stats for 'mpirun --allow-run-as-root --mca orte_base_help_aggregate 0 /homes/sys/suneja/treehouse/single-server-etrace/benchmarks/graph500/build/err_bfs 5':
57,714,008 L1-icache-load-misses (44.44%)
1,339,595,077,610 cycles (55.54%)
665,801,528,036 cycle_activity.cycles_no_execute (55.54%)
1,051,534,441,842 instructions # 0.78 insn per cycle (66.66%)
52,637,068 l2_rqsts.miss (66.67%)
4,428,000 dTLB-load-misses (66.67%)
131,650,843 L1-dcache-load-misses (66.67%)
2,631,684 iTLB-load-misses (55.57%)
491,024 LLC-load-misses (44.44%)
14,826,075 L1-icache-load-misses (44.31%)
105,809,742,622 cycles (55.51%)
52,828,424,983 cycle_activity.cycles_no_execute (55.64%)
81,347,638,321 instructions # 0.77 insn per cycle (66.82%)
33,051,302 l2_rqsts.miss (66.88%)
2,200,341 dTLB-load-misses (66.89%)
44,803,813 L1-dcache-load-misses (66.72%)
995,298 iTLB-load-misses (55.37%)
477,402 LLC-load-misses (44.19%)
64.285067760 seconds time elapsed
5.386520128 seconds time elapsed
********* graph500 *********
energy consumed: 6912.886353
energy consumed: 2162.643616
Performance counter stats for 'mpirun --allow-run-as-root --mca orte_base_help_aggregate 0 /homes/sys/suneja/treehouse/single-server-etrace/benchmarks/graph500/build/err_bfs 7':
61,432,088 L1-icache-load-misses (44.44%)
1,388,704,608,402 cycles (55.54%)
688,698,870,707 cycle_activity.cycles_no_execute (55.53%)
1,099,346,020,009 instructions # 0.79 insn per cycle (66.65%)
57,035,867 l2_rqsts.miss (66.66%)
3,720,605 dTLB-load-misses (66.67%)
166,557,847 L1-dcache-load-misses (66.68%)
3,597,340 iTLB-load-misses (55.58%)
660,096 LLC-load-misses (44.45%)
29,166,265 L1-icache-load-misses (44.44%)
439,278,004,248 cycles (55.55%)
216,548,398,356 cycle_activity.cycles_no_execute (55.54%)
348,518,350,083 instructions # 0.79 insn per cycle (66.67%)
37,689,328 l2_rqsts.miss (66.67%)
3,144,280 dTLB-load-misses (66.68%)
86,998,922 L1-dcache-load-misses (66.67%)
1,537,667 iTLB-load-misses (55.57%)
351,358 LLC-load-misses (44.43%)
66.593541155 seconds time elapsed
21.324661887 seconds time elapsed
********* graph500 *********
energy consumed: 55534.383545
energy consumed: 30378.670776
Performance counter stats for 'mpirun --allow-run-as-root --mca orte_base_help_aggregate 0 /homes/sys/suneja/treehouse/single-server-etrace/benchmarks/graph500/build/err_sssp 10':
433,632,630 L1-icache-load-misses (44.44%)
11,135,824,616,281 cycles (55.56%)
5,473,242,088,074 cycle_activity.cycles_no_execute (55.56%)
9,000,792,212,049 instructions # 0.81 insn per cycle (66.67%)
275,758,467 l2_rqsts.miss (66.67%)
19,917,309 dTLB-load-misses (66.67%)
979,053,106 L1-dcache-load-misses (66.67%)
18,082,953 iTLB-load-misses (55.55%)
505,250 LLC-load-misses (44.44%)
247,144,091 L1-icache-load-misses (44.44%)
6,093,495,981,209 cycles (55.55%)
2,995,936,592,528 cycle_activity.cycles_no_execute (55.55%)
4,934,513,027,092 instructions # 0.81 insn per cycle (66.67%)
175,090,009 l2_rqsts.miss (66.66%)
14,607,687 dTLB-load-misses (66.66%)
453,875,342 L1-dcache-load-misses (66.67%)
8,290,053 iTLB-load-misses (55.56%)
693,911 LLC-load-misses (44.45%)
531.189131356 seconds time elapsed
290.918637256 seconds time elapsed
********* graph500 *********
energy consumed: 1392.513306
energy consumed: 9996.351929
Performance counter stats for 'mpirun --allow-run-as-root --mca orte_base_help_aggregate 0 /homes/sys/suneja/treehouse/single-server-etrace/benchmarks/graph500/build/err_sssp 5':
24,555,265 L1-icache-load-misses (44.45%)
285,392,534,393 cycles (55.55%)
142,691,242,015 cycle_activity.cycles_no_execute (55.51%)
216,933,940,444 instructions # 0.76 insn per cycle (66.64%)
35,934,839 l2_rqsts.miss (66.63%)
2,241,228 dTLB-load-misses (66.64%)
65,650,795 L1-dcache-load-misses (66.68%)
1,335,792 iTLB-load-misses (55.62%)
526,891 LLC-load-misses (44.48%)
85,304,279 L1-icache-load-misses (44.44%)
2,007,011,249,671 cycles (55.55%)
995,820,691,821 cycle_activity.cycles_no_execute (55.56%)
1,578,038,456,142 instructions # 0.79 insn per cycle (66.67%)
69,862,772 l2_rqsts.miss (66.67%)
4,793,871 dTLB-load-misses (66.67%)
202,389,472 L1-dcache-load-misses (66.67%)
3,396,159 iTLB-load-misses (55.56%)
606,285 LLC-load-misses (44.44%)
13.938336494 seconds time elapsed
96.046208104 seconds time elapsed
********* graph500 *********
energy consumed: 25180.204590
energy consumed: 39621.261475
Performance counter stats for 'mpirun --allow-run-as-root --mca orte_base_help_aggregate 0 /homes/sys/suneja/treehouse/single-server-etrace/benchmarks/graph500/build/err_sssp 7':
198,047,737 L1-icache-load-misses (44.44%)
5,052,489,829,550 cycles (55.55%)
2,490,755,529,486 cycle_activity.cycles_no_execute (55.56%)
4,037,942,862,600 instructions # 0.80 insn per cycle (66.67%)
130,438,276 l2_rqsts.miss (66.67%)
8,730,454 dTLB-load-misses (66.67%)
390,230,286 L1-dcache-load-misses (66.67%)
6,511,198 iTLB-load-misses (55.56%)
384,875 LLC-load-misses (44.44%)
305,617,322 L1-icache-load-misses (44.45%)
7,941,593,121,825 cycles (55.56%)
3,913,962,190,944 cycle_activity.cycles_no_execute (55.55%)
6,396,995,410,148 instructions # 0.81 insn per cycle (66.67%)
183,576,848 l2_rqsts.miss (66.67%)
12,006,762 dTLB-load-misses (66.66%)
887,132,284 L1-dcache-load-misses (66.67%)
12,268,891 iTLB-load-misses (55.56%)
584,500 LLC-load-misses (44.45%)
241.252330907 seconds time elapsed
378.973453342 seconds time elapsed
*******************************Average over 1 runs: 208.768921 *******************************
*******************************Average over 1 runs: 230.815369 *******************************
Performance counter stats for '/homes/sys/suneja/treehouse/single-server-etrace/benchmarks/tests/msr/build/l1_msr':
178,414 L1-icache-load-misses (44.45%)
6,546,702,787 cycles (55.56%)
1,376,557,774 cycle_activity.cycles_no_execute (55.56%)
6,006,379,928 instructions # 0.92 insn per cycle (66.67%)
69,852,682 l2_rqsts.miss (66.67%)
123,396 dTLB-load-misses (66.67%)
817,018,435 L1-dcache-load-misses (66.66%)
13,969 iTLB-load-misses (55.55%)
7 LLC-load-misses (44.44%)
125,590 L1-icache-load-misses (44.14%)
7,559,444,092 cycles (55.31%)
1,808,223,419 cycle_activity.cycles_no_execute (55.42%)
6,009,341,465 instructions # 0.79 insn per cycle (66.59%)
56,604,712 l2_rqsts.miss (66.74%)
3,953,061 dTLB-load-misses (66.89%)
819,630,805 L1-dcache-load-misses (66.93%)
270 iTLB-load-misses (55.60%)
2,572 LLC-load-misses (44.28%)