Enable RDC policy feature
1. Add policy APIs 2. Add policy example for policy API usage Change-Id: I14deb7c809d0b865b7bb083842092fc37868025e Signed-off-by: Chao Fei <Chao.Fei@amd.com>
This commit is contained in:
@@ -31,6 +31,7 @@ THE SOFTWARE.
|
||||
#include "rdc_lib/RdcMetricsUpdater.h"
|
||||
#include "rdc_lib/RdcModuleMgr.h"
|
||||
#include "rdc_lib/RdcNotification.h"
|
||||
#include "rdc_lib/RdcPolicy.h"
|
||||
#include "rdc_lib/RdcWatchTable.h"
|
||||
|
||||
namespace amd {
|
||||
@@ -94,6 +95,18 @@ class RdcEmbeddedHandler final : public RdcHandler {
|
||||
// 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;
|
||||
// Policy API
|
||||
rdc_status_t rdc_policy_set(rdc_gpu_group_t group_id, rdc_policy_t policy) override;
|
||||
|
||||
rdc_status_t rdc_policy_get(rdc_gpu_group_t group_id, uint32_t* count,
|
||||
rdc_policy_t policies[RDC_MAX_POLICY_SETTINGS]) override;
|
||||
|
||||
rdc_status_t rdc_policy_delete(rdc_gpu_group_t group_id,
|
||||
rdc_policy_condition_type_t condition_type) override;
|
||||
|
||||
rdc_status_t rdc_policy_register(rdc_gpu_group_t group_id, rdc_policy_register_callback callback) override;
|
||||
|
||||
rdc_status_t rdc_policy_unregister(rdc_gpu_group_t group_id) override;
|
||||
|
||||
explicit RdcEmbeddedHandler(rdc_operation_mode_t op_mode);
|
||||
~RdcEmbeddedHandler() final;
|
||||
@@ -107,6 +120,7 @@ class RdcEmbeddedHandler final : public RdcHandler {
|
||||
RdcNotificationPtr rdc_notif_;
|
||||
RdcWatchTablePtr watch_table_;
|
||||
RdcMetricsUpdaterPtr metrics_updater_;
|
||||
RdcPolicyPtr policy_;
|
||||
std::future<void> updater_;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
Copyright (c) 2024 - 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 INCLUDE_RDC_LIB_IMPL_RDCPOLICYIMPL_H_
|
||||
#define INCLUDE_RDC_LIB_IMPL_RDCPOLICYIMPL_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex> // NOLINT
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <future>
|
||||
|
||||
#include "amd_smi/amdsmi.h"
|
||||
#include "rdc_lib/RdcPolicy.h"
|
||||
#include "rdc_lib/RdcMetricFetcher.h"
|
||||
#include "rdc_lib/RdcGroupSettings.h"
|
||||
|
||||
namespace amd {
|
||||
namespace rdc {
|
||||
|
||||
class RdcPolicyImpl : public RdcPolicy {
|
||||
public:
|
||||
RdcPolicyImpl(const RdcGroupSettingsPtr& group_settings, const RdcMetricFetcherPtr& metric_fetcher);
|
||||
~RdcPolicyImpl();
|
||||
|
||||
rdc_status_t rdc_policy_set(rdc_gpu_group_t group_id, rdc_policy_t policy) override;
|
||||
|
||||
rdc_status_t rdc_policy_get(rdc_gpu_group_t group_id, uint32_t* count,
|
||||
rdc_policy_t policies[RDC_MAX_POLICY_SETTINGS]) override;
|
||||
|
||||
rdc_status_t rdc_policy_delete(rdc_gpu_group_t group_id,
|
||||
rdc_policy_condition_type_t condition_type) override;
|
||||
|
||||
rdc_status_t rdc_policy_register(rdc_gpu_group_t group_id,rdc_policy_register_callback callback) override;
|
||||
|
||||
rdc_status_t rdc_policy_unregister(rdc_gpu_group_t group_id) override;
|
||||
|
||||
private:
|
||||
RdcGroupSettingsPtr group_settings_;
|
||||
RdcMetricFetcherPtr metric_fetcher_;
|
||||
std::mutex policy_mutex_;
|
||||
std::thread thread_;
|
||||
bool start_;
|
||||
|
||||
std::map<rdc_gpu_group_t, std::vector<rdc_policy_t> > settings_;
|
||||
std::map<rdc_gpu_group_t, rdc_policy_register_callback> callbacks_;
|
||||
|
||||
void rdc_policy_check_condition();
|
||||
void rdc_policy_gpu_reset(uint32_t gpu_index);
|
||||
rdc_policy_register_callback rdc_policy_get_callback(rdc_gpu_group_t group_id);
|
||||
};
|
||||
|
||||
} // namespace rdc
|
||||
} // namespace amd
|
||||
|
||||
#endif // INCLUDE_RDC_LIB_IMPL_RDCPOLICYIMPL_H_
|
||||
@@ -24,6 +24,8 @@ THE SOFTWARE.
|
||||
#include <grpcpp/grpcpp.h>
|
||||
|
||||
#include <memory>
|
||||
#include <future>
|
||||
#include <thread>
|
||||
|
||||
#include "rdc.grpc.pb.h" // NOLINT
|
||||
#include "rdc_lib/RdcHandler.h"
|
||||
@@ -89,6 +91,18 @@ class RdcStandaloneHandler : public RdcHandler {
|
||||
// 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;
|
||||
// Policy API
|
||||
rdc_status_t rdc_policy_set(rdc_gpu_group_t group_id, rdc_policy_t policy) override;
|
||||
|
||||
rdc_status_t rdc_policy_get(rdc_gpu_group_t group_id, uint32_t* count, rdc_policy_t policies[RDC_MAX_POLICY_SETTINGS]) override;
|
||||
|
||||
rdc_status_t rdc_policy_delete(rdc_gpu_group_t group_id,
|
||||
rdc_policy_condition_type_t condition_type) override;
|
||||
|
||||
rdc_status_t rdc_policy_register(rdc_gpu_group_t group_id,
|
||||
rdc_policy_register_callback callback) override;
|
||||
|
||||
rdc_status_t rdc_policy_unregister(rdc_gpu_group_t group_id) override;
|
||||
|
||||
explicit RdcStandaloneHandler(const char* ip_and_port, const char* root_ca,
|
||||
const char* client_cert, const char* client_key);
|
||||
@@ -100,6 +114,15 @@ class RdcStandaloneHandler : public RdcHandler {
|
||||
bool copy_gpu_usage_info(const ::rdc::GpuUsageInfo& src, rdc_gpu_usage_info_t* target);
|
||||
|
||||
std::unique_ptr<::rdc::RdcAPI::Stub> stub_;
|
||||
// thread for policy callback
|
||||
|
||||
struct policy_thread_context {
|
||||
bool start;
|
||||
std::thread *t;
|
||||
};
|
||||
|
||||
std::map<uint32_t, struct policy_thread_context> policy_threads_;
|
||||
|
||||
};
|
||||
|
||||
} // namespace rdc
|
||||
|
||||
Reference in New Issue
Block a user