DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Joshua Washington <joshwash@google.com>
Cc: dev@dpdk.org, Joshua Washington <joshwash@google.com>,
	 Bruce Richardson <bruce.richardson@intel.com>,
	Chengwen Feng <fengchengwen@huawei.com>
Subject: [PATCH v4 01/15] eal: introduce division round up macro
Date: Mon,  5 Oct 2026 19:30:37 -0700	[thread overview]
Message-ID: <20261006023053.2572501-2-joshwash@google.com> (raw)
In-Reply-To: <20261006023053.2572501-1-joshwash@google.com>

A number of drivers define the DIV_ROUND_UP macro -- add it to
rte_common.h so that other code looking to use that functionality
doesn't have to re-define it.

Signed-off-by: Joshua Washington <joshwash@google.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
Changes in v4:
  - Rebased changes
Changes in v3:
  - Add unit tests in app/test/test_common.c.
  - Add release notes entry.
  - Enhance Doxygen documentation to document parameters and caveats
    (divisor evaluation, non-negative inputs, wraparound).
Changes in v2:
  - Split out patches replacing usages
---
 app/test/test_common.c                 | 10 ++++++++++
 doc/guides/rel_notes/release_26_11.rst |  5 +++++
 lib/eal/include/rte_common.h           | 18 ++++++++++++++++++
 3 files changed, 33 insertions(+)

diff --git a/app/test/test_common.c b/app/test/test_common.c
index 3e1c7df0c1..bce2776ea6 100644
--- a/app/test/test_common.c
+++ b/app/test/test_common.c
@@ -47,6 +47,16 @@ test_macros(int __rte_unused unused_parm)
 		"RTE_MAX");
 	RTE_TEST_ASSERT_EQUAL(RTE_MIN(SMALLER, BIGGER), SMALLER,
 		"RTE_MIN");
+	RTE_TEST_ASSERT_EQUAL(RTE_DIV_ROUND_UP(10, 5), 2,
+		"RTE_DIV_ROUND_UP exact");
+	RTE_TEST_ASSERT_EQUAL(RTE_DIV_ROUND_UP(11, 5), 3,
+		"RTE_DIV_ROUND_UP remainder");
+	RTE_TEST_ASSERT_EQUAL(RTE_DIV_ROUND_UP(0, 5), 0,
+		"RTE_DIV_ROUND_UP n=0");
+	RTE_TEST_ASSERT_EQUAL(RTE_DIV_ROUND_UP(0, 1), 0,
+		"RTE_DIV_ROUND_UP n=0, d=1");
+	RTE_TEST_ASSERT_EQUAL(RTE_DIV_ROUND_UP(5, 1), 5,
+		"RTE_DIV_ROUND_UP d=1");
 
 	RTE_TEST_ASSERT_EQUAL(RTE_PTR_ADD(arr + 1, sizeof(arr[0])), &arr[2],
 		"RTE_PTR_ADD(expr, x)");
diff --git a/doc/guides/rel_notes/release_26_11.rst b/doc/guides/rel_notes/release_26_11.rst
index 030bd84cea..430e5ab1c1 100644
--- a/doc/guides/rel_notes/release_26_11.rst
+++ b/doc/guides/rel_notes/release_26_11.rst
@@ -138,6 +138,11 @@ New Features
   Added ``rte_bbdev_queue_stats_get()`` function to retrieve statistics
   for a specific queue, complementing the existing device-level statistics API.
 
+* **Added division round up macro.**
+
+  Added the ``RTE_DIV_ROUND_UP`` macro in ``rte_common.h`` to divide dividend
+  by divisor, rounding up to the nearest integer.
+
 
 Removed Items
 -------------
diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
index f872d3eabb..f3ff632713 100644
--- a/lib/eal/include/rte_common.h
+++ b/lib/eal/include/rte_common.h
@@ -704,6 +704,24 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
 		(ceil - (v)) > ((v) - floor) ? floor : ceil;	\
 	})
 
+/**
+ * Macro to divide dividend @p n by divisor @p d, rounding up if @p d does not divide @p n.
+ *
+ * @param n
+ *   Dividend. Must be a non-negative integer to round correctly.
+ * @param d
+ *   Divisor. Must be a positive integer. Evaluated twice.
+ * @return
+ *   Result of dividing @p n by @p d, rounded up.
+ *
+ * @note The divisor @p d is evaluated twice. Arguments must not have side effects.
+ * @note Both @p n and @p d must be non-negative to round correctly.
+ * @note The sum @c (n) + (d) - 1 can wrap around if @p n is close to the maximum
+ *       representable value of its type (e.g. RTE_DIV_ROUND_UP(UINT32_MAX, 2)
+ *       on uint32_t wraps to 0).
+ */
+#define RTE_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+
 /**
  * Checks if a pointer is aligned to a given power-of-two value
  *
-- 
2.56.0.rc1.315.gc6ed9934b7-goog


  reply	other threads:[~2026-10-06  2:31 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-12 22:30 [PATCH] eal: introduce division round up macro Joshua Washington
2026-08-13  1:29 ` Stephen Hemminger
2026-08-13 17:22 ` [PATCH v2 00/14] Introduce RTE_DIV_ROUND_UP Joshua Washington
2026-08-13 17:22   ` [PATCH v2 01/14] eal: introduce division round up macro Joshua Washington
2026-08-13 17:22   ` [PATCH v2 02/14] net/i40e: use common " Joshua Washington
2026-08-13 17:22   ` [PATCH v2 03/14] net/idpf: " Joshua Washington
2026-08-13 17:22   ` [PATCH v2 04/14] net/ice: " Joshua Washington
2026-08-13 17:22   ` [PATCH v2 05/14] net/qede: " Joshua Washington
2026-08-13 17:22   ` [PATCH v2 06/14] net/rnp: " Joshua Washington
2026-08-13 17:22   ` [PATCH v2 07/14] net/hns3: " Joshua Washington
2026-08-13 17:22   ` [PATCH v2 08/14] net/hinic: " Joshua Washington
2026-08-13 17:22   ` [PATCH v2 09/14] net/bnx2x: " Joshua Washington
2026-08-13 17:22   ` [PATCH v2 10/14] net/cxgbe: " Joshua Washington
2026-08-13 17:22   ` [PATCH v2 11/14] net/ena: " Joshua Washington
2026-08-13 17:22   ` [PATCH v2 12/14] raw/ifpga/base: " Joshua Washington
2026-08-13 17:22   ` [PATCH v2 13/14] drivers: " Joshua Washington
2026-08-13 17:22   ` [PATCH v2 14/14] app/procinfo: " Joshua Washington
2026-08-15 15:32   ` [PATCH v2 00/14] Introduce RTE_DIV_ROUND_UP Stephen Hemminger
2026-09-22  0:36   ` Stephen Hemminger
2026-09-23  1:07 ` [PATCH v3 00/16] " Joshua Washington
2026-09-23  1:07   ` [PATCH v3 01/16] eal: introduce division round up macro Joshua Washington
2026-09-23  7:29     ` Bruce Richardson
2026-09-24  7:47     ` fengchengwen
2026-09-23  1:07   ` [PATCH v3 02/16] net/i40e: use common " Joshua Washington
2026-09-23  7:30     ` Bruce Richardson
2026-09-23  7:35       ` Bruce Richardson
2026-09-29 22:44         ` Joshua Washington
2026-09-30  7:31           ` Bruce Richardson
2026-09-23  1:07   ` [PATCH v3 03/16] net/idpf: " Joshua Washington
2026-09-23  7:31     ` Bruce Richardson
2026-09-23  1:07   ` [PATCH v3 04/16] net/ice: " Joshua Washington
2026-09-23  7:31     ` Bruce Richardson
2026-09-23  1:07   ` [PATCH v3 05/16] net/qede: " Joshua Washington
2026-09-23  1:07   ` [PATCH v3 06/16] net/rnp: " Joshua Washington
2026-09-23  1:07   ` [PATCH v3 07/16] net/hns3: " Joshua Washington
2026-09-24  7:48     ` fengchengwen
2026-09-23  1:07   ` [PATCH v3 08/16] net/hinic: " Joshua Washington
2026-09-23  1:07   ` [PATCH v3 09/16] net/bnx2x: " Joshua Washington
2026-09-23  1:07   ` [PATCH v3 10/16] net/cxgbe: " Joshua Washington
2026-09-23  1:07   ` [PATCH v3 11/16] net/ena: " Joshua Washington
2026-09-23  1:07   ` [PATCH v3 12/16] raw/ifpga/base: " Joshua Washington
2026-09-23  1:07   ` [PATCH v3 13/16] net/nfp: " Joshua Washington
2026-09-23  1:07   ` [PATCH v3 14/16] app/procinfo: " Joshua Washington
2026-09-24  7:49     ` fengchengwen
2026-09-23  1:07   ` [PATCH v3 15/16] app/test: " Joshua Washington
2026-09-23  7:36     ` Bruce Richardson
2026-09-24  7:51     ` fengchengwen
2026-09-23  1:07   ` [PATCH v3 16/16] app/test-compress-perf: " Joshua Washington
2026-09-23  7:36     ` Bruce Richardson
2026-09-24  7:51     ` fengchengwen
2026-09-23 17:32   ` [PATCH v3 00/16] Introduce RTE_DIV_ROUND_UP Stephen Hemminger
2026-10-06  2:30   ` [PATCH v4 00/15] " Joshua Washington
2026-10-06  2:30     ` Joshua Washington [this message]
2026-10-06  2:30     ` [PATCH v4 02/15] net/i40e: use common division round up macro Joshua Washington
2026-10-06  2:30     ` [PATCH v4 03/15] net/idpf: " Joshua Washington
2026-10-06  2:30     ` [PATCH v4 04/15] net/ice: " Joshua Washington
2026-10-06  2:30     ` [PATCH v4 05/15] net/qede: " Joshua Washington
2026-10-06  2:30     ` [PATCH v4 06/15] net/rnp: " Joshua Washington
2026-10-06  2:30     ` [PATCH v4 07/15] net/hns3: " Joshua Washington
2026-10-06  2:30     ` [PATCH v4 08/15] net/hinic: " Joshua Washington
2026-10-06  2:30     ` [PATCH v4 09/15] net/bnx2x: " Joshua Washington
2026-10-06  2:30     ` [PATCH v4 10/15] net/cxgbe: " Joshua Washington
2026-10-06  2:30     ` [PATCH v4 11/15] net/ena: " Joshua Washington
2026-10-06  2:30     ` [PATCH v4 12/15] net/nfp: " Joshua Washington
2026-10-06  2:30     ` [PATCH v4 13/15] app/procinfo: " Joshua Washington
2026-10-06  2:30     ` [PATCH v4 14/15] app/test: " Joshua Washington
2026-10-06  2:30     ` [PATCH v4 15/15] app/test-compress-perf: " Joshua Washington
2026-10-06 16:38     ` [PATCH v4 00/15] Introduce RTE_DIV_ROUND_UP Stephen Hemminger
2026-10-07 20:21       ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261006023053.2572501-2-joshwash@google.com \
    --to=joshwash@google.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=fengchengwen@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox