NVIDIA DriveOS Linux SDK API Reference

7.2.5.0 Early Access Release
stm_logging.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2018-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6  * property and proprietary rights in and to this material, related
7  * documentation and any modifications thereto. Any use, reproduction,
8  * disclosure or distribution of this material and related documentation
9  * without an express license agreement from NVIDIA CORPORATION or
10  * its affiliates is strictly prohibited.
11  */
12 
30 #ifndef STM_LOGGING_H_
31 #define STM_LOGGING_H_
32 
33 #if __GNUC__ >= 4
34 #define STM_API __attribute__((visibility("default")))
35 #endif
36 
37 #include <stddef.h>
38 #include <stdbool.h>
39 #include <limits.h>
40 #include "stm_error.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
52 // Max number of bytes allowed for resource names in STM. Includes room for terminating character.
53 #define STM_RESOURCE_NAME_MAX (41)
54 // Max number of schedules permitted to run
55 #define STM_MAX_SCHEDULES (8)
56 
60 typedef enum __attribute__((__packed__)) {
72 
76 typedef enum __attribute__((__packed__)) stmEventType_t {
140 
141 typedef uint16_t stmElementOptionalVal;
142 typedef uint64_t stmElementTimestamp;
143 
147 typedef enum __attribute__((__packed__)) {
203 
207 typedef struct
208 {
212  uint32_t frame;
216  uint16_t scheduleId;
222 
226 typedef struct
227 {
229  uint64_t logTime;
231  uint32_t optVal1;
233  uint16_t optVal2;
235  uint16_t scheduleId;
240 } stmPerfInfo_t;
241 
245 typedef struct
246 {
248  uint64_t logTime;
250  uint32_t hyperepochHash;
252  uint16_t optVal;
254  uint16_t scheduleId;
260 
270 typedef int (*stmLoggingEventCallback_t)(void* userdata, stmElementInfo_t* buf, size_t size);
271 
281 typedef int (*stmLoggingStateCallback_t)(void* userdata, stmStateInfo_t* buf, size_t size);
282 
292 typedef int (*stmLoggingPerfInfoCallback_t)(void* userdata, stmPerfInfo_t* buf, size_t size);
293 
297 typedef struct
298 {
300  uint32_t major;
302  uint32_t minor;
304  uint32_t patch;
306  uint32_t numSchedules;
308  uint16_t scheduleIds[STM_MAX_SCHEDULES];
310  char scheduleNames[STM_MAX_SCHEDULES][PATH_MAX];
314 
331 
350 STM_API stmErrorCode_t stmLoggerInitWithDiscriminator(int32_t discriminator, stmHeaderInfo_t* header);
351 
366 
381 
396 
410 
421 STM_API stmErrorCode_t stmLoggerFlush(void);
422 
431 STM_API stmErrorCode_t stmLoggerExit(void);
432 
437 #ifdef __cplusplus
438 }
439 #endif
440 #endif // STM_LOGGING_H_
stmPerfInfo_t
A singular perfInfo event.
Definition: stm_logging.h:226
stmElementInfo_t::optVal
stmElementOptionalVal optVal
Optional value (provides additional context depending on event, eg, which runnables' start/end is bei...
Definition: stm_logging.h:214
STM_EVENT_RUNNABLE_END
@ STM_EVENT_RUNNABLE_END
Event logged when a CPU runnable ends.
Definition: stm_logging.h:96
STM_EVENT_MAX
@ STM_EVENT_MAX
Max log value.
Definition: stm_logging.h:138
stmElementTimestamp
uint64_t stmElementTimestamp
Definition: stm_logging.h:142
stmClock_DGPU
@ stmClock_DGPU
Dedicated GPU clock.
Definition: stm_logging.h:68
STM_EVENT_THREAD_START
@ STM_EVENT_THREAD_START
Event to collect active thread start time.
Definition: stm_logging.h:132
stmStateInfo_t::logEventId
stmEventType_t logEventId
Type of event being logged.
Definition: stm_logging.h:256
STM_EVENT_NV2DSUB_OVERHEAD
@ STM_EVENT_NV2DSUB_OVERHEAD
Event to collect runtime overhead for NV2DSUB STM command.
Definition: stm_logging.h:126
SCHED_CALLBACK_START
@ SCHED_CALLBACK_START
Rollover schedule switch callback start timestamp.
Definition: stm_logging.h:181
STM_EVENT_FENCE_TIMESTAMP_CF
@ STM_EVENT_FENCE_TIMESTAMP_CF
Event logged when a fence is signaled.
Definition: stm_logging.h:90
stmElementInfo_t::logEventId
stmEventType_t logEventId
Type of event being logged.
Definition: stm_logging.h:218
stmElementInfo_t::frame
uint32_t frame
Hyperepoch frame where event occurred.
Definition: stm_logging.h:212
stmElementInfo_t::logClkSource
stmClockInfo_t logClkSource
Clock source from which time has been obtained.
Definition: stm_logging.h:220
stmPerformanceEvent_t
stmPerformanceEvent_t
Type of event being logged for STM_EVENT_PERFORMANCE events.
Definition: stm_logging.h:147
STM_EVENT_RUNNABLE_START
@ STM_EVENT_RUNNABLE_START
Event logged when a CPU runnable starts.
Definition: stm_logging.h:94
stmLoggingPerfInfoCallback_t
int(* stmLoggingPerfInfoCallback_t)(void *userdata, stmPerfInfo_t *buf, size_t size)
Function signature for perfInfo log Callbacks.
Definition: stm_logging.h:292
INIT_MEMORY_OVERHEAD
@ INIT_MEMORY_OVERHEAD
STM master init memory overhead.
Definition: stm_logging.h:185
stm_error.h
Return/error codes for all STM functions.
stmClock_HW
@ stmClock_HW
Timestamp Counter.
Definition: stm_logging.h:62
LOGGER_SETUP_TIME_STOP
@ LOGGER_SETUP_TIME_STOP
STM master logger setup done.
Definition: stm_logging.h:197
STM_EVENT_EXECUTION_END
@ STM_EVENT_EXECUTION_END
End of hyperepoch frame.
Definition: stm_logging.h:80
stmPerfInfo_t::scheduleId
uint16_t scheduleId
Schedule ID.
Definition: stm_logging.h:235
STM_EVENT_NV2DF_OVERHEAD
@ STM_EVENT_NV2DF_OVERHEAD
Event to collect runtime overhead for NV2DF STM command.
Definition: stm_logging.h:128
stmClock_THREAD_CPU
@ stmClock_THREAD_CPU
Thread-specific CPU clock.
Definition: stm_logging.h:70
stmLoggerInit
STM_API stmErrorCode_t stmLoggerInit(stmHeaderInfo_t *header)
Initialize STM logger context.
stmRegisterPerfInfoCallBack
STM_API stmErrorCode_t stmRegisterPerfInfoCallBack(stmLoggingPerfInfoCallback_t func, void *userdata)
Registers a callback function with the Logger to be invoked during a perfInfo buffer write.
stmLoggingStateCallback_t
int(* stmLoggingStateCallback_t)(void *userdata, stmStateInfo_t *buf, size_t size)
Function signature for STM state manager log callbacks.
Definition: stm_logging.h:281
STM_EVENT_PERFORMANCE
@ STM_EVENT_PERFORMANCE
Performance profiling related info.
Definition: stm_logging.h:104
STM_EVENT_CUF_OVERHEAD
@ STM_EVENT_CUF_OVERHEAD
Event to collect runtime overhead for CUF STM command.
Definition: stm_logging.h:108
stmHeaderInfo_t::numSchedules
uint32_t numSchedules
Number of schedules provided to runtime.
Definition: stm_logging.h:306
MANAGED_CLIENT_SPAWN_START
@ MANAGED_CLIENT_SPAWN_START
STM master launching managed clients start.
Definition: stm_logging.h:199
STM_EVENT_FENCE_TIMESTAMP_SF
@ STM_EVENT_FENCE_TIMESTAMP_SF
Event logged for engine (GPU only) fences before the start of the engine submittee.
Definition: stm_logging.h:92
stmElementInfo_t::logTime
stmElementTimestamp logTime
Time when event occurred.
Definition: stm_logging.h:210
stmElementInfo_t::scheduleId
uint16_t scheduleId
Schedule ID.
Definition: stm_logging.h:216
MANAGED_CLIENT_SPAWN_STOP
@ MANAGED_CLIENT_SPAWN_STOP
STM master launching managed clients stop.
Definition: stm_logging.h:201
INIT_TIME_DONE
@ INIT_TIME_DONE
STM master init completion timestamp.
Definition: stm_logging.h:151
SCHED_START_INIT
@ SCHED_START_INIT
Complete schedule switch init start timestamp.
Definition: stm_logging.h:169
stmEventType_t
stmEventType_t
Types of Events logged by STM.
Definition: stm_logging.h:76
SCHED_STOP_INIT
@ SCHED_STOP_INIT
Complete schedule switch stop start timestamp.
Definition: stm_logging.h:173
ARG_PARSING_TIME_DONE
@ ARG_PARSING_TIME_DONE
STM master commandline parsing completion timestamp.
Definition: stm_logging.h:155
STM_RESOURCE_NAME_MAX
#define STM_RESOURCE_NAME_MAX
Definition: stm_logging.h:53
STM_EVENT_TIMESTAMP_COLLECTION_OVERHEAD
@ STM_EVENT_TIMESTAMP_COLLECTION_OVERHEAD
Event to collect runtime overhead for engine fence timestamps.
Definition: stm_logging.h:130
SCHED_ROLLOVER_INIT
@ SCHED_ROLLOVER_INIT
Rollover schedule switch init start timestamp.
Definition: stm_logging.h:177
stmElementOptionalVal
uint16_t stmElementOptionalVal
Definition: stm_logging.h:141
stmStateInfo_t::scheduleId
uint16_t scheduleId
Schedule ID.
Definition: stm_logging.h:254
stmHeaderInfo_t::major
uint32_t major
Major number of STM.
Definition: stm_logging.h:300
SYNC_TIME_START
@ SYNC_TIME_START
STM master sync server setup start timestamp.
Definition: stm_logging.h:165
SCHED_PARSING_TIME_START
@ SCHED_PARSING_TIME_START
STM master schedule parsing start timestamp.
Definition: stm_logging.h:157
stmPerfInfo_t::optVal2
uint16_t optVal2
Optional value 2 (e.g.
Definition: stm_logging.h:233
stmStateInfo_t::logClkSource
stmClockInfo_t logClkSource
Clock source from which time has been obtained.
Definition: stm_logging.h:258
SCHED_STOP_DONE
@ SCHED_STOP_DONE
Complete schedule switch stop completion timestamp.
Definition: stm_logging.h:175
STM_EVENT_CLIENT_CRASH
@ STM_EVENT_CLIENT_CRASH
Connected client crashed [Deprecated].
Definition: stm_logging.h:88
STM_MAX_SCHEDULES
#define STM_MAX_SCHEDULES
Definition: stm_logging.h:55
stmLoggerInitWithDiscriminator
STM_API stmErrorCode_t stmLoggerInitWithDiscriminator(int32_t discriminator, stmHeaderInfo_t *header)
Initialize STM logger context with a discriminator.
stmHeaderInfo_t::patch
uint32_t patch
Patch number of STM.
Definition: stm_logging.h:304
stmClockInfo_t
stmClockInfo_t
Types of Clocks used by STM.
Definition: stm_logging.h:60
SCHED_START_DONE
@ SCHED_START_DONE
Complete schedule switch init completion timestamp.
Definition: stm_logging.h:171
STM_EVENT_CLIENT_CONNECT
@ STM_EVENT_CLIENT_CONNECT
Client connected [Deprecated].
Definition: stm_logging.h:84
STM_EVENT_CLIENT_DISCONNECT
@ STM_EVENT_CLIENT_DISCONNECT
Client disconnected [Deprecated].
Definition: stm_logging.h:86
STM_EVENT_CUDLASUB_OVERHEAD
@ STM_EVENT_CUDLASUB_OVERHEAD
Event to collect runtime overhead for CUDLASUB STM command.
Definition: stm_logging.h:114
STM_EVENT_CUDLAF_OVERHEAD
@ STM_EVENT_CUDLAF_OVERHEAD
Event to collect runtime overhead for CUDLAF STM command.
Definition: stm_logging.h:116
stmStateInfo_t::optVal
uint16_t optVal
Optional value (provides additional context depending on event)
Definition: stm_logging.h:252
SYNC_MEMORY_OVERHEAD
@ SYNC_MEMORY_OVERHEAD
STM master sync server memory overhead.
Definition: stm_logging.h:187
STM_EVENT_EXECUTION_START
@ STM_EVENT_EXECUTION_START
Start of hyperepoch frame.
Definition: stm_logging.h:78
stmClock_REALTIME
@ stmClock_REALTIME
Real time Counter.
Definition: stm_logging.h:64
stmEnterLoggingLoop
STM_API stmErrorCode_t stmEnterLoggingLoop()
Enters logging loop which logs at a set frequency.
STM_EVENT_FRAME_SKIPPED
@ STM_EVENT_FRAME_SKIPPED
Event logged instead of START/END if the frame execution was skipped.
Definition: stm_logging.h:82
STM_EVENT_COLLECT_TSC
@ STM_EVENT_COLLECT_TSC
Collect Timestamp Counter.
Definition: stm_logging.h:100
SCHED_ROLLOVER_DONE
@ SCHED_ROLLOVER_DONE
Rollover schedule switch done completion timestamp.
Definition: stm_logging.h:179
stmPerfInfo_t::logEventId
stmEventType_t logEventId
Type of event being logged.
Definition: stm_logging.h:237
SCHED_PARSING_TIME_DONE
@ SCHED_PARSING_TIME_DONE
STM master schedule parsing completion timestamp.
Definition: stm_logging.h:159
stmHeaderInfo_t
STM Log Header Information needed by STM Analytics.
Definition: stm_logging.h:297
stmLoggingEventCallback_t
int(* stmLoggingEventCallback_t)(void *userdata, stmElementInfo_t *buf, size_t size)
Function signature for STM event log callbacks.
Definition: stm_logging.h:270
STM_EVENT_VPUF_OVERHEAD
@ STM_EVENT_VPUF_OVERHEAD
Event to collect runtime overhead for VPUF STM command.
Definition: stm_logging.h:112
COMMAND_RESOURCE_MEMORY_OVERHEAD
@ COMMAND_RESOURCE_MEMORY_OVERHEAD
STM master command memory overhead.
Definition: stm_logging.h:189
ARG_PARSING_TIME_START
@ ARG_PARSING_TIME_START
STM master commandline parsing start timestamp.
Definition: stm_logging.h:153
SHM_COMM_SETUP_TIME_START
@ SHM_COMM_SETUP_TIME_START
STM master shm/com setup start.
Definition: stm_logging.h:191
SCHED_CALLBACK_DONE
@ SCHED_CALLBACK_DONE
Rollover schedule switch callback done completion timestamp.
Definition: stm_logging.h:183
STM_EVENT_VPUSUB_OVERHEAD
@ STM_EVENT_VPUSUB_OVERHEAD
Event to collect runtime overhead for VPUSUB STM command.
Definition: stm_logging.h:110
STM_EVENT_STATE_UPDATE
@ STM_EVENT_STATE_UPDATE
Change state.
Definition: stm_logging.h:102
SYNC_TIME_DONE
@ SYNC_TIME_DONE
STM master sync server setup completion timestamp.
Definition: stm_logging.h:167
SHM_COMM_SETUP_TIME_STOP
@ SHM_COMM_SETUP_TIME_STOP
STM master shm/com setup done.
Definition: stm_logging.h:193
stmPerfInfo_t::logClkSource
stmClockInfo_t logClkSource
Clock source from which time has been obtained.
Definition: stm_logging.h:239
STM_EVENT_VULKANSUB_OVERHEAD
@ STM_EVENT_VULKANSUB_OVERHEAD
Event to collect runtime overhead for VULKANSUB STM command.
Definition: stm_logging.h:118
stmRegisterStateCallBack
STM_API stmErrorCode_t stmRegisterStateCallBack(stmLoggingStateCallback_t func, void *userdata)
Registers a callback function with the Logger to be invoked during a state buffer write.
stmErrorCode_t
stmErrorCode_t
Return/error codes for all STM functions.
Definition: stm_error.h:54
COMMAND_RESOURCE_TIME_START
@ COMMAND_RESOURCE_TIME_START
STM master command setup start timestamp.
Definition: stm_logging.h:161
STM_EVENT_VULKANF_OVERHEAD
@ STM_EVENT_VULKANF_OVERHEAD
Event to collect runtime overhead for VULKANF STM command.
Definition: stm_logging.h:120
stmLoggerFlush
STM_API stmErrorCode_t stmLoggerFlush(void)
Flush all buffers to the callbacks.
COMMAND_RESOURCE_TIME_DONE
@ COMMAND_RESOURCE_TIME_DONE
STM master command setup completion timestamp.
Definition: stm_logging.h:163
STM_EVENT_COLLECT_RTC
@ STM_EVENT_COLLECT_RTC
Collect Real Time Clock timestamp.
Definition: stm_logging.h:98
stmPerfInfo_t::optVal1
uint32_t optVal1
Optional value 1 (e.g.
Definition: stm_logging.h:231
stmStateInfo_t
A singular State Manager event.
Definition: stm_logging.h:245
stmRegisterEventCallBack
STM_API stmErrorCode_t stmRegisterEventCallBack(stmLoggingEventCallback_t func, void *userdata)
Registers a callback function with the Logger to be invoked during a event buffer write.
LOGGER_SETUP_TIME_START
@ LOGGER_SETUP_TIME_START
STM master logger setup start.
Definition: stm_logging.h:195
STM_EVENT_LDCF_OVERHEAD
@ STM_EVENT_LDCF_OVERHEAD
Event to collect runtime overhead for LDCF STM command.
Definition: stm_logging.h:124
stmStateInfo_t::logTime
uint64_t logTime
Time when event occurred.
Definition: stm_logging.h:248
stmLoggerExit
STM_API stmErrorCode_t stmLoggerExit(void)
Cleans up STM logger context.
STM_EVENT_THREAD_END
@ STM_EVENT_THREAD_END
Event to collect active thread end time.
Definition: stm_logging.h:134
STM_EVENT_CUSUB_OVERHEAD
@ STM_EVENT_CUSUB_OVERHEAD
Event to collect runtime overhead for CUSUB STM command.
Definition: stm_logging.h:106
stmPerfInfo_t::logTime
uint64_t logTime
Time when event occurred.
Definition: stm_logging.h:229
stmStateInfo_t::hyperepochHash
uint32_t hyperepochHash
Hash of hyperepoch corresponding to the event.
Definition: stm_logging.h:250
STM_EVENT_LDCSUB_OVERHEAD
@ STM_EVENT_LDCSUB_OVERHEAD
Event to collect runtime overhead for LDCSUB STM command.
Definition: stm_logging.h:122
INIT_TIME_START
@ INIT_TIME_START
STM master init start timestamp.
Definition: stm_logging.h:149
stmClock_PTP_IOCTL_NVPPS
@ stmClock_PTP_IOCTL_NVPPS
PTP hardware clock.
Definition: stm_logging.h:66
STM_EVENT_ERROR
@ STM_EVENT_ERROR
Logged to indicate an error while logging [Deprecated].
Definition: stm_logging.h:136
stmElementInfo_t
A singular event.
Definition: stm_logging.h:207
stmHeaderInfo_t::minor
uint32_t minor
Minor number of STM.
Definition: stm_logging.h:302