Use templates for module population

Also add stddef.h workaround for old GCC.
RHEL-8 still uses GCC 8.5 and templates are not well supported.

Change-Id: Ia4dae23892ec63682ea848c46ba81de85cf6d209
Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com>
This commit is contained in:
Galantsev, Dmitrii
2023-12-08 19:48:09 -06:00
rodzic eaa1862a80
commit f9e80cc37a
27 zmienionych plików z 135 dodań i 165 usunięć
+11 -7
Wyświetl plik
@@ -22,14 +22,12 @@ THE SOFTWARE.
#ifndef INCLUDE_RDC_LIB_RDCLIBRARYLOADER_H_
#define INCLUDE_RDC_LIB_RDCLIBRARYLOADER_H_
#include <dlfcn.h>
#include <string.h>
#include <map>
#include <mutex> // NOLINT(build/c++11)
#include "rdc/rdc.h"
#include "rdc_lib/RdcException.h"
#include "rdc_lib/RdcLogger.h"
#include "rdc_lib/rdc_common.h"
namespace amd {
namespace rdc {
@@ -37,6 +35,7 @@ class RdcLibraryLoader {
public:
RdcLibraryLoader();
// throws RdcException if lib not found
rdc_status_t load(const char* filename);
template <typename T>
@@ -57,7 +56,7 @@ class RdcLibraryLoader {
template <typename T>
rdc_status_t RdcLibraryLoader::load_symbol(T* func_handler, const char* func_name) {
if (!libHandler_) {
RDC_LOG(RDC_ERROR, "Must load the library before load the symbol");
RDC_LOG(RDC_ERROR, "Must load the library before loading the symbol");
return RDC_ST_FAIL_LOAD_MODULE;
}
@@ -83,9 +82,14 @@ rdc_status_t RdcLibraryLoader::load(const char* filename, T* func_make_handler)
return RDC_ST_FAIL_LOAD_MODULE;
}
rdc_status_t status = load(filename);
if (status != RDC_ST_OK) {
return status;
try {
rdc_status_t status = load(filename);
if (status != RDC_ST_OK) {
return status;
}
} catch (RdcException& e) {
RDC_LOG(RDC_ERROR, e.what());
return e.error_code();
}
return load_symbol(func_make_handler, "make_handler");
+13
Wyświetl plik
@@ -25,6 +25,19 @@ THE SOFTWARE.
#include <iostream>
#include <string>
#define RDC_ERROR 0
#define RDC_INFO 1
#define RDC_DEBUG 2
#define RDC_LOG(debug_level, msg) \
do { \
auto& logger = amd::rdc::RdcLogger::getLogger(); \
if (logger.should_log((debug_level))) { \
logger.get_ostream() << logger.get_log_header((debug_level), __FILE__, __LINE__) << msg \
<< std::endl; \
} \
} while (0)
namespace amd {
namespace rdc {
class RdcLogger {
+1 -2
Wyświetl plik
@@ -24,16 +24,15 @@ THE SOFTWARE.
#include <memory>
#include "rdc/rdc.h"
#include "rdc_lib/RdcDiagnostic.h"
#include "rdc_lib/RdcTelemetry.h"
#include "rdc_lib/rdc_common.h"
namespace amd {
namespace rdc {
class RdcModuleMgr {
public:
virtual ~RdcModuleMgr() = default;
virtual RdcTelemetryPtr get_telemetry_module() = 0;
virtual RdcDiagnosticPtr get_diagnostic_module() = 0;
};
@@ -28,7 +28,6 @@ THE SOFTWARE.
#include <vector>
#include "rdc_lib/RdcDiagnostic.h"
#include "rdc_lib/RdcMetricFetcher.h"
#include "rdc_lib/RdcTelemetryLibInterface.h"
namespace amd {
@@ -52,7 +51,7 @@ class RdcDiagnosticModule : public RdcDiagnostic {
rdc_status_t rdc_diag_init(uint64_t flags) override;
rdc_status_t rdc_diag_destroy() override;
explicit RdcDiagnosticModule(RdcMetricFetcherPtr& fetcher);
explicit RdcDiagnosticModule(std::list<RdcDiagnosticPtr> diagnostic_modules);
private:
//< Helper function to dispatch fields to module
+17 -1
Wyświetl plik
@@ -22,7 +22,7 @@ THE SOFTWARE.
#ifndef INCLUDE_RDC_LIB_IMPL_RDCMODULEMGRIMPL_H_
#define INCLUDE_RDC_LIB_IMPL_RDCMODULEMGRIMPL_H_
#include <memory>
#include <list>
#include "rdc_lib/RdcMetricFetcher.h"
#include "rdc_lib/RdcModuleMgr.h"
@@ -38,6 +38,22 @@ class RdcModuleMgrImpl : public RdcModuleMgr {
explicit RdcModuleMgrImpl(const RdcMetricFetcherPtr& fetcher);
private:
// Modules
std::list<RdcDiagnosticPtr> diagnostic_modules_;
std::list<RdcTelemetryPtr> telemetry_modules_;
// base case
template <typename T>
rdc_status_t insert_modules();
// recursive case
template <typename T, typename R, typename... TArgs>
rdc_status_t insert_modules();
// pass shared_ptr instead of creating it
template <typename T>
rdc_status_t insert_modules(std::shared_ptr<T> ptr);
// Function module
RdcTelemetryPtr rdc_telemetry_module_;
RdcDiagnosticPtr rdc_diagnostic_module_;
-2
Wyświetl plik
@@ -23,7 +23,6 @@ THE SOFTWARE.
#define INCLUDE_RDC_LIB_IMPL_RDCRVSLIB_H_
#include <memory>
#include <vector>
#include "rdc/rdc.h"
#include "rdc_lib/RdcDiagnostic.h"
@@ -51,7 +50,6 @@ class RdcRVSLib : public RdcDiagnostic {
rdc_status_t rdc_diag_destroy() override;
RdcRVSLib();
~RdcRVSLib() override;
private:
+1 -1
Wyświetl plik
@@ -49,7 +49,7 @@ class RdcRocpLib : public RdcTelemetry {
rdc_status_t rdc_telemetry_fields_unwatch(rdc_gpu_field_t* fields,
uint32_t fields_count) override;
explicit RdcRocpLib(const char* lib_name);
RdcRocpLib();
~RdcRocpLib();
-1
Wyświetl plik
@@ -23,7 +23,6 @@ THE SOFTWARE.
#define INCLUDE_RDC_LIB_IMPL_RDCSMILIB_H_
#include <memory>
#include <vector>
#include "rdc_lib/RdcDiagnostic.h"
#include "rdc_lib/RdcMetricFetcher.h"
@@ -47,7 +47,7 @@ class RdcTelemetryModule : public RdcTelemetry {
rdc_status_t rdc_telemetry_fields_unwatch(rdc_gpu_field_t* fields, uint32_t fields_count);
explicit RdcTelemetryModule(RdcMetricFetcherPtr fetcher);
explicit RdcTelemetryModule(std::list<RdcTelemetryPtr> telemetry_modules);
private:
//< Helper function to dispatch fields to module
-13
Wyświetl plik
@@ -28,19 +28,6 @@ THE SOFTWARE.
#include "rdc/rdc.h"
#define RDC_ERROR 0
#define RDC_INFO 1
#define RDC_DEBUG 2
#define RDC_LOG(debug_level, msg) \
do { \
auto& logger = amd::rdc::RdcLogger::getLogger(); \
if (logger.should_log((debug_level))) { \
logger.get_ostream() << logger.get_log_header((debug_level), __FILE__, __LINE__) << msg \
<< std::endl; \
} \
} while (0)
//<! The key to identify the field with <gpu_id, field_id>
typedef std::pair<uint32_t, rdc_field_t> RdcFieldKey;
@@ -1,27 +0,0 @@
/*
Copyright (c) 2021 - present Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef RDC_MODULES_RDC_DIAGNOSTIC_RDCDIAGNOSTICLIB_H_
#define RDC_MODULES_RDC_DIAGNOSTIC_RDCDIAGNOSTICLIB_H_
#include "rdc/rdc.h"
#include "rdc_lib/RdcTelemetryLibInterface.h"
#endif // RDC_MODULES_RDC_DIAGNOSTIC_RDCDIAGNOSTICLIB_H_
@@ -1,27 +0,0 @@
/*
Copyright (c) 2021 - present Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef RDC_MODULES_RDC_DIAGNOSTIC_RDCDIAGNOSTICLIB_H_
#define RDC_MODULES_RDC_DIAGNOSTIC_RDCDIAGNOSTICLIB_H_
#include "rdc/rdc.h"
#include "rdc_lib/RdcDiagnosticLibInterface.h"
#endif // RDC_MODULES_RDC_DIAGNOSTIC_RDCDIAGNOSTICLIB_H_