search for: round_down

Displaying 20 results from an estimated 80 matches for "round_down".

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.
...;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 pthread_mutex_t lock =...
2019 May 17
1
[nbdkit PATCH] truncate: Detect large image overflow with round-up
...gt; 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->size, round_up); + } if (round_down > 0) h->size = ROUND_DOWN (h->size, round_down); -- 2.20.1
2018 Sep 17
1
Re: [PATCH nbdkit v2] common: Introduce round up, down; and divide round up functions.
...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 (no sign extension is performed). > + > +/* Round down i to next multiple of n (n must be a power of 2). > + */ > +#define ROUND_DOWN(i, n) ({ \ > + assert (is_power_of_2 (n)); \ > + (i) & ~((n) - 1); \ > +}) And again. Also, ~((n)-1) is identical to -(n), if you want less typing (well, as long as you assume twos-complements signed num...
2018 Sep 17
0
[PATCH nbdkit v2] common: Introduce round up, down; and divide round up functions.
...ext 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_power_of_2 (n)); \ + (i) & ~((n) - 1); \ +}) + +/* Return n / d, rounding the result up to the next integer. */ +#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) + +#endif /* NBDKIT_ROUNDIN...
2019 Apr 27
0
[nbdkit PATCH 2/4] truncate: Fix corruption when plugin changes per-connection size
...(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; - static int par...
2018 Sep 17
0
[PATCH nbdkit v3 2/3] common: Introduce round up, down; and divide round up functions.
...ext 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_power_of_2 (n)); \ + (i) & -((typeof (i))(n)); \ +}) + +/* Return n / d, rounding the result up to the next integer. */ +#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) + +#endif /* NBDKIT_ROUNDIN...
2018 Jul 31
0
[PATCH nbdkit 1/4] Add truncate filter for truncating or extending the size of plugins.
...nclude <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, void *nxdata, +...
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
2019 May 16
3
[nbdkit PATCH 0/2] Avoid oddities with files unaligned to granularity
When using a filter that rounds up to alignment boundaries, the tail bytes of the plugin are difficult to access correctly. Rather than duplicating lots of code already in the truncate filter, it's easier to just make the other filters default to rounding down and add doc links on how to round up instead. Eric Blake (2): blocksize: Lift restriction against 0-size file cache, cow: Round
2020 Jul 09
0
[nbdkit PATCH] blocksize: Fix .extents when plugin changes type within minblock
...naligned + * ends. Also we only need to ask for maxlen of data, because it's + * fine to return less than the full count as long as we're making + * progress. */ - return next_ops->extents (nxdata, - MIN (count, maxlen), - ROUND_DOWN (offset, minblock), - flags, extents, err); + CLEANUP_EXTENTS_FREE struct nbdkit_extents *extents2 = NULL; + size_t i; + struct nbdkit_extent e; + + extents2 = nbdkit_extents_new (ROUND_DOWN (offset, minblock), + ROUND_UP (offset + coun...
2019 Apr 24
0
[nbdkit PATCH 2/4] truncate: Factor out reading real_size under mutex
..._get_size (struct nbdkit_next_ops *next_ops, void *nxdata, if (r == -1) return -1; - pthread_mutex_lock (&lock); + ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&lock); real_size = size = r; @@ -163,8 +170,6 @@ truncate_get_size (struct nbdkit_next_ops *next_ops, void *nxdata, size = ROUND_DOWN (size, round_down); ret = size; - pthread_mutex_unlock (&lock); - return ret; } @@ -176,11 +181,7 @@ truncate_pread (struct nbdkit_next_ops *next_ops, void *nxdata, { int r; uint32_t n; - uint64_t real_size_copy; - - pthread_mutex_lock (&lock); - real_size_copy = real_si...
2018 Aug 01
0
[PATCH v2 nbdkit 5/6] Add truncate filter for truncating or extending the size of plugins.
...<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; + +static int +pa...
2020 Jul 14
0
[PATCH v4 15/75] x86/boot/compressed/64: Always switch to own page-table
...ll become the new identity mappings. + * Once all ranges have been added, the new mapping is activated by calling + * finalize_identity_maps() below. + */ +void add_identity_map(unsigned long start, unsigned long size) +{ + unsigned long end = start + size; + + /* Align boundary to 2M. */ + start = round_down(start, PMD_SIZE); + end = round_up(end, PMD_SIZE); + if (start >= end) + return; + + /* Build the mapping. */ + kernel_ident_mapping_init(&mapping_info, (pgd_t *)top_level_pgt, + start, end); +} + /* Locates and clears a region for a new top level page table. */ void initialize_ident...
2020 Jul 08
1
Re: [nbdkit PATCH 2/3] extents: Add nbdkit_extents_aligned()
...or (i = 0; i < exts->extents.size; ++i) { > + e = exts->extents.ptr[i]; > + if (!IS_ALIGNED(e.length, align)) { > + /* If the unalignment is past align, just truncate and return early */ > + if (e.offset + e.length > offset + align) { > + e.length = ROUND_DOWN (e.length, align); > + exts->extents.size = i + !!e.length; > + exts->next = e.offset + e.length; > + break; > + } > + > + /* Otherwise, coalesce until we have at least align bytes, which > + * may require further queries. > +...
2019 May 13
3
[nbdkit PATCH v2 0/2] Bounce buffer cleanups
Based on Rich's review of my v1 that touched only cache.c, I have now tried to bring all three filters with alignment rounding in line with one another. There is definitely room for future improvements once we teach nbdkit to let filters and plugins advertise block sizes, but I'm hoping to get NBD_CMD_CACHE implemented first. Eric Blake (2): blocksize: Process requests in linear order
2019 May 16
0
[nbdkit PATCH 2/2] cache, cow: Round size down
...next_ops, void *nxdata, - void *handle) + void *handle) { int64_t size; int r; @@ -201,6 +204,7 @@ cache_get_size (struct nbdkit_next_ops *next_ops, void *nxdata, return -1; nbdkit_debug ("cache: underlying file size: %" PRIi64, size); + size = ROUND_DOWN (size, blksize); ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&lock); r = blk_set_size (size); diff --git a/filters/cow/cow.c b/filters/cow/cow.c index 1ce5893..aa1348b 100644 --- a/filters/cow/cow.c +++ b/filters/cow/cow.c @@ -49,6 +49,7 @@ #include "blk.h" #include "isaligned.h&quo...
2007 Feb 14
2
[PATCH 8/8] 2.6.17: scan DMI early
...bootmem":""); @@ -436,17 +441,34 @@ static inline int make_readonly(unsigned return readonly; } +#ifndef CONFIG_XEN /* Must run before zap_low_mappings */ __init void *early_ioremap(unsigned long addr, unsigned long size) { - return ioremap(addr, size); + unsigned long map = round_down(addr, LARGE_PAGE_SIZE); + + /* actually usually some more */ + if (size >= LARGE_PAGE_SIZE) { + printk("SMBIOS area too long %lu\n", size); + return NULL; + } + set_pmd(temp_mappings[0].pmd, __pmd(map | _KERNPG_TABLE | _PAGE_PSE)); + map += LARGE_PAGE_SIZE; + set_pmd(temp_mappings[1...
2017 Sep 08
2
[PATCH v15 3/5] virtio-balloon: VIRTIO_BALLOON_F_SG
...*vb, > > > + struct virtqueue *vq, > > > + unsigned long page_xb_start, > > > + unsigned long page_xb_end) > > > +{ > > > + unsigned long sg_pfn_start, sg_pfn_end; > > > + void *sg_addr; > > > + uint32_t sg_len, sg_max_len = round_down(UINT_MAX, PAGE_SIZE); > > > + > > > + sg_pfn_start = page_xb_start; > > > + while (sg_pfn_start < page_xb_end) { > > > + sg_pfn_start = xb_find_next_bit(&vb->page_xb, sg_pfn_start, > > > + page_xb_end, 1); > > > + if (sg_pfn_sta...
2017 Sep 08
2
[PATCH v15 3/5] virtio-balloon: VIRTIO_BALLOON_F_SG
...*vb, > > > + struct virtqueue *vq, > > > + unsigned long page_xb_start, > > > + unsigned long page_xb_end) > > > +{ > > > + unsigned long sg_pfn_start, sg_pfn_end; > > > + void *sg_addr; > > > + uint32_t sg_len, sg_max_len = round_down(UINT_MAX, PAGE_SIZE); > > > + > > > + sg_pfn_start = page_xb_start; > > > + while (sg_pfn_start < page_xb_end) { > > > + sg_pfn_start = xb_find_next_bit(&vb->page_xb, sg_pfn_start, > > > + page_xb_end, 1); > > > + if (sg_pfn_sta...