Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp675252pxy; Wed, 21 Apr 2021 12:05:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyALpqV13brGWkjROdU505UcApYViyZK7jJfoYSZDutagZzvHoOLnPhI9LXcKIX0cBU5b1I X-Received: by 2002:a17:902:7c94:b029:e6:e1d7:62b7 with SMTP id y20-20020a1709027c94b02900e6e1d762b7mr34804143pll.29.1619031954784; Wed, 21 Apr 2021 12:05:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619031954; cv=none; d=google.com; s=arc-20160816; b=e447+KOTpY+oLkPAzktgkPx1ADQAg4xH9SBGCsz7g/PmAbuYajbQmAo99vOxG1zAXn CoDnn0TKH8/m5oIsMwK0D9V2eb3eslGZtdTXJT/24nyms7hPkCk63UMg78xS8yNXPWdS 5ci6dOxptuaFN6pukXUBrejeBzaWcG0didF2hrV1MQVFUihjJhg5UcxO9g5VPtphaQEL you3hl+by6G/ZGGRbfK0Rh+0St7RgAvgSpEledAOicKNs4LIRmqzTnTFUZnOefVsGOdd BqXkIfO+miEiPFgl4wlK7ggSC4g8ZmOekHfi98zEIQEUQ/dhOEVUAcdz0ERQQKq6ps/r bX5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=ewNA2EVZwRNiuH0sNgsx+JfcvZ0BgXgneaqlK1rNFQs=; b=XjTgLLTwNvpml9CzRUxkjtqnIFECBTheHhpXvSsBHxd/wM3x3hvUrH5r/hcdeDHego LfZSUN4ei7lRPtf1LcnPyx7m3hAk68cK1PZIUgERM7YBcjM5lrDYhMIfEVRvC2MwyQ2f gpp4XPBjeUIHDErC27xT/WmST9IgAYRQtWZ7DfHjyZecy/hnJMT5iziph3b3L0/beeEv NSMPPwqPcNhyxKkh9TQovXGDFso5orc2akzTXqW3z65Y1ZwTAUdmnfvQzfYo1HFeMIC4 k/u5dJvRq8Df7FyQ/Ky1yNrh4wp4vBidvVGyNhKMsw90BWxAkA1gnGFE5kpbaReCRH/K onSg== 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 e64si3848956pjc.65.2021.04.21.12.05.43; Wed, 21 Apr 2021 12:05:54 -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 S243466AbhDUOUr (ORCPT + 99 others); Wed, 21 Apr 2021 10:20:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:49202 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241496AbhDUOUo (ORCPT ); Wed, 21 Apr 2021 10:20:44 -0400 Received: from gandalf.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 5C54D6144E; Wed, 21 Apr 2021 14:20:10 +0000 (UTC) Date: Wed, 21 Apr 2021 10:20:08 -0400 From: Steven Rostedt To: Rasmus Villemoes Cc: Dan Williams , "fweisbec@gmail.com" , "jeyu@kernel.org" , "mathieu.desnoyers@efficios.com" , "linux-kernel@vger.kernel.org" , "mingo@elte.hu" , "chris@chris-wilson.co.uk" , "yuanhan.liu@linux.intel.com" , "Grumbach, Emmanuel" Subject: Re: [PATCH][RFC] tracing: Enable tracepoints via module parameters Message-ID: <20210421102008.411af7c5@gandalf.local.home> In-Reply-To: <5d191e26-bd00-c338-e366-b4855ac08053@rasmusvillemoes.dk> References: <1299622684.20306.77.camel@gandalf.stny.rr.com> <877hc64klm.fsf@rustcorp.com.au> <20130813111442.632f3421@gandalf.local.home> <87siybk8yl.fsf@rustcorp.com.au> <20130814233228.778f25d0@gandalf.local.home> <77a6e40b57df092d1bd8967305906a210f286111.camel@intel.com> <20210419181111.5eb582e8@gandalf.local.home> <20210420085532.4062b15e@gandalf.local.home> <20210420163243.45293c9a@gandalf.local.home> <5d191e26-bd00-c338-e366-b4855ac08053@rasmusvillemoes.dk> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 21 Apr 2021 09:30:01 +0200 Rasmus Villemoes wrote: > On 20/04/2021 22.32, Steven Rostedt wrote: > > On Tue, 20 Apr 2021 12:54:39 -0700 > > Dan Williams wrote: > > > >> On Tue, Apr 20, 2021 at 5:55 AM Steven Rostedt wrote: > >>>> > >>>> The dev_dbg() filter language is attractive, it's too bad > >>> > >>> Not sure what you mean by that. What filter language. Tracepoints do have a > >>> pretty good filtering too. > >> > > > But you can add your own trace point, and even make it generic. That's what > > bpf did for their bpf_trace_printk. You could convert dev_dbg() into a > > tracepoint! > > > > > > static __printf(2, 3) int __dev_dbg(const struct device *dev, char *fmt, ...) > > { > > static char buf[DEV_DEBUG_PRINTK_SIZE]; > > unsigned long flags; > > va_list ap; > > int ret; > > > > raw_spin_lock_irqsave(&dev_dbg_printk_lock, flags); > > va_start(ap, fmt); > > ret = vsnprintf(buf, sizeof(buf), fmt, ap); > > va_end(ap); > > /* vsnprintf() will not append null for zero-length strings */ > > if (ret == 0) > > buf[0] = '\0'; > > Wrong. snprintf(buf, 16, "") will work just fine and cause a '\0' to be > written to buf[0]. As will snprintf(buf, 16, "%s", ""), and any other > case where there ends up being no characters printed. I just cut and pasted the bpf_trace_printk() code and modified it for here. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/trace/bpf_trace.c#n404 > > The only case where snprintf does not guarantee nul-termination is when > the _buffer size_ is 0, in which case vsnprintf obviously cannot and > must not write anything at all (that's used for the "how much do I need > to allocate" situation). > > > > > #define dev_dbg(dev, fmt, ...) \ > > do { \ > > if (trace_dev_dbg_printk_enabled()) \ > > __dev_dbg(dev, fmt, ##__VA_ARGS__); \ > > } while (0) > > > > Note, the "trace_dev_dbg_printk_enabled()" is a static branch, which means > > it is a nop when the dev_dbg_printk tracepoint is not enabled, and is a jmp > > to the __dev_dbg() logic when it is enabled. It's not a conditional branch. > > dynamic_debug has been implemented in terms of static_keys for a long > time. And that's a per-dev_dbg invocation static key. IIUC, the above > would cause every single dev_dbg in the kernel to pass through the "grab > a raw spin lock and do the snprintf" thing even when one is just > interested in the dev_dbgs inside a single driver or function. If you want to make it per device, I'm sure three's a way. Or allocate a per-cpu buffer for the sprintf storage, and then you only need to disable interrupts. And if you make the storage 4 levels deep per CPU (like trace_printk does), then you only need to disable preemption and not even interrupts. The above wasn't a patch submission. It was a proof of concept. Everything you brought up can be trivially dealt with. -- Steve