[RFC 0/9] nuclear pageflip

Ville Syrjälä ville.syrjala at linux.intel.com
Fri Sep 14 05:50:01 PDT 2012


On Thu, Sep 13, 2012 at 11:35:59AM -0500, Rob Clark wrote:
> On Thu, Sep 13, 2012 at 9:29 AM, Ville Syrjälä
> <ville.syrjala at linux.intel.com> wrote:
> > On Thu, Sep 13, 2012 at 08:39:54AM -0500, Rob Clark wrote:
> >> On Thu, Sep 13, 2012 at 3:40 AM, Ville Syrjälä
> >> <ville.syrjala at linux.intel.com> wrote:
> >> > On Wed, Sep 12, 2012 at 02:40:56PM -0500, Rob Clark wrote:
> >> >> On Wed, Sep 12, 2012 at 1:58 PM, Ville Syrjälä
> >> >> <ville.syrjala at linux.intel.com> wrote:
> >> >> > On Wed, Sep 12, 2012 at 01:00:19PM -0500, Clark, Rob wrote:
> >> >> >> On Wed, Sep 12, 2012 at 12:27 PM, Ville Syrjälä
> >> >> >> <ville.syrjala at linux.intel.com> wrote:
> >> >> >> > On Wed, Sep 12, 2012 at 10:48:16AM -0500, Rob Clark wrote:
> >> >> >> >> But I think we could still do this w/ one ioctl per crtc for atomic-pageflip.
> >> >> >> >
> >> >> >> > We could, if we want to sacrifice the synced multi display case. I just
> >> >> >> > think it might be a real use case at some point. IVI feels like the most
> >> >> >> > likely short term cadidate to me, but perhaps someone would finally
> >> >> >> > introduce some new style phone/tablet thingy. I have seen
> >> >> >> > concepts/prototypes of such multi display gadgets in the past, but the
> >> >> >> > industry apparently got a bit stuck on the rectangular slab with
> >> >> >> > touchscreen on one side design.
> >> >> >>
> >> >> >> I could be wrong, but I think IVI the screens would normally be too
> >> >> >> far apart to matter?
> >> >> >
> >> >> > I was thinking of something like a display on the dash that normally
> >> >> > sits low with only a small sliver visible, and extends upwards when
> >> >> > you fire up a movie player for example. Internally it could be made
> >> >> > up of two displays for power savings purposes.
> >> >> >
> >> >> >> Anyways, it is really only a problem if you can't do two ioctl()s
> >> >> >> within one vblank period. If it actually turns out to be a real
> >> >> >> problem,
> >> >> >
> >> >> > Well exactly that's the problem this whole atomic pageflip stuff is
> >> >> > trying to tackle, no? ;)
> >> >> >
> >> >> >> we could always add later an ioctl that takes an array of
> >> >> >> 'struct drm_mode_crtc_atomic_page_flip's.  I'm not sure if this is
> >> >> >> really useful or not.. but maybe I'm thinking too much about how
> >> >> >> weston does it's rendering of different output's independently.
> >> >> >
> >> >> > I'm just now thinking of surfaceflinger's way of doing things, with
> >> >> > its prepare and commit phases. If you need to issue two ioctls to handle
> >> >> > cloned displays, then you can end up in a somewhat funky situation.
> >> >> >
> >> >> > Let's say you have a video overlay in use (one each display naturally),
> >> >> > and you increase the downscaling factor enough so that you now have
> >> >> > enough memory bandwith to support only one overlay. With independent
> >> >> > check ioctls for each display, you never have the full device state
> >> >> > available in the kernel, so each check succeeds during the prepare
> >> >> > phase. So you decide that you can keep using the video overlays.
> >> >> >
> >> >> > You then proceed to commit the state, but after the first display has
> >> >> > been commited you get an error when trying to commit the second one.
> >> >> > What can you do now? The only option is to keep displaying the old
> >> >> > frame on the other displays for some time longer, and then on the
> >> >> > next frame you can switch to GPU composition. But on the next frame you
> >> >> > perhaps no longer need to use GPU composition, but since you can't
> >> >> > verify that in the prepare phase, you have no other option but to use
> >> >> > GPU composition.
> >> >> >
> >> >> > So when you run into a configuration that can be supported only
> >> >> > partially, you get animation stalls on some displays due to skipped
> >> >> > frames, and you always have to fall back to GPU composition for the
> >> >> > next frame.
> >> >> >
> >> >> > If on the other hand you would check the whole state in one ioctl,
> >> >> > you'd get the error in the first prepare phase, and could fall back
> >> >> > to GPU composition immediately.
> >> >> >
> >> >> > Am I too much of a perfectionst in considering such things? I don't
> >> >> > think so, but perhaps other people disagree.
> >> >>
> >> >> Ok, if you have a case where the state of the two crtc's are not
> >> >> actually independent, then I think you have a valid point.
> >> >>
> >> >> I'm not quite sure what userspace would do about it, though.. for the
> >> >> general case where vsync isn't locked, and you can't even necessarily
> >> >> assume vsync period is the same, then I don't really think you want to
> >> >> couple rendering to the displays.
> >> >
> >> > I would say this is going to be the most common use case if you consider
> >> > just the number of shipping devices. It's pretty much what every Android
> >> > phone/tablet with a HDMI port has to do.
> >>
> >> bleh, surfaceflinger kinda sucks then..
> >
> > Why? This use case is not enforced by surfaceflinger, it's just the use
> > case most devices would have.
> >
> > I don't think there's anything wrong with the way surfaceflinger is designed
> > with the prepare and commit phases. How else would you do it?
> 
> well, maybe I misunderstood how surfaceflinger works, but it sounded
> like it has one prepare/commit phase across outputs, vs what weston
> compositor does where each output is rendered and flipped
> independently at the rate of that particular output.  If the two
> outputs just happen to be vsync aligned, you would end up flipping at
> the same time, but if the are not locked you don't have any artificial
> constraint in the rendering/flipping.

OK so it's purely a pull based model, whereas surfaceflinger is more
push based. 

I suppose it might be possible to make surfaceflinger support a pull
model by driving the compositor loop through a combined signal from
multiple outputs. But IIRC it did have some timing related code in
there somewhere, so it might not be happy about it. It might also
affect the clients' rendering speed since the compositor would be
pulling their buffers from queue at non-constant speed. I don't
remember the details of the buffer management very well, so I can't be
sure though. But I probably wouldn't bother trying this, since the
straightforward approach is so simple, and the results are reasonably
good.

The pull model does seem more flexible. But it does require a bit of
extra complexity in the compositor to avoid compositing the same scene
multiple times needlessly when multiple cloned displays are involved. 
I suppose ideally you'd want to recompose for each display to minimize
visible latency, but from power usage POV it may not be a good idea.

> >> >> >From userspace API, I guess something like:
> >> >>
> >> >> struct drm_mode_crtc_atomic_page_flip {
> >> >>       uint32_t flags;
> >> >>       uint32_t count_crtcs;
> >> >>       uint64_t crtc_ids_ptr;  /* array of uint32_t */
> >> >>       uint64_t count_props_ptr; /* array of uint32_t, # of prop's per crtc */
> >> >>       uint64_t props_ptr;  /* ptr to array of drm_mode_obj_set_property */
> >> >>       uint64_t user_data;
> >> >> };
> >> >
> >> > Starting to look much like my drm_mode_atomic struct :)
> >> >
> >> > Let's compare:
> >> >
> >> > struct drm_mode_atomic {
> >> >         __u32 flags;
> >> >         __u32 count_objs;
> >> >         __u64 objs_ptr;
> >> >         __u64 count_props_ptr;
> >> >         __u64 props_ptr;
> >> >         __u64 prop_values_ptr;
> >> >         __u64 blob_values_ptr;
> >> > };
> >>
> >> well, you do miss userdata, I think
> >
> > Sure, because I didn't add the event stuff yet.
> 
> note that the test phase doesn't need vblank events, and also
> shouldn't -EBUSY if there is still a pending flip[*],

