Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8633756imu; Tue, 4 Dec 2018 11:30:24 -0800 (PST) X-Google-Smtp-Source: AFSGD/VYAjhstxm+pYOzTtBupoSI/3r23+7tFWtqGpO5jNQYwu5aTf/FfmYAYbih+xtXd6WPsA9l X-Received: by 2002:a62:4c5:: with SMTP id 188mr21634158pfe.130.1543951824083; Tue, 04 Dec 2018 11:30:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543951824; cv=none; d=google.com; s=arc-20160816; b=qsQ1RzcwqIipbIfZJCCDtYXH+pFBWJ4ISIJ4q6voHuILVnM4bmqWWHyobQ1NGyEN1k 5i76hmfnfAhMUi9jQmfrvnahcR0saj1KdQfCJ9aLCHhyaWnlg1UNAaR7QlTyNSMALbPQ 0q+iifV1nwZd4M07OeRMd5Y4opTiBS8/mmoRYwezOuA1GbA9yKD9IvuKg/QchkdmK07y ZIgxZVZ4PyWyAOcIrxn7bAjvv1cTHxR1Eh1Y7ZoqE5AcwSgz8V0IEkOMkLlSlMYziF4C 53n6yno8M7KJ/LdKwQL4DkLCiMcVEmKdjIBYVsD5UJ0901rs+t++LAxi59E5HopxqFih J+oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=InkRDJb3bMIXWPs5c5/xqK+kSTer9bJK74SZfDVgZxo=; b=XKn7z5dV0eeaIKjPGfKKYaPi4HzORx5cdBSlbsg52rhDyaWXkcwAd/rRGdGKN4Ez6I zgtMK3KTOr3tW9VfixE9h/ScuP9X0697WijKikXYZDYVRt+LgY9fKfVW70eEN4ilA9+8 T4XkEbWo9bs4+SyNSRTEvnzj4TfOBMpEiIF2Xqn3Qx1uTX0pU2gLfAg7VKtow+xWUoqC PqZVci3ucxuoj8tciArPSgOvb/PIemcZ6gdyRylKAAiv8ypCOWH5QPw1GLDY85Fpb5nE Lxpf72wYvzS0VZTpXWebjDqNGBqF9rSRIqcMJ1rFLF0h59zkZlBMrpPchLF8CDQnotRk TfFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Q/T928xt"; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d32si18476208pla.136.2018.12.04.11.30.09; Tue, 04 Dec 2018 11:30:24 -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=pass header.i=@linaro.org header.s=google header.b="Q/T928xt"; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726143AbeLDT3M (ORCPT + 99 others); Tue, 4 Dec 2018 14:29:12 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:40989 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725912AbeLDT3L (ORCPT ); Tue, 4 Dec 2018 14:29:11 -0500 Received: by mail-lj1-f195.google.com with SMTP id z80-v6so15998678ljb.8 for ; Tue, 04 Dec 2018 11:29:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=InkRDJb3bMIXWPs5c5/xqK+kSTer9bJK74SZfDVgZxo=; b=Q/T928xt76bOPzWNBRs8eIDvxhFDwvl8m/aCuQw/hFMVMHVkDqGOpLwXrS9DKPEtVF f8gY7A7z+GIWJpRz9IG107vWUKWbywnyObTWk35izIbagI8WIMIrAvfcOnWX2Yx2sSgE D7gI9mefs3fkYiggzx7ADfdojrQ2E3HmHC82k= 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:mime-version :content-transfer-encoding; bh=InkRDJb3bMIXWPs5c5/xqK+kSTer9bJK74SZfDVgZxo=; b=TfhUsHkL+l+yxxmNpjHKM3rKJQiSHLXapuWTexhMNsDq8qESZuRh00k7Po6EEza0GY 4rFh7/YCHGDGpVEqObRaZCpfc5diS5yv47+rC+06GSEhdoZFCvGqHrMa4+I6xPTYMJFQ YZ/P6RXWjNt3FzN7TMivl4XuLayIOuYOLxclNZYyIjaKdQowOcrXgmgSWilss3yyr9Ul dmRcu1Zbn0OjQ1JPWIM1+0x0DkGBvrHju5s5o7mbUlUBy5v0hp6TBBVjeL/5CkaNZ32u 2iSN3qm13lvKcYqUIp83QUv9qgZC2mrVEIstsYqYmmgRxmO8RKbfjNTliyUjkcs2yqR9 /jiQ== X-Gm-Message-State: AA+aEWYqFryCgfdM2XGIXClvyYE9H9sOIuy+7qBhZwV1Zp7jRgZoN1jP geMSFJbOl9tRSsI/ZkyjHqxBuA== X-Received: by 2002:a2e:83d7:: with SMTP id s23-v6mr3594602ljh.139.1543951748560; Tue, 04 Dec 2018 11:29:08 -0800 (PST) Received: from localhost (c-732171d5.07-21-73746f28.bbcust.telenor.se. [213.113.33.115]) by smtp.gmail.com with ESMTPSA id f8sm3396773lfe.72.2018.12.04.11.29.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Dec 2018 11:29:07 -0800 (PST) From: Anders Roxell To: rostedt@goodmis.org, mingo@redhat.com, catalin.marinas@arm.com, will.deacon@arm.com Cc: keescook@chromium.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Anders Roxell Subject: [PATCH v2] tracing: add cond_resched to ftrace_replace_code() Date: Tue, 4 Dec 2018 20:29:03 +0100 Message-Id: <20181204192903.8193-1-anders.roxell@linaro.org> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When running in qemu on an kernel built with allmodconfig and debug options (in particular kcov and ubsan) enabled, ftrace_replace_code function call take minutes. The ftrace selftest calls ftrace_replace_code to look >40000 through ftrace_make_call/ftrace_make_nop, and these end up calling __aarch64_insn_write/aarch64_insn_patch_text_nosync. Microseconds add up because this is called in a loop for each dyn_ftrace record, and this triggers the softlockup watchdog unless we let it sleep occasionally. Rework so that we call cond_resched() if !irqs_disabled() && !preempt_count(). Suggested-by: Steven Rostedt (VMware) Signed-off-by: Anders Roxell --- kernel/trace/ftrace.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index c375e33239f7..7080eb464983 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -2419,11 +2419,19 @@ void __weak ftrace_replace_code(int enable) { struct dyn_ftrace *rec; struct ftrace_page *pg; + bool schedulable; int failed; if (unlikely(ftrace_disabled)) return; + /* + * Some archs calls this function with interrupts or preemption + * disabled. However, for other archs that can preempt, this can cause + * an tremendous unneeded latency. + */ + schedulable = !irqs_disabled() && !preempt_count(); + do_for_each_ftrace_rec(pg, rec) { if (rec->flags & FTRACE_FL_DISABLED) @@ -2435,6 +2443,8 @@ void __weak ftrace_replace_code(int enable) /* Stop processing */ return; } + if (schedulable) + cond_resched(); } while_for_each_ftrace_rec(); } -- 2.19.2