From patchwork Wed Jul 11 06:35:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 10518827 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6F2C86032C for ; Wed, 11 Jul 2018 06:36:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FF4028E25 for ; Wed, 11 Jul 2018 06:36:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5457728E87; Wed, 11 Jul 2018 06:36:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C9E9C28E8D for ; Wed, 11 Jul 2018 06:36:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726499AbeGKGie (ORCPT ); Wed, 11 Jul 2018 02:38:34 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34921 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726347AbeGKGid (ORCPT ); Wed, 11 Jul 2018 02:38:33 -0400 Received: by mail-pf0-f196.google.com with SMTP id q7-v6so16644073pff.2 for ; Tue, 10 Jul 2018 23:35:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BdfWhrjr9wKw3yNm4cu6HOnRLkZAvO/Axt7JM6VJCtc=; b=ViCpbgm0x+ej7RxQRO9NaFiFBTWKGpUPVGwbRix1eCFAlTZDxSMoQaQmaYiGaYMjo+ aGeoTyRN6eFeFe06PdIBC5DIE54NuAs139OFQ+GIJOHcbZ8x8momoRFfbXAZ495CdPxn YdYuuS3Hr098sglHF6rYmOyaOPHL+vPCDLHQI= 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=BdfWhrjr9wKw3yNm4cu6HOnRLkZAvO/Axt7JM6VJCtc=; b=MxR5V6NC1TOm3ECLZaEoZ9zPg/7d/leKiT4rfoZ0PXTTqP1LQuue+PvT9r8fuCpKtg mRig6KwtukuDBNLCsyGdU1txf++KjvocYgnPTRy5FoLu+GZz6Olfqr4gHc6V3kYsm/DW 2/CCZjumEQy2R+WWNqUPYjrh8mr9UDUnemBu7zwyqMrB7pZ+DvoUn7tqv6xTGDspw5tU MSB1jnoP8DCl7lZ6oGX5FSnTu+WlX22VFn7UvjeZlOS9PC9v3aHf1PNwOB5Wd1K2qL2E Y4GIA8QDowJOHXUxvSbJqPr/EpWljBN31Jbl4wvFUBN88zQGHDTn3CXKh1W1JB2wnr5l Dbuw== X-Gm-Message-State: APt69E008VvOpGnt+HnuAWhG7MJpxxLWGxB/+mKx+/ORmEdEMfxylsYo +WDgyLNz4LVUlDLdwBvobSZYrw== X-Google-Smtp-Source: AAOMgpfg+EynEwsyUEFeJrYRBgSF43lw65VmaDAT58QtbBiHzHLAMekUnZmZWK2qwIvTfzqlfqKihQ== X-Received: by 2002:aa7:8118:: with SMTP id b24-v6mr1673242pfi.78.1531290950170; Tue, 10 Jul 2018 23:35:50 -0700 (PDT) Received: from joelaf.mtv.corp.google.com ([2620:0:1000:1600:3122:ea9c:d178:eb]) by smtp.gmail.com with ESMTPSA id h190-v6sm24731891pge.85.2018.07.10.23.35.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Jul 2018 23:35:49 -0700 (PDT) From: Joel Fernandes To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, "Joel Fernandes (Google)" , Andy Shevchenko , Boqun Feng , Byungchul Park , Erick Reyes , Ingo Molnar , Julia Cartwright , linux-kselftest@vger.kernel.org, Masami Hiramatsu , Mathieu Desnoyers , Namhyung Kim , Paul McKenney , Peter Zijlstra , Shuah Khan , Steven Rostedt , Thomas Glexiner , Todd Kjos , Tom Zanussi Subject: [PATCH 1/2] lib: Add module for testing preemptoff/irqsoff latency tracers Date: Tue, 10 Jul 2018 23:35:39 -0700 Message-Id: <20180711063540.91101-2-joel@joelfernandes.org> X-Mailer: git-send-email 2.18.0.203.gfac676dfb9-goog In-Reply-To: <20180711063540.91101-1-joel@joelfernandes.org> References: <20180711063540.91101-1-joel@joelfernandes.org> Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Joel Fernandes (Google)" Here we introduce a test module for introducing a long preempt or irq disable delay in the kernel which the preemptoff or irqsoff tracers can detect. This module is to be used only for test purposes and is default disabled. Following is the expected output (only briefly shown) that can be parsed to verify that the tracers are working correctly. We will use this from the kselftests in future patches. For the preemptoff tracer: echo preemptoff > /d/tracing/current_tracer sleep 1 insmod ./preemptirq_delay_test.ko test_mode=preempt delay=500000 sleep 1 bash-4.3# cat /d/tracing/trace preempt -1066 2...2 0us@: preemptirq_delay_run <-preemptirq_delay_run preempt -1066 2...2 500002us : preemptirq_delay_run <-preemptirq_delay_run preempt -1066 2...2 500004us : tracer_preempt_on <-preemptirq_delay_run preempt -1066 2...2 500012us : => kthread => ret_from_fork For the irqsoff tracer: echo irqsoff > /d/tracing/current_tracer sleep 1 insmod ./preemptirq_delay_test.ko test_mode=irq delay=500000 sleep 1 bash-4.3# cat /d/tracing/trace irq dis -1069 1d..1 0us@: preemptirq_delay_run irq dis -1069 1d..1 500001us : preemptirq_delay_run irq dis -1069 1d..1 500002us : tracer_hardirqs_on <-preemptirq_delay_run irq dis -1069 1d..1 500005us : => ret_from_fork Co-developed-by: Erick Reyes Cc: Andy Shevchenko Reviewed-by: Andy Shevchenko Signed-off-by: Joel Fernandes (Google) Signed-off-by: Add Erick's SOB here. --- kernel/trace/Kconfig | 15 ++++++ kernel/trace/Makefile | 1 + kernel/trace/preemptirq_delay_test.c | 72 ++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 kernel/trace/preemptirq_delay_test.c diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index 8d51351e3149..eb5ab6b511e2 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig @@ -699,6 +699,21 @@ config RING_BUFFER_STARTUP_TEST If unsure, say N +config PREEMPTIRQ_DELAY_TEST + tristate "Preempt / IRQ disable delay thread to test latency tracers" + depends on m + help + Select this option to build a test module that can help test latency + tracers by executing a preempt or irq disable section with a user + 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 + + If unsure, say N + config TRACE_EVAL_MAP_FILE bool "Show eval mappings for trace events" depends on TRACING diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile index 84a0cb222f20..677540bb1b62 100644 --- a/kernel/trace/Makefile +++ b/kernel/trace/Makefile @@ -36,6 +36,7 @@ obj-$(CONFIG_TRACING_MAP) += tracing_map.o obj-$(CONFIG_CONTEXT_SWITCH_TRACER) += trace_sched_switch.o obj-$(CONFIG_FUNCTION_TRACER) += trace_functions.o obj-$(CONFIG_PREEMPTIRQ_TRACEPOINTS) += trace_preemptirq.o +obj-$(CONFIG_PREEMPTIRQ_DELAY_TEST) += preemptirq_delay_test.o obj-$(CONFIG_IRQSOFF_TRACER) += trace_irqsoff.o obj-$(CONFIG_PREEMPT_TRACER) += trace_irqsoff.o obj-$(CONFIG_SCHED_TRACER) += trace_sched_wakeup.o diff --git a/kernel/trace/preemptirq_delay_test.c b/kernel/trace/preemptirq_delay_test.c new file mode 100644 index 000000000000..c97a026c0720 --- /dev/null +++ b/kernel/trace/preemptirq_delay_test.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Preempt / IRQ disable delay thread to test latency tracers + * + * Copyright (C) 2018 Joel Fernandes (Google) + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static ulong delay = 100; +static char test_mode[10] = "irq"; + +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)"); + +static void busy_wait(ulong time) +{ + ktime_t start, end; + start = ktime_get(); + do { + end = ktime_get(); + if (kthread_should_stop()) + break; + } while (ktime_to_ns(ktime_sub(end, start)) < (time * 1000)); +} + +int preemptirq_delay_run(void *data) +{ + unsigned long 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(); + } + + return 0; +} + +static int __init preemptirq_delay_init(void) +{ + char task_name[50]; + struct task_struct *test_task; + + snprintf(task_name, sizeof(task_name), "%s_test", test_mode); + + test_task = kthread_run(preemptirq_delay_run, NULL, task_name); + return PTR_ERR_OR_ZERO(test_task); +} + +static void __exit preemptirq_delay_exit(void) +{ + return; +} + +module_init(preemptirq_delay_init) +module_exit(preemptirq_delay_exit) +MODULE_LICENSE("GPL v2");