Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5601231pxb; Mon, 28 Mar 2022 14:48:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+6E94bVEHYQq8BArsm6wG1tKApOfKvlxvbkl7GpvMX6050uW75Dqtr8j6JQXW/Jhltpzk X-Received: by 2002:a05:6102:3025:b0:325:40ae:4a3 with SMTP id v5-20020a056102302500b0032540ae04a3mr13282686vsa.65.1648504133022; Mon, 28 Mar 2022 14:48:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648504133; cv=none; d=google.com; s=arc-20160816; b=WP03aSFYflD9jqbFTXmJh3/GuSNK4QisxO3b3vfDnZ4GodFRnFjVHsKPOy0Vq+4F9k Kf6lpwl8RB23xXHNFqMnci3V3+oCAYs+yxlREhcTI1TiMApuQ/HeFHcXXA9nwmIeZAqc /Il/GSAqTvv1UeOCHDW/2ncbhxywlucz1up9bdo0F9l703zav42gMB0bp8ldYolQuPOf 8eseYfML4Kx3Mz8P8K2GggbRRrAre0KK+sSK3JT8kH2YWDDOP61hoQ5z0wXQby1QQBFb QnQ2EYkSKaX3Hhs8mwfIEl3txp10jJ75WU0vqJfAu2GS/O7IlZn72ncMURoqygTiyOc7 zCAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=CCKplzUskEQ9PwRTyuFUMJADGXMGT+3wuQ0LIFqQJTA=; b=fAIOC81BolraIlPZ+8Lks6PRNv3oiwAy+1epECzZrbhvVeKsDNu1gbH2Q0vja9q93t idgPz3AzQVCypyy/dEr2LSYbhafqRcjooZS4nzSAIpPSHeuaGHUiypgu6S3nqU6hBLk6 lRxfwO34hA1rAlrqyKu/yNvYJ/2tOb34IoF4xp02y5ieVvpzNkE/zycD/NZo9fib71Jw 0xTSlMH/jjyFj2zN/LlcnGlPZ0wTFAIVznDexzB1D5A/0z5RDS2lyrEAn7QCh2wlUO2K ysTiijvcbVgF3tPL0JATN2/2o2qYLYaEEt8BQbbX2OWZoar/rY4Kaz6viqrYn+OFt4DF kgJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="iVLFo3/W"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m3-20020a67d583000000b00324c5c3be58si3104892vsj.154.2022.03.28.14.48.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 14:48:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="iVLFo3/W"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B651AEDF26; Mon, 28 Mar 2022 14:20:55 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245498AbiC1TJn (ORCPT + 99 others); Mon, 28 Mar 2022 15:09:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245491AbiC1TJh (ORCPT ); Mon, 28 Mar 2022 15:09:37 -0400 Received: from mail-ua1-x92d.google.com (mail-ua1-x92d.google.com [IPv6:2607:f8b0:4864:20::92d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A625E66AC1 for ; Mon, 28 Mar 2022 12:07:55 -0700 (PDT) Received: by mail-ua1-x92d.google.com with SMTP id m42so6733382uae.0 for ; Mon, 28 Mar 2022 12:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=CCKplzUskEQ9PwRTyuFUMJADGXMGT+3wuQ0LIFqQJTA=; b=iVLFo3/Wbarqi1Gy59ZX3ni8OxRbwnW/akTYc6RfW1m8CgbjSSyNDMtRp1RVi7Tejz b8YQxZyK2jg/JAPh9AsJ0u4zLhoff1XDlf7NrWZEhJegte0LIdZ4IU6PC0WYwSjaHDjG RFgv7u7HdAtOW66kFkWDiyk0LYdF9Ihm9DpHuX+mloqKl0secFILqUdD6yRMndKNIzGN EFEJJBx6HsqPkivC5Zr9d/3RQqo6iWX2oenhxT7GQSq58SPUyBmNv6jwsg86dQzXeyE3 A3TdXe+MnA71RRcWLkbZ3wp8uGAphDzGldReYbNgQVUH49wE9PBm9VkLo0ky5A2w1yNh 1p9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=CCKplzUskEQ9PwRTyuFUMJADGXMGT+3wuQ0LIFqQJTA=; b=LE7576LqdW95ovFi35Bo4PnXSZnjHVrglD5cFJh7cDox96SSKxZf8JljfVpi2zRCul 7rP0L4oRCaAZeORFjvg5e06gLY48X449cayJa0qIV4j9SN6oJTZ0gtub5MYuB2cRDfd0 6k9lmwjHmFAfAk42JGWvbHlA3XokxY/8reff0LYOBTljMu0nkuxeZcFlsfivmBjTkfia tkmMJcUhAiZdewz6JRdVL1PwnPOkWi3EqOnp1Mhue3xbu+Ct419u2XNM4LfeeaqjKQF6 X5e2Z5Sp95JzmWGezjJ8V9qM/0H3AfRsmdMECaourCEvPpLi1UJMKPVQYHfwUDok4NW4 8ikw== X-Gm-Message-State: AOAM532/dDHmENbxbR03UGYu7cVdYEM0QkOR+LH7VS3oPg82HpmN9O5f xU/4l9VYHnpaqeB6+R+11kX/2H45IcJIgtCoRLc= X-Received: by 2002:ab0:4ac1:0:b0:351:ed7d:e65c with SMTP id t1-20020ab04ac1000000b00351ed7de65cmr12559304uae.36.1648494474130; Mon, 28 Mar 2022 12:07:54 -0700 (PDT) MIME-Version: 1.0 References: <20220311044756.425777-1-jim.cromie@gmail.com> <20220311044756.425777-3-jim.cromie@gmail.com> <823e51e6-2af4-7854-9428-697a2af12488@akamai.com> <0d00c529-3bac-f09f-e07c-584194251a06@akamai.com> In-Reply-To: <0d00c529-3bac-f09f-e07c-584194251a06@akamai.com> From: jim.cromie@gmail.com Date: Mon, 28 Mar 2022 13:07:27 -0600 Message-ID: Subject: Re: [PATCH 2/5] dyndbg: add class_id field and query support To: Jason Baron Cc: Greg KH , LKML , Daniel Vetter , Sean Paul , robdclark@gmail.com, Rasmus Villemoes , Joe Perches , dri-devel , amd-gfx mailing list , intel-gvt-dev@lists.freedesktop.org, Intel Graphics Development Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 14, 2022 at 3:30 PM Jason Baron wrote: > > > > On 3/11/22 20:06, jim.cromie@gmail.com wrote: > > On Fri, Mar 11, 2022 at 12:06 PM Jason Baron wrote: > >> > >> > >> > >> On 3/10/22 23:47, Jim Cromie wrote: > >>> > >>> With the patch, one can enable current/unclassed callsites by: > >>> > >>> #> echo drm class 15 +p > /proc/dynamic_debug/control > >>> > >> > >> To me, this is hard to read, what the heck is '15'? I have to go look it > >> up in the control file and it's not descriptive. I think that using > >> classes/categories makes sense but I'm wondering if it can be a bit more > >> user friendly? Perhaps, we can pass an array of strings that is indexed > >> by the class id to each pr_debug() site that wants to use class. So > >> something like: hi Jason, Im now in basically full agreement with you 1. .class_id is a "global" space, in that all callsites have one. 2. 0-15 is an exceedingly small range for a global space Fix that by 3. make it private (by removing "class N" parsing) now nobody can do echo module * class N +p >control 4. add private/per-module "string" -> class_id map each module will have to declare the class-strings they use/accept opt-in - want coordinated / shared names for DRM_UT_KMS etc. 5. validate input using the known class_string -> class_id then, this is knowably right or wrong, depending on DRM_FOO: echo module drm class DRM_FOO +p > control it also means that echo class DRM_UT_KMS +p >control is both wellformed and minimal; any module that has DRM_UT_KMS defined will know which class_id *they* have mapped it to. theres no global "DRM_UT_KMS" to be abused. So Ive been working towards that.. Heres my current biggest roadblock DEFINE_DYNAMIC_DEBUG_CLASSBITS creates the class-strings[] array declaratively, at compile-time. This array is attached to the kernel-param.args, so it can be used by the callbacks (to construct the command) But its not obviously available from outside the sysfs knob that its attached to, as is needed to apply command >control generally. If I can attach the class-strings[] to struct ddebug_table, then ddebug_change() can use it to validate >control input. So, how to attach ? its got to work for both builtin & loadable modules. (which precludes something in struct module ?) I looked for a kernel_param_register callback, came up empty. Trying to add it feels invasive / imposing. > > > > If that works, its cuz DEFINE_DYNAMIC_DEBUG_CLASSBITS() > > plucks class symbols out of its __VA_ARGS__, and #stringifes them. > > So that macro could then build the 1-per-module static constant string array > > and (only) the callbacks would be able to use it. > > So Ive been tinkering hard on this macro, since its pretty central to the interface defn. heres some choices: this is what Ive been working towards. using enum symbols directly like this associates them by grep, in contrast, class-strings are mealy-mouthed, milquetoast. DEFINE_DYNAMIC_DEBUG_CLASSBITS(debug, __drm_debug, "p", "enable drm.debug categories - 1 bit per category", DRM_UT_CORE, DRM_UT_DRIVER, DRM_UT_KMS, DRM_UT_PRIME, DRM_UT_ATOMIC, DRM_UT_VBL, DRM_UT_STATE, DRM_UT_LEASE, DRM_UT_DP, DRM_UT_DRMRES); I found a slick MAP ( ) macro to do this: #define DEFINE_DYNAMIC_DEBUG_CLASSBITS(fsname, _var, _flgs, desc, ...) \ MODULE_PARM_DESC(fsname, desc); \ static struct dyndbg_classbits_param ddcats_##_var = { \ .bits = &(_var), \ .flags = _flgs, \ .classes = { __VA_ARGS__, _DPRINTK_CLASS_DFLT }, \ .class_names = { mgMAP(__stringify, sCOMMA, \ __VA_ARGS__, _DPRINTK_CLASS_DFLT) } \ }; \ module_param_cb(fsname, ¶m_ops_dyndbg_classbits, \ &ddcats_##_var, 0644) __VA_ARGS__ is used 2x .class_names is available for validating command >control As much as I like the above, the MAP macro has a longer, more risky path to the kernel so a more modest alternative: module user defines class-strings in interface, but they *must* align manually with the enum values they correspond to; the order determines the bit-pos in the sysfs node, since the interface no longer provides the enum values themselves. DEFINE_DYNAMIC_DEBUG_CLASS_STRINGS(debug, __drm_debug, "p", "enable drm.debug categories - 1 bit per category", "DRM_UT_CORE", "DRM_UT_DRIVER", "DRM_UT_KMS", different name allows CLASSBITs or similar in future, if MAP works out. class-strings are completely defined by users, drm can drop UT naming TLDR: FWIW iSTM that the same macro will support the coordinated use of class-strings across multiple modules. drm_print.c - natural home for exposed sysfs node amdgpu/, drm_helper/ i915/ nouveau/ will all need a DEFINE_DD added, so that ddebug_change() can allow those .class_ids to be controlled. sysfs perm inits can disable their nodes, since theyre coordinated. > > > > Ok, yeah so I guess I'm thinking about the 'class' more as global namespace, > so that for example, it could span modules, or be specific to certain modules. > I'm also thinking of it as a 'string' which is maybe hierarchical, so that it's > clear what sub-system, or sub-sub-system it belongs to. So for DRM for example, > it could be a string like "DRM:CORE". The index num I think is still helpful for > implementation so we don't have to store a pointer size, but I don't think it's > really exposed (except perhaps in module params b/c drm is doing that already?). > So what Ive got here is as described above, I just need a few bright ideas, then I can bring it together. got a spare tuit? Jim