Lines Matching full:stream
67 /* Lock to protect stream */
69 /* EU stall data stream */
70 struct xe_eu_stall_data_stream *stream; member
398 * @stream: xe EU stall data stream instance
403 static bool eu_stall_data_buf_poll(struct xe_eu_stall_data_stream *stream) in eu_stall_data_buf_poll() argument
406 u32 buf_size = stream->per_xecore_buf_size; in eu_stall_data_buf_poll()
408 struct xe_gt *gt = stream->gt; in eu_stall_data_buf_poll()
413 mutex_lock(&stream->xecore_buf_lock); in eu_stall_data_buf_poll()
415 xecore_buf = &stream->xecore_buf[xecore]; in eu_stall_data_buf_poll()
424 if (num_data_rows(total_data) >= stream->wait_num_reports) in eu_stall_data_buf_poll()
428 set_bit(xecore, stream->data_drop.mask); in eu_stall_data_buf_poll()
431 mutex_unlock(&stream->xecore_buf_lock); in eu_stall_data_buf_poll()
452 static int xe_eu_stall_data_buf_read(struct xe_eu_stall_data_stream *stream, in xe_eu_stall_data_buf_read() argument
470 xecore_buf = &stream->xecore_buf[xecore]; in xe_eu_stall_data_buf_read()
474 buf_size = stream->per_xecore_buf_size; in xe_eu_stall_data_buf_read()
517 if (test_bit(xecore, stream->data_drop.mask)) { in xe_eu_stall_data_buf_read()
519 clear_bit(xecore, stream->data_drop.mask); in xe_eu_stall_data_buf_read()
527 * @stream: A stream opened for EU stall count metrics
528 * @file: An xe EU stall data stream file
536 static ssize_t xe_eu_stall_stream_read_locked(struct xe_eu_stall_data_stream *stream, in xe_eu_stall_stream_read_locked() argument
540 struct xe_gt *gt = stream->gt; in xe_eu_stall_stream_read_locked()
546 mutex_lock(&stream->xecore_buf_lock); in xe_eu_stall_stream_read_locked()
547 if (bitmap_weight(stream->data_drop.mask, XE_MAX_DSS_FUSE_BITS)) { in xe_eu_stall_stream_read_locked()
548 if (!stream->data_drop.reported_to_user) { in xe_eu_stall_stream_read_locked()
549 stream->data_drop.reported_to_user = true; in xe_eu_stall_stream_read_locked()
551 XE_MAX_DSS_FUSE_BITS, stream->data_drop.mask); in xe_eu_stall_stream_read_locked()
552 mutex_unlock(&stream->xecore_buf_lock); in xe_eu_stall_stream_read_locked()
555 stream->data_drop.reported_to_user = false; in xe_eu_stall_stream_read_locked()
559 ret = xe_eu_stall_data_buf_read(stream, buf, count, &total_size, in xe_eu_stall_stream_read_locked()
564 mutex_unlock(&stream->xecore_buf_lock); in xe_eu_stall_stream_read_locked()
569 * Userspace must enable the EU stall stream with DRM_XE_OBSERVATION_IOCTL_ENABLE
578 struct xe_eu_stall_data_stream *stream = file->private_data; in xe_eu_stall_stream_read() local
579 struct xe_gt *gt = stream->gt; in xe_eu_stall_stream_read()
582 aligned_count = ALIGN_DOWN(count, stream->data_record_size); in xe_eu_stall_stream_read()
586 if (!stream->enabled) { in xe_eu_stall_stream_read()
587 xe_gt_dbg(gt, "EU stall data stream not enabled to read\n"); in xe_eu_stall_stream_read()
593 ret = wait_event_interruptible(stream->poll_wq, stream->pollin); in xe_eu_stall_stream_read()
598 ret = xe_eu_stall_stream_read_locked(stream, file, buf, aligned_count); in xe_eu_stall_stream_read()
603 ret = xe_eu_stall_stream_read_locked(stream, file, buf, aligned_count); in xe_eu_stall_stream_read()
612 stream->pollin = false; in xe_eu_stall_stream_read()
617 static void xe_eu_stall_stream_free(struct xe_eu_stall_data_stream *stream) in xe_eu_stall_stream_free() argument
619 struct xe_gt *gt = stream->gt; in xe_eu_stall_stream_free()
621 mutex_destroy(&stream->xecore_buf_lock); in xe_eu_stall_stream_free()
622 gt->eu_stall->stream = NULL; in xe_eu_stall_stream_free()
623 kfree(stream); in xe_eu_stall_stream_free()
626 static void xe_eu_stall_data_buf_destroy(struct xe_eu_stall_data_stream *stream) in xe_eu_stall_data_buf_destroy() argument
628 xe_bo_unpin_map_no_vm(stream->bo); in xe_eu_stall_data_buf_destroy()
629 kfree(stream->xecore_buf); in xe_eu_stall_data_buf_destroy()
632 static int xe_eu_stall_data_buf_alloc(struct xe_eu_stall_data_stream *stream, in xe_eu_stall_data_buf_alloc() argument
635 struct xe_tile *tile = stream->gt->tile; in xe_eu_stall_data_buf_alloc()
639 stream->xecore_buf = kcalloc(last_xecore, sizeof(*stream->xecore_buf), GFP_KERNEL); in xe_eu_stall_data_buf_alloc()
640 if (!stream->xecore_buf) in xe_eu_stall_data_buf_alloc()
643 size = stream->per_xecore_buf_size * last_xecore; in xe_eu_stall_data_buf_alloc()
648 kfree(stream->xecore_buf); in xe_eu_stall_data_buf_alloc()
653 stream->bo = bo; in xe_eu_stall_data_buf_alloc()
658 static int xe_eu_stall_stream_enable(struct xe_eu_stall_data_stream *stream) in xe_eu_stall_stream_enable() argument
662 struct xe_gt *gt = stream->gt; in xe_eu_stall_stream_enable()
668 stream->fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_RENDER); in xe_eu_stall_stream_enable()
669 if (!xe_force_wake_ref_has_domain(stream->fw_ref, XE_FW_RENDER)) { in xe_eu_stall_stream_enable()
690 write_ptr &= (stream->per_xecore_buf_size << 1) - 1; in xe_eu_stall_stream_enable()
691 xecore_buf = &stream->xecore_buf[xecore]; in xe_eu_stall_stream_enable()
695 stream->data_drop.reported_to_user = false; in xe_eu_stall_stream_enable()
696 bitmap_zero(stream->data_drop.mask, XE_MAX_DSS_FUSE_BITS); in xe_eu_stall_stream_enable()
701 stream->sampling_rate_mult)); in xe_eu_stall_stream_enable()
705 reg_value = xe_bo_ggtt_addr(stream->bo); in xe_eu_stall_stream_enable()
707 stream->per_xecore_buf_size / SZ_256K); in xe_eu_stall_stream_enable()
716 struct xe_eu_stall_data_stream *stream = in eu_stall_data_buf_poll_work_fn() local
717 container_of(work, typeof(*stream), buf_poll_work.work); in eu_stall_data_buf_poll_work_fn()
718 struct xe_gt *gt = stream->gt; in eu_stall_data_buf_poll_work_fn()
720 if (eu_stall_data_buf_poll(stream)) { in eu_stall_data_buf_poll_work_fn()
721 stream->pollin = true; in eu_stall_data_buf_poll_work_fn()
722 wake_up(&stream->poll_wq); in eu_stall_data_buf_poll_work_fn()
725 &stream->buf_poll_work, in eu_stall_data_buf_poll_work_fn()
729 static int xe_eu_stall_stream_init(struct xe_eu_stall_data_stream *stream, in xe_eu_stall_stream_init() argument
734 struct xe_gt *gt = stream->gt; in xe_eu_stall_stream_init()
754 init_waitqueue_head(&stream->poll_wq); in xe_eu_stall_stream_init()
755 mutex_init(&stream->xecore_buf_lock); in xe_eu_stall_stream_init()
756 INIT_DELAYED_WORK(&stream->buf_poll_work, eu_stall_data_buf_poll_work_fn); in xe_eu_stall_stream_init()
757 stream->per_xecore_buf_size = per_xecore_buf_size; in xe_eu_stall_stream_init()
758 stream->sampling_rate_mult = props->sampling_rate_mult; in xe_eu_stall_stream_init()
759 stream->wait_num_reports = props->wait_num_reports; in xe_eu_stall_stream_init()
760 stream->data_record_size = xe_eu_stall_data_record_size(gt_to_xe(gt)); in xe_eu_stall_stream_init()
762 ret = xe_eu_stall_data_buf_alloc(stream, last_xecore); in xe_eu_stall_stream_init()
767 xecore_buf = &stream->xecore_buf[xecore]; in xe_eu_stall_stream_init()
768 vaddr_offset = xecore * stream->per_xecore_buf_size; in xe_eu_stall_stream_init()
769 xecore_buf->vaddr = stream->bo->vmap.vaddr + vaddr_offset; in xe_eu_stall_stream_init()
774 static __poll_t xe_eu_stall_stream_poll_locked(struct xe_eu_stall_data_stream *stream, in xe_eu_stall_stream_poll_locked() argument
779 poll_wait(file, &stream->poll_wq, wait); in xe_eu_stall_stream_poll_locked()
781 if (stream->pollin) in xe_eu_stall_stream_poll_locked()
789 struct xe_eu_stall_data_stream *stream = file->private_data; in xe_eu_stall_stream_poll() local
790 struct xe_gt *gt = stream->gt; in xe_eu_stall_stream_poll()
794 ret = xe_eu_stall_stream_poll_locked(stream, file, wait); in xe_eu_stall_stream_poll()
800 static int xe_eu_stall_enable_locked(struct xe_eu_stall_data_stream *stream) in xe_eu_stall_enable_locked() argument
802 struct xe_gt *gt = stream->gt; in xe_eu_stall_enable_locked()
805 if (stream->enabled) in xe_eu_stall_enable_locked()
808 stream->enabled = true; in xe_eu_stall_enable_locked()
810 ret = xe_eu_stall_stream_enable(stream); in xe_eu_stall_enable_locked()
813 &stream->buf_poll_work, in xe_eu_stall_enable_locked()
818 static int xe_eu_stall_disable_locked(struct xe_eu_stall_data_stream *stream) in xe_eu_stall_disable_locked() argument
820 struct xe_gt *gt = stream->gt; in xe_eu_stall_disable_locked()
822 if (!stream->enabled) in xe_eu_stall_disable_locked()
825 stream->enabled = false; in xe_eu_stall_disable_locked()
829 cancel_delayed_work_sync(&stream->buf_poll_work); in xe_eu_stall_disable_locked()
835 xe_force_wake_put(gt_to_fw(gt), stream->fw_ref); in xe_eu_stall_disable_locked()
841 static long xe_eu_stall_stream_ioctl_locked(struct xe_eu_stall_data_stream *stream, in xe_eu_stall_stream_ioctl_locked() argument
846 return xe_eu_stall_enable_locked(stream); in xe_eu_stall_stream_ioctl_locked()
848 return xe_eu_stall_disable_locked(stream); in xe_eu_stall_stream_ioctl_locked()
856 struct xe_eu_stall_data_stream *stream = file->private_data; in xe_eu_stall_stream_ioctl() local
857 struct xe_gt *gt = stream->gt; in xe_eu_stall_stream_ioctl()
861 ret = xe_eu_stall_stream_ioctl_locked(stream, cmd, arg); in xe_eu_stall_stream_ioctl()
869 struct xe_eu_stall_data_stream *stream = file->private_data; in xe_eu_stall_stream_close() local
870 struct xe_gt *gt = stream->gt; in xe_eu_stall_stream_close()
875 xe_eu_stall_disable_locked(stream); in xe_eu_stall_stream_close()
876 xe_eu_stall_data_buf_destroy(stream); in xe_eu_stall_stream_close()
877 xe_eu_stall_stream_free(stream); in xe_eu_stall_stream_close()
897 struct xe_eu_stall_data_stream *stream; in xe_eu_stall_stream_open_locked() local
903 if (gt->eu_stall->stream) { in xe_eu_stall_stream_open_locked()
908 stream = kzalloc(sizeof(*stream), GFP_KERNEL); in xe_eu_stall_stream_open_locked()
909 if (!stream) in xe_eu_stall_stream_open_locked()
912 gt->eu_stall->stream = stream; in xe_eu_stall_stream_open_locked()
913 stream->gt = gt; in xe_eu_stall_stream_open_locked()
915 ret = xe_eu_stall_stream_init(stream, props); in xe_eu_stall_stream_open_locked()
917 xe_gt_dbg(gt, "EU stall stream init failed : %d\n", ret); in xe_eu_stall_stream_open_locked()
921 stream_fd = anon_inode_getfd("[xe_eu_stall]", &fops_eu_stall, stream, f_flags); in xe_eu_stall_stream_open_locked()
936 xe_eu_stall_data_buf_destroy(stream); in xe_eu_stall_stream_open_locked()
938 xe_eu_stall_stream_free(stream); in xe_eu_stall_stream_open_locked()
943 * xe_eu_stall_stream_open - Open a xe EU stall data stream fd
950 * This function opens a EU stall data stream with input properties from
953 * Returns: EU stall data stream fd on success or a negative error code.