freedreno: clamp priority based on # of rings

In case of a kernel that is new enough to support multiple submit-
queues, but with an adreno generation which doesn't support multiple
prioritized ringbuffers, we'd attempt to open a submit-queue with
prio=1 (medium), which is rejected by the kernel.

This could happen either w/ an older mesa (which uses fd_pipe_new())
or a newer mesa which defaults to prio=1 if no pipe context priority
flags are set.

The simple answer to fix both cases is to clamp the requested priority
according to the number of rings.  This might not do exactly what you
want, if we hypothetically had 2 rings (it would result in requested
medium priority being high priority instead of low priority).  But the
number of rings (for hw gen's that support this) is purely a software
construct, so the easy answer there is to have the kernel advertise at
least 3 rings if it supports more than one.  There isn't really any
reason to do otherwise.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
main
Rob Clark 2018-01-24 15:08:46 -05:00
parent 82aef5f0cb
commit 6f0f6cee5e
2 changed files with 18 additions and 12 deletions

View File

@ -49,6 +49,7 @@
#include "xf86atomic.h"
#include "util_double_list.h"
#include "util_math.h"
#include "freedreno_drmif.h"
#include "freedreno_ringbuffer.h"
@ -173,7 +174,6 @@ struct fd_bo {
time_t free_time; /* time when added to bucket-list */
};
#define ALIGN(v,a) (((v) + (a) - 1) & ~((a) - 1))
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define enable_debug 0 /* TODO make dynamic */

View File

@ -100,42 +100,48 @@ static int msm_pipe_wait(struct fd_pipe *pipe, uint32_t timestamp,
return 0;
}
static int open_submitqueue(struct fd_device *dev, uint32_t prio,
uint32_t *queue_id)
static int open_submitqueue(struct fd_pipe *pipe, uint32_t prio)
{
struct drm_msm_submitqueue req = {
.flags = 0,
.prio = prio,
};
uint64_t nr_rings = 1;
int ret;
if (fd_device_version(dev) < FD_VERSION_SUBMIT_QUEUES) {
*queue_id = 0;
if (fd_device_version(pipe->dev) < FD_VERSION_SUBMIT_QUEUES) {
to_msm_pipe(pipe)->queue_id = 0;
return 0;
}
ret = drmCommandWriteRead(dev->fd, DRM_MSM_SUBMITQUEUE_NEW, &req, sizeof(req));
msm_pipe_get_param(pipe, FD_NR_RINGS, &nr_rings);
req.prio = MIN2(req.prio, MAX2(nr_rings, 1) - 1);
ret = drmCommandWriteRead(pipe->dev->fd, DRM_MSM_SUBMITQUEUE_NEW,
&req, sizeof(req));
if (ret) {
ERROR_MSG("could not create submitqueue! %d (%s)", ret, strerror(errno));
return ret;
}
*queue_id = req.id;
to_msm_pipe(pipe)->queue_id = req.id;
return 0;
}
static void close_submitqueue(struct fd_device *dev, uint32_t queue_id)
static void close_submitqueue(struct fd_pipe *pipe, uint32_t queue_id)
{
if (fd_device_version(dev) < FD_VERSION_SUBMIT_QUEUES)
if (fd_device_version(pipe->dev) < FD_VERSION_SUBMIT_QUEUES)
return;
drmCommandWrite(dev->fd, DRM_MSM_SUBMITQUEUE_CLOSE, &queue_id, sizeof(queue_id));
drmCommandWrite(pipe->dev->fd, DRM_MSM_SUBMITQUEUE_CLOSE,
&queue_id, sizeof(queue_id));
}
static void msm_pipe_destroy(struct fd_pipe *pipe)
{
struct msm_pipe *msm_pipe = to_msm_pipe(pipe);
close_submitqueue(pipe->dev, msm_pipe->queue_id);
close_submitqueue(pipe, msm_pipe->queue_id);
free(msm_pipe);
}
@ -193,7 +199,7 @@ drm_private struct fd_pipe * msm_pipe_new(struct fd_device *dev,
INFO_MSG(" Chip-id: 0x%08x", msm_pipe->chip_id);
INFO_MSG(" GMEM size: 0x%08x", msm_pipe->gmem);
if (open_submitqueue(dev, prio, &msm_pipe->queue_id))
if (open_submitqueue(pipe, prio))
goto fail;
return pipe;