Commit graph

130 commits

Author SHA1 Message Date
Roman Gilg
138f2f2ac5
feat: add log format flags
With these flags API consumers can optimize the depiction of libliftoff's debug
log.

For now the two flags for a section start and end are introduced. It is
guaranteed that one section always ends before the next one begins.

Is no callback function setup section starts and ends in the default stderr
output will be marked with an empty line.

BREAKING CHANGE: The signature of the log callback changes.
2020-03-10 11:59:42 +01:00
Roman Gilg
c05f290f95
feat: log continuous debug messages into per-device buffers
Instead of exposing to consumers write streaming log data into a per-device
buffer that gets created on request and destroyed after the buffer has been
written to the log.

Passing a NULL string to the internal continuous log function triggers a write
of the buffer to the log.

BREAKING CHANGE: continuous log function is moved from log header to private
header.
2020-03-10 11:59:42 +01:00
Roman Gilg
273cf8a432
feat: log current planes on apply
It is helpful for debugging to know in which state the available planes on an
output are when a layout is applied that leads to a change.

For that log all planes that are compatible with the output. Currently disabled
planes have multiple properties logged per line to keep the log short.

Example:

== Apply request for output 62 ==
  Note: Reused previous plane allocation 5 times.

Available planes (on output 62):
  Plane 55:
    type: primary
    FB_ID: 93
    IN_FENCE_FD: -1
    CRTC_ID: 62
    CRTC_X: 39
    CRTC_Y: 0
    CRTC_W: 3761
    CRTC_H: 2160
    SRC_X: 0
    SRC_Y: 0
    SRC_W: 2349
    SRC_H: 1349
    COLOR_ENCODING: 0
    COLOR_RANGE: 0
  Plane 61 (inactive):
    type: cursor FB_ID: 0 IN_FENCE_FD: -1 CRTC_ID: 0
    CRTC_X: 0 CRTC_Y: 0 CRTC_W: 0 CRTC_H: 0
    SRC_X: 0 SRC_Y: 0 SRC_W: 0 SRC_H: 0
  Plane 58 (inactive):
    type: overlay FB_ID: 0 IN_FENCE_FD: -1 CRTC_ID: 0
    CRTC_X: 0 CRTC_Y: 0 CRTC_W: 0 CRTC_H: 0
    SRC_X: 0 SRC_Y: 0 SRC_W: 0 SRC_H: 0
    alpha: 65535 pixel blend mode: 0

Committed layers:
  Layer 0x561febd41260:
    FB_ID = 93
    zpos = 0
    SRC_X = 0
    SRC_Y = 0
    SRC_W = 2349
    SRC_H = 1349
    CRTC_X = 39
    CRTC_Y = 0
    CRTC_W = 3761
    CRTC_H = 2160
  Layer 0x561febd3c830:
    FB_ID = 110
    zpos = 2
    SRC_X = 0
    SRC_Y = 0
    SRC_W = 48
    SRC_H = 48
    CRTC_X = 66
    CRTC_Y = 39
    CRTC_W = 48
    CRTC_H = 48

Reset planes: 55 52 49 46 43 40 <p|c> 71 69 67 65 63 61 <c|o> 58

Performing allocation for plane 55 (1/13)
  Layer 0x561febd41260 -> plane 55: applying properties...
  Layer 0x561febd41260 -> plane 55: success
Performing allocation for plane 61 (12/13)
  Layer 0x561febd3c830 -> plane 61: applying properties...
  Layer 0x561febd3c830 -> plane 61: success
Performing allocation for plane 58 (13/13)
Found a better allocation with score=2
  Layer 0x561febd3c830 -> plane 55: applying properties...
  Layer 0x561febd3c830 -> plane 55: success
Performing allocation for plane 61 (12/13)
  Layer 0x561febd41260 -> plane 61: applying properties...
  Layer 0x561febd41260 -> plane 61: success
Performing allocation for plane 58 (13/13)
Found plane allocation for output 0x561febd3e2a0 with score=2

Final assignment of layers to planes:
  [1] Layer 0x561febd41260 -> plane 55 (primary)
  [2] Layer 0x561febd3c830 -> plane 61 (cursor)
