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
d28c1f96
Commit
d28c1f96
authored
1 month ago
by
Georges Da Costa
Browse files
Options
Downloads
Patches
Plain Diff
Adds disk support
parent
a3f4b357
No related branches found
No related tags found
1 merge request
!12
Libmoj
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
configure.sh
+1
-0
1 addition, 0 deletions
configure.sh
src/disk.c
+151
-0
151 additions, 0 deletions
src/disk.c
src/disk.h
+43
-0
43 additions, 0 deletions
src/disk.h
src/util.c
+14
-0
14 additions, 0 deletions
src/util.c
src/util.h
+2
-0
2 additions, 0 deletions
src/util.h
with
211 additions
and
0 deletions
configure.sh
+
1
−
0
View file @
d28c1f96
...
@@ -117,6 +117,7 @@ detect_caps() {
...
@@ -117,6 +117,7 @@ detect_caps() {
[
-r
/usr/include/linux/perf_event.h
]
&&
hdr_whitelist
=
counters
[
-r
/usr/include/linux/perf_event.h
]
&&
hdr_whitelist
=
counters
[
-d
/sys/class/infiniband
]
&&
hdr_whitelist
=
"
${
hdr_whitelist
}
|infiniband"
[
-d
/sys/class/infiniband
]
&&
hdr_whitelist
=
"
${
hdr_whitelist
}
|infiniband"
[
-r
/proc/stat
]
&&
hdr_whitelist
=
"
${
hdr_whitelist
}
|load"
[
-r
/proc/stat
]
&&
hdr_whitelist
=
"
${
hdr_whitelist
}
|load"
[
-r
/sys/block
]
&&
hdr_whitelist
=
"
${
hdr_whitelist
}
|disk"
[
-r
/proc/meminfo
]
&&
hdr_whitelist
=
"
${
hdr_whitelist
}
|memory_counters"
[
-r
/proc/meminfo
]
&&
hdr_whitelist
=
"
${
hdr_whitelist
}
|memory_counters"
if
[
"
$(
uname
-r
|
cut
-d
"."
-f
1
)
"
-gt
"2"
]
;
then
if
[
"
$(
uname
-r
|
cut
-d
"."
-f
1
)
"
-gt
"2"
]
;
then
...
...
This diff is collapsed.
Click to expand it.
src/disk.c
0 → 100644
+
151
−
0
View file @
d28c1f96
/*******************************************************
Copyright (C) 2019-2023 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
<unistd.h>
#include
<fcntl.h>
#include
<stdlib.h>
#include
<stdint.h>
#include
<string.h>
#include
<stdio.h>
#include
"util.h"
#include
<glob.h>
struct
Disk
{
uint64_t
*
values
;
uint64_t
*
tmp_values
;
int
*
sources
;
char
**
labels
;
int
nb
;
};
#define DISK_VALUES_SIZE 15
void
_get_disk
(
struct
Disk
*
state
)
{
char
disk_buffer
[
1024
];
for
(
int
disk_id
=
0
;
disk_id
<
state
->
nb
;
disk_id
++
)
{
if
(
pread
(
state
->
sources
[
disk_id
],
disk_buffer
,
1024
-
1
,
0
)
<
0
)
{
perror
(
"pread"
);
exit
(
1
);
}
char
*
ptr
=
disk_buffer
;
for
(
int
i
=
0
;
i
<
DISK_VALUES_SIZE
;
i
++
)
ptr
=
read_int
(
ptr
,
&
state
->
values
[
disk_id
*
DISK_VALUES_SIZE
+
i
]);
}
}
// Public interface
unsigned
int
init_disk
(
char
*
argument
,
void
**
state_tmp
)
{
UNUSED
(
argument
);
*
state_tmp
=
malloc
(
sizeof
(
struct
Disk
));
struct
Disk
*
state
=
(
struct
Disk
*
)
*
state_tmp
;
state
->
sources
=
NULL
;
state
->
labels
=
NULL
;
glob_t
res
;
glob
(
"/sys/block/*"
,
0
,
NULL
,
&
res
);
if
(
res
.
gl_pathc
==
0
)
{
fprintf
(
stderr
,
"No disk found.
\n
"
);
return
0
;
}
int
nb_disk
=
res
.
gl_pathc
;
char
*
_labels_disk
[
DISK_VALUES_SIZE
]
=
{
"%s_read_I_Os"
,
"%s_read_merges"
,
"%s_read_sectors"
,
"%s_read_ticks"
,
"%s_write_I_Os"
,
"%s_write_merges"
,
"%s_write_sectors"
,
"%s_write_ticks"
,
"%s_in_flight"
,
"%s_io_ticks"
,
"%s_time_in_queue"
,
"%s_discard_I_Os"
,
"%s_discard_merges"
,
"%s_discard_sectors"
,
"%s_discard_ticks"
};
char
buffer
[
1024
];
for
(
int
i
=
0
;
i
<
nb_disk
;
i
++
)
{
char
*
disk_path
=
res
.
gl_pathv
[
i
];
char
*
disk_name
=
rindex
(
disk_path
,
'/'
)
+
1
;
state
->
sources
=
(
int
*
)
realloc
(
state
->
sources
,
sizeof
(
int
)
*
(
i
+
1
));
sprintf
(
buffer
,
"/sys/block/%s/stat"
,
disk_name
);
state
->
sources
[
i
]
=
open
(
buffer
,
O_RDONLY
);
state
->
labels
=
(
char
**
)
realloc
(
state
->
labels
,
sizeof
(
char
*
)
*
DISK_VALUES_SIZE
*
(
i
+
1
));
for
(
int
j
=
0
;
j
<
DISK_VALUES_SIZE
;
j
++
)
{
state
->
labels
[
i
*
DISK_VALUES_SIZE
+
j
]
=
malloc
(
1024
*
sizeof
(
char
));
snprintf
(
state
->
labels
[
i
*
DISK_VALUES_SIZE
+
j
],
1023
,
_labels_disk
[
j
],
disk_name
);
}
}
state
->
nb
=
nb_disk
;
state
->
values
=
(
uint64_t
*
)
malloc
(
sizeof
(
uint64_t
)
*
state
->
nb
*
DISK_VALUES_SIZE
);
state
->
tmp_values
=
(
uint64_t
*
)
malloc
(
sizeof
(
uint64_t
)
*
state
->
nb
*
DISK_VALUES_SIZE
);
_get_disk
(
state
);
memcpy
(
state
->
tmp_values
,
state
->
values
,
sizeof
(
uint64_t
)
*
state
->
nb
*
DISK_VALUES_SIZE
);
globfree
(
&
res
);
return
state
->
nb
*
DISK_VALUES_SIZE
;
}
unsigned
int
get_disk
(
uint64_t
*
results
,
void
*
state_tmp
)
{
struct
Disk
*
state
=
(
struct
Disk
*
)
state_tmp
;
_get_disk
(
state
);
for
(
int
i
=
0
;
i
<
state
->
nb
*
DISK_VALUES_SIZE
;
i
++
)
{
results
[
i
]
=
state
->
values
[
i
]
-
state
->
tmp_values
[
i
];
}
memcpy
(
state
->
tmp_values
,
state
->
values
,
sizeof
(
uint64_t
)
*
state
->
nb
*
DISK_VALUES_SIZE
);
return
state
->
nb
*
DISK_VALUES_SIZE
;
}
void
clean_disk
(
void
*
state_tmp
)
{
struct
Disk
*
state
=
(
struct
Disk
*
)
state_tmp
;
free
(
state
->
values
);
free
(
state
->
tmp_values
);
for
(
int
i
=
0
;
i
<
state
->
nb
;
i
++
)
close
(
state
->
sources
[
i
]);
free
(
state
->
sources
);
for
(
int
i
=
0
;
i
<
state
->
nb
*
DISK_VALUES_SIZE
;
i
++
)
free
(
state
->
labels
[
i
]);
free
(
state
->
labels
);
free
(
state
);
}
void
label_disk
(
const
char
**
labels
,
void
*
state_tmp
)
{
struct
Disk
*
state
=
(
struct
Disk
*
)
state_tmp
;
for
(
int
i
=
0
;
i
<
state
->
nb
*
DISK_VALUES_SIZE
;
i
++
)
{
labels
[
i
]
=
state
->
labels
[
i
];
}
}
This diff is collapsed.
Click to expand it.
src/disk.h
0 → 100644
+
43
−
0
View file @
d28c1f96
/*******************************************************
Copyright (C) 2018-2023 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_disk
(
char
*
,
void
**
);
unsigned
int
get_disk
(
uint64_t
*
results
,
void
*
);
void
clean_disk
(
void
*
);
void
label_disk
(
const
char
**
labels
,
void
*
);
Sensor
disk
=
{
.
init
=
init_disk
,
.
get
=
get_disk
,
.
clean
=
clean_disk
,
.
label
=
label_disk
,
.
nb_opt
=
1
,
};
Optparse
disk_opt
[
1
]
=
{
{
.
longname
=
"disk"
,
.
shortname
=
'a'
,
.
argtype
=
OPTPARSE_NONE
,
.
usage_arg
=
NULL
,
.
usage_msg
=
"system disk/storage"
,
.
fn
=
NULL
,
},
};
This diff is collapsed.
Click to expand it.
src/util.c
+
14
−
0
View file @
d28c1f96
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
*******************************************************/
*******************************************************/
#include
<stdlib.h>
#include
"util.h"
#include
"util.h"
...
@@ -32,3 +33,16 @@ uint64_t modulo_substraction_bound(const uint64_t lhs, const uint64_t rhs, const
...
@@ -32,3 +33,16 @@ uint64_t modulo_substraction_bound(const uint64_t lhs, const uint64_t rhs, const
return
lhs
>=
rhs
?
(
lhs
-
rhs
)
return
lhs
>=
rhs
?
(
lhs
-
rhs
)
:
(
modulo
-
rhs
+
1
)
+
lhs
;
:
(
modulo
-
rhs
+
1
)
+
lhs
;
}
}
char
*
read_int
(
char
*
ptr
,
uint64_t
*
val
)
{
while
(
*
ptr
>
'9'
||
*
ptr
<
'0'
)
ptr
++
;
*
val
=
0
;
while
(
*
ptr
<=
'9'
&&
*
ptr
>=
'0'
)
{
*
val
=
*
val
*
10
+
(
*
ptr
-
'0'
);
ptr
++
;
}
return
ptr
;
}
This diff is collapsed.
Click to expand it.
src/util.h
+
2
−
0
View file @
d28c1f96
...
@@ -45,4 +45,6 @@
...
@@ -45,4 +45,6 @@
uint64_t
modulo_substraction
(
const
uint64_t
lhs
,
const
uint64_t
rhs
);
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
);
uint64_t
modulo_substraction_bound
(
const
uint64_t
lhs
,
const
uint64_t
rhs
,
const
uint64_t
modulo
);
char
*
read_int
(
char
*
ptr
,
uint64_t
*
val
);
#endif
#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