Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1742374ybg; Sat, 19 Oct 2019 01:31:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxM7Vqu5SPutnGttRZzy9KRFO928uL5ikMPUWx7RoK6I0cwHS1sDjvo8HOyjtcXqQlEalOx X-Received: by 2002:a17:906:7202:: with SMTP id m2mr12277426ejk.138.1571473902885; Sat, 19 Oct 2019 01:31:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571473902; cv=none; d=google.com; s=arc-20160816; b=e+P1P1R8p04b9h3DD8COonvaZAvzeCUnDokZmkbjBrFzGPoZJgXULf6PtH0db+XDsh YlTLJ809ZEmhSQqmDhFxvJxu/1vVfdikfX0tBtGjKNMZd+2Q4klXhjtzib1fnWHunBka Tb0VsM41cnbhE98uMWELhmvcINo5cv8vWqU1RaZboZ8xO2O8BrvzPFIqQknIQ56RHwv2 qxragmaqBq148O1L4u5S9qxr8KJIPTDxuhZ3YwZHV2aZivfMvPb8cqUcHqgLMDS8ENBY MLuz+v06uXPW7rWbtXTWxZIvV4AzhCztI38/2tmukJ9LY6U/rBDYgv17kHJBZe6rCmzg BHiQ== 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=YLk4rgpI3ra8cq7GidJOjYQl2q+Qi2SppaV+ZdIOjAo=; b=Uu+1f4waTsuglYu8zeirYED50JzzqO01jwkbq8nlw8jl7JsMsvdYEmOqPKZhvfascv FSyzt8r7woDtbs6DgcnUGZycvajWbn/gyh0iTjr0aHENWT5IknI5fV4bAnsurd430nLh /jATdAllUu6sxuTCZSNcylRDulgVfpeTG9x2qwcyyOXW/bCeQoEPHN+TGAyAj8CvImPY 1Jcb0ex7CWDUh+HPw6eFpYa3VmRoAguofudbQaera/f+Ot2ta7JBCSSXqqKlEEOe8Koa U1fe7KUoVQhY5s6u7pI756DLTFZGQ+lKF1Y1ECO//MpSpj5d9F7rgWjydsf/NOljy8cW Q10g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ixZTeNvQ; 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 p15si5568491eda.294.2019.10.19.01.31.20; Sat, 19 Oct 2019 01:31:42 -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=ixZTeNvQ; 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 S2439564AbfJRPJB (ORCPT + 99 others); Fri, 18 Oct 2019 11:09:01 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:34211 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392875AbfJRPI7 (ORCPT ); Fri, 18 Oct 2019 11:08:59 -0400 Received: by mail-wr1-f66.google.com with SMTP id t16so1518431wrr.1 for ; Fri, 18 Oct 2019 08:08:57 -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=YLk4rgpI3ra8cq7GidJOjYQl2q+Qi2SppaV+ZdIOjAo=; b=ixZTeNvQQYH6wmC+Geds7fX3KqJEyD0yNgsceFwEea3ZY+L/pJExdF9TPsH2jeLR5W OEwh/QmtbXk6okLn4fRf8XHfNNtXGNNQFhVt4A7Lj6PXaZkUnsdgYpXCMlcgB8FxQdUC VNL2cG6uUIw5dPLBUdfDqjKdp+tHgzutzFRMSOYNNgZLPSC57hdiv+2VzC1mp3ogjxAD hnbQnQHpm1vtrU9++uoAUmvqkyZO/t9ZMfmnfwu/LZNlQvxbcRYNiXtHssLnBKDYG4kk y/S70Pl0JLf6BgKE4n77Anml0aYgQBo88CbEF9XxGXQLnqvIDXYkama7veokxvsYY2i2 rBgA== 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=YLk4rgpI3ra8cq7GidJOjYQl2q+Qi2SppaV+ZdIOjAo=; b=agLgczvkc0Y+Ov+yfsSD2LdgUCf0wba1+V2qxel9eIEug2GRy+OPzA6yedKMcn1NT7 /xTAaN3vQLoe0mPrl01DaMITkftoqJ65lYr3prcDZxJwlfPvPNQM/qD/QFYEw9A5TCXl SmB5MxRgWtcM1rbXs4/vDc/86aQ/BQSRzrMBbE8ZInYSb2i8LhBSylpjJeL/52kcDGRt tbCwISmShKzXS/sXiRBpq0bK1wKM/+RrpKTdTLhWbliBr3bdQx3FH+XBhwuQuqClXJUZ Z3bouNpgJUtKzl7QMmoyV4RKe1cwv7ELtJ1I0JE14K4kozWxIJoMrlCE4BbWTdTikm88 s5sg== X-Gm-Message-State: APjAAAXltBkRvE51RIwQu9+KL0mp5nraNQdkFboyTRqCUOEY65Jurz7I CJagJALQZf1IAbPVEOUUxnkLvWk= X-Received: by 2002:adf:fd91:: with SMTP id d17mr8114579wrr.311.1571411336788; Fri, 18 Oct 2019 08:08:56 -0700 (PDT) Received: from buster-jangle.bmw-carit.intra ([217.89.178.117]) by smtp.gmail.com with ESMTPSA id z6sm6035074wro.16.2019.10.18.08.08.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2019 08:08:56 -0700 (PDT) From: "Viktor Rosendahl (BMW)" To: Steven Rostedt , Ingo Molnar , linux-kernel@vger.kernel.org Cc: Joel Fernandes , "Viktor Rosendahl (BMW)" Subject: [PATCH v10 2/4] preemptirq_delay_test: Add the burst feature and a sysfs trigger Date: Fri, 18 Oct 2019 17:08:50 +0200 Message-Id: <20191018150852.4322-3-viktor.rosendahl@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191018150852.4322-1-viktor.rosendahl@gmail.com> References: <20191018150852.4322-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 (BMW) Reviewed-by: Joel Fernandes (Google) --- kernel/trace/Kconfig | 6 +- kernel/trace/preemptirq_delay_test.c | 144 +++++++++++++++++++++++---- 2 files changed, 128 insertions(+), 22 deletions(-) diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index e08527f50d2a..2a58380ea310 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig @@ -752,9 +752,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..31c0fad4cb9e 100644 --- a/kernel/trace/preemptirq_delay_test.c +++ b/kernel/trace/preemptirq_delay_test.c @@ -10,18 +10,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 +41,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