From nobody Tue Feb 10 03:44:58 2026 Received: from mail-io1-f47.google.com (mail-io1-f47.google.com [209.85.166.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E2E120AF8F for ; Sat, 25 Jan 2025 06:47:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737787623; cv=none; b=jhB4OYhYoHH64a5WNaqC3JzYeV1Ga74naFHU0VF3kgrkS56YA1UUafdF2e7PaBCXL3xz0AV2jJvehh/NJjKzYF184AN/pFnIrhpIWPNqUJ4hpopBEA6YuyqGFckFlbmUOw30JzgBE6qZXK0rfkpnpcgntI0OwUsXSyAZLsSIIwo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737787623; c=relaxed/simple; bh=igIOyXsIVjERhgcOda2PMIdzCblmuTSjD0tS0IWV7mg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Epmn7jUiB5nYlI+qFSXDYspKthHLFGEdlmzwGTPn5lWL3DPTQi/PBcmOniqF0uCwCNz8OH63XiHNj0RIKN0jd/CKoXA9i4K8SzDMQKrAt4/tpxzRyWG/1theX4SdBbOQJTty8EtXgBAZSiyMcakr4BY5CMCyERqfsco0cihodKg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=X9EFJIPd; arc=none smtp.client-ip=209.85.166.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="X9EFJIPd" Received: by mail-io1-f47.google.com with SMTP id ca18e2360f4ac-844eb33827eso78307839f.2 for ; Fri, 24 Jan 2025 22:47:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737787621; x=1738392421; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ke4SvBesy7HOPaleQwpGGG+LJLBeY9FJV6nhVnr7e/A=; b=X9EFJIPd2yiYOJ+vHgnzfu4C+X4DD3l1Kpj45LLfzdRbxbbd6UJPfowHmqSHvZVNze OGyKqFK6j1MgEfd8TVcWGEBGW5v15Slqv2uPTFNzIl9dUmh2I/EEAOEeayXiBy5i+ozb mpTka8hdI9QO2dUMzswKhTn3+9KItWu06alF4y8s23++x/IRXgrvUcRjVQ4kyVWtvOMK oEh5WrffOwGuNEZ8+bIqJOds+/m7coBwT2mQaLuEItlK2kCeT55OJIrr24V9WR9qEYk8 bzbAw4AqK1hQ7gFKUKDwwwzf4p3qqMznp1qnQ0JHTfsitLWMlYHkdOg1zWumhU4o267w E00w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737787621; x=1738392421; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ke4SvBesy7HOPaleQwpGGG+LJLBeY9FJV6nhVnr7e/A=; b=pZHRCKFL0h4vwl7n4ZY4QHcOB04v2tTuan7ZfN76ExkT/SP2WfxLAsnk9XEK7LgYlp G/hxuLin/KheRThpNbzmw7h9OcptZL7m+DWQ5nuEBQpVB95vLlqoPAi1BryhG7Ho6M1+ lpQKDL46mYG22axd6MDIHdXYPawrl9p3Ienq2f+1vRsQbKnmX6GIu613qhnBSLmZKr50 XAWMsGpE37WM7ieYyb25Xnz/NuGzj/hECdeuuXrIwcyrXLasnR1Y6TWkK6HNAMtu2Nvc 7KPPFH0cBIB9awmrMu/NjIIKFe9QQ8DuBxWupCQoHFo+PByOdVk2/Rraa4RqQi6U+87P qmIg== X-Gm-Message-State: AOJu0YzK5+/i0GEOf63Ld6JyduIW5qzRPGG3NJ/SMET01DbVn1skeczK nt2fmL3DaNljVFiX12+Amq9AKuFr7x3APWY9fjQ/GWKzZrgoXqyFtpszug== X-Gm-Gg: ASbGnctizsKnxAkbb3u2/fKofLaiD5EGPfCkckmULMCbVsXc1BPG4GaHOOsFFk/Lyjv 2XqYa77GKEFsDJ0cb5e8+AkO++PTgLq65B3ClfWqVDR7WDse2SBsK4tZQTw4R5yekMGca+672pT 3VmXamWa+ihxcXUkiPSoj3JDWos+IbigztOk4WWC1rX5UL4YDKjpY0PWzErlWSrCFkb/S+Ga4fM SMacN8XeU4hH8KCI7GKSnBjl2Nia7x/YsbUEHr1o4XeTfhDql27y7N1aleXPjIU+fXCjmXoMnFh PIciV8axbC1Jmf6Po0d7B8B/wzpHnrWVTAaJuQ== X-Google-Smtp-Source: AGHT+IHEFU3echceWmiA4eLPNghqGqyfiHEPHKsu8QESTZXaHS27iWJhMF9tECXmhlWc+hFhQTlaGQ== X-Received: by 2002:a05:6602:3a8b:b0:84a:51e2:9f93 with SMTP id ca18e2360f4ac-851b6285d20mr2848702339f.9.1737787620929; Fri, 24 Jan 2025 22:47:00 -0800 (PST) Received: from gandalf.. (c-67-165-245-5.hsd1.co.comcast.net. [67.165.245.5]) by smtp.googlemail.com with ESMTPSA id 8926c6da1cb9f-4ec1da476fesm1174144173.58.2025.01.24.22.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 22:47:00 -0800 (PST) From: Jim Cromie To: linux-kernel@vger.kernel.org, jbaron@akamai.com, gregkh@linuxfoundation.org, ukaszb@chromium.org Cc: intel-gfx-trybot@lists.freedesktop.org, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, daniel.vetter@ffwll.ch, tvrtko.ursulin@linux.intel.com, jani.nikula@intel.com, ville.syrjala@linux.intel.com, Jim Cromie Subject: [PATCH 22/63] dyndbg: rework ddebug_attach_*module_classes() Date: Fri, 24 Jan 2025 23:45:36 -0700 Message-ID: <20250125064619.8305-23-jim.cromie@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125064619.8305-1-jim.cromie@gmail.com> References: <20250125064619.8305-1-jim.cromie@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" These 2 fns both start with a codeblock which cleans up the classmaps arrays, finding the few that pertain to the module being added. Reduce this repetition to a macro: dd_mark_vector_subrange() and call it 2x. This macro finds the matching-on-modname subrange of a linker ordered array of builtin classmaps/users, and saves the subrange into the dt/debug-table's ddebug-info record. Then hoist those calls from ddebug_attach*() up to ddebug_add_module(). This puts the "cleanup" of class* arrays into ddebug_add_module(), not cluttering the original purpose of the 2 routines. And with ddebug_add_module() now updating dt with the classmaps for the module, the di arg to ddebug_attach_{,user}module_classes() is no longer needed, so drop it. Finally, rename the 2 functions, from *attach* (describing the dt update in the macro) to module_apply_class_{maps,users} to reflect the tighter focus. NB: The macro's main purpose is to handle multiple builtin classmaps or users, which is the only circumstance where less than the full array of classmaps is pertinent. Signed-off-by: Jim Cromie --- --- lib/dynamic_debug.c | 104 ++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 56 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 0ef243e30663..8afcd4111531 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -1212,72 +1212,54 @@ static void ddebug_apply_params(const struct ddebug= _class_map *cm, const char *m } =20 /* - * Find this module's classmaps in a sub/whole-range of the builtin/ - * modular classmap vector/section. Save the start and length of the - * subrange at its edges. + * scan the named array: @_vec, ref'd from inside @_box, for the + * start,len of the sub-array of elements matching on ->mod_name; + * remember them in _dst. Macro depends upon the fields being in both + * _box and _dst. + * @_i: caller provided counter var. + * @_sp: cursor into @_vec. + * @_box: ptr to a struct with @_vec, num__##@_vec, mod_name fields. + * @_vec: name of ref into array[T] of builtin/modular __section data. + * @_dst: ptr to struct with @_vec and num__##@_vec fields, both updated. */ -static int ddebug_attach_module_classes(struct ddebug_table *dt, - const struct _ddebug_info *di, - u64 *reserved_ids) +#define dd_mark_vector_subrange(_i, _dst, _sp, _box, _vec) ({ \ + int nc =3D 0; \ + for_subvec(_i, _sp, _box, _vec) { \ + if (!strcmp((_sp)->mod_name, (_dst)->mod_name)) { \ + if (!nc++) \ + (_dst)->info._vec.start =3D (_sp); \ + } else { \ + if (nc) \ + break; /* end of consecutive matches */ \ + } \ + } \ + (_dst)->info._vec.len =3D nc; \ +}) + +static int ddebug_module_apply_class_maps(struct ddebug_table *dt, + u64 *reserved_ids) { struct ddebug_class_map *cm; - int i, nc =3D 0; - - for_subvec(i, cm, di, maps) { - if (!strcmp(cm->mod_name, dt->mod_name)) { - vpr_cm_info(cm, "classes[%d]:", i); - if (!nc++) - dt->info.maps.start =3D cm; - } - } - if (!nc) - return 0; - - vpr_info("module:%s attached %d classes\n", dt->mod_name, nc); - dt->info.maps.len =3D nc; + int i; =20 for_subvec(i, cm, &dt->info, maps) ddebug_apply_params(cm, cm->mod_name); + + vpr_info("module:%s attached %d classmaps\n", dt->mod_name, dt->info.maps= .len); return 0; } =20 -/* - * propagates class-params thru their classmaps to class-users. this - * means a query against the dt/module, which means it must be on the - * list to be seen by ddebug_change. - */ -static int ddebug_attach_user_module_classes(struct ddebug_table *dt, - const struct _ddebug_info *di, - u64 *reserved_ids) +static int ddebug_module_apply_class_users(struct ddebug_table *dt, + u64 *reserved_ids) { struct ddebug_class_user *cli; - int i, nc =3D 0; - - /* - * For builtins: scan the array, find start/length of this - * module's refs, save to dt. For loadables, this is the - * whole array. - */ - for_subvec(i, cli, di, users) { - if (WARN_ON_ONCE(!cli || !cli->map || !cli->mod_name)) - continue; - if (!strcmp(cli->mod_name, dt->mod_name)) { - vpr_cm_info(cli->map, "class_ref[%d] %s -> %s", i, - cli->mod_name, cli->map->mod_name); - if (!nc++) - dt->info.users.start =3D cli; - } - } - if (!nc) - return 0; - - dt->info.users.len =3D nc; + int i; =20 /* now iterate dt */ - for_subvec(i, cli, di, users) + for_subvec(i, cli, &dt->info, users) ddebug_apply_params(cli->map, cli->mod_name); =20 - vpr_dt_info(dt, "attach-client-module: "); + vpr_info("module:%s attached %d classmap uses\n", dt->mod_name, dt->info.= users.len); return 0; } =20 @@ -1288,8 +1270,10 @@ static int ddebug_attach_user_module_classes(struct = ddebug_table *dt, static int ddebug_add_module(struct _ddebug_info *di, const char *modname) { struct ddebug_table *dt; + struct ddebug_class_map *cm; + struct ddebug_class_user *cli; u64 reserved_ids =3D 0; - int rc; + int rc, i; =20 if (!di->descs.len) return 0; @@ -1311,9 +1295,17 @@ static int ddebug_add_module(struct _ddebug_info *di= , const char *modname) dt->info.descs =3D di->descs; =20 INIT_LIST_HEAD(&dt->link); + /* + * for builtin modules, ddebug_init() insures that the di + * cursor marks just the module's descriptors, but it doesn't + * do so for the builtin class _maps & _users. find the + * start,len of the vectors by mod_name, save to dt. + */ + dd_mark_vector_subrange(i, dt, cm, di, maps); + dd_mark_vector_subrange(i, dt, cli, di, users); =20 - if (di->maps.len) { - rc =3D ddebug_attach_module_classes(dt, di, &reserved_ids); + if (dt->info.maps.len) { + rc =3D ddebug_module_apply_class_maps(dt, &reserved_ids); if (rc) { kfree(dt); return rc; @@ -1324,8 +1316,8 @@ static int ddebug_add_module(struct _ddebug_info *di,= const char *modname) mutex_unlock(&ddebug_lock); =20 =20 - if (di->users.len) { - rc =3D ddebug_attach_user_module_classes(dt, di, &reserved_ids); + if (dt->info.users.len) { + rc =3D ddebug_module_apply_class_users(dt, &reserved_ids); if (rc) return rc; } --=20 2.48.1