2020-03-10 11:59:38 +01:00
Roman Gilg
06f05bf188
feat: log type of assigned planes
Additionally on apply log the type of planes in the final assignment for a
direct overview of the result.
2020-03-10 11:57:59 +01:00
Roman Gilg
80a31d0254
feat: log type information about reset planes
On apply to an output planes associated with the output are being reset. For
easier debugging make clear in the list in the log which planes have which
type.
2020-03-10 11:57:00 +01:00
Roman Gilg
31024f307e
feat: log output relevant data
Log the creation of outputs and simplify output-specific data on apply.
2020-03-10 11:56:58 +01:00
Roman Gilg
afef092218
feat: log device creation
For a new device log relevant data including all planes the output/CRTC
supports.
2020-03-10 11:52:37 +01:00
Roman Gilg
8028aef654
feat: log disabling planes without line breaks
Enumerating all planes to be disabled makes the log unnecessary
sparse. Instead just list all planes in a single line.

For that introduce new API function to log something without line
break in the end and adapt the log callback function pointer.

BREAKING CHANGE: log callback function arguments change.
2020-03-10 11:52:37 +01:00
Roman Gilg
52cd24a904
Omit logging inactive layer information
It is only of interest to log the currently active layers when debugging.
A layer is inactive when it does not have an fb and composition is not forced.

Check layers for that and otherwise skip them. Also tell if composition is
actually forced on the layer.
2020-03-08 22:31:59 +01:00
Roman Gilg
71bd11377a
Respect implicit type on layer props log
The CRTC_X and CRTC_Y values can be negative. Log respectively. Additionally
the SRC_W and SRC_H values are shifted. Shift these values back for the log.
2020-03-08 22:30:08 +01:00
Roman Gilg
6b2cbeb0d4
Indent log on property applying and layer assignment
Indent when applying properties and assigning the layers. The log is better to
read this way. Example:

    Apply on output 0x55c447db2b50.
    Layers on CRTC 62:
      Layer 0x55c447db2a40:
        FB_ID = 108
        zpos = 0
        alpha = 65535
        SRC_X = 0
        SRC_Y = 0
        SRC_W = 3840
        SRC_H = 2160
        CRTC_X = 0
        CRTC_Y = 0
        CRTC_W = 3840
        CRTC_H = 2160
    Disabling planes: 55 52 49 46 43 40 71 69 67 65 63 61 58
    Performing allocation for plane 55 (1/13)
      Layer 0x55c447db2a40 -> plane 55: applying properties...
      Layer 0x55c447db2a40 -> plane 55: incompatible properties
    Performing allocation for plane 61 (12/13)
      Layer 0x55c447db2a40 -> plane 61: applying properties...
      Layer 0x55c447db2a40 -> plane 61: incompatible properties
    Performing allocation for plane 58 (13/13)
      Layer 0x55c447db2a40 -> plane 58: applying properties...
      Layer 0x55c447db2a40 -> plane 58: success
    Found a better allocation with score=1
    Found plane allocation for output 0x55c447db2b50 with score=1
    Assigning layers to planes:
      Layer 0x55c447db2a40 -> plane 58
2020-03-08 14:18:09 +01:00
Roman Gilg
375a8123d2
Skip layer debug early
If the verbosity is low we can skip logging layer information early and do not
need to run the loop.
2020-03-08 13:06:11 +01:00
Roman Gilg
d68b1fc8d7
Add log verbosity helper
Separate function to check verbosity level, which can be used in other internal
parts as well.
2020-03-08 13:05:30 +01:00
Roman Gilg
a3b7c19204
Log layer priority only on change
Similar to reuse log print debug information only when the priority of a layer
changes not whenever priority gets updated but without change.

Otherwise the debug log is spammed (depending on LIFTOFF_PRIORITY_PERIOD).
2020-03-08 13:03:05 +01:00
Roman Gilg
b713b17d31
Log re-use only on change
On debug verbosity logging every reuse of planes is spamming the log making it
difficult to debug the process.

