Commit Graph

25 Commits

Author SHA1 Message Date
Sven Joachim
47387916fb Fix various spelling errors 2019-10-01 17:05:28 +00:00
Mario Kleiner
c9afd8cb5e modesetting: Fix and improve ms_kernel_msc_to_crtc_msc()
The old 32-Bit wraparound handling didn't actually work, due to some
integer casting bug, and the mapping was ill equipped to deal with input
from the new true 64-bit GetCrtcSequence/QueueCrtcSequence api's
introduced in Linux 4.15.

For 32-Bit truncated input from pageflip events and old vblank events
and old drmWaitVblank ioctl, implement new wraparound handling, which
also allows to deal with wraparound in the other direction, e.g., if a
32-Bit truncated sequence value is passed in, whose true 64-Bit
in-kernel hw value is within 2^30 counts of the previous processed
value, but whose 32-bit truncated sequence value happens to lie just
above or below a 2^32 boundary, iow. one of the two values 'sequence'
vs. 'msc_prev' lies above a 2^32 border, the other one below it.

The method is directly translated from Mesa's proven implementation of
the INTEL_swap_events extension, where a true underlying 64-Bit wide
swapbuffers count (SBC) needs to get reconstructed from a 32-Bit LSB
truncated SBC transported over the X11 protocol wire. Same conditions
apply, ie. successive true 64-Bit SBC values are close to each other,
but don't always get received in strictly monotonically increasing
order. See Mesa commit cc5ddd584d17abd422ae4d8e83805969485740d9 ("glx:
Handle out-of-sequence swap completion events correctly. (v2)") for
explanation.

Additionally add a separate path for true 64-bit msc input originating
from Linux 4.15+ drmCrtcGetSequence/QueueSequence ioctl's and
corresponding 64-bit vblank events. True 64-bit msc's don't need
remapping and must be passed through.

As a reliability bonus, they are also used here to update the tracking
values msc_prev and ms_high with perfect 64-Bit ground truth as baseline
for mapping msc from pageflip completion events, because pageflip events
are always 32-bit wide, even when the new kernel api's are used. Because
each pageflip(-event) is always preceeded close in time (and vblank
count) by a drmCrtcQueueSequence queued event or drmCrtcGetSequence
query as part of DRI2 or DRI3+Present swap scheduling, we can be certain
that each pageflip event will get its truncated 32-bit msc remapped
reliably to the true 64-bit msc of flip completion whenever the sequence
api is available, ie. on Linux 4.15 or later.

Note: In principle at least the 32-bit mapping path could also be
backported to earlier server branches, as this seems to be broken for at
least server 1.16 to 1.19.

Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Cc: Keith Packard <keithp@keithp.com>
Cc: Michel Dänzer <michel.daenzer@amd.com>
2018-05-07 14:01:01 -04:00
Mario Kleiner
73f0ed2d92 modesetting: Remove ms_crtc_msc_to_kernel_msc().
The function is ported from intel-ddx uxa backend around 2013, where its
stated purpose was to apply a vblank_offset to msc values to correct for
problems with those kernel provided msc values. Some (somewhat magic and
puzzling to myself) heuristic tried to guess if provided values were
unreasonable and tried to adapt the corrective vblank_offset to account
for that.

Except: It wasn't applied to kernel provided msc values, but the values
delivered by clients via DRI2 or Present, so valid client targetmsc
values, e.g., requesting a vblank event > 1000 vblanks in the future,
triggered the offset correction in arbitrarily wrong ways, leading to
wrong msc values being returned and thereby vblank events queued to the
kernel for the wrong time. This causes glXSwapBuffersMscOML and
glXWaitForMscOML to swap / return immediately whenever a swap/wait in >
1000 vblanks is requested.

The original code was also written to only deal with 32 bit mscs, but
server 1.20 modesetting ddx can now use new Linux 4.15+ kernel vblank
api to process true 64 bit msc's, which may confuse the heuristic even
more due to 32 bit integer truncation/wrapping.

This code caused various problems in the intel-ddx in the past since
year 2013, and was removed there in 2015 by Chris Wilson in commit
42ebe2ef9646be5c4586868cf332b4cd79bb4618:

"    uxa: Remove the filtering of bogus Present MSC values

    If the intention was to filter the return values from the kernel, the
    filtering would have been applied to the kernel values and not to the
    incoming values from Present. This filtering introduces crazy integer
    promotion and truncation bugs all because Present feeds garbage into its
    vblank requests.

"

Indeed, i found a Mesa bug yesterday which can cause Mesa's
PresentPixmap request to spuriously feed garbage targetMSC's into the
driver under some conditions. However, while other video drivers seem to
cope relatively well with that, modesetting ddx causes KDE-5's
plasmashell to lock up badly quite frequently, and my suspicion is that
the code removed in this commit is one major source of the extra
fragility.

Also my own tests fail for any swap scheduled more than 1000 vblanks
into the future, which is not uncommon for some scientific applications.

Iow. modesetting's swap scheduling seems to be more robust without this
function afaics.

Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Keith Packard <keithp@keithp.com>
Tested-by: Mike Lothian <mike@fireburn.co.uk>
2018-05-07 12:32:40 -04:00
Emil Velikov
d2568c0587 modesetting: remove always true DRM_IOCTL_CRTC_QUEUE_SEQUENCE guard
We already require libdrm 2.4.89 which provides the definition plus
guarding kernel UABI like that is generally a bad idea.

See previous commit for details why :-)

