From patchwork Tue Dec 4 19:29:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Roxell X-Patchwork-Id: 152842 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp8448013ljp; Tue, 4 Dec 2018 11:29:13 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xzj9SylY2i0mAowW0p7ubRAobqElRe4dy0aZNy6r7is2pGnW+TvTeqzoEYIGpKkHWIqbyL X-Received: by 2002:a17:902:7481:: with SMTP id h1mr21489290pll.341.1543951753402; Tue, 04 Dec 2018 11:29:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543951753; cv=none; d=google.com; s=arc-20160816; b=V3aE/K5QskE/4ILauAX6lPNq4E74yPjdH5pVWxCSGuEjrW+vn+cGeDgiyxjEEa/CYN taiXTWhzBdoCQMJCCuFN3C5UW57Lswdf/V9xHkPbp0MP9MqLiEGy9cJKGSZg3+dO0j10 2+oE4EE59utsqXw0iRgW+wAiR5R53D7i1fyarP6THzA9yoGuBNu1eqX5HMGEcPwJLK5L ORmtzzQj9W7Dl168hLRjCdnle+u6eb9FqjXXlaANqoB+COlOyv5lBDgTmc/UOpDp8TwS WIclhkE8RrfcBghJbiS3R1IzVw7EnxZSU7vm1wI4CRwqGeKDhuglrknMKIxSuCGunUP/ 9jpA== 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 y6si16858923pll.384.2018.12.04.11.29.13; Tue, 04 Dec 2018 11:29:13 -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 S1726153AbeLDT3M (ORCPT + 31 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 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(+) -- 2.19.2 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(); }