With this patch only the change of reusing the same allocation is logged and
how often the allocation was reused after this changed back again.
2020-03-08 13:00:08 +01:00
Simon Ser
7f5b699f2c
build: install public header file
Closes: https://github.com/emersion/libliftoff/issues/41
2020-01-27 11:04:52 +01:00
Simon Ser
f6b4cd6197
Retry atomic commit on EINTR and EAGAIN
From the kernel docs:

> -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted. This can
> either be due to a pending signal, or because the driver needs to completely
> bail out to recover from an exceptional situation like a GPU hang. From a
> userspace point of view all errors are treated equally.

We're not handling ERESTARTSYS because it's non-POSIX.
2020-01-13 12:28:39 +01:00
Simon Ser
95d16704b9
Move device_test_commit to device.c 2020-01-13 12:22:47 +01:00
Simon Ser
b16078769e
test/libdrm_mock: a test-only commit applies properties
The previous mock library assumed the DRM client would always set all
properties in the atomic request. However, if a previous test-only commit
has set a property, there's no need to set it again.

Accomodate for this in libdrm_mock. This will be useful when we'll skip
setting properties that haven't changed in libliftoff.

References: https://github.com/emersion/libliftoff/issues/37
2020-01-13 12:14:33 +01:00
Simon Ser
64cfbc8e58
Fix format string for plane ID 2020-01-13 10:42:46 +01:00
Simon Ser
cfeee41ec1
Allow NULL to be passed to destructors
In this case, the destructor will be a no-op. This is similar to free(3)'s
behavior and allows to omit a NULL check for callers.
2019-12-31 20:46:08 +01:00
Simon Ser
7286146341
test: add a test with a zero FB_ID
References: 53a7bfebc9 ("Don't allocate planes for layers without a FB")
2019-12-19 17:54:49 +01:00
Simon Ser
71200724c5
test: add a test with a layer without any prop set
Makes sure libliftoff doesn't allocate a plane for the layer and doesn't crash.

References: 799f694587 ("Fix segfault when FB_ID isn't set")
References: 53a7bfebc9 ("Don't allocate planes for layers without a FB")
2019-12-19 17:50:40 +01:00
Simon Ser
53a7bfebc9
Don't allocate planes for layers without a FB
When FB_ID is unet or zero, don't try to allocate a plane for the layer. There's
nothing to display anyway.
2019-12-19 17:50:20 +01:00
Simon Ser
799f694587
Fix segfault when FB_ID isn't set
This would previously result in a crash:

    ==169727==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000028 (pc 0x7f3e0c4d7dc7 bp 0x7ffc97f8aff0 sp 0x7ffc97f8afc0 T0)
    ==169727==The signal is caused by a READ memory access.
    ==169727==Hint: address points to the zero page.
        #0 0x7f3e0c4d7dc6 in layer_update_priority ../subprojects/libliftoff/layer.c:152
        #1 0x7f3e0c4d3a4c in update_layers_priority ../subprojects/libliftoff/alloc.c:573
        #2 0x7f3e0c4d3d7f in liftoff_output_apply ../subprojects/libliftoff/alloc.c:590
        …
2019-12-19 17:37:18 +01:00
Simon Ser
657a9917c5
Add a way to force FB composition
Closes: https://github.com/emersion/libliftoff/issues/17
2019-12-13 11:38:14 +01:00
Simon Ser
c9cdf8ec50
Log layer configuration before alloc 2019-12-12 23:40:01 +01:00
Simon Ser
dcca965fc1
Remove chatty debug log 2019-12-12 23:26:05 +01:00
Simon Ser
d8c20ddac2
Don't re-use prev alloc on composition layer change 2019-12-12 23:23:53 +01:00
Simon Ser
da59787f4a
Fix DEBUG logs printed when level is set to ERROR 2019-12-12 15:44:45 +01:00
Simon Ser
99ef3d5b2e
Unset plane->layer and layer->plane on destroy
This fixes a use-after-free when destroying a layer/plane early.
2019-12-06 15:06:14 +01:00
Simon Ser
333e454e98
test: make mock drmModeAtomicAddProperty return cursor
For consistency with the original libdrm function.
2019-11-29 11:06:57 +01:00
Simon Ser
e09ebdac27
test: add empty test
Make sure calling apply() with no layer works as expected.
2019-11-29 10:57:24 +01:00
Simon Ser
49b4f46762
Rename display.c to device.c
Forgot to do that when renaming the struct.
2019-11-29 01:51:22 +01:00
Simon Ser
ceb4a1ff9e
Replace liftoff_device_apply with liftoff_output_apply
Compositors need to drive multiple connectors, each with its own vblank timings.
For each device, there's one separate rendering loop per output.