Cc: Keith Packard <keithp@keithp.com>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-03-21 10:06:18 -04:00
Mario Kleiner
efe9e3e9ff modesetting: Fix fallback for lack of new vblank kernel API.
Turns out that the kernel DRM ioctl handling returns EINVAL
instead of ENOTTY if one tries to call the new drmCrtcGetSequence()
or drmCrtcQueueSequence() ioctl's introduced in Linux 4.15 on an
older kernel where they are missing. This causes the fallback code
not to fall back to the old drmWaitVblank() ioctl and thereby
failure of vblank stuff.

E.g., on Linux 4.13, glxgears -info runs unthrottled at 10000 fps
instead of 60 fps. Also breakage of OML_sync_control extension.

Check for errno != EINVAL before setting has_queue_sequence = TRUE.

Additionally in case of supported drmCrtcQueueSequence(), set
has_queue_sequence = TRUE on success, or we might get at
least a temporary failure in ms_queue_vblank().

One slight ambiguity is that we can also get EINVAL if
drm_crtc_vblank_get() fails in the kernel, so if that
happened at first invocation of the new api, we'd fall
back to drmWaitVblank() and then fail there, instead of
failing in the new api, but the end result would be the
same.

Fixes: 44d5f2eb8a ("xf86-video-modesetting: Support new vblank kernel API [v2]")
Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Cc: Keith Packard <keithp@keithp.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
2018-02-27 10:02:05 -05:00
Keith Packard
44d5f2eb8a xf86-video-modesetting: Support new vblank kernel API [v2]
drmCrtcGetSequence returns the current vblank sequence and time.

drmCrtcQueueSequence queues an event for delivery at a specified
vblank sequence.

Use these (when available) in preference to drmWaitVBlank.

v2: Remove FIRST_PIXEL_OUT_FLAG. This has been removed from the kernel
    API.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2018-01-22 17:22:21 -05:00
Keith Packard
32b4262721 modesetting: Use seq instead of msc in ms_queue_vblank failure path
When the call to queue a vblank event fails, we need to clean up by
removing the user-space queue entry. That is indexed by the local
sequence number, not by the kernel vblank count. The call in this
case was just passing the wrong value.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2018-01-16 16:10:27 -05:00
Alex Goins
266d9868ca xf86-video-modesetting: Fix ms_queue_vblank(flags = MS_QUEUE_RELATIVE)
Change 677c32bc refactored all usages of drmWaitVBlank() into a helper function,
ms_queue_vblank().

ms_queue_vblank() takes in an MS_QUEUE_RELATIVE flag to indicate that the
sequence number is relative rather than absolute, but still treats the actual
sequence number as absolute, passing it through ms_crtc_msc_to_kernel_msc()
unconditionally before calling drmWaitVBlank().

ms_crtc_msc_to_kernel_msc() works by subtracting a vblank offset from the
provided sequence number, which only makes sense for absolute sequence numbers.
In the case of PRIME Sync, drmmode_SharedPixmapPrsentOnVBlank() passes in 1,
which results in a large negative vblank offset. After subtracting, we're left
with a relative sequence number of 100,000+, i.e. wait for 100,000+ vblanks...

In the relative case we want to pass in the sequence number unmodified. Simply
add a check to do this.

Signed-off-by: Alex Goins <agoins@nvidia.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
2017-10-27 10:00:47 -04:00
Keith Packard
677c32bcda xf86-video-modesetting: Add ms_queue_vblank helper [v3]
This provides an API wrapper around the kernel interface for queueing
a vblank event, simplifying all of the callers.

v2: Fix missing '|' in computing vbl.request.type

v3: Remove spurious bit of next patch (thanks, Michel Dänzer)

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2017-10-04 15:17:41 -04:00
Daniel Stone
0c8e6ed858 modesetting: Set correct DRM event context version
DRM_EVENT_CONTEXT_VERSION is the latest context version supported by
whatever version of libdrm is present. modesetting was blindly asserting
it supported whatever version that may be, even if it actually didn't.

With libdrm 2.4.78, setting a higher context version than 2 will attempt
to call the page_flip_handler2 vfunc if it was non-NULL, which being a
random chunk of stack memory, it might well have been.

Set the version as 2, which should be bumped only with the appropriate
version checks.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Daniel Stone <daniels@collabora.com>
2017-04-07 09:57:54 -04:00
Hans de Goede
d8e05c0475 modesetting: Fall back to primary crtc for vblank for drawables on slave outputs
This fixes glxgears running at 1 fps when fully covering a slave-output
and the modesetting driver is used for the master gpu.

Reported-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2016-09-13 11:18:43 -04:00
Hans de Goede
7ade8ba10e modesetting: ms_covering_crtc: Allow calling on non modesetting Screens
99% of the code in ms_covering_crtc is video-driver agnostic. Add a
screen_is_ms parameter when when FALSE skips the one ms specific check,
this will allow calling ms_covering_crtc on slave GPUs.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2016-09-13 11:18:41 -04:00
Hans de Goede
dfa295b29c modesetting: ms_covering_crtc: Remove unused arguments, make static
Remove unused arguments from ms_covering_crtc, make it static as it is
only used in vblank.c.

While at it also change its first argument from a ScrnInfoPtr to a
ScreenPtr, this makes the next patch in this patch-set cleaner.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
2016-09-13 10:26:27 +02:00
Keith Packard
d403aca70a Switch poll() users to xserver_poll()
This uses the wrapper in case we need to emulate poll with select
as we do on Windows.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2016-07-21 15:04:36 -04:00
Keith Packard
6299ef3d74 modesetting: Use passed-in fd for drm event monitoring NotifyFd callback
This is a cleanup, proposed by Adam Jackson, but wasn't merged with
the original NotifyFD changes.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-18 15:25:59 -04:00
Keith Packard
8543d4d8bc modesetting: Use NotifyFd for drm event monitoring
Replace the block/wakeup handlers with a NotifyFd callback.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2015-12-01 13:55:25 -05:00
Dave Airlie
19e1dc8f6e modesetting: add zaphod support (v3)
This adds zaphod and ZaphodHeads support
to the the in-server modesetting driver.

this is based on a request from Mario,
and on the current radeon driver, along
with some patches from Mario to bring things
up to the state of the art in Zaphod.

v2: fixup vblank fd registring.
v3: squash Mario's fixes.
  modesetting: Allow/Fix use of multiple ZaphodHead outputs per x-screen.
  modesetting: Take shift in crtc positions for ZaphodHeads configs into account.
  modesetting: Add ZaphodHeads description to man page.
small cleanups (airlied).

