Lines Matching refs:stream

431 struct i915_perf_regs *__oa_regs(struct i915_perf_stream *stream)  in __oa_regs()  argument
433 return &stream->engine->oa_group->regs; in __oa_regs()
436 static u32 gen12_oa_hw_tail_read(struct i915_perf_stream *stream) in gen12_oa_hw_tail_read() argument
438 struct intel_uncore *uncore = stream->uncore; in gen12_oa_hw_tail_read()
440 return intel_uncore_read(uncore, __oa_regs(stream)->oa_tail_ptr) & in gen12_oa_hw_tail_read()
444 static u32 gen8_oa_hw_tail_read(struct i915_perf_stream *stream) in gen8_oa_hw_tail_read() argument
446 struct intel_uncore *uncore = stream->uncore; in gen8_oa_hw_tail_read()
451 static u32 gen7_oa_hw_tail_read(struct i915_perf_stream *stream) in gen7_oa_hw_tail_read() argument
453 struct intel_uncore *uncore = stream->uncore; in gen7_oa_hw_tail_read()
462 static u64 oa_report_id(struct i915_perf_stream *stream, void *report) in oa_report_id() argument
464 return oa_report_header_64bit(stream) ? *(u64 *)report : *(u32 *)report; in oa_report_id()
467 static u64 oa_report_reason(struct i915_perf_stream *stream, void *report) in oa_report_reason() argument
469 return (oa_report_id(stream, report) >> OAREPORT_REASON_SHIFT) & in oa_report_reason()
470 (GRAPHICS_VER(stream->perf->i915) == 12 ? in oa_report_reason()
475 static void oa_report_id_clear(struct i915_perf_stream *stream, u32 *report) in oa_report_id_clear() argument
477 if (oa_report_header_64bit(stream)) in oa_report_id_clear()
483 static bool oa_report_ctx_invalid(struct i915_perf_stream *stream, void *report) in oa_report_ctx_invalid() argument
485 return !(oa_report_id(stream, report) & in oa_report_ctx_invalid()
486 stream->perf->gen8_valid_ctx_bit); in oa_report_ctx_invalid()
489 static u64 oa_timestamp(struct i915_perf_stream *stream, void *report) in oa_timestamp() argument
491 return oa_report_header_64bit(stream) ? in oa_timestamp()
496 static void oa_timestamp_clear(struct i915_perf_stream *stream, u32 *report) in oa_timestamp_clear() argument
498 if (oa_report_header_64bit(stream)) in oa_timestamp_clear()
504 static u32 oa_context_id(struct i915_perf_stream *stream, u32 *report) in oa_context_id() argument
506 u32 ctx_id = oa_report_header_64bit(stream) ? report[4] : report[2]; in oa_context_id()
508 return ctx_id & stream->specific_ctx_id_mask; in oa_context_id()
511 static void oa_context_id_squash(struct i915_perf_stream *stream, u32 *report) in oa_context_id_squash() argument
513 if (oa_report_header_64bit(stream)) in oa_context_id_squash()
542 static bool oa_buffer_check_unlocked(struct i915_perf_stream *stream) in oa_buffer_check_unlocked() argument
544 u32 gtt_offset = i915_ggtt_offset(stream->oa_buffer.vma); in oa_buffer_check_unlocked()
545 int report_size = stream->oa_buffer.format->size; in oa_buffer_check_unlocked()
555 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags); in oa_buffer_check_unlocked()
557 hw_tail = stream->perf->ops.oa_hw_tail_read(stream); in oa_buffer_check_unlocked()
564 partial_report_size = OA_TAKEN(hw_tail, stream->oa_buffer.tail); in oa_buffer_check_unlocked()
583 while (OA_TAKEN(tail, stream->oa_buffer.tail) >= report_size) { in oa_buffer_check_unlocked()
584 void *report = stream->oa_buffer.vaddr + tail; in oa_buffer_check_unlocked()
586 if (oa_report_id(stream, report) || in oa_buffer_check_unlocked()
587 oa_timestamp(stream, report)) in oa_buffer_check_unlocked()
594 __ratelimit(&stream->perf->tail_pointer_race)) in oa_buffer_check_unlocked()
595 drm_notice(&stream->uncore->i915->drm, in oa_buffer_check_unlocked()
597 stream->oa_buffer.head, tail, hw_tail); in oa_buffer_check_unlocked()
599 stream->oa_buffer.tail = tail; in oa_buffer_check_unlocked()
601 pollin = OA_TAKEN(stream->oa_buffer.tail, in oa_buffer_check_unlocked()
602 stream->oa_buffer.head) >= report_size; in oa_buffer_check_unlocked()
604 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags); in oa_buffer_check_unlocked()
624 static int append_oa_status(struct i915_perf_stream *stream, in append_oa_status() argument
660 static int append_oa_sample(struct i915_perf_stream *stream, in append_oa_sample() argument
666 int report_size = stream->oa_buffer.format->size; in append_oa_sample()
673 header.size = stream->sample_size; in append_oa_sample()
683 oa_buf_end = stream->oa_buffer.vaddr + OA_BUFFER_SIZE; in append_oa_sample()
691 if (copy_to_user(buf, stream->oa_buffer.vaddr, in append_oa_sample()
724 static int gen8_append_oa_reports(struct i915_perf_stream *stream, in gen8_append_oa_reports() argument
729 struct intel_uncore *uncore = stream->uncore; in gen8_append_oa_reports()
730 int report_size = stream->oa_buffer.format->size; in gen8_append_oa_reports()
731 u8 *oa_buf_base = stream->oa_buffer.vaddr; in gen8_append_oa_reports()
732 u32 gtt_offset = i915_ggtt_offset(stream->oa_buffer.vma); in gen8_append_oa_reports()
739 if (drm_WARN_ON(&uncore->i915->drm, !stream->enabled)) in gen8_append_oa_reports()
742 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags); in gen8_append_oa_reports()
744 head = stream->oa_buffer.head; in gen8_append_oa_reports()
745 tail = stream->oa_buffer.tail; in gen8_append_oa_reports()
747 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags); in gen8_append_oa_reports()
776 reason = oa_report_reason(stream, report); in gen8_append_oa_reports()
777 ctx_id = oa_context_id(stream, report32); in gen8_append_oa_reports()
819 if (oa_report_ctx_invalid(stream, report) && in gen8_append_oa_reports()
820 GRAPHICS_VER_FULL(stream->engine->i915) < IP_VER(12, 55)) { in gen8_append_oa_reports()
822 oa_context_id_squash(stream, report32); in gen8_append_oa_reports()
856 if (!stream->ctx || in gen8_append_oa_reports()
857 stream->specific_ctx_id == ctx_id || in gen8_append_oa_reports()
858 stream->oa_buffer.last_ctx_id == stream->specific_ctx_id || in gen8_append_oa_reports()
865 if (stream->ctx && in gen8_append_oa_reports()
866 stream->specific_ctx_id != ctx_id) { in gen8_append_oa_reports()
867 oa_context_id_squash(stream, report32); in gen8_append_oa_reports()
870 ret = append_oa_sample(stream, buf, count, offset, in gen8_append_oa_reports()
875 stream->oa_buffer.last_ctx_id = ctx_id; in gen8_append_oa_reports()
883 oa_report_id_clear(stream, report32); in gen8_append_oa_reports()
884 oa_timestamp_clear(stream, report32); in gen8_append_oa_reports()
886 u8 *oa_buf_end = stream->oa_buffer.vaddr + in gen8_append_oa_reports()
903 oaheadptr = GRAPHICS_VER(stream->perf->i915) == 12 ? in gen8_append_oa_reports()
904 __oa_regs(stream)->oa_head_ptr : in gen8_append_oa_reports()
907 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags); in gen8_append_oa_reports()
915 stream->oa_buffer.head = head; in gen8_append_oa_reports()
917 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags); in gen8_append_oa_reports()
943 static int gen8_oa_read(struct i915_perf_stream *stream, in gen8_oa_read() argument
948 struct intel_uncore *uncore = stream->uncore; in gen8_oa_read()
953 if (drm_WARN_ON(&uncore->i915->drm, !stream->oa_buffer.vaddr)) in gen8_oa_read()
956 oastatus_reg = GRAPHICS_VER(stream->perf->i915) == 12 ? in gen8_oa_read()
957 __oa_regs(stream)->oa_status : in gen8_oa_read()
977 ret = append_oa_status(stream, buf, count, offset, in gen8_oa_read()
982 drm_dbg(&stream->perf->i915->drm, in gen8_oa_read()
984 stream->period_exponent); in gen8_oa_read()
986 stream->perf->ops.oa_disable(stream); in gen8_oa_read()
987 stream->perf->ops.oa_enable(stream); in gen8_oa_read()
997 ret = append_oa_status(stream, buf, count, offset, in gen8_oa_read()
1010 return gen8_append_oa_reports(stream, buf, count, offset); in gen8_oa_read()
1034 static int gen7_append_oa_reports(struct i915_perf_stream *stream, in gen7_append_oa_reports() argument
1039 struct intel_uncore *uncore = stream->uncore; in gen7_append_oa_reports()
1040 int report_size = stream->oa_buffer.format->size; in gen7_append_oa_reports()
1041 u8 *oa_buf_base = stream->oa_buffer.vaddr; in gen7_append_oa_reports()
1042 u32 gtt_offset = i915_ggtt_offset(stream->oa_buffer.vma); in gen7_append_oa_reports()
1049 if (drm_WARN_ON(&uncore->i915->drm, !stream->enabled)) in gen7_append_oa_reports()
1052 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags); in gen7_append_oa_reports()
1054 head = stream->oa_buffer.head; in gen7_append_oa_reports()
1055 tail = stream->oa_buffer.tail; in gen7_append_oa_reports()
1057 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags); in gen7_append_oa_reports()
1101 if (__ratelimit(&stream->perf->spurious_report_rs)) in gen7_append_oa_reports()
1107 ret = append_oa_sample(stream, buf, count, offset, report); in gen7_append_oa_reports()
1119 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags); in gen7_append_oa_reports()
1124 stream->oa_buffer.head = head; in gen7_append_oa_reports()
1126 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags); in gen7_append_oa_reports()
1148 static int gen7_oa_read(struct i915_perf_stream *stream, in gen7_oa_read() argument
1153 struct intel_uncore *uncore = stream->uncore; in gen7_oa_read()
1157 if (drm_WARN_ON(&uncore->i915->drm, !stream->oa_buffer.vaddr)) in gen7_oa_read()
1167 oastatus1 &= ~stream->perf->gen7_latched_oastatus1; in gen7_oa_read()
1190 ret = append_oa_status(stream, buf, count, offset, in gen7_oa_read()
1195 drm_dbg(&stream->perf->i915->drm, in gen7_oa_read()
1197 stream->period_exponent); in gen7_oa_read()
1199 stream->perf->ops.oa_disable(stream); in gen7_oa_read()
1200 stream->perf->ops.oa_enable(stream); in gen7_oa_read()
1206 ret = append_oa_status(stream, buf, count, offset, in gen7_oa_read()
1210 stream->perf->gen7_latched_oastatus1 |= in gen7_oa_read()
1214 return gen7_append_oa_reports(stream, buf, count, offset); in gen7_oa_read()
1231 static int i915_oa_wait_unlocked(struct i915_perf_stream *stream) in i915_oa_wait_unlocked() argument
1234 if (!stream->periodic) in i915_oa_wait_unlocked()
1237 return wait_event_interruptible(stream->poll_wq, in i915_oa_wait_unlocked()
1238 oa_buffer_check_unlocked(stream)); in i915_oa_wait_unlocked()
1251 static void i915_oa_poll_wait(struct i915_perf_stream *stream, in i915_oa_poll_wait() argument
1255 poll_wait(file, &stream->poll_wq, wait); in i915_oa_poll_wait()
1270 static int i915_oa_read(struct i915_perf_stream *stream, in i915_oa_read() argument
1275 return stream->perf->ops.read(stream, buf, count, offset); in i915_oa_read()
1278 static struct intel_context *oa_pin_context(struct i915_perf_stream *stream) in oa_pin_context() argument
1281 struct i915_gem_context *ctx = stream->ctx; in oa_pin_context()
1287 if (ce->engine != stream->engine) /* first match! */ in oa_pin_context()
1315 stream->pinned_ctx = ce; in oa_pin_context()
1316 return stream->pinned_ctx; in oa_pin_context()
1410 static int gen12_get_render_context_id(struct i915_perf_stream *stream) in gen12_get_render_context_id() argument
1415 if (intel_engine_uses_guc(stream->engine)) { in gen12_get_render_context_id()
1416 ret = gen12_guc_sw_ctx_id(stream->pinned_ctx, &ctx_id); in gen12_get_render_context_id()
1422 } else if (GRAPHICS_VER_FULL(stream->engine->i915) >= IP_VER(12, 55)) { in gen12_get_render_context_id()
1435 stream->specific_ctx_id = ctx_id & mask; in gen12_get_render_context_id()
1436 stream->specific_ctx_id_mask = mask; in gen12_get_render_context_id()
1522 static int oa_get_render_ctx_id(struct i915_perf_stream *stream) in oa_get_render_ctx_id() argument
1527 ce = oa_pin_context(stream); in oa_get_render_ctx_id()
1531 if (engine_supports_mi_query(stream->engine) && in oa_get_render_ctx_id()
1532 HAS_LOGICAL_RING_CONTEXTS(stream->perf->i915)) { in oa_get_render_ctx_id()
1540 drm_err(&stream->perf->i915->drm, in oa_get_render_ctx_id()
1542 stream->engine->name); in oa_get_render_ctx_id()
1553 stream->specific_ctx_id = i915_ggtt_offset(ce->state); in oa_get_render_ctx_id()
1554 stream->specific_ctx_id_mask = 0; in oa_get_render_ctx_id()
1571 stream->specific_ctx_id = ce->lrc.lrca >> 12; in oa_get_render_ctx_id()
1577 stream->specific_ctx_id_mask = in oa_get_render_ctx_id()
1580 stream->specific_ctx_id_mask = in oa_get_render_ctx_id()
1582 stream->specific_ctx_id = stream->specific_ctx_id_mask; in oa_get_render_ctx_id()
1588 ret = gen12_get_render_context_id(stream); in oa_get_render_ctx_id()
1595 ce->tag = stream->specific_ctx_id; in oa_get_render_ctx_id()
1597 drm_dbg(&stream->perf->i915->drm, in oa_get_render_ctx_id()
1599 stream->specific_ctx_id, in oa_get_render_ctx_id()
1600 stream->specific_ctx_id_mask); in oa_get_render_ctx_id()
1612 static void oa_put_render_ctx_id(struct i915_perf_stream *stream) in oa_put_render_ctx_id() argument
1616 ce = fetch_and_zero(&stream->pinned_ctx); in oa_put_render_ctx_id()
1622 stream->specific_ctx_id = INVALID_CTX_ID; in oa_put_render_ctx_id()
1623 stream->specific_ctx_id_mask = 0; in oa_put_render_ctx_id()
1627 free_oa_buffer(struct i915_perf_stream *stream) in free_oa_buffer() argument
1629 i915_vma_unpin_and_release(&stream->oa_buffer.vma, in free_oa_buffer()
1632 stream->oa_buffer.vaddr = NULL; in free_oa_buffer()
1636 free_oa_configs(struct i915_perf_stream *stream) in free_oa_configs() argument
1640 i915_oa_config_put(stream->oa_config); in free_oa_configs()
1641 llist_for_each_entry_safe(oa_bo, tmp, stream->oa_config_bos.first, node) in free_oa_configs()
1646 free_noa_wait(struct i915_perf_stream *stream) in free_noa_wait() argument
1648 i915_vma_unpin_and_release(&stream->noa_wait, 0); in free_noa_wait()
1661 static void i915_oa_stream_destroy(struct i915_perf_stream *stream) in i915_oa_stream_destroy() argument
1663 struct i915_perf *perf = stream->perf; in i915_oa_stream_destroy()
1664 struct intel_gt *gt = stream->engine->gt; in i915_oa_stream_destroy()
1665 struct i915_perf_group *g = stream->engine->oa_group; in i915_oa_stream_destroy()
1667 if (WARN_ON(stream != g->exclusive_stream)) in i915_oa_stream_destroy()
1677 perf->ops.disable_metric_set(stream); in i915_oa_stream_destroy()
1679 free_oa_buffer(stream); in i915_oa_stream_destroy()
1681 intel_uncore_forcewake_put(stream->uncore, FORCEWAKE_ALL); in i915_oa_stream_destroy()
1682 intel_engine_pm_put(stream->engine); in i915_oa_stream_destroy()
1684 if (stream->ctx) in i915_oa_stream_destroy()
1685 oa_put_render_ctx_id(stream); in i915_oa_stream_destroy()
1687 free_oa_configs(stream); in i915_oa_stream_destroy()
1688 free_noa_wait(stream); in i915_oa_stream_destroy()
1696 static void gen7_init_oa_buffer(struct i915_perf_stream *stream) in gen7_init_oa_buffer() argument
1698 struct intel_uncore *uncore = stream->uncore; in gen7_init_oa_buffer()
1699 u32 gtt_offset = i915_ggtt_offset(stream->oa_buffer.vma); in gen7_init_oa_buffer()
1702 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags); in gen7_init_oa_buffer()
1709 stream->oa_buffer.head = 0; in gen7_init_oa_buffer()
1717 stream->oa_buffer.tail = 0; in gen7_init_oa_buffer()
1719 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags); in gen7_init_oa_buffer()
1725 stream->perf->gen7_latched_oastatus1 = 0; in gen7_init_oa_buffer()
1738 memset(stream->oa_buffer.vaddr, 0, OA_BUFFER_SIZE); in gen7_init_oa_buffer()
1741 static void gen8_init_oa_buffer(struct i915_perf_stream *stream) in gen8_init_oa_buffer() argument
1743 struct intel_uncore *uncore = stream->uncore; in gen8_init_oa_buffer()
1744 u32 gtt_offset = i915_ggtt_offset(stream->oa_buffer.vma); in gen8_init_oa_buffer()
1747 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags); in gen8_init_oa_buffer()
1751 stream->oa_buffer.head = 0; in gen8_init_oa_buffer()
1768 stream->oa_buffer.tail = 0; in gen8_init_oa_buffer()
1775 stream->oa_buffer.last_ctx_id = INVALID_CTX_ID; in gen8_init_oa_buffer()
1777 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags); in gen8_init_oa_buffer()
1791 memset(stream->oa_buffer.vaddr, 0, OA_BUFFER_SIZE); in gen8_init_oa_buffer()
1794 static void gen12_init_oa_buffer(struct i915_perf_stream *stream) in gen12_init_oa_buffer() argument
1796 struct intel_uncore *uncore = stream->uncore; in gen12_init_oa_buffer()
1797 u32 gtt_offset = i915_ggtt_offset(stream->oa_buffer.vma); in gen12_init_oa_buffer()
1800 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags); in gen12_init_oa_buffer()
1802 intel_uncore_write(uncore, __oa_regs(stream)->oa_status, 0); in gen12_init_oa_buffer()
1803 intel_uncore_write(uncore, __oa_regs(stream)->oa_head_ptr, in gen12_init_oa_buffer()
1805 stream->oa_buffer.head = 0; in gen12_init_oa_buffer()
1815 intel_uncore_write(uncore, __oa_regs(stream)->oa_buffer, gtt_offset | in gen12_init_oa_buffer()
1817 intel_uncore_write(uncore, __oa_regs(stream)->oa_tail_ptr, in gen12_init_oa_buffer()
1821 stream->oa_buffer.tail = 0; in gen12_init_oa_buffer()
1828 stream->oa_buffer.last_ctx_id = INVALID_CTX_ID; in gen12_init_oa_buffer()
1830 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags); in gen12_init_oa_buffer()
1844 memset(stream->oa_buffer.vaddr, 0, in gen12_init_oa_buffer()
1845 stream->oa_buffer.vma->size); in gen12_init_oa_buffer()
1848 static int alloc_oa_buffer(struct i915_perf_stream *stream) in alloc_oa_buffer() argument
1850 struct drm_i915_private *i915 = stream->perf->i915; in alloc_oa_buffer()
1851 struct intel_gt *gt = stream->engine->gt; in alloc_oa_buffer()
1856 if (drm_WARN_ON(&i915->drm, stream->oa_buffer.vma)) in alloc_oa_buffer()
1862 bo = i915_gem_object_create_shmem(stream->perf->i915, OA_BUFFER_SIZE); in alloc_oa_buffer()
1887 stream->oa_buffer.vma = vma; in alloc_oa_buffer()
1889 stream->oa_buffer.vaddr = in alloc_oa_buffer()
1891 if (IS_ERR(stream->oa_buffer.vaddr)) { in alloc_oa_buffer()
1892 ret = PTR_ERR(stream->oa_buffer.vaddr); in alloc_oa_buffer()
1904 stream->oa_buffer.vaddr = NULL; in alloc_oa_buffer()
1905 stream->oa_buffer.vma = NULL; in alloc_oa_buffer()
1910 static u32 *save_restore_register(struct i915_perf_stream *stream, u32 *cs, in save_restore_register() argument
1919 if (GRAPHICS_VER(stream->perf->i915) >= 8) in save_restore_register()
1925 *cs++ = i915_ggtt_offset(stream->noa_wait) + offset + 4 * d; in save_restore_register()
1932 static int alloc_noa_wait(struct i915_perf_stream *stream) in alloc_noa_wait() argument
1934 struct drm_i915_private *i915 = stream->perf->i915; in alloc_noa_wait()
1935 struct intel_gt *gt = stream->engine->gt; in alloc_noa_wait()
1939 intel_gt_ns_to_clock_interval(to_gt(stream->perf->i915), in alloc_noa_wait()
1940 atomic64_read(&stream->perf->noa_programming_delay)); in alloc_noa_wait()
1941 const u32 base = stream->engine->mmio_base; in alloc_noa_wait()
1998 stream->noa_wait = vma; in alloc_noa_wait()
2006 stream, cs, true /* save */, CS_GPR(i), in alloc_noa_wait()
2009 stream, cs, true /* save */, mi_predicate_result, in alloc_noa_wait()
2125 stream, cs, false /* restore */, CS_GPR(i), in alloc_noa_wait()
2128 stream, cs, false /* restore */, mi_predicate_result, in alloc_noa_wait()
2189 alloc_oa_config_buffer(struct i915_perf_stream *stream, in alloc_oa_config_buffer() argument
2209 obj = i915_gem_object_create_shmem(stream->perf->i915, config_length); in alloc_oa_config_buffer()
2238 *cs++ = (GRAPHICS_VER(stream->perf->i915) < 8 ? in alloc_oa_config_buffer()
2241 *cs++ = i915_ggtt_offset(stream->noa_wait); in alloc_oa_config_buffer()
2248 &stream->engine->gt->ggtt->vm, in alloc_oa_config_buffer()
2256 llist_add(&oa_bo->node, &stream->oa_config_bos); in alloc_oa_config_buffer()
2277 get_oa_vma(struct i915_perf_stream *stream, struct i915_oa_config *oa_config) in get_oa_vma() argument
2285 llist_for_each_entry(oa_bo, stream->oa_config_bos.first, node) { in get_oa_vma()
2293 oa_bo = alloc_oa_config_buffer(stream, oa_config); in get_oa_vma()
2302 emit_oa_config(struct i915_perf_stream *stream, in emit_oa_config() argument
2312 vma = get_oa_vma(stream, oa_config); in emit_oa_config()
2372 static struct intel_context *oa_context(struct i915_perf_stream *stream) in oa_context() argument
2374 return stream->pinned_ctx ?: stream->engine->kernel_context; in oa_context()
2378 hsw_enable_metric_set(struct i915_perf_stream *stream, in hsw_enable_metric_set() argument
2381 struct intel_uncore *uncore = stream->uncore; in hsw_enable_metric_set()
2398 return emit_oa_config(stream, in hsw_enable_metric_set()
2399 stream->oa_config, oa_context(stream), in hsw_enable_metric_set()
2403 static void hsw_disable_metric_set(struct i915_perf_stream *stream) in hsw_disable_metric_set() argument
2405 struct intel_uncore *uncore = stream->uncore; in hsw_disable_metric_set()
2445 const struct i915_perf_stream *stream) in gen8_update_reg_state_unlocked() argument
2447 u32 ctx_oactxctrl = stream->perf->ctx_oactxctrl_offset; in gen8_update_reg_state_unlocked()
2448 u32 ctx_flexeu0 = stream->perf->ctx_flexeu0_offset; in gen8_update_reg_state_unlocked()
2463 (stream->period_exponent << GEN8_OA_TIMER_PERIOD_SHIFT) | in gen8_update_reg_state_unlocked()
2464 (stream->periodic ? GEN8_OA_TIMER_ENABLE : 0) | in gen8_update_reg_state_unlocked()
2469 oa_config_flex_reg(stream->oa_config, flex_regs[i]); in gen8_update_reg_state_unlocked()
2576 static int gen8_configure_context(struct i915_perf_stream *stream, in gen8_configure_context() argument
2606 static int gen12_configure_oar_context(struct i915_perf_stream *stream, in gen12_configure_oar_context() argument
2610 struct intel_context *ce = stream->pinned_ctx; in gen12_configure_oar_context()
2611 u32 format = stream->oa_buffer.format->format; in gen12_configure_oar_context()
2612 u32 offset = stream->perf->ctx_oactxctrl_offset; in gen12_configure_oar_context()
2682 oa_configure_all_contexts(struct i915_perf_stream *stream, in oa_configure_all_contexts() argument
2687 struct drm_i915_private *i915 = stream->perf->i915; in oa_configure_all_contexts()
2689 struct intel_gt *gt = stream->engine->gt; in oa_configure_all_contexts()
2718 err = gen8_configure_context(stream, ctx, regs, num_regs); in oa_configure_all_contexts()
2752 lrc_configure_all_contexts(struct i915_perf_stream *stream, in lrc_configure_all_contexts() argument
2756 u32 ctx_oactxctrl = stream->perf->ctx_oactxctrl_offset; in lrc_configure_all_contexts()
2758 const u32 ctx_flexeu0 = stream->perf->ctx_flexeu0_offset; in lrc_configure_all_contexts()
2781 (stream->period_exponent << GEN8_OA_TIMER_PERIOD_SHIFT) | in lrc_configure_all_contexts()
2782 (stream->periodic ? GEN8_OA_TIMER_ENABLE : 0) | in lrc_configure_all_contexts()
2788 return oa_configure_all_contexts(stream, in lrc_configure_all_contexts()
2794 gen8_enable_metric_set(struct i915_perf_stream *stream, in gen8_enable_metric_set() argument
2797 struct intel_uncore *uncore = stream->uncore; in gen8_enable_metric_set()
2798 struct i915_oa_config *oa_config = stream->oa_config; in gen8_enable_metric_set()
2824 if (IS_GRAPHICS_VER(stream->perf->i915, 9, 11)) { in gen8_enable_metric_set()
2835 ret = lrc_configure_all_contexts(stream, oa_config, active); in gen8_enable_metric_set()
2839 return emit_oa_config(stream, in gen8_enable_metric_set()
2840 stream->oa_config, oa_context(stream), in gen8_enable_metric_set()
2844 static u32 oag_report_ctx_switches(const struct i915_perf_stream *stream) in oag_report_ctx_switches() argument
2847 (stream->sample_flags & SAMPLE_OA_REPORT) ? in oag_report_ctx_switches()
2852 gen12_enable_metric_set(struct i915_perf_stream *stream, in gen12_enable_metric_set() argument
2855 struct drm_i915_private *i915 = stream->perf->i915; in gen12_enable_metric_set()
2856 struct intel_uncore *uncore = stream->uncore; in gen12_enable_metric_set()
2857 bool periodic = stream->periodic; in gen12_enable_metric_set()
2858 u32 period_exponent = stream->period_exponent; in gen12_enable_metric_set()
2874 intel_uncore_write(uncore, __oa_regs(stream)->oa_debug, in gen12_enable_metric_set()
2882 oag_report_ctx_switches(stream)); in gen12_enable_metric_set()
2884 intel_uncore_write(uncore, __oa_regs(stream)->oa_ctx_ctrl, periodic ? in gen12_enable_metric_set()
2905 if (stream->ctx) { in gen12_enable_metric_set()
2906 ret = gen12_configure_oar_context(stream, active); in gen12_enable_metric_set()
2911 return emit_oa_config(stream, in gen12_enable_metric_set()
2912 stream->oa_config, oa_context(stream), in gen12_enable_metric_set()
2916 static void gen8_disable_metric_set(struct i915_perf_stream *stream) in gen8_disable_metric_set() argument
2918 struct intel_uncore *uncore = stream->uncore; in gen8_disable_metric_set()
2921 lrc_configure_all_contexts(stream, NULL, NULL); in gen8_disable_metric_set()
2926 static void gen11_disable_metric_set(struct i915_perf_stream *stream) in gen11_disable_metric_set() argument
2928 struct intel_uncore *uncore = stream->uncore; in gen11_disable_metric_set()
2931 lrc_configure_all_contexts(stream, NULL, NULL); in gen11_disable_metric_set()
2937 static void gen12_disable_metric_set(struct i915_perf_stream *stream) in gen12_disable_metric_set() argument
2939 struct intel_uncore *uncore = stream->uncore; in gen12_disable_metric_set()
2940 struct drm_i915_private *i915 = stream->perf->i915; in gen12_disable_metric_set()
2954 if (stream->ctx) in gen12_disable_metric_set()
2955 gen12_configure_oar_context(stream, NULL); in gen12_disable_metric_set()
2967 static void gen7_oa_enable(struct i915_perf_stream *stream) in gen7_oa_enable() argument
2969 struct intel_uncore *uncore = stream->uncore; in gen7_oa_enable()
2970 struct i915_gem_context *ctx = stream->ctx; in gen7_oa_enable()
2971 u32 ctx_id = stream->specific_ctx_id; in gen7_oa_enable()
2972 bool periodic = stream->periodic; in gen7_oa_enable()
2973 u32 period_exponent = stream->period_exponent; in gen7_oa_enable()
2974 u32 report_format = stream->oa_buffer.format->format; in gen7_oa_enable()
2985 gen7_init_oa_buffer(stream); in gen7_oa_enable()
2997 static void gen8_oa_enable(struct i915_perf_stream *stream) in gen8_oa_enable() argument
2999 struct intel_uncore *uncore = stream->uncore; in gen8_oa_enable()
3000 u32 report_format = stream->oa_buffer.format->format; in gen8_oa_enable()
3011 gen8_init_oa_buffer(stream); in gen8_oa_enable()
3023 static void gen12_oa_enable(struct i915_perf_stream *stream) in gen12_oa_enable() argument
3032 if (!(stream->sample_flags & SAMPLE_OA_REPORT)) in gen12_oa_enable()
3035 gen12_init_oa_buffer(stream); in gen12_oa_enable()
3037 regs = __oa_regs(stream); in gen12_oa_enable()
3038 val = (stream->oa_buffer.format->format << regs->oa_ctrl_counter_format_shift) | in gen12_oa_enable()
3041 intel_uncore_write(stream->uncore, regs->oa_ctrl, val); in gen12_oa_enable()
3053 static void i915_oa_stream_enable(struct i915_perf_stream *stream) in i915_oa_stream_enable() argument
3055 stream->pollin = false; in i915_oa_stream_enable()
3057 stream->perf->ops.oa_enable(stream); in i915_oa_stream_enable()
3059 if (stream->sample_flags & SAMPLE_OA_REPORT) in i915_oa_stream_enable()
3060 hrtimer_start(&stream->poll_check_timer, in i915_oa_stream_enable()
3061 ns_to_ktime(stream->poll_oa_period), in i915_oa_stream_enable()
3065 static void gen7_oa_disable(struct i915_perf_stream *stream) in gen7_oa_disable() argument
3067 struct intel_uncore *uncore = stream->uncore; in gen7_oa_disable()
3073 drm_err(&stream->perf->i915->drm, in gen7_oa_disable()
3077 static void gen8_oa_disable(struct i915_perf_stream *stream) in gen8_oa_disable() argument
3079 struct intel_uncore *uncore = stream->uncore; in gen8_oa_disable()
3085 drm_err(&stream->perf->i915->drm, in gen8_oa_disable()
3089 static void gen12_oa_disable(struct i915_perf_stream *stream) in gen12_oa_disable() argument
3091 struct intel_uncore *uncore = stream->uncore; in gen12_oa_disable()
3093 intel_uncore_write(uncore, __oa_regs(stream)->oa_ctrl, 0); in gen12_oa_disable()
3095 __oa_regs(stream)->oa_ctrl, in gen12_oa_disable()
3098 drm_err(&stream->perf->i915->drm, in gen12_oa_disable()
3106 drm_err(&stream->perf->i915->drm, in gen12_oa_disable()
3118 static void i915_oa_stream_disable(struct i915_perf_stream *stream) in i915_oa_stream_disable() argument
3120 stream->perf->ops.oa_disable(stream); in i915_oa_stream_disable()
3122 if (stream->sample_flags & SAMPLE_OA_REPORT) in i915_oa_stream_disable()
3123 hrtimer_cancel(&stream->poll_check_timer); in i915_oa_stream_disable()
3135 static int i915_perf_stream_enable_sync(struct i915_perf_stream *stream) in i915_perf_stream_enable_sync() argument
3144 err = stream->perf->ops.enable_metric_set(stream, active); in i915_perf_stream_enable_sync()
3228 static int i915_oa_stream_init(struct i915_perf_stream *stream, in i915_oa_stream_init() argument
3232 struct drm_i915_private *i915 = stream->perf->i915; in i915_oa_stream_init()
3233 struct i915_perf *perf = stream->perf; in i915_oa_stream_init()
3238 drm_dbg(&stream->perf->i915->drm, in i915_oa_stream_init()
3250 drm_dbg(&stream->perf->i915->drm, in i915_oa_stream_init()
3256 (GRAPHICS_VER(perf->i915) < 12 || !stream->ctx)) { in i915_oa_stream_init()
3257 drm_dbg(&stream->perf->i915->drm, in i915_oa_stream_init()
3263 drm_dbg(&stream->perf->i915->drm, in i915_oa_stream_init()
3274 drm_dbg(&stream->perf->i915->drm, in i915_oa_stream_init()
3280 drm_dbg(&stream->perf->i915->drm, in i915_oa_stream_init()
3285 stream->engine = props->engine; in i915_oa_stream_init()
3286 stream->uncore = stream->engine->gt->uncore; in i915_oa_stream_init()
3288 stream->sample_size = sizeof(struct drm_i915_perf_record_header); in i915_oa_stream_init()
3290 stream->oa_buffer.format = &perf->oa_formats[props->oa_format]; in i915_oa_stream_init()
3291 if (drm_WARN_ON(&i915->drm, stream->oa_buffer.format->size == 0)) in i915_oa_stream_init()
3294 stream->sample_flags = props->sample_flags; in i915_oa_stream_init()
3295 stream->sample_size += stream->oa_buffer.format->size; in i915_oa_stream_init()
3297 stream->hold_preemption = props->hold_preemption; in i915_oa_stream_init()
3299 stream->periodic = props->oa_periodic; in i915_oa_stream_init()
3300 if (stream->periodic) in i915_oa_stream_init()
3301 stream->period_exponent = props->oa_period_exponent; in i915_oa_stream_init()
3303 if (stream->ctx) { in i915_oa_stream_init()
3304 ret = oa_get_render_ctx_id(stream); in i915_oa_stream_init()
3306 drm_dbg(&stream->perf->i915->drm, in i915_oa_stream_init()
3312 ret = alloc_noa_wait(stream); in i915_oa_stream_init()
3314 drm_dbg(&stream->perf->i915->drm, in i915_oa_stream_init()
3319 stream->oa_config = i915_perf_get_oa_config(perf, props->metrics_set); in i915_oa_stream_init()
3320 if (!stream->oa_config) { in i915_oa_stream_init()
3321 drm_dbg(&stream->perf->i915->drm, in i915_oa_stream_init()
3339 intel_engine_pm_get(stream->engine); in i915_oa_stream_init()
3340 intel_uncore_forcewake_get(stream->uncore, FORCEWAKE_ALL); in i915_oa_stream_init()
3342 ret = alloc_oa_buffer(stream); in i915_oa_stream_init()
3346 stream->ops = &i915_oa_stream_ops; in i915_oa_stream_init()
3348 stream->engine->gt->perf.sseu = props->sseu; in i915_oa_stream_init()
3349 WRITE_ONCE(g->exclusive_stream, stream); in i915_oa_stream_init()
3351 ret = i915_perf_stream_enable_sync(stream); in i915_oa_stream_init()
3353 drm_dbg(&stream->perf->i915->drm, in i915_oa_stream_init()
3358 drm_dbg(&stream->perf->i915->drm, in i915_oa_stream_init()
3360 stream->oa_config->uuid); in i915_oa_stream_init()
3362 hrtimer_init(&stream->poll_check_timer, in i915_oa_stream_init()
3364 stream->poll_check_timer.function = oa_poll_check_timer_cb; in i915_oa_stream_init()
3365 init_waitqueue_head(&stream->poll_wq); in i915_oa_stream_init()
3366 spin_lock_init(&stream->oa_buffer.ptr_lock); in i915_oa_stream_init()
3367 mutex_init(&stream->lock); in i915_oa_stream_init()
3373 perf->ops.disable_metric_set(stream); in i915_oa_stream_init()
3375 free_oa_buffer(stream); in i915_oa_stream_init()
3378 intel_uncore_forcewake_put(stream->uncore, FORCEWAKE_ALL); in i915_oa_stream_init()
3379 intel_engine_pm_put(stream->engine); in i915_oa_stream_init()
3381 free_oa_configs(stream); in i915_oa_stream_init()
3384 free_noa_wait(stream); in i915_oa_stream_init()
3387 if (stream->ctx) in i915_oa_stream_init()
3388 oa_put_render_ctx_id(stream); in i915_oa_stream_init()
3396 struct i915_perf_stream *stream; in i915_oa_init_reg_state() local
3402 stream = READ_ONCE(engine->oa_group->exclusive_stream); in i915_oa_init_reg_state()
3403 if (stream && GRAPHICS_VER(stream->perf->i915) < 12) in i915_oa_init_reg_state()
3404 gen8_update_reg_state_unlocked(ce, stream); in i915_oa_init_reg_state()
3430 struct i915_perf_stream *stream = file->private_data; in i915_perf_read() local
3438 if (!stream->enabled || !(stream->sample_flags & SAMPLE_OA_REPORT)) in i915_perf_read()
3450 ret = stream->ops->wait_unlocked(stream); in i915_perf_read()
3454 mutex_lock(&stream->lock); in i915_perf_read()
3455 ret = stream->ops->read(stream, buf, count, &offset); in i915_perf_read()
3456 mutex_unlock(&stream->lock); in i915_perf_read()
3459 mutex_lock(&stream->lock); in i915_perf_read()
3460 ret = stream->ops->read(stream, buf, count, &offset); in i915_perf_read()
3461 mutex_unlock(&stream->lock); in i915_perf_read()
3476 stream->pollin = false; in i915_perf_read()
3484 struct i915_perf_stream *stream = in oa_poll_check_timer_cb() local
3485 container_of(hrtimer, typeof(*stream), poll_check_timer); in oa_poll_check_timer_cb()
3487 if (oa_buffer_check_unlocked(stream)) { in oa_poll_check_timer_cb()
3488 stream->pollin = true; in oa_poll_check_timer_cb()
3489 wake_up(&stream->poll_wq); in oa_poll_check_timer_cb()
3493 ns_to_ktime(stream->poll_oa_period)); in oa_poll_check_timer_cb()
3510 static __poll_t i915_perf_poll_locked(struct i915_perf_stream *stream, in i915_perf_poll_locked() argument
3516 stream->ops->poll_wait(stream, file, wait); in i915_perf_poll_locked()
3524 if (stream->pollin) in i915_perf_poll_locked()
3545 struct i915_perf_stream *stream = file->private_data; in i915_perf_poll() local
3548 mutex_lock(&stream->lock); in i915_perf_poll()
3549 ret = i915_perf_poll_locked(stream, file, wait); in i915_perf_poll()
3550 mutex_unlock(&stream->lock); in i915_perf_poll()
3565 static void i915_perf_enable_locked(struct i915_perf_stream *stream) in i915_perf_enable_locked() argument
3567 if (stream->enabled) in i915_perf_enable_locked()
3571 stream->enabled = true; in i915_perf_enable_locked()
3573 if (stream->ops->enable) in i915_perf_enable_locked()
3574 stream->ops->enable(stream); in i915_perf_enable_locked()
3576 if (stream->hold_preemption) in i915_perf_enable_locked()
3577 intel_context_set_nopreempt(stream->pinned_ctx); in i915_perf_enable_locked()
3594 static void i915_perf_disable_locked(struct i915_perf_stream *stream) in i915_perf_disable_locked() argument
3596 if (!stream->enabled) in i915_perf_disable_locked()
3600 stream->enabled = false; in i915_perf_disable_locked()
3602 if (stream->hold_preemption) in i915_perf_disable_locked()
3603 intel_context_clear_nopreempt(stream->pinned_ctx); in i915_perf_disable_locked()
3605 if (stream->ops->disable) in i915_perf_disable_locked()
3606 stream->ops->disable(stream); in i915_perf_disable_locked()
3609 static long i915_perf_config_locked(struct i915_perf_stream *stream, in i915_perf_config_locked() argument
3613 long ret = stream->oa_config->id; in i915_perf_config_locked()
3615 config = i915_perf_get_oa_config(stream->perf, metrics_set); in i915_perf_config_locked()
3619 if (config != stream->oa_config) { in i915_perf_config_locked()
3631 err = emit_oa_config(stream, config, oa_context(stream), NULL); in i915_perf_config_locked()
3633 config = xchg(&stream->oa_config, config); in i915_perf_config_locked()
3652 static long i915_perf_ioctl_locked(struct i915_perf_stream *stream, in i915_perf_ioctl_locked() argument
3658 i915_perf_enable_locked(stream); in i915_perf_ioctl_locked()
3661 i915_perf_disable_locked(stream); in i915_perf_ioctl_locked()
3664 return i915_perf_config_locked(stream, arg); in i915_perf_ioctl_locked()
3685 struct i915_perf_stream *stream = file->private_data; in i915_perf_ioctl() local
3688 mutex_lock(&stream->lock); in i915_perf_ioctl()
3689 ret = i915_perf_ioctl_locked(stream, cmd, arg); in i915_perf_ioctl()
3690 mutex_unlock(&stream->lock); in i915_perf_ioctl()
3705 static void i915_perf_destroy_locked(struct i915_perf_stream *stream) in i915_perf_destroy_locked() argument
3707 if (stream->enabled) in i915_perf_destroy_locked()
3708 i915_perf_disable_locked(stream); in i915_perf_destroy_locked()
3710 if (stream->ops->destroy) in i915_perf_destroy_locked()
3711 stream->ops->destroy(stream); in i915_perf_destroy_locked()
3713 if (stream->ctx) in i915_perf_destroy_locked()
3714 i915_gem_context_put(stream->ctx); in i915_perf_destroy_locked()
3716 kfree(stream); in i915_perf_destroy_locked()
3732 struct i915_perf_stream *stream = file->private_data; in i915_perf_release() local
3733 struct i915_perf *perf = stream->perf; in i915_perf_release()
3734 struct intel_gt *gt = stream->engine->gt; in i915_perf_release()
3742 i915_perf_destroy_locked(stream); in i915_perf_release()
3796 struct i915_perf_stream *stream = NULL; in i915_perf_open_ioctl_locked() local
3872 stream = kzalloc(sizeof(*stream), GFP_KERNEL); in i915_perf_open_ioctl_locked()
3873 if (!stream) { in i915_perf_open_ioctl_locked()
3878 stream->perf = perf; in i915_perf_open_ioctl_locked()
3879 stream->ctx = specific_ctx; in i915_perf_open_ioctl_locked()
3880 stream->poll_oa_period = props->poll_oa_period; in i915_perf_open_ioctl_locked()
3882 ret = i915_oa_stream_init(stream, param, props); in i915_perf_open_ioctl_locked()
3890 if (WARN_ON(stream->sample_flags != props->sample_flags)) { in i915_perf_open_ioctl_locked()
3900 stream_fd = anon_inode_getfd("[i915_perf]", &fops, stream, f_flags); in i915_perf_open_ioctl_locked()
3907 i915_perf_enable_locked(stream); in i915_perf_open_ioctl_locked()
3917 if (stream->ops->destroy) in i915_perf_open_ioctl_locked()
3918 stream->ops->destroy(stream); in i915_perf_open_ioctl_locked()
3920 kfree(stream); in i915_perf_open_ioctl_locked()