It's not possible to call liftoff_device_apply each time we want to submit a new
frame to one output, because this could touch another's output state, submitting
a new frame there in the process. When the other output will submit a new frame,
it'll get EBUSY (can't submit two frames without waiting for vblank).

Closes: https://github.com/emersion/libliftoff/issues/21
2019-11-24 18:13:40 +01:00
Simon Ser
ef75ba26e0
Don't re-use previous allocation if a layer has been removed
Start from scratch since we may be able to come up with a better allocation
(if the layer made another layer fall back to composition for instance).

Closes: https://github.com/emersion/libliftoff/issues/30
2019-11-24 13:25:59 +01:00
Simon Ser
44d65288d7
Fixup display → device bulk rename
I managed to do a bit of a mess here.

Fixes: b0e2b083f9 ("Rename display to device")
2019-11-24 13:07:12 +01:00
Simon Ser
b0e2b083f9
Rename display to device
"Display" can also mean "screen"/"monitor", so it's kind of confusing for
this usage.
2019-11-24 12:59:10 +01:00
Simon Ser
5f39331f78
Keep track of the update frequency of each layer
Keep track of the number of layer updates per 60 page-flips.

We could implement a more fine-grained tracking, for instance with a sliding
window. However it's a lot more complex than the current solution and the gains
are not clear. I'd prefer to keep the current solution and experiment with other
solutions once we have a good test-bed.

References: https://github.com/emersion/libliftoff/issues/22
2019-11-15 21:43:44 +01:00
Matt Hoosier
78cc612f10 example: improve CRTC search algorithm
Add a fallback case for finding an eligible CRTC for the
selected connector. The encoder picked may not have been
wired up to that connector by the previous DRM master.
2019-11-08 00:08:06 +01:00
Simon Ser
d51e2fb2fe
test/libdrm_mock: bump resource limitations
Bump the maximum number of layers and properties to allow more aggressive
benchmarking.
2019-10-30 21:16:42 +01:00
Simon Ser
8272b61150
test: add benchmark
This is a pretty basic benchmark measuring the time spent in
liftoff_display_apply.

The current behaviour tries to reproduce the worst case scenario: layers don't
intersect and one plane is incompatible with all layers.
2019-10-30 21:16:42 +01:00
Simon Ser
af36f762ca
log: reset log callback to default when NULL is passed 2019-10-30 20:52:30 +01:00
Simon Ser
5faa1e466b
Remove outdated TODO 2019-10-30 20:45:15 +01:00
Simon Ser
30073e5295
test: add a new test for layer priority
This test continuously updates a layer's FB for some time, and keeps another
layer static. The continously updated layer should be put in a plane.

The test is disabled for now because priorities aren't implemented yet.
2019-10-30 20:41:25 +01:00
Simon Ser
b06596085d
example/multi-output: new example
This example sets up libliftoff with multiple outputs, with a fixed number of
layers per output.
2019-10-30 18:54:21 +01:00
Simon Ser
db6366dc25
Add build-* to .gitignore 2019-10-19 13:46:11 +03:00
Simon Ser
ef29d341cb
Move plane allocation algorithm to alloc.c
And move plane-related functions to plane.c.
2019-10-19 13:43:09 +03:00
Simon Ser
ba80e32054
Introduce liftoff_log_errno
Like perror, but uses the liftoff logging infrastructure.
2019-10-19 13:35:14 +03:00
Simon Ser
dc9c39ed5c
Introduce display_test_commit
This function wraps drmModeAtomicCommit and handles error conditions and
logging.
2019-10-19 13:15:34 +03:00