From patchwork Wed Aug 29 12:17:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Motai.Hirotaka@aj.MitsubishiElectric.co.jp" X-Patchwork-Id: 10580153 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 19417174A for ; Wed, 29 Aug 2018 12:36:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 084D12AFB5 for ; Wed, 29 Aug 2018 12:36:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F08622AFBA; Wed, 29 Aug 2018 12:36:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 70A2F2AFB5 for ; Wed, 29 Aug 2018 12:36:55 +0000 (UTC) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id EC526CB7; Wed, 29 Aug 2018 12:36:36 +0000 (UTC) X-Original-To: ltsi-dev@lists.linuxfoundation.org Delivered-To: ltsi-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 35CF5CAC for ; Wed, 29 Aug 2018 12:36:35 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mx04.melco.co.jp (mx04.melco.co.jp [192.218.140.144]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 20F74772 for ; Wed, 29 Aug 2018 12:36:34 +0000 (UTC) Received: from mr04.melco.co.jp (mr04 [133.141.98.166]) by mx04.melco.co.jp (Postfix) with ESMTP id EB8AA3A32B7 for ; Wed, 29 Aug 2018 21:18:07 +0900 (JST) Received: from mr04.melco.co.jp (unknown [127.0.0.1]) by mr04.imss (Postfix) with ESMTP id 420l5C6mQYzRk8j for ; Wed, 29 Aug 2018 21:18:07 +0900 (JST) Received: from mf03_second.melco.co.jp (unknown [192.168.20.183]) by mr04.melco.co.jp (Postfix) with ESMTP id 420l5C6STbzRjwX for ; Wed, 29 Aug 2018 21:18:07 +0900 (JST) Received: from mf03.melco.co.jp (unknown [133.141.98.183]) by mf03_second.melco.co.jp (Postfix) with ESMTP id 420l5C5z3KzRk8v for ; Wed, 29 Aug 2018 21:18:07 +0900 (JST) Received: from JPN01-TY1-obe.outbound.protection.outlook.com (unknown [23.103.139.184]) by mf03.melco.co.jp (Postfix) with ESMTP id 420l5C5r0dzRk38 for ; Wed, 29 Aug 2018 21:18:07 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mitsubishielectricgroup.onmicrosoft.com; s=selector1-mitsubishielectricgroup-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Shv2DghBVP38U0eBYW5evEAo015jPv79DM6Fr2TobEI=; b=FdmBavUcLfZr3zDbDmFImwjYCBrfyqz6KdreFocjd42vW5vopRzfBSS8v4XfCrGJzHyYrA6CMQOcItttJCTuEMwznrutyMY+kEhZURuyUH7Xf2zP4GXu8I+7SjnJiNWtIIivC5uDGdhdiOvgxPWxjYZY4yR7iR4URL41MNHRvPk= Received: from TY1PR01MB1692.jpnprd01.prod.outlook.com (52.133.160.145) by TY1PR01MB0762.jpnprd01.prod.outlook.com (10.167.158.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1080.15; Wed, 29 Aug 2018 12:18:07 +0000 Received: from TY1PR01MB1692.jpnprd01.prod.outlook.com ([fe80::d04e:e6f6:c782:22fa]) by TY1PR01MB1692.jpnprd01.prod.outlook.com ([fe80::d04e:e6f6:c782:22fa%2]) with mapi id 15.20.1080.015; Wed, 29 Aug 2018 12:18:07 +0000 From: "Motai.Hirotaka@aj.MitsubishiElectric.co.jp" To: "ltsi-dev@lists.linuxfoundation.org" Thread-Topic: [LTSI-dev] [PATCH 41/54] ring-buffer: Add nesting for adding events within events Thread-Index: AdQ/jNIwxCFkxtzOQnKdAE9c8CPx9w== Date: Wed, 29 Aug 2018 12:17:11 +0000 Deferred-Delivery: Wed, 29 Aug 2018 12:15:00 +0000 Message-ID: Accept-Language: ja-JP, en-US Content-Language: ja-JP X-MS-Has-Attach: X-MS-TNEF-Correlator: x-melpop: 1 authentication-results: spf=none (sender IP is ) smtp.mailfrom=Motai.Hirotaka@aj.MitsubishiElectric.co.jp; x-originating-ip: [153.231.200.201] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; TY1PR01MB0762; 6:7mHLBGUoh4Pu99xzBz6KwuXvGkEThEPHKDYCbZTvSfCTqxulHAFaeWcV7shJApMzF2IIgZlI1LYf1I18ZpSBrrxOSHAgvzIbUB+I4aLWQX2xnASAhOlw49zjrP302FtIQ9Oq+H65fJRYT9uWBXzF4S+MajkCUPbZoIhQDSCvzew6eZ49jJNP2fM5x1S7+AlNRm1X2sAF+aZJz6rc54JTLa9RJ/mIQbjXBWGGzI2Nw+Ua92CcVhdfToQZ3um14/MrL9H94Mgzv4nyW5SpAPC7gN6EgILBbv2d5uibh4R8Rd7lb/11wP3+uELJUF57otNxDaTWpS3zEmCHY6gdB/yTjPwTazKOzpjAo/+ycqsHl9zVXF0Wt1RKiaePffujVFfkGmr75+Gz+AocvrESJxHoAZzMMl7pVqMvqSZwqQPYLXI33poRKzxyIAwLuuRYKuvxXrXMrl6Ihst6i9w7A41tDA==; 5:QEZyWjK57dpacSGgr0k12qu4gaV9uyGKljelLnJrh314kGt3qf1gjlZtQOH7Ulb76yEvsQPhHKSl91Df8xox66CShIf3JfoVddqH/764/m0H9cRcyKktCRZ19tF/l2r3cU57yQrChcTRI/FlC4Ujn53TRC+5j42IyzZIQioVJJY=; 7:B2QMxdIdlLrQg1YsKKQYeSvQXXE9n1BFPZebtmorsjsvjEtOBS658vU2lg1NYoKvKLfLjvUpQ1xtk8S2kmiGv5iWyiOdwl/NgnwarFUA+NK4a7e1qCv20oYyXyugHSuzxkDorpVpYolk7v/GeIYfDPpQVYUnINHJbRvB/WbrolNUXKvFMJ8oh4vudWYt8aGjQuUN/HFvibD06LqI+TcZUJpWZ35RQmtUulmwUJPy/1HV7qnejMZ1Zi/JXoWG5d6E x-ms-office365-filtering-correlation-id: 85dabc9c-2973-4825-aa3a-08d60da97a61 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:TY1PR01MB0762; x-ms-traffictypediagnostic: TY1PR01MB0762: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(3231311)(944501410)(52105095)(93006095)(93001095)(3002001)(10201501046)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123558120)(20161123560045)(201708071742011)(7699016); SRVR:TY1PR01MB0762; BCL:0; PCL:0; RULEID:; SRVR:TY1PR01MB0762; x-forefront-prvs: 077929D941 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(396003)(346002)(376002)(136003)(366004)(199004)(189003)(7696005)(186003)(72206003)(6116002)(478600001)(3846002)(1857600001)(256004)(74482002)(5250100002)(5660300001)(14444005)(2501003)(99286004)(2900100001)(8936002)(53936002)(68736007)(33656002)(9686003)(2906002)(97736004)(26005)(476003)(7736002)(305945005)(74316002)(6666003)(316002)(14454004)(486006)(55016002)(81166006)(5640700003)(66066001)(8676002)(86362001)(6436002)(2351001)(6506007)(106356001)(25786009)(6916009)(105586002)(102836004)(575784001)(81156014); DIR:OUT; SFP:1102; SCL:1; SRVR:TY1PR01MB0762; H:TY1PR01MB1692.jpnprd01.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:0; MX:1; received-spf: None (protection.outlook.com: aj.MitsubishiElectric.co.jp does not designate permitted sender hosts) x-microsoft-antispam-message-info: wJ2uEwxlMUzdz6o8bcvK+zENDtheQXzyiidbwbuyPX2pNXbqiIEbY0v3xWL0Fc2jLvVvlVVopoOhNEdmly+NobRpwQ+HnGoDj9jWEJtkYT9/5RmLVmK/jY3G0uQR9QlGHSDU8puIWTmRL226+rwzGBd+08sSZidtdPFxi4QaSXYBYaGLBbnt0tzlypENrpqSkbKYqeXuGDsAtNde+4cSoZmCeS5L6YxDBeKlyAkammjBD7dZjHbfTk0DNfIuQHRe1/ByM/dxhh4+0+q5lEFsNMmIgBdwrUuLD4ifRa1Swnk/jhOHs5H1biJxzhyHEvil1Cf5PC0ngqE9QtRfmX30rq21TeYft6tFWNTWZBZmJuw= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aj.MitsubishiElectric.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: 85dabc9c-2973-4825-aa3a-08d60da97a61 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2018 12:17:22.6457 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: c5a75b62-4bff-4c96-a720-6621ce9978e5 X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY1PR01MB0762 Subject: [LTSI-dev] [PATCH 41/54] ring-buffer: Add nesting for adding events within events X-BeenThere: ltsi-dev@lists.linuxfoundation.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "A list to discuss patches, development, and other things related to the LTSI project" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ltsi-dev-bounces@lists.linuxfoundation.org Errors-To: ltsi-dev-bounces@lists.linuxfoundation.org X-Virus-Scanned: ClamAV using ClamSMTP The ring-buffer code has recusion protection in case tracing ends up tracing itself, the ring-buffer will detect that it was called at the same context (normal, softirq, interrupt or NMI), and not continue to record the event. With the histogram synthetic events, they are called while tracing another event at the same context. The recusion protection triggers because it detects tracing at the same context and stops it. Add ring_buffer_nest_start() and ring_buffer_nest_end() that will notify the ring buffer that a trace is about to happen within another trace and that it is intended, and not to trigger the recursion blocking. Signed-off-by: Steven Rostedt (VMware) (cherry picked from commit 8e012066fe0de5ff5be606836f9075511bce5604) Signed-off-by: Hirotaka MOTAI --- include/linux/ring_buffer.h | 3 ++ kernel/trace/ring_buffer.c | 57 +++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h index 6c2a6b3f..abce5f53 100644 --- a/include/linux/ring_buffer.h +++ b/include/linux/ring_buffer.h @@ -112,16 +112,19 @@ void ring_buffer_change_overwrite(struct ring_buffer *buffer, int val); struct ring_buffer_event *ring_buffer_lock_reserve(struct ring_buffer *buffer, unsigned long length); int ring_buffer_unlock_commit(struct ring_buffer *buffer, struct ring_buffer_event *event); int ring_buffer_write(struct ring_buffer *buffer, unsigned long length, void *data); +void ring_buffer_nest_start(struct ring_buffer *buffer); +void ring_buffer_nest_end(struct ring_buffer *buffer); + struct ring_buffer_event * ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts, unsigned long *lost_events); struct ring_buffer_event * ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts, unsigned long *lost_events); struct ring_buffer_iter * diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 45fc9155..75fea932 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -472,16 +472,17 @@ struct ring_buffer_per_cpu { unsigned int current_context; struct list_head *pages; struct buffer_page *head_page; /* read from head */ struct buffer_page *tail_page; /* write to tail */ struct buffer_page *commit_page; /* committed pages */ struct buffer_page *reader_page; unsigned long lost_events; unsigned long last_overrun; + unsigned long nest; local_t entries_bytes; local_t entries; local_t overrun; local_t commit_overrun; local_t dropped_events; local_t committing; local_t commits; unsigned long read; @@ -2630,29 +2631,79 @@ trace_recursive_lock(struct ring_buffer_per_cpu *cpu_buffer) int bit; if (!(pc & (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET))) bit = RB_CTX_NORMAL; else bit = pc & NMI_MASK ? RB_CTX_NMI : pc & HARDIRQ_MASK ? RB_CTX_IRQ : RB_CTX_SOFTIRQ; - if (unlikely(val & (1 << bit))) + if (unlikely(val & (1 << (bit + cpu_buffer->nest)))) return 1; - val |= (1 << bit); + val |= (1 << (bit + cpu_buffer->nest)); cpu_buffer->current_context = val; return 0; } static __always_inline void trace_recursive_unlock(struct ring_buffer_per_cpu *cpu_buffer) { - cpu_buffer->current_context &= cpu_buffer->current_context - 1; + cpu_buffer->current_context &= + cpu_buffer->current_context - (1 << cpu_buffer->nest); +} + +/* The recursive locking above uses 4 bits */ +#define NESTED_BITS 4 + +/** + * ring_buffer_nest_start - Allow to trace while nested + * @buffer: The ring buffer to modify + * + * The ring buffer has a safty mechanism to prevent recursion. + * But there may be a case where a trace needs to be done while + * tracing something else. In this case, calling this function + * will allow this function to nest within a currently active + * ring_buffer_lock_reserve(). + * + * Call this function before calling another ring_buffer_lock_reserve() and + * call ring_buffer_nest_end() after the nested ring_buffer_unlock_commit(). + */ +void ring_buffer_nest_start(struct ring_buffer *buffer) +{ + struct ring_buffer_per_cpu *cpu_buffer; + int cpu; + + /* Enabled by ring_buffer_nest_end() */ + preempt_disable_notrace(); + cpu = raw_smp_processor_id(); + cpu_buffer = buffer->buffers[cpu]; + /* This is the shift value for the above recusive locking */ + cpu_buffer->nest += NESTED_BITS; +} + +/** + * ring_buffer_nest_end - Allow to trace while nested + * @buffer: The ring buffer to modify + * + * Must be called after ring_buffer_nest_start() and after the + * ring_buffer_unlock_commit(). + */ +void ring_buffer_nest_end(struct ring_buffer *buffer) +{ + struct ring_buffer_per_cpu *cpu_buffer; + int cpu; + + /* disabled by ring_buffer_nest_start() */ + cpu = raw_smp_processor_id(); + cpu_buffer = buffer->buffers[cpu]; + /* This is the shift value for the above recusive locking */ + cpu_buffer->nest -= NESTED_BITS; + preempt_enable_notrace(); } /** * ring_buffer_unlock_commit - commit a reserved * @buffer: The buffer to commit to * @event: The event pointer to commit. * * This commits the data to the ring buffer, and releases any locks held.