Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1547223pxa; Thu, 6 Aug 2020 10:00:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+5M6aPYBoooT7TE1D3zupQEU4EJzXAaKmWLTAKN3C6NSS0ox7fudcwylQuHuK/OKY7Py0 X-Received: by 2002:a17:906:348a:: with SMTP id g10mr5053816ejb.551.1596733229083; Thu, 06 Aug 2020 10:00:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596733229; cv=none; d=google.com; s=arc-20160816; b=xkSrfMTYYwPjOsQX2cLLoubh/TmNnqrOW2c2hsFByLy9HCrSKuOCv9hczRp70lpOyW fyFadS22eqGGFa/rmmcN0KcRgmtkZTKJQg6Yy7reIGnKO4edRWbJrjE8QgS6QsoaVR0y Pac8WeBGQ+om9z50c573e7dtXRtyoKUQkjS9WiEPlXsAkATMxF5VvpCT7Z5L+nt0o6XL SCeZHYh+VA+CZAdAdCq4bRTMri+7LbmVV3UAXfjoh6C0xeogzk4nGsj+LsS2cCFFuEUM Culo0j+gJ8xjqHkGKd4I/3zu6z+9y3vFBAvkoVsus08WpRIuJRlmmK69mDnMbwTllLxf sCuQ== 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:subject:cc:to:from:date; bh=/SIvgOzsTbrP8PUZFsQbHuEnvK3VGNboGraiRdV65v8=; b=CSpCCpGS8GglSUOnRt/dDZ9oIJknO4prUY0QbNlPmTe5bA0MU7V3a0JMkBlbowak5b taivCiKKtHzFatyUUhFUHskKNBfFFzeu8EJ9CafWuuBIViONP4iz0i6vfZ4eo1YMbbXr Mkkz/gkJPbYSg/bWcw1nSxZcNhHEWXWPNgmerEGIa8CvQUjQklWCzzPj6wU0Q4+9gtFG 3D2CPtmp7wEKbJAIp9OZc4aAAZuT/tUHe/bgK4s5fkG9xaGFFMopch23KhHCdmhroKdA ZC//auIhX5HdS0BOdgPoBvfrV84ds2Ila46Pmx6godPtLtl7h8tGOJ/6SO42Ar+vX/MX VZPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z12si3547067edx.530.2020.08.06.10.00.06; Thu, 06 Aug 2020 10:00:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729896AbgHFQ6E (ORCPT + 99 others); Thu, 6 Aug 2020 12:58:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:59368 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729876AbgHFQ5N (ORCPT ); Thu, 6 Aug 2020 12:57:13 -0400 Received: from oasis.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C3F4C2086A; Thu, 6 Aug 2020 16:57:12 +0000 (UTC) Date: Thu, 6 Aug 2020 12:57:10 -0400 From: Steven Rostedt To: LKML Cc: Sean Paul Subject: tracing: Add trace_array_init_printk() to initialize instance trace_printk() buffers Message-ID: <20200806125710.3e9bd355@oasis.local.home> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Steven Rostedt (VMware)" As trace_array_printk() used with not global instances will not add noise to the main buffer, they are OK to have in the kernel (unlike trace_printk()). This require the subsystem to create their own tracing instance, and the trace_array_printk() only writes into those instances. Add trace_array_init_printk() to initialize the trace_printk() buffers without printing out the WARNING message. Reported-by: Sean Paul Signed-off-by: Steven Rostedt (VMware) --- kernel/trace/trace.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 06c0feae5ff9..48b608d9c5b1 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -3129,6 +3129,9 @@ static int alloc_percpu_trace_buffer(void) { struct trace_buffer_struct *buffers; + if (trace_percpu_buffer) + return 0; + buffers = alloc_percpu(struct trace_buffer_struct); if (MEM_FAIL(!buffers, "Could not allocate percpu trace_printk buffer")) return -ENOMEM; @@ -3331,6 +3334,26 @@ int trace_array_vprintk(struct trace_array *tr, return __trace_array_vprintk(tr->array_buffer.buffer, ip, fmt, args); } +/** + * trace_array_printk - Print a message to a specific instance + * @tr: The instance trace_array descriptor + * @ip: The instruction pointer that this is called from. + * @fmt: The format to print (printf format) + * + * If a subsystem sets up its own instance, they have the right to + * printk strings into their tracing instance buffer using this + * function. Note, this function will not write into the top level + * buffer (use trace_printk() for that), as writing into the top level + * buffer should only have events that can be individually disabled. + * trace_printk() is only used for debugging a kernel, and should not + * be ever encorporated in normal use. + * + * trace_array_printk() can be used, as it will not add noise to the + * top level tracing buffer. + * + * Note, trace_array_init_printk() must be called on @tr before this + * can be used. + */ __printf(3, 0) int trace_array_printk(struct trace_array *tr, unsigned long ip, const char *fmt, ...) @@ -3355,6 +3378,26 @@ int trace_array_printk(struct trace_array *tr, } EXPORT_SYMBOL_GPL(trace_array_printk); +/** + * trace_array_init_printk - Initialize buffers for trace_array_printk() + * @tr: The trace array to initialize the buffers for + * + * As trace_array_printk() only writes into instances, they are OK to + * have in the kernel (unlike trace_printk()). This needs to be called + * before trace_array_printk() can be used on a trace_array. + */ +int trace_array_init_printk(struct trace_array *tr) +{ + if (!tr) + return -ENOENT; + + /* This is only allowed for created instances */ + if (tr == &global_trace) + return -EINVAL; + + return alloc_percpu_trace_buffer(); +} + __printf(3, 4) int trace_array_printk_buf(struct trace_buffer *buffer, unsigned long ip, const char *fmt, ...) -- 2.25.4