From: "Keith Packard" <keithp@keithp.com>
To: Jason Ekstrand <jason@jlekstrand.net>
Cc: ML mesa-dev <mesa-dev@lists.freedesktop.org>,
Maling list - DRI developers <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH 4/7] anv: Support wait for heterogeneous list of fences [v2]
Date: Tue, 19 Jun 2018 17:36:45 -0700 [thread overview]
Message-ID: <87lgbaqoo2.fsf@keithp.com> (raw)
In-Reply-To: <CAOFGe94-8KdifZ7ZrK_2y7TrYKMpFZUm49ZfDKRUdp+XE2WWPw@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 3195 bytes --]
Jason Ekstrand <jason@jlekstrand.net> writes:
> I still don't really like this but I agree that this code really should not
> be getting hit very often so it's probably not too bad. Maybe one day
> we'll be able to drop the non-syncobj paths entirely. Wouldn't that be
> nice.
I agree. What I want to have is kernel-side syncobj support for all of
the WSI fences that we need here.
I thought about using syncobjs and signaling them from user-space, but
realized that we couldn't eliminate the non-syncobj path quite yet as
that requires a new enough kernel. And, if we want to get to
kernel-native WSI syncobjs, that would mean we'd eventually have three
code paths. I think it's better to have one 'legacy' path, which works
on all kernels, and then one 'modern' path which does what we want.
> In the mean time, this is probably fine. I did see one issue below
> with time conversions that should be fixed though.
Always a hard thing to get right.
>> +static uint64_t anv_get_absolute_timeout(uint64_t timeout)
>> +{
>> + if (timeout == 0)
>> + return 0;
>> + uint64_t current_time = gettime_ns();
>> +
>> + timeout = MIN2(INT64_MAX - current_time, timeout);
>> +
>> + return (current_time + timeout);
>> +}
>>
>
> This does not have the same behavior as the code it replaces. In
> particular, the old code saturates at INT64_MAX whereas this code does not
> do so properly anymore. If UINT64_MAX gets passed into timeout, I believe
> that will be implicitly casted to signed and the MIN will yield -1 which
> gets casted back to unsigned and you get UINT64_MAX again.
It won't not get implicitly casted to signed; the implicit cast works
the other way where <signed> OP <unsigned> implicitly casts the <signed>
operand to unsigned for types of the same 'rank' (where 'rank' is not
quite equivalent to size). Here's a fine article on this:
https://wiki.sei.cmu.edu/confluence/display/c/INT02-C.+Understand+integer+conversion+rules
However, this is a rather obscure part of the ISO standard, and I don't
think we should expect that people reading the code know it well. Adding
a cast to make it clear what we want is a good idea. How about this?
static uint64_t anv_get_absolute_timeout(uint64_t timeout)
{
if (timeout == 0)
return 0;
uint64_t current_time = gettime_ns();
uint64_t max_timeout = (uint64_t) INT64_MAX - current_time;
timeout = MIN2(max_timeout, timeout);
return (current_time + timeout);
}
> This is a problem because the value we pass into the kernel ioctls is
> signed. The behavior of the kernel *should* be infinite when timeout
> < 0 but, on some older kernels, -1 is treated as 0 and you get no
> timeout.
Yeah, we definitely want to cap the values to INT64_MAX.
>> - else if (current_ns + _timeout > INT64_MAX)
>>
>
> I suspect we need to cast INT64_MAX to a uint64_t here to ensure we don't
> accidentally get an implicit conversion to signed.
Again, it's not necessary given the C conversion rules, but it is a good
way to clarify the intent.
--
-keith
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2018-06-20 0:36 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-15 2:52 [PATCH 0/7] vulkan: Add VK_EXT_display_control and VK_EXT_display_surface_counter Keith Packard
2018-06-15 2:52 ` [PATCH 1/7] vulkan: Add VK_EXT_display_surface_counter [v4] Keith Packard
2018-06-16 18:22 ` Jason Ekstrand
2018-06-16 18:55 ` Keith Packard
2018-06-15 2:52 ` [PATCH 2/7] anv: Add VK_EXT_display_surface_counter to anv driver [v2] Keith Packard
2018-06-15 2:52 ` [PATCH 3/7] radv: Add VK_EXT_display_surface_counter to radv driver Keith Packard
2018-06-15 2:52 ` [PATCH 4/7] anv: Support wait for heterogeneous list of fences [v2] Keith Packard
2018-06-19 23:26 ` Jason Ekstrand
2018-06-20 0:36 ` Keith Packard [this message]
2018-06-20 0:42 ` Jason Ekstrand
2018-06-20 1:22 ` Keith Packard
2018-06-20 2:22 ` Jason Ekstrand
2018-06-20 5:16 ` Keith Packard
2018-06-20 5:22 ` Jason Ekstrand
2018-06-20 5:36 ` Keith Packard
2018-06-15 2:52 ` [PATCH 5/7] vulkan: add VK_EXT_display_control [v5] Keith Packard
2018-06-20 0:28 ` Jason Ekstrand
2018-06-20 4:44 ` Keith Packard
2018-06-20 21:52 ` Jason Ekstrand
2018-06-20 22:49 ` Keith Packard
2018-06-15 2:52 ` [PATCH 6/7] anv: add VK_EXT_display_control to anv driver [v2] Keith Packard
2018-06-20 0:33 ` Jason Ekstrand
2018-06-20 5:31 ` Keith Packard
2018-06-20 17:13 ` Jason Ekstrand
2018-06-20 22:45 ` Keith Packard
2018-06-15 2:52 ` [PATCH 7/7] radv: add VK_EXT_display_control to radv driver [v3] Keith Packard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lgbaqoo2.fsf@keithp.com \
--to=keithp@keithp.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jason@jlekstrand.net \
--cc=mesa-dev@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox