Skip to content

Commit f9c4178

Browse files
committedSep 17, 2018
Labee Structure Driver and Dummy driver implementation
1 parent 05acfed commit f9c4178

File tree

9 files changed

+294
-13
lines changed

9 files changed

+294
-13
lines changed
 

Diff for: ‎Makefile.am

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AM_CFLAGS = -Wall -Werror -Wextra -pedantic -fno-strict-aliasing
1+
AM_CFLAGS = -Wall -Wno-error -Wextra -pedantic -fno-strict-aliasing
22
ACLOCAL_AMFLAGS = -I m4
33

44
#Shared library
@@ -24,6 +24,12 @@ lib@PACKAGE_TARNAME@_la_SOURCES = \
2424

2525
lib@PACKAGE_TARNAME@_la_LIBADD =
2626

27+
28+
if ENABLE_DUMMY
29+
lib@PACKAGE_TARNAME@_la_CPPFLAGS += -DENABLE_DUMMY
30+
lib@PACKAGE_TARNAME@_la_SOURCES += src/driver-dummy.c
31+
endif
32+
2733
if ENABLE_MIC
2834
lib@PACKAGE_TARNAME@_la_CPPFLAGS += -DENABLE_MIC
2935
lib@PACKAGE_TARNAME@_la_SOURCES += src/driver-mic.c
@@ -53,6 +59,11 @@ lib@PACKAGE_TARNAME@_la_CPPFLAGS += -DENABLE_ODROID
5359
lib@PACKAGE_TARNAME@_la_SOURCES += src/driver-odroid.c
5460
endif
5561

62+
if ENABLE_LABEE
63+
lib@PACKAGE_TARNAME@_la_CPPFLAGS += -DENABLE_LABEE
64+
lib@PACKAGE_TARNAME@_la_SOURCES += src/driver-labee.c
65+
endif
66+
5667

5768
#Flags for common dependencies
5869

Diff for: ‎configure.ac

+18-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ AC_SEARCH_LIBS([pthread_create], [pthread])
1919

2020
PKG_CHECK_MODULES([CONFUSE], [libconfuse])
2121

