Add support for device counter collection ioctl (#46)

Add support for device counter colleciton ioctl

Adds support for the device counter collection IOCTL. This IOCTL
allows for device wide counters to be collected even if the queue
is not intercepted by rocprofiler-sdk (required for system profilers).

A test is also included which checks this behavior by creating a queue
that does not have profiling enabled on it and checks to see if SQ
counters can be read from it. Note: this test will be skipped if the KFD
version does not contain this IOCTL.

Right now the check is "soft" in that if the IOCTL is present and there
is an error with permissions, rocprofiler will continue but will print
an error stating that system wide device profiling and collected counter
values may be degraded. This is primarily to avoid breaking existing
users (like PAPI) who may not need the IOCTL's capability and to give
them time to update.

Co-authored-by: Benjamin Welton <ben@amd.com>
Bu işleme şunda yer alıyor:
Welton, Benjamin
2024-12-19 13:27:35 -08:00
işlemeyi yapan: GitHub
ebeveyn 9c21c49aa1
işleme c574881cdb
12 değiştirilmiş dosya ile 305 ekleme ve 61 silme
+14 -1
Dosyayı Görüntüle
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
// Copyright (c) 2024 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
@@ -29,6 +29,7 @@
#include "lib/rocprofiler-sdk/buffer.hpp"
#include "lib/rocprofiler-sdk/context/context.hpp"
#include "lib/rocprofiler-sdk/counters/ioctl.hpp"
namespace rocprofiler
{
@@ -97,6 +98,18 @@ CounterController::configure_agent_collection(rocprofiler_context_id_t context_i
return ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT;
}
if(counters::counter_collection_has_device_lock())
{
/**
* Note: This should retrun if the lock fails to aquire in the future. However, this
* is a change in the required permissions for rocprofiler and needs to be communicated
* with partners before strict enforcement. If the required permissions are not obtained,
* those profilers will function as they currently do (without any of the benefits of the
* IOCTL).
*/
counters::counter_collection_device_lock(rocprofiler::agent::get_agent(agent_id), true);
}
ctx.device_counter_collection->agent_data.emplace_back();
ctx.device_counter_collection->agent_data.back().callback_data =
rocprofiler_user_data_t{.ptr = user_data};