Received: by 10.192.165.148 with SMTP id m20csp1445699imm; Wed, 25 Apr 2018 19:19:35 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+c5U/T3zVbbM36vPmHl11DGBUxl6mtC1Il/Pe2ykTGUC6DotpeKMdi++CUpYPsPPRcvpVT X-Received: by 10.98.103.86 with SMTP id b83mr30254522pfc.76.1524709175684; Wed, 25 Apr 2018 19:19:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524709175; cv=none; d=google.com; s=arc-20160816; b=oGGb41rq4P9FQKO7vK29WZ11g8si+2jTWjKwdBlxilWHCSZ0Q0nixWAGy3vyiRrf6k aAVrZhpWtvu9Le/XLixMFO2SjvX0FbuGQC/DJ8+51THXbMy3ckwXEIwXzK4cJgrxUagM SpGK0Fkc5raRX8uir/uTirDzltDxzJ9peZlBGYn4LsnQtLVu9RvemWp2EdLge10ULloC lK2mr0H/H4xL0mUR+JLuhG7LGrXrubjr2xOTBGvpFEJFx02I1gHY/jg0r10sMFo9nHYQ 03X7A9+PJzG4JTvnynOph8ciNf2yfexnZOD0cMu8oU5wmeBwzDLMuc31y5jR6ENcPnUq 9e3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=vNEsdwT//Cq8mSfl+4VQDWuMAouJOoTzHNlaPvzRY10=; b=Nd8/Ebqtb6ZMROcMfYHXfmKtCaq0kJ88JP08BCE2WL5mzfq+MxRVc8ela3WECkPgyj VDIXBnh3zeSbS7XoRohKbTXQTxqbcfj9gIPWcwKa5tR0ro04JgGFQrkJmIOhQ6bX5vK+ Te60A4GWm2075TSUY8znMi8lWIHAJagbEBX9kfrggt/ygTmxHwhhAHOL06izahHf7Lx1 nftGALAlMhGkXx+9S7o2Pceqaz9IqG2VPp+X56qkaPoHhG7ucZXxgTY1teRTOIL/AeIk qs8n2xO+4KIRb7zRpI4Z9y2cbQ1+DC9YYsn6IOeuqj8QYpenqwEB+Ru89ZDtxbx/uUPT XwuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=F3V4Q5RI; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z18si14523565pgc.99.2018.04.25.19.19.21; Wed, 25 Apr 2018 19:19:35 -0700 (PDT) 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=@google.com header.s=20161025 header.b=F3V4Q5RI; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753505AbeDZCSP (ORCPT + 99 others); Wed, 25 Apr 2018 22:18:15 -0400 Received: from mail-it0-f42.google.com ([209.85.214.42]:50628 "EHLO mail-it0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751913AbeDZCSM (ORCPT ); Wed, 25 Apr 2018 22:18:12 -0400 Received: by mail-it0-f42.google.com with SMTP id p3-v6so22048705itc.0 for ; Wed, 25 Apr 2018 19:18:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=vNEsdwT//Cq8mSfl+4VQDWuMAouJOoTzHNlaPvzRY10=; b=F3V4Q5RIQ8vKeUbT2asSBuJ+fuLZ5UjpJQMROGLYmjE/Mlkce5GQfZmeIsqcppDsaM 0VZNuMQrj9AWViClLEpIKifpJlpnfkIoBmJ74wa245svGHqJQaEFts/vGpVcJvqS63XK RCdzrzdaenQo/9ZTobI3IfK5pSxXyScEUw9YFJbqszZoUVVNxxFdoGeU5ptNYHzHn2lI +8L13MElggQs5bE/pi3zLkH5Vg1fB+mdCIS0/1E8ThYrvPAtO8snTALPPz2hzxD1JiOj AoTGPlutRh/oEMYRXIKtX44OUnLq79HtnRQ/tYHvqTETmmpIks5hnfcjetaxH500gJUu Jx1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=vNEsdwT//Cq8mSfl+4VQDWuMAouJOoTzHNlaPvzRY10=; b=AH44zXJgMrpLkRR9sZ/4ziKhuFH/uFLrWA47pQ+3CaYplSJ+vpj7B8l+bqnkwNYaR3 XIckLgWQW+iNz4iHMgLk7Er/AjYUXqxvBAycAfzyNXJzMXUEOIVBD+Vv0yT8xoAaxyHj N2nIJCntyBi+sYJTgv5IsYvPkpFWmW/mffq9iMEa3DOPpKnVG059hrQNcWgjowefA+pj mZ25S/W0MjIJEHRCKet2NZwIe6kmimV9X6HqgkvDPnXRbELGdMtKwB7Sw4qt0Ow/W5B7 qonLG9OBGH2uw+INb4vXPBMb9iofEVp5QzRlIj5/yeIxJA8+wAi9Zh5HjyNNLnRxmFZO dBeA== X-Gm-Message-State: ALQs6tD/psdhF2zpuBQPOKXupc7aVzY+7pKkbhVoKRILXxIrhi+bYGr5 Rxo+VTelUVcoZ4gJ/9ZQDU4fyb3ac+QdBiHth/FGxg== X-Received: by 2002:a24:6d5:: with SMTP id 204-v6mr16109188itv.47.1524709091678; Wed, 25 Apr 2018 19:18:11 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.181.213 with HTTP; Wed, 25 Apr 2018 19:18:10 -0700 (PDT) In-Reply-To: <20180423031926.GF26088@linux.vnet.ibm.com> References: <20180417040748.212236-1-joelaf@google.com> <20180417040748.212236-4-joelaf@google.com> <20180418180250.7b6038dddba46b37c94b796c@kernel.org> <20180419054302.GD13370@sejong> <20180423031926.GF26088@linux.vnet.ibm.com> From: Joel Fernandes Date: Wed, 25 Apr 2018 19:18:10 -0700 Message-ID: Subject: Re: [RFC v4 3/4] irqflags: Avoid unnecessary calls to trace_ if you can To: Paul McKenney Cc: Namhyung Kim , Masami Hiramatsu , LKML , linux-rt-users , Steven Rostedt , Peter Zilstra , Ingo Molnar , Mathieu Desnoyers , Tom Zanussi , Thomas Glexiner , Boqun Feng , Frederic Weisbecker , Randy Dunlap , Fenguang Wu , Baohong Liu , Vedang Patel , kernel-team Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Apr 22, 2018 at 8:19 PM, Paul E. McKenney wrote: > On Sun, Apr 22, 2018 at 06:14:18PM -0700, Joel Fernandes wrote: [...] >> I narrowed the performance hit down to the call to >> rcu_irq_enter_irqson() and rcu_irq_exit_irqson() in __DO_TRACE. >> Commenting these 2 functions brings the perf level back. >> >> I was thinking about RCU usage here, and really we never change this >> particular performance-sensitive tracepoint's function table 99.9% of >> the time, so it seems there's quite in a win if we just had another >> read-mostly synchronization mechanism that doesn't do all the RCU >> tracking that's currently done here and such a mechanism can be >> simpler.. >> >> If I understand correctly, RCU also adds other complications such as >> that it can't be used from the idle path, that's why the >> rcu_irq_enter_* was added in the first place. Would be nice if we can >> just avoid these RCU calls for the preempt/irq tracepoints... Any >> thoughts about this or any other ideas to solve this? > > In theory, the tracepoint code could use SRCU instead of RCU, given that > SRCU readers can be in the idle loop, although at the expense of a couple > of smp_mb() calls in each tracepoint. In practice, I must defer to the > people who know the tracepoint code better than I. Paul and me were chatting about handling of tracing from an NMI. If the tracepoint's implementation were to be switched to using SRCU instead of RCU, a complication could arise due to the use of this_cpu_inc from srcu_read_lock. int __srcu_read_lock(struct srcu_struct *sp) { int idx; idx = READ_ONCE(sp->srcu_idx) & 0x1; this_cpu_inc(sp->sda->srcu_lock_count[idx]); smp_mb(); /* B */ /* Avoid leaking the critical section. */ return idx; } EXPORT_SYMBOL_GPL(__srcu_read_lock); What could happen is if an NMI preempts the this_cpu_inc, and also happens to call a tracepoint from the NMI handler, then this could result in a lost-update issue on architectures that don't support add-to-memory instructions. Paul said he wouldn't want to use atomics to resolve this inorder to keep the srcu overhead low. One way we discussed to resolve this could be to use a different srcu_struct for NMI invocations, so that the above lost update doesn't occur. We could use in_nmi() and switch the srcu_read_lock to use the NMI version of the srcu_struct. Another way could be to just warn for now if the srcu version of the trace_ API was used from NMI. This could be fragile if some code path indirect results in a tracepoint call so we should probably handle it by detecting and using the correct srcu_struct for the srcu_read_lock. thanks, - Joel