22+
# Optional: Dummy testing module Support
23+
AC_ARG_ENABLE([dummy], AS_HELP_STRING([--enable-dummy],
24+
[Enable Dummy testing support
25+
(default: disabled)]))
26+
AS_IF([test "x$enable_dummy" != "xno"], [have_dummy=yes])
27+
AM_CONDITIONAL([ENABLE_DUMMY], [test "x$have_dummy" = "xyes"])
28+
2229
# Optional: Intel MIC support
2330
AC_ARG_WITH([mic], AS_HELP_STRING([--without-mic],
2431
[Disable Intel Many Integrated Core support
@@ -43,20 +50,26 @@ AS_IF([test "x$with_nvml" != "xno"],
4350
AM_CONDITIONAL([ENABLE_NVML], [test "x$have_nvml" = "xyes"])
4451

4552
# Optional: Schleifenbauer PDU support
46-
AC_ARG_WITH([sb_pdu], AS_HELP_STRING([--without-sb-pdu],
47-
[Disable Schleifenbauer PDU support
48-
(default: enabled if libcrypto is available)]))
49-
AS_IF([test "x$with_sb_pdu" != "xno"],
53+
AC_ARG_ENABLE([sb_pdu], AS_HELP_STRING([--enable-sb-pdu],
54+
[Enable Schleifenbauer PDU support
55+
(default: disabled)]))
56+
AS_IF([test "x$enable_sb_pdu" = "xyes"],
5057
[PKG_CHECK_MODULES([CRYPTO], [libcrypto], [have_sb_pdu=yes])])
5158
AM_CONDITIONAL([ENABLE_SB_PDU], [test "x$have_sb_pdu" = "xyes"])
5259

5360
# Optional: Odroid INA231 Sensor support
54-
AC_ARG_WITH([sb_pdu], AS_HELP_STRING([--without-odroid],
61+
AC_ARG_WITH([odroid], AS_HELP_STRING([--without-odroid],
5562
[Disable Odroid support
5663
(default: enabled)]))
5764
AS_IF([test "x$with_odroid" != "xno"], [have_odroid=yes])
5865
AM_CONDITIONAL([ENABLE_ODROID], [test "x$have_odroid" = "xyes"])
5966

67+
# Optional: Labee(PSNN) REST Support
68+
AC_ARG_ENABLE([labee], AS_HELP_STRING([--enable-labee],
69+
[Enable Labee support
70+
(default: disable)]))
71+
AS_IF([test "x$enable_labee" = "xyes"], [have_labee=yes])
72+
AM_CONDITIONAL([ENABLE_LABEE], [test "x$have_labee" = "xyes"])
6073

6174
LT_INIT
6275

Diff for: ‎include/eml/device.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,20 @@ typedef struct emlDevice emlDevice_t;
3535

3636
/** Known device types */
3737
typedef enum emlDeviceType {
38+
/** Dummy measurement for testing algorithms */
39+
EML_DEV_DUMMY = 0,
3840
/** Nvidia cards supporting power readings through NVML */
39-
EML_DEV_NVML = 0,
41+
EML_DEV_NVML = 1,
4042
/** Intel CPUs supporting energy counters through RAPL */
41-
EML_DEV_RAPL = 1,
43+
EML_DEV_RAPL = 2,
4244
/** Intel MICs (Xeon Phi) */
43-
EML_DEV_MIC = 2,
45+
EML_DEV_MIC = 3,
4446
/** Schleifenbauer PDUs */
45-
EML_DEV_SB_PDU = 3,
47+
EML_DEV_SB_PDU = 4,
4648
/** Odroid with sensor support */
47-
EML_DEV_ODROID = 4,
49+
EML_DEV_ODROID = 5,
50+
/** Labee(PSNN) Rest interface */
51+
EML_DEV_LABEE = 6,
4852
/** Number of supported device types */
4953
EML_DEVICE_TYPE_COUNT
5054
} emlDeviceType_t;

Diff for: ‎src/device.c

+16
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ enum emlError emlInit() {
3232
if (devices)
3333
return EML_ALREADY_INITIALIZED;
3434

35+
#ifdef ENABLE_DUMMY
36+
extern struct emlDriver dummy_driver;
37+
drivers[EML_DEV_DUMMY] = &dummy_driver;
38+
#endif
39+
3540
#ifdef ENABLE_NVML
3641
extern struct emlDriver nvml_driver;
3742
drivers[EML_DEV_NVML] = &nvml_driver;
@@ -57,9 +62,17 @@ enum emlError emlInit() {
5762
drivers[EML_DEV_ODROID] = &odroid_driver;
5863
#endif
5964

65+
#ifdef ENABLE_LABEE
66+
extern struct emlDriver labee_driver;
67+
drivers[EML_DEV_LABEE] = &labee_driver;
68+
#endif
6069

6170
cfg_opt_t cfgopts[] = {
6271

72+
#ifdef ENABLE_DUMMY
73+
CFG_SEC("dummy", drivers[EML_DEV_DUMMY]->cfgopts, CFGF_NONE),
74+
#endif
75+
6376
#ifdef ENABLE_NVML
6477
CFG_SEC("nvml", drivers[EML_DEV_NVML]->cfgopts, CFGF_NONE),
6578
#endif
@@ -80,6 +93,9 @@ enum emlError emlInit() {
8093
CFG_SEC("odroid", drivers[EML_DEV_ODROID]->cfgopts, CFGF_NONE),
8194
#endif
8295

96+
#ifdef ENABLE_LABEE
97+
CFG_SEC("labee", drivers[EML_DEV_LABEE]->cfgopts, CFGF_NONE),
98+
#endif
8399

84100
CFG_END()
85101
};

Diff for: ‎src/driver-dummy.c

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (c) 2017 Universidad de La Laguna <cap@pcg.ull.es>
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms of the GNU General Public License as published by the Free
6+
* Software Foundation; either version 2 of the License, or (at your option)
7+
* any later version.
8+
*/
9+
10+
//feature test macro for pread() in unistd.h
11+
#define _XOPEN_SOURCE 500
12+
13+
#define DUMMY_DEFAULT_SAMPLING_INTERVAL 100000000L // ~100ms
14+
15+
#include <assert.h>
16+
//#include <ctype.h>
17+
//#include <errno.h>
18+
//#include <stddef.h>
19+
//#include <stdint.h>
20+
//#include <stdio.h>
21+
#include <stdlib.h>
22+
#include <string.h>
23+
//#include <dirent.h>
24+
//
25+
//#include <confuse.h>
26+
//#include <fcntl.h>
27+
//#include <sys/stat.h>
28+
//#include <unistd.h>
29+
//
30+
#include "data.h"
31+
#include "debug.h"
32+
#include "driver.h"
33+
#include "error.h"
34+
#include "timer.h"
35+
36+
struct emlDriver dummy_driver;
37+
38+
39+
static enum emlError init(cfg_t* const config) {
40+
assert(!dummy_driver.initialized);
41+
assert(config);
42+
dummy_driver.config = config;
43+
44+
printf("OMG pre\n");
45+
dummy_driver.ndevices = 1;
46+
dummy_driver.devices = malloc(dummy_driver.ndevices * sizeof(*dummy_driver.devices));
47+
for (size_t i = 0; i < dummy_driver.ndevices; i++) {
48+
struct emlDevice devinit = {
49+
.driver = &dummy_driver,
50+
.index = i,
51+
};
52+
sprintf(devinit.name, "%s%zu", dummy_driver.name, i);
53+
54+
struct emlDevice* const dev = &dummy_driver.devices[i];
55+
memcpy(dev, &devinit, sizeof(*dev));
56+
}
57+
58+
printf("OMG\n");
59+
dummy_driver.initialized = 1;
60+
return EML_SUCCESS;
61+
}
62+
63+
64+
static enum emlError shutdown() {
65+
assert(dummy_driver.initialized);
66+
67+
dummy_driver.initialized = 0;
68+
69+
return EML_SUCCESS;
70+
}
71+
72+
static enum emlError measure(size_t devno, unsigned long long* values) {
73+
assert(dummy_driver.initialized);
74+
assert(devno < dummy_driver.ndevices); // Shouldn't be more than one anyways
75+
76+
values[0] = millitimestamp();
77+
values[dummy_driver.default_props->inst_power_field * DATABLOCK_SIZE] = values[0];
78+
return EML_SUCCESS;
79+
}
80+
81+
// default measurement properties for this driver
82+
static struct emlDataProperties default_props = {
83+
.time_factor = EML_SI_MILLI,
84+
.energy_factor = EML_SI_MILLI, // Measurement is in W, but to store on a long, it is multiplied by EML_SI_MEGA
85+
// .power_factor = EML_SI_MICRO,
86+
.inst_energy_field = 0,
87+
.inst_power_field = 1,
88+
};
89+
90+
static cfg_opt_t cfgopts[] = {
91+
CFG_BOOL("disabled", cfg_true, CFGF_NONE),
92+
CFG_INT("sampling_interval", DUMMY_DEFAULT_SAMPLING_INTERVAL, CFGF_NONE),
93+
CFG_END()
94+
};
95+
96+
//public driver state and interface
97+
struct emlDriver dummy_driver = {
98+
.name = "dummy",
99+
.type = EML_DEV_DUMMY,
100+
.failed_reason = "",
101+
.default_props = &default_props,
102+
.cfgopts = cfgopts,
103+
.config = NULL,
104+
105+
.init = &init,
106+
.shutdown = &shutdown,
107+
.measure = &measure,
108+
};

Diff for: ‎src/driver-labee.c

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Copyright (c) 2018 Universidad de La Laguna <cap@pcg.ull.es>
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms of the GNU General Public License as published by the Free
6+
* Software Foundation; either version 2 of the License, or (at your option)
7+
* any later version.
8+
*
9+
* @author: Alberto Cabrera Perez <Alberto.Cabrera@ull.edu.es>
10+
*/
11+
12+
#define _XOPEN_SOURCE 500
13+
14+
#include <assert.h>
15+
//#include <ctype.h>
16+
//#include <errno.h>
17+
//#include <stddef.h>
18+
//#include <stdint.h>
19+
//#include <stdio.h>
20+
#include <stdlib.h>
21+
#include <string.h>
22+
//#include <dirent.h>
23+
//
24+
#include <confuse.h>
25+
//#include <fcntl.h>
26+
//#include <sys/stat.h>
27+
//#include <unistd.h>
28+
//
29+
#include "data.h"
30+
#include "debug.h"
31+
#include "driver.h"
32+
#include "error.h"
33+
#include "timer.h"
34+
35+
#define LABEE_DEFAULT_SAMPLING_INTERVAL 100000000L // 100ms
36+
37+
struct emlDriver labee_driver;
38+
39+
40+
static enum emlError init(cfg_t* const config) {
41+
assert(!labee_driver.initialized);
42+
assert(config);
43+
labee_driver.config = config;
44+
45+
enum emlError err;
46+
47+
// TODO Check if the API is up
48+
49+
// FUnction that generates error code
50+
if (err != EML_SUCCESS)
51+
goto err_free;
52+
53+
labee_driver.ndevices = 1;
54+
labee_driver.devices = malloc(labee_driver.ndevices * sizeof(*labee_driver.devices));
55+
for (size_t i = 0; i < labee_driver.ndevices; i++) {
56+
struct emlDevice devinit = {
57+
.driver = &labee_driver,
58+
.index = i,
59+
};
60+
sprintf(devinit.name, "%s%zu", labee_driver.name, i);
61+
62+
struct emlDevice* const dev = &labee_driver.devices[i];
63+
memcpy(dev, &devinit, sizeof(*dev));
64+
}
65+
66+
labee_driver.initialized = 1;
67+
return EML_SUCCESS;
68+
69+
err_free:
70+
if (labee_driver.failed_reason[0] == '\0')
71+
strncpy(labee_driver.failed_reason, emlErrorMessage(err), sizeof(labee_driver.failed_reason) - 1);
72+
return err;
73+
}
74+
75+
76+
static enum emlError shutdown() {
77+
assert(labee_driver.initialized);
78+
79+
labee_driver.initialized = 0;
80+
81+
return EML_SUCCESS;
82+
}
83+
84+
static enum emlError measure(size_t devno, unsigned long long* values) {
85+
assert(labee_driver.initialized);
86+
assert(devno < labee_driver.ndevices); // Shouldn't be more than one anyways
87+
88+
enum emlError err;
89+
90+
values[0] = millitimestamp();
91+
const long sampling_interval = cfg_getint(labee_driver.config, "sampling_interval");
92+
unsigned long long power = 1 / sampling_interval;
93+
94+
//TODO parse xml from rest api apply average proportionally to interval
95+
values[labee_driver.default_props->inst_energy_field * DATABLOCK_SIZE] = power;
96+
return EML_SUCCESS;
97+
}
98+
99+
// default measurement properties for this driver
100+
static struct emlDataProperties default_props = {
101+
.time_factor = EML_SI_MILLI,
102+
.energy_factor = EML_SI_MICRO, // Measurement is in J, but to store on a long, it is multiplied by EML_SI_MEGA
103+
.power_factor = EML_SI_MICRO, // Measurement is in W, same principle, with EML_SI_MEGA
104+
.inst_energy_field = 1,
105+
.inst_power_field = 2,
106+
};
107+
108+
static cfg_opt_t cfgopts[] = {
109+
CFG_BOOL("disabled", cfg_false, CFGF_NONE),
110+
CFG_INT("sampling_interval", LABEE_DEFAULT_SAMPLING_INTERVAL, CFGF_NONE),
111+
CFG_END()
112+
};
113+
114+
//public driver state and interface
115+
struct emlDriver labee_driver = {
116+
.name = "labee",
117+
.type = EML_DEV_LABEE,
118+
.failed_reason = "",
119+
.default_props = &default_props,
120+
.cfgopts = cfgopts,
121+
.config = NULL,
122+
123+
.init = &init,
124+
.shutdown = &shutdown,
125+
.measure = &measure,
126+
};

Diff for: ‎src/driver-odroid.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static enum emlError init(cfg_t* const config) {
199199
free(sensors);
200200

201201
if (odroid_driver.failed_reason[0] == '\0')
202-
strncpy(odroid_driver.failed_reason, emlErrorMessage(err), sizeof(odroid_driver.failed_reason));
202+
strncpy(odroid_driver.failed_reason, emlErrorMessage(err), sizeof(odroid_driver.failed_reason) - 1);
203203
return err;
204204
}
205205

Diff for: ‎src/driver-rapl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ static enum emlError init(cfg_t* const config) {
405405

406406
error:
407407
if (rapl_driver.failed_reason[0] == '\0')
408-
strncpy(rapl_driver.failed_reason, emlErrorMessage(err), sizeof(rapl_driver.failed_reason));
408+
strncpy(rapl_driver.failed_reason, emlErrorMessage(err), sizeof(rapl_driver.failed_reason) - 1);
409409
return err;
410410
}
411411

0 commit comments

Comments
 (0)
Failed to load comments.