From patchwork Thu Oct 12 17:21:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Cromie X-Patchwork-Id: 152075 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1388848vqb; Thu, 12 Oct 2023 10:23:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUud9lbOhIqpBEZj2b/AxEutspgZCp8X/5GWbuGUeEYogJKLKSlYnH1DRqiJKgBRnhFrGA X-Received: by 2002:a05:6a00:3985:b0:68f:c8b3:3077 with SMTP id fi5-20020a056a00398500b0068fc8b33077mr26599028pfb.1.1697131414449; Thu, 12 Oct 2023 10:23:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697131414; cv=none; d=google.com; s=arc-20160816; b=CWwhF6z1fR/4vSAgMeG5CkJGtKo8VvOKHBLQzFZRFRxvN2T62uiDS0HxT9apn68PWp jETAV9mWlSfvrQcFPVUjQFjGICWBpyxcv7uuBiNC/W0TImGtcekXpvvQcNTSftind4p2 4NdsifSv5HoHP1jeKHWupv0mm61hy7AJxblPINYsA/UmKLITiG+fGvktUvjgZqcxlZ60 CQOT7u/YaGLkozllCm0oZ1jWDFdZZyecwXUoqC825BTErOjUJ6GJkGYpobRMZe0rNmXZ mlyZb7OwlAZNPKGqyX0XBQ8fzrtiCh7uD/eEeX1RR7XPlUbgYA+jmkVeZhlRqXw7661o Zu2A== 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:date:subject:cc:to:from :dkim-signature; bh=tXsSOg8f2yCgJEL2pCIM6ReAyW7r5JJg4FpT0/i3350=; fh=iMt9mR7tPHpILUTScbdc/cv5Bu8Y4MLmy8xlWClXVSw=; b=LjGUgBTjwaKJldegGJ9G/ke2aTiPk/RgDKi5aH/4GPi+D7stGywIeyjKfseXZErJw5 UpKiN1x60wYhuGQVTJZjHv0xIOo6meZ4VUn2zHCKKHZrzpdcR2IamVekRzpIcGJ6+7J8 Bdg8VOz6kr/7NsPk47w14dR93uMBmqtP1878HXLE5tY0dpd4Y6bFIa54uLUGWgM8QAHA UUuvo+45B8ttrPDjSCEnw2YXPkFymFDgykd3YfAKlwDSXLGene4KeYVvja43JRgCO4ut YFUwanwV0VjyJcp0SE/ELuj8Dtr8rfbPh2MmO3zAZ8ztmb7w7E+uVE6sRVOIxl3BugxY 1vQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=lZA8EkeH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id l71-20020a63884a000000b00578639ad1d3si2613024pgd.319.2023.10.12.10.23.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 10:23:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=lZA8EkeH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id CF03183C9F8F; Thu, 12 Oct 2023 10:23:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441925AbjJLRXQ (ORCPT + 19 others); Thu, 12 Oct 2023 13:23:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379711AbjJLRWg (ORCPT ); Thu, 12 Oct 2023 13:22:36 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 458461AE; Thu, 12 Oct 2023 10:22:04 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-79fb64b5265so49334039f.1; Thu, 12 Oct 2023 10:22:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697131323; x=1697736123; 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=tXsSOg8f2yCgJEL2pCIM6ReAyW7r5JJg4FpT0/i3350=; b=lZA8EkeHYzLiCQZ73UQbJ4Atzf+3t+sNGQngku8xquV8c/NhUpYEmodzsRS3brdH9t np2wfTQsrujUrW6uUAu7IvOkRu09SWlgMRicwbF9E8Y3v1IMYteeCaBVQ3fEdKhM/SL3 PcWMMv9v8mehS+TF7OAHs8DtTy3A2SVqeKzfAOZFc8kXv+YthfhMsj++aVe98HXyPeQB WaDTMw6eNA0ZTtmr+8RbC2CQ5rPuvGktAJFcSl+DIgMa53Ol+sjnt4RL5ZTnjHMXnI2o PgH80qs3kvMHxdYbnkUTljMJGUBrK/VHpxo42rhOUqG+vZr3BsQeTeZzrclxRPeSu8j1 9JHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697131323; x=1697736123; 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=tXsSOg8f2yCgJEL2pCIM6ReAyW7r5JJg4FpT0/i3350=; b=VGGkEOHTiRBcpELSctw4lYYpim7ZVusByoC/V/rNKNgjESbp5ELrmiDB8j/g7uA+TB way7+oANul49VqZG6bUoOxiJd0uyVD52QGOEU05zo3bIxsKmx1Ie25O046WOXJ66uPQU P3wQWCHcChNyVFlA+JhMWII/9y+aQkIKCzas+abjIoHB7Wy7h5azTJAbRDPELV6kTf9X rfaW3P/B6JhSaVN8Uqd2zqdn0bKaAyuPq2WnaYPEVPY/z8YB3961ZIL5roKYNWveMFXw +VUlBNUgkbgyN+sa+UZwsPWns4oL4Vx5I/ABgCkB5bC09K1kq43xEtB8sOZD/lHsna0p V5gA== X-Gm-Message-State: AOJu0YyLbrHwoo4d+6QMiHnH+yidy8XL9koaWoAtnyWLAHfkXUSpFXi4 uCcIt2OuZpnqmgde8X1rBb5J704MWenbCQ== X-Received: by 2002:a6b:5c02:0:b0:792:96e5:962 with SMTP id z2-20020a6b5c02000000b0079296e50962mr25893270ioh.6.1697131322893; Thu, 12 Oct 2023 10:22:02 -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 r25-20020a028819000000b0043cef0711c1sm3992211jai.158.2023.10.12.10.22.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 10:22:02 -0700 (PDT) From: Jim Cromie To: linux-kernel@vger.kernel.org, jbaron@akamai.com, gregkh@linuxfoundation.org, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Cc: daniel.vetter@ffwll.ch, jani.nikula@intel.com, ville.syrjala@linux.intel.com, seanpaul@chromium.org, robdclark@gmail.com, groeck@google.com, yanivt@google.com, bleung@google.com, linux-doc@vger.kernel.org, Jim Cromie Subject: [PATCH v7 15/25] dyndbg: add for_each_boxed_vector Date: Thu, 12 Oct 2023 11:21:26 -0600 Message-ID: <20231012172137.3286566-16-jim.cromie@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231012172137.3286566-1-jim.cromie@gmail.com> References: <20231012172137.3286566-1-jim.cromie@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 12 Oct 2023 10:23:28 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779571270116574233 X-GMAIL-MSGID: 1779571270116574233 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 be49e104ec76..c11feca70d6f 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); @@ -1230,7 +1233,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); dt->num_classes = nc; - 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); } @@ -1250,7 +1253,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; @@ -1268,8 +1271,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: ");