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
46f7e35f
Commit
46f7e35f
authored
4 years ago
by
Georges Da Costa
Browse files
Options
Downloads
Patches
Plain Diff
Changes the load sensor to use pread
parent
00471708
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
load.c
+14
-4
14 additions, 4 deletions
load.c
load.h
+2
-0
2 additions, 0 deletions
load.h
mojitos.c
+5
-1
5 additions, 1 deletion
mojitos.c
with
21 additions
and
5 deletions
load.c
+
14
−
4
View file @
46f7e35f
...
...
@@ -17,16 +17,21 @@
along with MojitO/S. If not, see <https://www.gnu.org/licenses/>.
*******************************************************/
#include
<stdio.h>
#include
<unistd.h>
#include
<fcntl.h>
#include
<stdlib.h>
#define LOAD_BUFFER_SIZE 1024
char
buffer
[
LOAD_BUFFER_SIZE
];
static
int
load_fid
=-
1
;
void
init_load
()
{
load_fid
=
open
(
"/proc/stat"
,
O_RDONLY
);
}
void
get_load
(
long
long
*
results
)
{
FILE
*
f
=
fopen
(
"/proc/stat"
,
"rb"
);
fgets
(
buffer
,
LOAD_BUFFER_SIZE
,
f
);
fclose
(
f
);
pread
(
load_fid
,
buffer
,
LOAD_BUFFER_SIZE
-
1
,
0
);
int
pos
=
0
;
while
(
buffer
[
pos
]
>
'9'
||
buffer
[
pos
]
<
'0'
)
pos
++
;
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
...
...
@@ -35,3 +40,8 @@ void get_load(long long* results) {
pos
++
;
}
}
void
clean_load
()
{
close
(
load_fid
);
}
This diff is collapsed.
Click to expand it.
load.h
+
2
−
0
View file @
46f7e35f
...
...
@@ -18,4 +18,6 @@
*******************************************************/
void
init_load
();
void
get_load
(
long
long
*
results
);
void
clean_load
();
This diff is collapsed.
Click to expand it.
mojitos.c
+
5
−
1
View file @
46f7e35f
...
...
@@ -207,8 +207,10 @@ int main(int argc, char **argv) {
// Load initialization
long
long
load_values
[
10
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
long
long
tmp_load_values
[
10
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
if
(
load_mode
==
0
)
if
(
load_mode
==
0
)
{
init_load
();
get_load
(
load_values
);
}
// RAPL initialization
_rapl_t
*
rapl
=
NULL
;
...
...
@@ -353,6 +355,8 @@ int main(int argc, char **argv) {
free
(
rapl_values
);
free
(
tmp_rapl_values
);
}
if
(
load_mode
==
0
)
clean_load
();
if
(
dev
!=
NULL
)
clean_network
(
network_sources
);
if
(
infi_path
!=
NULL
)
...
...
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