Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8644545imu; Tue, 4 Dec 2018 11:42:06 -0800 (PST) X-Google-Smtp-Source: AFSGD/U8uMtgoLivDXaIYSGcT3eSGnRAJvNs5trrNOCAKLaytl3DT2huNcPLTD0h1aFZYth3VEw/ X-Received: by 2002:a62:1c7:: with SMTP id 190mr21407813pfb.46.1543952526873; Tue, 04 Dec 2018 11:42:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543952526; cv=none; d=google.com; s=arc-20160816; b=tHSsKWkDE2xPwLCLSwYRbglaO3a7m+HgEtkiIqO78Wgncvt0BMsoF6KjjRrPC/OCaW lXcZNJTHd7MAeDxM1ihOvyzgPcxQE7U5nt6vJYbfZxUKdQ8D0dmBIiBlPGqGzcvCWZsI OnN+QrltOemGMW9hfu2BOiRgzyTf/le/O46oln2l1iDlgIl0dUWue40x7La5jLOIhcVm uBzrbhG+5zfaF+27Ak8/Wb0nbwJHCfymmJ1MHwre0e/48pj93lkhy9pXuBsCw+mOiaK5 2uptXQ4cfjwSC4L6zpNhAznHro/pv1E9sud8lCBUkKoh27UNohfbvZoGYD5f73RYKR2E i+YA== 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=MJ2RoHnxkmKN1SVC9aFtGcbGzzZFAKHvy0LyoUhWX9E=; b=VgPI7cMU9LJc1vv7KZZd80yHa5hC5rXoMhnf8AGU8GMzEF8lneTV8F5E1+2MvagdQv JyyDS7IAPap4s1lhwhc8S/w4V9ir/ORI+UbnyxYVkAI0drKDiLtrgdFbxiOMHBsEjYPU HnHW2r/ww5VaoPS4mrC5KSmkdc+KvmeCokb1oIB9Ex3JmKdKLttyEGZUVkhvxxnPyLT4 TvRbXbH6TIJbQ+NSK7RoaPt9iFxDHiiGLh111IxxkdGUZ/HJ/7PR9nCzGeMEZBLtzZDL gdPt4x83dm1aBBt9eJuL4PlWJGeK3E2H+IKeMEFOr1xZYVl2xEnvQioNLmLSjbeXQ6Dh 5BUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OjEOaGAO; 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.41.52; Tue, 04 Dec 2018 11:42:06 -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=OjEOaGAO; 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 S1726152AbeLDTky (ORCPT + 99 others); Tue, 4 Dec 2018 14:40:54 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:43856 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725874AbeLDTky (ORCPT ); Tue, 4 Dec 2018 14:40:54 -0500 Received: by mail-lf1-f65.google.com with SMTP id u18so12881244lff.10 for ; Tue, 04 Dec 2018 11:40:53 -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=MJ2RoHnxkmKN1SVC9aFtGcbGzzZFAKHvy0LyoUhWX9E=; b=OjEOaGAOFkvDZNcY6d+glGYmOCDflfGVTlcSq7GeLuHN2n3uCFPDwIGkWqVm/tIcfP cQMhbLZcN/CQuT1vVh4F7zR+wNgo5NYyZyk+tf48SggDyKpRpD9wHEjVaKvtM7rm7Vig Wig9sYqCOseL68ELNr7naLr3FBy4R59c70Rnw= 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=MJ2RoHnxkmKN1SVC9aFtGcbGzzZFAKHvy0LyoUhWX9E=; b=b23ML0AEoIzuQXfrY3LjcrDnXhIrWwiJDJ0v+DOsjPmIBigU/SG+hhvVDaIXAAUGgh +L/L1g49gJb0nlirm8PUMyUzJAkQx4Jbtm8XHY7bVbtxmV1QglauqW/qjKaHFZ80AJqw 9CPpYwzxIbP+ej173T9+REg93APYshPNwf6sY7CbxtyG03ZxvLvllvwoYPnnEQPay4Up Q7jzL4nrilvtf1kP0B/3LA3O0TsRiLoqtNbtLUOINGw+m5yE8iRmfzxewrzJjQ4A4oku ad4x+JzC6Vtun7+vwlC3QR10w8k0Vxcm99OO7kWv/McZTk4wYriTNBqppgzcXJ7ZQMJ1 e+kw== X-Gm-Message-State: AA+aEWb1r/6iBrPFtZDJSzTFTHM5iw+6WBSXZmdyf90f/L/B9swjotXK 2Rz4lYMWunI5Lk3UD2wpOuAVew== X-Received: by 2002:a19:c413:: with SMTP id u19mr12341607lff.100.1543952452174; Tue, 04 Dec 2018 11:40:52 -0800 (PST) Received: from localhost (c-732171d5.07-21-73746f28.bbcust.telenor.se. [213.113.33.115]) by smtp.gmail.com with ESMTPSA id i75sm3187945lfb.58.2018.12.04.11.40.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Dec 2018 11:40:51 -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 v3] tracing: add cond_resched to ftrace_replace_code() Date: Tue, 4 Dec 2018 20:40:44 +0100 Message-Id: <20181204194044.9506-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..7c9f49a5a1ab 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 call 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