Path: blob/21.2-virgl/src/intel/perf/intel_perf.c
4547 views
/*1* Copyright © 2018 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include <dirent.h>2425#include <sys/types.h>26#include <sys/stat.h>27#include <fcntl.h>28#include <unistd.h>29#include <errno.h>3031#ifndef HAVE_DIRENT_D_TYPE32#include <limits.h> // PATH_MAX33#endif3435#include <drm-uapi/i915_drm.h>3637#include "common/intel_gem.h"3839#include "dev/intel_debug.h"40#include "dev/intel_device_info.h"4142#include "perf/intel_perf.h"43#include "perf/intel_perf_regs.h"44#include "perf/intel_perf_mdapi.h"45#include "perf/intel_perf_metrics.h"46#include "perf/intel_perf_private.h"4748#include "util/bitscan.h"49#include "util/macros.h"50#include "util/mesa-sha1.h"51#include "util/u_math.h"5253#define FILE_DEBUG_FLAG DEBUG_PERFMON5455static bool56is_dir_or_link(const struct dirent *entry, const char *parent_dir)57{58#ifdef HAVE_DIRENT_D_TYPE59return entry->d_type == DT_DIR || entry->d_type == DT_LNK;60#else61struct stat st;62char path[PATH_MAX + 1];63snprintf(path, sizeof(path), "%s/%s", parent_dir, entry->d_name);64lstat(path, &st);65return S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode);66#endif67}6869static bool70get_sysfs_dev_dir(struct intel_perf_config *perf, int fd)71{72struct stat sb;73int min, maj;74DIR *drmdir;75struct dirent *drm_entry;76int len;7778perf->sysfs_dev_dir[0] = '\0';7980if (INTEL_DEBUG & DEBUG_NO_OACONFIG)81return true;8283if (fstat(fd, &sb)) {84DBG("Failed to stat DRM fd\n");85return false;86}8788maj = major(sb.st_rdev);89min = minor(sb.st_rdev);9091if (!S_ISCHR(sb.st_mode)) {92DBG("DRM fd is not a character device as expected\n");93return false;94}9596len = snprintf(perf->sysfs_dev_dir,97sizeof(perf->sysfs_dev_dir),98"/sys/dev/char/%d:%d/device/drm", maj, min);99if (len < 0 || len >= sizeof(perf->sysfs_dev_dir)) {100DBG("Failed to concatenate sysfs path to drm device\n");101return false;102}103104drmdir = opendir(perf->sysfs_dev_dir);105if (!drmdir) {106DBG("Failed to open %s: %m\n", perf->sysfs_dev_dir);107return false;108}109110while ((drm_entry = readdir(drmdir))) {111if (is_dir_or_link(drm_entry, perf->sysfs_dev_dir) &&112strncmp(drm_entry->d_name, "card", 4) == 0)113{114len = snprintf(perf->sysfs_dev_dir,115sizeof(perf->sysfs_dev_dir),116"/sys/dev/char/%d:%d/device/drm/%s",117maj, min, drm_entry->d_name);118closedir(drmdir);119if (len < 0 || len >= sizeof(perf->sysfs_dev_dir))120return false;121else122return true;123}124}125126closedir(drmdir);127128DBG("Failed to find cardX directory under /sys/dev/char/%d:%d/device/drm\n",129maj, min);130131return false;132}133134static bool135read_file_uint64(const char *file, uint64_t *val)136{137char buf[32];138int fd, n;139140fd = open(file, 0);141if (fd < 0)142return false;143while ((n = read(fd, buf, sizeof (buf) - 1)) < 0 &&144errno == EINTR);145close(fd);146if (n < 0)147return false;148149buf[n] = '\0';150*val = strtoull(buf, NULL, 0);151152return true;153}154155static bool156read_sysfs_drm_device_file_uint64(struct intel_perf_config *perf,157const char *file,158uint64_t *value)159{160char buf[512];161int len;162163len = snprintf(buf, sizeof(buf), "%s/%s", perf->sysfs_dev_dir, file);164if (len < 0 || len >= sizeof(buf)) {165DBG("Failed to concatenate sys filename to read u64 from\n");166return false;167}168169return read_file_uint64(buf, value);170}171172static void173register_oa_config(struct intel_perf_config *perf,174const struct intel_device_info *devinfo,175const struct intel_perf_query_info *query,176uint64_t config_id)177{178struct intel_perf_query_info *registered_query =179intel_perf_append_query_info(perf, 0);180181*registered_query = *query;182registered_query->oa_format = devinfo->ver >= 8 ?183I915_OA_FORMAT_A32u40_A4u32_B8_C8 : I915_OA_FORMAT_A45_B8_C8;184registered_query->oa_metrics_set_id = config_id;185DBG("metric set registered: id = %" PRIu64", guid = %s\n",186registered_query->oa_metrics_set_id, query->guid);187}188189static void190enumerate_sysfs_metrics(struct intel_perf_config *perf,191const struct intel_device_info *devinfo)192{193DIR *metricsdir = NULL;194struct dirent *metric_entry;195char buf[256];196int len;197198len = snprintf(buf, sizeof(buf), "%s/metrics", perf->sysfs_dev_dir);199if (len < 0 || len >= sizeof(buf)) {200DBG("Failed to concatenate path to sysfs metrics/ directory\n");201return;202}203204metricsdir = opendir(buf);205if (!metricsdir) {206DBG("Failed to open %s: %m\n", buf);207return;208}209210while ((metric_entry = readdir(metricsdir))) {211struct hash_entry *entry;212if (!is_dir_or_link(metric_entry, buf) ||213metric_entry->d_name[0] == '.')214continue;215216DBG("metric set: %s\n", metric_entry->d_name);217entry = _mesa_hash_table_search(perf->oa_metrics_table,218metric_entry->d_name);219if (entry) {220uint64_t id;221if (!intel_perf_load_metric_id(perf, metric_entry->d_name, &id)) {222DBG("Failed to read metric set id from %s: %m", buf);223continue;224}225226register_oa_config(perf, devinfo,227(const struct intel_perf_query_info *)entry->data, id);228} else229DBG("metric set not known by mesa (skipping)\n");230}231232closedir(metricsdir);233}234235static void236add_all_metrics(struct intel_perf_config *perf,237const struct intel_device_info *devinfo)238{239hash_table_foreach(perf->oa_metrics_table, entry) {240const struct intel_perf_query_info *query = entry->data;241register_oa_config(perf, devinfo, query, 0);242}243}244245static bool246kernel_has_dynamic_config_support(struct intel_perf_config *perf, int fd)247{248uint64_t invalid_config_id = UINT64_MAX;249250return intel_ioctl(fd, DRM_IOCTL_I915_PERF_REMOVE_CONFIG,251&invalid_config_id) < 0 && errno == ENOENT;252}253254static int255i915_query_items(struct intel_perf_config *perf, int fd,256struct drm_i915_query_item *items, uint32_t n_items)257{258struct drm_i915_query q = {259.num_items = n_items,260.items_ptr = to_user_pointer(items),261};262return intel_ioctl(fd, DRM_IOCTL_I915_QUERY, &q);263}264265static bool266i915_query_perf_config_supported(struct intel_perf_config *perf, int fd)267{268struct drm_i915_query_item item = {269.query_id = DRM_I915_QUERY_PERF_CONFIG,270.flags = DRM_I915_QUERY_PERF_CONFIG_LIST,271};272273return i915_query_items(perf, fd, &item, 1) == 0 && item.length > 0;274}275276static bool277i915_query_perf_config_data(struct intel_perf_config *perf,278int fd, const char *guid,279struct drm_i915_perf_oa_config *config)280{281struct {282struct drm_i915_query_perf_config query;283struct drm_i915_perf_oa_config config;284} item_data;285struct drm_i915_query_item item = {286.query_id = DRM_I915_QUERY_PERF_CONFIG,287.flags = DRM_I915_QUERY_PERF_CONFIG_DATA_FOR_UUID,288.data_ptr = to_user_pointer(&item_data),289.length = sizeof(item_data),290};291292memset(&item_data, 0, sizeof(item_data));293memcpy(item_data.query.uuid, guid, sizeof(item_data.query.uuid));294memcpy(&item_data.config, config, sizeof(item_data.config));295296if (!(i915_query_items(perf, fd, &item, 1) == 0 && item.length > 0))297return false;298299memcpy(config, &item_data.config, sizeof(item_data.config));300301return true;302}303304bool305intel_perf_load_metric_id(struct intel_perf_config *perf_cfg,306const char *guid,307uint64_t *metric_id)308{309char config_path[280];310311snprintf(config_path, sizeof(config_path), "%s/metrics/%s/id",312perf_cfg->sysfs_dev_dir, guid);313314/* Don't recreate already loaded configs. */315return read_file_uint64(config_path, metric_id);316}317318static uint64_t319i915_add_config(struct intel_perf_config *perf, int fd,320const struct intel_perf_registers *config,321const char *guid)322{323struct drm_i915_perf_oa_config i915_config = { 0, };324325memcpy(i915_config.uuid, guid, sizeof(i915_config.uuid));326327i915_config.n_mux_regs = config->n_mux_regs;328i915_config.mux_regs_ptr = to_const_user_pointer(config->mux_regs);329330i915_config.n_boolean_regs = config->n_b_counter_regs;331i915_config.boolean_regs_ptr = to_const_user_pointer(config->b_counter_regs);332333i915_config.n_flex_regs = config->n_flex_regs;334i915_config.flex_regs_ptr = to_const_user_pointer(config->flex_regs);335336int ret = intel_ioctl(fd, DRM_IOCTL_I915_PERF_ADD_CONFIG, &i915_config);337return ret > 0 ? ret : 0;338}339340static void341init_oa_configs(struct intel_perf_config *perf, int fd,342const struct intel_device_info *devinfo)343{344hash_table_foreach(perf->oa_metrics_table, entry) {345const struct intel_perf_query_info *query = entry->data;346uint64_t config_id;347348if (intel_perf_load_metric_id(perf, query->guid, &config_id)) {349DBG("metric set: %s (already loaded)\n", query->guid);350register_oa_config(perf, devinfo, query, config_id);351continue;352}353354int ret = i915_add_config(perf, fd, &query->config, query->guid);355if (ret < 0) {356DBG("Failed to load \"%s\" (%s) metrics set in kernel: %s\n",357query->name, query->guid, strerror(errno));358continue;359}360361register_oa_config(perf, devinfo, query, ret);362DBG("metric set: %s (added)\n", query->guid);363}364}365366static void367compute_topology_builtins(struct intel_perf_config *perf,368const struct intel_device_info *devinfo)369{370perf->sys_vars.slice_mask = devinfo->slice_masks;371perf->sys_vars.n_eu_slices = devinfo->num_slices;372373for (int i = 0; i < sizeof(devinfo->subslice_masks[i]); i++) {374perf->sys_vars.n_eu_sub_slices +=375util_bitcount(devinfo->subslice_masks[i]);376}377378for (int i = 0; i < sizeof(devinfo->eu_masks); i++)379perf->sys_vars.n_eus += util_bitcount(devinfo->eu_masks[i]);380381perf->sys_vars.eu_threads_count = devinfo->num_thread_per_eu;382383/* The subslice mask builtin contains bits for all slices. Prior to Gfx11384* it had groups of 3bits for each slice, on Gfx11 it's 8bits for each385* slice.386*387* Ideally equations would be updated to have a slice/subslice query388* function/operator.389*/390perf->sys_vars.subslice_mask = 0;391392int bits_per_subslice = devinfo->ver == 11 ? 8 : 3;393394for (int s = 0; s < util_last_bit(devinfo->slice_masks); s++) {395for (int ss = 0; ss < (devinfo->subslice_slice_stride * 8); ss++) {396if (intel_device_info_subslice_available(devinfo, s, ss))397perf->sys_vars.subslice_mask |= 1ULL << (s * bits_per_subslice + ss);398}399}400}401402static bool403init_oa_sys_vars(struct intel_perf_config *perf,404const struct intel_device_info *devinfo,405bool use_register_snapshots)406{407uint64_t min_freq_mhz = 0, max_freq_mhz = 0;408409if (!(INTEL_DEBUG & DEBUG_NO_OACONFIG)) {410if (!read_sysfs_drm_device_file_uint64(perf, "gt_min_freq_mhz", &min_freq_mhz))411return false;412413if (!read_sysfs_drm_device_file_uint64(perf, "gt_max_freq_mhz", &max_freq_mhz))414return false;415} else {416min_freq_mhz = 300;417max_freq_mhz = 1000;418}419420memset(&perf->sys_vars, 0, sizeof(perf->sys_vars));421perf->sys_vars.gt_min_freq = min_freq_mhz * 1000000;422perf->sys_vars.gt_max_freq = max_freq_mhz * 1000000;423perf->sys_vars.timestamp_frequency = devinfo->timestamp_frequency;424perf->sys_vars.revision = devinfo->revision;425perf->sys_vars.query_mode = use_register_snapshots;426compute_topology_builtins(perf, devinfo);427428return true;429}430431typedef void (*perf_register_oa_queries_t)(struct intel_perf_config *);432433static perf_register_oa_queries_t434get_register_queries_function(const struct intel_device_info *devinfo)435{436if (devinfo->is_haswell)437return intel_oa_register_queries_hsw;438if (devinfo->is_cherryview)439return intel_oa_register_queries_chv;440if (devinfo->is_broadwell)441return intel_oa_register_queries_bdw;442if (devinfo->is_broxton)443return intel_oa_register_queries_bxt;444if (devinfo->is_skylake) {445if (devinfo->gt == 2)446return intel_oa_register_queries_sklgt2;447if (devinfo->gt == 3)448return intel_oa_register_queries_sklgt3;449if (devinfo->gt == 4)450return intel_oa_register_queries_sklgt4;451}452if (devinfo->is_kabylake) {453if (devinfo->gt == 2)454return intel_oa_register_queries_kblgt2;455if (devinfo->gt == 3)456return intel_oa_register_queries_kblgt3;457}458if (devinfo->is_geminilake)459return intel_oa_register_queries_glk;460if (devinfo->is_coffeelake) {461if (devinfo->gt == 2)462return intel_oa_register_queries_cflgt2;463if (devinfo->gt == 3)464return intel_oa_register_queries_cflgt3;465}466if (devinfo->ver == 11) {467if (devinfo->is_elkhartlake)468return intel_oa_register_queries_ehl;469return intel_oa_register_queries_icl;470}471if (devinfo->is_tigerlake) {472if (devinfo->gt == 1)473return intel_oa_register_queries_tglgt1;474if (devinfo->gt == 2)475return intel_oa_register_queries_tglgt2;476}477if (devinfo->is_rocketlake)478return intel_oa_register_queries_rkl;479if (devinfo->is_dg1)480return intel_oa_register_queries_dg1;481if (devinfo->is_alderlake)482return intel_oa_register_queries_adl;483484return NULL;485}486487static int488intel_perf_compare_counter_names(const void *v1, const void *v2)489{490const struct intel_perf_query_counter *c1 = v1;491const struct intel_perf_query_counter *c2 = v2;492493return strcmp(c1->name, c2->name);494}495496static void497sort_query(struct intel_perf_query_info *q)498{499qsort(q->counters, q->n_counters, sizeof(q->counters[0]),500intel_perf_compare_counter_names);501}502503static void504load_pipeline_statistic_metrics(struct intel_perf_config *perf_cfg,505const struct intel_device_info *devinfo)506{507struct intel_perf_query_info *query =508intel_perf_append_query_info(perf_cfg, MAX_STAT_COUNTERS);509510query->kind = INTEL_PERF_QUERY_TYPE_PIPELINE;511query->name = "Pipeline Statistics Registers";512513intel_perf_query_add_basic_stat_reg(query, IA_VERTICES_COUNT,514"N vertices submitted");515intel_perf_query_add_basic_stat_reg(query, IA_PRIMITIVES_COUNT,516"N primitives submitted");517intel_perf_query_add_basic_stat_reg(query, VS_INVOCATION_COUNT,518"N vertex shader invocations");519520if (devinfo->ver == 6) {521intel_perf_query_add_stat_reg(query, GFX6_SO_PRIM_STORAGE_NEEDED, 1, 1,522"SO_PRIM_STORAGE_NEEDED",523"N geometry shader stream-out primitives (total)");524intel_perf_query_add_stat_reg(query, GFX6_SO_NUM_PRIMS_WRITTEN, 1, 1,525"SO_NUM_PRIMS_WRITTEN",526"N geometry shader stream-out primitives (written)");527} else {528intel_perf_query_add_stat_reg(query, GFX7_SO_PRIM_STORAGE_NEEDED(0), 1, 1,529"SO_PRIM_STORAGE_NEEDED (Stream 0)",530"N stream-out (stream 0) primitives (total)");531intel_perf_query_add_stat_reg(query, GFX7_SO_PRIM_STORAGE_NEEDED(1), 1, 1,532"SO_PRIM_STORAGE_NEEDED (Stream 1)",533"N stream-out (stream 1) primitives (total)");534intel_perf_query_add_stat_reg(query, GFX7_SO_PRIM_STORAGE_NEEDED(2), 1, 1,535"SO_PRIM_STORAGE_NEEDED (Stream 2)",536"N stream-out (stream 2) primitives (total)");537intel_perf_query_add_stat_reg(query, GFX7_SO_PRIM_STORAGE_NEEDED(3), 1, 1,538"SO_PRIM_STORAGE_NEEDED (Stream 3)",539"N stream-out (stream 3) primitives (total)");540intel_perf_query_add_stat_reg(query, GFX7_SO_NUM_PRIMS_WRITTEN(0), 1, 1,541"SO_NUM_PRIMS_WRITTEN (Stream 0)",542"N stream-out (stream 0) primitives (written)");543intel_perf_query_add_stat_reg(query, GFX7_SO_NUM_PRIMS_WRITTEN(1), 1, 1,544"SO_NUM_PRIMS_WRITTEN (Stream 1)",545"N stream-out (stream 1) primitives (written)");546intel_perf_query_add_stat_reg(query, GFX7_SO_NUM_PRIMS_WRITTEN(2), 1, 1,547"SO_NUM_PRIMS_WRITTEN (Stream 2)",548"N stream-out (stream 2) primitives (written)");549intel_perf_query_add_stat_reg(query, GFX7_SO_NUM_PRIMS_WRITTEN(3), 1, 1,550"SO_NUM_PRIMS_WRITTEN (Stream 3)",551"N stream-out (stream 3) primitives (written)");552}553554intel_perf_query_add_basic_stat_reg(query, HS_INVOCATION_COUNT,555"N TCS shader invocations");556intel_perf_query_add_basic_stat_reg(query, DS_INVOCATION_COUNT,557"N TES shader invocations");558559intel_perf_query_add_basic_stat_reg(query, GS_INVOCATION_COUNT,560"N geometry shader invocations");561intel_perf_query_add_basic_stat_reg(query, GS_PRIMITIVES_COUNT,562"N geometry shader primitives emitted");563564intel_perf_query_add_basic_stat_reg(query, CL_INVOCATION_COUNT,565"N primitives entering clipping");566intel_perf_query_add_basic_stat_reg(query, CL_PRIMITIVES_COUNT,567"N primitives leaving clipping");568569if (devinfo->is_haswell || devinfo->ver == 8) {570intel_perf_query_add_stat_reg(query, PS_INVOCATION_COUNT, 1, 4,571"N fragment shader invocations",572"N fragment shader invocations");573} else {574intel_perf_query_add_basic_stat_reg(query, PS_INVOCATION_COUNT,575"N fragment shader invocations");576}577578intel_perf_query_add_basic_stat_reg(query, PS_DEPTH_COUNT,579"N z-pass fragments");580581if (devinfo->ver >= 7) {582intel_perf_query_add_basic_stat_reg(query, CS_INVOCATION_COUNT,583"N compute shader invocations");584}585586query->data_size = sizeof(uint64_t) * query->n_counters;587588sort_query(query);589}590591static int592i915_perf_version(int drm_fd)593{594int tmp;595drm_i915_getparam_t gp = {596.param = I915_PARAM_PERF_REVISION,597.value = &tmp,598};599600int ret = intel_ioctl(drm_fd, DRM_IOCTL_I915_GETPARAM, &gp);601602/* Return 0 if this getparam is not supported, the first version supported603* is 1.604*/605return ret < 0 ? 0 : tmp;606}607608static void609i915_get_sseu(int drm_fd, struct drm_i915_gem_context_param_sseu *sseu)610{611struct drm_i915_gem_context_param arg = {612.param = I915_CONTEXT_PARAM_SSEU,613.size = sizeof(*sseu),614.value = to_user_pointer(sseu)615};616617intel_ioctl(drm_fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &arg);618}619620static inline int621compare_str_or_null(const char *s1, const char *s2)622{623if (s1 == NULL && s2 == NULL)624return 0;625if (s1 == NULL)626return -1;627if (s2 == NULL)628return 1;629630return strcmp(s1, s2);631}632633static int634compare_counter_categories_and_names(const void *_c1, const void *_c2)635{636const struct intel_perf_query_counter_info *c1 = (const struct intel_perf_query_counter_info *)_c1;637const struct intel_perf_query_counter_info *c2 = (const struct intel_perf_query_counter_info *)_c2;638639/* pipeline counters don't have an assigned category */640int r = compare_str_or_null(c1->counter->category, c2->counter->category);641if (r)642return r;643644return strcmp(c1->counter->name, c2->counter->name);645}646647static void648build_unique_counter_list(struct intel_perf_config *perf)649{650assert(perf->n_queries < 64);651652size_t max_counters = 0;653654for (int q = 0; q < perf->n_queries; q++)655max_counters += perf->queries[q].n_counters;656657/*658* Allocate big enough array to hold maximum possible number of counters.659* We can't alloc it small and realloc when needed because the hash table660* below contains pointers to this array.661*/662struct intel_perf_query_counter_info *counter_infos =663ralloc_array_size(perf, sizeof(counter_infos[0]), max_counters);664665perf->n_counters = 0;666667struct hash_table *counters_table =668_mesa_hash_table_create(perf,669_mesa_hash_string,670_mesa_key_string_equal);671struct hash_entry *entry;672for (int q = 0; q < perf->n_queries ; q++) {673struct intel_perf_query_info *query = &perf->queries[q];674675for (int c = 0; c < query->n_counters; c++) {676struct intel_perf_query_counter *counter;677struct intel_perf_query_counter_info *counter_info;678679counter = &query->counters[c];680entry = _mesa_hash_table_search(counters_table, counter->symbol_name);681682if (entry) {683counter_info = entry->data;684counter_info->query_mask |= BITFIELD64_BIT(q);685continue;686}687assert(perf->n_counters < max_counters);688689counter_info = &counter_infos[perf->n_counters++];690counter_info->counter = counter;691counter_info->query_mask = BITFIELD64_BIT(q);692693counter_info->location.group_idx = q;694counter_info->location.counter_idx = c;695696_mesa_hash_table_insert(counters_table, counter->symbol_name, counter_info);697}698}699700_mesa_hash_table_destroy(counters_table, NULL);701702/* Now we can realloc counter_infos array because hash table doesn't exist. */703perf->counter_infos = reralloc_array_size(perf, counter_infos,704sizeof(counter_infos[0]), perf->n_counters);705706qsort(perf->counter_infos, perf->n_counters, sizeof(perf->counter_infos[0]),707compare_counter_categories_and_names);708}709710static bool711oa_metrics_available(struct intel_perf_config *perf, int fd,712const struct intel_device_info *devinfo,713bool use_register_snapshots)714{715perf_register_oa_queries_t oa_register = get_register_queries_function(devinfo);716bool i915_perf_oa_available = false;717struct stat sb;718719perf->i915_query_supported = i915_query_perf_config_supported(perf, fd);720perf->i915_perf_version = i915_perf_version(fd);721722/* Record the default SSEU configuration. */723i915_get_sseu(fd, &perf->sseu);724725/* The existence of this sysctl parameter implies the kernel supports726* the i915 perf interface.727*/728if (stat("/proc/sys/dev/i915/perf_stream_paranoid", &sb) == 0) {729730/* If _paranoid == 1 then on Gfx8+ we won't be able to access OA731* metrics unless running as root.732*/733if (devinfo->is_haswell)734i915_perf_oa_available = true;735else {736uint64_t paranoid = 1;737738read_file_uint64("/proc/sys/dev/i915/perf_stream_paranoid", ¶noid);739740if (paranoid == 0 || geteuid() == 0)741i915_perf_oa_available = true;742}743744perf->platform_supported = oa_register != NULL;745}746747return i915_perf_oa_available &&748oa_register &&749get_sysfs_dev_dir(perf, fd) &&750init_oa_sys_vars(perf, devinfo, use_register_snapshots);751}752753static void754load_oa_metrics(struct intel_perf_config *perf, int fd,755const struct intel_device_info *devinfo)756{757int existing_queries = perf->n_queries;758759perf_register_oa_queries_t oa_register = get_register_queries_function(devinfo);760761perf->oa_metrics_table =762_mesa_hash_table_create(perf, _mesa_hash_string,763_mesa_key_string_equal);764765/* Index all the metric sets mesa knows about before looking to see what766* the kernel is advertising.767*/768oa_register(perf);769770if (!(INTEL_DEBUG & DEBUG_NO_OACONFIG)) {771if (kernel_has_dynamic_config_support(perf, fd))772init_oa_configs(perf, fd, devinfo);773else774enumerate_sysfs_metrics(perf, devinfo);775} else {776add_all_metrics(perf, devinfo);777}778779/* sort counters in each individual group created by this function by name */780for (int i = existing_queries; i < perf->n_queries; ++i)781sort_query(&perf->queries[i]);782783/* Select a fallback OA metric. Look for the TestOa metric or use the last784* one if no present (on HSW).785*/786for (int i = existing_queries; i < perf->n_queries; i++) {787if (perf->queries[i].symbol_name &&788strcmp(perf->queries[i].symbol_name, "TestOa") == 0) {789perf->fallback_raw_oa_metric = perf->queries[i].oa_metrics_set_id;790break;791}792}793if (perf->fallback_raw_oa_metric == 0 && perf->n_queries > 0)794perf->fallback_raw_oa_metric = perf->queries[perf->n_queries - 1].oa_metrics_set_id;795}796797struct intel_perf_registers *798intel_perf_load_configuration(struct intel_perf_config *perf_cfg, int fd, const char *guid)799{800if (!perf_cfg->i915_query_supported)801return NULL;802803struct drm_i915_perf_oa_config i915_config = { 0, };804if (!i915_query_perf_config_data(perf_cfg, fd, guid, &i915_config))805return NULL;806807struct intel_perf_registers *config = rzalloc(NULL, struct intel_perf_registers);808config->n_flex_regs = i915_config.n_flex_regs;809config->flex_regs = rzalloc_array(config, struct intel_perf_query_register_prog, config->n_flex_regs);810config->n_mux_regs = i915_config.n_mux_regs;811config->mux_regs = rzalloc_array(config, struct intel_perf_query_register_prog, config->n_mux_regs);812config->n_b_counter_regs = i915_config.n_boolean_regs;813config->b_counter_regs = rzalloc_array(config, struct intel_perf_query_register_prog, config->n_b_counter_regs);814815/*816* struct intel_perf_query_register_prog maps exactly to the tuple of817* (register offset, register value) returned by the i915.818*/819i915_config.flex_regs_ptr = to_const_user_pointer(config->flex_regs);820i915_config.mux_regs_ptr = to_const_user_pointer(config->mux_regs);821i915_config.boolean_regs_ptr = to_const_user_pointer(config->b_counter_regs);822if (!i915_query_perf_config_data(perf_cfg, fd, guid, &i915_config)) {823ralloc_free(config);824return NULL;825}826827return config;828}829830uint64_t831intel_perf_store_configuration(struct intel_perf_config *perf_cfg, int fd,832const struct intel_perf_registers *config,833const char *guid)834{835if (guid)836return i915_add_config(perf_cfg, fd, config, guid);837838struct mesa_sha1 sha1_ctx;839_mesa_sha1_init(&sha1_ctx);840841if (config->flex_regs) {842_mesa_sha1_update(&sha1_ctx, config->flex_regs,843sizeof(config->flex_regs[0]) *844config->n_flex_regs);845}846if (config->mux_regs) {847_mesa_sha1_update(&sha1_ctx, config->mux_regs,848sizeof(config->mux_regs[0]) *849config->n_mux_regs);850}851if (config->b_counter_regs) {852_mesa_sha1_update(&sha1_ctx, config->b_counter_regs,853sizeof(config->b_counter_regs[0]) *854config->n_b_counter_regs);855}856857uint8_t hash[20];858_mesa_sha1_final(&sha1_ctx, hash);859860char formatted_hash[41];861_mesa_sha1_format(formatted_hash, hash);862863char generated_guid[37];864snprintf(generated_guid, sizeof(generated_guid),865"%.8s-%.4s-%.4s-%.4s-%.12s",866&formatted_hash[0], &formatted_hash[8],867&formatted_hash[8 + 4], &formatted_hash[8 + 4 + 4],868&formatted_hash[8 + 4 + 4 + 4]);869870/* Check if already present. */871uint64_t id;872if (intel_perf_load_metric_id(perf_cfg, generated_guid, &id))873return id;874875return i915_add_config(perf_cfg, fd, config, generated_guid);876}877878static uint64_t879get_passes_mask(struct intel_perf_config *perf,880const uint32_t *counter_indices,881uint32_t counter_indices_count)882{883uint64_t queries_mask = 0;884885assert(perf->n_queries < 64);886887/* Compute the number of passes by going through all counters N times (with888* N the number of queries) to make sure we select the most constraining889* counters first and look at the more flexible ones (that could be890* obtained from multiple queries) later. That way we minimize the number891* of passes required.892*/893for (uint32_t q = 0; q < perf->n_queries; q++) {894for (uint32_t i = 0; i < counter_indices_count; i++) {895assert(counter_indices[i] < perf->n_counters);896897uint32_t idx = counter_indices[i];898if (util_bitcount64(perf->counter_infos[idx].query_mask) != (q + 1))899continue;900901if (queries_mask & perf->counter_infos[idx].query_mask)902continue;903904queries_mask |= BITFIELD64_BIT(ffsll(perf->counter_infos[idx].query_mask) - 1);905}906}907908return queries_mask;909}910911uint32_t912intel_perf_get_n_passes(struct intel_perf_config *perf,913const uint32_t *counter_indices,914uint32_t counter_indices_count,915struct intel_perf_query_info **pass_queries)916{917uint64_t queries_mask = get_passes_mask(perf, counter_indices, counter_indices_count);918919if (pass_queries) {920uint32_t pass = 0;921for (uint32_t q = 0; q < perf->n_queries; q++) {922if ((1ULL << q) & queries_mask)923pass_queries[pass++] = &perf->queries[q];924}925}926927return util_bitcount64(queries_mask);928}929930void931intel_perf_get_counters_passes(struct intel_perf_config *perf,932const uint32_t *counter_indices,933uint32_t counter_indices_count,934struct intel_perf_counter_pass *counter_pass)935{936uint64_t queries_mask = get_passes_mask(perf, counter_indices, counter_indices_count);937ASSERTED uint32_t n_passes = util_bitcount64(queries_mask);938939for (uint32_t i = 0; i < counter_indices_count; i++) {940assert(counter_indices[i] < perf->n_counters);941942uint32_t idx = counter_indices[i];943counter_pass[i].counter = perf->counter_infos[idx].counter;944945uint32_t query_idx = ffsll(perf->counter_infos[idx].query_mask & queries_mask) - 1;946counter_pass[i].query = &perf->queries[query_idx];947948uint32_t clear_bits = 63 - query_idx;949counter_pass[i].pass = util_bitcount64((queries_mask << clear_bits) >> clear_bits) - 1;950assert(counter_pass[i].pass < n_passes);951}952}953954/* Accumulate 32bits OA counters */955static inline void956accumulate_uint32(const uint32_t *report0,957const uint32_t *report1,958uint64_t *accumulator)959{960*accumulator += (uint32_t)(*report1 - *report0);961}962963/* Accumulate 40bits OA counters */964static inline void965accumulate_uint40(int a_index,966const uint32_t *report0,967const uint32_t *report1,968uint64_t *accumulator)969{970const uint8_t *high_bytes0 = (uint8_t *)(report0 + 40);971const uint8_t *high_bytes1 = (uint8_t *)(report1 + 40);972uint64_t high0 = (uint64_t)(high_bytes0[a_index]) << 32;973uint64_t high1 = (uint64_t)(high_bytes1[a_index]) << 32;974uint64_t value0 = report0[a_index + 4] | high0;975uint64_t value1 = report1[a_index + 4] | high1;976uint64_t delta;977978if (value0 > value1)979delta = (1ULL << 40) + value1 - value0;980else981delta = value1 - value0;982983*accumulator += delta;984}985986static void987gfx8_read_report_clock_ratios(const uint32_t *report,988uint64_t *slice_freq_hz,989uint64_t *unslice_freq_hz)990{991/* The lower 16bits of the RPT_ID field of the OA reports contains a992* snapshot of the bits coming from the RP_FREQ_NORMAL register and is993* divided this way :994*995* RPT_ID[31:25]: RP_FREQ_NORMAL[20:14] (low squashed_slice_clock_frequency)996* RPT_ID[10:9]: RP_FREQ_NORMAL[22:21] (high squashed_slice_clock_frequency)997* RPT_ID[8:0]: RP_FREQ_NORMAL[31:23] (squashed_unslice_clock_frequency)998*999* RP_FREQ_NORMAL[31:23]: Software Unslice Ratio Request1000* Multiple of 33.33MHz 2xclk (16 MHz 1xclk)1001*1002* RP_FREQ_NORMAL[22:14]: Software Slice Ratio Request1003* Multiple of 33.33MHz 2xclk (16 MHz 1xclk)1004*/10051006uint32_t unslice_freq = report[0] & 0x1ff;1007uint32_t slice_freq_low = (report[0] >> 25) & 0x7f;1008uint32_t slice_freq_high = (report[0] >> 9) & 0x3;1009uint32_t slice_freq = slice_freq_low | (slice_freq_high << 7);10101011*slice_freq_hz = slice_freq * 16666667ULL;1012*unslice_freq_hz = unslice_freq * 16666667ULL;1013}10141015void1016intel_perf_query_result_read_frequencies(struct intel_perf_query_result *result,1017const struct intel_device_info *devinfo,1018const uint32_t *start,1019const uint32_t *end)1020{1021/* Slice/Unslice frequency is only available in the OA reports when the1022* "Disable OA reports due to clock ratio change" field in1023* OA_DEBUG_REGISTER is set to 1. This is how the kernel programs this1024* global register (see drivers/gpu/drm/i915/i915_perf.c)1025*1026* Documentation says this should be available on Gfx9+ but experimentation1027* shows that Gfx8 reports similar values, so we enable it there too.1028*/1029if (devinfo->ver < 8)1030return;10311032gfx8_read_report_clock_ratios(start,1033&result->slice_frequency[0],1034&result->unslice_frequency[0]);1035gfx8_read_report_clock_ratios(end,1036&result->slice_frequency[1],1037&result->unslice_frequency[1]);1038}10391040static inline bool1041can_use_mi_rpc_bc_counters(const struct intel_device_info *devinfo)1042{1043return devinfo->ver <= 11;1044}10451046void1047intel_perf_query_result_accumulate(struct intel_perf_query_result *result,1048const struct intel_perf_query_info *query,1049const struct intel_device_info *devinfo,1050const uint32_t *start,1051const uint32_t *end)1052{1053int i;10541055if (result->hw_id == INTEL_PERF_INVALID_CTX_ID &&1056start[2] != INTEL_PERF_INVALID_CTX_ID)1057result->hw_id = start[2];1058if (result->reports_accumulated == 0)1059result->begin_timestamp = start[1];1060result->reports_accumulated++;10611062switch (query->oa_format) {1063case I915_OA_FORMAT_A32u40_A4u32_B8_C8:1064accumulate_uint32(start + 1, end + 1,1065result->accumulator + query->gpu_time_offset); /* timestamp */1066accumulate_uint32(start + 3, end + 3,1067result->accumulator + query->gpu_clock_offset); /* clock */10681069/* 32x 40bit A counters... */1070for (i = 0; i < 32; i++) {1071accumulate_uint40(i, start, end,1072result->accumulator + query->a_offset + i);1073}10741075/* 4x 32bit A counters... */1076for (i = 0; i < 4; i++) {1077accumulate_uint32(start + 36 + i, end + 36 + i,1078result->accumulator + query->a_offset + 32 + i);1079}10801081if (can_use_mi_rpc_bc_counters(devinfo)) {1082/* 8x 32bit B counters */1083for (i = 0; i < 8; i++) {1084accumulate_uint32(start + 48 + i, end + 48 + i,1085result->accumulator + query->b_offset + i);1086}10871088/* 8x 32bit C counters... */1089for (i = 0; i < 8; i++) {1090accumulate_uint32(start + 56 + i, end + 56 + i,1091result->accumulator + query->c_offset + i);1092}1093}1094break;10951096case I915_OA_FORMAT_A45_B8_C8:1097accumulate_uint32(start + 1, end + 1, result->accumulator); /* timestamp */10981099for (i = 0; i < 61; i++) {1100accumulate_uint32(start + 3 + i, end + 3 + i,1101result->accumulator + query->a_offset + i);1102}1103break;11041105default:1106unreachable("Can't accumulate OA counters in unknown format");1107}11081109}11101111#define GET_FIELD(word, field) (((word) & field ## _MASK) >> field ## _SHIFT)11121113void1114intel_perf_query_result_read_gt_frequency(struct intel_perf_query_result *result,1115const struct intel_device_info *devinfo,1116const uint32_t start,1117const uint32_t end)1118{1119switch (devinfo->ver) {1120case 7:1121case 8:1122result->gt_frequency[0] = GET_FIELD(start, GFX7_RPSTAT1_CURR_GT_FREQ) * 50ULL;1123result->gt_frequency[1] = GET_FIELD(end, GFX7_RPSTAT1_CURR_GT_FREQ) * 50ULL;1124break;1125case 9:1126case 11:1127case 12:1128result->gt_frequency[0] = GET_FIELD(start, GFX9_RPSTAT0_CURR_GT_FREQ) * 50ULL / 3ULL;1129result->gt_frequency[1] = GET_FIELD(end, GFX9_RPSTAT0_CURR_GT_FREQ) * 50ULL / 3ULL;1130break;1131default:1132unreachable("unexpected gen");1133}11341135/* Put the numbers into Hz. */1136result->gt_frequency[0] *= 1000000ULL;1137result->gt_frequency[1] *= 1000000ULL;1138}11391140void1141intel_perf_query_result_read_perfcnts(struct intel_perf_query_result *result,1142const struct intel_perf_query_info *query,1143const uint64_t *start,1144const uint64_t *end)1145{1146for (uint32_t i = 0; i < 2; i++) {1147uint64_t v0 = start[i] & PERF_CNT_VALUE_MASK;1148uint64_t v1 = end[i] & PERF_CNT_VALUE_MASK;11491150result->accumulator[query->perfcnt_offset + i] = v0 > v1 ?1151(PERF_CNT_VALUE_MASK + 1 + v1 - v0) :1152(v1 - v0);1153}1154}11551156static uint32_t1157query_accumulator_offset(const struct intel_perf_query_info *query,1158enum intel_perf_query_field_type type,1159uint8_t index)1160{1161switch (type) {1162case INTEL_PERF_QUERY_FIELD_TYPE_SRM_PERFCNT:1163return query->perfcnt_offset + index;1164case INTEL_PERF_QUERY_FIELD_TYPE_SRM_OA_B:1165return query->b_offset + index;1166case INTEL_PERF_QUERY_FIELD_TYPE_SRM_OA_C:1167return query->c_offset + index;1168default:1169unreachable("Invalid register type");1170return 0;1171}1172}11731174void1175intel_perf_query_result_accumulate_fields(struct intel_perf_query_result *result,1176const struct intel_perf_query_info *query,1177const struct intel_device_info *devinfo,1178const void *start,1179const void *end,1180bool no_oa_accumulate)1181{1182struct intel_perf_query_field_layout *layout = &query->perf->query_layout;11831184for (uint32_t r = 0; r < layout->n_fields; r++) {1185struct intel_perf_query_field *field = &layout->fields[r];11861187if (field->type == INTEL_PERF_QUERY_FIELD_TYPE_MI_RPC) {1188intel_perf_query_result_read_frequencies(result, devinfo,1189start + field->location,1190end + field->location);1191/* no_oa_accumulate=true is used when doing GL perf queries, we1192* manually parse the OA reports from the OA buffer and substract1193* unrelated deltas, so don't accumulate the begin/end reports here.1194*/1195if (!no_oa_accumulate) {1196intel_perf_query_result_accumulate(result, query, devinfo,1197start + field->location,1198end + field->location);1199}1200} else {1201uint64_t v0, v1;12021203if (field->size == 4) {1204v0 = *(const uint32_t *)(start + field->location);1205v1 = *(const uint32_t *)(end + field->location);1206} else {1207assert(field->size == 8);1208v0 = *(const uint64_t *)(start + field->location);1209v1 = *(const uint64_t *)(end + field->location);1210}12111212if (field->mask) {1213v0 = field->mask & v0;1214v1 = field->mask & v1;1215}12161217/* RPSTAT is a bit of a special case because its begin/end values1218* represent frequencies. We store it in a separate location.1219*/1220if (field->type == INTEL_PERF_QUERY_FIELD_TYPE_SRM_RPSTAT)1221intel_perf_query_result_read_gt_frequency(result, devinfo, v0, v1);1222else1223result->accumulator[query_accumulator_offset(query, field->type, field->index)] = v1 - v0;1224}1225}1226}12271228void1229intel_perf_query_result_clear(struct intel_perf_query_result *result)1230{1231memset(result, 0, sizeof(*result));1232result->hw_id = INTEL_PERF_INVALID_CTX_ID;1233}12341235void1236intel_perf_query_result_print_fields(const struct intel_perf_query_info *query,1237const struct intel_device_info *devinfo,1238const void *data)1239{1240const struct intel_perf_query_field_layout *layout = &query->perf->query_layout;12411242for (uint32_t r = 0; r < layout->n_fields; r++) {1243const struct intel_perf_query_field *field = &layout->fields[r];1244const uint32_t *value32 = data + field->location;12451246switch (field->type) {1247case INTEL_PERF_QUERY_FIELD_TYPE_MI_RPC:1248fprintf(stderr, "MI_RPC:\n");1249fprintf(stderr, " TS: 0x%08x\n", *(value32 + 1));1250fprintf(stderr, " CLK: 0x%08x\n", *(value32 + 3));1251break;1252case INTEL_PERF_QUERY_FIELD_TYPE_SRM_OA_B:1253fprintf(stderr, "B%u: 0x%08x\n", field->index, *value32);1254break;1255case INTEL_PERF_QUERY_FIELD_TYPE_SRM_OA_C:1256fprintf(stderr, "C%u: 0x%08x\n", field->index, *value32);1257break;1258default:1259break;1260}1261}1262}12631264static int1265intel_perf_compare_query_names(const void *v1, const void *v2)1266{1267const struct intel_perf_query_info *q1 = v1;1268const struct intel_perf_query_info *q2 = v2;12691270return strcmp(q1->name, q2->name);1271}12721273static inline struct intel_perf_query_field *1274add_query_register(struct intel_perf_query_field_layout *layout,1275enum intel_perf_query_field_type type,1276uint16_t offset,1277uint16_t size,1278uint8_t index)1279{1280/* Align MI_RPC to 64bytes (HW requirement) & 64bit registers to 8bytes1281* (shows up nicely in the debugger).1282*/1283if (type == INTEL_PERF_QUERY_FIELD_TYPE_MI_RPC)1284layout->size = align(layout->size, 64);1285else if (size % 8 == 0)1286layout->size = align(layout->size, 8);12871288layout->fields[layout->n_fields++] = (struct intel_perf_query_field) {1289.mmio_offset = offset,1290.location = layout->size,1291.type = type,1292.index = index,1293.size = size,1294};1295layout->size += size;12961297return &layout->fields[layout->n_fields - 1];1298}12991300static void1301intel_perf_init_query_fields(struct intel_perf_config *perf_cfg,1302const struct intel_device_info *devinfo,1303bool use_register_snapshots)1304{1305struct intel_perf_query_field_layout *layout = &perf_cfg->query_layout;13061307layout->n_fields = 0;13081309/* MI_RPC requires a 64byte alignment. */1310layout->alignment = 64;13111312layout->fields = rzalloc_array(perf_cfg, struct intel_perf_query_field, 5 + 16);13131314add_query_register(layout, INTEL_PERF_QUERY_FIELD_TYPE_MI_RPC,13150, 256, 0);13161317if (use_register_snapshots) {1318if (devinfo->ver <= 11) {1319struct intel_perf_query_field *field =1320add_query_register(layout,1321INTEL_PERF_QUERY_FIELD_TYPE_SRM_PERFCNT,1322PERF_CNT_1_DW0, 8, 0);1323field->mask = PERF_CNT_VALUE_MASK;13241325field = add_query_register(layout,1326INTEL_PERF_QUERY_FIELD_TYPE_SRM_PERFCNT,1327PERF_CNT_2_DW0, 8, 1);1328field->mask = PERF_CNT_VALUE_MASK;1329}13301331if (devinfo->ver == 8 && !devinfo->is_cherryview) {1332add_query_register(layout,1333INTEL_PERF_QUERY_FIELD_TYPE_SRM_RPSTAT,1334GFX7_RPSTAT1, 4, 0);1335}13361337if (devinfo->ver >= 9) {1338add_query_register(layout,1339INTEL_PERF_QUERY_FIELD_TYPE_SRM_RPSTAT,1340GFX9_RPSTAT0, 4, 0);1341}13421343if (!can_use_mi_rpc_bc_counters(devinfo)) {1344if (devinfo->ver >= 8 && devinfo->ver <= 11) {1345for (uint32_t i = 0; i < GFX8_N_OA_PERF_B32; i++) {1346add_query_register(layout, INTEL_PERF_QUERY_FIELD_TYPE_SRM_OA_B,1347GFX8_OA_PERF_B32(i), 4, i);1348}1349for (uint32_t i = 0; i < GFX8_N_OA_PERF_C32; i++) {1350add_query_register(layout, INTEL_PERF_QUERY_FIELD_TYPE_SRM_OA_C,1351GFX8_OA_PERF_C32(i), 4, i);1352}1353} else if (devinfo->ver == 12) {1354for (uint32_t i = 0; i < GFX12_N_OAG_PERF_B32; i++) {1355add_query_register(layout, INTEL_PERF_QUERY_FIELD_TYPE_SRM_OA_B,1356GFX12_OAG_PERF_B32(i), 4, i);1357}1358for (uint32_t i = 0; i < GFX12_N_OAG_PERF_C32; i++) {1359add_query_register(layout, INTEL_PERF_QUERY_FIELD_TYPE_SRM_OA_C,1360GFX12_OAG_PERF_C32(i), 4, i);1361}1362}1363}1364}13651366/* Align the whole package to 64bytes so that 2 snapshots can be put1367* together without extract alignment for the user.1368*/1369layout->size = align(layout->size, 64);1370}13711372void1373intel_perf_init_metrics(struct intel_perf_config *perf_cfg,1374const struct intel_device_info *devinfo,1375int drm_fd,1376bool include_pipeline_statistics,1377bool use_register_snapshots)1378{1379intel_perf_init_query_fields(perf_cfg, devinfo, use_register_snapshots);13801381if (include_pipeline_statistics) {1382load_pipeline_statistic_metrics(perf_cfg, devinfo);1383intel_perf_register_mdapi_statistic_query(perf_cfg, devinfo);1384}13851386bool oa_metrics = oa_metrics_available(perf_cfg, drm_fd, devinfo,1387use_register_snapshots);1388if (oa_metrics)1389load_oa_metrics(perf_cfg, drm_fd, devinfo);13901391/* sort query groups by name */1392qsort(perf_cfg->queries, perf_cfg->n_queries,1393sizeof(perf_cfg->queries[0]), intel_perf_compare_query_names);13941395build_unique_counter_list(perf_cfg);13961397if (oa_metrics)1398intel_perf_register_mdapi_oa_query(perf_cfg, devinfo);1399}140014011402