Add perf OA tools for GPUvis
Subsystems (2)
cover Add perf OA tools for GPUvis
The tools provided here enable capturing performance metrics from the i915 driver and are used in conjunction with the GPUvis software here -
https://github.com/mikesart/gpuvis
The changes required in GPUvis are wip and will be posted following the merge of these tools.
For more information, view tools/i915-perf/README in this patch series
Lionel Landwerlin (4):
lib/i915/perf: Add i915_perf library lib/i915/perf: Add support for loading perf configurations tools/i915/perf: Add i915 perf recorder tool lib/i915/perf: Add i915 perf data reader
lib/i915-perf.pc.in | 10 + lib/i915/perf-configs/README.md | 115 + lib/i915/perf-configs/codegen.py | 33 + lib/i915/perf-configs/guids.xml | 282 + lib/i915/perf-configs/mdapi-xml-convert.py | 1000 + lib/i915/perf-configs/oa-bdw.xml | 15653 ++++++++++++++++ lib/i915/perf-configs/oa-bxt.xml | 9595 ++++++++++ lib/i915/perf-configs/oa-cflgt2.xml | 10866 +++++++++++ lib/i915/perf-configs/oa-cflgt3.xml | 10933 +++++++++++ lib/i915/perf-configs/oa-chv.xml | 9757 ++++++++++ lib/i915/perf-configs/oa-cnl.xml | 10411 ++++++++++ lib/i915/perf-configs/oa-glk.xml | 9346 +++++++++ lib/i915/perf-configs/oa-hsw.xml | 4615 +++++ lib/i915/perf-configs/oa-icl.xml | 11899 ++++++++++++ lib/i915/perf-configs/oa-kblgt2.xml | 10866 +++++++++++ lib/i915/perf-configs/oa-kblgt3.xml | 10933 +++++++++++ lib/i915/perf-configs/oa-sklgt2.xml | 11895 ++++++++++++ lib/i915/perf-configs/oa-sklgt3.xml | 10933 +++++++++++ lib/i915/perf-configs/oa-sklgt4.xml | 10956 +++++++++++ lib/i915/perf-configs/perf-codegen.py | 854 + lib/i915/perf-configs/update-guids.py | 230 + lib/i915/perf.c | 332 + lib/i915/perf.h | 240 + lib/i915/perf_data.h | 88 + lib/i915/perf_data_reader.c | 330 + lib/i915/perf_data_reader.h | 103 + lib/meson.build | 67 + tools/i915-perf/README | 70 + tools/i915-perf/i915_perf_configs.c | 277 + tools/i915-perf/i915_perf_control.c | 133 + tools/i915-perf/i915_perf_recorder.c | 931 + tools/i915-perf/i915_perf_recorder_commands.h | 39 + tools/i915-perf/meson.build | 17 + tools/meson.build | 1 + 34 files changed, 153810 insertions(+) create mode 100644 lib/i915-perf.pc.in create mode 100644 lib/i915/perf-configs/README.md create mode 100644 lib/i915/perf-configs/codegen.py create mode 100644 lib/i915/perf-configs/guids.xml create mode 100755 lib/i915/perf-configs/mdapi-xml-convert.py create mode 100644 lib/i915/perf-configs/oa-bdw.xml create mode 100644 lib/i915/perf-configs/oa-bxt.xml create mode 100644 lib/i915/perf-configs/oa-cflgt2.xml create mode 100644 lib/i915/perf-configs/oa-cflgt3.xml create mode 100644 lib/i915/perf-configs/oa-chv.xml create mode 100644 lib/i915/perf-configs/oa-cnl.xml create mode 100644 lib/i915/perf-configs/oa-glk.xml create mode 100644 lib/i915/perf-configs/oa-hsw.xml create mode 100644 lib/i915/perf-configs/oa-icl.xml create mode 100644 lib/i915/perf-configs/oa-kblgt2.xml create mode 100644 lib/i915/perf-configs/oa-kblgt3.xml create mode 100644 lib/i915/perf-configs/oa-sklgt2.xml create mode 100644 lib/i915/perf-configs/oa-sklgt3.xml create mode 100644 lib/i915/perf-configs/oa-sklgt4.xml create mode 100755 lib/i915/perf-configs/perf-codegen.py create mode 100755 lib/i915/perf-configs/update-guids.py create mode 100644 lib/i915/perf.c create mode 100644 lib/i915/perf.h create mode 100644 lib/i915/perf_data.h create mode 100644 lib/i915/perf_data_reader.c create mode 100644 lib/i915/perf_data_reader.h create mode 100644 tools/i915-perf/README create mode 100644 tools/i915-perf/i915_perf_configs.c create mode 100644 tools/i915-perf/i915_perf_control.c create mode 100644 tools/i915-perf/i915_perf_recorder.c create mode 100644 tools/i915-perf/i915_perf_recorder_commands.h create mode 100644 tools/i915-perf/meson.build
Signature · 6 lines
2.20.1 _______________________________________________ igt-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/igt-dev
PATCH 2/4 lib/i915/perf: Add support for loading perf configurations
From: Lionel Landwerlin <[email protected]>
Add support for loading perf configurations used by gpuvis.
v2: rebase fixes for igt list (Umesh)
--- lib/i915/perf.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/i915/perf.h | 2 + 2 files changed, 140 insertions(+)
lib/i915/perf.c +138 -0
@@ -20,8 +20,18 @@* SOFTWARE. */ +#include <assert.h> +#include <errno.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> +#include <dirent.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <sys/stat.h> +#include <sys/sysmacros.h> +#include <sys/types.h> +#include <unistd.h> #include "intel_chipset.h" #include "perf.h"
@@ -192,3 +202,131 @@ intel_perf_add_metric_set(struct intel_perf *perf, {igt_list_add_tail (&metric_set->link, &perf->metric_sets); } + +static bool +read_file_uint64 (const char *file,uint64_t *value) +{ +char buf[32 ]; +int fd, n; + + fd =open (file,0 ); +if (fd <0 ) +return false; + n =read (fd, buf,sizeof (buf) -1 ); +close (fd); +if (n <0 ) +return false; + + buf[n] ='\0' ; + *value =strtoull (buf,0 ,0 ); + +return true; +} + +static int +get_card_for_fd (int fd) +{ +struct stat sb; +int mjr, mnr; +char buffer[128 ]; +DIR *drm_dir; +struct dirent *entry; +int retval =-1 ; + +if (fstat (fd, &sb)) +return -1 ; + + mjr =major (sb.st_rdev); + mnr =minor (sb.st_rdev); + +snprintf (buffer,sizeof (buffer),"/sys/dev/char/%d:%d/device/drm" , mjr, mnr); + + drm_dir =opendir (buffer); +assert (drm_dir !=NULL ); + +while ((entry =readdir (drm_dir))) { +if (entry->d_type ==DT_DIR &&strncmp (entry->d_name,"card" ,4 ) ==0 ) { + retval =strtoull (entry->d_name +4 ,NULL ,10 ); +break ; + } + } + +closedir (drm_dir); + +return retval; +} + +static void +load_metric_set_config (struct intel_perf_metric_set *metric_set,int drm_fd) +{ +struct drm_i915_perf_oa_config config; +uint64_t config_id =0 ; + +memset (&config,0 ,sizeof (config)); + +memcpy (config.uuid, metric_set->hw_config_guid,sizeof (config.uuid)); + + config.n_mux_regs = metric_set->n_mux_regs; + config.mux_regs_ptr = (uintptr_t ) metric_set->mux_regs; + + config.n_boolean_regs = metric_set->n_b_counter_regs; + config.boolean_regs_ptr = (uintptr_t ) metric_set->b_counter_regs; + + config.n_flex_regs = metric_set->n_flex_regs; + config.flex_regs_ptr = (uintptr_t ) metric_set->flex_regs; + +while (ioctl (drm_fd,DRM_IOCTL_I915_PERF_ADD_CONFIG , &config) <0 && + (errno ==EAGAIN || errno ==EINTR )); + + metric_set->perf_oa_metrics_set = config_id; +} + +void +intel_perf_load_perf_configs (struct intel_perf *perf,int drm_fd) +{ +int drm_card =get_card_for_fd (drm_fd); +struct dirent *entry; +char metrics_path[128 ]; +DIR *metrics_dir; +struct intel_perf_metric_set *metric_set; + +snprintf (metrics_path,sizeof (metrics_path), +"/sys/class/drm/card%d/metrics" , drm_card); + metrics_dir =opendir (metrics_path); +if (!metrics_dir) +return ; + +while ((entry =readdir (metrics_dir))) { +char *metric_id_path; +uint64_t metric_id; + +if (entry->d_type !=DT_DIR ) +continue ; + +asprintf (&metric_id_path,"%s/%s/id" , + metrics_path, entry->d_name); + +if (!read_file_uint64 (metric_id_path, &metric_id)) { +free (metric_id_path); +continue ; + } + +free (metric_id_path); + +igt_list_for_each_entry (metric_set, &perf->metric_sets, link) { +if (!strcmp (metric_set->hw_config_guid, entry->d_name)) { + metric_set->perf_oa_metrics_set = metric_id; +break ; + } + } + } + +closedir (metrics_dir); + +igt_list_for_each_entry (metric_set, &perf->metric_sets, link) { +if (metric_set->perf_oa_metrics_set) +continue ; + +load_metric_set_config (metric_set, drm_fd); + } +}
lib/i915/perf.h +2 -0
@@ -231,6 +231,8 @@ void intel_perf_add_logical_counter(struct intel_perf *perf,void intel_perf_add_metric_set (struct intel_perf *perf,struct intel_perf_metric_set *metric_set); +void intel_perf_load_perf_configs (struct intel_perf *perf,int drm_fd); + #ifdef __cplusplus };#endif
Signature · 6 lines
2.20.1 _______________________________________________ igt-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/igt-dev
PATCH 3/4 tools/i915/perf: Add i915 perf recorder tool
In reply to Umesh Nerlige RamappaFrom: Lionel Landwerlin <[email protected]>
i915 perf recorder tool captures OA perf data for a specific metric set in a circular buffer of specified size. The i915 perf control tool is used to dump the data captured in the circular buffer to a trace file. The data captured is used to view relevant events in gpuvis.
v2: (Umesh)
- rebase fixes for igt_list apis
- memset circular_buffer to 0 to initialize size, beginpos and enpos
- _FORTIFY_SOURCE=2 caused snprintf to go through __snprintf_chk that falsely flagged a buffer overflow and sent an abort signal to i915_perf_control when capturing traces. undef the _FORTIFY_SOURCE selectively for i915 control tool.
--- lib/i915/perf_data.h | 88 ++ lib/meson.build | 1 + tools/i915-perf/i915_perf_control.c | 133 +++ tools/i915-perf/i915_perf_recorder.c | 931 ++++++++++++++++++ tools/i915-perf/i915_perf_recorder_commands.h | 39 + tools/i915-perf/meson.build | 12 + 6 files changed, 1204 insertions(+) create mode 100644 lib/i915/perf_data.h create mode 100644 tools/i915-perf/i915_perf_control.c create mode 100644 tools/i915-perf/i915_perf_recorder.c create mode 100644 tools/i915-perf/i915_perf_recorder_commands.h
lib/i915/perf_data.h new file +88 -0
@@ -0,0 +1,88 @@ +/* +* Copyright (C) 2019 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#ifndef PERF_DATA_H +#define PERF_DATA_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* The structures below are embedded in the i915-perf stream so as to +* provide metadata. The types used in the +* drm_i915_perf_record_header.type are defined in +* intel_perf_record_type. +* +* Once defined, those structures cannot change. If you need to add +* new data, just define a new structure & record_type. +*/ + +#include <stdint.h> + +enum intel_perf_record_type { +/* Start at 65536, which is pretty safe since after 3years the +* kernel hasn't defined more than 3 entries. +*/ + +/* intel_perf_record_device_info */ +INTEL_PERF_RECORD_TYPE_DEVICE_INFO =1 <<16 , + +/* intel_perf_record_device_topology */ +INTEL_PERF_RECORD_TYPE_DEVICE_TOPOLOGY , + +/* intel_perf_record_timestamp_correlation */ +INTEL_PERF_RECORD_TYPE_TIMESTAMP_CORRELATION , +}; + +struct intel_perf_record_device_info { +/* Frequency of the timestamps in the records. */ +uint64_t timestamp_frequency; + +/* PCI ID */ +uint32_t device_id; + +/* enum drm_i915_oa_format */ +uint32_t oa_format; + +/* Configuration identifier */ +char uuid[40 ]; +}; + +/* Topology as reported by i915. */ +struct intel_perf_record_device_topology { +struct drm_i915_query_topology_info topology; +}; + +/* Timestamp correlation between CPU/GPU. */ +struct intel_perf_record_timestamp_correlation { +/* In CLOCK_MONOTONIC */ +uint64_t cpu_timestamp; + +/* Engine timestamp associated with the OA unit */ +uint64_t gpu_timestamp; +}; + +#ifdef __cplusplus +}; +#endif + +#endif /* PERF_DATA_H */
lib/meson.build +1 -0
@@ -217,6 +217,7 @@ install_headers( 'igt_list.h', 'intel_chipset.h', 'i915/perf.h', + 'i915/perf_data.h', subdir : 'i915-perf' )
tools/i915-perf/i915_perf_control.c new file +133 -0
133 lines not on this page · raw message
tools/i915-perf/i915_perf_recorder.c new file +931 -0
931 lines not on this page · raw message
tools/i915-perf/i915_perf_recorder_commands.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Copyright (C) 2019 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <stdint.h> + +#define I915_PERF_RECORD_FIFO_PATH "/tmp/.i915-perf-record" + +enum recorder_command { +RECORDER_COMMAND_DUMP =1 , +RECORDER_COMMAND_QUIT , +}; + +struct recorder_command_base { +uint32_t command; +uint32_t size; +}; + +struct recorder_command_dump { +uint8_t path[0 ]; +};
tools/i915-perf/meson.build +12 -0
@@ -3,3 +3,15 @@ executable('i915-perf-configs', include_directories: inc, dependencies: [lib_igt_chipset, lib_igt_i915_perf], install: true) + +executable('i915-perf-recorder', + [ 'i915_perf_recorder.c' ], + include_directories: inc, + dependencies: [lib_igt, lib_igt_i915_perf], + install: true) + +executable('i915-perf-control', + [ 'i915_perf_control.c' ], + c_args: '-U_FORTIFY_SOURCE', + include_directories: inc, + install: true)
Signature · 6 lines
2.20.1 _______________________________________________ igt-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/igt-dev
PATCH 4/4 lib/i915/perf: Add i915 perf data reader
In reply to Umesh Nerlige RamappaFrom: Lionel Landwerlin <[email protected]>
Read perf OA records and correlate timestamps between the GPU and CPU.
v2: (Umesh)
- Add README on usage
- rebase fixes for igt_list
--- lib/i915/perf_data_reader.c | 330 ++++++++++++++++++++++++++++++++++++ lib/i915/perf_data_reader.h | 103 +++++++++++ lib/meson.build | 2 + tools/i915-perf/README | 70 ++++++++ 4 files changed, 505 insertions(+) create mode 100644 lib/i915/perf_data_reader.c create mode 100644 lib/i915/perf_data_reader.h create mode 100644 tools/i915-perf/README
lib/i915/perf_data_reader.c new file +330 -0
@@ -0,0 +1,330 @@ +/* +* Copyright (C) 2019 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <assert.h> +#include <stdlib.h> +#include <string.h> +#include <sys/mman.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> + +#include "intel_chipset.h" +#include "perf.h" +#include "perf_data_reader.h" + +#define MAX (a,b) ((a) > (b) ? (a) : (b)) +#define ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0])) + +static inline bool +oa_report_ctx_is_valid (const struct intel_perf_devinfo *devinfo, +const uint8_t *_report) +{ +const uint32_t *report = (const uint32_t *) _report; + +if (devinfo->gen <8 ) { +return false;/* TODO */ + }else if (devinfo->gen ==8 ) { +return report[0 ] & (1ul <<25 ); + }else if (devinfo->gen >8 ) { +return report[0 ] & (1ul <<16 ); + } + +return false; +} + +static uint32_t +oa_report_ctx_id (const struct intel_perf_devinfo *devinfo,const uint8_t *report) +{ +if (!oa_report_ctx_is_valid (devinfo, report)) +return 0xffffffff ; +return ((const uint32_t *) report)[2 ]; +} + +static inline uint64_t +oa_report_timestamp (const uint8_t *report) +{ +return ((const uint32_t *)report)[1 ]; +} + +static void +append_record (struct intel_perf_data_reader *reader, +const struct drm_i915_perf_record_header *header) +{ +if (reader->n_records >= reader->n_allocated_records) { + reader->n_allocated_records =MAX (100 ,2 * reader->n_allocated_records); + reader->records = + (const struct drm_i915_perf_record_header **) +realloc ((void *) reader->records, + reader->n_allocated_records * +sizeof (*reader->records)); +assert (reader->records); + } + + reader->records[reader->n_records++] = header; +} + +static void +append_timestamp_correlation (struct intel_perf_data_reader *reader, +const struct intel_perf_record_timestamp_correlation *corr) +{ +if (reader->n_correlations >= reader->n_allocated_correlations) { + reader->n_allocated_correlations =MAX (100 ,2 * reader->n_allocated_correlations); + reader->correlations = + (const struct intel_perf_record_timestamp_correlation **) +realloc ((void *) reader->correlations, + reader->n_allocated_correlations * +sizeof (*reader->correlations)); +assert (reader->correlations); + } + + reader->correlations[reader->n_correlations++] = corr; +} + +static struct intel_perf_metric_set * +find_metric_set (struct intel_perf *perf,const char *uuid) +{ +struct intel_perf_metric_set *metric_set; + +igt_list_for_each_entry (metric_set, &perf->metric_sets, link) { +if (!strcmp (uuid, metric_set->hw_config_guid)) +return metric_set; + } + +return NULL ; +} + +static void +init_devinfo (struct intel_perf_devinfo *perf_devinfo, +const struct intel_device_info *devinfo, +uint32_t devid, +uint64_t timestamp_frequency) +{ + perf_devinfo->devid = devid; + perf_devinfo->gen = devinfo->gen; + perf_devinfo->timestamp_frequency = timestamp_frequency; +} + +static bool +parse_data (struct intel_perf_data_reader *reader) +{ +const uint8_t *end = reader->mmap_data + reader->mmap_size; +const uint8_t *iter = reader->mmap_data; +while (iter < end) { +const struct drm_i915_perf_record_header *header = + (const struct drm_i915_perf_record_header *) iter; + +switch (header->type) { +case DRM_I915_PERF_RECORD_SAMPLE : +append_record (reader, header); +break ; + +case DRM_I915_PERF_RECORD_OA_REPORT_LOST : +case DRM_I915_PERF_RECORD_OA_BUFFER_LOST : +assert (header->size ==sizeof (*header)); +break ; + +case INTEL_PERF_RECORD_TYPE_DEVICE_INFO : { +const struct intel_device_info *devinfo; + + reader->record_info = + (const struct intel_perf_record_device_info *) (header +1 ); +assert (header->size == (sizeof (*reader->record_info) +sizeof (*header))); + devinfo =intel_get_device_info (reader->record_info->device_id); +if (!devinfo) +return false; +init_devinfo (&reader->devinfo, devinfo, + reader->record_info->device_id, + reader->record_info->timestamp_frequency); + reader->perf =intel_perf_for_devinfo (devinfo); + reader->metric_set =find_metric_set (reader->perf, reader->record_info->uuid); +break ; + } + +case INTEL_PERF_RECORD_TYPE_TIMESTAMP_CORRELATION : { +append_timestamp_correlation (reader, + (const struct intel_perf_record_timestamp_correlation *) (header +1 )); +break ; + } + } + + iter += header->size; + } + +return true; +} + +static uint64_t +correlate_gpu_timestamp (struct intel_perf_data_reader *reader, +uint64_t gpu_ts) +{ +/* OA reports only have the lower 32bits of the timestamp +* register, while our correlation data has the whole 36bits. +* Try to figure what portion of the correlation data the +* 32bit timestamp belongs to. +*/ +uint64_t mask =0xffffffff ; +int corr_idx =-1 ; + +for (uint32_t i =0 ; i < reader->n_correlation_chunks; i++) { +if (gpu_ts >= (reader->correlation_chunks[i].gpu_ts_begin & mask) && + gpu_ts <= (reader->correlation_chunks[i].gpu_ts_end & mask)) { + corr_idx = reader->correlation_chunks[i].idx; +break ; + } + } + +/* Not found? Assume prior to the first timestamp correlation. +*/ +if (corr_idx <0 ) { +return reader->correlations[0 ]->cpu_timestamp - + ((reader->correlations[0 ]->gpu_timestamp & mask) - gpu_ts) * + (reader->correlations[1 ]->cpu_timestamp - reader->correlations[0 ]->cpu_timestamp) / + (reader->correlations[1 ]->gpu_timestamp - reader->correlations[0 ]->gpu_timestamp); + } + +for (uint32_t i = corr_idx; i < (reader->n_correlations -1 ); i++) { +if (gpu_ts >= (reader->correlations[i]->gpu_timestamp & mask) && + gpu_ts < (reader->correlations[i +1 ]->gpu_timestamp & mask)) { +return reader->correlations[i]->cpu_timestamp + + (gpu_ts - (reader->correlations[i]->gpu_timestamp & mask)) * + (reader->correlations[i +1 ]->cpu_timestamp - reader->correlations[i]->cpu_timestamp) / + (reader->correlations[i +1 ]->gpu_timestamp - reader->correlations[i]->gpu_timestamp); + } + } + +/* This is a bit harsh, but the recording tool should ensure we have +* sampling points on either side of the bag of OA reports. +*/ +assert (0 ); +} + +static void +append_timeline_event (struct intel_perf_data_reader *reader, +uint64_t ts_start,uint64_t ts_end, +uint32_t record_start,uint32_t record_end, +uint32_t hw_id) +{ +if (reader->n_timelines >= reader->n_allocated_timelines) { + reader->n_allocated_timelines =MAX (100 ,2 * reader->n_allocated_timelines); + reader->timelines = + (struct intel_perf_timeline_item *) +realloc ((void *) reader->timelines, + reader->n_allocated_timelines * +sizeof (*reader->timelines)); +assert (reader->timelines); + } + + reader->timelines[reader->n_timelines].ts_start = ts_start; + reader->timelines[reader->n_timelines].ts_end = ts_end; + reader->timelines[reader->n_timelines].cpu_ts_start = +correlate_gpu_timestamp (reader, ts_start); + reader->timelines[reader->n_timelines].cpu_ts_end = +correlate_gpu_timestamp (reader, ts_end); + reader->timelines[reader->n_timelines].record_start = record_start; + reader->timelines[reader->n_timelines].record_end = record_end; + reader->timelines[reader->n_timelines].hw_id = hw_id; + reader->n_timelines++; +} + +static void +generate_cpu_events (struct intel_perf_data_reader *reader) +{ +uint32_t last_header_idx =0 ; +const struct drm_i915_perf_record_header *last_header = reader->records[0 ]; + +for (uint32_t i =1 ; i < reader->n_records; i++) { +const struct drm_i915_perf_record_header *current_header = + reader->records[i]; +const uint8_t *start_report = (const uint8_t *) (last_header +1 ), + *end_report = (const uint8_t *) (current_header +1 ); +uint32_t last_ctx_id =oa_report_ctx_id (&reader->devinfo, start_report), + current_ctx_id =oa_report_ctx_id (&reader->devinfo, end_report); +uint64_t gpu_ts_start =oa_report_timestamp (start_report), + gpu_ts_end =oa_report_timestamp (end_report); + +if (last_ctx_id == current_ctx_id) +continue ; + +append_timeline_event (reader, gpu_ts_start, gpu_ts_end, last_header_idx, i, last_ctx_id); + + last_header = current_header; + last_header_idx = i; + } +} + +static void +compute_correlation_chunks (struct intel_perf_data_reader *reader) +{ +uint64_t mask = ~(0xffffffff ); +uint32_t last_idx =0 ; +uint64_t last_ts = reader->correlations[last_idx]->gpu_timestamp; + +for (uint32_t i =0 ; i < reader->n_correlations; i++) { +if (!reader->n_correlation_chunks || + (last_ts & mask) != (reader->correlations[i]->gpu_timestamp & mask)) { +assert (reader->n_correlation_chunks <ARRAY_SIZE (reader->correlation_chunks)); + reader->correlation_chunks[reader->n_correlation_chunks].gpu_ts_begin = last_ts; + reader->correlation_chunks[reader->n_correlation_chunks].gpu_ts_end = last_ts | ~mask; + reader->correlation_chunks[reader->n_correlation_chunks].idx = last_idx; + last_ts = reader->correlation_chunks[reader->n_correlation_chunks].gpu_ts_end +1 ; + last_idx = i; + reader->n_correlation_chunks++; + } + } +} + +bool +intel_perf_data_reader_init (struct intel_perf_data_reader *reader, +int perf_file_fd) +{ +struct stat st; +if (fstat (perf_file_fd, &st) !=0 ) +return false; + +memset (reader,0 ,sizeof (*reader)); + + reader->mmap_size = st.st_size; + reader->mmap_data = (const uint8_t *)mmap (NULL , st.st_size, +PROT_READ ,MAP_PRIVATE , + perf_file_fd,0 ); +if (reader->mmap_data ==MAP_FAILED ) +return false; + +if (!parse_data (reader)) +return false; + +compute_correlation_chunks (reader); +generate_cpu_events (reader); + +return true; +} + +void +intel_perf_data_reader_fini (struct intel_perf_data_reader *reader) +{ +intel_perf_free (reader->perf); +free (reader->records); +free (reader->timelines); +free (reader->correlations); +munmap ((void *)reader->mmap_data, reader->mmap_size); +}
lib/i915/perf_data_reader.h new file +103 -0
103 lines not on this page · raw message
lib/meson.build +2 -0
@@ -173,6 +173,7 @@ lib_igt_perf = declare_dependency(link_with : lib_igt_perf_build, i915_perf_files = [ 'i915/perf.c', + 'i915/perf_data_reader.c', ] i915_perf_hardware = [
@@ -218,6 +219,7 @@ install_headers( 'intel_chipset.h', 'i915/perf.h', 'i915/perf_data.h', + 'i915/perf_data_reader.h', subdir : 'i915-perf' )
tools/i915-perf/README new file +70 -0
70 lines not on this page · raw message
Signature · 6 lines
2.20.1 _______________________________________________ igt-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/igt-dev
There was a small communication hiccup. Umesh thought I did not work on this stuff anymore, but I actually just picked up the stuff again last week.
Sending an update with more changes/updates.
Sorry for the confusion.
-Lionel
Quoted 75 lines · Umesh Nerlige Ramappa
The tools provided here enable capturing performance metrics from the i915 driver and are used in conjunction with the GPUvis software here -
https://github.com/mikesart/gpuvis
The changes required in GPUvis are wip and will be posted following the merge of these tools.
For more information, view
tools/i915-perf/READMEin this patch seriesLionel Landwerlin (4):
lib/i915/perf: Addi915_perflibrarylib/i915/perf: Add support for loading perf configurationstools/i915/perf: Add i915 perf recorder toollib/i915/perf: Add i915 perf data readerlib/i915-perf.pc.in | 10 + lib/i915/perf-configs/README.md | 115 + lib/i915/perf-configs/codegen.py | 33 + lib/i915/perf-configs/guids.xml | 282 + lib/i915/perf-configs/mdapi-xml-convert.py | 1000 + lib/i915/perf-configs/oa-bdw.xml | 15653 ++++++++++++++++ lib/i915/perf-configs/oa-bxt.xml | 9595 ++++++++++ lib/i915/perf-configs/oa-cflgt2.xml | 10866 +++++++++++ lib/i915/perf-configs/oa-cflgt3.xml | 10933 +++++++++++ lib/i915/perf-configs/oa-chv.xml | 9757 ++++++++++ lib/i915/perf-configs/oa-cnl.xml | 10411 ++++++++++ lib/i915/perf-configs/oa-glk.xml | 9346 +++++++++ lib/i915/perf-configs/oa-hsw.xml | 4615 +++++ lib/i915/perf-configs/oa-icl.xml | 11899 ++++++++++++ lib/i915/perf-configs/oa-kblgt2.xml | 10866 +++++++++++ lib/i915/perf-configs/oa-kblgt3.xml | 10933 +++++++++++ lib/i915/perf-configs/oa-sklgt2.xml | 11895 ++++++++++++ lib/i915/perf-configs/oa-sklgt3.xml | 10933 +++++++++++ lib/i915/perf-configs/oa-sklgt4.xml | 10956 +++++++++++ lib/i915/perf-configs/perf-codegen.py | 854 + lib/i915/perf-configs/update-guids.py | 230 + lib/i915/perf.c | 332 + lib/i915/perf.h | 240 + lib/i915/perf_data.h | 88 + lib/i915/perf_data_reader.c | 330 + lib/i915/perf_data_reader.h | 103 + lib/meson.build | 67 + tools/i915-perf/README | 70 + tools/i915-perf/i915_perf_configs.c | 277 + tools/i915-perf/i915_perf_control.c | 133 + tools/i915-perf/i915_perf_recorder.c | 931 + tools/i915-perf/i915_perf_recorder_commands.h | 39 + tools/i915-perf/meson.build | 17 + tools/meson.build | 1 + 34 files changed, 153810 insertions(+)create mode 100644
lib/i915-perf.pc.in
create mode 100644lib/i915/perf-configs/README.mdcreate mode 100644lib/i915/perf-configs/codegen.pycreate mode 100644lib/i915/perf-configs/guids.xmlcreate mode 100755lib/i915/perf-configs/mdapi-xml-convert.pycreate mode 100644lib/i915/perf-configs/oa-bdw.xmlcreate mode 100644lib/i915/perf-configs/oa-bxt.xmlcreate mode 100644lib/i915/perf-configs/oa-cflgt2.xmlcreate mode 100644lib/i915/perf-configs/oa-cflgt3.xmlcreate mode 100644lib/i915/perf-configs/oa-chv.xmlcreate mode 100644lib/i915/perf-configs/oa-cnl.xmlcreate mode 100644lib/i915/perf-configs/oa-glk.xmlcreate mode 100644lib/i915/perf-configs/oa-hsw.xmlcreate mode 100644lib/i915/perf-configs/oa-icl.xmlcreate mode 100644lib/i915/perf-configs/oa-kblgt2.xmlcreate mode 100644lib/i915/perf-configs/oa-kblgt3.xmlcreate mode 100644lib/i915/perf-configs/oa-sklgt2.xmlcreate mode 100644lib/i915/perf-configs/oa-sklgt3.xmlcreate mode 100644lib/i915/perf-configs/oa-sklgt4.xmlcreate mode 100755lib/i915/perf-configs/perf-codegen.pycreate mode 100755lib/i915/perf-configs/update-guids.pycreate mode 100644lib/i915/perf.c
create mode 100644lib/i915/perf.h
create mode 100644lib/i915/perf_data.h
Quoted 9 lines
create mode 100644
lib/i915/perf_data_reader.c
create mode 100644lib/i915/perf_data_reader.h
create mode 100644tools/i915-perf/README
create mode 100644tools/i915-perf/i915_perf_configs.ccreate mode 100644tools/i915-perf/i915_perf_control.ccreate mode 100644tools/i915-perf/i915_perf_recorder.ccreate mode 100644tools/i915-perf/i915_perf_recorder_commands.hcreate mode 100644tools/i915-perf/meson.build
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev