Displaying 20 results from an estimated 105 matches for "round_up".
2019 May 23
4
[RFC][PATCH] kernel.h: Add generic roundup_64() macro
...nding of the internals.
>
> And it looks to me like the use case you want this for is very much
> probably a power of two. In which case division is all kinds of just
> stupid.
>
> And we already have a power-of-two round up function that works on
> u64. It's called "round_up()".
>
> I wish we had a better visual warning about the differences between
> "round_up()" (limited to powers-of-two, but efficient, and works with
> any size) and "roundup()" (generic, potentially horribly slow, and
> doesn't work for 64-bit on 32-bit)....
2019 May 17
1
[nbdkit PATCH] truncate: Detect large image overflow with round-up
...<string.h>
#include <limits.h>
#include <errno.h>
+#include <inttypes.h>
#include <nbdkit-filter.h>
@@ -172,8 +173,14 @@ truncate_prepare (struct nbdkit_next_ops *next_ops, void *nxdata,
*/
if (truncate_size >= 0)
h->size = truncate_size;
- if (round_up > 0)
+ if (round_up > 0) {
+ if (ROUND_UP (h->size, round_up) > INT64_MAX) {
+ nbdkit_error ("cannot round size %" PRId64 " up to next boundary of %u",
+ h->size, round_up);
+ return -1;
+ }
h->size = ROUND_UP (h->siz...
2018 Sep 17
2
[PATCH nbdkit v2] common: Introduce round up, down; and divide round
Since we're using ({ .. }) gcc/clang extension, let's rewrite the
rounding.h change too.
Rich.
2018 Aug 01
1
Re: [PATCH v2 nbdkit 5/6] Add truncate filter for truncating or extending the size of plugins.
...ltiple of C<N>.
> +Use either C<round-up=N> or C<round-down=N>.
Worth mentioning that N must be a power of 2.
> +
> +#define THREAD_MODEL NBDKIT_THREAD_MODEL_PARALLEL
> +
> +/* These are the parameters. */
> +static int64_t truncate = -1;
> +static unsigned round_up = 0, round_down = 0;
> +
> +/* The real size of the underlying plugin. */
> +static uint64_t real_size;
> +
> +/* The calculated size after applying the parameters. */
> +static uint64_t size;
> +
> +/* This lock protects the real_size and size fields. */
> +static pthrea...
2019 May 23
1
[RFC][PATCH] kernel.h: Add generic roundup_64() macro
...g:
>
> So that at least handles the constant case that the normal "roundup()"
> case also handles.
>
> At the same time, in the case you are talking about, I really do
> suspect that we have a (non-constant) power of two, and that you
> should have just used "round_up()" which works fine regardless of
> size, and is always efficient.
I think you are correct in this.
act_size = roundup_64(attr->length, MLX5_SW_ICM_BLOCK_SIZE(dm_db->dev));
Where we have:
#define MLX5_SW_ICM_BLOCK_SIZE(dev) (1 << MLX5_LOG_SW_ICM_BLOCK_SIZE(dev))
Whic...
2019 May 23
2
[RFC][PATCH] kernel.h: Add generic roundup_64() macro
From: Steven Rostedt (VMware) <rostedt at goodmis.org>
In discussing a build failure on x86_32 due to the use of roundup() on
a 64 bit number, I realized that there's no generic equivalent
roundup_64(). It is implemented in two separate places in the kernel,
but there really should be just one that all can use.
Although the other implementations are a static inline function, this
2018 Sep 17
1
Re: [PATCH nbdkit v2] common: Introduce round up, down; and divide round up functions.
...| 2 +-
> filters/cow/Makefile.am | 3 +-
> filters/cow/cow.c | 2 +-
> filters/truncate/truncate.c | 5 ++--
> 6 files changed, 68 insertions(+), 6 deletions(-)
>
> +/* Round up i to next multiple of n (n must be a power of 2).
> + */
> +#define ROUND_UP(i, n) ({ \
> + assert (is_power_of_2 (n)); \
> + ((i) + (n) - 1) & ~((n) - 1); \
> +})
Potential bug: if n is 32-bit unsigned, but i is 64-bit, the bitmask on
the right half of & will be inappropriately truncated...
2018 Sep 17
0
[PATCH nbdkit v2] common: Introduce round up, down; and divide round up functions.
...S SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef NBDKIT_ROUNDING_H
+#define NBDKIT_ROUNDING_H
+
+#include <stdint.h>
+#include <assert.h>
+
+#include "ispowerof2.h"
+
+/* Round up i to next multiple of n (n must be a power of 2).
+ */
+#define ROUND_UP(i, n) ({ \
+ assert (is_power_of_2 (n)); \
+ ((i) + (n) - 1) & ~((n) - 1); \
+})
+
+/* Round down i to next multiple of n (n must be a power of 2).
+ */
+#define ROUND_DOWN(i, n) ({ \
+ assert (is_po...
2019 May 23
0
[RFC][PATCH] kernel.h: Add generic roundup_64() macro
...hat about something like the following:
So that at least handles the constant case that the normal "roundup()"
case also handles.
At the same time, in the case you are talking about, I really do
suspect that we have a (non-constant) power of two, and that you
should have just used "round_up()" which works fine regardless of
size, and is always efficient.
On a slight tangent.. Maybe we should have something like this:
#define size_fn(x, prefix, ...) ({ \
typeof(x) __ret; \
switch (sizeof(x)) {...
2018 Sep 17
0
[PATCH nbdkit v3 2/3] common: Introduce round up, down; and divide round up functions.
...Y OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef NBDKIT_ROUNDING_H
+#define NBDKIT_ROUNDING_H
+
+#include <assert.h>
+
+#include "ispowerof2.h"
+
+/* Round up i to next multiple of n (n must be a power of 2).
+ */
+#define ROUND_UP(i, n) ({ \
+ assert (is_power_of_2 (n)); \
+ ((i) + (n) - 1) & -((typeof (i))n); \
+})
+
+/* Round down i to next multiple of n (n must be a power of 2).
+ */
+#define ROUND_DOWN(i, n) ({ \
+ assert (is_po...
2019 Apr 27
0
[nbdkit PATCH 2/4] truncate: Fix corruption when plugin changes per-connection size
...- * Copyright (C) 2018 Red Hat Inc.
+ * Copyright (C) 2018-2019 Red Hat Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -54,15 +54,6 @@
static int64_t truncate_size = -1;
static unsigned round_up = 0, round_down = 0;
-/* The real size of the underlying plugin. */
-static uint64_t real_size;
-
-/* The calculated size after applying the parameters. */
-static uint64_t size;
-
-/* This lock protects the real_size and size fields. */
-static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
-...
2016 Jan 22
1
[supermin] [PATCH] ext2: check for needed block size
...c/ext2fs-c.c b/src/ext2fs-c.c
index f01ca9d..e45980a 100644
--- a/src/ext2fs-c.c
+++ b/src/ext2fs-c.c
@@ -52,6 +52,9 @@
/* fts.h in glibc is broken, forcing us to use the GNUlib alternative. */
#include "fts_.h"
+/* How many blocks of size S are needed for storing N bytes. */
+#define ROUND_UP(N, S) (((N) + (S) - 1) / (S))
+
struct ext2_data
{
ext2_filsys fs;
@@ -629,6 +632,7 @@ ext2_copy_file (struct ext2_data *data, const char *src, const char *dest)
errcode_t err;
struct stat statbuf;
struct statvfs statvfsbuf;
+ size_t blocks;
if (data->debug >= 3)
prin...
2018 Jul 31
0
[PATCH nbdkit 1/4] Add truncate filter for truncating or extending the size of plugins.
...fig.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+
+#include <nbdkit-filter.h>
+
+#define THREAD_MODEL NBDKIT_THREAD_MODEL_PARALLEL
+
+/* These are the parameters. */
+static int64_t truncate = -1, round_up = -1, round_down = -1;
+
+/* The real size of the underlying plugin. */
+static int64_t real_size;
+
+/* The calculated size after applying the parameters. */
+static int64_t size;
+
+/* Called for each key=value passed on the command line. */
+static int
+truncate_config (nbdkit_next_config *next,...
2019 May 23
0
[RFC][PATCH] kernel.h: Add generic roundup_64() macro
...piler
doesn't have any understanding of the internals.
And it looks to me like the use case you want this for is very much
probably a power of two. In which case division is all kinds of just
stupid.
And we already have a power-of-two round up function that works on
u64. It's called "round_up()".
I wish we had a better visual warning about the differences between
"round_up()" (limited to powers-of-two, but efficient, and works with
any size) and "roundup()" (generic, potentially horribly slow, and
doesn't work for 64-bit on 32-bit).
Side note: "round_...
2019 May 24
1
[RFC][PATCH] kernel.h: Add generic roundup_64() macro
...05/2019 16:27, Steven Rostedt wrote:
>
> I haven't yet tested this, but what about something like the following:
>
> ...perhaps forget about the constant check, and just force
> the power of two check:
>
> \
> if (!(__y & (__y >> 1))) { \
> __x = round_up(x, y); \
> } else { \
You probably want
if (!(__y & (__y - 1))
--
Roger
2007 Feb 14
2
[PATCH 8/8] 2.6.17: scan DMI early
...able_space(unsigned long end)
{
- unsigned long puds, pmds, ptes, tables;
+ unsigned long puds, pmds, ptes, tables, fixmap_tables;
puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
pmds = (end + PMD_SIZE - 1) >> PMD_SHIFT;
@@ -660,7 +682,16 @@ static void __init find_early_table_spac
round_up(pmds * 8, PAGE_SIZE) +
round_up(ptes * 8, PAGE_SIZE);
- extend_init_mapping(tables);
+ /* Also reserve pages for fixmaps that need to be set up early.
+ * Their pud is shared with the kernel pud.
+ */
+ pmds = (PMD_SIZE - 1 - FIXADDR_START) >> PMD_SHIFT;
+ ptes = (PTE_SIZE - 1 - FIXA...
2019 Apr 27
8
[nbdkit PATCH 0/4] Fix truncate handling of real_size
While working on adding assertions to pthread_mutex_lock calls, I
noticed that the truncate filter's use of mutex didn't really protect
us, and isn't really necessary. Cleaning that up also spotted a couple
of other potential cleanups.
Eric Blake (4):
filters: Drop useless .open callbacks
truncate: Fix corruption when plugin changes per-connection size
truncate: Test for safe
2018 Aug 01
0
[PATCH v2 nbdkit 5/6] Add truncate filter for truncating or extending the size of plugins.
...gt;
+#include <errno.h>
+
+#include <pthread.h>
+
+#include <nbdkit-filter.h>
+
+#include "ispowerof2.h"
+#include "iszero.h"
+
+#define THREAD_MODEL NBDKIT_THREAD_MODEL_PARALLEL
+
+/* These are the parameters. */
+static int64_t truncate = -1;
+static unsigned round_up = 0, round_down = 0;
+
+/* The real size of the underlying plugin. */
+static uint64_t real_size;
+
+/* The calculated size after applying the parameters. */
+static uint64_t size;
+
+/* This lock protects the real_size and size fields. */
+static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+...
2019 May 24
0
[RFC][PATCH] kernel.h: Add generic roundup_64() macro
...;
> > I haven't yet tested this, but what about something like the following:
> >
> > ...perhaps forget about the constant check, and just force
> > the power of two check:
> >
> > \
> > if (!(__y & (__y >> 1))) { \
> > __x = round_up(x, y); \
> > } else { \
>
> You probably want
>
> if (!(__y & (__y - 1))
>
> --
Yes I do. I corrected it in my next email.
http://lkml.kernel.org/r/20190523133648.591f9e78 at gandalf.local.home
> #define roundup(x, y) ( \
> { \...
2019 May 24
1
[RFC][PATCH] kernel.h: Add generic roundup_64() macro
...39;t yet tested this, but what about something like the following:
>>>
>>> ...perhaps forget about the constant check, and just force
>>> the power of two check:
>>>
>>> \
>>> if (!(__y & (__y >> 1))) { \
>>> __x = round_up(x, y); \
>>> } else { \
>>
>> You probably want
>>
>> if (!(__y & (__y - 1))
>>
>> --
>
> Yes I do. I corrected it in my next email.
>
> http://lkml.kernel.org/r/20190523133648.591f9e78 at gandalf.local.home
Or pe...