Right. Personally I'm not a fan of the EBUSY behaviour at all. Seems
a bit pointless since user space can take care of it via the event
mechanism. But I suppose you want it for omap so that you can avoid
having to write software workarounds to overcome the GO bit
limitations.

> so I'd propose
> that however we go about pageflip (one super-ioctl, or one per crtc),
> we could use the atomic-modeset ioctl for the test step

Yeah that seems reasonable. If we do that, then it doesn't matter that
much whether we have commit per pipe or not, except for the synced
displays case, which I'd still like to support if possible. At least
someone explicitly wanted such a feature in Medfield. I assume they
had a fairly compelling use case because they were able to convince
the hardware designers of the need.

> [*] this is one thing not correct still in my current patches.. the
> driver doesn't know the difference between test and real-flip at the
> point where it checks if there is a pending flip.
> 
> >> > One differences seem to be that you have a mix of SOA and AOS concepts
> >> > in yours, whereas mine is pure SOA.
> >>
> >> well, I was trying to re-use drm_mode_obj_set_property because that
> >> seemed to keep the code simple, and makes it more similar to existing
> >> set-property stuff.
> >
> > I sort of modelled mine after the way things are done by the various
> > getter ioctls. I don't like messing up my brain by mixing SOA
> > and AOS in the same place.
> 
> fair enough.. anyways, that was just a quick proposal in an email
> thread, we can tweak how the data is layed out

Sure. The layout isn't that important to me either. All the ioctl
structures are already ugly so we can't make the situation much
worse :)

> >> OTOH, maybe that doesn't really matter because
> >> userspace would normally be going through libdrm and not seeing the
> >> ioctl structs directly, so we could make the ioctl structs as ugly as
> >> we want.
> >>
> >> I'm a bit on the fence about how the pageflip ioctl should look, in
> >> particular about pageflip on multiple CRTCs.  I'd like to know the
> >> involved CRTC(s) upfront, as that seems to make error checking easier
> >> on the driver (in case of already pending flip).  Although I'll think
> >> a bit about alternatives.
> >
> > I don't see much point in iterating that information directly in begin().
> > You anyway get the same information during the set() operations. I
> > suppose you could save some effort by avoiding some state allocation in
> > begin(). But really, this seems like optimizing for the an uncommon error
> > case. You should not encounter it in practice unless your user space is
> > doing something silly.
> 
> well, it was more about trying to make the error checking easy to get
> right in the drivers.  But maybe it is easy enough to keep track of
> the involved crtc(s) and do the check in the atomic_test() step.
> 
> >> Also, if you pageflip on multiple CRTC's, should the be multiple
> >> vblank events, and multiple userdata's?
> >
> > That's a bit of an open question. I was considering several options:
> 
> the thing I like about one ioctl per crtc is that it avoids this whole
> question..
> 
> And, I think as long as you have to update multiple different scanout
> address registers, there is always going to be a race in multi-crtc
> flipping.  Having a single ioctl does make the race smaller.  I'm not
> sure how important that point is.

Which race?

> > 1) One event after the full operation is complete
> >  Not a good idea when you want to throttle based on a fast refreshing
> >  display but the system has also slow refreshing displays.
> >
> > 2) One event per pipe
> >  Seems reasonable. We could use a bitmask so that the user can ask for
> >  the event to be delivered only for specific pipes. I'm not sure whether
> >  multiple user_datas would be better, or just the one with user space
> >  taking care of refcounting it in case it's a pointer to some object.
> >
> > 3) One event per scanout engine
> >  Not sure this makes sense since the idea is anyway to do things
> >  atomically within the pipe.
> 
> well, if you aren't vsync locked, it isn't going to be atomic
> anyways.. and not vsync locked seems like the common case to me.

One reason why I considered the one event per scanout engine is that
some overlay implementations can have their own "vblank/flip done"
interrupt independent from the whole pipe. Such an interrupt would fire
as soon as the scan has passed over the overlay's visible region, even if
that happens to be well inside the crtc's active video region. It could
allow the rendering for the next frame to begin slightly earlier when
there's a shortage of buffers.

> >> Really the atomic-pageflip ioctl is pretty much a small part of the
> >> entire patchset, so I'm not really too much against changing it.  Most
> >> of the point of the patchset was to try to enhance properties to do
> >> what we need, and come up w/ a sane way to decouple state from the
> >> various kms objects to easily handle atomic commit or rollback.
> >
> > I agree 100% with this goal. Once the state would be split cleanly, we
> > could do stuff like keep the user and fbcon states totally separate.
> > Restoring the fbcon state would then trivial. Currently the fbcon
> > state as such doesn't really exist. IIRC you had some patches to reset
> > various bits of state at certain points just to work around this issue.
> 
> one minor point:  I was thinking the same thing but Daniel pointed out
> that we still have to deal w/ the potential case that the user
> unplugged one display and plugged a different display between leaving
> fbcon and restoring fbcon.  So we always have to deal with the
> potential for full modeset.  But maybe that is ok, we perhaps could
> just let the atomic_test() step fail in this case and then trigger
> full modeset?  I'm not quite sure, I haven't thought through this
> fully, but it does seem like there is potential to simplify things.
> At any rate, it isn't so important for the initial patchset, but it is
> worth thinking about when we get to the atomic-modeset part and
> figuring out how helpers, etc, fit in to this.

Yeah, the displays changing does pose a problem. I think ideally you'd
take the saved state, but instead of commiting it as is, you'd adjust
it to accomodate the new display layout.

> >> > Also your struct has a bunch of redundant data since
> >> > drm_mode_obj_set_property keeps repeating the object ID needlessly, and
> >> > crtc_ids_ptr is also just repeating information already present in
> >> > drm_mode_obj_set_property. drm_mode_obj_set_property further forces you
> >> > to pass in the object type, which is pretty much useless.
> >>
> >> well, not completely, the object-id/type could also be a plane
> >> attached to a crtc..
> >
> > Sure, but even that gets repeated needlessly for every prop.
> 
> well, for libdrm API, what made sense to me is just an array of
> property type+id+value..  libdrm *could* support this by sorting the
> props and flattening things out.  It would make the amount of data
> that is copy_from_user()'d a bit more compact.  But I am not sure that
> this is really worth worrying about.  Especially if you are just
> passing the values that have changed since last flip.  I'd lean
> towards keeping it simple rather than optimizing out a few bytes of
> copy_from_user().

Did you check the libdrm API I have? It frees the client from having to
collect any property arrays because that could turn into a realloc()
fest quite quickly. And the implementation itself is hidden inside libdrm
so if the linked list based implementation turns out insufficient it's
possible to change the data structrures.

> >> > Your version can't pass in blobs, which is going to be a problem
> >> > when you want to push in gamma tables/ramps and whatnot. Also I've been
> >> > considering that for atomic modesetting I'd pass display modes as blobs
> >> > too, since the display mode object IDs are currently hidden from user
> >> > space, and also the IDs are a bit volatile since the modes can be
> >> > shuffled around during EDID probing. I suppose one could try to fix
> >> > these display mode ID issues, and when you need to push in gamma tables
> >> > or other heavy weight data, you invent new types of drm objects to
> >> > describe them, and you pass them by ID as well.
> >>
> >> hmm, ok, I was wondering why you were supporting blobs, when existing
> >> setprop APIs where not.  Well, maybe it wouldn't be a bad idea to
> >> start by making existing setprop stuff support blobs.
> >
> > I wouldn't care about the existing APIs. Why would anyone use them when
> > the atomic API provides the same capability and more?
> 
> well, I guess there is no strong need to.. but it just seemed strange
> to require using the new API to set a single property.  Anyways, it
> could be that it is not worth worrying about.

It keeps the client code much simpler.

> Fwiw the way drm_ioctl() works, it should be possible to add new
> fields to an ioctl struct at the end, as long as zero has a sensible /
> backwards-compatible meaning.  Ie. old userspace w/ smaller struct on
> new kernel, the driver will just see the new fields memset to zero.
> New userspace on old kernel, drm_property_change_is_valid() would
> fail.

Really? Isn't the struct size encoded into the ioctl ID itself?

-- 
Ville Syrjälä
Intel OTC


More information about the dri-devel mailing list