From cd98bb7f9013bcdfe40bf9c4504676cfed44b6f8 Mon Sep 17 00:00:00 2001 From: Chen Gong Date: Sun, 25 Aug 2024 00:18:48 +0800 Subject: [PATCH] Implement the code related to the GetMixedComponentVersion() Change-Id: I98aad97b4cb6498b7f2fc03a2d5ee7c9e949d5f1 Signed-off-by: Chen Gong [ROCm/rdc commit: 1edd04d84eafb30fda178d00cee1f7004a60a56d] --- projects/rdc/include/rdc/rdc_private.h | 66 +++++++++++++++++++ projects/rdc/include/rdc_lib/RdcHandler.h | 5 ++ .../include/rdc_lib/impl/RdcEmbeddedHandler.h | 4 ++ .../rdc_lib/impl/RdcStandaloneHandler.h | 4 ++ .../rdc_libs/bootstrap/src/RdcBootStrap.cc | 10 +++ .../rdc_libs/rdc/src/RdcEmbeddedHandler.cc | 8 +++ .../rdc_client/src/RdcStandaloneHandler.cc | 22 +++++++ .../rdc/server/include/rdc/rdc_api_service.h | 2 + projects/rdc/server/src/rdc_api_service.cc | 33 +++++++++- 9 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 projects/rdc/include/rdc/rdc_private.h diff --git a/projects/rdc/include/rdc/rdc_private.h b/projects/rdc/include/rdc/rdc_private.h new file mode 100644 index 0000000000..e9ccb937ad --- /dev/null +++ b/projects/rdc/include/rdc/rdc_private.h @@ -0,0 +1,66 @@ + +#ifndef INCLUDE_RDC_RDC_PRIVATE_H_ +#define INCLUDE_RDC_RDC_PRIVATE_H_ + +#include "rdc/rdc.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +#ifdef __cplusplus + +// cstddef include causes issues on older GCC +// use stddef.h instead +#if __GNUC__ < 9 +#include +#else +#include +#endif // __GNUC__ + +#include +#else +#include +#include +#endif // __cplusplus + +/** + * @brief The maximum string length occupied by version information. + */ +#define USR_MAX_VERSION_STR_LENGTH 60 + +/** + * @brief Version information of mixed components + */ +typedef struct { + char version[USR_MAX_VERSION_STR_LENGTH]; +} mixed_component_version_t; + +/** + * @brief Type of Components + */ +typedef enum { + RDCD_COMPONENT + //If needed later, add them one by one +} mixed_component_t; + +/** + * @brief Get ersion information of mixed components. + * + * @details Given a component type, return its version information. + * + * @param[in] p_rdc_handle The RDC handler. + * + * @param[in] component Component type. + * + * @param[out] p_mixed_compv Version information of the corresponding component. + * + * @retval ::RDC_ST_OK is returned upon successful call. + */ +rdc_status_t get_mixed_component_version(rdc_handle_t p_rdc_handle, mixed_component_t component, mixed_component_version_t* p_mixed_compv); + +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // INCLUDE_RDC_RDC_PRIVATE_H_ \ No newline at end of file diff --git a/projects/rdc/include/rdc_lib/RdcHandler.h b/projects/rdc/include/rdc_lib/RdcHandler.h index f5b92efcb9..167802fc55 100644 --- a/projects/rdc/include/rdc_lib/RdcHandler.h +++ b/projects/rdc/include/rdc_lib/RdcHandler.h @@ -23,6 +23,7 @@ THE SOFTWARE. #define INCLUDE_RDC_LIB_RDCHANDLER_H_ #include "rdc/rdc.h" +#include "rdc/rdc_private.h" #include "rdc_lib/rdc_common.h" namespace amd { @@ -88,6 +89,10 @@ class RdcHandler { // Control API virtual rdc_status_t rdc_field_update_all(uint32_t wait_for_update) = 0; + // It is just a client interface under the GRPC framework and is not used as an RDC API. + // The reason is that RdcEmbeddedHandler::get_mixed_component_version does not need to be called. + virtual rdc_status_t get_mixed_component_version(mixed_component_t component, mixed_component_version_t* p_mixed_compv) = 0; + virtual ~RdcHandler() {} }; diff --git a/projects/rdc/include/rdc_lib/impl/RdcEmbeddedHandler.h b/projects/rdc/include/rdc_lib/impl/RdcEmbeddedHandler.h index 8d08cbefb4..b6463076ed 100644 --- a/projects/rdc/include/rdc_lib/impl/RdcEmbeddedHandler.h +++ b/projects/rdc/include/rdc_lib/impl/RdcEmbeddedHandler.h @@ -91,6 +91,10 @@ class RdcEmbeddedHandler final : public RdcHandler { // Control API rdc_status_t rdc_field_update_all(uint32_t wait_for_update) override; + // It is just a client interface under the GRPC framework and is not used as an RDC API. + // Pure virtual functions need to be overridden. + rdc_status_t get_mixed_component_version(mixed_component_t component, mixed_component_version_t* p_mixed_compv) override; + explicit RdcEmbeddedHandler(rdc_operation_mode_t op_mode); ~RdcEmbeddedHandler() final; diff --git a/projects/rdc/include/rdc_lib/impl/RdcStandaloneHandler.h b/projects/rdc/include/rdc_lib/impl/RdcStandaloneHandler.h index af81355779..5434b46ff7 100644 --- a/projects/rdc/include/rdc_lib/impl/RdcStandaloneHandler.h +++ b/projects/rdc/include/rdc_lib/impl/RdcStandaloneHandler.h @@ -86,6 +86,10 @@ class RdcStandaloneHandler : public RdcHandler { // Control RdcAPI rdc_status_t rdc_field_update_all(uint32_t wait_for_update) override; + // It is just a client interface under the GRPC framework and is not used as an RDC API. + // Pure virtual functions need to be overridden + rdc_status_t get_mixed_component_version(mixed_component_t component, mixed_component_version_t* p_mixed_compv) override; + explicit RdcStandaloneHandler(const char* ip_and_port, const char* root_ca, const char* client_cert, const char* client_key); diff --git a/projects/rdc/rdc_libs/bootstrap/src/RdcBootStrap.cc b/projects/rdc/rdc_libs/bootstrap/src/RdcBootStrap.cc index 9f5268654d..91a74f19fa 100644 --- a/projects/rdc/rdc_libs/bootstrap/src/RdcBootStrap.cc +++ b/projects/rdc/rdc_libs/bootstrap/src/RdcBootStrap.cc @@ -26,6 +26,7 @@ THE SOFTWARE. #include "common/rdc_fields_supported.h" #include "rdc/rdc.h" +#include "rdc/rdc_private.h" #include "rdc_lib/RdcHandler.h" #include "rdc_lib/RdcLibraryLoader.h" #include "rdc_lib/RdcLogger.h" @@ -324,6 +325,15 @@ rdc_status_t rdc_test_case_run(rdc_handle_t p_rdc_handle, rdc_gpu_group_t group_ ->rdc_test_case_run(group_id, test_case, config, config_size, result); } +rdc_status_t get_mixed_component_version(rdc_handle_t p_rdc_handle, mixed_component_t component, mixed_component_version_t* p_mixed_compv) { + if (!p_rdc_handle || !p_mixed_compv) { + return RDC_ST_INVALID_HANDLER; + } + + return static_cast(p_rdc_handle) + ->get_mixed_component_version(component, p_mixed_compv); +} + const char* rdc_status_string(rdc_status_t result) { switch (result) { case RDC_ST_OK: diff --git a/projects/rdc/rdc_libs/rdc/src/RdcEmbeddedHandler.cc b/projects/rdc/rdc_libs/rdc/src/RdcEmbeddedHandler.cc index c70b0780f8..c7c8465788 100644 --- a/projects/rdc/rdc_libs/rdc/src/RdcEmbeddedHandler.cc +++ b/projects/rdc/rdc_libs/rdc/src/RdcEmbeddedHandler.cc @@ -421,5 +421,13 @@ rdc_status_t RdcEmbeddedHandler::rdc_field_update_all(uint32_t wait_for_update) return RDC_ST_OK; } +// It is just a client interface under the GRPC framework and is not used as an RDC API. +// Just write an empty function to solve compilation errors +rdc_status_t RdcEmbeddedHandler::get_mixed_component_version(mixed_component_t component, mixed_component_version_t* p_mixed_compv) { + (void)(component); + (void)(p_mixed_compv); + return RDC_ST_OK; +} + } // namespace rdc } // namespace amd diff --git a/projects/rdc/rdc_libs/rdc_client/src/RdcStandaloneHandler.cc b/projects/rdc/rdc_libs/rdc_client/src/RdcStandaloneHandler.cc index 52a88843ff..1664ebe4ec 100644 --- a/projects/rdc/rdc_libs/rdc_client/src/RdcStandaloneHandler.cc +++ b/projects/rdc/rdc_libs/rdc_client/src/RdcStandaloneHandler.cc @@ -662,5 +662,27 @@ rdc_status_t RdcStandaloneHandler::rdc_field_update_all(uint32_t wait_for_update return error_handle(status, reply.status()); } +// It is only an interface for the client under the GRPC framework and is not used as an RDC API. +rdc_status_t RdcStandaloneHandler::get_mixed_component_version(mixed_component_t component, mixed_component_version_t* p_mixed_compv) { + + if (!p_mixed_compv) { + return RDC_ST_BAD_PARAMETER; + } + + ::rdc::GetMixedComponentVersionRequest request; + ::rdc::GetMixedComponentVersionResponse reply; + ::grpc::ClientContext context; + + request.set_component_id(component); + ::grpc::Status status = stub_->GetMixedComponentVersion(&context, request, &reply); + + rdc_status_t err_status = error_handle(status, reply.status()); + if (err_status != RDC_ST_OK) return err_status; + + strncpy_with_null(p_mixed_compv->version, reply.version().c_str(), USR_MAX_VERSION_STR_LENGTH); + return RDC_ST_OK; + +} + } // namespace rdc } // namespace amd diff --git a/projects/rdc/server/include/rdc/rdc_api_service.h b/projects/rdc/server/include/rdc/rdc_api_service.h index b8011de9a6..a91ee90661 100644 --- a/projects/rdc/server/include/rdc/rdc_api_service.h +++ b/projects/rdc/server/include/rdc/rdc_api_service.h @@ -125,6 +125,8 @@ class RdcAPIServiceImpl final : public ::rdc::RdcAPI::Service { const ::rdc::DiagnosticTestCaseRunRequest* request, ::rdc::DiagnosticTestCaseRunResponse* reply) override; + ::grpc::Status GetMixedComponentVersion(::grpc::ServerContext* context, const ::rdc::GetMixedComponentVersionRequest* request, + ::rdc::GetMixedComponentVersionResponse* reply) override; private: bool copy_gpu_usage_info(const rdc_gpu_usage_info_t& src, ::rdc::GpuUsageInfo* target); rdc_handle_t rdc_handle_; diff --git a/projects/rdc/server/src/rdc_api_service.cc b/projects/rdc/server/src/rdc_api_service.cc index 30ebc6421e..66c86d57da 100644 --- a/projects/rdc/server/src/rdc_api_service.cc +++ b/projects/rdc/server/src/rdc_api_service.cc @@ -20,7 +20,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "rdc/rdc_api_service.h" - +#include "rdc/rdc_server_main.h" #include #include @@ -31,6 +31,7 @@ THE SOFTWARE. #include "rdc.grpc.pb.h" // NOLINT #include "rdc/rdc.h" +#include "rdc/rdc_private.h" #include "rdc_lib/RdcLogger.h" #include "rdc_lib/rdc_common.h" @@ -660,5 +661,35 @@ bool RdcAPIServiceImpl::copy_gpu_usage_info(const rdc_gpu_usage_info_t& src, return ::grpc::Status::OK; } +::grpc::Status RdcAPIServiceImpl::GetMixedComponentVersion(::grpc::ServerContext* context, + const ::rdc::GetMixedComponentVersionRequest* request, + ::rdc::GetMixedComponentVersionResponse* reply) { + (void)(context); + if (!reply) { + return ::grpc::Status(::grpc::StatusCode::INTERNAL, "Empty reply"); + } + + mixed_component_t component = static_cast(request->component_id()); + + if (component == RDCD_COMPONENT) { + std::string version = RDC_SERVER_VERSION_STRING; + std::string hash; + std::string rdcdversion; +#ifdef CURRENT_GIT_HASH + hash = QUOTE(CURRENT_GIT_HASH); + rdcdversion = version + "+" + hash; +#else + hash = ""; + rdcdversion = version; +#endif + + reply->set_version(rdcdversion); + reply->set_status(RDC_ST_OK); + return ::grpc::Status::OK; + } else { + return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "The provided request parameters are invalid"); + } +} + } // namespace rdc } // namespace amd