From patchwork Mon Sep 11 23:08:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Cromie X-Patchwork-Id: 13380351 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ACE0BCA0EC3 for ; Mon, 11 Sep 2023 23:09:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F252410E379; Mon, 11 Sep 2023 23:09:03 +0000 (UTC) Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4911E10E203; Mon, 11 Sep 2023 23:08:58 +0000 (UTC) Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-7926a450a0aso172886739f.3; Mon, 11 Sep 2023 16:08:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694473737; x=1695078537; darn=lists.freedesktop.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=pRKwABwSVQ1OTkJFIkg8SfKEtpKioqDF4/CYpQb4P2w=; b=SxMpvsiZGuZEnzICqJhxqwMHBAYssjh+HrK2Dwh/jDZru7e0QhNEVWl9eSpXwqmrE5 /idtVP7p7jssR2N1SnUyti3UJBL7HNkY16uT096vdyYf4mf1tBaN8wBU5vTboQnvSJYc HhzcHh1SvYXt5d+ThH84uRQPdbAjyhcHoTrJdFTW+UoDPXYIyGaTbLC1DGt0aYU1lB9H vSDd7ChlZiZ63Il4RcUbMf59s0b2JobQ7AAcNmNtTkg4o+mNhEoUIdxbX4Kmu8mXzjCF UFJWHoPBEqcns47Hz3ygveHKe14e2HVWFQc5k28/RpacfxmBWllj+5IbJivDtVeLH25J Kxpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694473737; x=1695078537; 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=pRKwABwSVQ1OTkJFIkg8SfKEtpKioqDF4/CYpQb4P2w=; b=asqSvdv6m/eHpuXTbgbsS0EzqPoc2+mbFkppP4xS4HvBuiGPM+ySeAcylsuIFp2NRL ClU67RqYPPmVy97ws79b/Tevf+ObdQYXMtAaHvC9yoBJHVK6BqiVqk0iznDkThpY89Zo 8jpdWtXLo8z7r2mMFKUTorG8NqzkDUrUJp4qA61znZ2WyImDj3cpT6inbqX6jncV+p9l kylzJF79qcNuaGM0PqAwztEdbzStQvupMzC0sAlYtJLJKRpgQpgVswSuTZ3cPhiZJfwB G8eO2V8MjuCiPEGvSb8W98Aj8NO9HC0d/5zzW9o1FTRk0B3CdVu90Jo4VcS0Td2lGq0s l+6g== X-Gm-Message-State: AOJu0YyPAxQwO7GmbfECY4Op3oCr07b1EUDon9l0aqjFlFdc3ych7jK+ 0tRA+CfUnSnYzKQx8LorNIQ= X-Google-Smtp-Source: AGHT+IGnBiv6UbJsu+sBM5Hhx9sTk4Vk8peUvrBdp3UqCNKfl/LsZspNoj46K2gBb3H7JdLQgmF4mw== X-Received: by 2002:a5e:8912:0:b0:792:9a3e:2dd with SMTP id k18-20020a5e8912000000b007929a3e02ddmr13540344ioj.3.1694473737580; Mon, 11 Sep 2023 16:08:57 -0700 (PDT) Received: from frodo.. (c-73-78-62-130.hsd1.co.comcast.net. [73.78.62.130]) by smtp.googlemail.com with ESMTPSA id z4-20020a029f04000000b00423240c7296sm2512607jal.69.2023.09.11.16.08.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 16:08:57 -0700 (PDT) From: Jim Cromie To: jbaron@akamai.com, gregkh@linuxfoundation.org, mcgrof@kernel.org, daniel.vetter@ffwll.ch Date: Mon, 11 Sep 2023 17:08:29 -0600 Message-ID: <20230911230838.14461-14-jim.cromie@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230911230838.14461-1-jim.cromie@gmail.com> References: <20230911230838.14461-1-jim.cromie@gmail.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v6 13/22] dyndbg: add for_each_boxed_vector X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-doc@vger.kernel.org, jani.nikula@intel.com, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, Jim Cromie , seanpaul@chromium.org, dri-devel@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Add a for_each iterator to walk a counted vector member in a struct (ie the box), and use it to replace 8 open-coded loops. Signed-off-by: Jim Cromie --- v5- parens-on-box-force-precedence --- lib/dynamic_debug.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 018578923897..851e7f9de085 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -158,6 +158,9 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg) _dt->num_class_users); \ }) +#define for_each_boxed_vector(_box, _vec, _len, _ct, _curs) \ + for (_ct = 0, _curs = (_box)->_vec; _ct < (_box)->_len; _ct++, _curs++) + #define __outvar /* filled by callee */ static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table const *dt, const char *class_string, @@ -167,7 +170,7 @@ static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table cons struct ddebug_class_user *cli; int i, idx; - for (i = 0, map = dt->classes; i < dt->num_classes; i++, map++) { + for_each_boxed_vector(dt, classes, num_classes, i, map) { idx = match_string(map->class_names, map->length, class_string); if (idx >= 0) { *class_id = idx + map->base; @@ -175,7 +178,7 @@ static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table cons return map; } } - for (i = 0, cli = dt->class_users; i < dt->num_class_users; i++, cli++) { + for_each_boxed_vector(dt, class_users, num_class_users, i, cli) { idx = match_string(cli->map->class_names, cli->map->length, class_string); if (idx >= 0) { *class_id = idx + cli->map->base; @@ -1058,11 +1061,11 @@ static const char *ddebug_class_name(struct ddebug_table *dt, struct _ddebug *dp struct ddebug_class_user *cli = dt->class_users; int i; - for (i = 0; i < dt->num_classes; i++, map++) + for_each_boxed_vector(dt, classes, num_classes, i, map) if (class_in_range(dp->class_id, map)) return map->class_names[dp->class_id - map->base]; - for (i = 0; i < dt->num_class_users; i++, cli++) + for_each_boxed_vector(dt, class_users, num_class_users, i, cli) if (class_in_range(dp->class_id, cli->map)) return cli->map->class_names[dp->class_id - cli->map->base]; @@ -1216,7 +1219,7 @@ static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug struct ddebug_class_map *cm; int i, nc = 0; - for (i = 0, cm = di->classes; i < di->num_classes; i++, cm++) { + for_each_boxed_vector(di, classes, num_classes, i, cm) { if (!strcmp(cm->mod_name, dt->mod_name)) { vpr_cm_info(cm, "classes[%d]:", i); @@ -1229,7 +1232,7 @@ static void ddebug_attach_module_classes(struct ddebug_table *dt, struct _ddebug vpr_info("module:%s attached %d classes\n", dt->mod_name, nc); /* now iterate dt */ - for (i = 0, cm = dt->classes; i < dt->num_classes; i++, cm++) + for_each_boxed_vector(di, classes, num_classes, i, cm) ddebug_apply_params(cm, cm->mod_name); } @@ -1249,7 +1252,7 @@ static void ddebug_attach_user_module_classes(struct ddebug_table *dt, * module's refs, save to dt. For loadables, this is the * whole array. */ - for (i = 0, cli = di->class_users; i < di->num_class_users; i++, cli++) { + for_each_boxed_vector(di, class_users, num_class_users, i, cli) { if (WARN_ON(!cli || !cli->map || !cli->user_mod_name)) continue; @@ -1264,8 +1267,7 @@ static void ddebug_attach_user_module_classes(struct ddebug_table *dt, } dt->num_class_users = nc; - /* now iterate dt */ - for (i = 0, cli = dt->class_users; i < dt->num_class_users; i++, cli++) + for_each_boxed_vector(di, class_users, num_class_users, i, cli) ddebug_apply_params(cli->map, cli->user_mod_name); vpr_dt_info(dt, "attach-client-module: ");