From patchwork Wed Aug 19 00:58:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyungwon Hwang X-Patchwork-Id: 7034331 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 B55C69F358 for ; Wed, 19 Aug 2015 00:59:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B1C5020569 for ; Wed, 19 Aug 2015 00:59:00 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 9299A20751 for ; Wed, 19 Aug 2015 00:58:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A00706E73B; Tue, 18 Aug 2015 17:58:58 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id E06856E732 for ; Tue, 18 Aug 2015 17:58:53 -0700 (PDT) Received: from epcpsbgr5.samsung.com (u145.gpu120.samsung.co.kr [203.254.230.145]) by mailout1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NTB035NQ1E3C810@mailout1.samsung.com> for dri-devel@lists.freedesktop.org; Wed, 19 Aug 2015 09:58:51 +0900 (KST) Received: from epcpsbgm2new.samsung.com ( [172.20.52.113]) by epcpsbgr5.samsung.com (EPCPMTA) with SMTP id 63.BD.17770.BC4D3D55; Wed, 19 Aug 2015 09:58:51 +0900 (KST) X-AuditID: cbfee691-f79ca6d00000456a-80-55d3d4cbe301 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id 6E.14.07062.BC4D3D55; Wed, 19 Aug 2015 09:58:51 +0900 (KST) Received: from localhost.localdomain.localdomain ([10.252.82.145]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NTB0003C1DZWBK0@mmp1.samsung.com>; Wed, 19 Aug 2015 09:58:51 +0900 (KST) From: Hyungwon Hwang To: dri-devel@lists.freedesktop.org, human.hwang@samsung.com Subject: [PATCH 6/6] modetest: add atomic page flip support Date: Wed, 19 Aug 2015 09:58:44 +0900 Message-id: <1439945924-22630-6-git-send-email-human.hwang@samsung.com> X-Mailer: git-send-email 2.4.3 In-reply-to: <1439945924-22630-1-git-send-email-human.hwang@samsung.com> References: <1439945924-22630-1-git-send-email-human.hwang@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOLMWRmVeSWpSXmKPExsWyRsSkUPf0lcuhBlevaFtc+fqezWLpjD5W ByaP+93HmTz6tqxiDGCK4rJJSc3JLEst0rdL4Mo49mwWW8F/vYqZ71YxNzA+VO1i5OSQEDCR 2NyznhnCFpO4cG89WxcjF4eQwApGiQt33jLDFF2e8BwqsZRR4vSLnewQThuTxPKnT1hAqtgE 9CQWXPsBlODgEBGwkZhzMQPEFAYyb64Fq2ARUJU4vqcRbCavgLtE1/PjjBDz5STOrf8CVsMp 4CGxYvtjNhBbCKhm57+TTCCrJAQus0m8ObCRHWKQgMS3yYdYQOZLCMhKbDoAdaekxMEVN1gm MAotYGRYxSiaWpBcUJyUXmSqV5yYW1yal66XnJ+7iREYfqf/PZu4g/H+AetDjAIcjEo8vDO2 XQ4VYk0sK67MPcRoCrRhIrOUaHI+MMjzSuINjc2MLExNTI2NzC3NlMR5daR/BgsJpCeWpGan phakFsUXleakFh9iZOLglGpgDDaxrb0YEnf39PSHtYcf7d94SawgT8XrmEv1we2h8xMvZ6Qn aj4JPWOz59K8J5d8gusDT5v7vnjt+dZfedGeW7OZFDumrT17vWzR8f/fmk/LznPb8e3M37Vx us+iVXb9enxohvfS2Rcv/XmfopHd/0FR+fT0G9uVl2uuLXONufZIS2Oy7pOka8FKLMUZiYZa zEXFiQDO+wrcOgIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrCLMWRmVeSWpSXmKPExsVy+t9jAd3TVy6HGux8qWZx5et7NoulM/pY HZg87ncfZ/Lo27KKMYApqoHRJiM1MSW1SCE1Lzk/JTMv3VbJOzjeOd7UzMBQ19DSwlxJIS8x N9VWycUnQNctMwdogZJCWWJOKVAoILG4WEnfDtOE0BA3XQuYxghd35AguB4jAzSQsIYx49iz WWwF//UqZr5bxdzA+FC1i5GTQ0LAROLyhOdsELaYxIV764FsLg4hgaWMEqdf7GSHcNqYJJY/ fcICUsUmoCex4NoPoAQHh4iAjcScixkgpjCQeXMtWAWLgKrE8T2NzCA2r4C7RNfz44wQ8+Uk zq3/AlbDKeAhsWL7Y7C9QkA1O/+dZJrAyLOAkWEVo0RqQXJBcVJ6rlFearlecWJucWleul5y fu4mRnCIP5PewXh4l/shRgEORiUe3hnbLocKsSaWFVfmHmKU4GBWEuH9uRMoxJuSWFmVWpQf X1Sak1p8iNEU6LCJzFKiyfnA+MsriTc0NjEzsjQyN7QwMjZXEufVN9kUKiSQnliSmp2aWpBa BNPHxMEp1cC4Tvjvijl8i+u/XNBb+UDzs/mhXC3F/TM3B9co9eo8nq1z3e1ZHuf+a079z7zn rGFWzDhzqfx25Mfqmwmrjh4ojZp02NLQ0Gr/1dMeNx+s3RT/dNJ7iYme7yMuV59wY39ifPGh 7VQlpzR+5sjrUp1vn2tryJbHtfxI7Py+r8WDv+WomRy3tKeiEktxRqKhFnNRcSIAc1nFv4cC AAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-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.6 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 -W option with the plane id for testing atomic page flipping. Signed-off-by: Hyungwon Hwang --- tests/modetest/modetest.c | 150 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 147 insertions(+), 3 deletions(-) diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index bf9222d..d1b7dc4 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -719,6 +719,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 { @@ -1446,6 +1450,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-W ::\tset property\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"); @@ -1637,7 +1642,137 @@ static void atomic_modeset(struct device *dev, drmModeAtomicReqPtr req, drmModeAtomicCommit(dev->fd, req, flags, NULL); } -static char optstr[] = "acdD:efM:P:ps:Cvw:W:"; +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; + + pipe = (struct pipe_arg *)(unsigned long)data; + + 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++; + + req = drmModeAtomicAlloc(); + + drmModeAtomicAddProperty(req, pipe->plane_id, pipe->fb_obj_id, new_fb_id); + + flags = DRM_MODE_PAGE_FLIP_EVENT; + drmModeAtomicCommit(fd, req, flags, pipe); + + 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 int atomic_test_page_flip(struct device *dev, drmModeAtomicReqPtr req, + struct resources *res, unsigned int plane_id) +{ + struct bo *other_bo; + unsigned int other_fb_id; + struct pipe_arg *pipe = NULL; + drmEventContext evctx; + uint32_t flags = 0, fb_obj_id = 0, pixel_format; + uint64_t width, height; + int ret; + + if (!is_atomic_obj_in_request(req, plane_id)) + return -1; + + fb_obj_id = get_atomic_plane_prop_id(res, plane_id, "FB_ID"); + if (!fb_obj_id) + return -1; + + width = get_atomic_plane_prop_value_in_request(req, res, + plane_id, "SRC_W"); + height = get_atomic_plane_prop_value_in_request(req, res, + plane_id, "SRC_H"); + pixel_format = DRM_FORMAT_XRGB8888; + + ret = allocate_fb(dev, req, res, width, height, pixel_format, + PATTERN_TILES, &other_bo, &other_fb_id); + if (ret < 0) + return ret; + + ret = drmModeAtomicAddProperty(req, plane_id, fb_obj_id, + other_fb_id); + if (ret < 0) + goto err; + + if (!fb_obj_id) { + fprintf(stderr, "page flipping requires at least one plane setting.\n"); + return -1; + } + + pipe = drmMalloc(sizeof *pipe); + + gettimeofday(&pipe->start, NULL); + pipe->swap_count = 0; + pipe->plane_id = 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) + goto err_rmfb; + + memset(&evctx, 0, sizeof evctx); + evctx.version = DRM_EVENT_CONTEXT_VERSION; + 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; + int ret; + + 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_rmfb: + drmFree(pipe); + drmModeRmFB(dev->fd, other_fb_id); +err: + bo_destroy(other_bo); + + return 0; +} + +static char optstr[] = "acdD:efM:P:ps:CvV:w:W:"; int main(int argc, char **argv) { @@ -1651,7 +1786,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; int count = 0, plane_count = 0; unsigned int prop_count = 0; struct pipe_arg *pipe_args = NULL; @@ -1732,6 +1867,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); @@ -1788,7 +1928,7 @@ int main(int argc, char **argv) return -1; } - if (test_vsync && !count) { + if (test_vsync && (!count && !req)) { fprintf(stderr, "page flipping requires at least one -s option.\n"); return -1; } @@ -1818,6 +1958,10 @@ int main(int argc, char **argv) if (req) { atomic_modeset(&dev, req, dev.resources); + if (test_vsync) + atomic_test_page_flip(&dev, req, dev.resources, + flip_plane_id); + getchar(); } else { for (i = 0; i < prop_count; ++i)