Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1732706rdb; Sat, 23 Dec 2023 22:15:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjRt+OYnMv4Eh1jbDnbEMwHS1ZbpT1R/tbiFAXe8j/NoiTHMB4l5HZdnZTon6y+np3FHlY X-Received: by 2002:a05:6e02:152a:b0:35f:ebe0:9b with SMTP id i10-20020a056e02152a00b0035febe0009bmr3110082ilu.39.1703398509731; Sat, 23 Dec 2023 22:15:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703398509; cv=none; d=google.com; s=arc-20160816; b=OFnmCGzLtzU/fprdfY/e2WEDyJv23HEK451lfu+9ZWVF1/Hf6zNGWTpBU+eQL8dPp3 TDn7uG0yvRPK461RwJCQ7R2rGZlW9tttpbxm1bqNaMLjp9do4PiVElyMDdoL1OrTsXac g2CXVKWmEx7ekqRsbtAGRVHbvDKMDj+HrVt1uMVReqWkJB2tVtwYVkyH1288Sb/qd3aF L+3kqAxSJB6b8xjy57zJw8ggtDdgIqCQKfSzCljjwub8w2Qe/Dewk1lnhsGojjsSWIdT GO/erAvN7+aMFwK2Uio6+hVjkCztO/0W5hePHOimxga4ybWNektalgu68yFNG+tGF3qF BvUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:message-id:subject:to:from:date:dkim-signature; bh=+9RW3h4kKdKL1nOAU3014G7TqCbC5fHLZ2Mi71tGitw=; fh=y5qC3UvQ4LxjtNsRrPU9DGkpO8tFY69ehcJMS4yOJ5Q=; b=HPWoJOiXXapQpQPxaXzQVyjrK2Vu0F1UvrvIanDWDRk35WTBLFZpNNHVpqD9/94kRf BFwV71c5EM4nVu9xue/40MuRKdyZU4jXXT40IGFvDQtcxU4Qdzh+w1RkE8LAIeIIeXeK 63LWleJh8x+TGCXlsB+UXCDG2VcqaOu4ltxOOeiz0iDivVCUdIA65QmXcp/eY9s4+Zx8 tcMPKRGOHal+GqnG4OSZyAFGSz3ccLM4Gj2GIpIhZac6ubjJQGOne9v2JC8AUfPO9FZK mEhxEJwIukci9wFSc6M7boPLqJ+CDzyihhSoCuyl8HrCBPHvp4ECcipdJUI4JLu2H8vS HPfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=LrCh7Hml; spf=pass (google.com: domain of linux-kernel+bounces-10645-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10645-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id u3-20020a17090341c300b001d44b36b701si693071ple.512.2023.12.23.22.15.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Dec 2023 22:15:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10645-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=LrCh7Hml; spf=pass (google.com: domain of linux-kernel+bounces-10645-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10645-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 1E2E0B21523 for ; Sun, 24 Dec 2023 06:14:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 13C5E110C; Sun, 24 Dec 2023 06:14:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=inria.fr header.i=@inria.fr header.b="LrCh7Hml" X-Original-To: linux-kernel@vger.kernel.org Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A40EED2 for ; Sun, 24 Dec 2023 06:14:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=inria.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=inria.fr DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=date:from:to:subject:message-id:mime-version; bh=+9RW3h4kKdKL1nOAU3014G7TqCbC5fHLZ2Mi71tGitw=; b=LrCh7HmlbzWiOlLrbRvCuBb4OrQ2giJGqourX6HzJRGn32J6hK46VSE9 PZeFRhSTYiCZxxgeoRgtta3etZB17bPow2/mcn58+UPkXcIA1m1xOAknb uDwRWe7J2TaHfgdMcZRwF87vXSnN7nchIUib0Iwqr7ml5AnIOfq4gdE4r c=; Authentication-Results: mail3-relais-sop.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=julia.lawall@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.04,300,1695679200"; d="scan'208";a="75276603" Received: from 231.85.89.92.rev.sfr.net (HELO hadrien) ([92.89.85.231]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Dec 2023 07:14:06 +0100 Date: Sun, 24 Dec 2023 07:14:04 +0100 (CET) From: Julia Lawall X-X-Sender: jll@hadrien To: Ben Skeggs , Lyude Paul , linux-kernel@vger.kernel.org, oe-kbuild-all@lists.linux.dev Subject: drivers/gpu/drm/nouveau/nvkm/engine/gr/gv100.c:153:33-34: WARNING opportunity for max() (fwd) Message-ID: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII ---------- Forwarded message ---------- Date: Sun, 24 Dec 2023 11:53:26 +0800 From: kernel test robot To: oe-kbuild@lists.linux.dev Cc: lkp@intel.com, Julia Lawall Subject: drivers/gpu/drm/nouveau/nvkm/engine/gr/gv100.c:153:33-34: WARNING opportunity for max() BCC: lkp@intel.com CC: oe-kbuild-all@lists.linux.dev CC: linux-kernel@vger.kernel.org TO: Ben Skeggs CC: Lyude Paul tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 3f82f1c3a03694800a4104ca6b6d3282bd4e213d commit: 3ffa6f329b610029b44ebd7bc2320a92468a0e42 drm/nouveau/gr/gv100-: port smid mapping code from nvgpu date: 1 year, 1 month ago :::::: branch date: 8 hours ago :::::: commit date: 1 year, 1 month ago config: loongarch-randconfig-r062-20231222 (https://download.01.org/0day-ci/archive/20231224/202312241110.HuCnnbZr-lkp@intel.com/config) compiler: loongarch64-linux-gcc (GCC) 13.2.0 If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot | Reported-by: Julia Lawall | Closes: https://lore.kernel.org/r/202312241110.HuCnnbZr-lkp@intel.com/ cocci warnings: (new ones prefixed by >>) >> drivers/gpu/drm/nouveau/nvkm/engine/gr/gv100.c:153:33-34: WARNING opportunity for max() vim +153 drivers/gpu/drm/nouveau/nvkm/engine/gr/gv100.c 3ffa6f329b6100 Ben Skeggs 2022-06-01 104 3ffa6f329b6100 Ben Skeggs 2022-06-01 105 static int 3ffa6f329b6100 Ben Skeggs 2022-06-01 106 gv100_gr_scg_estimate_perf(struct gf100_gr *gr, unsigned long *gpc_tpc_mask, 3ffa6f329b6100 Ben Skeggs 2022-06-01 107 u32 disable_gpc, u32 disable_tpc, int *perf) 3ffa6f329b6100 Ben Skeggs 2022-06-01 108 { 3ffa6f329b6100 Ben Skeggs 2022-06-01 109 const u32 scale_factor = 512UL; /* Use fx23.9 */ 3ffa6f329b6100 Ben Skeggs 2022-06-01 110 const u32 pix_scale = 1024*1024UL; /* Pix perf in [29:20] */ 3ffa6f329b6100 Ben Skeggs 2022-06-01 111 const u32 world_scale = 1024UL; /* World performance in [19:10] */ 3ffa6f329b6100 Ben Skeggs 2022-06-01 112 const u32 tpc_scale = 1; /* TPC balancing in [9:0] */ 3ffa6f329b6100 Ben Skeggs 2022-06-01 113 u32 scg_num_pes = 0; 3ffa6f329b6100 Ben Skeggs 2022-06-01 114 u32 min_scg_gpc_pix_perf = scale_factor; /* Init perf as maximum */ 3ffa6f329b6100 Ben Skeggs 2022-06-01 115 u32 average_tpcs = 0; /* Average of # of TPCs per GPC */ 3ffa6f329b6100 Ben Skeggs 2022-06-01 116 u32 deviation; /* absolute diff between TPC# and average_tpcs, averaged across GPCs */ 3ffa6f329b6100 Ben Skeggs 2022-06-01 117 u32 norm_tpc_deviation; /* deviation/max_tpc_per_gpc */ 3ffa6f329b6100 Ben Skeggs 2022-06-01 118 u32 tpc_balance; 3ffa6f329b6100 Ben Skeggs 2022-06-01 119 u32 scg_gpc_pix_perf; 3ffa6f329b6100 Ben Skeggs 2022-06-01 120 u32 scg_world_perf; 3ffa6f329b6100 Ben Skeggs 2022-06-01 121 u32 gpc; 3ffa6f329b6100 Ben Skeggs 2022-06-01 122 u32 pes; 3ffa6f329b6100 Ben Skeggs 2022-06-01 123 int diff; 3ffa6f329b6100 Ben Skeggs 2022-06-01 124 bool tpc_removed_gpc = false; 3ffa6f329b6100 Ben Skeggs 2022-06-01 125 bool tpc_removed_pes = false; 3ffa6f329b6100 Ben Skeggs 2022-06-01 126 u32 max_tpc_gpc = 0; 3ffa6f329b6100 Ben Skeggs 2022-06-01 127 u32 num_tpc_mask; 3ffa6f329b6100 Ben Skeggs 2022-06-01 128 u32 *num_tpc_gpc; 3ffa6f329b6100 Ben Skeggs 2022-06-01 129 int ret = -EINVAL; 3ffa6f329b6100 Ben Skeggs 2022-06-01 130 3ffa6f329b6100 Ben Skeggs 2022-06-01 131 if (!(num_tpc_gpc = kcalloc(gr->gpc_nr, sizeof(*num_tpc_gpc), GFP_KERNEL))) 3ffa6f329b6100 Ben Skeggs 2022-06-01 132 return -ENOMEM; 3ffa6f329b6100 Ben Skeggs 2022-06-01 133 3ffa6f329b6100 Ben Skeggs 2022-06-01 134 /* Calculate pix-perf-reduction-rate per GPC and find bottleneck TPC */ 3ffa6f329b6100 Ben Skeggs 2022-06-01 135 for (gpc = 0; gpc < gr->gpc_nr; gpc++) { 3ffa6f329b6100 Ben Skeggs 2022-06-01 136 num_tpc_mask = gpc_tpc_mask[gpc]; 3ffa6f329b6100 Ben Skeggs 2022-06-01 137 3ffa6f329b6100 Ben Skeggs 2022-06-01 138 if ((gpc == disable_gpc) && num_tpc_mask & BIT(disable_tpc)) { 3ffa6f329b6100 Ben Skeggs 2022-06-01 139 /* Safety check if a TPC is removed twice */ 3ffa6f329b6100 Ben Skeggs 2022-06-01 140 if (WARN_ON(tpc_removed_gpc)) 3ffa6f329b6100 Ben Skeggs 2022-06-01 141 goto done; 3ffa6f329b6100 Ben Skeggs 2022-06-01 142 3ffa6f329b6100 Ben Skeggs 2022-06-01 143 /* Remove logical TPC from set */ 3ffa6f329b6100 Ben Skeggs 2022-06-01 144 num_tpc_mask &= ~BIT(disable_tpc); 3ffa6f329b6100 Ben Skeggs 2022-06-01 145 tpc_removed_gpc = true; 3ffa6f329b6100 Ben Skeggs 2022-06-01 146 } 3ffa6f329b6100 Ben Skeggs 2022-06-01 147 3ffa6f329b6100 Ben Skeggs 2022-06-01 148 /* track balancing of tpcs across gpcs */ 3ffa6f329b6100 Ben Skeggs 2022-06-01 149 num_tpc_gpc[gpc] = hweight32(num_tpc_mask); 3ffa6f329b6100 Ben Skeggs 2022-06-01 150 average_tpcs += num_tpc_gpc[gpc]; 3ffa6f329b6100 Ben Skeggs 2022-06-01 151 3ffa6f329b6100 Ben Skeggs 2022-06-01 152 /* save the maximum numer of gpcs */ 3ffa6f329b6100 Ben Skeggs 2022-06-01 @153 max_tpc_gpc = num_tpc_gpc[gpc] > max_tpc_gpc ? num_tpc_gpc[gpc] : max_tpc_gpc; 3ffa6f329b6100 Ben Skeggs 2022-06-01 154 3ffa6f329b6100 Ben Skeggs 2022-06-01 155 /* 3ffa6f329b6100 Ben Skeggs 2022-06-01 156 * Calculate ratio between TPC count and post-FS and post-SCG 3ffa6f329b6100 Ben Skeggs 2022-06-01 157 * 3ffa6f329b6100 Ben Skeggs 2022-06-01 158 * ratio represents relative throughput of the GPC 3ffa6f329b6100 Ben Skeggs 2022-06-01 159 */ 3ffa6f329b6100 Ben Skeggs 2022-06-01 160 scg_gpc_pix_perf = scale_factor * num_tpc_gpc[gpc] / gr->tpc_nr[gpc]; 3ffa6f329b6100 Ben Skeggs 2022-06-01 161 if (min_scg_gpc_pix_perf > scg_gpc_pix_perf) 3ffa6f329b6100 Ben Skeggs 2022-06-01 162 min_scg_gpc_pix_perf = scg_gpc_pix_perf; 3ffa6f329b6100 Ben Skeggs 2022-06-01 163 3ffa6f329b6100 Ben Skeggs 2022-06-01 164 /* Calculate # of surviving PES */ 3ffa6f329b6100 Ben Skeggs 2022-06-01 165 for (pes = 0; pes < gr->ppc_nr[gpc]; pes++) { 3ffa6f329b6100 Ben Skeggs 2022-06-01 166 /* Count the number of TPC on the set */ 3ffa6f329b6100 Ben Skeggs 2022-06-01 167 num_tpc_mask = gr->ppc_tpc_mask[gpc][pes] & gpc_tpc_mask[gpc]; 3ffa6f329b6100 Ben Skeggs 2022-06-01 168 3ffa6f329b6100 Ben Skeggs 2022-06-01 169 if ((gpc == disable_gpc) && (num_tpc_mask & BIT(disable_tpc))) { 3ffa6f329b6100 Ben Skeggs 2022-06-01 170 if (WARN_ON(tpc_removed_pes)) 3ffa6f329b6100 Ben Skeggs 2022-06-01 171 goto done; 3ffa6f329b6100 Ben Skeggs 2022-06-01 172 3ffa6f329b6100 Ben Skeggs 2022-06-01 173 num_tpc_mask &= ~BIT(disable_tpc); 3ffa6f329b6100 Ben Skeggs 2022-06-01 174 tpc_removed_pes = true; 3ffa6f329b6100 Ben Skeggs 2022-06-01 175 } 3ffa6f329b6100 Ben Skeggs 2022-06-01 176 3ffa6f329b6100 Ben Skeggs 2022-06-01 177 if (hweight32(num_tpc_mask)) 3ffa6f329b6100 Ben Skeggs 2022-06-01 178 scg_num_pes++; 3ffa6f329b6100 Ben Skeggs 2022-06-01 179 } 3ffa6f329b6100 Ben Skeggs 2022-06-01 180 } 3ffa6f329b6100 Ben Skeggs 2022-06-01 181 3ffa6f329b6100 Ben Skeggs 2022-06-01 182 if (WARN_ON(!tpc_removed_gpc || !tpc_removed_pes)) 3ffa6f329b6100 Ben Skeggs 2022-06-01 183 goto done; 3ffa6f329b6100 Ben Skeggs 2022-06-01 184 3ffa6f329b6100 Ben Skeggs 2022-06-01 185 if (max_tpc_gpc == 0) { 3ffa6f329b6100 Ben Skeggs 2022-06-01 186 *perf = 0; 3ffa6f329b6100 Ben Skeggs 2022-06-01 187 goto done_ok; 3ffa6f329b6100 Ben Skeggs 2022-06-01 188 } 3ffa6f329b6100 Ben Skeggs 2022-06-01 189 3ffa6f329b6100 Ben Skeggs 2022-06-01 190 /* Now calculate perf */ 3ffa6f329b6100 Ben Skeggs 2022-06-01 191 scg_world_perf = (scale_factor * scg_num_pes) / gr->ppc_total; 3ffa6f329b6100 Ben Skeggs 2022-06-01 192 deviation = 0; 3ffa6f329b6100 Ben Skeggs 2022-06-01 193 average_tpcs = scale_factor * average_tpcs / gr->gpc_nr; 3ffa6f329b6100 Ben Skeggs 2022-06-01 194 for (gpc = 0; gpc < gr->gpc_nr; gpc++) { 3ffa6f329b6100 Ben Skeggs 2022-06-01 195 diff = average_tpcs - scale_factor * num_tpc_gpc[gpc]; 3ffa6f329b6100 Ben Skeggs 2022-06-01 196 if (diff < 0) 3ffa6f329b6100 Ben Skeggs 2022-06-01 197 diff = -diff; 3ffa6f329b6100 Ben Skeggs 2022-06-01 198 3ffa6f329b6100 Ben Skeggs 2022-06-01 199 deviation += diff; 3ffa6f329b6100 Ben Skeggs 2022-06-01 200 } 3ffa6f329b6100 Ben Skeggs 2022-06-01 201 3ffa6f329b6100 Ben Skeggs 2022-06-01 202 deviation /= gr->gpc_nr; 3ffa6f329b6100 Ben Skeggs 2022-06-01 203 3ffa6f329b6100 Ben Skeggs 2022-06-01 204 norm_tpc_deviation = deviation / max_tpc_gpc; 3ffa6f329b6100 Ben Skeggs 2022-06-01 205 3ffa6f329b6100 Ben Skeggs 2022-06-01 206 tpc_balance = scale_factor - norm_tpc_deviation; 3ffa6f329b6100 Ben Skeggs 2022-06-01 207 3ffa6f329b6100 Ben Skeggs 2022-06-01 208 if ((tpc_balance > scale_factor) || 3ffa6f329b6100 Ben Skeggs 2022-06-01 209 (scg_world_perf > scale_factor) || 3ffa6f329b6100 Ben Skeggs 2022-06-01 210 (min_scg_gpc_pix_perf > scale_factor) || 3ffa6f329b6100 Ben Skeggs 2022-06-01 211 (norm_tpc_deviation > scale_factor)) { 3ffa6f329b6100 Ben Skeggs 2022-06-01 212 WARN_ON(1); 3ffa6f329b6100 Ben Skeggs 2022-06-01 213 goto done; 3ffa6f329b6100 Ben Skeggs 2022-06-01 214 } 3ffa6f329b6100 Ben Skeggs 2022-06-01 215 3ffa6f329b6100 Ben Skeggs 2022-06-01 216 *perf = (pix_scale * min_scg_gpc_pix_perf) + 3ffa6f329b6100 Ben Skeggs 2022-06-01 217 (world_scale * scg_world_perf) + 3ffa6f329b6100 Ben Skeggs 2022-06-01 218 (tpc_scale * tpc_balance); 3ffa6f329b6100 Ben Skeggs 2022-06-01 219 done_ok: 3ffa6f329b6100 Ben Skeggs 2022-06-01 220 ret = 0; 3ffa6f329b6100 Ben Skeggs 2022-06-01 221 done: 3ffa6f329b6100 Ben Skeggs 2022-06-01 222 kfree(num_tpc_gpc); 3ffa6f329b6100 Ben Skeggs 2022-06-01 223 return ret; 3ffa6f329b6100 Ben Skeggs 2022-06-01 224 } 3ffa6f329b6100 Ben Skeggs 2022-06-01 225 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki