Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1654495yba; Tue, 2 Apr 2019 13:05:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzl+8lVlL7Amh77S1dL//6dhsGIyHHbBexCSJQJDKEH5ySFLW70hvz5RavXj0oajKUHkoFa X-Received: by 2002:a63:e554:: with SMTP id z20mr64423214pgj.234.1554235514468; Tue, 02 Apr 2019 13:05:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554235514; cv=none; d=google.com; s=arc-20160816; b=Zg27eXEZB0/yz9IMldzTM4438b4a31bn2nHCZtcX6C51jjADBvW4nqbq+W3ZemH9bb Nh0uvoBFWGIPr3Ba3t+4nXiai5/edY4s7b9Wt6ua9SKBM6rTMxzG+/UzKC9nhvHlBFoE XpRj8C5sQ0CWrE+vA6d3Hqnf1gtFf6DLB1DLfLUVnqS9+4XEq4kr0pjIX4guld3Ri1Vj /8ovvvQlItFy3L4MBL9vskfXQ+nMVOXv6hE9AXxotnDqGdSqp6Ooy85FbW4PLd3Q5MuQ 8ovLoKAyNwzSb5Syq/6JV2eFbJQHouNuJkd8mPwy2bpVliuUsceUyJ4Cd18y8kqG0YKu Zk5w== 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; bh=XUMZV+xvnaECk7afDe0wxaC+rbmCGdrHgIRKwzY8D24=; b=vm2ZL91s5Ik8DslAUmHW8TRyPqWpknDMe1jkZ1sbRESQX9esAEmIV+ACk8xDQ9ahmh r4evG184oQn5MfdReG1bs16WIvEx/hgcHJTVxj59daLQF/rBz3kOAJ/iB+uozhJfV4iV aYVV3E6QKyhtok8bgZOgY/mR5b1iZmJBTorplfXCox4oWUlm/sL+n2KBNKRm0eOS9LVQ JpI4Uq7ZlGA2mD33BrsX5hKqtrwLnwabG60rG3oo6ly/O1iDo30Rz6KR2JBAOC9haem8 Wxc3Zr9xxM/ZWM3JpE1V/p7FsE7OlPj3jQ8m68SR75mSXeV+yGoRVIUgIl1mHxtqcfnX vAPg== 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 h185si11546938pge.84.2019.04.02.13.04.59; Tue, 02 Apr 2019 13:05: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 S1726444AbfDBUEK (ORCPT + 99 others); Tue, 2 Apr 2019 16:04:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41922 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726419AbfDBUEJ (ORCPT ); Tue, 2 Apr 2019 16:04:09 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 48BC390B10; Tue, 2 Apr 2019 20:04:09 +0000 (UTC) Received: from localhost.default (ovpn-116-31.phx2.redhat.com [10.3.116.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 929136014D; Tue, 2 Apr 2019 20:04:05 +0000 (UTC) From: Daniel Bristot de Oliveira To: linux-kernel@vger.kernel.org Cc: Steven Rostedt , Arnaldo Carvalho de Melo , Ingo Molnar , Andy Lutomirski , Thomas Gleixner , Borislav Petkov , Peter Zijlstra , "H. Peter Anvin" , "Joel Fernandes (Google)" , Jiri Olsa , Namhyung Kim , Alexander Shishkin , Tommaso Cucinotta , Romulo Silva de Oliveira , Clark Williams , x86@kernel.org Subject: [RFC PATCH 0/7] Early task context tracking Date: Tue, 2 Apr 2019 22:03:52 +0200 Message-Id: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 02 Apr 2019 20:04:09 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Note: do not take it too seriously, it is just a proof of concept. Some time ago, while using perf to check the automaton model, I noticed that perf was losing events. The same was reproducible with ftrace. See: https://www.spinics.net/lists/linux-rt-users/msg19781.html Steve pointed to a problem in the identification of the context execution used by the recursion control. Currently, recursion control uses the preempt_counter to identify the current context. The NMI/HARD/SOFT IRQ counters are set in the preempt_counter in the irq_enter/exit functions. In a trace, they are set like this: -------------- %< -------------------- 0) ==========> | 0) | do_IRQ() { /* First C function */ 0) | irq_enter() { 0) | /* set the IRQ context. */ 0) 1.081 us | } 0) | handle_irq() { 0) | /* IRQ handling code */ 0) + 10.290 us | } 0) | irq_exit() { 0) | /* unset the IRQ context. */ 0) 6.657 us | } 0) + 18.995 us | } 0) <========== | -------------- >% -------------------- As one can see, functions (and events) that take place before the set and after unset the preempt_counter are identified in the wrong context, causing the miss interpretation that a recursion is taking place. When this happens, events are dropped. To resolve this problem, the set/unset of the IRQ/NMI context needs to be done before the execution of the first C execution, and after its return. By doing so, and using this method to identify the context in the trace recursion protection, no more events are lost. A possible solution is to use a per-cpu variable set and unset in the entry point of NMI/IRQs, before calling the C handler. This possible solution is presented in the next patches as a proof of concept, for x86_64. However, other ideas might be better than mine... so... Daniel Bristot de Oliveira (7): x86/entry: Add support for early task context tracking trace: Move the trace recursion context enum to trace.h and reuse it trace: Optimize trace_get_context_bit() trace/ring_buffer: Use trace_get_context_bit() trace: Use early task context tracking if available events: Create an trace_get_context_bit() events: Use early task context tracking if available arch/x86/entry/entry_64.S | 9 ++++++ arch/x86/include/asm/irqflags.h | 30 ++++++++++++++++++++ arch/x86/kernel/cpu/common.c | 4 +++ include/linux/irqflags.h | 4 +++ kernel/events/internal.h | 50 +++++++++++++++++++++++++++------ kernel/softirq.c | 5 +++- kernel/trace/ring_buffer.c | 28 ++---------------- kernel/trace/trace.h | 46 ++++++++++++++++++++++-------- 8 files changed, 129 insertions(+), 47 deletions(-) -- 2.20.1