From patchwork Fri Aug 18 18:51:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 110427 Delivered-To: patches@linaro.org Received: by 10.140.95.78 with SMTP id h72csp1287484qge; Fri, 18 Aug 2017 11:51:14 -0700 (PDT) X-Received: by 10.84.130.78 with SMTP id 72mr10560643plc.471.1503082274838; Fri, 18 Aug 2017 11:51:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503082274; cv=none; d=google.com; s=arc-20160816; b=WYqUPtZHpj5vw9PgqEMr3eFsqrxri2OL4HnCcgdo1fGldz1I6oQR8ycjDvM6m19aI5 fIXIABz3+nFhOq3O/sgtZPQf8vUIeBla2/q0XgbtV9SCVXZaOieGxDhhBEMt+lVFILfH xs4Go1/G2U6GA0HJ99Qo1lHP+u9csnVy26F4qRufZvoPNTP+1nFBuLBXOuBUS9BEB18Q YfTkIYP6aVm3OQhbxci2BjR4hLU8WJ5Ohtsyn6GReDyGAQ0hWmZsXJmo7mkyYf47WhOn ypw1zAX02FhTZ7KBynO25p2cf7ngYrJ6eE+5O1HXU9uH4mNVEjcVE1GZJCdySlg1H4a/ Qjmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=gnjP2QzQRYWEdHBGENV+8SgesivTywiIdive8zqkDwM=; b=oMIKdHMJKkeEHu1W8IASOa2//MyoShjYDE7q95SzR9o7PzYQ1BHgezFZPm96zlxJ0p 5wTHSKW/I7QTAENLamzyzjHKqDk1Yh5q6QfUUeCi0aZIRKo6H4Lo5BpYBsoviSWX/+KK JbueXavkvSsxg9r3UBPLKPFvGLtKeKbESZ5t7wGSfFYXTenQ1RIyywONx9gRxdoBeWCw ztfAidU+hEGPdwCq34PdVQTdBYZB7zXiGMwypXERiN3iJT394uHYeeRCxUH8Q/La4w1q E3FGYtwpl8S2Fv5rAADeWoSjPcAP6K5Fi4POF0nTMYdDGpUKGvc67vYIHuuG5Zs45B3Y egCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FlcruEGN; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::229 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-pg0-x229.google.com (mail-pg0-x229.google.com. [2607:f8b0:400e:c05::229]) by mx.google.com with ESMTPS id m10si3907024pgs.819.2017.08.18.11.51.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Aug 2017 11:51:14 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::229 as permitted sender) client-ip=2607:f8b0:400e:c05::229; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FlcruEGN; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::229 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-pg0-x229.google.com with SMTP id t3so41497470pgt.0 for ; Fri, 18 Aug 2017 11:51:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gnjP2QzQRYWEdHBGENV+8SgesivTywiIdive8zqkDwM=; b=FlcruEGNXxbJMnd8l4G9aSlA3XHPodm8RvECdtGp1j+keKZjwOf4F6EGaDli6J+aCr IO2+5tX0XpVrqOtDRYuevp21Ae3F/9gVURzrQGJ2pSfPWj1B6xfQCXtB1/p6y/Z0XHin D5E0baEEdg+TA+d9im6jq31pMEnDtRXu5UrxI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gnjP2QzQRYWEdHBGENV+8SgesivTywiIdive8zqkDwM=; b=dq0meHTlU9POtA+ux4GUw6LKfuPaE4RpKLc6NnRYh+5H/pBJrfrmVr+IR26N9IGz+Z ft6llRdIXQMmg2x/k8/1/gJbjH1g/TpP2TRYqhk1NRvw1BRjRGxE4+MVKML0UjzrdcWr vTsvioycLXVJaBy7sx3xQYHJ8yd9zDUxUX/n0ttXc4f85LFrbxM+kUxd6d4AMdgdSd0o 8JvUzjnwGMv1kXCKZwdKWa2i1YNIT4D6X4A4FIFMVhb2/cvH4IUu4sv+4Xu7MmPzyxDL akQddLMwdRdj2fhKG028AjqKF/c61YOlZNLZBbbVdboJS0FdaeUBRiHbd/jsNuLkdNId HTNA== X-Gm-Message-State: AHYfb5iHoeeoO7iVENErWn+sWHohD1tG6swtYUXZPuR//qomVWOzY1I7 7lrO6LkrllO2B6tunos= X-Received: by 10.98.34.201 with SMTP id p70mr9686241pfj.330.1503082274536; Fri, 18 Aug 2017 11:51:14 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id l132sm12518790pfc.150.2017.08.18.11.51.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 Aug 2017 11:51:13 -0700 (PDT) From: John Stultz To: lkml Cc: Greg Hackmann , Thomas Gleixner , Ingo Molnar , Miroslav Lichvar , Richard Cochran , Prarit Bhargava , Stephen Boyd , Shuah Khan , linux-kselftest@vger.kernel.org, John Stultz Subject: [PATCH 4/6] kselftests: timers: set-timer-lat: Add one-shot timer test cases Date: Fri, 18 Aug 2017 11:51:00 -0700 Message-Id: <1503082262-29450-5-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503082262-29450-1-git-send-email-john.stultz@linaro.org> References: <1503082262-29450-1-git-send-email-john.stultz@linaro.org> From: Greg Hackmann These testcases are motivated by a recent alarmtimer regression, which caused one-shot CLOCK_{BOOTTIME,REALTIME}_ALARM timers to become periodic timers. The new testcases are very similar to the existing testcases for repeating timers. But rather than waiting for 5 alarms, they wait for 5 seconds and verify that the alarm fired exactly once. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Cc: Shuah Khan Cc: linux-kselftest@vger.kernel.org Signed-off-by: Greg Hackmann Signed-off-by: John Stultz --- tools/testing/selftests/timers/set-timer-lat.c | 86 ++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 13 deletions(-) -- 2.7.4 diff --git a/tools/testing/selftests/timers/set-timer-lat.c b/tools/testing/selftests/timers/set-timer-lat.c index 10c2e18..15434da 100644 --- a/tools/testing/selftests/timers/set-timer-lat.c +++ b/tools/testing/selftests/timers/set-timer-lat.c @@ -20,6 +20,7 @@ */ +#include #include #include #include @@ -122,17 +123,17 @@ void sigalarm(int signo) max_latency_ns = delta_ns; } -void describe_timer(int flags) +void describe_timer(int flags, int interval) { - printf("%-22s %s ", + printf("%-22s %s %s ", clockstring(clock_id), - flags ? "ABSTIME":"RELTIME"); + flags ? "ABSTIME":"RELTIME", + interval ? "PERIODIC":"ONE-SHOT"); } -int do_timer(int clock_id, int flags) +int setup_timer(int clock_id, int flags, int interval, timer_t *tm1) { struct sigevent se; - timer_t tm1; struct itimerspec its1, its2; int err; @@ -146,7 +147,7 @@ int do_timer(int clock_id, int flags) alarmcount = 0; timer_fired_early = 0; - err = timer_create(clock_id, &se, &tm1); + err = timer_create(clock_id, &se, tm1); if (err) { if ((clock_id == CLOCK_REALTIME_ALARM) || (clock_id == CLOCK_BOOTTIME_ALARM)) { @@ -167,19 +168,23 @@ int do_timer(int clock_id, int flags) its1.it_value.tv_sec = TIMER_SECS; its1.it_value.tv_nsec = 0; } - its1.it_interval.tv_sec = TIMER_SECS; + its1.it_interval.tv_sec = interval; its1.it_interval.tv_nsec = 0; - err = timer_settime(tm1, flags, &its1, &its2); + err = timer_settime(*tm1, flags, &its1, &its2); if (err) { printf("%s - timer_settime() failed\n", clockstring(clock_id)); return -1; } - while (alarmcount < 5) - sleep(1); + return 0; +} - describe_timer(flags); +int check_timer_latency(int flags, int interval) +{ + int err = 0; + + describe_timer(flags, interval); printf("timer fired early: %7d : ", timer_fired_early); if (!timer_fired_early) { printf("[OK]\n"); @@ -188,10 +193,9 @@ int do_timer(int clock_id, int flags) err = -1; } - describe_timer(flags); + describe_timer(flags, interval); printf("max latency: %10lld ns : ", max_latency_ns); - timer_delete(tm1); if (max_latency_ns < UNRESONABLE_LATENCY) { printf("[OK]\n"); } else { @@ -201,6 +205,60 @@ int do_timer(int clock_id, int flags) return err; } +int check_alarmcount(int flags, int interval) +{ + describe_timer(flags, interval); + printf("count: %19d : ", alarmcount); + if (alarmcount == 1) { + printf("[OK]\n"); + return 0; + } + printf("[FAILED]\n"); + return -1; +} + +int do_timer(int clock_id, int flags) +{ + timer_t tm1; + const int interval = TIMER_SECS; + int err; + + err = setup_timer(clock_id, flags, interval, &tm1); + if (err) + return err; + + while (alarmcount < 5) + sleep(1); + + timer_delete(tm1); + return check_timer_latency(flags, interval); +} + +int do_timer_oneshot(int clock_id, int flags) +{ + timer_t tm1; + const int interval = 0; + struct timeval timeout; + fd_set fds; + int err; + + err = setup_timer(clock_id, flags, interval, &tm1); + if (err) + return err; + + memset(&timeout, 0, sizeof(timeout)); + timeout.tv_sec = 5; + FD_ZERO(&fds); + do { + err = select(FD_SETSIZE, &fds, NULL, NULL, &timeout); + } while (err == -1 && errno == EINTR); + + timer_delete(tm1); + err = check_timer_latency(flags, interval); + err |= check_alarmcount(flags, interval); + return err; +} + int main(void) { struct sigaction act; @@ -226,6 +284,8 @@ int main(void) ret |= do_timer(clock_id, TIMER_ABSTIME); ret |= do_timer(clock_id, 0); + ret |= do_timer_oneshot(clock_id, TIMER_ABSTIME); + ret |= do_timer_oneshot(clock_id, 0); } if (ret) return ksft_exit_fail();