Performance Counter Functions#
Functions | |
rsmi_status_t | rsmi_dev_counter_group_supported (uint32_t dv_ind, rsmi_event_group_t group) |
Tell if an event group is supported by a given device. More... | |
rsmi_status_t | rsmi_dev_counter_create (uint32_t dv_ind, rsmi_event_type_t type, rsmi_event_handle_t *evnt_handle) |
Create a performance counter object. More... | |
rsmi_status_t | rsmi_dev_counter_destroy (rsmi_event_handle_t evnt_handle) |
Deallocate a performance counter object. More... | |
rsmi_status_t | rsmi_counter_control (rsmi_event_handle_t evt_handle, rsmi_counter_command_t cmd, void *cmd_args) |
Issue performance counter control commands. More... | |
rsmi_status_t | rsmi_counter_read (rsmi_event_handle_t evt_handle, rsmi_counter_value_t *value) |
Read the current value of a performance counter. More... | |
rsmi_status_t | rsmi_counter_available_counters_get (uint32_t dv_ind, rsmi_event_group_t grp, uint32_t *available) |
Get the number of currently available counters. More... | |
Detailed Description
These functions are used to configure, query and control performance counting.
These functions use the same mechanisms as the "perf" command line utility. They share the same underlying resources and have some similarities in how they are used. The events supported by this API should have corresponding perf events that can be seen with "perf stat ...". The events supported by perf can be seen with "perf list"
The types of events available and the ability to count those events are dependent on which device is being targeted and if counters are still available for that device, respectively. rsmi_dev_counter_group_supported() can be used to see which event types (rsmi_event_group_t) are supported for a given device. Assuming a device supports a given event type, we can then check to see if there are counters available to count a specific event with rsmi_counter_available_counters_get(). Counters may be occupied by other perf based programs.
Once it is determined that events are supported and counters are available, an event counter can be created/destroyed and controlled.
rsmi_dev_counter_create() allocates internal data structures that will be used to used to control the event counter, and return a handle to this data structure.
Once an event counter handle is obtained, the event counter can be controlled (i.e., started, stopped,...) with rsmi_counter_control() by passing rsmi_counter_command_t commands. RSMI_CNTR_CMD_START starts an event counter and RSMI_CNTR_CMD_STOP stops a counter. rsmi_counter_read() reads an event counter.
Once the counter is no longer needed, the resources it uses should be freed by calling rsmi_dev_counter_destroy().
Important Notes about Counter Values
- A running "absolute" counter is kept internally. For the discussion that follows, we will call the internal counter value at time t valt
- Issuing RSMI_CNTR_CMD_START or calling rsmi_counter_read(), causes RSMI (in kernel) to internally record the current absolute counter value
- rsmi_counter_read() returns the number of events that have occurred since the previously recorded value (ie, a relative value, valt - valt-1) from the issuing of RSMI_CNTR_CMD_START or calling rsmi_counter_read()
Example of event counting sequence:
Function Documentation
◆ rsmi_dev_counter_group_supported()
rsmi_status_t rsmi_dev_counter_group_supported | ( | uint32_t | dv_ind, |
rsmi_event_group_t | group | ||
) |
Tell if an event group is supported by a given device.
Given a device index dv_ind
and an event group specifier group
, tell if group
type events are supported by the device associated with dv_ind
- Parameters
-
[in] dv_ind device index of device being queried [in] group rsmi_event_group_t identifier of group for which support is being queried
- Return values
-
RSMI_STATUS_SUCCESS if the device associatee with dv_ind
support counting events of the type indicated bygroup
.RSMI_STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments group
◆ rsmi_dev_counter_create()
rsmi_status_t rsmi_dev_counter_create | ( | uint32_t | dv_ind, |
rsmi_event_type_t | type, | ||
rsmi_event_handle_t * | evnt_handle | ||
) |
Create a performance counter object.
Create a performance counter object of type type
for the device with a device index of dv_ind
, and write a handle to the object to the memory location pointed to by evnt_handle
. evnt_handle
can be used with other performance event operations. The handle should be deallocated with rsmi_dev_counter_destroy() when no longer needed.
- Parameters
-
[in] dv_ind a device index [in] type the rsmi_event_type_t of performance event to create [in,out] evnt_handle A pointer to a rsmi_event_handle_t which will be associated with a newly allocated counter If this parameter is nullptr, this function will return RSMI_STATUS_INVALID_ARGS if the function is supported with the provided, arguments and RSMI_STATUS_NOT_SUPPORTED if it is not supported with the provided arguments.
- Return values
-
RSMI_STATUS_SUCCESS call was successful RSMI_STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments RSMI_STATUS_INVALID_ARGS the provided arguments are not valid RSMI_STATUS_OUT_OF_RESOURCES unable to allocate memory for counter RSMI_STATUS_PERMISSION function requires root access
◆ rsmi_dev_counter_destroy()
rsmi_status_t rsmi_dev_counter_destroy | ( | rsmi_event_handle_t | evnt_handle | ) |
Deallocate a performance counter object.
Deallocate the performance counter object with the provided rsmi_event_handle_t evnt_handle
- Parameters
-
[in] evnt_handle handle to event object to be deallocated
- Return values
-
RSMI_STATUS_SUCCESS is returned upon successful call RSMI_STATUS_INVALID_ARGS the provided arguments are not valid RSMI_STATUS_PERMISSION function requires root access
◆ rsmi_counter_control()
rsmi_status_t rsmi_counter_control | ( | rsmi_event_handle_t | evt_handle, |
rsmi_counter_command_t | cmd, | ||
void * | cmd_args | ||
) |
Issue performance counter control commands.
Issue a command cmd
on the event counter associated with the provided handle evt_handle
.
- Parameters
-
[in] evt_handle an event handle [in] cmd The event counter command to be issued [in,out] cmd_args Currently not used. Should be set to NULL.
- Return values
-
RSMI_STATUS_SUCCESS is returned upon successful call RSMI_STATUS_INVALID_ARGS the provided arguments are not valid RSMI_STATUS_PERMISSION function requires root access
◆ rsmi_counter_read()
rsmi_status_t rsmi_counter_read | ( | rsmi_event_handle_t | evt_handle, |
rsmi_counter_value_t * | value | ||
) |
Read the current value of a performance counter.
Read the current counter value of the counter associated with the provided handle evt_handle
and write the value to the location pointed to by value
.
- Parameters
-
[in] evt_handle an event handle [in,out] value pointer to memory of size of rsmi_counter_value_t to which the counter value will be written
- Return values
-
RSMI_STATUS_SUCCESS is returned upon successful call RSMI_STATUS_INVALID_ARGS the provided arguments are not valid RSMI_STATUS_PERMISSION function requires root access
◆ rsmi_counter_available_counters_get()
rsmi_status_t rsmi_counter_available_counters_get | ( | uint32_t | dv_ind, |
rsmi_event_group_t | grp, | ||
uint32_t * | available | ||
) |
Get the number of currently available counters.
Given a device index dv_ind
, a performance event group grp
, and a pointer to a uint32_t available
, this function will write the number of grp
type counters that are available on the device with index dv_ind
to the memory that available
points to.
- Parameters
-
[in] dv_ind a device index [in] grp an event device group [in,out] available A pointer to a uint32_t to which the number of available counters will be written
- Return values
-
RSMI_STATUS_SUCCESS is returned upon successful call RSMI_STATUS_INVALID_ARGS the provided arguments are not valid