From patchwork Wed Sep 23 02:45:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyungwon Hwang X-Patchwork-Id: 7247081 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5D8A59F372 for ; Wed, 23 Sep 2015 02:45:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3ACC32089F for ; Wed, 23 Sep 2015 02:45:30 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id EE70B20A8C for ; Wed, 23 Sep 2015 02:45:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0CE926EBBD; Tue, 22 Sep 2015 19:45:28 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by gabe.freedesktop.org (Postfix) with ESMTPS id A9DA66EBB8 for ; Tue, 22 Sep 2015 19:45:23 -0700 (PDT) Received: from epcpsbgr1.samsung.com (u141.gpu120.samsung.co.kr [203.254.230.141]) by mailout3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NV302254ZNK4T10@mailout3.samsung.com> for dri-devel@lists.freedesktop.org; Wed, 23 Sep 2015 11:45:20 +0900 (KST) Received: from epcpsbgm2new.samsung.com ( [172.20.52.112]) by epcpsbgr1.samsung.com (EPCPMTA) with SMTP id A8.8B.05274.04212065; Wed, 23 Sep 2015 11:45:20 +0900 (KST) X-AuditID: cbfee68d-f79ae6d00000149a-b3-56021240999b Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id 4E.08.18629.04212065; Wed, 23 Sep 2015 11:45:20 +0900 (KST) Received: from localhost.localdomain.localdomain ([10.252.82.145]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NV300GR1ZNG6Y00@mmp2.samsung.com>; Wed, 23 Sep 2015 11:45:19 +0900 (KST) From: Hyungwon Hwang To: dri-devel@lists.freedesktop.org, ppaalanen@gmail.com, emil.l.velikov@gmail.com Subject: [PATCH v3 3/3] modetest: add atomic page flip support Date: Wed, 23 Sep 2015 11:45:14 +0900 Message-id: <1442976314-5792-3-git-send-email-human.hwang@samsung.com> X-Mailer: git-send-email 2.4.3 In-reply-to: <1442976314-5792-1-git-send-email-human.hwang@samsung.com> References: <1442976314-5792-1-git-send-email-human.hwang@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrILMWRmVeSWpSXmKPExsWyRsSkQNdBiCnMYPNjAYsrX9+zWey5eo/J YumMPlaL1rZqBxaPnbPusnvc7z7O5NG3ZRVjAHMUl01Kak5mWWqRvl0CV8a3jU1MBc2eFcf2 LGZpYLxu1cXIwSEhYCJx4S9PFyMnkCkmceHeerYuRi4OIYEVjBIX301kgkiYSPydNwHMFhKY xSjRMdMVoqiNSeLS1zvsIAk2AT2JBdd+gNkiAiESG7ZsBLOZBXQkrt/cwgxiCwvYSez6up4F xGYRUJV49WQOWA2vgJvEteVTmCGWyUmcW/8FrIZTwF1iXcMtqMVuErc//GEFWSwh8JlN4uGZ l6wQgwQkvk0+xALxjazEpgNQcyQlDq64wTKBUXgBI8MqRtHUguSC4qT0IkO94sTc4tK8dL3k /NxNjMCQPf3vWe8OxtsHrA8xCnAwKvHwPvjCGCbEmlhWXJl7iNEUaMNEZinR5HxgZOSVxBsa mxlZmJqYGhuZW5opifMqSv0MFhJITyxJzU5NLUgtii8qzUktPsTIxMEp1cDYnXDx/M55T0Pt bOIX2f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Filter-Loop: Reflected X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for atomic page flip. User can specify -V option with the plane id for testing atomic page flipping. Signed-off-by: Hyungwon Hwang --- tests/modetest/modetest.c | 195 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 187 insertions(+), 8 deletions(-) diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index bc5a227..418acaa 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -747,6 +747,10 @@ struct pipe_arg { struct timeval start; int swap_count; + + /* for atomic modeset */ + uint32_t plane_id; + uint32_t fb_obj_id; }; struct plane_arg { @@ -1477,7 +1481,7 @@ static int parse_property(struct property_arg *p, const char *arg) static void usage(char *name) { - fprintf(stderr, "usage: %s [-acDdefMPpsCvw]\n", name); + fprintf(stderr, "usage: %s [-acDdefMPpsCvVw]\n", name); fprintf(stderr, "\tA: supported in atomic modeset\n"); fprintf(stderr, "\tL: supported in legacy modeset\n"); @@ -1492,6 +1496,7 @@ static void usage(char *name) fprintf(stderr, "\n Atomic Test options: [A]\n\n"); fprintf(stderr, "\t-a\tuse atomic modeset\n"); + fprintf(stderr, "\t-V \ttest vsynced page flipping\n"); fprintf(stderr, "\n Legacy test options: [L]\n\n"); fprintf(stderr, "\t-P :x[++][*][@]\tset a plane\n"); @@ -1641,7 +1646,8 @@ static int allocate_fb(int fd, drmModeAtomicReqPtr req, struct resources *res, static int allocate_fbs(struct device *dev, drmModeAtomicReqPtr req, struct resources *res, struct property_arg *prop_args, - unsigned int prop_count, struct bo **bo, uint32_t *fb_id) + unsigned int prop_count, struct bo **bo, uint32_t *fb_id, + uint32_t flip_plane_id) { uint32_t plane_id, fb_obj_id, pixel_format; uint64_t width, height; @@ -1652,6 +1658,9 @@ static int allocate_fbs(struct device *dev, drmModeAtomicReqPtr req, if (!is_obj_id_in_prop_args(prop_args, prop_count, plane_id)) continue; + if (flip_plane_id == plane_id) + dev->mode.fb_id = fb_id[i]; + fb_obj_id = get_plane_prop_id(res, plane_id, "FB_ID"); if (!fb_obj_id) { fprintf(stderr, "plane(%u) does not exist\n", plane_id); @@ -1714,8 +1723,162 @@ static void deallocate_fbs(int fd, int num_planes, uint32_t *fb_id, struct bo ** } } +static void atomic_page_flip_handler(int fd, unsigned int frame, unsigned int sec, + unsigned int usec, void *data) +{ + static drmModeAtomicReqPtr req = NULL; + unsigned int new_fb_id; + struct timeval end; + struct pipe_arg *pipe; + double t; + uint32_t flags = 0; + int ret; + + pipe = (struct pipe_arg *)(unsigned long)data; + + req = drmModeAtomicAlloc(); + if (!req) { + fprintf(stderr, "failed to allocate drmModeAtomicReqPtr\n"); + return; + } + + if (pipe->current_fb_id == pipe->fb_id[0]) + new_fb_id = pipe->fb_id[1]; + else + new_fb_id = pipe->fb_id[0]; + + pipe->current_fb_id = new_fb_id; + pipe->swap_count++; + + ret = drmModeAtomicAddProperty(req, pipe->plane_id, pipe->fb_obj_id, new_fb_id); + if (ret < 0) { + fprintf(stderr, "failed to add atomic property in pageflip handler\n"); + drmModeAtomicFree(req); + return; + } + + flags = DRM_MODE_PAGE_FLIP_EVENT; + ret = drmModeAtomicCommit(fd, req, flags, pipe); + if (ret < 0) { + fprintf(stderr, "failed to commit in pageflip handler\n"); + drmModeAtomicFree(req); + return; + } + + if (pipe->swap_count == 60) { + gettimeofday(&end, NULL); + t = end.tv_sec + end.tv_usec * 1e-6 - + (pipe->start.tv_sec + pipe->start.tv_usec * 1e-6); + fprintf(stderr, "freq: %.02fHz\n", pipe->swap_count / t); + pipe->swap_count = 0; + pipe->start = end; + } + + drmModeAtomicFree(req); +} + +static void atomic_test_page_flip(struct device *dev, drmModeAtomicReqPtr req, + struct resources *res, struct property_arg *prop_args, + unsigned int prop_count, unsigned int flip_plane_id) +{ + struct bo *other_bo; + unsigned int other_fb_id; + struct pipe_arg pipe; + drmEventContext evctx; + uint32_t flags = 0, fb_obj_id = 0, pixel_format; + uint64_t width, height; + int ret; + + fb_obj_id = get_plane_prop_id(res, flip_plane_id, "FB_ID"); + if (!fb_obj_id) { + fprintf(stderr, "plane(%u) does not exist\n", flip_plane_id); + return; + } + + if (!is_obj_id_in_prop_args(prop_args, prop_count, flip_plane_id)) { + fprintf(stderr, "plane (%u) must be set for pageflip\n", flip_plane_id); + return; + } + + ret = get_value_in_prop_args(prop_args, prop_count, flip_plane_id, + "SRC_W", &width); + if (ret < 0) { + fprintf(stderr, "SRC_W for plane (%u) must be set\n", flip_plane_id); + return; + } + + ret = get_value_in_prop_args(prop_args, prop_count, flip_plane_id, + "SRC_H", &height); + if (ret < 0) { + fprintf(stderr, "SRC_H for plane (%u) must be set\n", flip_plane_id); + return; + } + + pixel_format = DRM_FORMAT_XRGB8888; + + ret = allocate_fb(dev->fd, req, res, width, height, pixel_format, + PATTERN_TILES, &other_bo, &other_fb_id); + if (ret < 0) + return; + + ret = drmModeAtomicAddProperty(req, flip_plane_id, fb_obj_id, + other_fb_id); + if (ret < 0) { + fprintf(stderr, "failed to add atomic property for pageflip"); + goto err; + } + + gettimeofday(&pipe.start, NULL); + pipe.swap_count = 0; + pipe.plane_id = flip_plane_id; + pipe.fb_obj_id = fb_obj_id; + pipe.fb_id[0] = dev->mode.fb_id; + pipe.fb_id[1] = other_fb_id; + pipe.current_fb_id = other_fb_id; + + flags = DRM_MODE_PAGE_FLIP_EVENT; + + ret = drmModeAtomicCommit(dev->fd, req, flags, &pipe); + if (ret < 0) { + fprintf(stderr, "failed to commit for pageflip\n"); + goto err; + } + + memset(&evctx, 0, sizeof evctx); + evctx.version = 2; + evctx.vblank_handler = NULL; + evctx.page_flip_handler = atomic_page_flip_handler; + + while (1) { + struct timeval timeout = { .tv_sec = 3, .tv_usec = 0 }; + fd_set fds; + + FD_ZERO(&fds); + FD_SET(0, &fds); + FD_SET(dev->fd, &fds); + ret = select(dev->fd + 1, &fds, NULL, NULL, &timeout); + + if (ret <= 0) { + fprintf(stderr, "select timed out or error (ret %d)\n", + ret); + continue; + } else if (FD_ISSET(0, &fds)) { + break; + } + + drmHandleEvent(dev->fd, &evctx); + } + +err: + drmModeRmFB(dev->fd, other_fb_id); + bo_destroy(other_bo); + + return; +} + static int atomic_modeset(struct device *dev, drmModeAtomicReqPtr req, - struct property_arg *prop_args, unsigned int prop_count) + struct property_arg *prop_args, unsigned int prop_count, + int test_vsync, int flip_plane_id) { unsigned int num_planes; const char *obj_type = NULL; @@ -1753,7 +1916,8 @@ static int atomic_modeset(struct device *dev, drmModeAtomicReqPtr req, return -1; } - ret = allocate_fbs(dev, req, dev->resources, prop_args, prop_count, bo, fb_id); + ret = allocate_fbs(dev, req, dev->resources, prop_args, prop_count, bo, + fb_id, flip_plane_id); if (ret < 0) { free(fb_id); free(bo); @@ -1769,6 +1933,10 @@ static int atomic_modeset(struct device *dev, drmModeAtomicReqPtr req, return ret; } + if (test_vsync) + atomic_test_page_flip(dev, req, dev->resources, + prop_args, prop_count, flip_plane_id); + getchar(); deallocate_fbs(dev->fd, num_planes, fb_id, bo); @@ -1778,7 +1946,7 @@ static int atomic_modeset(struct device *dev, drmModeAtomicReqPtr req, return 0; } -static char optstr[] = "acdD:efM:P:ps:Cvw:"; +static char optstr[] = "acdD:efM:P:ps:CvV:w:"; int main(int argc, char **argv) { @@ -1792,7 +1960,7 @@ int main(int argc, char **argv) const char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx", "omapdrm", "exynos", "tilcdc", "msm", "sti", "tegra", "imx-drm", "rockchip", "atmel-hlcdc" }; char *device = NULL; char *module = NULL; - unsigned int i; + unsigned int i, flip_plane_id = 0; unsigned int count = 0, plane_count = 0; unsigned int prop_count = 0; struct pipe_arg *pipe_args = NULL; @@ -1873,6 +2041,11 @@ int main(int argc, char **argv) case 'v': test_vsync = 1; break; + case 'V': + if (sscanf(optarg, "%u", &flip_plane_id) != 1) + usage(argv[0]); + test_vsync = 1; + break; case 'w': prop_args = realloc(prop_args, (prop_count + 1) * sizeof *prop_args); @@ -1925,11 +2098,16 @@ int main(int argc, char **argv) return -1; } - if (test_vsync && !count) { + if (test_vsync && (!count && !is_atomic)) { fprintf(stderr, "page flipping requires at least one -s option.\n"); return -1; } + if (test_vsync && is_atomic && flip_plane_id == 0) { + fprintf(stderr, "fliping plane id must be set for atomic pageflip\n"); + return -1; + } + if (test_cursor && !cursor_supported()) { fprintf(stderr, "hw cursor not supported by drm.\n"); return -1; @@ -1974,7 +2152,8 @@ int main(int argc, char **argv) dump_resource(&dev, framebuffers); if (is_atomic) { - ret = atomic_modeset(&dev, req, prop_args, prop_count); + ret = atomic_modeset(&dev, req, prop_args, prop_count, + test_vsync, flip_plane_id); if (ret < 0) fprintf(stderr, "failed to atomic modeset (%s)\n", strerror(errno));