[PATCH 2/5] drm/syncobj: add sync obj wait interface.

Chris Wilson chris at chris-wilson.co.uk
Thu May 4 08:22:53 UTC 2017


On Wed, Apr 26, 2017 at 01:28:30PM +1000, Dave Airlie wrote:
> +/**
> + * calc_timeout - calculate jiffies timeout from absolute value
> + *
> + * @timeout_ns: timeout in ns
> + *
> + * Calculate the timeout in jiffies from an absolute timeout in ns.
> + */
> +unsigned long calc_wait_timeout(uint64_t timeout_ns)
> +{
> +        unsigned long timeout_jiffies;
> +        ktime_t timeout;
> +
> +        /* clamp timeout if it's to large */
> +        if (((int64_t)timeout_ns) < 0)
> +                return MAX_SCHEDULE_TIMEOUT;
> +
> +        timeout = ktime_sub(ns_to_ktime(timeout_ns), ktime_get());
> +        if (ktime_to_ns(timeout) < 0)
> +                return 0;
> +
> +        timeout_jiffies = nsecs_to_jiffies(ktime_to_ns(timeout));
> +        /*  clamp timeout to avoid unsigned-> signed overflow */
> +        if (timeout_jiffies > MAX_SCHEDULE_TIMEOUT )
> +                return MAX_SCHEDULE_TIMEOUT - 1;
> +
> +        return timeout_jiffies;
> +}
> +
> +static int drm_syncobj_wait_all_fences(struct drm_device *dev,
> +				       struct drm_file *file_private,
> +				       struct drm_syncobj_wait *wait,
> +				       uint32_t *handles)
> +{
> +	uint32_t i;
> +	int ret;
> +
> +	for (i = 0; i < wait->count_handles; i++) {
> +		unsigned long timeout = calc_wait_timeout(wait->timeout_ns);
> +		struct dma_fence *fence;
> +
> +		ret = drm_syncobj_fence_get(file_private, handles[i],
> +					    &fence);
> +		if (ret)
> +			return ret;
> +
> +		if (!fence)
> +			continue;
> +
> +		ret = dma_fence_wait_timeout(fence, true, timeout);

We are resetting the timeout for each wait, and do not report the
remaining time back to the user. Useful for handling SIGINT and keeping
the maximum waittime intact.

> +		dma_fence_put(fence);
> +		if (ret < 0)
> +			return ret;
> +		if (ret == 0)
> +			break;
> +	}
> +
> +	wait->out_status = (ret > 0);
> +	wait->first_signaled = 0;
> +	return 0;
> +}

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the dri-devel mailing list