Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp9272775imu; Wed, 5 Dec 2018 01:55:25 -0800 (PST) X-Google-Smtp-Source: AFSGD/XSi7yQ87UfzF77xbjcPses2n+6vztKeiBzoawVpSAzkdo9onH7t7KNHtbChQg/6C5CkJFy X-Received: by 2002:a62:1447:: with SMTP id 68mr23342004pfu.257.1544003725508; Wed, 05 Dec 2018 01:55:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544003725; cv=none; d=google.com; s=arc-20160816; b=RZKkTs0GfZ23ugM8sDzvRg6nbzh4x4UVh4qpC/bxOXY6qxYiu99M0bBJWqKEEat3t3 ZSfM/HlGhW8FBgSsaMAchKb8MoVo38xVZtXeo3IG7y8NtYscre9hirspBxSjieHlv+q4 nhpsBsxjl0JhPHH8HoLqGpEU+bwh16T5dUFBA3950b4o4yXne96YBBSx/rLZi6sOR2h3 /QztNpACA9vXT1EU4y3H46pfIdwHUmr6PvrqriN0q/Z0ajVExqwueA/w9414DSfrptSH qjzrJhcf25xfih2e7roJidafknPG9n438cyAWDhW6NlpKCcqtWNiKeGuGeNBT5AvwLXM theg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=PsmToMaXVfOls81sr0qAUfrDtKBAuhbnbidoKyliwcw=; b=eLyrB0yEGObH/WvYdH6vD7MBwmqRhdJzwna/s0aTV0ryVgrNiBipZCrrxcrykIx06b f5hUMP0mTvWstYo0lIrF/BZjA6aF04BLaaO+FpTou3fEpp+z4qQoX5xklpRD30xoek+G RGzMy8fejYdVhu6Z/NZKfdNis6m3o7rjw5cBYljWVLeYDKORRT8mzK3JH+kHNzymT07q Dq8m6D0CMnlyVWx8l9Go2ouG0i8xQRvOPeGyagGofHu0vqYxqHkUGaX9clvFzB0xfr80 skRfDDljnsZHF2hlYpZMddhi94986e8fUYwRwyqx4u8Cz94PgFT/Iwnd2mt/Qv4NpMSM A4vg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a10si4897916pgq.270.2018.12.05.01.55.10; Wed, 05 Dec 2018 01:55:25 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729774AbeLEJye (ORCPT + 99 others); Wed, 5 Dec 2018 04:54:34 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50250 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730127AbeLEJy0 (ORCPT ); Wed, 5 Dec 2018 04:54:26 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 276EC80D; Wed, 5 Dec 2018 01:54:26 -0800 (PST) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EB5443F575; Wed, 5 Dec 2018 01:54:25 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 974C51AE0BA8; Wed, 5 Dec 2018 09:54:46 +0000 (GMT) Date: Wed, 5 Dec 2018 09:54:46 +0000 From: Will Deacon To: Anders Roxell Cc: rostedt@goodmis.org, mingo@redhat.com, catalin.marinas@arm.com, keescook@chromium.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v2] tracing: add cond_resched to ftrace_replace_code() Message-ID: <20181205095445.GA14317@arm.com> References: <20181204192903.8193-1-anders.roxell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181204192903.8193-1-anders.roxell@linaro.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Anders, Steve, On Tue, Dec 04, 2018 at 08:29:03PM +0100, Anders Roxell wrote: > 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(); Is there a reason not to use preemptible() here? Will