From patchwork Tue Dec 4 19:40:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anders Roxell X-Patchwork-Id: 152843 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp8458485ljp; Tue, 4 Dec 2018 11:40:56 -0800 (PST) X-Google-Smtp-Source: AFSGD/WmwjOhcjnthff2rL2j76hc1LkrdpSQ2pmOsSxm8VS/KT79GBGvQMXXNOItDDOWvjlEvOn2 X-Received: by 2002:a63:e19:: with SMTP id d25mr17693806pgl.272.1543952455986; Tue, 04 Dec 2018 11:40:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543952455; cv=none; d=google.com; s=arc-20160816; b=Dbkc650T1thZvDt4Z/b5IgtXi1COn/DZLv9iBdfIDB63XsPgLSvFQEk1wzgu9Ng6fX PbJbLc6KP9UKjX1/7nBqxZrLAe+sIglmfw4QUqHngzmjLXMbA+mwGeiwrKYTx4ZmUYiA DX4gb+AUTMKElsB0hyMRnDX1/BQ4d8Ya2ntMmw6yaMLD6WJgimJBI5n8gXrJUz/H39Q1 hU1Y5aiG1kjsPo0B17azvj8B62TlarqrjyyP4vmgAId9c9/yri5DsryX6otUuLO2+7ae 7hevrZivUegWGMNz+32n+XsT5jhvBGfj4OccyeTCzDankEHj9TIImsPZOYC1S493tRGg Wjlw== 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 r23si15415467pgu.359.2018.12.04.11.40.55; Tue, 04 Dec 2018 11:40:55 -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 S1726166AbeLDTky (ORCPT + 31 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 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..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(); }