Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
cmake_minimum_required(VERSION 3.13)
project(hwpc-sensor LANGUAGES C)
project(hwpc-sensor LANGUAGES CXX)

option(WITH_MONGODB "Build with support for MongoDB storage module" ON)

set(CMAKE_C_STANDARD 11)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

add_compile_options(-Werror -Wall -Wextra -Wpedantic -Wformat=2 -Wnull-dereference -Wno-gnu-statement-expression)
add_link_options(-Wl,-z,relro,-z,now -pie)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Og -fsanitize=address,undefined -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -D_FORTIFY_SOURCE=2 -fstack-protector-strong")
add_compile_options(-Werror -Wall -Wextra -Wformat=2 -fstack-protector-strong -D_FORTIFY_SOURCE=2 -fPIE)
add_link_options(-pie -Wl,-z,relro,-z,now -Wl,-z,noexecstack -Wl,-z,defs -Wl,--as-needed)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# These warnings need to be suppressed temporarily, as the only fix is to rewrite the code in C++
add_compile_options(-Wno-deprecated -Wno-c99-designator -Wno-vla-cxx-extension)
endif()

if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-Og -fsanitize=address,undefined -fno-omit-frame-pointer)
add_link_options(-fsanitize=address,undefined)
endif()

set(SENSOR_SOURCES
src/config_cli.c
Expand Down Expand Up @@ -51,5 +57,13 @@ if(DEFINED ENV{GIT_TAG} AND DEFINED ENV{GIT_REV})
endif()

add_executable(hwpc-sensor "${SENSOR_SOURCES}")

foreach(src ${SENSOR_SOURCES})
set_source_files_properties(${src} PROPERTIES LANGUAGE CXX)
endforeach()

target_compile_features(hwpc-sensor PUBLIC cxx_std_20)
set_target_properties(hwpc-sensor PROPERTIES CXX_EXTENSIONS OFF LINKER_LANGUAGE CXX)

target_include_directories(hwpc-sensor SYSTEM PRIVATE "${LIBPFM_INCLUDE_DIRS}" "${CZMQ_INCLUDE_DIRS}" "${JSONC_INCLUDE_DIRS}" "${MONGOC_INCLUDE_DIRS}")
target_link_libraries(hwpc-sensor "${LIBPFM_LIBRARIES}" "${CZMQ_LIBRARIES}" "${JSONC_LIBRARIES}" "${MONGOC_LIBRARIES}")
4 changes: 2 additions & 2 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
struct config *
config_create(void)
{
struct config *config = malloc(sizeof(struct config));
struct config *config = (struct config *) malloc(sizeof(struct config));

if (!config)
return NULL;
Expand Down Expand Up @@ -104,7 +104,7 @@ is_events_group_empty(zhashx_t *events_groups)
{
struct events_group *events_group = NULL;

for (events_group = zhashx_first(events_groups); events_group; events_group = zhashx_next(events_groups)) {
for (events_group = (struct events_group *) zhashx_first(events_groups); events_group; events_group = (struct events_group *) zhashx_next(events_groups)) {
if (zlistx_size(events_group->events) == 0) {
zsys_error("config: Events group '%s' is empty", events_group->name);
return -1;
Expand Down
4 changes: 2 additions & 2 deletions src/config_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,14 @@ config_setup_from_cli(int argc, char **argv, struct config *config)
if (setup_global_events_group(config, optarg)) {
return -1;
}
current_events_group = zhashx_lookup(config->events.system, optarg);
current_events_group = (struct events_group *) zhashx_lookup(config->events.system, optarg);
break;

case 'c':
if (setup_cgroups_events_group(config, optarg)) {
return -1;
}
current_events_group = zhashx_lookup(config->events.containers, optarg);
current_events_group = (struct events_group *) zhashx_lookup(config->events.containers, optarg);
break;

case 'o':
Expand Down
2 changes: 1 addition & 1 deletion src/config_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ static int
parse_json_configuration_file_from_fd(int fd, json_object **obj)
{
int ret = -1;
char buffer[JSON_FILE_BUFFER_SIZE] = {0};
char buffer[JSON_FILE_BUFFER_SIZE] = {};
json_tokener *tok = NULL;
enum json_tokener_error jerr;
size_t line, column;
Expand Down
12 changes: 6 additions & 6 deletions src/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ get_msr_pmu_event_encoding(const char *event_name, struct perf_event_attr *attr)
static int
setup_perf_event_attr(const char *event_name, struct perf_event_attr *attr)
{
pfm_perf_encode_arg_t arg = {0};
pfm_perf_encode_arg_t arg = {};

attr->size = sizeof(struct perf_event_attr);
attr->disabled = 1;
Expand All @@ -120,11 +120,11 @@ setup_perf_event_attr(const char *event_name, struct perf_event_attr *attr)
struct event_config *
event_config_create(const char *event_name)
{
struct perf_event_attr attr = {0};
struct perf_event_attr attr = {};
struct event_config *config = NULL;

if (!setup_perf_event_attr(event_name, &attr)) {
config = malloc(sizeof(struct event_config));
config = (struct event_config *) malloc(sizeof(struct event_config));
if (config) {
snprintf(config->name, NAME_MAX, "%s", event_name);
config->attr = attr;
Expand All @@ -140,7 +140,7 @@ event_config_dup(struct event_config *config)
struct event_config *copy = NULL;

if (config) {
copy = malloc(sizeof(struct event_config));
copy = (struct event_config *) malloc(sizeof(struct event_config));
if (copy) {
snprintf(copy->name, NAME_MAX, "%s", config->name);
copy->attr = config->attr;
Expand All @@ -162,7 +162,7 @@ event_config_destroy(struct event_config **config)
struct events_group *
events_group_create(const char *name)
{
struct events_group *group = malloc(sizeof(struct events_group));
struct events_group *group = (struct events_group *) malloc(sizeof(struct events_group));

if (group) {
snprintf(group->name, NAME_MAX, "%s", name);
Expand All @@ -182,7 +182,7 @@ events_group_dup(struct events_group *group)
struct events_group *copy = NULL;

if (group) {
copy = malloc(sizeof(struct events_group));
copy = (struct events_group *) malloc(sizeof(struct events_group));
if (copy) {
snprintf(copy->name, NAME_MAX, "%s", group->name);
copy->type = group->type;
Expand Down
18 changes: 9 additions & 9 deletions src/hwinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
static struct hwinfo_pkg *
hwinfo_pkg_create(void)
{
struct hwinfo_pkg *pkg = malloc(sizeof(struct hwinfo_pkg));
struct hwinfo_pkg *pkg = (struct hwinfo_pkg *) malloc(sizeof(struct hwinfo_pkg));

if (!pkg)
return NULL;
Expand All @@ -67,7 +67,7 @@ hwinfo_pkg_create(void)
static struct hwinfo_pkg *
hwinfo_pkg_dup(struct hwinfo_pkg *pkg)
{
struct hwinfo_pkg *pkgcpy = malloc(sizeof(struct hwinfo_pkg));
struct hwinfo_pkg *pkgcpy = (struct hwinfo_pkg *) malloc(sizeof(struct hwinfo_pkg));

if (!pkgcpy)
return NULL;
Expand All @@ -92,7 +92,7 @@ static int
get_cpu_online_status(const char *cpu_dir)
{
int status = 1;
char path[PATH_MAX] = {0};
char path[PATH_MAX] = {};
FILE *f = NULL;
char buffer[2]; /* boolean expected */

Expand All @@ -118,7 +118,7 @@ static char *
get_package_id(const char *cpu_dir)
{
FILE *f = NULL;
char path[PATH_MAX] = {0};
char path[PATH_MAX] = {};
char buffer[24]; /* log10(ULLONG_MAX) */
char *id = NULL;

Expand All @@ -138,7 +138,7 @@ get_package_id(const char *cpu_dir)
static char *
parse_cpu_id_from_name(const char *str)
{
regex_t re = {0};
regex_t re = {};
regmatch_t matches[CPU_ID_REGEX_EXPECTED_MATCHES];
char *id = NULL;

Expand Down Expand Up @@ -191,7 +191,7 @@ do_packages_detection(struct hwinfo *hwinfo)
}

/* get cpu pkg or create it if never encountered */
pkg = zhashx_lookup(hwinfo->pkgs, pkg_id);
pkg = (struct hwinfo_pkg *) zhashx_lookup(hwinfo->pkgs, pkg_id);
if (!pkg) {
pkg = hwinfo_pkg_create();
if (!pkg) {
Expand All @@ -201,7 +201,7 @@ do_packages_detection(struct hwinfo *hwinfo)

zhashx_insert(hwinfo->pkgs, pkg_id, pkg);
hwinfo_pkg_destroy(&pkg);
pkg = zhashx_lookup(hwinfo->pkgs, pkg_id); /* get the copy the pkg done by zhashx_insert */
pkg = (struct hwinfo_pkg *) zhashx_lookup(hwinfo->pkgs, pkg_id); /* get the copy the pkg done by zhashx_insert */
}

zlistx_add_end(pkg->cpus_id, cpu_id);
Expand Down Expand Up @@ -235,7 +235,7 @@ hwinfo_detect(struct hwinfo *hwinfo)
struct hwinfo *
hwinfo_create(void)
{
struct hwinfo *hw = malloc(sizeof(struct hwinfo));
struct hwinfo *hw = (struct hwinfo *) malloc(sizeof(struct hwinfo));

if (!hw)
return NULL;
Expand All @@ -250,7 +250,7 @@ hwinfo_create(void)
struct hwinfo *
hwinfo_dup(struct hwinfo *hwinfo)
{
struct hwinfo *hwinfocpy = malloc(sizeof(struct hwinfo));
struct hwinfo *hwinfocpy = (struct hwinfo *) malloc(sizeof(struct hwinfo));

if (!hwinfocpy)
return NULL;
Expand Down
8 changes: 4 additions & 4 deletions src/payload.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
struct payload_cpu_data *
payload_cpu_data_create(void)
{
struct payload_cpu_data *data = malloc(sizeof(struct payload_cpu_data));
struct payload_cpu_data *data = (struct payload_cpu_data *) malloc(sizeof(struct payload_cpu_data));

if (!data)
return NULL;
Expand All @@ -64,7 +64,7 @@ payload_cpu_data_destroy(struct payload_cpu_data **data_ptr)
struct payload_pkg_data *
payload_pkg_data_create(void)
{
struct payload_pkg_data *data = malloc(sizeof(struct payload_pkg_data));
struct payload_pkg_data *data = (struct payload_pkg_data *) malloc(sizeof(struct payload_pkg_data));

if (!data)
return NULL;
Expand All @@ -89,7 +89,7 @@ payload_pkg_data_destroy(struct payload_pkg_data **data_ptr)
struct payload_group_data *
payload_group_data_create(void)
{
struct payload_group_data *data = malloc(sizeof(struct payload_group_data));
struct payload_group_data *data = (struct payload_group_data *) malloc(sizeof(struct payload_group_data));

if (!data)
return NULL;
Expand All @@ -114,7 +114,7 @@ payload_group_data_destroy(struct payload_group_data **data_ptr)
struct payload *
payload_create(uint64_t timestamp, const char *target_name)
{
struct payload *payload = malloc(sizeof(struct payload));
struct payload *payload = (struct payload *) malloc(sizeof(struct payload));

if (!payload)
return NULL;
Expand Down
Loading
Loading