Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6180489imu; Mon, 21 Jan 2019 04:38:45 -0800 (PST) X-Google-Smtp-Source: ALg8bN4ZTQM3j2eQ1J6p8tnrtoxxW2jiIGJ+wrTZJDGbK6lSEUOepp8Mcot9KKANtlATT6SGYMqk X-Received: by 2002:a63:34c3:: with SMTP id b186mr27190167pga.184.1548074325802; Mon, 21 Jan 2019 04:38:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548074325; cv=none; d=google.com; s=arc-20160816; b=xNt1yGnpx6Ynb0BSjrR1cY0Gdnd4U2yQqujfCUF4E0cuov4Wczt12iincSGnlfUt9T ERGNedEB3rj3Df+i1M32smqRbuDNwAufTwuoqqdQo1tU9mmU4RXQOZu3GlaK5jlComEv Mo2hTadWzUb9LdwUrhFY9c+ODoy7+7Tkk3wdU/jaEbxWu7qf0n5KJrtCG80MeY0dMMVn o3egpXTOAIwk0HOJwCYx0x2VsXHU0CiS20SgKz97/0saMhXe3CP2unUFSS1XbGJiOoGc qTP/obrULUqsLGdkmeNGXX7iPzkG9Cv6fZCIsf+6Qq4jR8k48CP6fYMmC5WLoHhHvy2t 7dYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature; bh=VSg+RmkXm7gYFBzQHz9dyyLY95denFG+EsQPs9oCogE=; b=uhTofy4P3jNfAypYKWpbOWYyEFB9FdTyqRUC22zEtvRBa0AGD0YX0GnXjr7zqikD3b VCZekTDBKzQpZL43qXpNB429ngE1Jxq9/AKG3szgpDd/LjQrphdmHuVc/0fUywSop2Tk RgmYBSbvVSulsx/AnO0kiZ59n1LX2yGZrCr8PellpwW3slmTK1PrwN2mv9ED411WRkMF yqZ/fsR1SyC3iZtYyINO1N111N2YzaBxtHCaEpQomj6sUjHlsMGqHjDNgQIvyAvqYNhB v7p/O5av71WntBNtvb7diNiyJBVxU/8OJjoN7dTCmqI3N/HUMKXpDLZQyD84o7rwzE7P A/QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kapsi.fi header.s=20161220 header.b=FbWp7X0E; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bmw.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o3si1267352pll.201.2019.01.21.04.38.24; Mon, 21 Jan 2019 04:38:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@kapsi.fi header.s=20161220 header.b=FbWp7X0E; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bmw.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728774AbfAUMfp (ORCPT + 99 others); Mon, 21 Jan 2019 07:35:45 -0500 Received: from mail.kapsi.fi ([91.232.154.25]:40801 "EHLO mail.kapsi.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728482AbfAUMfX (ORCPT ); Mon, 21 Jan 2019 07:35:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender: Reply-To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=VSg+RmkXm7gYFBzQHz9dyyLY95denFG+EsQPs9oCogE=; b=FbWp7X0EUODlg74xtQZMdawC34 rBLAZjY62G1I/JNOjYDHEVgRgQJ806xUoqK2VgkTAbzC5JuNfCQnpYbH71vj7VvSbJqmJ5aQ2kBJp +SjSxnpzPGvRl64CWCXTLEQqIXHht/r9oSww1e5jHcXaAQhpT0hALklR4ExLq6MxVYhDBkWA5ULch 5KgQM8B6Ypq7vkdOqDzp7XkdzQEcsnoAN5UBbIpOx+/bWKPlcGVKmHa2pk9FdiZ4wY/5/NV7SOTEk JOYXyTfx9ZMeKtpszdUdbWGnXVAHtLYKtBIlJ+9pRfW6kmrokiq574ooU6KmwEyGWsysSoj6sdqjO hKJiC2MA==; Received: from lakka.kapsi.fi ([2001:67c:1be8::1] ident=Debian-exim) by mail.kapsi.fi with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1glYnJ-0003qz-Qt; Mon, 21 Jan 2019 14:35:13 +0200 Received: from mcfrisk by lakka.kapsi.fi with local (Exim 4.84_2) (envelope-from ) id 1glYnJ-0004Mf-Nk; Mon, 21 Jan 2019 14:35:13 +0200 From: Viktor Rosendahl To: Ingo Molnar , Steven Rostedt , linux-kernel@vger.kernel.org Subject: [PATCH 2/4] preemptirq_delay_test: Add the burst feature and a sysfs trigger Date: Mon, 21 Jan 2019 14:35:11 +0200 Message-Id: <1548074113-16599-3-git-send-email-Viktor.Rosendahl@bmw.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1548074113-16599-1-git-send-email-Viktor.Rosendahl@bmw.de> References: <1548074113-16599-1-git-send-email-Viktor.Rosendahl@bmw.de> X-SA-Exim-Connect-IP: 2001:67c:1be8::1 X-SA-Exim-Mail-From: mcfrisk@kapsi.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This burst feature enables the user to generate a burst of preempt/irqsoff latencies. This makes it possible to test whether we are able to detect latencies that systematically occur very close to each other. In addition, there is a sysfs trigger, so that it's not necessary to reload the module to repeat the test. The trigger will appear as /sys/kernel/preemptirq_delay_test/trigger in sysfs. Signed-off-by: Viktor Rosendahl --- kernel/trace/preemptirq_delay_test.c | 139 +++++++++++++++++++++++---- 1 file changed, 120 insertions(+), 19 deletions(-) diff --git a/kernel/trace/preemptirq_delay_test.c b/kernel/trace/preemptirq_delay_test.c index d8765c952fab..1fc3cdbdd293 100644 --- a/kernel/trace/preemptirq_delay_test.c +++ b/kernel/trace/preemptirq_delay_test.c @@ -3,6 +3,7 @@ * Preempt / IRQ disable delay thread to test latency tracers * * Copyright (C) 2018 Joel Fernandes (Google) + * Copyright (C) 2018 BMW Car IT GmbH */ #include @@ -10,18 +11,23 @@ #include #include #include +#include #include #include #include #include +#include static ulong delay = 100; -static char test_mode[10] = "irq"; +static char test_mode[12] = "irq"; +static uint burst_size = 1; -module_param_named(delay, delay, ulong, S_IRUGO); -module_param_string(test_mode, test_mode, 10, S_IRUGO); -MODULE_PARM_DESC(delay, "Period in microseconds (100 uS default)"); -MODULE_PARM_DESC(test_mode, "Mode of the test such as preempt or irq (default irq)"); +module_param_named(delay, delay, ulong, 0444); +module_param_string(test_mode, test_mode, 12, 0444); +module_param_named(burst_size, burst_size, uint, 0444); +MODULE_PARM_DESC(delay, "Period in microseconds (100 us default)"); +MODULE_PARM_DESC(test_mode, "Mode of the test such as preempt, irq, or alternate (default irq)"); +MODULE_PARM_DESC(burst_size, "The size of a burst (default 1)"); static void busy_wait(ulong time) { @@ -34,37 +40,132 @@ static void busy_wait(ulong time) } while ((end - start) < (time * 1000)); } -static int preemptirq_delay_run(void *data) +static __always_inline void irqoff_test(void) { unsigned long flags; + local_irq_save(flags); + busy_wait(delay); + local_irq_restore(flags); +} + +static __always_inline void preemptoff_test(void) +{ + preempt_disable(); + busy_wait(delay); + preempt_enable(); +} - if (!strcmp(test_mode, "irq")) { - local_irq_save(flags); - busy_wait(delay); - local_irq_restore(flags); - } else if (!strcmp(test_mode, "preempt")) { - preempt_disable(); - busy_wait(delay); - preempt_enable(); +static void execute_preemptirqtest(int idx) +{ + if (!strcmp(test_mode, "irq")) + irqoff_test(); + else if (!strcmp(test_mode, "preempt")) + preemptoff_test(); + else if (!strcmp(test_mode, "alternate")) { + if (idx % 2 == 0) + irqoff_test(); + else + preemptoff_test(); } +} + +#define DECLARE_TESTFN(POSTFIX) \ + static void preemptirqtest_##POSTFIX(int idx) \ + { \ + execute_preemptirqtest(idx); \ + } \ + +DECLARE_TESTFN(0) +DECLARE_TESTFN(1) +DECLARE_TESTFN(2) +DECLARE_TESTFN(3) +DECLARE_TESTFN(4) +DECLARE_TESTFN(5) +DECLARE_TESTFN(6) +DECLARE_TESTFN(7) +DECLARE_TESTFN(8) +DECLARE_TESTFN(9) +static void (*testfuncs[])(int) = { + preemptirqtest_0, + preemptirqtest_1, + preemptirqtest_2, + preemptirqtest_3, + preemptirqtest_4, + preemptirqtest_5, + preemptirqtest_6, + preemptirqtest_7, + preemptirqtest_8, + preemptirqtest_9, +}; + +#define NR_TEST_FUNCS ARRAY_SIZE(testfuncs) + +static int preemptirq_delay_run(void *data) +{ + + int i; + + for (i = 0; i < burst_size; i++) + (testfuncs[i % NR_TEST_FUNCS])(i); return 0; } -static int __init preemptirq_delay_init(void) +static struct task_struct *preemptirq_start_test(void) { char task_name[50]; - struct task_struct *test_task; snprintf(task_name, sizeof(task_name), "%s_test", test_mode); + return kthread_run(preemptirq_delay_run, NULL, task_name); +} + + +static ssize_t trigger_store(struct kobject *kobj, struct kobj_attribute *attr, + const char *buf, size_t count) +{ + preemptirq_start_test(); + return count; +} + +static struct kobj_attribute trigger_attribute = + __ATTR(trigger, 0200, NULL, trigger_store); + +static struct attribute *attrs[] = { + &trigger_attribute.attr, + NULL, +}; + +static struct attribute_group attr_group = { + .attrs = attrs, +}; + +static struct kobject *preemptirq_delay_kobj; + +static int __init preemptirq_delay_init(void) +{ + struct task_struct *test_task; + int retval; + + test_task = preemptirq_start_test(); + retval = PTR_ERR_OR_ZERO(test_task); + if (retval != 0) + return retval; + + preemptirq_delay_kobj = kobject_create_and_add("preemptirq_delay_test", + kernel_kobj); + if (!preemptirq_delay_kobj) + return -ENOMEM; + + retval = sysfs_create_group(preemptirq_delay_kobj, &attr_group); + if (retval) + kobject_put(preemptirq_delay_kobj); - test_task = kthread_run(preemptirq_delay_run, NULL, task_name); - return PTR_ERR_OR_ZERO(test_task); + return retval; } static void __exit preemptirq_delay_exit(void) { - return; + kobject_put(preemptirq_delay_kobj); } module_init(preemptirq_delay_init) -- 2.17.1