Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp432801ybt; Sat, 13 Jun 2020 09:01:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxU7+Dgrlhj+Avk8C7TNQxB0CMDZdTGzqjh0nEe5udFbRO3gXPQaDyNMQyl/q1EPhdP63de X-Received: by 2002:aa7:d359:: with SMTP id m25mr16032116edr.365.1592064069082; Sat, 13 Jun 2020 09:01:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592064069; cv=none; d=google.com; s=arc-20160816; b=sOwTTA3Y64cJFxJ6Sk8VJMTQF51QFutRX0K9G8iVAGI9MCWnsci+hbNmBdyyAaMPS1 k4e2n/smralvIPLD/guI16Wn99Y5lSe93IVYiJfvtnAZzqKYkvgxFiNzK4E6uf0wQYHv EdxQXHkXCOqgeQq3/JkziSlxsDSdHGHTUDQ4yt+vk5yJS5Zw9KQnFAwxXYI/nrdlcxtt lfw+x8r33HgXhLBXQdYgBtToFgr4BnvZp/dFSFVhPL3lKCiaQ+DOJwfb2qLmCz2RF+1P XIFwO3ndvjl5fuskwOiNvXGaTtfKQ4tioIUFF6d7H5z8j1+n2DxZJzVaPGdFYPmQwZzo P93A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=On9x8U6BadMsH1Q4D0HNQM4K9MGExTx1lOtQM+fe6Ts=; b=GL/DNu6p5GI3OAnPlD/UkrW+WZID5AHeIw80wCWxxW4wQ6xW4aF3L+B4vAKKkilyCJ taf4hYBRa0a/yRtrKK0EpJNXJkwrMb/ZUI9D/6mBQkPiV7Opb6U1bG6Zjk9zJjVa69Wb jx0PZlueEkUfG4xVh5E4GnfUBo21mOdK+DLtVPzud+tOS6wBzI+dTtsfhEZuEXR/Luqq luPscqrncMHpfR/NFGqwro0BN+nRzot918tSYVf+rfYcknHGsdGzYid9LQXfu/MXUhMl Ofl4912BPwskxepxzy8X/GMBYWOiyjDslm782ScIkiyeKnnv1+/zrk2K3F4Xw4vlz5Kh BP8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VZ9xdhob; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mj14si6015582ejb.464.2020.06.13.09.00.46; Sat, 13 Jun 2020 09:01:09 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VZ9xdhob; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726688AbgFMP6m (ORCPT + 99 others); Sat, 13 Jun 2020 11:58:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726656AbgFMP6f (ORCPT ); Sat, 13 Jun 2020 11:58:35 -0400 Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A83CEC03E96F for ; Sat, 13 Jun 2020 08:58:34 -0700 (PDT) Received: by mail-ot1-x32b.google.com with SMTP id n6so9789587otl.0 for ; Sat, 13 Jun 2020 08:58:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=On9x8U6BadMsH1Q4D0HNQM4K9MGExTx1lOtQM+fe6Ts=; b=VZ9xdhobG94BzWwaEhzZ/jBYnpzXsFyfTeW1VAFncAltn5buWrt29ELQYpfFV2++5g OIL6m6gWgXgyVOgnD99EIC3eYuU188nCAj4hSB8uwPyC7mcxtNQjGmleKdf8IZzf55zv MVjLZwmmx/QC1yRIOxqc2H+gPAKs2H972MpGixdrf1N5+wA6CG63a9Ai5mhpEJbpyjgC YzGbMlLUNMSq+thI3hMMw088wKjfo+1vKKq9v740ytiFiisguUYe8fHKz5R8s2++0gTM gtfh3X87Ty4rKZ7OlYfMP/t3e6Lc3jLZKkpk+N6NRVTNEyEMbml563GeIjP1iU7DZu4a KBgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=On9x8U6BadMsH1Q4D0HNQM4K9MGExTx1lOtQM+fe6Ts=; b=hiPbLfvsDMW6CIo+SlxsyZuGAXQ0ctDL3NMggPe29ve8HV0ilFxxKC0j36glRabO8a Sf8Ipy10Os/nIGoJDq5QdoRIAu98ifewngEAOia0ZF5LrY0NXv0Gqd46lvbe+RZldQXc CWgUr5A9mtQAum+SR+cSRGv4EZacTM8dJsFT/F/9PjzmKeJcW4WbpMwdR6jtwHvef/a2 iZ74ca7imJvZULEq3D7MEa/zUgVHFNGZVfna4ZgwJnqpws1nCAZ5I0Aje6TvPcGQhqk1 J+Y9l3ye8ElrdEEJtiKnLIYzqV2GHsWOfyBAQH4y1t99Bi5NBkeLUfW05AN6P+8SCiz8 6K9Q== X-Gm-Message-State: AOAM531IZItf2FlGCb2bm6MARTVnxx+1GQZlX68BLfy0iQuirnYDDW2q BigdIEZAkdMTeRYqPw2sGZzO3Mf3cQY= X-Received: by 2002:a9d:560d:: with SMTP id e13mr15024943oti.55.1592063913824; Sat, 13 Jun 2020 08:58:33 -0700 (PDT) Received: from frodo.hsd1.co.comcast.net ([2601:284:8204:6ba0::aaac]) by smtp.googlemail.com with ESMTPSA id 53sm2105565otv.22.2020.06.13.08.58.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2020 08:58:33 -0700 (PDT) From: Jim Cromie To: jbaron@akamai.com, linux-kernel@vger.kernel.org, akpm@linuxfoundation.org, gregkh@linuxfoundation.org Cc: linux@rasmusvillemoes.dk, Jim Cromie Subject: [PATCH v2 20/24] dyndbg: WIP towards debug-print-class based callsite controls Date: Sat, 13 Jun 2020 09:57:34 -0600 Message-Id: <20200613155738.2249399-21-jim.cromie@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200613155738.2249399-1-jim.cromie@gmail.com> References: <20200613155738.2249399-1-jim.cromie@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are *lots* of ad-hoc debug printing solutions in kernel, this is a 1st attempt at providing a common mechanism for many of them. Basically, there are 2 styles of debug printing: - levels, with increasing verbosity, 1-10 forex - bits/flags, independently controlling separate groups of dprints This patch does bits/flags only. proposed API: Usage model is for a module developer to create N exclusive subsets of pr_debug()s by changing some of them to pr_debug_n(1,) .. pr_debug_n(N,). Each callsite must be a single print-class, with 0 default. No multi-type classification ala pr_debug_M(1|2, ...) is contemplated. - change pr_debug(...) --> pr_debug_n(pr_class=0, ...) - all existing uses have pr_class=0 - developer creates exclusive types of log messages with pr_class>0 1, 2, 3 are disjoint groups, for example: hi, mid, low 0 is reserved for existing uses. - adds query term: "mflags $arg" rename keyword to prcls ? Qfoo() { echo module foo $* >/proc/dynamic_debug/control } Qfoo +p # all groups, including default 0 Qfoo mflags 1 +p # only group 1 Qfoo mflags 12 +p # TBD[1]: groups 1 or 2 Qfoo mflags 0 +p # ignored atm TBD[2] Qfoo mflags af +p # TBD[3]: groups a or f (10 or 15) so patch does: - add unsigned int pr_classes into struct ddebug_query this is a bit-vector bit positions select which print-classes to filter callsites for - add unsigned int pr_class:5 to struct _ddebug picks a single debugflag bit. No subclass or multitype nonsense. nice and dense, packs with other members. if adoption is good, kernel will have a lot of struct _ddebugs. - in ddebug_change() IFF query->module is given, and matches dt->mod_name print-classes are defined on a module, so we require one. this is fooled by "module *" simple fix is to exclude any wildcard when mflags given - in parse_query() accept new query term: mflags $arg populate query->mflags arg-type needs some attention, but basic plumbing is there WIP: not included: - pr_debug_n( pr_class=0, ....) aka: pr_debug_class() or pr_debug_id() bikeshedding welcome. the bitpos is 1<0 for distinct developer groups */ unsigned int lineno:18; /* * The flags field controls the behaviour at the callsite. diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index cb5c7480e026..0035218d7059 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -55,6 +55,7 @@ struct ddebug_query { const char *function; const char *format; unsigned int first_lineno, last_lineno; + unsigned int pr_classes; }; struct ddebug_iter { @@ -132,13 +133,14 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg) fmtlen--; } - vpr_info("%s: func=\"%s\" file=\"%s\" module=\"%s\" format=\"%.*s\" lineno=%u-%u\n", + vpr_info("%s: func=\"%s\" file=\"%s\" module=\"%s\" format=\"%.*s\" lineno=%u-%u prcls=0x%x\n", msg, maybe(query->function, ""), maybe(query->filename, ""), maybe(query->module, ""), fmtlen, maybe(query->format, ""), - query->first_lineno, query->last_lineno); + query->first_lineno, query->last_lineno, + query->pr_classes); } /* @@ -203,6 +205,27 @@ static int ddebug_change(const struct ddebug_query *query, if ((~dp->flags & filter->mask) != filter->mask) continue; + /* filter on non-zero print-classes */ + if (query->pr_classes) { + if (!query->module) { + pr_err("using prcls requires module too"); + return -EINVAL; + } + /* since print-classes are module + * specific, require a module query + * too. For 'module kvm* mflags 1' + * >control, this will enable + * pr_class=1 in several matching modules + */ + if ((query->pr_classes & (1<<(dp->pr_class-1))) + != (1<<(dp->pr_class-1))) { + v2pr_info("%s ~ %s mflags:0x%x !~ %d\n", + dt->mod_name, query->module, + query->pr_classes, dp->pr_class); + continue; + } + } + nfound++; newflags = (dp->flags & mods->mask) | mods->flags; @@ -427,6 +450,12 @@ static int ddebug_parse_query(char *words[], int nwords, } else if (!strcmp(keyword, "line")) { if (parse_linerange(query, arg)) return -EINVAL; + } else if (!strcmp(keyword, "mflags")) { + pr_info("handle mflags arg: %s\n", arg); + if (kstrtouint(arg, 4, &query->pr_classes) < 0) { + pr_err("bad arg for mflags: %s\n", arg); + return -EINVAL; + } } else { pr_err("unknown keyword \"%s\"\n", keyword); return -EINVAL; -- 2.26.2