From 55ba4575be4ab58e1f41df8e8583c937344dd2bd Mon Sep 17 00:00:00 2001 From: Felix DeGrood Date: Wed, 22 Feb 2023 01:40:19 +0000 Subject: [PATCH] intel: INTEL_MEASURE cpu mode INTEL_MEASURE normally measures timing of GPU events. However, it is sometimes useful to instead measure when these gfx API calls were requested of the driver. INTEL_MEASURE cpu can be used in in conjunction with other driver debug capabilities, like INTEL_DEBUG=pc for analyzing stalls/flushes or when debugger is attached, to track which frame you're currently on or where in the frame you're at. Initial commit, without plumbing into anv/iris. "INTEL_MEASURE=cpu" will collect a cpu timestamp for each INTEL_MEASURE event instead of GPU timestamps. Reviewed-by: Mark Janes Part-of: --- src/intel/common/intel_measure.c | 38 ++++++++++++++++++++++++++++---- src/intel/common/intel_measure.h | 9 ++++++++ 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/intel/common/intel_measure.c b/src/intel/common/intel_measure.c index 4a58945bc31..4364eaf1d97 100644 --- a/src/intel/common/intel_measure.c +++ b/src/intel/common/intel_measure.c @@ -38,6 +38,7 @@ #include #include "dev/intel_device_info.h" +#include "util/os_time.h" #include "util/u_debug.h" #include "util/macros.h" @@ -97,6 +98,7 @@ intel_measure_init(struct intel_measure_device *device) const char *interval_s = strstr(env_copy, "interval="); const char *batch_size_s = strstr(env_copy, "batch_size="); const char *buffer_size_s = strstr(env_copy, "buffer_size="); + const char *cpu_s = strstr(env_copy, "cpu"); while (true) { char *sep = strrchr(env_copy, ','); if (sep == NULL) @@ -206,10 +208,19 @@ intel_measure_init(struct intel_measure_device *device) config.buffer_size = buffer_size; } - fputs("draw_start,draw_end,frame,batch," - "event_index,event_count,type,count,vs,tcs,tes," - "gs,fs,cs,ms,ts,framebuffer,idle_us,time_us\n", - config.file); + if (cpu_s) { + config.cpu_measure = true; + } + + if (!config.cpu_measure) + fputs("draw_start,draw_end,frame,batch," + "event_index,event_count,type,count,vs,tcs,tes," + "gs,fs,cs,ms,ts,framebuffer,idle_us,time_us\n", + config.file); + else + fputs("draw_start,frame,batch,event_index,event_count," + "type,count\n", + config.file); } device->config = NULL; @@ -616,6 +627,25 @@ print_combined_results(struct intel_measure_device *measure_device, (double)duration_time_ns / 1000.0); } +/** + * Write data for a cpu event. + */ +void +intel_measure_print_cpu_result(unsigned int frame, + unsigned int batch_count, + unsigned int event_index, + unsigned int event_count, + unsigned int count, + const char* event_name) +{ + assert(config.cpu_measure); + uint64_t start_ns = os_time_get_nano(); + + fprintf(config.file, "%"PRIu64",%u,%3u,%3u,%u,%s,%u\n", + start_ns, frame, batch_count, event_index, event_count, + event_name, count); +} + /** * Empty the ringbuffer of events that can be printed. */ diff --git a/src/intel/common/intel_measure.h b/src/intel/common/intel_measure.h index 83a26599ec6..069924603a6 100644 --- a/src/intel/common/intel_measure.h +++ b/src/intel/common/intel_measure.h @@ -100,6 +100,9 @@ struct intel_measure_config { /* true when snapshots are currently being collected */ bool enabled; + + /* Measure CPU timing, not GPU timing */ + bool cpu_measure; }; struct intel_measure_batch; @@ -164,6 +167,12 @@ void intel_measure_frame_transition(unsigned frame); bool intel_measure_ready(struct intel_measure_batch *batch); struct intel_device_info; +void intel_measure_print_cpu_result(unsigned int frame, + unsigned int batch_count, + unsigned int event_index, + unsigned int event_count, + unsigned int count, + const char* event_name); void intel_measure_gather(struct intel_measure_device *device, const struct intel_device_info *info);