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
1037717e
Commit
1037717e
authored
1 year ago
by
Georges Da Costa
Browse files
Options
Downloads
Plain Diff
Merge branch 'intel_rapl' into 'main'
Intel rapl See merge request
!11
parents
c348a8df
64676909
No related branches found
No related tags found
1 merge request
!11
Intel rapl
Pipeline
#9363
passed
1 year ago
Stage: build-option
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/rapl.c
+49
-27
49 additions, 27 deletions
src/rapl.c
src/util.c
+6
-0
6 additions, 0 deletions
src/util.c
src/util.h
+1
-6
1 addition, 6 deletions
src/util.h
with
56 additions
and
33 deletions
src/rapl.c
+
49
−
27
View file @
1037717e
...
...
@@ -60,21 +60,25 @@ struct IntelRapl {
int
*
fids
;
uint64_t
*
values
;
uint64_t
*
tmp_values
;
uint64_t
*
modulo
;
};
typedef
struct
IntelRapl
IntelRapl
;
void
add_rapl_source
(
IntelRapl
*
rapl
,
char
*
name
,
char
*
energy_uj
)
void
add_rapl_source
(
IntelRapl
*
rapl
,
char
*
name
,
uint64_t
modulo
,
char
*
energy_uj
)
{
rapl
->
nb
+=
1
;
rapl
->
names
=
realloc
(
rapl
->
names
,
sizeof
(
char
**
)
*
rapl
->
nb
);
rapl
->
fids
=
realloc
(
rapl
->
fids
,
sizeof
(
int
*
)
*
rapl
->
nb
);
rapl
->
modulo
=
realloc
(
rapl
->
modulo
,
sizeof
(
uint64_t
)
*
rapl
->
nb
);
rapl
->
names
[
rapl
->
nb
-
1
]
=
malloc
(
strlen
(
name
)
+
1
);
strcpy
(
rapl
->
names
[
rapl
->
nb
-
1
],
name
);
//printf("%s\n", energy_uj);
rapl
->
modulo
[
rapl
->
nb
-
1
]
=
modulo
;
int
fd
=
open
(
energy_uj
,
O_RDONLY
);
if
(
fd
<
0
)
{
...
...
@@ -102,6 +106,28 @@ void _get_rapl(uint64_t *values, IntelRapl *rapl)
}
}
int
add_rapl_source_from_str
(
IntelRapl
*
rapl
,
const
char
*
name_base
,
const
int
i
)
{
char
buffer
[
BUFFER_SIZE
];
snprintf
(
buffer
,
BUFFER_SIZE
,
name_base
,
i
);
strcat
(
buffer
,
"name"
);
char
*
tmp
=
get_rapl_string
(
buffer
);
if
(
tmp
==
NULL
)
return
0
;
append
(
tmp
,
i
,
MAX_HEADER
);
// tmp contains the name with its index. ex: dram0
snprintf
(
buffer
,
BUFFER_SIZE
,
name_base
,
i
);
strcat
(
buffer
,
"max_energy_range_uj"
);
uint64_t
modulo
=
strtoull
(
get_rapl_string
(
buffer
),
NULL
,
10
);
snprintf
(
buffer
,
BUFFER_SIZE
,
name_base
,
i
);
strcat
(
buffer
,
"energy_uj"
);
add_rapl_source
(
rapl
,
tmp
,
modulo
,
buffer
);
free
(
tmp
);
return
1
;
}
unsigned
int
init_rapl
(
char
*
none
,
void
**
ptr
)
{
...
...
@@ -110,38 +136,25 @@ unsigned int init_rapl(char *none, void **ptr)
rapl
->
nb
=
0
;
rapl
->
names
=
NULL
;
rapl
->
fids
=
NULL
;
rapl
->
modulo
=
NULL
;
char
buffer
[
BUFFER_SIZE
];
char
*
name_base
=
"/sys/devices/virtual/powercap/intel-rapl/intel-rapl:%d/
%s
"
;
char
*
name_sub
=
"/sys/devices/virtual/powercap/intel-rapl/intel-rapl:%d/intel-rapl:%d:%
d/%
s"
;
char
*
name_base
=
"/sys/devices/virtual/powercap/intel-rapl/intel-rapl:%d/"
;
char
*
name_sub
=
"/sys/devices/virtual/powercap/intel-rapl/intel-rapl:%d/intel-rapl:%d:%s
/
"
;
for
(
unsigned
int
i
=
0
;;
i
++
)
{
snprintf
(
buffer
,
BUFFER_SIZE
,
name_base
,
i
,
"name"
);
char
*
tmp
=
get_rapl_string
(
buffer
);
if
(
tmp
==
NULL
)
{
break
;
}
append
(
tmp
,
i
,
MAX_HEADER
);
snprintf
(
buffer
,
BUFFER_SIZE
,
name_base
,
i
,
"energy_uj"
);
add_rapl_source
(
rapl
,
tmp
,
buffer
);
free
(
tmp
);
for
(
unsigned
int
j
=
0
;;
j
++
)
{
snprintf
(
buffer
,
BUFFER_SIZE
,
name_sub
,
i
,
i
,
j
,
"name"
);
char
*
tmp_sub
=
get_rapl_string
(
buffer
);
if
(
!
add_rapl_source_from_str
(
rapl
,
name_base
,
i
))
break
;
if
(
tmp_sub
==
NULL
)
{
break
;
}
for
(
unsigned
int
j
=
0
;;
j
++
)
{
snprintf
(
buffer
,
BUFFER_SIZE
,
name_sub
,
i
,
i
,
"%d"
);
append
(
tmp_sub
,
i
,
MAX_HEADER
);
snprintf
(
buffer
,
BUFFER_SIZE
,
name_sub
,
i
,
i
,
j
,
"energy_uj"
);
add_rapl_source
(
rapl
,
tmp_sub
,
buffer
);
if
(
!
add_rapl_source_from_str
(
rapl
,
buffer
,
j
))
break
;
free
(
tmp_sub
);
}
}
}
rapl
->
values
=
calloc
(
sizeof
(
uint64_t
),
rapl
->
nb
);
...
...
@@ -159,8 +172,17 @@ unsigned int get_rapl(uint64_t *results, void *ptr)
IntelRapl
*
state
=
(
IntelRapl
*
)
ptr
;
_get_rapl
(
state
->
tmp_values
,
state
);
fprintf
(
stderr
,
"RAPL
\t
"
);
for
(
unsigned
int
i
=
0
;
i
<
state
->
nb
;
i
++
)
{
fprintf
(
stderr
,
"%"
PRIu64
"
\t
"
,
state
->
values
[
i
]);
}
fprintf
(
stderr
,
"
\n
"
);
for
(
unsigned
int
i
=
0
;
i
<
state
->
nb
;
i
++
)
{
results
[
i
]
=
modulo_substraction
(
state
->
tmp_values
[
i
],
state
->
values
[
i
]);
results
[
i
]
=
modulo_substraction_bound
(
state
->
tmp_values
[
i
],
state
->
values
[
i
],
state
->
modulo
[
i
]);
}
memcpy
(
state
->
values
,
state
->
tmp_values
,
sizeof
(
uint64_t
)
*
state
->
nb
);
...
...
This diff is collapsed.
Click to expand it.
src/util.c
+
6
−
0
View file @
1037717e
...
...
@@ -26,3 +26,9 @@ uint64_t modulo_substraction(const uint64_t lhs, const uint64_t rhs)
return
lhs
>=
rhs
?
(
lhs
-
rhs
)
:
(
UINT64_MAX
-
rhs
+
1
)
+
lhs
;
}
uint64_t
modulo_substraction_bound
(
const
uint64_t
lhs
,
const
uint64_t
rhs
,
const
uint64_t
modulo
)
{
return
lhs
>=
rhs
?
(
lhs
-
rhs
)
:
(
modulo
-
rhs
+
1
)
+
lhs
;
}
This diff is collapsed.
Click to expand it.
src/util.h
+
1
−
6
View file @
1037717e
...
...
@@ -23,12 +23,6 @@
#include
<stdint.h>
#define CASSERT(predicate, file) _impl_CASSERT_LINE(predicate,__LINE__,file)
#define _impl_PASTE(a,b) a##b
#define _impl_CASSERT_LINE(predicate, line, file) \
typedef char _impl_PASTE(assertion_failed_##file##_,line)[2*!!(predicate)-1];
#define UNUSED(expr) do { (void)(expr); } while (0)
#define PANIC(code, fmt, ...) \
do { \
...
...
@@ -49,5 +43,6 @@
* @return uint64_t
*/
uint64_t
modulo_substraction
(
const
uint64_t
lhs
,
const
uint64_t
rhs
);
uint64_t
modulo_substraction_bound
(
const
uint64_t
lhs
,
const
uint64_t
rhs
,
const
uint64_t
modulo
);
#endif
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