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
401520c3
Commit
401520c3
authored
4 years ago
by
Georges Da Costa
Browse files
Options
Downloads
Patches
Plain Diff
Adds temperature sensor
parent
a3d535e3
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
makefile
+1
-1
1 addition, 1 deletion
makefile
mojitos.c
+7
-3
7 additions, 3 deletions
mojitos.c
temperature.c
+137
-0
137 additions, 0 deletions
temperature.c
temperature.h
+24
-0
24 additions, 0 deletions
temperature.h
with
169 additions
and
4 deletions
makefile
+
1
−
1
View file @
401520c3
all
:
mojitos
OBJECTS
=
mojitos.o counters_individual.o rapl.o network.o load.o infiniband.o
OBJECTS
=
mojitos.o counters_individual.o rapl.o network.o load.o infiniband.o
temperature.o
mojitos
:
$(OBJECTS) counters_option.h
gcc
$(
DEBUG
)
-O3
-Wall
-o
mojitos
$(
OBJECTS
)
-lpowercap
...
...
This diff is collapsed.
Click to expand it.
mojitos.c
+
7
−
3
View file @
401520c3
...
...
@@ -30,7 +30,7 @@
#include
"network.h"
#include
"infiniband.h"
#include
"load.h"
#include
"temperature.h"
...
...
@@ -111,7 +111,7 @@ int main(int argc, char **argv) {
signal
(
15
,
flush
);
int
c
;
while
((
c
=
getopt
(
argc
,
argv
,
"ilhftdeoprsu"
))
!=
-
1
&&
application
==
NULL
)
while
((
c
=
getopt
(
argc
,
argv
,
"ilh
c
ftdeoprsu"
))
!=
-
1
&&
application
==
NULL
)
switch
(
c
)
{
case
'f'
:
frequency
=
atoi
(
argv
[
optind
]);
...
...
@@ -146,6 +146,9 @@ int main(int argc, char **argv) {
case
'u'
:
add_source
(
init_load
,
NULL
,
label_load
,
get_load
,
clean_load
);
break
;
case
'c'
:
add_source
(
init_temperature
,
NULL
,
label_temperature
,
get_temperature
,
clean_temperature
);
break
;
case
's'
:
stat_mode
=
0
;
break
;
...
...
@@ -155,7 +158,8 @@ int main(int argc, char **argv) {
default:
usage
(
argv
);
}
struct
timespec
ts
;
struct
timespec
ts_ref
;
...
...
This diff is collapsed.
Click to expand it.
temperature.c
0 → 100644
+
137
−
0
View file @
401520c3
/*******************************************************
Copyright (C) 2018-2021 Georges Da Costa <georges.da-costa@irit.fr>
This file is part of Mojitos.
Mojitos is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Mojitos is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MojitO/S. If not, see <https://www.gnu.org/licenses/>.
*******************************************************/
#include
<stdlib.h>
#include
<unistd.h>
#include
<fcntl.h>
#include
<string.h>
#include
<stdio.h>
#include
<stdint.h>
struct
temperature_t
{
char
**
label_list
;
int
*
fid_list
;
int
nb_elem
;
};
int
get_string
(
char
*
filename
,
char
*
buffer
,
int
max_size
)
{
int
fid
=
open
(
filename
,
O_RDONLY
);
//printf("Tries to open : %s : %d\n", filename, fid);
if
(
fid
==
-
1
)
return
-
1
;
int
nb
=
read
(
fid
,
buffer
,
max_size
);
if
(
nb
==
-
1
)
{
close
(
fid
);
return
-
1
;
}
buffer
[
nb
]
=
0
;
close
(
fid
);
return
0
;
}
void
add_to_list
(
char
***
list_name
,
char
*
source
,
int
nb_elem
)
{
//printf("Adds: %s\n", source);
*
list_name
=
realloc
(
*
list_name
,
(
nb_elem
+
1
)
*
sizeof
(
char
*
));
(
*
list_name
)[
nb_elem
]
=
malloc
(
strlen
(
source
)
+
1
);
strcpy
((
*
list_name
)[
nb_elem
],
source
);
}
void
add_temperature_sensor
(
int
id_rep
,
struct
temperature_t
*
state
)
{
static
int
key
=
0
;
static
char
buffer_filename
[
512
];
static
char
buffer_label
[
512
];
int
delta
=
sprintf
(
buffer_label
,
"Temp_%d_"
,
key
);
for
(
int
i
=
1
;;
i
++
)
{
sprintf
(
buffer_filename
,
"/sys/class/hwmon/hwmon%d/temp%d_label"
,
id_rep
,
i
);
if
(
get_string
(
buffer_filename
,
buffer_label
+
delta
,
100
)
==
-
1
)
break
;
for
(
int
pos
=
0
;
pos
<
strlen
(
buffer_label
);
pos
++
)
{
if
(
buffer_label
[
pos
]
==
' '
)
buffer_label
[
pos
]
=
'_'
;
if
(
buffer_label
[
pos
]
==
'\n'
)
buffer_label
[
pos
]
=
'\0'
;
}
add_to_list
(
&
state
->
label_list
,
buffer_label
,
state
->
nb_elem
);
sprintf
(
buffer_filename
,
"/sys/class/hwmon/hwmon%d/temp%d_input"
,
id_rep
,
i
);
state
->
fid_list
=
realloc
(
state
->
fid_list
,
(
state
->
nb_elem
+
1
)
*
sizeof
(
int
));
state
->
fid_list
[
state
->
nb_elem
]
=
open
(
buffer_filename
,
O_RDONLY
);
state
->
nb_elem
++
;
// printf("%s : %s\n", buffer_label, buffer_filename);
}
key
++
;
}
unsigned
int
init_temperature
(
char
*
args
,
void
**
ptr
)
{
struct
temperature_t
*
state
=
malloc
(
sizeof
(
struct
temperature_t
));
state
->
nb_elem
=
0
;
state
->
label_list
=
NULL
;
state
->
fid_list
=
NULL
;
char
base_name
[]
=
"/sys/class/hwmon/hwmon%d/name"
;
static
char
name
[
512
];
static
char
buffer
[
512
];
int
i
=
0
;
sprintf
(
name
,
base_name
,
i
);
while
(
get_string
(
name
,
buffer
,
8
)
!=
-
1
)
{
if
(
strcmp
(
buffer
,
"coretemp"
)
==
0
)
add_temperature_sensor
(
i
,
state
);
i
++
;
sprintf
(
name
,
base_name
,
i
);
}
*
ptr
=
(
void
*
)
state
;
return
state
->
nb_elem
;
}
unsigned
int
get_temperature
(
uint64_t
*
results
,
void
*
ptr
)
{
struct
temperature_t
*
state
=
(
struct
temperature_t
*
)
ptr
;
static
char
buffer
[
512
];
for
(
int
i
=
0
;
i
<
state
->
nb_elem
;
i
++
)
{
pread
(
state
->
fid_list
[
i
],
buffer
,
100
,
0
);
results
[
i
]
=
strtoull
(
buffer
,
NULL
,
10
);
}
return
state
->
nb_elem
;
}
void
clean_temperature
(
void
*
ptr
)
{
struct
temperature_t
*
state
=
(
struct
temperature_t
*
)
ptr
;
for
(
int
i
=
0
;
i
<
state
->
nb_elem
;
i
++
)
{
free
(
state
->
label_list
[
i
]);
close
(
state
->
fid_list
[
i
]);
}
free
(
state
->
label_list
);
free
(
state
->
fid_list
);
free
(
state
);
}
void
label_temperature
(
char
**
labels
,
void
*
ptr
)
{
struct
temperature_t
*
state
=
(
struct
temperature_t
*
)
ptr
;
for
(
int
i
=
0
;
i
<
state
->
nb_elem
;
i
++
)
labels
[
i
]
=
state
->
label_list
[
i
];
}
This diff is collapsed.
Click to expand it.
temperature.h
0 → 100644
+
24
−
0
View file @
401520c3
/*******************************************************
Copyright (C) 2018-2021 Georges Da Costa <georges.da-costa@irit.fr>
This file is part of Mojitos.
Mojitos is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Mojitos is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MojitO/S. If not, see <https://www.gnu.org/licenses/>.
*******************************************************/
unsigned
int
init_temperature
(
char
*
,
void
**
);
unsigned
int
get_temperature
(
uint64_t
*
results
,
void
*
);
void
clean_temperature
(
void
*
);
void
label_temperature
(
char
**
labels
,
void
*
);
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