Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5217746ybi; Tue, 4 Jun 2019 03:16:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6Lj8tZZ4Oc8hijJ3F2UKIYru7FTi8aSO3mOdGHa/rLEB8hOL0Go4Uf9GR0NXYJRV/y+6E X-Received: by 2002:a17:90a:8c0b:: with SMTP id a11mr28451326pjo.80.1559643374597; Tue, 04 Jun 2019 03:16:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559643374; cv=none; d=google.com; s=arc-20160816; b=awcxsmdHxYpftDR/udhcvbxG1OEJVMoWYAthCPqwYyCMpd00PtSKa39X/AexJL5DYT I24u2lcoG96iYqekXDN7JFLtbyLBfyDpqhHPs+jpENIdZyLOijFviMafpD1Ni/zMMKUg /ms5skVL459c4tIgCYTvMLiN1db0uGwW8PKNeQrWSAzYdYEw1rEBI4rfl+9QT/USPVWJ A51D7hRIWwML0LMpdbOWcQ2l2ch7kuZgAJF8hu/D87l2b6s8sxUJC7JxiuMqPyZjnPXE LEIH76QbAN9hC5MD04YBDTKMEC3tberziHILaCj4I0bdgxAkd3Z4pjDeD+EPRAtal3gq OJ/A== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=um8w67w6LCCsT/DE9snQkkvxxZYU83IofxVrJcLAJG0=; b=O5FYKMWgsx2laeZYZYL+850FA77DsoR3kCVitg4IAZFDj+PVLQbidbxfsno8n65Rr5 IZ2bHfG1cNkZbyHBNUcF7XXsDf2TaFQOXD2I0IbcNOTAt+pHQOD9yHJAeQzl52OI02ZP Qf2S3qsj+pwxprT5WZ4qBcTTSiw945fln+WZw+WcCh0pQrhW8cRo1MZgb3xYXD5uptmm pGbKH3o1GKLy1P9bkjwZrao82thVdhOJcpDapgUaaH1GiCcQdeIYUAUKP8kuLC1wn04V wiSLmYGINP0Mb4LxIWOzAIDGsg+Vtw1AYZDSLrrZby/uuQDsRL5Jg7D59FZ/C+v9CzJh niAg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q17si21206069pll.285.2019.06.04.03.15.57; Tue, 04 Jun 2019 03:16:14 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727456AbfFDKM4 (ORCPT + 99 others); Tue, 4 Jun 2019 06:12:56 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:42997 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727122AbfFDKMy (ORCPT ); Tue, 4 Jun 2019 06:12:54 -0400 Received: by mail-wr1-f67.google.com with SMTP id o12so8050316wrj.9 for ; Tue, 04 Jun 2019 03:12:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=um8w67w6LCCsT/DE9snQkkvxxZYU83IofxVrJcLAJG0=; b=dj4jGaaRWKIYULybOblXCZOtUr7fy2Vq1eHI6heDrbSkqaTsRFC/G+DE9a7AJSZUB6 EAHXLNffMIiy1t8ysusi8A0hpey1Q7AkUDtqtwGzA6UqRq4VGalN8E7sMiHoq0PUjs0T dcbR5WGr9lAl6g0rwxdnG1uT3wFgR76dvXKN0/LoF77GW3bZTmrBaoKvkKiTmNMC+ezi oNvrPVUrEoHADSSqRBUPs0ITpw2NGLSR9JqaeH1FSgLTqH7ZCS4keb9AmbJQvP/2V8c8 PLjnXI3aEud42KAindupvSP/JEffX8r7mucGND+BXKHOKcVue81PwsenAPTCtlYhxDtR ePcQ== X-Gm-Message-State: APjAAAXwBofidnZpN48GOEide0vROBLXv13repp6snalU22AbohbUjAS 6vim9hGgMikgttxkjU5HevtO/Q== X-Received: by 2002:adf:ee0e:: with SMTP id y14mr18755685wrn.275.1559643172203; Tue, 04 Jun 2019 03:12:52 -0700 (PDT) Received: from t460s.bristot.redhat.com ([5.170.68.106]) by smtp.gmail.com with ESMTPSA id h21sm14765898wmb.47.2019.06.04.03.12.50 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jun 2019 03:12:51 -0700 (PDT) Subject: Re: [RFC 2/3] preempt_tracer: Disable IRQ while starting/stopping due to a preempt_counter change To: Joel Fernandes Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, williams@redhat.com, daniel@bristot.me, "Steven Rostedt (VMware)" , Ingo Molnar , Thomas Gleixner , "Paul E. McKenney" , Matthias Kaehlcke , Frederic Weisbecker , Yangtao Li , Tommaso Cucinotta References: <20190529083357.GF2623@hirez.programming.kicks-ass.net> <20190531074729.GA153831@google.com> From: Daniel Bristot de Oliveira Message-ID: <3a17724b-f903-bc18-1a35-84efd3ea90c9@redhat.com> Date: Tue, 4 Jun 2019 12:12:36 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190531074729.GA153831@google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 31/05/2019 09:47, Joel Fernandes wrote: > On Wed, May 29, 2019 at 11:40:34AM +0200, Daniel Bristot de Oliveira wrote: >> On 29/05/2019 10:33, Peter Zijlstra wrote: >>> On Tue, May 28, 2019 at 05:16:23PM +0200, Daniel Bristot de Oliveira wrote: >>>> The preempt_disable/enable tracepoint only traces in the disable <-> enable >>>> case, which is correct. But think about this case: >>>> >>>> ---------------------------- %< ------------------------------ >>>> THREAD IRQ >>>> | | >>>> preempt_disable() { >>>> __preempt_count_add(1) >>>> -------> smp_apic_timer_interrupt() { >>>> preempt_disable() >>>> do not trace (preempt count >= 1) >>>> .... >>>> preempt_enable() >>>> do not trace (preempt count >= 1) >>>> } >>>> trace_preempt_disable(); >>>> } >>>> ---------------------------- >% ------------------------------ >>>> >>>> The tracepoint will be skipped. >>> >>> .... for the IRQ. But IRQs are not preemptible anyway, so what the >>> problem? >> >> >> right, they are. >> >> exposing my problem in a more specific way: >> >> To show in a model that an event always takes place with preemption disabled, >> but not necessarily with IRQs disabled, it is worth having the preemption >> disable events separated from IRQ disable ones. >> >> The main reason is that, although IRQs disabled postpone the execution of the >> scheduler, it is more pessimistic, as it also delays IRQs. So the more precise >> the model is, the less pessimistic the analysis will be. >> >> But there are other use-cases, for instance: >> >> (Steve, correct me if I am wrong) >> >> The preempt_tracer will not notice a "preempt disabled" section in an IRQ >> handler if the problem above happens. >> >> (Yeah, I know these problems are very specific... but...) > > I agree with the problem. I think Daniel does not want to miss the preemption > disabled event caused by the IRQ disabling. Hi Joel! Correct, but ... look bellow. >>>> To avoid skipping the trace, the change in the counter should be "atomic" >>>> with the start/stop, w.r.t the interrupts. >>>> >>>> Disable interrupts while the adding/starting stopping/subtracting. >>> >>>> +static inline void preempt_add_start_latency(int val) >>>> +{ >>>> + unsigned long flags; >>>> + >>>> + raw_local_irq_save(flags); >>>> + __preempt_count_add(val); >>>> + preempt_latency_start(val); >>>> + raw_local_irq_restore(flags); >>>> +} >>> >>>> +static inline void preempt_sub_stop_latency(int val) >>>> +{ >>>> + unsigned long flags; >>>> + >>>> + raw_local_irq_save(flags); >>>> + preempt_latency_stop(val); >>>> + __preempt_count_sub(val); >>>> + raw_local_irq_restore(flags); >>>> +} >>> >>> That is hideously expensive :/ >> >> Yeah... :-( Is there another way to provide such "atomicity"? >> >> Can I use the argument "if one has these tracepoints enabled, they are not >> considering it as a hot-path?" > > The only addition here seems to the raw_local_irq_{save,restore} around the > calls to increment the preempt counter and start the latency tracking. > > Is there any performance data with the tracepoint enabled and with/without > this patch? Like with hackbench? I discussed this with Steve at the Summit on the Summit (the reason why I did not reply this email earlier is because I was in the conf/traveling), and he also agrees with peterz, disabling and (mainly) re-enabling IRQs costs too much. We need to find another way to resolve this problem (or mitigate the cost).... :-(. Ideas? Thanks!! -- Daniel