Home | History | Annotate | Download | only in i915

Lines Matching refs:stream

38  * descriptor representing a stream of GPU metrics which can then be read() as
39 * a stream of sample records.
58 * i915 perf file descriptors represent a "stream" instead of an "event"; where
59 * a perf event primarily corresponds to a single 64bit value, while a stream
63 * of related counters. Samples for an i915 perf stream capturing OA metrics
66 * selected by the user opening the stream. Perf has support for grouping
70 * i915 perf stream configurations are provided as an array of u64 (key,value)
363 * struct perf_open_properties - for validated properties given to open a stream
376 * to open a stream of metrics the configuration is built up in the structure
444 static u32 gen12_oa_hw_tail_read(struct i915_perf_stream *stream)
446 struct intel_uncore *uncore = stream->uncore;
452 static u32 gen8_oa_hw_tail_read(struct i915_perf_stream *stream)
454 struct intel_uncore *uncore = stream->uncore;
459 static u32 gen7_oa_hw_tail_read(struct i915_perf_stream *stream)
461 struct intel_uncore *uncore = stream->uncore;
469 * @stream: i915 stream instance
486 * only called while the stream is enabled, while the global OA configuration
491 static bool oa_buffer_check(struct i915_perf_stream *stream)
493 int report_size = stream->oa_buffer.format_size;
507 head = stream->oa_buffer.head;
509 aged_idx = stream->oa_buffer.aged_tail_idx;
510 aged_tail = stream->oa_buffer.tails[aged_idx].offset;
511 aging_tail = stream->oa_buffer.tails[!aged_idx].offset;
513 hw_tail = stream->perf->ops.oa_hw_tail_read(stream);
533 ((now - stream->oa_buffer.aging_timestamp) >
537 stream->oa_buffer.aged_tail_idx = aged_idx;
542 stream->oa_buffer.tails[!aged_idx].offset = INVALID_TAIL_PTR;
557 struct i915_vma *vma = stream->oa_buffer.vma;
566 stream->oa_buffer.tails[!aged_idx].offset =
568 stream->oa_buffer.aging_timestamp = now;
581 * @stream: An i915-perf stream opened for OA metrics
594 static int append_oa_status(struct i915_perf_stream *stream,
626 * @stream: An i915-perf stream opened for OA metrics
633 * properties when opening a stream, tracked as `stream->sample_flags`. This
641 static int append_oa_sample(struct i915_perf_stream *stream,
653 int report_size = stream->oa_buffer.format_size;
655 u32 sample_flags = stream->sample_flags;
659 header.size = stream->sample_size;
696 * @stream: An i915-perf stream opened for OA metrics
715 static int gen8_append_oa_reports(struct i915_perf_stream *stream,
720 static int gen8_append_oa_reports(struct i915_perf_stream *stream,
726 struct intel_uncore *uncore = stream->uncore;
727 int report_size = stream->oa_buffer.format_size;
728 u8 *oa_buf_base = stream->oa_buffer.vaddr;
729 u32 gtt_offset = i915_ggtt_offset(stream->oa_buffer.vma);
742 if (WARN_ON(!stream->enabled))
745 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
747 head = stream->oa_buffer.head;
748 aged_tail_idx = stream->oa_buffer.aged_tail_idx;
749 tail = stream->oa_buffer.tails[aged_tail_idx].offset;
751 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
813 (IS_GEN(stream->perf->i915, 12) ?
817 if (__ratelimit(&stream->perf->spurious_report_rs))
822 ctx_id = report32[2] & stream->specific_ctx_id_mask;
832 if (!(report32[0] & stream->perf->gen8_valid_ctx_bit) &&
833 INTEL_GEN(stream->perf->i915) <= 11)
867 if (!stream->perf->exclusive_stream->ctx ||
868 stream->specific_ctx_id == ctx_id ||
869 stream->oa_buffer.last_ctx_id == stream->specific_ctx_id ||
876 if (stream->perf->exclusive_stream->ctx &&
877 stream->specific_ctx_id != ctx_id) {
881 ret = append_oa_sample(stream, buf, count, offset,
886 stream->oa_buffer.last_ctx_id = ctx_id;
907 oaheadptr = IS_GEN(stream->perf->i915, 12) ?
910 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
919 stream->oa_buffer.head = head;
921 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
929 * @stream: An i915-perf stream opened for OA metrics
948 static int gen8_oa_read(struct i915_perf_stream *stream,
953 static int gen8_oa_read(struct i915_perf_stream *stream,
959 struct intel_uncore *uncore = stream->uncore;
964 if (WARN_ON(!stream->oa_buffer.vaddr))
967 oastatus_reg = IS_GEN(stream->perf->i915, 12) ?
987 ret = append_oa_status(stream, buf, count, offset,
993 stream->period_exponent);
995 stream->perf->ops.oa_disable(stream);
996 stream->perf->ops.oa_enable(stream);
1006 ret = append_oa_status(stream, buf, count, offset,
1014 return gen8_append_oa_reports(stream, buf, count, offset);
1019 * @stream: An i915-perf stream opened for OA metrics
1038 static int gen7_append_oa_reports(struct i915_perf_stream *stream,
1043 static int gen7_append_oa_reports(struct i915_perf_stream *stream,
1049 struct intel_uncore *uncore = stream->uncore;
1050 int report_size = stream->oa_buffer.format_size;
1051 u8 *oa_buf_base = stream->oa_buffer.vaddr;
1052 u32 gtt_offset = i915_ggtt_offset(stream->oa_buffer.vma);
1065 if (WARN_ON(!stream->enabled))
1068 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
1070 head = stream->oa_buffer.head;
1071 aged_tail_idx = stream->oa_buffer.aged_tail_idx;
1072 tail = stream->oa_buffer.tails[aged_tail_idx].offset;
1074 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
1127 if (__ratelimit(&stream->perf->spurious_report_rs))
1132 ret = append_oa_sample(stream, buf, count, offset, report);
1151 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
1161 stream->oa_buffer.head = head;
1163 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
1171 * @stream: An i915-perf stream opened for OA metrics
1186 static int gen7_oa_read(struct i915_perf_stream *stream,
1191 static int gen7_oa_read(struct i915_perf_stream *stream,
1197 struct intel_uncore *uncore = stream->uncore;
1201 if (WARN_ON(!stream->oa_buffer.vaddr))
1211 oastatus1 &= ~stream->perf->gen7_latched_oastatus1;
1234 ret = append_oa_status(stream, buf, count, offset,
1240 stream->period_exponent);
1242 stream->perf->ops.oa_disable(stream);
1243 stream->perf->ops.oa_enable(stream);
1249 ret = append_oa_status(stream, buf, count, offset,
1253 stream->perf->gen7_latched_oastatus1 |=
1257 return gen7_append_oa_reports(stream, buf, count, offset);
1262 * @stream: An i915-perf stream opened for OA metrics
1264 * Called when userspace tries to read() from a blocking stream FD opened
1274 static int i915_oa_wait_unlocked(struct i915_perf_stream *stream)
1280 if (!stream->periodic)
1283 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
1284 DRM_SPIN_WAIT_UNTIL(ret, &stream->poll_wq, &stream->oa_buffer.ptr_lock,
1285 oa_buffer_check(stream));
1286 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
1292 * i915_oa_poll_wait - call poll_wait() for an OA stream poll()
1293 * @stream: An i915-perf stream opened for OA metrics
1294 * @file: An i915 perf stream file
1297 * For handling userspace polling on an i915 perf stream opened for OA metrics,
1302 static void i915_oa_poll_wait(struct i915_perf_stream *stream,
1306 poll_wait(file, &stream->poll_wq, wait);
1312 * @stream: An i915-perf stream opened for OA metrics
1323 static int i915_oa_read(struct i915_perf_stream *stream,
1328 static int i915_oa_read(struct i915_perf_stream *stream,
1334 return stream->perf->ops.read(stream, buf, count, offset);
1337 static struct intel_context *oa_pin_context(struct i915_perf_stream *stream)
1340 struct i915_gem_context *ctx = stream->ctx;
1345 if (ce->engine != stream->engine) /* first match! */
1354 stream->pinned_ctx = ce;
1360 return stream->pinned_ctx;
1365 * @stream: An i915-perf stream opened for OA metrics
1368 * lifetime of the stream. This ensures that we don't have to worry about
1373 static int oa_get_render_ctx_id(struct i915_perf_stream *stream)
1377 ce = oa_pin_context(stream);
1387 stream->specific_ctx_id = i915_ggtt_offset(ce->state);
1388 stream->specific_ctx_id_mask = 0;
1396 stream->specific_ctx_id_mask =
1398 stream->specific_ctx_id = stream->specific_ctx_id_mask;
1410 stream->specific_ctx_id =
1417 stream->specific_ctx_id_mask =
1424 stream->specific_ctx_id_mask =
1426 stream->specific_ctx_id = stream->specific_ctx_id_mask;
1434 ce->tag = stream->specific_ctx_id_mask;
1437 stream->specific_ctx_id,
1438 stream->specific_ctx_id_mask);
1445 * @stream: An i915-perf stream opened for OA metrics
1448 * for the lifetime of the stream, then that can be undone here.
1450 static void oa_put_render_ctx_id(struct i915_perf_stream *stream)
1454 ce = fetch_and_zero(&stream->pinned_ctx);
1460 stream->specific_ctx_id = INVALID_CTX_ID;
1461 stream->specific_ctx_id_mask = 0;
1465 free_oa_buffer(struct i915_perf_stream *stream)
1467 i915_vma_unpin_and_release(&stream->oa_buffer.vma,
1470 stream->oa_buffer.vaddr = NULL;
1474 free_oa_configs(struct i915_perf_stream *stream)
1478 i915_oa_config_put(stream->oa_config);
1479 llist_for_each_entry_safe(oa_bo, tmp, stream->oa_config_bos.first, node)
1484 free_noa_wait(struct i915_perf_stream *stream)
1486 i915_vma_unpin_and_release(&stream->noa_wait, 0);
1489 static void i915_oa_stream_destroy(struct i915_perf_stream *stream)
1491 struct i915_perf *perf = stream->perf;
1493 BUG_ON(stream != perf->exclusive_stream);
1495 spin_lock_destroy(&stream->oa_buffer.ptr_lock);
1496 seldestroy(&stream->poll_selq);
1497 DRM_DESTROY_WAITQUEUE(&stream->poll_wq);
1498 hrtimer_cancel(&stream->poll_check_timer);
1505 perf->ops.disable_metric_set(stream);
1507 free_oa_buffer(stream);
1509 intel_uncore_forcewake_put(stream->uncore, FORCEWAKE_ALL);
1510 intel_engine_pm_put(stream->engine);
1512 if (stream->ctx)
1513 oa_put_render_ctx_id(stream);
1515 free_oa_configs(stream);
1516 free_noa_wait(stream);
1524 static void gen7_init_oa_buffer(struct i915_perf_stream *stream)
1526 struct intel_uncore *uncore = stream->uncore;
1527 u32 gtt_offset = i915_ggtt_offset(stream->oa_buffer.vma);
1530 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
1537 stream->oa_buffer.head = gtt_offset;
1545 stream->oa_buffer.tails[0].offset = INVALID_TAIL_PTR;
1546 stream->oa_buffer.tails[1].offset = INVALID_TAIL_PTR;
1548 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
1554 stream->perf->gen7_latched_oastatus1 = 0;
1559 * when re-enabling a stream or in error/reset paths.
1567 memset(stream->oa_buffer.vaddr, 0, OA_BUFFER_SIZE);
1569 stream->pollin = false;
1572 static void gen8_init_oa_buffer(struct i915_perf_stream *stream)
1574 struct intel_uncore *uncore = stream->uncore;
1575 u32 gtt_offset = i915_ggtt_offset(stream->oa_buffer.vma);
1578 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
1582 stream->oa_buffer.head = gtt_offset;
1599 stream->oa_buffer.tails[0].offset = INVALID_TAIL_PTR;
1600 stream->oa_buffer.tails[1].offset = INVALID_TAIL_PTR;
1607 stream->oa_buffer.last_ctx_id = INVALID_CTX_ID;
1609 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
1615 * when re-enabling a stream or in error/reset paths.
1623 memset(stream->oa_buffer.vaddr, 0, OA_BUFFER_SIZE);
1625 stream->pollin = false;
1628 static void gen12_init_oa_buffer(struct i915_perf_stream *stream)
1630 struct intel_uncore *uncore = stream->uncore;
1631 u32 gtt_offset = i915_ggtt_offset(stream->oa_buffer.vma);
1634 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
1639 stream->oa_buffer.head = gtt_offset;
1655 stream->oa_buffer.tails[0].offset = INVALID_TAIL_PTR;
1656 stream->oa_buffer.tails[1].offset = INVALID_TAIL_PTR;
1663 stream->oa_buffer.last_ctx_id = INVALID_CTX_ID;
1665 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
1671 * when re-enabling a stream or in error/reset paths.
1679 memset(stream->oa_buffer.vaddr, 0,
1680 stream->oa_buffer.vma->size);
1682 stream->pollin = false;
1685 static int alloc_oa_buffer(struct i915_perf_stream *stream)
1691 if (WARN_ON(stream->oa_buffer.vma))
1697 bo = i915_gem_object_create_shmem(stream->perf->i915, OA_BUFFER_SIZE);
1711 stream->oa_buffer.vma = vma;
1713 stream->oa_buffer.vaddr =
1715 if (IS_ERR(stream->oa_buffer.vaddr)) {
1716 ret = PTR_ERR(stream->oa_buffer.vaddr);
1728 stream->oa_buffer.vaddr = NULL;
1729 stream->oa_buffer.vma = NULL;
1734 static u32 *save_restore_register(struct i915_perf_stream *stream, u32 *cs,
1742 if (INTEL_GEN(stream->perf->i915) >= 8)
1748 *cs++ = intel_gt_scratch_offset(stream->engine->gt,
1756 static int alloc_noa_wait(struct i915_perf_stream *stream)
1758 struct drm_i915_private *i915 = stream->perf->i915;
1763 atomic64_read(&stream->perf->noa_programming_delay) *
1766 const u32 base = stream->engine->mmio_base;
1788 * needs to be fixed during the lifetime of the i915/perf stream.
1805 stream, cs, true /* save */, CS_GPR(i),
1808 stream, cs, true /* save */, MI_PREDICATE_RESULT_1,
1912 stream, cs, false /* restore */, CS_GPR(i),
1915 stream, cs, false /* restore */, MI_PREDICATE_RESULT_1,
1926 stream->noa_wait = vma;
1970 alloc_oa_config_buffer(struct i915_perf_stream *stream,
1989 obj = i915_gem_object_create_shmem(stream->perf->i915, config_length);
2012 *cs++ = (INTEL_GEN(stream->perf->i915) < 8 ?
2015 *cs++ = i915_ggtt_offset(stream->noa_wait);
2022 &stream->engine->gt->ggtt->vm,
2030 llist_add(&oa_bo->node, &stream->oa_config_bos);
2042 get_oa_vma(struct i915_perf_stream *stream, struct i915_oa_config *oa_config)
2048 * to the stream.
2050 llist_for_each_entry(oa_bo, stream->oa_config_bos.first, node) {
2058 oa_bo = alloc_oa_config_buffer(stream, oa_config);
2066 static int emit_oa_config(struct i915_perf_stream *stream,
2074 vma = get_oa_vma(stream, oa_config);
2110 static struct intel_context *oa_context(struct i915_perf_stream *stream)
2112 return stream->pinned_ctx ?: stream->engine->kernel_context;
2115 static int hsw_enable_metric_set(struct i915_perf_stream *stream)
2117 struct intel_uncore *uncore = stream->uncore;
2134 return emit_oa_config(stream, stream->oa_config, oa_context(stream));
2137 static void hsw_disable_metric_set(struct i915_perf_stream *stream)
2139 struct intel_uncore *uncore = stream->uncore;
2179 const struct i915_perf_stream *stream)
2181 u32 ctx_oactxctrl = stream->perf->ctx_oactxctrl_offset;
2182 u32 ctx_flexeu0 = stream->perf->ctx_flexeu0_offset;
2197 (stream->period_exponent << GEN8_OA_TIMER_PERIOD_SHIFT) |
2198 (stream->periodic ? GEN8_OA_TIMER_ENABLE : 0) |
2203 oa_config_flex_reg(stream->oa_config, flex_regs[i]);
2329 static int gen12_configure_oar_context(struct i915_perf_stream *stream, bool enable)
2332 struct intel_context *ce = stream->pinned_ctx;
2333 u32 format = stream->oa_buffer.format;
2337 stream->perf->ctx_oactxctrl_offset + 1,
2377 * Manages updating the per-context aspects of the OA stream
2401 static int oa_configure_all_contexts(struct i915_perf_stream *stream,
2405 struct drm_i915_private *i915 = stream->perf->i915;
2410 lockdep_assert_held(&stream->perf->lock);
2468 static int gen12_configure_all_contexts(struct i915_perf_stream *stream,
2478 return oa_configure_all_contexts(stream, regs, ARRAY_SIZE(regs));
2481 static int lrc_configure_all_contexts(struct i915_perf_stream *stream,
2485 const u32 ctx_flexeu0 = stream->perf->ctx_flexeu0_offset;
2494 stream->perf->ctx_oactxctrl_offset + 1,
2508 (stream->period_exponent << GEN8_OA_TIMER_PERIOD_SHIFT) |
2509 (stream->periodic ? GEN8_OA_TIMER_ENABLE : 0) |
2515 return oa_configure_all_contexts(stream, regs, ARRAY_SIZE(regs));
2518 static int gen8_enable_metric_set(struct i915_perf_stream *stream)
2520 struct intel_uncore *uncore = stream->uncore;
2521 struct i915_oa_config *oa_config = stream->oa_config;
2547 if (IS_GEN_RANGE(stream->perf->i915, 9, 11)) {
2558 ret = lrc_configure_all_contexts(stream, oa_config);
2562 return emit_oa_config(stream, oa_config, oa_context(stream));
2565 static u32 oag_report_ctx_switches(const struct i915_perf_stream *stream)
2568 (stream->sample_flags & SAMPLE_OA_REPORT) ?
2572 static int gen12_enable_metric_set(struct i915_perf_stream *stream)
2574 struct intel_uncore *uncore = stream->uncore;
2575 struct i915_oa_config *oa_config = stream
2576 bool periodic = stream->periodic;
2577 u32 period_exponent = stream->period_exponent;
2588 oag_report_ctx_switches(stream));
2601 ret = gen12_configure_all_contexts(stream, oa_config);
2610 if (stream->ctx) {
2611 ret = gen12_configure_oar_context(stream, true);
2616 return emit_oa_config(stream, oa_config, oa_context(stream));
2619 static void gen8_disable_metric_set(struct i915_perf_stream *stream)
2621 struct intel_uncore *uncore = stream->uncore;
2624 lrc_configure_all_contexts(stream, NULL);
2629 static void gen10_disable_metric_set(struct i915_perf_stream *stream)
2631 struct intel_uncore *uncore = stream->uncore;
2634 lrc_configure_all_contexts(stream, NULL);
2640 static void gen12_disable_metric_set(struct i915_perf_stream *stream)
2642 struct intel_uncore *uncore = stream->uncore;
2645 gen12_configure_all_contexts(stream, NULL);
2648 if (stream->ctx)
2649 gen12_configure_oar_context(stream, false);
2655 static void gen7_oa_enable(struct i915_perf_stream *stream)
2657 struct intel_uncore *uncore = stream->uncore;
2658 struct i915_gem_context *ctx = stream->ctx;
2659 u32 ctx_id = stream->specific_ctx_id;
2660 bool periodic = stream->periodic;
2661 u32 period_exponent = stream->period_exponent;
2662 u32 report_format = stream->oa_buffer.format;
2673 gen7_init_oa_buffer(stream);
2685 static void gen8_oa_enable(struct i915_perf_stream *stream)
2687 struct intel_uncore *uncore = stream->uncore;
2688 u32 report_format = stream->oa_buffer.format;
2699 gen8_init_oa_buffer(stream);
2711 static void gen12_oa_enable(struct i915_perf_stream *stream)
2713 struct intel_uncore *uncore = stream->uncore;
2714 u32 report_format = stream->oa_buffer.format;
2720 if (!(stream->sample_flags & SAMPLE_OA_REPORT))
2723 gen12_init_oa_buffer(stream);
2731 * i915_oa_stream_enable - handle `I915_PERF_IOCTL_ENABLE` for OA stream
2732 * @stream: An i915 perf stream opened for OA metrics
2735 * when opening the stream. This also starts a hrtimer that will periodically
2739 static void i915_oa_stream_enable(struct i915_perf_stream *stream)
2741 stream->perf->ops.oa_enable(stream);
2743 if (stream->periodic)
2744 hrtimer_start(&stream->poll_check_timer,
2749 static void gen7_oa_disable(struct i915_perf_stream *stream)
2751 struct intel_uncore *uncore = stream->uncore;
2760 static void gen8_oa_disable(struct i915_perf_stream *stream)
2762 struct intel_uncore *uncore = stream->uncore;
2771 static void gen12_oa_disable(struct i915_perf_stream *stream)
2773 struct intel_uncore *uncore = stream->uncore;
2784 * i915_oa_stream_disable - handle `I915_PERF_IOCTL_DISABLE` for OA stream
2785 * @stream: An i915 perf stream opened for OA metrics
2791 static void i915_oa_stream_disable(struct i915_perf_stream *stream)
2793 stream->perf->ops.oa_disable(stream);
2795 if (stream->periodic)
2796 hrtimer_cancel(&stream->poll_check_timer);
2811 * i915_oa_stream_init - validate combined props for OA stream and init
2812 * @stream: An i915 perf stream
2814 * @props: The property state that configures stream (individually validated)
2819 * At this point it has been determined that userspace wants a stream of
2828 static int i915_oa_stream_init(struct i915_perf_stream *stream,
2832 struct i915_perf *perf = stream->perf;
2852 (INTEL_GEN(perf->i915) < 12 || !stream->ctx)) {
2877 stream->engine = props->engine;
2878 stream->uncore = stream->engine->gt->uncore;
2880 stream->sample_size = sizeof(struct drm_i915_perf_record_header);
2884 stream->sample_flags = props->sample_flags;
2885 stream->sample_size += format_size;
2887 stream->oa_buffer.format_size = format_size;
2888 if (WARN_ON(stream->oa_buffer.format_size == 0))
2891 stream->hold_preemption = props->hold_preemption;
2893 stream->oa_buffer.format =
2896 stream->periodic = props->oa_periodic;
2897 if (stream->periodic)
2898 stream->period_exponent = props->oa_period_exponent;
2900 if (stream->ctx) {
2901 ret = oa_get_render_ctx_id(stream);
2908 ret = alloc_noa_wait(stream);
2914 stream->oa_config = i915_perf_get_oa_config(perf, props->metrics_set);
2915 if (!stream->oa_config) {
2933 intel_engine_pm_get(stream->engine);
2934 intel_uncore_forcewake_get(stream->uncore, FORCEWAKE_ALL);
2936 ret = alloc_oa_buffer(stream);
2940 stream->ops = &i915_oa_stream_ops;
2941 perf->exclusive_stream = stream;
2943 ret = perf->ops.enable_metric_set(stream);
2949 DRM_DEBUG("opening stream oa config uuid=%s\n",
2950 stream->oa_config->uuid);
2952 hrtimer_init(&stream->poll_check_timer,
2954 stream->poll_check_timer.function = oa_poll_check_timer_cb;
2955 DRM_INIT_WAITQUEUE(&stream->poll_wq, "i915perf");
2956 selinit(&stream->poll_selq);
2957 spin_lock_init(&stream->oa_buffer.ptr_lock);
2963 perf->ops.disable_metric_set(stream);
2965 free_oa_buffer(stream);
2968 free_oa_configs(stream);
2970 intel_uncore_forcewake_put(stream->uncore, FORCEWAKE_ALL);
2971 intel_engine_pm_put(stream->engine);
2974 free_noa_wait(stream);
2977 if (stream->ctx)
2978 oa_put_render_ctx_id(stream);
2986 struct i915_perf_stream *stream;
2993 stream = engine->i915->perf.exclusive_stream;
2998 if (stream && INTEL_GEN(stream->perf->i915) < 12)
2999 gen8_update_reg_state_unlocked(ce, stream);
3004 * @stream: An i915 perf stream
3005 * @file: An i915 perf stream file
3028 static int i915_perf_read_locked(struct i915_perf_stream *stream,
3034 return stream->ops->read(stream, buf, count, ppos);
3037 static ssize_t i915_perf_read_locked(struct i915_perf_stream *stream,
3047 * stream->ops->read() implementations.
3050 int ret = stream->ops->read(stream, buf, count, &offset);
3057 * i915_perf_read - handles read() FOP for i915 perf stream FDs
3058 * @file: An i915 perf stream file
3063 * The entry point for handling a read() on a stream file descriptor from
3065 * &i915_perf_stream_ops->read but to save having stream implementations (of
3068 * We can also consistently treat trying to read from a disabled stream
3069 * as an IO error so implementations can assume the stream is enabled
3088 struct i915_perf_stream *stream = file->f_data;
3090 struct i915_perf_stream *stream = file->private_data;
3092 struct i915_perf *perf = stream->perf;
3096 * disabled stream as an error. In particular it might otherwise lead
3099 if (!stream->enabled)
3110 * stream->ops->wait_unlocked.
3117 ret = stream->ops->wait_unlocked(stream);
3122 ret = i915_perf_read_locked(stream, file,
3128 ret = i915_perf_read_locked(stream, file, buf, count, ppos);
3141 /* Maybe make ->pollin per-stream state if we support multiple
3144 stream->pollin = false;
3152 struct i915_perf_stream *stream =
3153 container_of(hrtimer, typeof(*stream), poll_check_timer);
3156 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
3157 if (oa_buffer_check(stream)) {
3158 stream->pollin = true;
3159 DRM_SPIN_WAKEUP_ONE(&stream->poll_wq,
3160 &stream->oa_buffer.ptr_lock);
3161 selnotify(&stream->poll_selq, POLLIN|POLLRDNORM, NOTE_SUBMIT);
3163 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
3175 struct i915_perf_stream *stream = fp->f_data;
3179 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
3180 if (stream->pollin)
3183 selrecord(curlwp, &stream->poll_selq);
3184 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
3192 * i915_perf_poll_locked - poll_wait() with a suitable wait queue for stream
3193 * @stream: An i915 perf stream
3194 * @file: An i915 perf stream file
3197 * For handling userspace polling on an i915 perf stream, this calls through to
3199 * will be woken for new stream data.
3206 static __poll_t i915_perf_poll_locked(struct i915_perf_stream *stream,
3212 stream->ops->poll_wait(stream, file, wait);
3220 if (stream->pollin)
3227 * i915_perf_poll - call poll_wait() with a suitable wait queue for stream
3228 * @file: An i915 perf stream file
3231 * For handling userspace polling on an i915 perf stream, this ensures
3232 * poll_wait() gets called with a wait queue that will be woken for new stream
3241 struct i915_perf_stream *stream = file->private_data;
3242 struct i915_perf *perf = stream->perf;
3246 ret = i915_perf_poll_locked(stream, file, wait);
3256 * @stream: A disabled i915 perf stream
3258 * [Re]enables the associated capture of data for this stream.
3260 * If a stream was previously enabled then there's currently no intention
3264 static void i915_perf_enable_locked(struct i915_perf_stream *stream)
3266 if (stream->enabled)
3269 /* Allow stream->ops->enable() to refer to this */
3270 stream->enabled = true;
3272 if (stream->ops->enable)
3273 stream->ops->enable(stream);
3275 if (stream->hold_preemption)
3276 intel_context_set_nopreempt(stream->pinned_ctx);
3281 * @stream: An enabled i915 perf stream
3283 * Disables the associated capture of data for this stream.
3285 * The intention is that disabling an re-enabling a stream will ideally be
3286 * cheaper than destroying and re-opening a stream with the same configuration,
3288 * must be retained between disabling and re-enabling a stream.
3290 * Note: while a stream is disabled it's considered an error for userspace
3291 * to attempt to read from the stream (-EIO).
3293 static void i915_perf_disable_locked(struct i915_perf_stream *stream)
3295 if (!stream->enabled)
3298 /* Allow stream->ops->disable() to refer to this */
3299 stream->enabled = false;
3301 if (stream->hold_preemption)
3302 intel_context_clear_nopreempt(stream->pinned_ctx);
3304 if (stream->ops->disable)
3305 stream->ops->disable(stream);
3308 static long i915_perf_config_locked(struct i915_perf_stream *stream,
3312 long ret = stream->oa_config->id;
3314 config = i915_perf_get_oa_config(stream->perf, metrics_set);
3318 if (config != stream->oa_config) {
3330 err = emit_oa_config(stream, config, oa_context(stream));
3332 config = xchg(&stream->oa_config, config);
3343 * i915_perf_ioctl - support ioctl() usage with i915 perf stream FDs
3344 * @stream: An i915 perf stream
3354 static long i915_perf_ioctl_locked(struct i915_perf_stream *stream,
3360 i915_perf_enable_locked(stream);
3363 i915_perf_disable_locked(stream);
3366 return i915_perf_config_locked(stream, arg);
3373 * i915_perf_ioctl - support ioctl() usage with i915 perf stream FDs
3374 * @file: An i915 perf stream file
3395 struct i915_perf_stream *stream = file->f_data;
3397 struct i915_perf_stream *stream = file->private_data;
3399 struct i915_perf *perf = stream->perf;
3403 ret = i915_perf_ioctl_locked(stream, cmd, arg);
3410 * i915_perf_destroy_locked - destroy an i915 perf stream
3411 * @stream: An i915 perf stream
3413 * Frees all resources associated with the given i915 perf @stream, disabling
3419 static void i915_perf_destroy_locked(struct i915_perf_stream *stream)
3421 if (stream->enabled)
3422 i915_perf_disable_locked(stream);
3424 if (stream->ops->destroy)
3425 stream->ops->destroy(stream);
3427 if (stream->ctx)
3428 i915_gem_context_put(stream->ctx);
3430 kfree(stream);
3434 * i915_perf_release - handles userspace close() of a stream file
3436 * @file: An i915 perf stream file
3438 * Cleans up any resources associated with an open i915 perf stream file.
3447 struct i915_perf_stream *stream = fp->f_data;
3448 struct i915_perf *perf = stream->perf;
3451 i915_perf_destroy_locked(stream);
3454 /* Release the reference the perf stream kept on the driver. */
3462 struct i915_perf_stream *stream = file->private_data;
3463 struct i915_perf *perf = stream->perf;
3466 i915_perf_destroy_locked(stream);
3469 /* Release the reference the perf stream kept on the driver. */
3525 * i915_perf_open_ioctl_locked - DRM ioctl() for userspace to open a stream FD
3533 * Implements further stream config validation and stream initialization on
3542 * config validation and stream initialization details will be handled by
3544 * will be relevant to all stream types / backends.
3555 struct i915_perf_stream *stream = NULL;
3567 DRM_DEBUG("Failed to look up context with ID %u for opening perf stream\n",
3590 * doesn't request global stream access (i.e. query based sampling
3615 DRM_DEBUG("Insufficient privileges to open i915 perf stream\n");
3620 stream = kzalloc(sizeof(*stream), GFP_KERNEL);
3621 if (!stream) {
3626 stream->perf = perf;
3627 stream->ctx = specific_ctx;
3629 ret = i915_oa_stream_init(stream, param, props);
3633 /* we avoid simply assigning stream->sample_flags = props->sample_flags
3637 if (WARN_ON(stream->sample_flags != props->sample_flags)) {
3665 stream_fd = anon_inode_getfd("[i915_perf]", &fops, stream, f_flags);
3673 i915_perf_enable_locked(stream);
3683 if (stream->ops->destroy)
3684 stream->ops->destroy(stream);
3686 kfree(stream);
3701 * read_properties_unlocked - validate + copy userspace stream open properties
3705 * @props: The stream configuration built up while validating properties
3709 * properties necessary for a particular kind of stream have been set.
3851 * i915_perf_open_ioctl - DRM ioctl() for userspace to open a stream FD
3856 * Validates the stream open parameters given by userspace including flags
3859 * Very little is assumed up front about the nature of the stream being
3861 * i915-perf stream is expected to be a suitable interface for other forms of
3871 * Return: A newly opened i915 Perf stream file descriptor or negative
3916 * used to open an i915-perf stream.
4400 * and their content will be freed when the stream using the config is closed.
4627 * stream instead of waiting until driver _fini which no one