Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8620243imu; Tue, 4 Dec 2018 11:14:38 -0800 (PST) X-Google-Smtp-Source: AFSGD/WxhO4aAGwSx/PlEVda6EhodQID7g//diCBqflQU0X6qC0e5Equ6Inu+uOJWk6jEcD4kE73 X-Received: by 2002:a17:902:6b49:: with SMTP id g9mr20833289plt.98.1543950878702; Tue, 04 Dec 2018 11:14:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543950878; cv=none; d=google.com; s=arc-20160816; b=KfMwR8Uapnh527dl+jBKld5MkDNL+nD6//RzfYsPRApzCZYUkfYX1qLN+A2THBdCWG DCoSdk2TNsUfINSnHF95XWDBmDJ5rmw26H0Aff3yTCqlLZRJ9UuNRidnk6/mDxx+znUd Vw5yPlE8kTCKAqzJy/IAFjKMsR8myv53mPpteaWGpX2uqtctP6OvCt7lB0YVr7HmOcmN B0cGsVyh/bCnspLqIMIzSQaB2UCNsyfb7Ofkk6EK7s7lI5BYrCogFUzStQoNZ77y0q1/ p2UIDkbROBfwgyY46dpH/pGgRtJo/dTcA0PB5B+CwZqctsp9bQGO0mvUrU1SovfD8m8d mbqQ== 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=//4FO27EOO8cJvGZSWp42VAK+MHOwE9eX7iULiXx+NQ=; b=sAlinQ+uqEObeyZWp+qiOWrKr6cHmq4SzjF3qwQ+OPlL0pxzUr63Fgtpt//wV0O82y PVrQGMrQMahmSSReciKyabJF8+kmTsFlIagHwIiG6viUk7Aa+vz9hKQJegyDk6wkt7Xp mqQs63xc8Xf0KZ/lmQVsecLepiUcL9zQFCofiZMc7BK5U6ymVWy4j5S1uZdhcdiAhpdB UZD3rAgExRSwMyqev46H0wmtg9uI0sXt6JQ+wl6RIaJXorjfgsH3vEYCLOau7ocrjsQ8 qtuq1IQPWmi5Mu39hDwxL9WoKVCW5jKhFr+I6cB4+7RStCZ2tOfhqe9L94aZU99qpXJb BE8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AL5otzb+; 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 t17si3866430pgk.217.2018.12.04.11.14.22; Tue, 04 Dec 2018 11:14:38 -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=AL5otzb+; 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 S1726303AbeLDTMi (ORCPT + 99 others); Tue, 4 Dec 2018 14:12:38 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:42573 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725864AbeLDTMi (ORCPT ); Tue, 4 Dec 2018 14:12:38 -0500 Received: by mail-lj1-f196.google.com with SMTP id l15-v6so15974674lja.9 for ; Tue, 04 Dec 2018 11:12:36 -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=//4FO27EOO8cJvGZSWp42VAK+MHOwE9eX7iULiXx+NQ=; b=AL5otzb+xOXtn4QEnKRppU81XMGlj6grJ+JkKUIvawxYMmV8SR/cJtdLQYLgVwV3dJ yQEjxbd+5i+yTM+xUkJLWV6PqYTe455r9rIUGZ4oRB6F+CRAgdDNlTFfU4kXUUEBcSwl C417mNp+NmnXAlV2NN1/5/EadWCXxSHatXGG0= 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=//4FO27EOO8cJvGZSWp42VAK+MHOwE9eX7iULiXx+NQ=; b=Z3SGDUxgPa7movmiKIKKFp09AOWqn6KC1w6lXmcdSLAjMzccOVokD0MbDE/gbnzooB VyA0ZsXX47ZxiotyDF0nv5R6J8i0P4nV36YJfWu6EBM0QRCKaP1DUHTw801k0dhV7RSc OGtueIQnEuaUWF0kwc1kzKWHLHPfiLZXsCufYrsgOlxnOJzt8jEVZP7MSo/Jh7DaPcCe ZXjvRuDfqX2kbsu/ObLMj1Fb6rEwhNFhthG6gDJAg3GnGn9M8C/z5W4ox8pBfoz9DLBz 7vBqNx4hwFxWbVaqBO1fxXMcUKwbt8Lb3Z5+HmSdV+BSSDgCK0k2vP3paH/2R0Wyi4dT OfSw== X-Gm-Message-State: AA+aEWbLlYk4q+RG++5ckr81o576KAhISOBPr/JOhGXcQ3r65BJab0xs KDQa8Q8pds6mD3Xq89JVJtl87g== X-Received: by 2002:a2e:9556:: with SMTP id t22-v6mr14969452ljh.36.1543950755121; Tue, 04 Dec 2018 11:12:35 -0800 (PST) Received: from localhost (c-732171d5.07-21-73746f28.bbcust.telenor.se. [213.113.33.115]) by smtp.gmail.com with ESMTPSA id o26sm3316312lfl.18.2018.12.04.11.12.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Dec 2018 11:12:34 -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] tracing: add cond_resched to ftrace_replace_code() Date: Tue, 4 Dec 2018 20:12:28 +0100 Message-Id: <20181204191229.6851-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..582e3441e318 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -2419,11 +2419,14 @@ void __weak ftrace_replace_code(int enable) { struct dyn_ftrace *rec; struct ftrace_page *pg; + bool schedulable; int failed; if (unlikely(ftrace_disabled)) return; + schedulable = !irqs_disabled() && !preempt_count(); + do_for_each_ftrace_rec(pg, rec) { if (rec->flags & FTRACE_FL_DISABLED) @@ -2435,6 +2438,13 @@ void __weak ftrace_replace_code(int enable) /* Stop processing */ return; } + /* + * Some archs calls this function with interrupts or preemption + * disabled. Howeve, other archs don't and this can cause a + * tremendous unneeded latency. + */ + if (schedulable) + cond_resched(); } while_for_each_ftrace_rec(); } -- 2.19.2