Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp135526rdb; Thu, 1 Feb 2024 04:34:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IFvEf30eMFkvPwgIctrmjH1/Pi8bMOQT8PdsB+M0XMnNxeTbAPj+KNA0qWSx3FTSIQ21vk8 X-Received: by 2002:a92:cc0d:0:b0:363:9f50:971f with SMTP id s13-20020a92cc0d000000b003639f50971fmr2716310ilp.22.1706790858284; Thu, 01 Feb 2024 04:34:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706790858; cv=pass; d=google.com; s=arc-20160816; b=aoVw89K6hgx6gNfpjOk0SoccJ6KqUopS+A/LC0VJ7X+a0BOcYHp7B5dHBaod5hUapj nTc3rR1pzXyY72sDlLPc1bZb4m6f61eHjSotYeim/2cTX63FOlXGQ7n/WiGuweHP2xcH m6i0rqwkVVTlHANOGhnhHNuXINjr1D1AVYxa68Ha317T2SHdGt2zdFOMzRpvSMM0Gmre Q01oAZiPqQgGMkG90uL9FUu9cWcGmm5YkINKlbjPRcNQ1nnRiQGVUkxbeGCU0lq85NOu JesYGNxjZA45mL3kL5JCE7RT0yP9Z+NoZj0yiqO5cM1gqH/qxM4zAqAJBLRMCJq7O7ec s7ew== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=A6ed4ZCnthg7H5zksJplhCnPki0CElvRiUR+4yXcZMI=; fh=0+SpTXHaJNl6m0HS79NAqMImdQ17WxyXVENQpxtQiR4=; b=FkweIesYSG0h0Xjd0pwh1L3+tRzY7Ary2qfZHZliJcAFXUMtB2vt/4x3xxI8WfabDq 0r23NuzRLFpy0YfnaMHnnYbVtUgd43ByT9BZz/19RGJL7uVdlSIla26bAwn9OnVRkImd 35YxNwpmjRuIMhG0RgK7BwOecs5FKx1kpmJ5VWwgDlK/HAZufrFOqOQVr/EIQGsI3PtV oCvTcdOvXdK5S8HvSSyG72oLdort8ZLouSk1ewylagj9RjYjUJ5lpGoiISX4m+vC7UsT WXEbp9ZRKmHGO5n1zasrVS9dtSjqjg95D8m0fuLLjN6yK+tM864QHFCz0ejPgITESWFl xLOg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Wir7IGcQ; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-48116-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48116-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCUpXXR7NSL0MAe4v+rBgQB2CtMRjZdSjOft/w1WA5YYpdIcNyN/XDp1MjGCjk79jtCOlDm/0lYVIrTub4edY9HsvK+fMoq6rIx+H2cLzw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n32-20020a635c60000000b00565db2812a0si11912683pgm.60.2024.02.01.04.34.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 04:34:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48116-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Wir7IGcQ; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-48116-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48116-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 28AD12945D0 for ; Thu, 1 Feb 2024 12:25:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0E0D015F30B; Thu, 1 Feb 2024 12:24:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Wir7IGcQ" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 8E0A8161B7E; Thu, 1 Feb 2024 12:23:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706790239; cv=none; b=fZAhM92QO5U3hnejIVdyb878FJh2TpKtCSjCyJ6oDxaPvaakOdjJPGMwE67P6DRD37vJeiE3fRqtvv36RsZqiI0DsMMqdiCMfd5G5uYk3CpK70sgpkpTRw5QhuyuDbPc2Jnmk1pP5zoHeT8VfHMBCS9fonHU7KlCSzetyvnzKzQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706790239; c=relaxed/simple; bh=HprukPdQXTcNr0Y7BiRuIS1YVLmvP2/8dsePu0XWy8Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kMsKNeKWT9Y/wbxudZnVOA5akFIiHM90fENfGiq+wFF4D/dYaSDryenJr7sZLAEKAmTl9fbYGl26l5wvWfn/HNK4nMFC4PYoEBD81s5Bez/jntJ4ywuTXRojHqczfIUcBzUGJ7xvIMZfaX4VxEhI30ioNBoasGs3beNuds7LlMM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Wir7IGcQ; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706790238; x=1738326238; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HprukPdQXTcNr0Y7BiRuIS1YVLmvP2/8dsePu0XWy8Q=; b=Wir7IGcQ0BN+y2rClcFbM/Fwr1bppQXkyP1BvIat4IfgcDGopc50nZ2J 4qtgK1YFp/IX1WDKfswYL8b3WrRlg5qp0U3R6R4EFrvhV7fKPAx0sJTjG oJuWJm9QXdVvf0HtzH2Pv6+zvDDjSI36f4IyloeATXeptOnhtilgbgI2p POwq0EcjqnHq+SxsZwXBnIK8/y5yLCTkXNMYulA+ODBWSA20Jllm3yTsC bz0homTE4ouPAIDNyDj4jKSGvPPF3Ps0rex9vl+kw1udoF7Cr7Y1ZY1el Man6cMMXoaWQdHr1BQKFf6d4sRVxXOx+EC9tTdylJq0W0z6gOd7aK74Bj g==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="3746972" X-IronPort-AV: E=Sophos;i="6.05,234,1701158400"; d="scan'208";a="3746972" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2024 04:23:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,234,1701158400"; d="scan'208";a="4499098" Received: from newjersey.igk.intel.com ([10.102.20.203]) by orviesa004.jf.intel.com with ESMTP; 01 Feb 2024 04:23:52 -0800 From: Alexander Lobakin To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Alexander Lobakin , Michal Swiatkowski , Marcin Szycik , Wojciech Drewek , Yury Norov , Andy Shevchenko , Rasmus Villemoes , Alexander Potapenko , Jiri Pirko , Ido Schimmel , Przemek Kitszel , Simon Horman , linux-btrfs@vger.kernel.org, dm-devel@redhat.com, ntfs3@lists.linux.dev, linux-s390@vger.kernel.org, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Shevchenko Subject: [PATCH net-next v5 05/21] bitops: make BYTES_TO_BITS() treewide-available Date: Thu, 1 Feb 2024 13:22:00 +0100 Message-ID: <20240201122216.2634007-6-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240201122216.2634007-1-aleksander.lobakin@intel.com> References: <20240201122216.2634007-1-aleksander.lobakin@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Avoid open-coding that simple expression each time by moving BYTES_TO_BITS() from the probes code to to export it to the rest of the kernel. Simplify the macro while at it. `BITS_PER_LONG / sizeof(long)` always equals to %BITS_PER_BYTE, regardless of the target architecture. Do the same for the tools ecosystem as well (incl. its version of bitops.h). The previous implementation had its implicit type of long, while the new one is int, so adjust the format literal accordingly in the perf code. Suggested-by: Andy Shevchenko Reviewed-by: Przemek Kitszel Signed-off-by: Alexander Lobakin --- include/linux/bitops.h | 2 ++ tools/include/linux/bitops.h | 2 ++ kernel/trace/trace_probe.c | 2 -- tools/perf/util/probe-finder.c | 4 +--- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/linux/bitops.h b/include/linux/bitops.h index f7f5a783da2a..e0cd09eb91cd 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -21,6 +21,8 @@ #define BITS_TO_U32(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u32)) #define BITS_TO_BYTES(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(char)) +#define BYTES_TO_BITS(nb) ((nb) * BITS_PER_BYTE) + extern unsigned int __sw_hweight8(unsigned int w); extern unsigned int __sw_hweight16(unsigned int w); extern unsigned int __sw_hweight32(unsigned int w); diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h index f18683b95ea6..bc6600466e7b 100644 --- a/tools/include/linux/bitops.h +++ b/tools/include/linux/bitops.h @@ -20,6 +20,8 @@ #define BITS_TO_U32(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(u32)) #define BITS_TO_BYTES(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(char)) +#define BYTES_TO_BITS(nb) ((nb) * BITS_PER_BYTE) + extern unsigned int __sw_hweight8(unsigned int w); extern unsigned int __sw_hweight16(unsigned int w); extern unsigned int __sw_hweight32(unsigned int w); diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 4dc74d73fc1d..2b743c1e37db 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -1053,8 +1053,6 @@ parse_probe_arg(char *arg, const struct fetch_type *type, return ret; } -#define BYTES_TO_BITS(nb) ((BITS_PER_LONG * (nb)) / sizeof(long)) - /* Bitfield type needs to be parsed into a fetch function */ static int __parse_bitfield_probe_arg(const char *bf, const struct fetch_type *t, diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index c8923375e30d..630e16c54ed5 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c @@ -186,8 +186,6 @@ static int convert_variable_location(Dwarf_Die *vr_die, Dwarf_Addr addr, return ret2; } -#define BYTES_TO_BITS(nb) ((nb) * BITS_PER_LONG / sizeof(long)) - static int convert_variable_type(Dwarf_Die *vr_die, struct probe_trace_arg *tvar, const char *cast, bool user_access) @@ -217,7 +215,7 @@ static int convert_variable_type(Dwarf_Die *vr_die, total = dwarf_bytesize(vr_die); if (boffs < 0 || total < 0) return -ENOENT; - ret = snprintf(buf, 16, "b%d@%d/%zd", bsize, boffs, + ret = snprintf(buf, 16, "b%d@%d/%d", bsize, boffs, BYTES_TO_BITS(total)); goto formatted; } -- 2.43.0