Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MojitOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sepia-pub
MojitOS
Commits
c9e184e1
Commit
c9e184e1
authored
4 years ago
by
Georges Da Costa
Browse files
Options
Downloads
Patches
Plain Diff
Refactors of the network monitoring infrastructure
parent
1b2a4032
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
infiniband.c
+21
-6
21 additions, 6 deletions
infiniband.c
mojitos.c
+40
-42
40 additions, 42 deletions
mojitos.c
network.c
+47
-19
47 additions, 19 deletions
network.c
network.h
+5
-3
5 additions, 3 deletions
network.h
with
113 additions
and
70 deletions
infiniband.c
+
21
−
6
View file @
c9e184e1
...
@@ -24,9 +24,19 @@
...
@@ -24,9 +24,19 @@
#include
<glob.h>
#include
<glob.h>
int
*
init_infiniband
(
char
*
infi_path
)
{
#include
<stdint.h>
struct
network_t
{
uint64_t
values
[
4
];
uint64_t
tmp_values
[
4
];
int
sources
[
4
];
};
unsigned
int
_get_network
(
uint64_t
*
results
,
int
*
sources
);
unsigned
int
init_infiniband
(
char
*
infi_path
,
void
**
ptr
)
{
if
(
infi_path
==
NULL
)
if
(
infi_path
==
NULL
)
return
NULL
;
return
0
;
if
(
strcmp
(
infi_path
,
"X"
)
==
0
)
{
if
(
strcmp
(
infi_path
,
"X"
)
==
0
)
{
...
@@ -34,7 +44,7 @@ int *init_infiniband(char* infi_path) {
...
@@ -34,7 +44,7 @@ int *init_infiniband(char* infi_path) {
glob
(
"/sys/class/infiniband/*/ports/*/counters/"
,
0
,
NULL
,
&
res
);
glob
(
"/sys/class/infiniband/*/ports/*/counters/"
,
0
,
NULL
,
&
res
);
if
(
res
.
gl_pathc
==
0
)
if
(
res
.
gl_pathc
==
0
)
return
NULL
;
return
0
;
infi_path
=
res
.
gl_pathv
[
0
];
infi_path
=
res
.
gl_pathv
[
0
];
}
}
...
@@ -42,14 +52,19 @@ int *init_infiniband(char* infi_path) {
...
@@ -42,14 +52,19 @@ int *init_infiniband(char* infi_path) {
"%s/port_rcv_data"
,
"%s/port_rcv_data"
,
"%s/port_xmit_packets"
,
"%s/port_xmit_packets"
,
"%s/port_xmit_data"
};
"%s/port_xmit_data"
};
int
*
sources
=
malloc
(
sizeof
(
int
)
*
4
);
struct
network_t
*
state
=
malloc
(
sizeof
(
struct
network_t
));
char
buffer
[
1024
];
char
buffer
[
1024
];
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
sprintf
(
buffer
,
filenames
[
i
],
infi_path
);
sprintf
(
buffer
,
filenames
[
i
],
infi_path
);
sources
[
i
]
=
open
(
buffer
,
O_RDONLY
);
state
->
sources
[
i
]
=
open
(
buffer
,
O_RDONLY
);
}
}
*
ptr
=
(
void
*
)
state
;
_get_network
(
state
->
values
,
state
->
sources
);
return
sources
;
return
4
;
}
}
/* void get_network(long long* results, char** sources) { */
/* void get_network(long long* results, char** sources) { */
...
...
This diff is collapsed.
Click to expand it.
mojitos.c
+
40
−
42
View file @
c9e184e1
...
@@ -146,8 +146,6 @@ int main(int argc, char **argv) {
...
@@ -146,8 +146,6 @@ int main(int argc, char **argv) {
int
total_time
=
1
;
int
total_time
=
1
;
int
delta
=
0
;
int
delta
=
0
;
int
frequency
=
1
;
int
frequency
=
1
;
char
*
dev
=
NULL
;
char
*
infi_path
=
NULL
;
char
**
application
=
NULL
;
char
**
application
=
NULL
;
int
rapl_mode
=
-
1
;
int
rapl_mode
=
-
1
;
...
@@ -177,10 +175,10 @@ int main(int argc, char **argv) {
...
@@ -177,10 +175,10 @@ int main(int argc, char **argv) {
}
}
break
;
break
;
case
'd'
:
case
'd'
:
dev
=
argv
[
optind
]
;
add_source
(
init_network
,
argv
[
optind
],
label_network
,
get_network
,
clean_network
)
;
break
;
break
;
case
'i'
:
case
'i'
:
infi_path
=
argv
[
optind
]
;
add_source
(
init_infiniband
,
argv
[
optind
],
label_network
,
get_network
,
clean_network
)
;
break
;
break
;
case
'o'
:
case
'o'
:
output
=
fopen
(
argv
[
optind
],
"wb"
);
output
=
fopen
(
argv
[
optind
],
"wb"
);
...
@@ -210,22 +208,22 @@ int main(int argc, char **argv) {
...
@@ -210,22 +208,22 @@ int main(int argc, char **argv) {
}
}
// Network initialization
/*
// Network initialization
*/
int
*
network_sources
=
NULL
;
/*
int *network_sources = NULL;
*/
if
(
dev
!=
NULL
)
/*
if(dev != NULL)
*/
network_sources
=
init_network
(
dev
);
/*
network_sources = init_network(dev);
*/
uint64_t
network_values
[
4
]
=
{
0
,
0
,
0
,
0
};
/*
uint64_t network_values[4]={0,0,0,0};
*/
uint64_t
tmp_network_values
[
4
]
=
{
0
,
0
,
0
,
0
};
/*
uint64_t tmp_network_values[4]={0,0,0,0};
*/
get_network
(
network_values
,
network_sources
);
/*
get_network(network_values, network_sources);
*/
int
*
infiniband_sources
=
NULL
;
/*
int * infiniband_sources = NULL;
*/
if
(
infi_path
!=
NULL
)
/*
if(infi_path != NULL)
*/
infiniband_sources
=
init_infiniband
(
infi_path
);
/*
infiniband_sources = init_infiniband(infi_path);
*/
if
(
infiniband_sources
==
NULL
)
/*
if(infiniband_sources == NULL)
*/
infi_path
=
NULL
;
/*
infi_path = NULL;
*/
uint64_t
infiniband_values
[
4
]
=
{
0
,
0
,
0
,
0
};
/*
uint64_t infiniband_values[4]={0,0,0,0};
*/
uint64_t
tmp_infiniband_values
[
4
]
=
{
0
,
0
,
0
,
0
};
/*
uint64_t tmp_infiniband_values[4]={0,0,0,0};
*/
get_network
(
infiniband_values
,
infiniband_sources
);
/*
get_network(infiniband_values, infiniband_sources);
*/
// RAPL initialization
// RAPL initialization
_rapl_t
*
rapl
=
NULL
;
_rapl_t
*
rapl
=
NULL
;
...
@@ -265,10 +263,10 @@ int main(int argc, char **argv) {
...
@@ -265,10 +263,10 @@ int main(int argc, char **argv) {
if
(
perf_mode
==
0
)
if
(
perf_mode
==
0
)
for
(
int
i
=
0
;
i
<
nb_perf
;
i
++
)
for
(
int
i
=
0
;
i
<
nb_perf
;
i
++
)
fprintf
(
output
,
"%s "
,
perf_static_info
[
perf_indexes
[
i
]].
name
);
fprintf
(
output
,
"%s "
,
perf_static_info
[
perf_indexes
[
i
]].
name
);
if
(
dev
!=
NULL
)
/*
if(dev!=NULL)
*/
fprintf
(
output
,
"rxp rxb txp txb "
);
/*
fprintf(output, "rxp rxb txp txb ");
*/
if
(
infi_path
!=
NULL
)
/*
if(infi_path!=NULL)
*/
fprintf
(
output
,
"irxp irxb itxp itxb "
);
/*
fprintf(output, "irxp irxb itxp itxb ");
*/
if
(
rapl_mode
==
0
)
if
(
rapl_mode
==
0
)
for
(
int
r
=
0
;
r
<
nb_rapl
;
r
++
)
for
(
int
r
=
0
;
r
<
nb_rapl
;
r
++
)
...
@@ -296,10 +294,10 @@ int main(int argc, char **argv) {
...
@@ -296,10 +294,10 @@ int main(int argc, char **argv) {
// Get Data
// Get Data
if
(
perf_mode
==
0
)
if
(
perf_mode
==
0
)
get_counters
(
fd
,
tmp_counter_values
);
get_counters
(
fd
,
tmp_counter_values
);
if
(
dev
!=
NULL
)
//
if(dev != NULL)
get_network
(
tmp_network_values
,
network_sources
);
//
get_network(tmp_network_values, network_sources);
if
(
infi_path
!=
NULL
)
//
if(infi_path != NULL)
get_network
(
tmp_infiniband_values
,
infiniband_sources
);
//
get_network(tmp_infiniband_values, infiniband_sources);
if
(
rapl_mode
==
0
)
if
(
rapl_mode
==
0
)
get_rapl
(
tmp_rapl_values
,
rapl
);
get_rapl
(
tmp_rapl_values
,
rapl
);
...
@@ -343,12 +341,12 @@ int main(int argc, char **argv) {
...
@@ -343,12 +341,12 @@ int main(int argc, char **argv) {
if
(
perf_mode
==
0
)
if
(
perf_mode
==
0
)
for
(
int
i
=
0
;
i
<
nb_perf
;
i
++
)
for
(
int
i
=
0
;
i
<
nb_perf
;
i
++
)
fprintf
(
output
,
"%"
PRIu64
" "
,
tmp_counter_values
[
i
]
-
counter_values
[
i
]);
fprintf
(
output
,
"%"
PRIu64
" "
,
tmp_counter_values
[
i
]
-
counter_values
[
i
]);
if
(
dev
!=
NULL
)
/*
if(dev != NULL)
*/
for
(
int
i
=
0
;
i
<
4
;
i
++
)
/*
for(int i=0; i<4; i++)
*/
fprintf
(
output
,
"%"
PRIu64
" "
,
tmp_network_values
[
i
]
-
network_values
[
i
]);
/*
fprintf(output, "%" PRIu64 " ", tmp_network_values[i]-network_values[i]);
*/
if
(
infi_path
!=
NULL
)
/*
if(infi_path != NULL)
*/
for
(
int
i
=
0
;
i
<
4
;
i
++
)
/*
for(int i=0; i<4; i++)
*/
fprintf
(
output
,
"%"
PRIu64
" "
,
tmp_infiniband_values
[
i
]
-
infiniband_values
[
i
]);
/*
fprintf(output, "%" PRIu64 " ", tmp_infiniband_values[i]-infiniband_values[i]);
*/
if
(
rapl_mode
==
0
)
if
(
rapl_mode
==
0
)
for
(
int
r
=
0
;
r
<
nb_rapl
;
r
++
)
for
(
int
r
=
0
;
r
<
nb_rapl
;
r
++
)
fprintf
(
output
,
"%"
PRIu64
" "
,
tmp_rapl_values
[
r
]
-
rapl_values
[
r
]);
fprintf
(
output
,
"%"
PRIu64
" "
,
tmp_rapl_values
[
r
]
-
rapl_values
[
r
]);
...
@@ -369,10 +367,10 @@ int main(int argc, char **argv) {
...
@@ -369,10 +367,10 @@ int main(int argc, char **argv) {
if
(
rapl_mode
==
0
)
if
(
rapl_mode
==
0
)
memcpy
(
rapl_values
,
tmp_rapl_values
,
nb_rapl
*
sizeof
(
uint64_t
));
memcpy
(
rapl_values
,
tmp_rapl_values
,
nb_rapl
*
sizeof
(
uint64_t
));
if
(
dev
!=
NULL
)
/*
if(dev !=NULL)
*/
memcpy
(
network_values
,
tmp_network_values
,
sizeof
(
network_values
));
/*
memcpy(network_values, tmp_network_values, sizeof(network_values));
*/
if
(
infi_path
!=
NULL
)
/*
if(infi_path !=NULL)
*/
memcpy
(
infiniband_values
,
tmp_infiniband_values
,
sizeof
(
infiniband_values
));
/*
memcpy(infiniband_values, tmp_infiniband_values, sizeof(infiniband_values));
*/
clock_gettime
(
CLOCK_MONOTONIC
,
&
ts
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
ts
);
usleep
(
1000
*
1000
/
frequency
-
(
ts
.
tv_nsec
/
1000
)
%
(
1000
*
1000
/
frequency
));
usleep
(
1000
*
1000
/
frequency
-
(
ts
.
tv_nsec
/
1000
)
%
(
1000
*
1000
/
frequency
));
}
}
...
@@ -385,10 +383,10 @@ int main(int argc, char **argv) {
...
@@ -385,10 +383,10 @@ int main(int argc, char **argv) {
for
(
int
i
=
0
;
i
<
nb_sources
;
i
++
)
for
(
int
i
=
0
;
i
<
nb_sources
;
i
++
)
cleaner
[
i
](
states
[
i
]);
cleaner
[
i
](
states
[
i
]);
if
(
dev
!=
NULL
)
/*
if(dev!=NULL)
*/
clean_network
(
network_sources
);
/*
clean_network(network_sources);
*/
if
(
infi_path
!=
NULL
)
/*
if(infi_path!=NULL)
*/
clean_network
(
infiniband_sources
);
/*
clean_network(infiniband_sources);
*/
if
(
perf_mode
==
0
){
if
(
perf_mode
==
0
){
clean_counters
(
fd
);
clean_counters
(
fd
);
free
(
counter_values
);
free
(
counter_values
);
...
...
This diff is collapsed.
Click to expand it.
network.c
+
47
−
19
View file @
c9e184e1
...
@@ -24,9 +24,29 @@
...
@@ -24,9 +24,29 @@
#include
<string.h>
#include
<string.h>
#include
<stdint.h>
#include
<stdint.h>
int
*
init_network
(
char
*
dev
)
{
struct
network_t
{
uint64_t
values
[
4
];
uint64_t
tmp_values
[
4
];
int
sources
[
4
];
};
unsigned
int
_get_network
(
uint64_t
*
results
,
int
*
sources
)
{
if
(
sources
==
NULL
)
return
0
;
char
buffer
[
128
];
for
(
int
i
=
0
;
i
<
4
;
i
++
){
pread
(
sources
[
i
],
buffer
,
127
,
0
);
results
[
i
]
=
strtoull
(
buffer
,
NULL
,
10
);
}
return
4
;
}
unsigned
int
init_network
(
char
*
dev
,
void
**
ptr
)
{
if
(
dev
==
NULL
)
if
(
dev
==
NULL
)
return
NULL
;
return
0
;
if
(
strcmp
(
dev
,
"X"
)
==
0
)
{
if
(
strcmp
(
dev
,
"X"
)
==
0
)
{
int
f
=
open
(
"/proc/net/route"
,
O_RDONLY
);
int
f
=
open
(
"/proc/net/route"
,
O_RDONLY
);
...
@@ -43,33 +63,41 @@ int *init_network(char* dev) {
...
@@ -43,33 +63,41 @@ int *init_network(char* dev) {
"/sys/class/net/%s/statistics/rx_bytes"
,
"/sys/class/net/%s/statistics/rx_bytes"
,
"/sys/class/net/%s/statistics/tx_packets"
,
"/sys/class/net/%s/statistics/tx_packets"
,
"/sys/class/net/%s/statistics/tx_bytes"
};
"/sys/class/net/%s/statistics/tx_bytes"
};
int
*
sources
=
malloc
(
sizeof
(
int
)
*
4
);
struct
network_t
*
state
=
malloc
(
sizeof
(
struct
network_t
));
char
buffer2
[
256
];
char
buffer2
[
256
];
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
sprintf
(
buffer2
,
filenames
[
i
],
dev
);
sprintf
(
buffer2
,
filenames
[
i
],
dev
);
sources
[
i
]
=
open
(
buffer2
,
O_RDONLY
);
state
->
sources
[
i
]
=
open
(
buffer2
,
O_RDONLY
);
}
}
*
ptr
=
(
void
*
)
state
;
_get_network
(
state
->
values
,
state
->
sources
);
return
sources
;
return
4
;
}
}
void
get_network
(
uint64_t
*
results
,
int
*
sources
)
{
unsigned
int
get_network
(
uint64_t
*
results
,
void
*
ptr
)
{
if
(
sources
==
NULL
)
struct
network_t
*
state
=
(
struct
network_t
*
)
ptr
;
return
;
_get_network
(
state
->
tmp_values
,
state
->
sources
);
char
buffer
[
128
];
for
(
int
i
=
0
;
i
<
4
;
i
++
)
for
(
int
i
=
0
;
i
<
4
;
i
++
){
results
[
i
]
=
state
->
tmp_values
[
i
]
-
state
->
values
[
i
];
pread
(
sources
[
i
],
buffer
,
127
,
0
);
results
[
i
]
=
strtoull
(
buffer
,
NULL
,
10
);
memcpy
(
state
->
values
,
state
->
tmp_values
,
4
*
sizeof
(
uint64_t
));
return
4
;
//results[i] = atoll(buffer);
}
}
}
void
clean_network
(
int
*
sources
)
{
void
clean_network
(
void
*
ptr
)
{
if
(
sources
==
NULL
)
struct
network_t
*
state
=
(
struct
network_t
*
)
ptr
;
if
(
state
==
NULL
)
return
;
return
;
for
(
int
i
=
0
;
i
<
4
;
i
++
)
for
(
int
i
=
0
;
i
<
4
;
i
++
)
close
(
sources
[
i
]);
close
(
state
->
sources
[
i
]);
free
(
s
ources
);
free
(
s
tate
);
}
}
char
*
_labels_network
[
4
]
=
{
"rxp"
,
"rxb"
,
"txp"
,
"txb"
};
void
label_network
(
char
**
labels
)
{
for
(
int
i
=
0
;
i
<
4
;
i
++
)
labels
[
i
]
=
_labels_network
[
i
];
}
This diff is collapsed.
Click to expand it.
network.h
+
5
−
3
View file @
c9e184e1
...
@@ -18,6 +18,8 @@
...
@@ -18,6 +18,8 @@
*******************************************************/
*******************************************************/
int
*
init_network
(
char
*
dev
);
unsigned
int
init_network
(
char
*
,
void
**
);
void
get_network
(
uint64_t
*
results
,
int
*
sources
);
unsigned
int
get_network
(
uint64_t
*
results
,
void
*
);
void
clean_network
(
int
*
sources
);
void
clean_network
(
void
*
);
void
label_network
(
char
**
labels
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment