PC Sampling: Add create and destroy APIs
Implement PC Sampling session create and destroy APIs. Change-Id: I93370d3d01b74ee15e71b8b0e20feb8f0066a3dc Signed-off-by: David Yat Sin <David.YatSin@amd.com> Signed-off-by: Vladimir Indic <Vladimir.Indic@amd.com> Change-Id: Ib0c64356a1a4616b12d5dbeebe16273fe2a84abe
This commit is contained in:
@@ -192,6 +192,13 @@ class GpuAgentInt : public core::Agent {
|
||||
// @retval HSA_STATUS_SUCCESS if successful
|
||||
virtual hsa_status_t PcSamplingIterateConfig(hsa_ven_amd_pcs_iterate_configuration_callback_t cb,
|
||||
void* cb_data) = 0;
|
||||
|
||||
virtual hsa_status_t PcSamplingCreate(pcs::PcsRuntime::PcSamplingSession& session) = 0;
|
||||
|
||||
virtual hsa_status_t PcSamplingCreateFromId(HsaPcSamplingTraceId pcsId,
|
||||
pcs::PcsRuntime::PcSamplingSession& session) = 0;
|
||||
|
||||
virtual hsa_status_t PcSamplingDestroy(pcs::PcsRuntime::PcSamplingSession& session) = 0;
|
||||
};
|
||||
|
||||
class GpuAgent : public GpuAgentInt {
|
||||
@@ -474,6 +481,10 @@ class GpuAgent : public GpuAgentInt {
|
||||
|
||||
hsa_status_t PcSamplingIterateConfig(hsa_ven_amd_pcs_iterate_configuration_callback_t cb,
|
||||
void* cb_data);
|
||||
hsa_status_t PcSamplingCreate(pcs::PcsRuntime::PcSamplingSession& session);
|
||||
hsa_status_t PcSamplingCreateFromId(HsaPcSamplingTraceId pcsId,
|
||||
pcs::PcsRuntime::PcSamplingSession& session);
|
||||
hsa_status_t PcSamplingDestroy(pcs::PcsRuntime::PcSamplingSession& session);
|
||||
|
||||
// @brief Node properties.
|
||||
const HsaNodeProperties properties_;
|
||||
@@ -677,6 +688,15 @@ class GpuAgent : public GpuAgentInt {
|
||||
std::function<void*(size_t size, core::MemoryRegion::AllocateFlags flags)> finegrain_allocator_;
|
||||
|
||||
std::function<void(void*)> finegrain_deallocator_;
|
||||
|
||||
/* PC Sampling fields - begin */
|
||||
typedef struct {
|
||||
pcs::PcsRuntime::PcSamplingSession* session;
|
||||
} pcs_hosttrap_t;
|
||||
|
||||
pcs_hosttrap_t pcs_hosttrap_data_;
|
||||
/* PC Sampling fields - end */
|
||||
|
||||
// @brief device handle
|
||||
amdgpu_device_handle ldrm_dev_;
|
||||
|
||||
|
||||
@@ -113,7 +113,8 @@ GpuAgent::GpuAgent(HSAuint32 node, const HsaNodeProperties& node_props, bool xna
|
||||
sdma_blit_used_mask_(0),
|
||||
scratch_limit_async_threshold_(0),
|
||||
scratch_cache_(
|
||||
[this](void* base, size_t size, bool large) { ReleaseScratch(base, size, large); }) {
|
||||
[this](void* base, size_t size, bool large) { ReleaseScratch(base, size, large); }),
|
||||
pcs_hosttrap_data_() {
|
||||
const bool is_apu_node = (properties_.NumCPUCores > 0);
|
||||
profile_ = (is_apu_node) ? HSA_PROFILE_FULL : HSA_PROFILE_BASE;
|
||||
|
||||
@@ -2362,6 +2363,49 @@ hsa_status_t GpuAgent::PcSamplingIterateConfig(hsa_ven_amd_pcs_iterate_configura
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
hsa_status_t GpuAgent::PcSamplingCreate(pcs::PcsRuntime::PcSamplingSession& session) {
|
||||
HsaPcSamplingInfo sampleInfo = {};
|
||||
HsaPcSamplingTraceId thunkId;
|
||||
|
||||
// IOCTL id does not exist at the moment, so passing 0 is OK,
|
||||
// since it will be overridden later in this function.
|
||||
hsa_status_t ret = PcSamplingCreateFromId(0, session);
|
||||
if (ret != HSA_STATUS_SUCCESS) return ret;
|
||||
|
||||
session.GetHsaKmtSamplingInfo(&sampleInfo);
|
||||
HSAKMT_STATUS retkmt = hsaKmtPcSamplingCreate(node_id(), &sampleInfo, &thunkId);
|
||||
if (retkmt != HSAKMT_STATUS_SUCCESS) {
|
||||
return (retkmt == HSAKMT_STATUS_KERNEL_ALREADY_OPENED) ? (hsa_status_t)HSA_STATUS_ERROR_RESOURCE_BUSY
|
||||
: HSA_STATUS_ERROR;
|
||||
}
|
||||
|
||||
debug_print("Created PC sampling session with thunkId:%d\n", thunkId);
|
||||
|
||||
session.SetThunkId(thunkId);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
hsa_status_t GpuAgent::PcSamplingCreateFromId(HsaPcSamplingTraceId ioctlId,
|
||||
pcs::PcsRuntime::PcSamplingSession& session) {
|
||||
pcs_hosttrap_t& ht_data = pcs_hosttrap_data_;
|
||||
|
||||
if (session.method() == HSA_VEN_AMD_PCS_METHOD_HOSTTRAP_V1 && ht_data.session)
|
||||
return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
|
||||
|
||||
session.SetThunkId(ioctlId);
|
||||
ht_data.session = &session;
|
||||
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
hsa_status_t GpuAgent::PcSamplingDestroy(pcs::PcsRuntime::PcSamplingSession& session) {
|
||||
pcs_hosttrap_t& ht_data = pcs_hosttrap_data_;
|
||||
HSAKMT_STATUS retKmt = hsaKmtPcSamplingDestroy(node_id(), session.ThunkId());
|
||||
ht_data.session = NULL;
|
||||
|
||||
return (retKmt == HSAKMT_STATUS_SUCCESS) ? HSA_STATUS_SUCCESS : HSA_STATUS_ERROR;
|
||||
}
|
||||
|
||||
} // namespace amd
|
||||
} // namespace rocr
|
||||
|
||||
Reference in New Issue
Block a user