From patchwork Sat Nov 22 05:37:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jasper St. Pierre" X-Patchwork-Id: 5358911 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 623D5C11AC for ; Sat, 22 Nov 2014 05:37:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4A8F62013A for ; Sat, 22 Nov 2014 05:37:23 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id D70D920127 for ; Sat, 22 Nov 2014 05:37:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 521A66E030; Fri, 21 Nov 2014 21:37:19 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com [209.85.220.54]) by gabe.freedesktop.org (Postfix) with ESMTP id 2F7346E030 for ; Fri, 21 Nov 2014 21:37:18 -0800 (PST) Received: by mail-pa0-f54.google.com with SMTP id fb1so6261206pad.41 for ; Fri, 21 Nov 2014 21:37:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mecheye.net; s=google; h=from:to:cc:subject:date:message-id; bh=oUlR62Ne43ie311ref8Cb+8kiuin9U6oq4Zw1NowRKQ=; b=I50bBQcFaPb8bhghD67KERCWNFwAsvJ7wFG0v0odbcthS4C7+jadG5aRXVcKd0jEvv MEkGWOxgvLCfJQikXkn0ePrh3igZW8kyz5yGQOfhVEVYSlt9ev1i0tzNYCltEdhzWss9 TypJgePyN+f0N8MfNcc37TeGZmd1EwiBV2doA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=oUlR62Ne43ie311ref8Cb+8kiuin9U6oq4Zw1NowRKQ=; b=UWJnnPfDRyNLIEVugMsYxeWh4TJxthE3gZin9wS+qWlsi+U4Fyto4bdjeeY+2WWy2K eCaYNVHqQWEFB8FUw47VtRaLt7jD1CuhfeOkpVPR5GRGChKfKHLpIw4YplTlJqMHpEMw dnxARUeNlJC1yRTlc2w3x0qMSqLNmryrYktNhWg7DH4B79pUj1XFNOiAqgSTkvnj1p8g 2EWqR8sK3hQETNFtgo5evJnrWrF0iFP9xofsfkOooQbaNOYuhwjENXeZnY6GbvSq6Q95 qEjcjGVrIPpcx2ejlNbkCERFpGZZJD8MjlVSNBEzIJDLkaHEs/EWFDdJ9NcQLGhWfoEX 0+RA== X-Gm-Message-State: ALoCoQlLzjMuS+kn0r+m5QJ48W3cJyVTPPBqnPRLFoi4RpgDRSrSnAKKL8mX8Ayw53sW718S1mbA X-Received: by 10.68.250.131 with SMTP id zc3mr13752569pbc.34.1416634637795; Fri, 21 Nov 2014 21:37:17 -0800 (PST) Received: from jstpierre-snappy.localdomain (c-69-181-181-60.hsd1.ca.comcast.net. [69.181.181.60]) by mx.google.com with ESMTPSA id c9sm6294916pdn.81.2014.11.21.21.37.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Nov 2014 21:37:17 -0800 (PST) From: "Jasper St. Pierre" To: dri-devel@lists.freedesktop.org Subject: [PATCH] modetest: Use threads for cursors instead of SIGALRM Date: Fri, 21 Nov 2014 21:37:12 -0800 Message-Id: <1416634632-19319-1-git-send-email-jstpierre@mecheye.net> X-Mailer: git-send-email 2.1.0 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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_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 fixes an issue when trying to use -v and -C together. When trying to read the page flip event, we are interrupted by the SIGALRM that comes in, and so we think we timed out when we simply got EINTR. While we could just loop checking for EINTR, SIGALRM is just bad idea to begin with, so just rewrite it to use a thread. --- tests/modetest/Makefile.am | 3 ++- tests/modetest/cursor.c | 57 +++++++++++++++++++++++----------------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/tests/modetest/Makefile.am b/tests/modetest/Makefile.am index 0a6af01..8fc924a 100644 --- a/tests/modetest/Makefile.am +++ b/tests/modetest/Makefile.am @@ -19,7 +19,8 @@ modetest_SOURCES = $(MODETEST_FILES) modetest_LDADD = \ $(top_builddir)/libdrm.la \ - $(top_builddir)/libkms/libkms.la + $(top_builddir)/libkms/libkms.la \ + -lpthread if HAVE_CAIRO AM_CFLAGS += $(CAIRO_CFLAGS) diff --git a/tests/modetest/cursor.c b/tests/modetest/cursor.c index 60f240a..62a50ef 100644 --- a/tests/modetest/cursor.c +++ b/tests/modetest/cursor.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include "xf86drm.h" #include "xf86drmMode.h" @@ -59,6 +61,9 @@ struct cursor { static struct cursor cursors[MAX_CURSORS]; static int ncursors; +static pthread_t cursor_thread; +static int cursor_running; + /* * Timer driven program loops through these steps to move/enable/disable * the cursor @@ -137,33 +142,29 @@ static struct cursor_step steps[] = { { set_cursor, 10, 0, 0 }, /* disable */ }; -/* - * Cursor API: - */ - -static void run_step(int sig) +static void *cursor_thread_func(void *data) { - struct cursor_step *step = &steps[indx % ARRAY_SIZE(steps)]; - struct itimerval itimer = { - .it_value.tv_usec = 1000 * step->msec, - }; - int i; - - for (i = 0; i < ncursors; i++) { - struct cursor *cursor = &cursors[i]; - step->run(cursor, step); - } - - /* iterate to next count/step: */ - if (count < step->repeat) { - count++; - } else { - count = 0; - indx++; + while (cursor_running) { + struct cursor_step *step = &steps[indx % ARRAY_SIZE(steps)]; + int i; + + for (i = 0; i < ncursors; i++) { + struct cursor *cursor = &cursors[i]; + step->run(cursor, step); + } + + /* iterate to next count/step: */ + if (count < step->repeat) { + count++; + } else { + count = 0; + indx++; + } + + usleep(1000 * step->msec); } - /* and lastly, setup timer for next step */ - setitimer(ITIMER_REAL, &itimer, NULL); + return NULL; } int cursor_init(int fd, uint32_t bo_handle, uint32_t crtc_id, @@ -194,16 +195,16 @@ int cursor_init(int fd, uint32_t bo_handle, uint32_t crtc_id, int cursor_start(void) { - /* setup signal handler to update cursor: */ - signal(SIGALRM, run_step); + cursor_running = 1; + pthread_create(&cursor_thread, NULL, cursor_thread_func, NULL); printf("starting cursor\n"); - run_step(SIGALRM); return 0; } int cursor_stop(void) { - signal(SIGALRM, NULL); + cursor_running = 0; + pthread_join(cursor_thread, NULL); printf("cursor stopped\n"); return 0; }