Reviewed-and-tested-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2015-08-13 00:36:03 +01:00
Dave Airlie
edec6394a4 modesetting: drop unused struct in vblank.c
this isn't used anywhere here.

Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2015-06-30 13:44:09 +10:00
Kenneth Graunke
bf262b4300 modesetting: Implement an ms_drm_abort_seq() function.
This is a specialization of ms_drm_abort that matches based on the drm
event queue's sequence number.

Based on code by Keith Packard.

Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
2015-06-30 13:44:09 +10:00
Kenneth Graunke
f2171d0a20 modesetting: Make ms_crtc_on non-static.
I want to use this in present.c.

Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
2015-06-30 13:44:09 +10:00
Jason Ekstrand
fef2f6357b modesetting: Return the crtc for a drawable even if it's rotated
All of our checks for what crtc we are on take rotation into account so we
select the correct crtc.  The only problem is that we weren't returning it
we were rotated.  This caused X to think DRI3 apps were not on any crtc and
limit them to 1 FPS.

Signed-off-by: Jason Ekstrand <jason.ekstrand@intel.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2015-01-23 10:50:11 -08:00
Kenneth Graunke
09230a2d43 modesetting: Add vblank synchronization support when using Present.
modesetting hooked up vblank support for DRI2, but was missing support
for vblanks in Present.

This is mostly copy and pasted from Keith's code in the intel driver.

v2: Use ms_crtc_msc_to_kernel_msc in ms_present_queue_vblank to hook
    up the vblank_offset workaround for bogus MSC values (which the
    DRI2 code already did).

    Also simplify the ms_present_get_crtc function.  vblank.c already
    implements the functionality; we just need to convert types.

v3: Fix ms_flush_drm_events return code.  I'd copied code where 0 meant
    success into a function that returned a boolean, so the return code
    was always backwards.

    Also add DebugPresent calls in ms_present_vblank_{handler,abort}.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Keith Packard <keithp@keithp.com>
Tested-by: Jason Ekstrand <jason.ekstrand@intel.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2014-12-25 13:39:19 -08:00
Kenneth Graunke
7d1fc04d27 modesetting: Check DPMS mode in ms_covering_crtc().
crtc->enabled is insufficient; we should also make sure DPMS is on.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Keith Packard <keithp@keithp.com>
Tested-by: Jason Ekstrand <jason.ekstrand@intel.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2014-12-25 13:39:14 -08:00
Keith Packard
5adc20179e modesetting: Skip kernel work-around on error in crtc to kernel msc
ms_crtc_msc_to_kernel_msc attempts to work around kernel
inconsistencies in reporting msc values by comparing the expected
value with the reported value. If the kernel fails to
actually provide its current values, then just skip the work around
steps as there's really nothing better we can do.

Signed-off-by: Keith Packard <keithp@keithp.com>
2014-10-27 15:28:14 -07:00
Eric Anholt
cac4b064f9 modesetting: Add support for DRI2 with glamor.
This is derived from the intel driver DRI2 code, with swapchain and
pageflipping dropped, functions renamed, and vblank event management
shared code moved to a vblank.c for reuse by Present.

This allows AIGLX to load, which means that you get appropriate
visuals exposed in GL, along with many extensions under
direct-rendering that require presence in GLX (which aren't supported
in glxdriswrast.c).

v2: Drop unused header includes in pageflip.c, wrap in #ifdef GLAMOR.
    Drop triple-buffering, which was totally broken in practice (I'll
    try to fix this later).  Fix up some style nits.  Document the
    general flow of pageflipping and why, rename the DRI2 frame event
    type enums to reflect what they're for, and handle them in a
    single switch statement so you can understand the state machine
    more easily.
v3: Drop pageflipping entirely -- it's unstable on my Intel laptop
    (not that the normal 2D driver is stable with pageflipping for
    me), and I won't get it fixed before the merge window.  It now
    passes all of the OML_sync_control tests from Jamey and Theo
    (except for occasional warns in timing -fullscreen -divisor 2).
v4: Fix doxygen at the top of vblank.c

Signed-off-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2014-10-27 13:16:43 -07:00