From patchwork Mon Aug 4 18:35:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 34885 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EC96320F2E for ; Mon, 4 Aug 2014 18:35:58 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id nu7sf39168396obb.11 for ; Mon, 04 Aug 2014 11:35:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=DiCobm7jOdhZ2umtl02LSbEZWEFMrYM1Yz0ySIiSz0U=; b=SI+QpjEFADbEyMf6UGjoonxzFKI0udayU3Q9UouRJ5HBH5VbxlBZ4UqcIaMAz+EIAe pyKWYc0ByxgWst/0F8GkdGSUWzBpLzOMGL9uk/e3WDX75GfIYbqCPc7JVot/n9tIz036 bgTVWi6wQbOXC21uv8GadRPeCpSxdLEy684v6X0Hn5Oi/tw/iq96dlJUvyyPfjXTr9H6 FVly9ndraH9ozFDOaj5DRhwfW8JvVvHBVQiQwmicXMp3xcWTmLDLfmsh4/apwBp8zeg7 GIyKFUH7G8SNlC7mEXK7Vn8MGmYzHX4IfQtQQQBhPmMbTkOFS5mitMb+Nide9BlbmBX8 etMA== X-Gm-Message-State: ALoCoQkXcvstNW00iYtASmTwkEmwMAm//64B/Ep/lZCOSWXloDafPRWwQUIvD/Ye1QvKKsM+YEM9 X-Received: by 10.42.212.207 with SMTP id gt15mr21684953icb.31.1407177354830; Mon, 04 Aug 2014 11:35:54 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.29.55 with SMTP id a52ls2462837qga.14.gmail; Mon, 04 Aug 2014 11:35:54 -0700 (PDT) X-Received: by 10.220.196.147 with SMTP id eg19mr4413245vcb.60.1407177354720; Mon, 04 Aug 2014 11:35:54 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id ss10si12572982vcb.92.2014.08.04.11.35.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 04 Aug 2014 11:35:54 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id lf12so11922623vcb.1 for ; Mon, 04 Aug 2014 11:35:54 -0700 (PDT) X-Received: by 10.220.50.8 with SMTP id x8mr25801364vcf.18.1407177354539; Mon, 04 Aug 2014 11:35:54 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp325511vcb; Mon, 4 Aug 2014 11:35:53 -0700 (PDT) X-Received: by 10.66.246.138 with SMTP id xw10mr3877055pac.142.1407177353532; Mon, 04 Aug 2014 11:35:53 -0700 (PDT) Received: from mail-pd0-f169.google.com (mail-pd0-f169.google.com [209.85.192.169]) by mx.google.com with ESMTPS id bw1si6856492pdb.508.2014.08.04.11.35.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 04 Aug 2014 11:35:53 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.169 as permitted sender) client-ip=209.85.192.169; Received: by mail-pd0-f169.google.com with SMTP id y10so10107749pdj.14 for ; Mon, 04 Aug 2014 11:35:53 -0700 (PDT) X-Received: by 10.68.225.74 with SMTP id ri10mr5338513pbc.116.1407177352944; Mon, 04 Aug 2014 11:35:52 -0700 (PDT) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id vy3sm15908902pbc.92.2014.08.04.11.35.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Aug 2014 11:35:52 -0700 (PDT) From: John Stultz To: LKML Cc: John Stultz , Kees Cook , Greg KH , Stephen Rothwell , Thomas Gleixner , Ingo Molnar , Linux-Next , David Riley Subject: [PATCH] time: Rename udelay_test.c to test_udelay.c Date: Mon, 4 Aug 2014 11:35:40 -0700 Message-Id: <1407177340-29359-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Kees requested that this test module be renamed for consistency sake, so this patch renames the udelay_test.c file (recently added to tip/timers/core for 3.17) to test_udelay.c Cc: Kees Cook Cc: Greg KH Cc: Stephen Rothwell Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Linux-Next Cc: David Riley Signed-off-by: John Stultz Acked-by: Kees Cook Acked-by: David Riley --- kernel/time/Makefile | 2 +- kernel/time/test_udelay.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++ kernel/time/udelay_test.c | 168 ---------------------------------------------- 3 files changed, 169 insertions(+), 169 deletions(-) create mode 100644 kernel/time/test_udelay.c delete mode 100644 kernel/time/udelay_test.c diff --git a/kernel/time/Makefile b/kernel/time/Makefile index 7347426..f622cf2 100644 --- a/kernel/time/Makefile +++ b/kernel/time/Makefile @@ -13,7 +13,7 @@ obj-$(CONFIG_TICK_ONESHOT) += tick-oneshot.o obj-$(CONFIG_TICK_ONESHOT) += tick-sched.o obj-$(CONFIG_TIMER_STATS) += timer_stats.o obj-$(CONFIG_DEBUG_FS) += timekeeping_debug.o -obj-$(CONFIG_TEST_UDELAY) += udelay_test.o +obj-$(CONFIG_TEST_UDELAY) += test_udelay.o $(obj)/time.o: $(obj)/timeconst.h diff --git a/kernel/time/test_udelay.c b/kernel/time/test_udelay.c new file mode 100644 index 0000000..e622ba3 --- /dev/null +++ b/kernel/time/test_udelay.c @@ -0,0 +1,168 @@ +/* + * udelay() test kernel module + * + * Test is executed by writing and reading to /sys/kernel/debug/udelay_test + * Tests are configured by writing: USECS ITERATIONS + * Tests are executed by reading from the same file. + * Specifying usecs of 0 or negative values will run multiples tests. + * + * Copyright (C) 2014 Google, Inc. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include + +#define DEFAULT_ITERATIONS 100 + +#define DEBUGFS_FILENAME "udelay_test" + +static DEFINE_MUTEX(udelay_test_lock); +static struct dentry *udelay_test_debugfs_file; +static int udelay_test_usecs; +static int udelay_test_iterations = DEFAULT_ITERATIONS; + +static int udelay_test_single(struct seq_file *s, int usecs, uint32_t iters) +{ + int min = 0, max = 0, fail_count = 0; + uint64_t sum = 0; + uint64_t avg; + int i; + /* Allow udelay to be up to 0.5% fast */ + int allowed_error_ns = usecs * 5; + + for (i = 0; i < iters; ++i) { + struct timespec ts1, ts2; + int time_passed; + + ktime_get_ts(&ts1); + udelay(usecs); + ktime_get_ts(&ts2); + time_passed = timespec_to_ns(&ts2) - timespec_to_ns(&ts1); + + if (i == 0 || time_passed < min) + min = time_passed; + if (i == 0 || time_passed > max) + max = time_passed; + if ((time_passed + allowed_error_ns) / 1000 < usecs) + ++fail_count; + WARN_ON(time_passed < 0); + sum += time_passed; + } + + avg = sum; + do_div(avg, iters); + seq_printf(s, "%d usecs x %d: exp=%d allowed=%d min=%d avg=%lld max=%d", + usecs, iters, usecs * 1000, + (usecs * 1000) - allowed_error_ns, min, avg, max); + if (fail_count) + seq_printf(s, " FAIL=%d", fail_count); + seq_puts(s, "\n"); + + return 0; +} + +static int udelay_test_show(struct seq_file *s, void *v) +{ + int usecs; + int iters; + int ret = 0; + + mutex_lock(&udelay_test_lock); + usecs = udelay_test_usecs; + iters = udelay_test_iterations; + mutex_unlock(&udelay_test_lock); + + if (usecs > 0 && iters > 0) { + return udelay_test_single(s, usecs, iters); + } else if (usecs == 0) { + struct timespec ts; + + ktime_get_ts(&ts); + seq_printf(s, "udelay() test (lpj=%ld kt=%ld.%09ld)\n", + loops_per_jiffy, ts.tv_sec, ts.tv_nsec); + seq_puts(s, "usage:\n"); + seq_puts(s, "echo USECS [ITERS] > " DEBUGFS_FILENAME "\n"); + seq_puts(s, "cat " DEBUGFS_FILENAME "\n"); + } + + return ret; +} + +static int udelay_test_open(struct inode *inode, struct file *file) +{ + return single_open(file, udelay_test_show, inode->i_private); +} + +static ssize_t udelay_test_write(struct file *file, const char __user *buf, + size_t count, loff_t *pos) +{ + char lbuf[32]; + int ret; + int usecs; + int iters; + + if (count >= sizeof(lbuf)) + return -EINVAL; + + if (copy_from_user(lbuf, buf, count)) + return -EFAULT; + lbuf[count] = '\0'; + + ret = sscanf(lbuf, "%d %d", &usecs, &iters); + if (ret < 1) + return -EINVAL; + else if (ret < 2) + iters = DEFAULT_ITERATIONS; + + mutex_lock(&udelay_test_lock); + udelay_test_usecs = usecs; + udelay_test_iterations = iters; + mutex_unlock(&udelay_test_lock); + + return count; +} + +static const struct file_operations udelay_test_debugfs_ops = { + .owner = THIS_MODULE, + .open = udelay_test_open, + .read = seq_read, + .write = udelay_test_write, + .llseek = seq_lseek, + .release = single_release, +}; + +static int __init udelay_test_init(void) +{ + mutex_lock(&udelay_test_lock); + udelay_test_debugfs_file = debugfs_create_file(DEBUGFS_FILENAME, + S_IRUSR, NULL, NULL, &udelay_test_debugfs_ops); + mutex_unlock(&udelay_test_lock); + + return 0; +} + +module_init(udelay_test_init); + +static void __exit udelay_test_exit(void) +{ + mutex_lock(&udelay_test_lock); + debugfs_remove(udelay_test_debugfs_file); + mutex_unlock(&udelay_test_lock); +} + +module_exit(udelay_test_exit); + +MODULE_AUTHOR("David Riley "); +MODULE_LICENSE("GPL"); diff --git a/kernel/time/udelay_test.c b/kernel/time/udelay_test.c deleted file mode 100644 index e622ba3..0000000 --- a/kernel/time/udelay_test.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * udelay() test kernel module - * - * Test is executed by writing and reading to /sys/kernel/debug/udelay_test - * Tests are configured by writing: USECS ITERATIONS - * Tests are executed by reading from the same file. - * Specifying usecs of 0 or negative values will run multiples tests. - * - * Copyright (C) 2014 Google, Inc. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#include -#include -#include -#include -#include - -#define DEFAULT_ITERATIONS 100 - -#define DEBUGFS_FILENAME "udelay_test" - -static DEFINE_MUTEX(udelay_test_lock); -static struct dentry *udelay_test_debugfs_file; -static int udelay_test_usecs; -static int udelay_test_iterations = DEFAULT_ITERATIONS; - -static int udelay_test_single(struct seq_file *s, int usecs, uint32_t iters) -{ - int min = 0, max = 0, fail_count = 0; - uint64_t sum = 0; - uint64_t avg; - int i; - /* Allow udelay to be up to 0.5% fast */ - int allowed_error_ns = usecs * 5; - - for (i = 0; i < iters; ++i) { - struct timespec ts1, ts2; - int time_passed; - - ktime_get_ts(&ts1); - udelay(usecs); - ktime_get_ts(&ts2); - time_passed = timespec_to_ns(&ts2) - timespec_to_ns(&ts1); - - if (i == 0 || time_passed < min) - min = time_passed; - if (i == 0 || time_passed > max) - max = time_passed; - if ((time_passed + allowed_error_ns) / 1000 < usecs) - ++fail_count; - WARN_ON(time_passed < 0); - sum += time_passed; - } - - avg = sum; - do_div(avg, iters); - seq_printf(s, "%d usecs x %d: exp=%d allowed=%d min=%d avg=%lld max=%d", - usecs, iters, usecs * 1000, - (usecs * 1000) - allowed_error_ns, min, avg, max); - if (fail_count) - seq_printf(s, " FAIL=%d", fail_count); - seq_puts(s, "\n"); - - return 0; -} - -static int udelay_test_show(struct seq_file *s, void *v) -{ - int usecs; - int iters; - int ret = 0; - - mutex_lock(&udelay_test_lock); - usecs = udelay_test_usecs; - iters = udelay_test_iterations; - mutex_unlock(&udelay_test_lock); - - if (usecs > 0 && iters > 0) { - return udelay_test_single(s, usecs, iters); - } else if (usecs == 0) { - struct timespec ts; - - ktime_get_ts(&ts); - seq_printf(s, "udelay() test (lpj=%ld kt=%ld.%09ld)\n", - loops_per_jiffy, ts.tv_sec, ts.tv_nsec); - seq_puts(s, "usage:\n"); - seq_puts(s, "echo USECS [ITERS] > " DEBUGFS_FILENAME "\n"); - seq_puts(s, "cat " DEBUGFS_FILENAME "\n"); - } - - return ret; -} - -static int udelay_test_open(struct inode *inode, struct file *file) -{ - return single_open(file, udelay_test_show, inode->i_private); -} - -static ssize_t udelay_test_write(struct file *file, const char __user *buf, - size_t count, loff_t *pos) -{ - char lbuf[32]; - int ret; - int usecs; - int iters; - - if (count >= sizeof(lbuf)) - return -EINVAL; - - if (copy_from_user(lbuf, buf, count)) - return -EFAULT; - lbuf[count] = '\0'; - - ret = sscanf(lbuf, "%d %d", &usecs, &iters); - if (ret < 1) - return -EINVAL; - else if (ret < 2) - iters = DEFAULT_ITERATIONS; - - mutex_lock(&udelay_test_lock); - udelay_test_usecs = usecs; - udelay_test_iterations = iters; - mutex_unlock(&udelay_test_lock); - - return count; -} - -static const struct file_operations udelay_test_debugfs_ops = { - .owner = THIS_MODULE, - .open = udelay_test_open, - .read = seq_read, - .write = udelay_test_write, - .llseek = seq_lseek, - .release = single_release, -}; - -static int __init udelay_test_init(void) -{ - mutex_lock(&udelay_test_lock); - udelay_test_debugfs_file = debugfs_create_file(DEBUGFS_FILENAME, - S_IRUSR, NULL, NULL, &udelay_test_debugfs_ops); - mutex_unlock(&udelay_test_lock); - - return 0; -} - -module_init(udelay_test_init); - -static void __exit udelay_test_exit(void) -{ - mutex_lock(&udelay_test_lock); - debugfs_remove(udelay_test_debugfs_file); - mutex_unlock(&udelay_test_lock); -} - -module_exit(udelay_test_exit); - -MODULE_AUTHOR("David Riley "); -MODULE_LICENSE("GPL");