[Intel-xe] [PATCH v7 1/1] drm/xe: Use nanoseconds instead of jiffies in uapi for user fence
Andi Shyti
andi.shyti at linux.intel.com
Wed Jun 28 17:49:40 UTC 2023
Hi Zbigniew,
[...]
> +static unsigned long to_jiffies_timeout(struct drm_xe_wait_user_fence *args)
> +{
> + unsigned long timeout;
> +
> + if (args->flags & DRM_XE_UFENCE_WAIT_ABSTIME)
> + return drm_timeout_abs_to_jiffies(args->timeout);
> +
> + if (args->timeout == MAX_SCHEDULE_TIMEOUT || args->timeout == 0)
> + return args->timeout;
> +
> + timeout = nsecs_to_jiffies(args->timeout);
> +
> + return timeout ?: 1;
> +}
> +
> int xe_wait_user_fence_ioctl(struct drm_device *dev, void *data,
> struct drm_file *file)
> {
> @@ -98,7 +114,8 @@ int xe_wait_user_fence_ioctl(struct drm_device *dev, void *data,
> int err;
> bool no_engines = args->flags & DRM_XE_UFENCE_WAIT_SOFT_OP ||
> args->flags & DRM_XE_UFENCE_WAIT_VM_ERROR;
> - unsigned long timeout = args->timeout;
> + unsigned long timeout;
> + ktime_t start;
>
> if (XE_IOCTL_ERR(xe, args->extensions) || XE_IOCTL_ERR(xe, args->pad) ||
> XE_IOCTL_ERR(xe, args->reserved[0] || args->reserved[1]))
> @@ -149,8 +166,18 @@ int xe_wait_user_fence_ioctl(struct drm_device *dev, void *data,
> addr = vm->async_ops.error_capture.addr;
> }
>
> - if (XE_IOCTL_ERR(xe, timeout > MAX_SCHEDULE_TIMEOUT))
> - return -EINVAL;
> + /*
> + * For negative timeout we want to wait "forever" by setting
> + * MAX_SCHEDULE_TIMEOUT. But we have to assign this value also
> + * to args->timeout to avoid being zeroed on the signal delivery
> + * (see arithmetics after wait).
> + */
> + if (args->timeout < 0)
> + args->timeout = MAX_SCHEDULE_TIMEOUT;
> +
> + timeout = to_jiffies_timeout(args);
> +
> + start = ktime_get();
>
> /*
> * FIXME: Very simple implementation at the moment, single wait queue
> @@ -189,17 +216,17 @@ int xe_wait_user_fence_ioctl(struct drm_device *dev, void *data,
> } else {
> remove_wait_queue(&xe->ufence_wq, &w_wait);
> }
> +
> + if (!(args->flags & DRM_XE_UFENCE_WAIT_ABSTIME)) {
> + args->timeout -= ktime_to_ns(ktime_sub(ktime_get(), start));
> + if (args->timeout < 0)
> + args->timeout = 0;
OK... good catch!
Reviewed-by: Andi Shyti <andi.shyti at linux.intel.com>
Andi
More information about the Intel-xe
mailing list