From nobody Fri Dec 19 20:35:03 2025 Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (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 9452F20DD72; Wed, 4 Jun 2025 19:39:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749065996; cv=none; b=l8olkmoCpVqpUwLu+SnJNoGvW9G/BQ0H23OP7aPv3YlsMiXco55pbomhiyvFwISsE0VgmvjkJztc49e4MaS83Ug9sTdbaQ2BC324kiTStSEy8HIoFn2Y8aAqevfiVJSHG8ZggZ6LzRlU1fvITmW5lfaVhgxgyB/nuFhJTHAo6Js= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749065996; c=relaxed/simple; bh=UNp5sqGlio4wPyqEid3+h1wdqCojiTPLatwSkLYSc4E=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lceTQweig1eCsNILlYlILyXlZsrkFVThmfDp13jZK0xPkbyogUWfEf0tYczChNVKy3R3Ik1+zkurul1OGHnYda4b0fw1kYpwFBkv93T1nl+SHNIsjsVp+VJCY19UXFdlVXX2jtdMuuQAeCOuMxmZyt0ezxJM/Q09pUyNeCd7fm4= 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=YMrx+S+W; arc=none smtp.client-ip=209.85.128.179 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="YMrx+S+W" Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-70f862dbeaeso3162097b3.1; Wed, 04 Jun 2025 12:39:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749065993; x=1749670793; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=xtcL+s/DLeTuORFgG0EXQX9QcVRzeCvaUqTavb6Svjk=; b=YMrx+S+WiiyVJlnR3aI1mGaNFH6dP8oJ+IP0iOPLDD/VIxVovhFWxnElfKAZcMw5eo Lr2BWYXcVARrPwsJSYY3xWJwdJu/uDOVkNbVEv3Wr2ZMxMTElv0QtwOFo2RMKwW0XeKC vXhdhyVS5HZAPY598y/hwIMWfk1IhMIOVQoI3R7qbd4/8jScsTUnmFAS49K6hDsO/3Xi JGBCxDbAtjayosAxliPq4nrK/GPQjfNCJwfK77uu1aKxoRNZIVwbwrLDjpG6GDId+1is A7pjPzbu2waBgCXkMXPXNEmtFNAdkkpv9PLLBnrq61dptC7y9GUFKVRrhDVuKki6j7Pq 898A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749065993; x=1749670793; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xtcL+s/DLeTuORFgG0EXQX9QcVRzeCvaUqTavb6Svjk=; b=Kc+Rex2SZkprz11qb6YleEMNrGpGUwi4foyXvK/OtBo6FcuoTz8i+cdu7BZbq1nu9L c2CbSaOaYx0TDcAZYkzEkzbWhG0X6U2y4MSvmkFs/zuaI0rNlm8i7MmSsbgMxOPdOUg+ ZDuA7twm80p5kzdP2t8D3fcuRMXrrbAfqKNR+IhNhrn+WnZO5rd6DK7wNeEg32IV/Uz8 JDU4gumwCIf2i8nAKdhzTGrMfWotyY/ERdxaw0DddqYY4UqszLsVUDf1rrjv8cLW5k/S oluBCPOtRvn8csIEcoEsMRwkBPrdVW8ZTL0GgflHe2HIxJ5j78ip0t9c8BWbEEeMOfNb B1eQ== X-Forwarded-Encrypted: i=1; AJvYcCUbOi+qXEHWZSInSVTtEdELUG21q0ur7Q0hh8UvBEHMU+T8l6dAVR0Ly9G+4Sbv4DsWNw1PpJMIjLUGvpM=@vger.kernel.org, AJvYcCXUjPECfA7++9wHpaETNPBY/5Qebc4YvTZrlbwgcbJAnCYJEqmvGdgrMgYOV1VQFO5ZnexqnqundTaNmQ==@vger.kernel.org X-Gm-Message-State: AOJu0YxjoqlLiJfR7ipXfoVYPtDCS05EXqGA4EtROhStyGMGba5rwfQt hlyWW1jbaDAL5CFYbrxBQ75WLfVBxF59iAxUK3yiaoNQ7RkXHizsu47g9eJZWA== X-Gm-Gg: ASbGncsfl7P/OpNqlK9cwf2hG7tnsWGkjU1mXBWjqGM/6QP+/A9cgpHQNJSwcfXjsMA Un49zPTY55MgySie+JgPyTgv1LFC+nGINptoctEfIErIsSKsTYV04iTDn7/n9kYig+TbK2x6DEs HyZtkWSm29Hi2YhrD1OWmGm9Yu+GMk0ZK6JYaki1UfgDogxY/+V8fQK81rjB7zB9PdXk7ARiHSS +Hatg/8T/clYgPl7VDTxbYzDTiCSoDnEJDFdUWQpuvWrId1Kd063Tc4UwMu0OdU1oPbrNH31Oh5 hHVw/q6GGrJ5mZFXwoxgn12w0Uc4jo0s7Vimpbcc31ku/3rWgtwKHRT6bvi/UvnTfaCXisDd0Cc Yw02i2qci7Rg= X-Google-Smtp-Source: AGHT+IEb/8pjUHipKwSFHmPsLnf637ipTMRL9HrqMwk/IBHVo78VZvfskYHNpKqjjh2gXY8sR374yg== X-Received: by 2002:a05:690c:6812:b0:70d:f892:2dca with SMTP id 00721157ae682-710d9e69561mr60158447b3.32.1749065993425; Wed, 04 Jun 2025 12:39:53 -0700 (PDT) Received: from localhost (c-73-224-175-84.hsd1.fl.comcast.net. [73.224.175.84]) by smtp.gmail.com with ESMTPSA id 00721157ae682-70f8ac0d136sm31513247b3.61.2025.06.04.12.39.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jun 2025 12:39:52 -0700 (PDT) From: Yury Norov To: Dennis Dalessandro , Jason Gunthorpe , Leon Romanovsky , Yury Norov , Rasmus Villemoes , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/7] cpumask: add cpumask_clear_cpus() Date: Wed, 4 Jun 2025 15:39:37 -0400 Message-ID: <20250604193947.11834-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250604193947.11834-1-yury.norov@gmail.com> References: <20250604193947.11834-1-yury.norov@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" From: "Yury Norov [NVIDIA]" When user wants to clear a range in cpumask, the only option the API provides now is a for-loop, like: for_each_cpu_from(cpu, mask) { if (cpu >=3D ncpus) break; __cpumask_clear_cpu(cpu, mask); } In the bitmap API we have bitmap_clear() for that, which is significantly faster than a for-loop. Propagate it to cpumasks. Signed-off-by: Yury Norov [NVIDIA] --- include/linux/cpumask.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 7ae80a7ca81e..ede95bbe8b80 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -609,6 +609,18 @@ void __cpumask_set_cpu(unsigned int cpu, struct cpumas= k *dstp) __set_bit(cpumask_check(cpu), cpumask_bits(dstp)); } =20 +/** + * cpumask_clear_cpus - clear cpus in a cpumask + * @dstp: the cpumask pointer + * @cpu: cpu number (< nr_cpu_ids) + * @ncpus: number of cpus to clear (< nr_cpu_ids) + */ +static __always_inline void cpumask_clear_cpus(struct cpumask *dstp, + unsigned int cpu, unsigned int ncpus) +{ + cpumask_check(cpu + ncpus - 1); + bitmap_clear(cpumask_bits(dstp), cpumask_check(cpu), ncpus); +} =20 /** * cpumask_clear_cpu - clear a cpu in a cpumask --=20 2.43.0 From nobody Fri Dec 19 20:35:03 2025 Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.179]) (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 20629213E74; Wed, 4 Jun 2025 19:39:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749065997; cv=none; b=ia7xxjuL1sodH6druVT0acyiFE1DoIW40Zrr4khzvsWvA505eNcAG2JeXEKBvb76ccc7aYJE3qHNO3Ogh+OmXjjCDWgkUujJVjF+/NwPoQ2eXPkqZN+mkIFo8hPLmp2l9kf3AaBrig8Jn0TaQ3E5ejLpobpHlu3oBvFWfQwWk4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749065997; c=relaxed/simple; bh=ViSSTCKpKLV5MKVh04ahkikwxHNh5vZ68dOXQITILJ8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kmaxh4hxRGCNewjNQ10SDeI5Fk8kGzJBfeD4xe1Iv19hnRwroNYKPyl+flJDqAkyiuZpXcxSNjz3HkDvmu2cQDnXimPcvcqdhh17SCTHKPFUszjvHsFN22IyCtn+4n/p2kUGAujMYWJ4k2qqvoj2aWihPldKw9szzC4X/d5BTrE= 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=T5VzBf+G; arc=none smtp.client-ip=209.85.219.179 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="T5VzBf+G" Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-e75668006b9so279353276.3; Wed, 04 Jun 2025 12:39:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749065995; x=1749670795; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Vi1sLCQhsKy2utXyIOZAD3VMEh2HzP7evqyBYkZJKF8=; b=T5VzBf+GpzAN+aLsDTPRLqBSKSD167ySD80cfXSpv3nZS0YHXFSDfFqwri/L+XHdMb zTd9PpraMuXxf9e+Jv2QOUBTOnuwL73clldx7Uvwe2l9XmgIdR5o+Qr4QW7tEVrV7jQk hMufQQngx0TtaNWjPq/SDy/KuAsWpD0KSutQex8ze2s1hkQFtBsVRoQBKt40DOz7Oy/p sNfyqv/Dt1iIMN3EktKfeua4ZjJSjAXv9r9SZh7oI40wB4HU4p53jbOd4NtLbL94ZNy7 OS2dG+2pBdPiKqyCFHcN/EmSouxnkYVrnvSLwPqtPfyMZSpLgCZONlnb8zBeQ9C7Ityh u2Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749065995; x=1749670795; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Vi1sLCQhsKy2utXyIOZAD3VMEh2HzP7evqyBYkZJKF8=; b=Ihi9gbSb/EzaZZ1WdlGwDgq1RtAYrxlPJNEJWFDtGL+2u0gTvz2ESsfpov7RCW5diW c97MTYUAyjn0aL2LhX/Ak3lIIOfaq2LdpznWaJ0cIWpCOKMnDfeop/UTCZ8AjYBZU7TF BLhc9UTcVBT970nUjKJKh/5uP8vjQv0N20HeQbgJwjiDv71SxeDDpThUtwnhGGGawPHC zQdk/36+M+EBAYhenPdlRDCBLsQhSk/WCvXrm8+apK/Fzx6xtg0kH/cKW52hg1RAP6GX fr3SsZnqwRk5+y9vPXgvu0r/2HXos6IBgGl4iHl8JsxRPbEL5DMGtti5VQP2HOdHhzD0 zuVA== X-Forwarded-Encrypted: i=1; AJvYcCWMuX8cR1dg5QgooCmfl41AiGCXixGAJfhjNIEg0fJsTCnDEezjuUeXnQDiIWUiiQR8knAYWRiIQi8d+ms=@vger.kernel.org, AJvYcCXIY2EnlEjfk/gFmNqZWqZ1kIsboFxiAJYEGLLqiEaGkfAjNZgyKu8Psq3pTapDlplGTfRorBlD9FtyoQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yx4sq7qwXRimHHvw6+4t3USS6WixQIdqt+CZu9JOFvozWrW3uNN ICJaY6xoVURQk9d3fvA9lvUADrKiu8o6He/tvG5w+TTzzKJnC2gjth1r X-Gm-Gg: ASbGnct4UnPHD89DRcgR4VqkM5RX0YODnPEOTT8vbNUlh0mI/gIcriHf/LCx+m/29iN SP5ez5WWfnjuf1e5frj3QZDevfWelDoE6CDFZD5YzRXyo52BYUM6RXgFOrLC3Ig1B5I9kpF+ZBV 6VP3EP9PwkhBYO8FvoZaWD23DW3IBusW0okFK2Dh4UmLu5nzrKOMurXh9sDf+HyFkpV9r0OzAT4 hSCGbXG549mqoeCWAyVg5XWVCtl1IgpFbLZBEne8yVC6ADkSKU2/+kavModw9dQ/Sgj+kc08oWe q6lippyccAYbWmBaRlYs4a7Pe3MeodBWr2tTiwFKVII75r5gV/PD5V6tFUIY1NIe5Rs62B846g5 S4yFigdg902Dq2V0Wl501LA== X-Google-Smtp-Source: AGHT+IHLXyrVRpp+GuPD1ypPcVeRJtYeyciAJWyVcJxXvEzReNn1owfVG7IgU2EMJJCgJtI3oSQeYw== X-Received: by 2002:a05:6902:1243:b0:e7d:7c54:952d with SMTP id 3f1490d57ef6-e8179c1d496mr5306728276.7.1749065994880; Wed, 04 Jun 2025 12:39:54 -0700 (PDT) Received: from localhost (c-73-224-175-84.hsd1.fl.comcast.net. [73.224.175.84]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e7f734febd4sm3254007276.46.2025.06.04.12.39.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jun 2025 12:39:54 -0700 (PDT) From: Yury Norov To: Dennis Dalessandro , Jason Gunthorpe , Leon Romanovsky , Yury Norov , Rasmus Villemoes , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/7] RDMA: hfi1: fix possible divide-by-zero in find_hw_thread_mask() Date: Wed, 4 Jun 2025 15:39:38 -0400 Message-ID: <20250604193947.11834-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250604193947.11834-1-yury.norov@gmail.com> References: <20250604193947.11834-1-yury.norov@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" From: "Yury Norov [NVIDIA]" The function divides number of online CPUs by num_core_siblings, and later checks the divider by zero. This implies a possibility to get and divide-by-zero runtime error. Fix it by moving the check prior to division. This also helps to save one indentation level. Signed-off-by: Yury Norov [NVIDIA] --- drivers/infiniband/hw/hfi1/affinity.c | 44 +++++++++++++++------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/affinity.c b/drivers/infiniband/hw/= hfi1/affinity.c index 7ead8746b79b..f2c530ab85a5 100644 --- a/drivers/infiniband/hw/hfi1/affinity.c +++ b/drivers/infiniband/hw/hfi1/affinity.c @@ -964,31 +964,35 @@ static void find_hw_thread_mask(uint hw_thread_no, cp= umask_var_t hw_thread_mask, struct hfi1_affinity_node_list *affinity) { int possible, curr_cpu, i; - uint num_cores_per_socket =3D node_affinity.num_online_cpus / + uint num_cores_per_socket; + + cpumask_copy(hw_thread_mask, &affinity->proc.mask); + + if (affinity->num_core_siblings =3D=3D 0) + return; + + num_cores_per_socket =3D node_affinity.num_online_cpus / affinity->num_core_siblings / node_affinity.num_online_nodes; =20 - cpumask_copy(hw_thread_mask, &affinity->proc.mask); - if (affinity->num_core_siblings > 0) { - /* Removing other siblings not needed for now */ - possible =3D cpumask_weight(hw_thread_mask); - curr_cpu =3D cpumask_first(hw_thread_mask); - for (i =3D 0; - i < num_cores_per_socket * node_affinity.num_online_nodes; - i++) - curr_cpu =3D cpumask_next(curr_cpu, hw_thread_mask); - - for (; i < possible; i++) { - cpumask_clear_cpu(curr_cpu, hw_thread_mask); - curr_cpu =3D cpumask_next(curr_cpu, hw_thread_mask); - } + /* Removing other siblings not needed for now */ + possible =3D cpumask_weight(hw_thread_mask); + curr_cpu =3D cpumask_first(hw_thread_mask); + for (i =3D 0; + i < num_cores_per_socket * node_affinity.num_online_nodes; + i++) + curr_cpu =3D cpumask_next(curr_cpu, hw_thread_mask); =20 - /* Identifying correct HW threads within physical cores */ - cpumask_shift_left(hw_thread_mask, hw_thread_mask, - num_cores_per_socket * - node_affinity.num_online_nodes * - hw_thread_no); + for (; i < possible; i++) { + cpumask_clear_cpu(curr_cpu, hw_thread_mask); + curr_cpu =3D cpumask_next(curr_cpu, hw_thread_mask); } + + /* Identifying correct HW threads within physical cores */ + cpumask_shift_left(hw_thread_mask, hw_thread_mask, + num_cores_per_socket * + node_affinity.num_online_nodes * + hw_thread_no); } =20 int hfi1_get_proc_affinity(int node) --=20 2.43.0 From nobody Fri Dec 19 20:35:03 2025 Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (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 5CB96224240; Wed, 4 Jun 2025 19:39:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749065999; cv=none; b=t3KDUmzppJUoay9sqVaTcTkK2bJefGPhL5DtLjor+yuqN7DB28EuJjLSHzKfrvqf8aaEz71hsWkD5Ai4mWn294jTuExncKeV3+do220LPhjJM1cFUDY276phuMbhlbrwqdX3JnQp4MFV9L0Hl3m4hb7b6xzXWLg3QnIW+VV4rxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749065999; c=relaxed/simple; bh=oGFCg0J/Z5ouvwRpXSM5emXVDJjuz/SuabIDX7rLAdM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GeGi82aI2e490MEp5n72BNuQoKhH9gIQ0jNEas6BP0u7MAilzqNyvhowRQq4y7Yl4zvH/JYkaDv/GvcpPHgnnxeNr7Ai722ZPEFRd7m1lZO9leislWAJ3yQIojXl1LbXywOEyUqkJ2gPFQ3XQ+8StjLLq7W0MVfGgyuOj5HVKHU= 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=SEwOC+9K; arc=none smtp.client-ip=209.85.128.175 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="SEwOC+9K" Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-70e6bddc30aso2956937b3.0; Wed, 04 Jun 2025 12:39:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749065996; x=1749670796; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=n4I2Bz3ZfW9SEL1Ccr90vp6SfH9JMIvUDuGOi2RaIiY=; b=SEwOC+9KFdLKJ18SAKTY3e0TaYWRtPFKSUGov5XudQ3KsDMu++LIpCbL0P1e2H1OCv j3/ndu9dtxMzMpJ9MJXC6xlBRlyxuYokHHCxFTNrc2NqrTQWm9zfzQFHyf/hGu8cIq28 AdHSqG9JZG5ua8EXJZpAWZmgSPaAIaNvvuXJphHO+6ZY/2c5fCgnZYPvprY4mKGpUXpo 2RZGz98lI44b3h7YYWtf3IfkMwrUqhPEsN5zie3dTj3WcSsV/0q2aYw4fEpYG74K5EMi 7D364utwB5SR8geBzS3CyntnS0tDBtiVmVvxRHc/hCwS9pYv0q7Fgg2VJwLIq9vCTsZ9 yaHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749065996; x=1749670796; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n4I2Bz3ZfW9SEL1Ccr90vp6SfH9JMIvUDuGOi2RaIiY=; b=FhMUBShlnVzV8OGgbFijHcDOdoHr+10WmwwmOEaSf944ID59qprzHALBL/nJxKekm4 3HgS3NKRLSrrPkkjoa4F3ZmLF9FM6g1PB3JQiLKmuETE5LF/JI5uJw04IBvPYQPS5b/d C9cZZiXWjXNIdz8C6y0FByatj0QfMFZbAuM0HQbJUD+FhIsncN82BfioXVDAEGTJxw/C 4k+4vAjwll6wS48xNdFpSDNGjpEqedBcOcdYUONzSUUsK4vdhy15BwebcIsm8vo55aGY t0CBqbf1mnNNjd2aCExIrU0S5tTogS1UETubvHxMS0pt6zSNhOpNKl+BUD1wc6X+aoVC pZ8Q== X-Forwarded-Encrypted: i=1; AJvYcCU4wtNY4xypLb7R1Xpv4VcB2EHFvdjAiFue72OHpgVW7FxqDUjpgwPXeOzPBW+fKlE6IYH9qzNGdCMVhpg=@vger.kernel.org, AJvYcCUAUU5OLi6aBoKDYdtizDcXMtyhklYUE8pBu/r/NMtVWx+8j1dTf7Q9jAwEw0kXMQeDjHtN9WJaBZIwHQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yzqb4ZYqbUPmyEUsldwez11JogDJxvUUofUFT+06VEovWJbYf8F D2DrzIihQaflL097J5UpTAtnBGPc+mhqQvH4xyuU9kzKN5o/LWtiBom3 X-Gm-Gg: ASbGncvBxPEEtwYao3GjmTo9sF0HAkRxNu7zh72ks+hHGwJ9zE9xSkt6HWf0ixtgHa0 GmuFJDhD4eS6S7b3KqWwiMIXk4mMBArHGAIHbafjJS1Br1ZxFuWcd7WUSsLEALc5HxiSdh35JhF odBPD848zaejeYa4Q19OPlKbjt0m1vb8laDlPv7xRUk0r0AQ7LTj+F4zVXFt2cVjPtFTCycqOSz 2Kxfn/5uxOSKdutuP81+mo24WLiryXED+cvpWmoFdCxQs4Xq/nMuarISvb0ToBg/c0Bfz0aF0VI qu7P4lIwt6v+iwkNzOYSB06Fu7Z6pZLI9x3qpkEfY1XDZtVfHab09Rc5SxHPcziyE3nOoVifl43 0nFvv5wRowQU= X-Google-Smtp-Source: AGHT+IH0TTM1N/ue4r56F37tJpMbUjpFHqUnJQwvt9Dz56+KoAOH4k/1gxcNvszFlTBnbSuZ94IHxg== X-Received: by 2002:a05:690c:fc1:b0:70d:f6ff:cc6f with SMTP id 00721157ae682-710d99fd79bmr56266467b3.4.1749065996280; Wed, 04 Jun 2025 12:39:56 -0700 (PDT) Received: from localhost (c-73-224-175-84.hsd1.fl.comcast.net. [73.224.175.84]) by smtp.gmail.com with ESMTPSA id 00721157ae682-70f8ad00637sm31473297b3.109.2025.06.04.12.39.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jun 2025 12:39:55 -0700 (PDT) From: Yury Norov To: Dennis Dalessandro , Jason Gunthorpe , Leon Romanovsky , Yury Norov , Rasmus Villemoes , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/7] RDMA: hfi1: simplify find_hw_thread_mask() Date: Wed, 4 Jun 2025 15:39:39 -0400 Message-ID: <20250604193947.11834-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250604193947.11834-1-yury.norov@gmail.com> References: <20250604193947.11834-1-yury.norov@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" From: "Yury Norov [NVIDIA]" The function opencodes cpumask_nth() and cpumask_clear_cpus(). The dedicated helpers are easier to use and usually much faster than opencoded for-loops. Signed-off-by: Yury Norov [NVIDIA] --- drivers/infiniband/hw/hfi1/affinity.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/affinity.c b/drivers/infiniband/hw/= hfi1/affinity.c index f2c530ab85a5..9ea80b777061 100644 --- a/drivers/infiniband/hw/hfi1/affinity.c +++ b/drivers/infiniband/hw/hfi1/affinity.c @@ -963,7 +963,7 @@ void hfi1_put_irq_affinity(struct hfi1_devdata *dd, static void find_hw_thread_mask(uint hw_thread_no, cpumask_var_t hw_thread= _mask, struct hfi1_affinity_node_list *affinity) { - int possible, curr_cpu, i; + int curr_cpu; uint num_cores_per_socket; =20 cpumask_copy(hw_thread_mask, &affinity->proc.mask); @@ -976,17 +976,9 @@ static void find_hw_thread_mask(uint hw_thread_no, cpu= mask_var_t hw_thread_mask, node_affinity.num_online_nodes; =20 /* Removing other siblings not needed for now */ - possible =3D cpumask_weight(hw_thread_mask); - curr_cpu =3D cpumask_first(hw_thread_mask); - for (i =3D 0; - i < num_cores_per_socket * node_affinity.num_online_nodes; - i++) - curr_cpu =3D cpumask_next(curr_cpu, hw_thread_mask); - - for (; i < possible; i++) { - cpumask_clear_cpu(curr_cpu, hw_thread_mask); - curr_cpu =3D cpumask_next(curr_cpu, hw_thread_mask); - } + curr_cpu =3D cpumask_cpumask_nth(num_cores_per_socket * + node_affinity.num_online_nodes, hw_thread_mask) + 1; + cpumask_clear_cpus(hw_thread_mask, curr_cpu, nr_cpu_ids - curr_cpu); =20 /* Identifying correct HW threads within physical cores */ cpumask_shift_left(hw_thread_mask, hw_thread_mask, --=20 2.43.0 From nobody Fri Dec 19 20:35:03 2025 Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) (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 9D1A822A4EA; Wed, 4 Jun 2025 19:39:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749066000; cv=none; b=GxsTgyCcVKZ6O1ukpUHc7slZblqOZkixKapI8VkJsK6I6kNHQzuKQ8mmVM4fbzZN0Xrr3jV8DErBTu7pGEAYCo8Hv7jwAru431v0a+Jb5a32BUjP0RDaMx8Z6zvT7PrWMb+jD9t8mU2Pl9x/tDpo4yYJJrB9BWEOyJzfcB5+IK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749066000; c=relaxed/simple; bh=fdlMxrWrqPg8wfQKTYPJsz7i0ts4zXCT17a8KPSe6so=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=je2LfantEA5OmrLqToZ5EE3cU8/gJn6e2tmlxfImUJ+yYTK/rSutXdD0SYSJOPe/HMsI+dHTezjo6TbytQNh3klhT0S/Ny5nAXGxnuPyQCa6GlhRXRJ5OYQpxCKC3OLvR8gCz9NuJ6IQRXBxt/88LXc02qGkC3ubU08iCszfiqc= 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=LDUnSH4A; arc=none smtp.client-ip=209.85.128.181 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="LDUnSH4A" Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-70e23e9aeefso2085047b3.2; Wed, 04 Jun 2025 12:39:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749065998; x=1749670798; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=W164iHtS8OogxzrMF1ZiWRrGDfnxEQGSfT/uh6T/EYg=; b=LDUnSH4AO5tkv+NY4iy/ymVU3CZ8tBwyCPPxB4fgx+xtM84Mm5vP1LVqSgW7lK4VK+ acSYBcqjiXVCT/1WDlgpU+TKfZZN+yfpl71nkKgT73hpsmU9oB0jPyH1NsqPtGSaqfax TYRQsVMxi9Ed8/BIdsi0ka0YxYlPueJwsFWe9PReYanYX2NCknYuHOOSKD+dfkpbKBPw m6hzopNwj9kA79XTUQJZJp25G5o+IqvpjVVZmfGVvWcbxQMishcgaBld4nWcoC9qzw4+ Zj1KNAUh4QQrH1OsWb5leuFem7T6r6UE+u48WuTXU9ocvUvywO5a3/6Wlcr1prhOHfev Ofrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749065998; x=1749670798; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W164iHtS8OogxzrMF1ZiWRrGDfnxEQGSfT/uh6T/EYg=; b=O0U1AsWrcqdbAGaMEKmZ+R5678rBD+Ab4rfmESE2RAuQNxEThj0jBpl3WUyWSnrPrJ 0Bt7zoAQRzjR/IncuaW8V9qaStdsaZjb1sIPrQe4ac/Sc5it9TupnAQqInycrcpybrIi 71AvEQfmvjJ1TVnNIIFxhRpiCizFso/To8nff7CX9H5QQfEvcmdcciCmFVPfkn5ih8vN fq7IaIvsRpm5epKhmE/GUfbkxEEJwspMAk6PSMnWOYlAr9ZMeSQQnmkgiim7gcuGJGOZ o6SJtwwVuWpfm0J+LxN9tBFh+kwgR5W93e/dgAawBQDTQA6tTGQ9JFou4rL7z/9olKL3 f+VQ== X-Forwarded-Encrypted: i=1; AJvYcCUFyQDWXDYqeAp5teHsMGX8C8hjo3813WIu2vKdP/6EyK6RCNdMlFtLwjYWl0AEfpVrNaUtITCuLqTJrE0=@vger.kernel.org, AJvYcCXOKRbyuGZOZfbNDcw9ZYA8xWHquY8iMIQzveuu9nwi8iglzKDL1fu7ypw/5ZOCThRbbbr3ZF77/DrDkw==@vger.kernel.org X-Gm-Message-State: AOJu0YyrhO6zd0WacRlJIp7vXe64B65DeGai1Nj7iCFTDC9SH3n4WmVy AABebyOdeyLsDbofLbSRtespb2IOdIJnmhkLJVbnpuLkKjTOSfXpmv3g X-Gm-Gg: ASbGncu0HtPAeFyjRg5AewONcieM9DFKijJlbkvQ3Jp+ucTsh6dEbCYjwKUOLW0sO2B OY17pBsm3mthCUARSyLsqDvt/4HjIq0l5KCtjhEd0EoN7FlVeRy1Onmy/HUd38C1p3IeEVWWWWH QKRZ7NrqDAC9EOFF+tvRTm4w2ScDzONsiCeWd3fwxR/zsGQUVTtomv2rN6f/RvBTMbMrzuRJ9eK mOp3DMUsIZ56RKl8ZhLb+iliXn+jaZ3CeF0epFYXkmw654xMZdWTgkzVpmEI2gig20LUIYpioBN VIDjZmgrKLFeAOUgpQfeQq5rwu3pyZyAzKt3UwMH2l60n55qIpVqTm1RPnSj7ZCKmRR4nyJW229 UJQ/gEx1dA/8= X-Google-Smtp-Source: AGHT+IEeePTZ8YEfFgEG3z2f910W63Ne+F6I2OoZmIUOGBvIiqJZd5atotfItjr4HUs2F1UsNR0IRg== X-Received: by 2002:a05:690c:4b8a:b0:70c:a854:8384 with SMTP id 00721157ae682-710d9df47fbmr62223187b3.11.1749065997614; Wed, 04 Jun 2025 12:39:57 -0700 (PDT) Received: from localhost (c-73-224-175-84.hsd1.fl.comcast.net. [73.224.175.84]) by smtp.gmail.com with ESMTPSA id 00721157ae682-70f8abed254sm31170997b3.39.2025.06.04.12.39.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jun 2025 12:39:57 -0700 (PDT) From: Yury Norov To: Dennis Dalessandro , Jason Gunthorpe , Leon Romanovsky , Yury Norov , Rasmus Villemoes , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/7] RDMA: hfi1: simplify init_real_cpu_mask() Date: Wed, 4 Jun 2025 15:39:40 -0400 Message-ID: <20250604193947.11834-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250604193947.11834-1-yury.norov@gmail.com> References: <20250604193947.11834-1-yury.norov@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" From: "Yury Norov [NVIDIA]" The function opencodes cpumask_nth() and cpumask_clear_cpus(). The dedicated helpers are easier to use and usually much faster than opencoded for-loops. While there, drop useless clear of real_cpu_mask. Signed-off-by: Yury Norov [NVIDIA] --- drivers/infiniband/hw/hfi1/affinity.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/affinity.c b/drivers/infiniband/hw/= hfi1/affinity.c index 9ea80b777061..b2884226827a 100644 --- a/drivers/infiniband/hw/hfi1/affinity.c +++ b/drivers/infiniband/hw/hfi1/affinity.c @@ -92,9 +92,7 @@ static void cpu_mask_set_put(struct cpu_mask_set *set, in= t cpu) /* Initialize non-HT cpu cores mask */ void init_real_cpu_mask(void) { - int possible, curr_cpu, i, ht; - - cpumask_clear(&node_affinity.real_cpu_mask); + int possible, curr_cpu, ht; =20 /* Start with cpu online mask as the real cpu mask */ cpumask_copy(&node_affinity.real_cpu_mask, cpu_online_mask); @@ -110,17 +108,10 @@ void init_real_cpu_mask(void) * "real" cores. Assumes that HT cores are not enumerated in * succession (except in the single core case). */ - curr_cpu =3D cpumask_first(&node_affinity.real_cpu_mask); - for (i =3D 0; i < possible / ht; i++) - curr_cpu =3D cpumask_next(curr_cpu, &node_affinity.real_cpu_mask); - /* - * Step 2. Remove the remaining HT siblings. Use cpumask_next() to - * skip any gaps. - */ - for (; i < possible; i++) { - cpumask_clear_cpu(curr_cpu, &node_affinity.real_cpu_mask); - curr_cpu =3D cpumask_next(curr_cpu, &node_affinity.real_cpu_mask); - } + curr_cpu =3D cpumask_nth(possible / ht, &node_affinity.real_cpu_mask) + 1; + + /* Step 2. Remove the remaining HT siblings. */ + cpumask_clear_cpus(&node_affinity.real_cpu_mask, curr_cpu, nr_cpu_ids - c= urr_cpu); } =20 int node_affinity_init(void) --=20 2.43.0 From nobody Fri Dec 19 20:35:03 2025 Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) (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 44B292309B9; Wed, 4 Jun 2025 19:39:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749066001; cv=none; b=pPI3ZGVH4OVd9QG8NyXEIYM5jscUtwmu5NIrdyDm5rMGFhUqJdnIW5c6oBkSeD6b0xBo5R6OXa8twbSGqdsBpRPsZXQ2vOHs0wzNwinZ2lleBHaGcmbQzXpY0JAeNPGLDP7mTqPJ+nzH068txmL7NtQUPpzDhiKYX9FVnNUiXEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749066001; c=relaxed/simple; bh=s/QY1Po14ZBHkphoj9O06O6cWcEVoAzPu+iI0zwgk68=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RkvJWl9LyQWG9YtLng7AkqBKw47tEtbpuFalpYX9o/ExW6R+zBGgAWYrkCwoiq42AMe1xcRXgSz2S2QYnybVHntSPo2+gEnknafsTviohvCSfuidCeb6P5G3/e3ViRe9cSWS94CTVkrjuGWiAFmpy872XZIqfSZc5VE0hPGyGcw= 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=nP2BuS9e; arc=none smtp.client-ip=209.85.219.170 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="nP2BuS9e" Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-e740a09eae0so253017276.1; Wed, 04 Jun 2025 12:39:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749065999; x=1749670799; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=xy03+0qgXoOuGkAi7VZcxw14vCcZM8u7fP3a/MZQfrA=; b=nP2BuS9e2V5f+0lMekXh0NvGzOZ84DaqB/vRvab05364crBwMvKP3dJF65/ma1/FZk T2Msof7XuBliaeyZbMyRSXnTB0RdVERdDXjmGl5fzMNGkn7D0urwX+nozC4xWNg9hDA5 NoRoCjkFGtOpf6i6azxufmlRXQrAt8XtCrOiIH40Q4jb7faGXzaZF+oZXlL/KtpPbqDV toqvSUfqSKHuu6D3LULykbcbK4GtZnXwPYtTK90lS8Pv+MrKGkGXmTyGPVQM6QrI6Lrr dpQS90kxw4RC1arjTQmkIeo/zVwgZz/KzMBfrt+QxBMdlvYDa3A1FPhiY5cLBqEO/iSP NVhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749065999; x=1749670799; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xy03+0qgXoOuGkAi7VZcxw14vCcZM8u7fP3a/MZQfrA=; b=aYzKYlHF8jRcAds5LxbPhpvCg14+gR7LXU9YxujYaCe+GmpDSfL92qm5xWFsr4OXZc wS+TAx/wHcv3ExbvUPWRXcHfI8DITXnkzfr0yIT1V4LoLXNjeUGbByPlgZhnXhPDzpaK KKkN8i2l7ISIVwIOntm6zmTQzvfl7GS/EdcFTMejIZeGEQXj3MYsQn3BYXevdVVzg6hu t4OqrAvgF6yYtU3zYl+13NAHazThopQc+qZtHwpwpqVZQ5lLhA6KJ1khzYXczUBSGZW/ a8t7SG5VS4o0oEKv0quRBZ6zDWaDctyuG/MxSgStcl4NabaYARbzr1gqU1fv6A0Nr0mI 2eAg== X-Forwarded-Encrypted: i=1; AJvYcCVBLBdDkrpvpa+qsfvoSNCUY1P54iDGxIF8yJ6Nk+z7O3LAfLPEZ6q/8w75w6qRdB0nGeS2q1bbTXwo5x8=@vger.kernel.org, AJvYcCW5yv0O/ylAv+EGyNDX3MCmMgVaiqEh/z61jd8K0ylT0+ChdksdjQCqPIjyYeXOBMmL4KYaoL4QiPvF1A==@vger.kernel.org X-Gm-Message-State: AOJu0YxZ8DfLl+582WmpIFGCw6SZlHOZmc8AaVUxHV14Q6vIUrLFx+gi rBBuNUJpdEPQ9Z06PoezKByPQWekeJklMIT6fFs2o5+1NejFKWfe8k81 X-Gm-Gg: ASbGncvPK1tnCpeTMvWN+gYANLm7CkkxGdxGIF2BIc/832Eo1hyfWjQ0dVE/IHusJZr M4cxzqUOSbR1Ywxkdp+1hrPUjc0WV+4EnGT0eXgaEV7LOZhsGBa/oEQ9eufeEpWkrg+RTfxykmK FoECgx9anA3huPqf5/KkXRqre7zmQRssLs1uFjYzhJ79NR6lkQbTgOUwAYPTcoXx0NePM37Lu3G z++3LD88YZKyky6F7zLash5UrXAnOZka0lAYh5vjQt7hPwwVwTL3KyOpjOKuw6HNRjGGlKBPGrp zDnE/CcMT3zoBKUbunjuuHIeMSuFzB8PIEO4mGtUXBoy/AMmnm9xIZE7710X8t5qUr6b8WDAuGw 5Fsn9kDepiu1m8QiAjQgJew== X-Google-Smtp-Source: AGHT+IEgvSDC4r8ZjyVtKq87tEo+4ymzPJnysSG8drZl8IKClKNZ9U2jvuLNhJU6uUsAy6V0VhXkWw== X-Received: by 2002:a05:690c:6d12:b0:70d:fe09:9b18 with SMTP id 00721157ae682-710d9d5f295mr61705857b3.2.1749065999029; Wed, 04 Jun 2025 12:39:59 -0700 (PDT) Received: from localhost (c-73-224-175-84.hsd1.fl.comcast.net. [73.224.175.84]) by smtp.gmail.com with ESMTPSA id 00721157ae682-70f8abce663sm31506727b3.2.2025.06.04.12.39.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jun 2025 12:39:58 -0700 (PDT) From: Yury Norov To: Dennis Dalessandro , Jason Gunthorpe , Leon Romanovsky , Yury Norov , Rasmus Villemoes , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/7] RDMA: hfi1: use rounddown in find_hw_thread_mask() Date: Wed, 4 Jun 2025 15:39:41 -0400 Message-ID: <20250604193947.11834-6-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250604193947.11834-1-yury.norov@gmail.com> References: <20250604193947.11834-1-yury.norov@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" From: "Yury Norov [NVIDIA]" num_cores_per_socket is calculated by dividing by node_affinity.num_online_nodes, but all users of this variable multiply it by node_affinity.num_online_nodes again. This effectively is the same as rounding it down by node_affinity.num_online_nodes. Signed-off-by: Yury Norov [NVIDIA] --- drivers/infiniband/hw/hfi1/affinity.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/affinity.c b/drivers/infiniband/hw/= hfi1/affinity.c index b2884226827a..7fa894c23fea 100644 --- a/drivers/infiniband/hw/hfi1/affinity.c +++ b/drivers/infiniband/hw/hfi1/affinity.c @@ -955,27 +955,22 @@ static void find_hw_thread_mask(uint hw_thread_no, cp= umask_var_t hw_thread_mask, struct hfi1_affinity_node_list *affinity) { int curr_cpu; - uint num_cores_per_socket; + uint num_cores; =20 cpumask_copy(hw_thread_mask, &affinity->proc.mask); =20 if (affinity->num_core_siblings =3D=3D 0) return; =20 - num_cores_per_socket =3D node_affinity.num_online_cpus / - affinity->num_core_siblings / - node_affinity.num_online_nodes; + num_cores =3D rounddown(node_affinity.num_online_cpus / affinity->num_cor= e_siblings, + node_affinity.num_online_nodes); =20 /* Removing other siblings not needed for now */ - curr_cpu =3D cpumask_cpumask_nth(num_cores_per_socket * - node_affinity.num_online_nodes, hw_thread_mask) + 1; + curr_cpu =3D cpumask_nth(num_cores * node_affinity.num_online_nodes, hw_t= hread_mask) + 1; cpumask_clear_cpus(hw_thread_mask, curr_cpu, nr_cpu_ids - curr_cpu); =20 /* Identifying correct HW threads within physical cores */ - cpumask_shift_left(hw_thread_mask, hw_thread_mask, - num_cores_per_socket * - node_affinity.num_online_nodes * - hw_thread_no); + cpumask_shift_left(hw_thread_mask, hw_thread_mask, num_cores * hw_thread_= no); } =20 int hfi1_get_proc_affinity(int node) --=20 2.43.0 From nobody Fri Dec 19 20:35:03 2025 Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) (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 70EB323370F; Wed, 4 Jun 2025 19:40:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749066003; cv=none; b=QNP08yVnwW7yMSy0Y35l07VkhKwZv8hM+ENDTs9y3mP712wnqLfQFdspczXq3mqSGj8JQ5//ZElCoQKKXMdysu7BalJGURcBKZgme5MqB2ElAFXgo6VVX+c9VT/uo1enkoaZzhXWJ2VdesDZ/GIsm/sOFWQ62oNXlIwWVpQPff4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749066003; c=relaxed/simple; bh=MIhYYerpHajYvheCWKIv8Y4X1PDOoAE3QIOCxTs5Frw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lNnBigG512YSXCvY9sPOqbWuMovHSPzn2LO6Go7ldF3RSMlHXTgaEStVYPR1qx9f2yvrPbqAzO7wUauRD8aZIgqaz0pO0tKHWIykTVUr1tMABueIHRWjbePPIVK1kBwPk+eUycFT1HhujqNBHmSTFV1rBENmlKS0fSC6rqhuAAE= 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=Pi0Mv2Gi; arc=none smtp.client-ip=209.85.128.182 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="Pi0Mv2Gi" Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-70f94fe1e40so14849607b3.1; Wed, 04 Jun 2025 12:40:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749066000; x=1749670800; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=bDOaohN/0lM/HKNz/0q/mSwu9lg5mfFLnFFub3FhmQs=; b=Pi0Mv2GijYLHER9+aJvXGUk0RWQioUu1L8CI7pbeCTYZ/0xNOctaB/gs+7vUysuOpN YnOfPbQu1OJHtq6Jg0X/wg1pMmhBNvT2LqSzpiLlVP/zVSs1dwLAQZ+22oGhiQAhpAGH 2a8B8TpOnj41D/RvA2fGKXAa0rWVYqScr4Kx7Gms1Bkcyf6guXec6A3gtkaAvlRf8B/y 2qTNei/m/R8zSZmMAGlr0Mj33cNQJIz7eMyLGrD0/quShqzckTcCi2v4u3tT+kO6LQBU W24vTDoDKGH1HzimuEImP2CCXn4a10pSRCV7v7A8GPK8DLrauLNhhtvxvfEbcX5P+qGP LTrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749066000; x=1749670800; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bDOaohN/0lM/HKNz/0q/mSwu9lg5mfFLnFFub3FhmQs=; b=d/TMMvVLtBpY+80rpG8hes6C61FMEUdNZjn9fWq48SmXMoJA2rZLv5eDTfSkNlMzJt 9eDo94P/fvBmZFtvZuklZ6Ru93ofNsa5v8bPSSlNkGe4UXvx2WGL2bM/nYUcSmzOzl7K RmsvJ5VpAs4sH3FT/Pt5q/ct7C45DisDX4iHj1+uYGJYvJA0OfNhXxcVCJuIhPkp0WLy LyntxRA/oavRzLndSSNDLBxcGkDjt5sBWpl2plazlQrwNhH8pZlB20v5AUvtY4eMUTQq 9u+Y4x7wtUq7oPJwm1fM2cCbQDolRHPF/adyVJw7DHUWHZn3UsZC0vGxpO/YlZHS/p5x Sr+w== X-Forwarded-Encrypted: i=1; AJvYcCW1APJSPHGJsL+L7czn5PzGQF4nsG3wBUCTbJejakzcaidT/5iJZGOTeH2edlPhNHkO8ySvXgtcLGGjtA==@vger.kernel.org, AJvYcCXZ+keR72EXu0a3Cq8UiVtqGSholih6WM6d9Ygjt5tV2iV2oux2fXr8mCO26cGnFHksvB6DydydXbrl8ek=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1365f5icCk3JRWocOSOw4okBBTi+t+DaeFm4n34jAy1ZQCyov K3cuUVNicCAQrnbt1F9fk54P3Us6LG9s25oXaP9XQfX7QJutnknzpJJ0 X-Gm-Gg: ASbGncsTXgY1mqGO3b4VZTQoMe0NfIov7v4X1zjYIePK5VhUay9Q0Pu0/9vFRFhHLOb au+fNqxu7ghR9DqjlpXiLaEGMyAMnqjZr6kUm1K3CzXEL5rzxFZ4OexfsQvX/run6YFjduNogQI islcy/ahQ/cYesbQgaOZNwKijEhDP3mrDbFd/XYuzRz4R7A3AWpDJ9hFLvYwMK6RJgZfl+ZRK5Q U4Eqf0b2VEOv7kjYLuEmcIZL3UPz3hV5HmJhrDC/9+Z8u0VvetKI+gggeq4TsYO2iqo6nndoppm l7onwjEE3YxL3znHlwFKRLebpSbmw2vsstGypRgj4vcSpf6NZb8FZIT5QyhhLij6Eov4OTeWUGV iGTfjGMzC3Hc= X-Google-Smtp-Source: AGHT+IGK+BqJ1B8gD6QRGEzuv64zDg1s+DsjlakjVCGWVSQlOuravBEcZObRW0kjpTfCjxDCVvO2qQ== X-Received: by 2002:a05:690c:6f07:b0:70e:7f7f:cfda with SMTP id 00721157ae682-710e7e2df77mr13839807b3.10.1749066000450; Wed, 04 Jun 2025 12:40:00 -0700 (PDT) Received: from localhost (c-73-224-175-84.hsd1.fl.comcast.net. [73.224.175.84]) by smtp.gmail.com with ESMTPSA id 00721157ae682-70f8ac0d92dsm31213747b3.58.2025.06.04.12.39.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jun 2025 12:39:59 -0700 (PDT) From: Yury Norov To: Dennis Dalessandro , Jason Gunthorpe , Leon Romanovsky , Yury Norov , Rasmus Villemoes , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/7] RDMA: hfi1: simplify hfi1_get_proc_affinity() Date: Wed, 4 Jun 2025 15:39:42 -0400 Message-ID: <20250604193947.11834-7-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250604193947.11834-1-yury.norov@gmail.com> References: <20250604193947.11834-1-yury.norov@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" From: "Yury Norov [NVIDIA]" The function protects the for loop with affinity->num_core_siblings > 0 condition, which is redundant because the loop will break immediately in that case. Drop it and save one indentation level. Signed-off-by: Yury Norov [NVIDIA] --- drivers/infiniband/hw/hfi1/affinity.c | 28 +++++++++++++-------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/affinity.c b/drivers/infiniband/hw/= hfi1/affinity.c index 7fa894c23fea..8974aa1e63d1 100644 --- a/drivers/infiniband/hw/hfi1/affinity.c +++ b/drivers/infiniband/hw/hfi1/affinity.c @@ -1069,22 +1069,20 @@ int hfi1_get_proc_affinity(int node) * If HT cores are enabled, identify which HW threads within the * physical cores should be used. */ - if (affinity->num_core_siblings > 0) { - for (i =3D 0; i < affinity->num_core_siblings; i++) { - find_hw_thread_mask(i, hw_thread_mask, affinity); + for (i =3D 0; i < affinity->num_core_siblings; i++) { + find_hw_thread_mask(i, hw_thread_mask, affinity); =20 - /* - * If there's at least one available core for this HW - * thread number, stop looking for a core. - * - * diff will always be not empty at least once in this - * loop as the used mask gets reset when - * (set->mask =3D=3D set->used) before this loop. - */ - cpumask_andnot(diff, hw_thread_mask, &set->used); - if (!cpumask_empty(diff)) - break; - } + /* + * If there's at least one available core for this HW + * thread number, stop looking for a core. + * + * diff will always be not empty at least once in this + * loop as the used mask gets reset when + * (set->mask =3D=3D set->used) before this loop. + */ + cpumask_andnot(diff, hw_thread_mask, &set->used); + if (!cpumask_empty(diff)) + break; } hfi1_cdbg(PROC, "Same available HW thread on all physical CPUs: %*pbl", cpumask_pr_args(hw_thread_mask)); --=20 2.43.0 From nobody Fri Dec 19 20:35:03 2025 Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (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 0474423505E; Wed, 4 Jun 2025 19:40:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749066004; cv=none; b=XfguqXDNBHtETR+btt9JcoLltqXDnPrjh8gWBBmvy/U8f21uMu59gy2eIPgZyjuT+ZdiiopqNpOY0BIBSrKAnVFvgUmWBvzbNwJ4eZJ04CDBwf8GY5TDt8fn+42lyfoMD0uYGo0ZAr19urEF5GZnmJLGarhCrADQbjdSS8y/IjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749066004; c=relaxed/simple; bh=t8DDjh3HwhAUE4zYiGY9G7C1Q0qjemSopgAtlZt5dtk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y/MK8cYWe1lpFWJT4i9PyWg2eTuSHW5a2Yi1Ml8vPpoXIO4HipYmMgbJhhaTzAM6Zj2eQlwcKoSkA1KqRhxmyHH6TE8SKna2+eziOp6pc9VCltH8xlh6AsFYE5Z3MQkEXzM0CE5gpgOUQ5zf9CRhgtk4CbF352495Z4sJSH5hvA= 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=k5aHFriN; arc=none smtp.client-ip=209.85.128.176 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="k5aHFriN" Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-70e4bd65106so3142147b3.0; Wed, 04 Jun 2025 12:40:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749066002; x=1749670802; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Z0R/5dQHAJsM2XSNwZKRpcLz7ma4lbCJr+VnH+Xq6Sw=; b=k5aHFriNp2THJQQ+a/AOMcSQRg2Bcld8V9wC62gZyWj3s2MhBIk2HcCpg9N9VA7x8X XQcuj3PsQb/o11z/WSKkoVdZvZOCL7pOI5zWcnhHdlhkFSTLKbl/ix9/YqzAf78QYEGC a+QYjiDACDqIkNoHnYCvwsueK9cqzVGXEBU12pkBxDiIHhQ+0mCMjjlZoa+S6Mmfm3tz /2ULwgAVrWwIpqe/n7jEvj3XACWc8RINnOC0SX0EjttGpJqeLibjJRRuu7SRbR4NiTg5 qnTt4vjJU2njShDbRErjSOs2ZpzbNdJM1JVLqy++sRC9J45mNj3BBbJqRFz/eDh43ALL tJqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749066002; x=1749670802; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z0R/5dQHAJsM2XSNwZKRpcLz7ma4lbCJr+VnH+Xq6Sw=; b=QXrEz2ebHPBcqUQ2OHxbfQO13CraxgKYFkJe7tgH8/bu/uJ1UR/BK+asVoks4mrvNX OtO62otp26NLZkOD7OjUuLCq7jJYxULPs7UjV2uFoBgUiOHKpKwPcRPBMrMaZ16Z5dO+ c0UugG7fw2iNlg9l3ZsPksqPWy800pdHTHlbaaHenRnx0TH8MOccyYK9htoyHPIb1NPW tNhilJEOYFZDSRZAfD3WoxU4uX12mJNDyjl+SxFEMvFPEQ+L7jRyDlmy5SKlWskDVRDC j29FzvyhLri4RRRGQzbr6uldhJyGyH7ZgZAyLhDDPZES8uCWqSJLOg4QiDGnlr0YBajV ee1Q== X-Forwarded-Encrypted: i=1; AJvYcCVzCgouR17zBWHdlaa0xjGffoI+yVpURZY+w6e77xXlp/NCozzKvwaTWkg6DFNAYVZvb/fl/U1NPjq3ew==@vger.kernel.org, AJvYcCWqYeXRJ6gE1AMT454YzK0OtXflcPvWA390o9J0UFH829v+DLNyNgP4fV/EoR6NFZoDQbehvKCNzj3z++g=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/E9wMPtcBhn1oEbnkKjRCGNygC6zTnKQKCcyM5lY0SC7D3c5k wufhZUG+S2PSV8TImzDRBf4dKfE3LtuBMveaTPBERTFjmD83788WdTdq X-Gm-Gg: ASbGncte8uORB/mxh1Ju17lEf0n4wtD5CfwuzEyK0GrMC8zSSCZ+9N1Duvl2RFMNnol MMbfInCk+6YM+ZHNfsdPyRDMKQ2U0PJwmaXWdlUvVOB8bN70PfBd/fYUWRGgJWCr7eDL/r94zPF YuCjxpOzOhVhCJpCCPtC7lOMeJ6x0yNM8/9ImsCsVOc8N3E6ORYoqmlywg/r9AuDiaQ8lIl9MUp uIOp4+oYeJB9LtAOmxo1tkq856Qp4ofCtW0imCfyCDa8bkyp5FQmgD3crGg97dHDA0tXQhB96or lL1U1k7kRa1abG8NCrAQauMRI5KWpEBzTmYuLSypkmN2QvvHVyWuoMut4xnBIAFrGbz6rd+dOV/ eFaHuCraAhPrzmm0yXYHetA== X-Google-Smtp-Source: AGHT+IFYWxiL7TNZ3JEn9azdO9bVH4NGbsVwwW4UwjDwr23W89zWnd7GL9lCUfaagJF0SJ0QndQ2oQ== X-Received: by 2002:a05:690c:4910:b0:6ef:6d61:c254 with SMTP id 00721157ae682-710da020a73mr55388607b3.38.1749066001974; Wed, 04 Jun 2025 12:40:01 -0700 (PDT) Received: from localhost (c-73-224-175-84.hsd1.fl.comcast.net. [73.224.175.84]) by smtp.gmail.com with ESMTPSA id 00721157ae682-710e4aa7655sm2076707b3.46.2025.06.04.12.40.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jun 2025 12:40:01 -0700 (PDT) From: Yury Norov To: Dennis Dalessandro , Jason Gunthorpe , Leon Romanovsky , Yury Norov , Rasmus Villemoes , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/7] RDMI: hfi1: drop cpumask_empty() call in hfi1/affinity.c Date: Wed, 4 Jun 2025 15:39:43 -0400 Message-ID: <20250604193947.11834-8-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250604193947.11834-1-yury.norov@gmail.com> References: <20250604193947.11834-1-yury.norov@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" From: "Yury Norov [NVIDIA]" In few places, the driver tests a cpumask for emptiness immediately before calling functions that report emptiness themself. Signed-off-by: Yury Norov [NVIDIA] --- drivers/infiniband/hw/hfi1/affinity.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/affinity.c b/drivers/infiniband/hw/= hfi1/affinity.c index 8974aa1e63d1..ee7fedc67b86 100644 --- a/drivers/infiniband/hw/hfi1/affinity.c +++ b/drivers/infiniband/hw/hfi1/affinity.c @@ -337,9 +337,10 @@ static int _dev_comp_vect_cpu_get(struct hfi1_devdata = *dd, &entry->def_intr.used); =20 /* If there are non-interrupt CPUs available, use them first */ - if (!cpumask_empty(non_intr_cpus)) - cpu =3D cpumask_first(non_intr_cpus); - else /* Otherwise, use interrupt CPUs */ + cpu =3D cpumask_first(non_intr_cpus); + + /* Otherwise, use interrupt CPUs */ + if (cpu >=3D nr_cpu_ids) cpu =3D cpumask_first(available_cpus); =20 if (cpu >=3D nr_cpu_ids) { /* empty */ @@ -1080,8 +1081,7 @@ int hfi1_get_proc_affinity(int node) * loop as the used mask gets reset when * (set->mask =3D=3D set->used) before this loop. */ - cpumask_andnot(diff, hw_thread_mask, &set->used); - if (!cpumask_empty(diff)) + if (cpumask_andnot(diff, hw_thread_mask, &set->used)) break; } hfi1_cdbg(PROC, "Same available HW thread on all physical CPUs: %*pbl", @@ -1113,8 +1113,7 @@ int hfi1_get_proc_affinity(int node) * used for process assignments using the same method as * the preferred NUMA node. */ - cpumask_andnot(diff, available_mask, intrs_mask); - if (!cpumask_empty(diff)) + if (cpumask_andnot(diff, available_mask, intrs_mask)) cpumask_copy(available_mask, diff); =20 /* If we don't have CPUs on the preferred node, use other NUMA nodes */ @@ -1130,8 +1129,7 @@ int hfi1_get_proc_affinity(int node) * At first, we don't want to place processes on the same * CPUs as interrupt handlers. */ - cpumask_andnot(diff, available_mask, intrs_mask); - if (!cpumask_empty(diff)) + if (cpumask_andnot(diff, available_mask, intrs_mask)) cpumask_copy(available_mask, diff); } hfi1_cdbg(PROC, "Possible CPUs for process: %*pbl", --=20 2.43.0