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
10d6b8c4
Commit
10d6b8c4
authored
2 years ago
by
ghuter
Browse files
Options
Downloads
Patches
Plain Diff
fix sensor example (doc)
plus add build instructions (in doc/counter_ex.c)
parent
9026cbb2
Branches
Branches containing commit
No related tags found
4 merge requests
!9
fix sensor example (doc)
,
!4
Amd, Tests, Doc, CI/CD
,
!2
build system (v0), add long options
,
!1
build system (v0), add long options, corrections
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
doc/counter_ex.c
+86
-9
86 additions, 9 deletions
doc/counter_ex.c
doc/counter_ex.h
+2
-2
2 additions, 2 deletions
doc/counter_ex.h
with
88 additions
and
11 deletions
doc/counter_ex.c
+
86
−
9
View file @
10d6b8c4
/*
* compilation:
*
# normally, this part is done with `configure.sh`, but here we need to
# do this manually
cat <<EOF > src/sensors.h
#include "counter_ex.h"
#include "counter_ex.h"
static
int
acc
;
#define NB_SENSOR 1
#define NB_SENSOR_OPT 1
void init_sensors(Optparse *opts, Sensor *sensors, size_t len, size_t offset, int *nb_defined)
{
int opt_idx = offset;
for (int i = 0; i < counter_ex.nb_opt; i++) {
opts[opt_idx++] = counter_ex_opt[i];
}
sensors[(*nb_defined)++] = counter_ex;
assert((offset + *nb_defined) <= len);
}
EOF
# idem
echo 'CAPTOR_OBJ = doc/counters_ex.o' > sensors.mk
# actual compilation here
gcc -std=gnu99 -Wall -Wpedantic -I./lib -I./doc -I./src -g -Og -c doc/counter_ex.c -o obj/counter_ex.o
gcc -std=gnu99 -Wall -Wpedantic -I./lib -I./doc -I./src -g -Og -c doc/util.c -o obj/util.o
gcc -std=gnu99 -Wall -Wpedantic -I./lib -I./doc -I./src -g -Og -c doc/mojitos.c -o obj/mojitos.o
gcc -std=gnu99 -Wall -Wpedantic -I./lib -I./doc -I./src -g -Og obj/util.o obj/mojitos.o obj/counter_ex.o -o bin/mojitos
unsigned
int
init_acc
(
char
*
a
,
void
**
b
)
*
**/
#include
<stdint.h>
#include
<stdlib.h>
#include
"util.h"
#define NB_SENSOR 3
struct
accumulator_t
{
int
v
[
NB_SENSOR
];
};
void
_get_acc
(
int
v
[
NB_SENSOR
])
{
{
acc
=
0
;
for
(
int
i
=
0
;
i
<
NB_SENSOR
;
i
++
)
{
v
[
i
]
++
;
}
}
}
unsigned
int
ge
t_acc
(
uint64_t
*
results
,
void
*
none
)
unsigned
int
ini
t_acc
(
char
*
none
,
void
*
*
ptr
)
{
{
/* "none" refers to an optionnal command-line argument */
/* there is none in this case, so this parameter is not used */
UNUSED
(
none
);
UNUSED
(
none
);
return
a
++
;
struct
accumulator_t
*
state
=
malloc
(
sizeof
(
struct
accumulator_t
));
for
(
int
i
=
0
;
i
<
NB_SENSOR
;
i
++
)
{
state
->
v
[
i
]
=
-
1
;
}
*
ptr
=
(
void
*
)
state
;
_get_acc
(
state
->
v
);
return
NB_SENSOR
;
}
unsigned
int
get_acc
(
uint64_t
*
results
,
void
*
ptr
)
{
struct
accumulator_t
*
state
=
(
struct
accumulator_t
*
)
ptr
;
_get_acc
(
state
->
v
);
for
(
int
i
=
0
;
i
<
NB_SENSOR
;
i
++
)
{
results
[
i
]
=
state
->
v
[
i
];
}
return
NB_SENSOR
;
}
}
char
*
_labels_accumulator
[
NB_SENSOR
]
=
{
"acc1"
,
"acc2"
,
"acc3"
};
void
label_acc
(
char
**
labels
,
void
*
none
)
void
label_acc
(
char
**
labels
,
void
*
none
)
{
{
UNUSED
(
none
);
UNUSED
(
none
);
labels
[
0
]
=
"acc"
;
for
(
int
i
=
0
;
i
<
NB_SENSOR
;
i
++
)
{
labels
[
i
]
=
_labels_accumulator
[
i
];
}
}
}
void
clean_acc
(
void
*
none
)
void
clean_acc
(
void
*
ptr
)
{
{
/* That's a no-op for this example */
struct
accumulator_t
*
state
=
(
struct
accumulator_t
*
)
ptr
;
UNUSED
(
none
);
if
(
state
==
NULL
)
{
return
;
}
free
(
state
);
}
}
This diff is collapsed.
Click to expand it.
doc/counter_ex.h
+
2
−
2
View file @
10d6b8c4
...
@@ -7,7 +7,7 @@ unsigned int get_acc(uint64_t *results, void *);
...
@@ -7,7 +7,7 @@ unsigned int get_acc(uint64_t *results, void *);
void
clean_acc
(
void
*
);
void
clean_acc
(
void
*
);
void
label_acc
(
char
**
labels
,
void
*
);
void
label_acc
(
char
**
labels
,
void
*
);
Sensor
rapl
=
{
Sensor
counter_ex
=
{
.
init
=
init_acc
,
.
init
=
init_acc
,
.
get
=
get_acc
,
.
get
=
get_acc
,
.
clean
=
clean_acc
,
.
clean
=
clean_acc
,
...
@@ -15,7 +15,7 @@ Sensor rapl = {
...
@@ -15,7 +15,7 @@ Sensor rapl = {
.
nb_opt
=
1
,
.
nb_opt
=
1
,
};
};
Optparse
rapl
_opt
[
1
]
=
{
Optparse
counter_ex
_opt
[
1
]
=
{
{
{
.
longname
=
"accumulator"
,
.
longname
=
"accumulator"
,
.
shortname
=
'a'
,
.
shortname
=
'a'
,
...
...
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