Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2364705yba; Fri, 17 May 2019 15:50:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/TbOPSc5vtaK7Z+05hOnNMEwPA8udmC8mVA0uN0oEFcGcEKMq2TaTF/XM2MJw+/nq5f3z X-Received: by 2002:a17:902:324:: with SMTP id 33mr59951714pld.284.1558133406848; Fri, 17 May 2019 15:50:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558133406; cv=none; d=google.com; s=arc-20160816; b=L2nSof3znTCiMwhN82s+E7KHwScXPBuc9jjtfGzZtaaGKylww7dg7XI5BtRJ3s4FUD to9TkAQq5hrQX/FYV1abtuZFb2ETLN4mQ5bZ2hQbQcKRNNCRUehI2UMV67LefJw8Ro10 wPndAvYqdrqrCfWbgUKQlghTt+AKl4EzYnkcRgR2Mugwq6636oAbvrNKZVmiwri+qJNE eiUWCyV1M+I7w9t7nSmBel9Ct2aS7QTpKtUdm6abuimMgjOBg23A8TDLGSpv2a4+Kiaw +3wY4BVoGK1Dny/W1Gu3vnkdZDRF/qkpoYzz/mRuLncSrLFQcyvKmF2caGP5jpHnUuEx 7wzQ== 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:cc:to:from:dkim-signature; bh=VeOHKUgWc5lzs0lL8W8bL8bApiz7pnYC5IgVm7QTTfQ=; b=T+dTHF9bRCDiTp42roCASHMGRAmOYyI2IsT02sYzFQrTezlWO81HUBh2igQ7BrmiUZ kbdO0K7cXfRv1LRL3inh2Weyl7VdmD/5PsNYvplbc2zPeJ3pOyk4XK92pEGXTO6XzMz7 4pnmHivuBVmAgPtLmUoJwKdwlHB+EhQCXr1vjarMBYmF0wL37iVgB8GccJK8RH/z+nwJ pKACzy0TA+R2TlI8SiKJorMDJP4UkJxNiOMozN9dQuR7X/gJ+6w1a+RJdWvQm3YNFWul TFbo4vgrEfRv9TgwqaAE4pQVbFemLgL6IcJHMNAKvBz86fuBcBZw9/tOpt3L8Iw02e4Z vesA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pPiWKxIb; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 68si6992136plc.160.2019.05.17.15.49.52; Fri, 17 May 2019 15:50:06 -0700 (PDT) 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=pass header.i=@gmail.com header.s=20161025 header.b=pPiWKxIb; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728374AbfEQUeo (ORCPT + 99 others); Fri, 17 May 2019 16:34:44 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:43267 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728181AbfEQUel (ORCPT ); Fri, 17 May 2019 16:34:41 -0400 Received: by mail-qt1-f193.google.com with SMTP id i26so9494911qtr.10 for ; Fri, 17 May 2019 13:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VeOHKUgWc5lzs0lL8W8bL8bApiz7pnYC5IgVm7QTTfQ=; b=pPiWKxIb6t9pa81kUBWYHCae94g7GcL/7GzBqEVXdUZPvG10Gy+uCdnNdY5dreStqg aobDdlgUEt3oSjLpHg6yUjwXErXrEKpuKwL8oQeyySTfuErXv13Tq0CPfF47vagHkUDK 9gOfa+nJ28G9l/GitVr1OVKTfkCMb3czwuND+9soMghl93i8fnPSOEnI5yhwz4VT77kB 9lO3ERGhxSQTuKbCI+Fk7O/IKt9TMx4hpB4azrWNPj/ReG/qY8VeLMlU1bdsbfbz/qVg uMMi+zAwN/OgDJpkdoGj7Cw3miZnNjGyO5vpT15oMNWLRI8F1epNAZanHyu2FvcoQuC2 5Ouw== 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=VeOHKUgWc5lzs0lL8W8bL8bApiz7pnYC5IgVm7QTTfQ=; b=AJ3mDsLC6/xz/GvW0hA+rR3BrKb9TJbZwIzq171p1SDiwIEOOTnoffc9JBs8uk+nfG pyP3cnXvm1MS4ShnZ2RHt7hVrGMx8IaoVmEi+axcBUlxB+eUwmPFx+McdLY/0qrkcLOh 7sNG27tXiZpQcSPHpthEO6XuMEbvK5s0lrT0UKD8hzjeGuB91NQcW0nqIs9o1r+VrR9/ 94jNtoS9MAW6HRDB2/9FDSUnA4TtnZhqYbcrlo1Szqn8cfS3AAhIvZ+A/29h5W76qMm2 P0brv8hWlo11Rmnm2I+ocsp1F4SB0jw3JeTwnFgFJbH43WPAIlPRLTgDA/s//NE/2N1C M88Q== X-Gm-Message-State: APjAAAUaaj0FrWlY2ApTbpS3dv+PQFS7igHVaDZ7XuT6W8EvTbx6KgRb HjrrxHsrRRSxLHQZEa5VOg== X-Received: by 2002:aed:22ad:: with SMTP id p42mr48888837qtc.86.1558125280492; Fri, 17 May 2019 13:34:40 -0700 (PDT) Received: from localhost.localdomain ([92.117.189.151]) by smtp.gmail.com with ESMTPSA id u5sm5499145qtj.95.2019.05.17.13.34.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 May 2019 13:34:39 -0700 (PDT) From: Viktor Rosendahl To: Steven Rostedt , Ingo Molnar , linux-kernel@vger.kernel.org Cc: Joel Fernandes , Viktor Rosendahl Subject: [PATCH v4 2/4] preemptirq_delay_test: Add the burst feature and a sysfs trigger Date: Fri, 17 May 2019 22:34:28 +0200 Message-Id: <20190517203430.6729-3-viktor.rosendahl@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190517203430.6729-1-viktor.rosendahl@gmail.com> References: <20190517203430.6729-1-viktor.rosendahl@gmail.com> 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. The maximum burst size is 10. We also create 10 identical test functions, so that we get 10 different backtraces; this is useful when we want to test whether we can detect all the latencies in a burst. Otherwise, there would be no easy way of differentiating between which latency in a burst was captured by the tracer. 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/Kconfig | 6 +- kernel/trace/preemptirq_delay_test.c | 145 +++++++++++++++++++++++---- 2 files changed, 129 insertions(+), 22 deletions(-) diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index 5d965cef6c77..aab8909dfbff 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig @@ -740,9 +740,9 @@ config PREEMPTIRQ_DELAY_TEST configurable delay. The module busy waits for the duration of the critical section. - For example, the following invocation forces a one-time irq-disabled - critical section for 500us: - modprobe preemptirq_delay_test test_mode=irq delay=500000 + For example, the following invocation generates a burst of three + irq-disabled critical sections for 500us: + modprobe preemptirq_delay_test test_mode=irq delay=500 burst_size=3 If unsure, say N diff --git a/kernel/trace/preemptirq_delay_test.c b/kernel/trace/preemptirq_delay_test.c index d8765c952fab..dc281fa75198 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, 2019 BMW Car IT GmbH */ #include @@ -10,18 +11,25 @@ #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)"); + +#define MIN(x, y) ((x) < (y) ? (x) : (y)) static void busy_wait(ulong time) { @@ -34,37 +42,136 @@ 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); +} - 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 __always_inline void preemptoff_test(void) +{ + 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); \ + } \ +/* + * We create 10 different functions, so that we can get 10 different + * backtraces. + */ +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; + int s = MIN(burst_size, NR_TEST_FUNCS); + + for (i = 0; i < s; i++) + (testfuncs[i])(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