Merge pull request #18 from mariuszbarczak/own-min-max-div-round-up-macros
OCF provides own macros for MIN, MAX, and DIV_ROUND_UP
This commit is contained in:
commit
561f5900b0
@ -695,7 +695,7 @@ int cleaning_policy_acp_add_core(ocf_cache_t cache,
|
|||||||
ocf_core_id_t core_id)
|
ocf_core_id_t core_id)
|
||||||
{
|
{
|
||||||
uint64_t core_size = cache->core_conf_meta[core_id].length;
|
uint64_t core_size = cache->core_conf_meta[core_id].length;
|
||||||
uint64_t num_chunks = DIV_ROUND_UP(core_size, ACP_CHUNK_SIZE);
|
uint64_t num_chunks = OCF_DIV_ROUND_UP(core_size, ACP_CHUNK_SIZE);
|
||||||
struct acp_context *acp = _acp_get_ctx_from_cache(cache);
|
struct acp_context *acp = _acp_get_ctx_from_cache(cache);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ static int _ocf_discard_step(struct ocf_request *req)
|
|||||||
|
|
||||||
req->byte_position = SECTORS_TO_BYTES(req->discard.sector +
|
req->byte_position = SECTORS_TO_BYTES(req->discard.sector +
|
||||||
req->discard.handled);
|
req->discard.handled);
|
||||||
req->byte_length = MIN(SECTORS_TO_BYTES(req->discard.nr_sects -
|
req->byte_length = OCF_MIN(SECTORS_TO_BYTES(req->discard.nr_sects -
|
||||||
req->discard.handled), MAX_TRIM_RQ_SIZE);
|
req->discard.handled), MAX_TRIM_RQ_SIZE);
|
||||||
req->core_line_first = ocf_bytes_2_lines(cache, req->byte_position);
|
req->core_line_first = ocf_bytes_2_lines(cache, req->byte_position);
|
||||||
req->core_line_last =
|
req->core_line_last =
|
||||||
|
@ -85,11 +85,11 @@ static ocf_cache_line_t ocf_metadata_hash_get_entires(
|
|||||||
OCF_HASH_PRIME - 1;
|
OCF_HASH_PRIME - 1;
|
||||||
|
|
||||||
case metadata_segment_sb_config:
|
case metadata_segment_sb_config:
|
||||||
return DIV_ROUND_UP(sizeof(struct ocf_superblock_config),
|
return OCF_DIV_ROUND_UP(sizeof(struct ocf_superblock_config),
|
||||||
PAGE_SIZE);
|
PAGE_SIZE);
|
||||||
|
|
||||||
case metadata_segment_sb_runtime:
|
case metadata_segment_sb_runtime:
|
||||||
return DIV_ROUND_UP(sizeof(struct ocf_superblock_runtime),
|
return OCF_DIV_ROUND_UP(sizeof(struct ocf_superblock_runtime),
|
||||||
PAGE_SIZE);
|
PAGE_SIZE);
|
||||||
|
|
||||||
case metadata_segment_reserved:
|
case metadata_segment_reserved:
|
||||||
@ -247,7 +247,7 @@ static int ocf_metadata_hash_calculate_metadata_size(
|
|||||||
* Setup SSD location and size
|
* Setup SSD location and size
|
||||||
*/
|
*/
|
||||||
raw->ssd_pages_offset = count_pages;
|
raw->ssd_pages_offset = count_pages;
|
||||||
raw->ssd_pages = DIV_ROUND_UP(raw->entries,
|
raw->ssd_pages = OCF_DIV_ROUND_UP(raw->entries,
|
||||||
raw->entries_in_page);
|
raw->entries_in_page);
|
||||||
|
|
||||||
/* Update offset for next container */
|
/* Update offset for next container */
|
||||||
@ -495,7 +495,7 @@ static int ocf_metadata_hash_init(struct ocf_cache *cache,
|
|||||||
* Setup SSD location and size
|
* Setup SSD location and size
|
||||||
*/
|
*/
|
||||||
raw->ssd_pages_offset = page;
|
raw->ssd_pages_offset = page;
|
||||||
raw->ssd_pages = DIV_ROUND_UP(raw->entries,
|
raw->ssd_pages = OCF_DIV_ROUND_UP(raw->entries,
|
||||||
raw->entries_in_page);
|
raw->entries_in_page);
|
||||||
|
|
||||||
/* Update offset for next container */
|
/* Update offset for next container */
|
||||||
|
@ -90,7 +90,7 @@ int metadata_io_read_i_atomic(struct ocf_cache *cache,
|
|||||||
count = io_sectors_count;
|
count = io_sectors_count;
|
||||||
for (i = 0; i < io_sectors_count; i += curr_count) {
|
for (i = 0; i < io_sectors_count; i += curr_count) {
|
||||||
/* Get sectors count of this IO iteration */
|
/* Get sectors count of this IO iteration */
|
||||||
curr_count = MIN(max_sectors_count, count);
|
curr_count = OCF_MIN(max_sectors_count, count);
|
||||||
|
|
||||||
env_completion_init(&meta_atom_req.complete);
|
env_completion_init(&meta_atom_req.complete);
|
||||||
meta_atom_req.error = 0;
|
meta_atom_req.error = 0;
|
||||||
@ -268,7 +268,7 @@ int metadata_io_write_i_asynch(struct ocf_cache *cache, uint32_t queue,
|
|||||||
{
|
{
|
||||||
uint32_t curr_count, written;
|
uint32_t curr_count, written;
|
||||||
uint32_t max_count = metadata_io_max_page(cache);
|
uint32_t max_count = metadata_io_max_page(cache);
|
||||||
uint32_t io_count = DIV_ROUND_UP(count, max_count);
|
uint32_t io_count = OCF_DIV_ROUND_UP(count, max_count);
|
||||||
uint32_t i, i_fill;
|
uint32_t i, i_fill;
|
||||||
int error = 0, ret;
|
int error = 0, ret;
|
||||||
struct ocf_io *io;
|
struct ocf_io *io;
|
||||||
@ -546,7 +546,7 @@ static int metadata_io(struct metadata_io *mio)
|
|||||||
env_completion_init(&mio->completion);
|
env_completion_init(&mio->completion);
|
||||||
|
|
||||||
while (count) {
|
while (count) {
|
||||||
this_count = MIN(count, max_count);
|
this_count = OCF_MIN(count, max_count);
|
||||||
|
|
||||||
err = metadata_submit_io(cache, mio, this_count, written);
|
err = metadata_submit_io(cache, mio, this_count, written);
|
||||||
if (err)
|
if (err)
|
||||||
|
@ -128,7 +128,7 @@ static uint32_t _raw_ram_size_on_ssd(struct ocf_cache *cache,
|
|||||||
{
|
{
|
||||||
const size_t alignment = 128 * KiB / PAGE_SIZE;
|
const size_t alignment = 128 * KiB / PAGE_SIZE;
|
||||||
|
|
||||||
return DIV_ROUND_UP(raw->ssd_pages, alignment) * alignment;
|
return OCF_DIV_ROUND_UP(raw->ssd_pages, alignment) * alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -190,7 +190,7 @@ uint32_t raw_dynamic_size_on_ssd(struct ocf_cache *cache,
|
|||||||
{
|
{
|
||||||
const size_t alignment = 128 * KiB / PAGE_SIZE;
|
const size_t alignment = 128 * KiB / PAGE_SIZE;
|
||||||
|
|
||||||
return DIV_ROUND_UP(raw->ssd_pages, alignment) * alignment;
|
return OCF_DIV_ROUND_UP(raw->ssd_pages, alignment) * alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -210,8 +210,8 @@ static unsigned long _ocf_mngt_find_first_free_core(const unsigned long *bitmap)
|
|||||||
for (i = 0; i * sizeof(unsigned long) * 8 < OCF_CORE_MAX; i++) {
|
for (i = 0; i * sizeof(unsigned long) * 8 < OCF_CORE_MAX; i++) {
|
||||||
unsigned long long ignore_mask = (i == 0) ? 1UL : 0UL;
|
unsigned long long ignore_mask = (i == 0) ? 1UL : 0UL;
|
||||||
if (~(bitmap[i] | ignore_mask)) {
|
if (~(bitmap[i] | ignore_mask)) {
|
||||||
ret = MIN(OCF_CORE_MAX, i * sizeof(unsigned long) * 8 +
|
ret = OCF_MIN(OCF_CORE_MAX, i * sizeof(unsigned long) *
|
||||||
_ffz(bitmap[i] | ignore_mask));
|
8 + _ffz(bitmap[i] | ignore_mask));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -243,7 +243,7 @@ static int __ocf_mngt_lookup_core_uuid(ocf_cache_t cache,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!env_strncmp(core->obj.uuid.data, cfg->uuid.data,
|
if (!env_strncmp(core->obj.uuid.data, cfg->uuid.data,
|
||||||
min(core->obj.uuid.size,
|
OCF_MIN(core->obj.uuid.size,
|
||||||
cfg->uuid.size)))
|
cfg->uuid.size)))
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ ocf_data_obj_t ocf_mngt_core_pool_lookup(ocf_ctx_t ctx, ocf_uuid_t uuid,
|
|||||||
list_for_each_entry(sobj, &ctx->core_pool.core_pool_head,
|
list_for_each_entry(sobj, &ctx->core_pool.core_pool_head,
|
||||||
core_pool_item) {
|
core_pool_item) {
|
||||||
if (sobj->type == type && !env_strncmp(sobj->uuid.data,
|
if (sobj->type == type && !env_strncmp(sobj->uuid.data,
|
||||||
uuid->data, min(sobj->uuid.size, uuid->size))) {
|
uuid->data, OCF_MIN(sobj->uuid.size, uuid->size))) {
|
||||||
return sobj;
|
return sobj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -264,10 +264,10 @@ static void _ocf_mngt_flush_portion(struct flush_container *fc)
|
|||||||
/* regardless those calculations, limit flush portion to be
|
/* regardless those calculations, limit flush portion to be
|
||||||
* between OCF_MNG_FLUSH_MIN and OCF_MNG_FLUSH_MAX
|
* between OCF_MNG_FLUSH_MIN and OCF_MNG_FLUSH_MAX
|
||||||
*/
|
*/
|
||||||
fc->flush_portion = MIN(fc->flush_portion, OCF_MNG_FLUSH_MAX);
|
fc->flush_portion = OCF_MIN(fc->flush_portion, OCF_MNG_FLUSH_MAX);
|
||||||
fc->flush_portion = MAX(fc->flush_portion, OCF_MNG_FLUSH_MIN);
|
fc->flush_portion = OCF_MAX(fc->flush_portion, OCF_MNG_FLUSH_MIN);
|
||||||
|
|
||||||
curr_count = MIN(fc->count - fc->iter, fc->flush_portion);
|
curr_count = OCF_MIN(fc->count - fc->iter, fc->flush_portion);
|
||||||
|
|
||||||
ocf_cleaner_do_flush_data_async(fc->cache,
|
ocf_cleaner_do_flush_data_async(fc->cache,
|
||||||
&fc->flush_data[fc->iter],
|
&fc->flush_data[fc->iter],
|
||||||
|
@ -141,7 +141,7 @@ int ocf_cache_get_info(ocf_cache_t cache, struct ocf_cache_info *info)
|
|||||||
core_runtime_meta[i].dirty_since);
|
core_runtime_meta[i].dirty_since);
|
||||||
if (core_dirty_since) {
|
if (core_dirty_since) {
|
||||||
dirty_since = (dirty_since ?
|
dirty_since = (dirty_since ?
|
||||||
MIN(dirty_since, core_dirty_since) :
|
OCF_MIN(dirty_since, core_dirty_since) :
|
||||||
core_dirty_since);
|
core_dirty_since);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,32 +15,26 @@
|
|||||||
#define BYTES_TO_PAGES(x) ((((uint64_t)x) + (PAGE_SIZE - 1)) / PAGE_SIZE)
|
#define BYTES_TO_PAGES(x) ((((uint64_t)x) + (PAGE_SIZE - 1)) / PAGE_SIZE)
|
||||||
#define PAGES_TO_BYTES(x) (((uint64_t)x) * PAGE_SIZE)
|
#define PAGES_TO_BYTES(x) (((uint64_t)x) * PAGE_SIZE)
|
||||||
|
|
||||||
#ifndef DIV_ROUND_UP
|
#define OCF_DIV_ROUND_UP(x, y) \
|
||||||
# define DIV_ROUND_UP(x, y) \
|
|
||||||
({ \
|
({ \
|
||||||
__typeof__ (x) __x = (x); \
|
__typeof__ (x) __x = (x); \
|
||||||
__typeof__ (y) __y = (y); \
|
__typeof__ (y) __y = (y); \
|
||||||
(__x + __y - 1) / __y; \
|
(__x + __y - 1) / __y; \
|
||||||
})
|
})
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef MAX
|
#define OCF_MAX(x,y) \
|
||||||
# define MAX(x,y) \
|
|
||||||
({ \
|
({ \
|
||||||
__typeof__ (x) __x = (x); \
|
__typeof__ (x) __x = (x); \
|
||||||
__typeof__ (y) __y = (y); \
|
__typeof__ (y) __y = (y); \
|
||||||
__x > __y ? __x : __y; \
|
__x > __y ? __x : __y; \
|
||||||
})
|
})
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef MIN
|
#define OCF_MIN(x,y) \
|
||||||
#define MIN(x,y) \
|
|
||||||
({ \
|
({ \
|
||||||
__typeof__ (x) __x = (x); \
|
__typeof__ (x) __x = (x); \
|
||||||
__typeof__ (y) __y = (y); \
|
__typeof__ (y) __y = (y); \
|
||||||
__x < __y ? __x : __y; \
|
__x < __y ? __x : __y; \
|
||||||
})
|
})
|
||||||
#endif
|
|
||||||
|
|
||||||
#define METADATA_VERSION() ((OCF_VERSION_MAIN << 16) + \
|
#define METADATA_VERSION() ((OCF_VERSION_MAIN << 16) + \
|
||||||
(OCF_VERSION_MAJOR << 8) + OCF_VERSION_MINOR)
|
(OCF_VERSION_MAJOR << 8) + OCF_VERSION_MINOR)
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#define __OCF_PRIV_H__
|
#define __OCF_PRIV_H__
|
||||||
|
|
||||||
#include "ocf_env.h"
|
#include "ocf_env.h"
|
||||||
|
#include "ocf_def_priv.h"
|
||||||
|
|
||||||
#define OCF_CHECK_NULL(p) ENV_BUG_ON(!(p))
|
#define OCF_CHECK_NULL(p) ENV_BUG_ON(!(p))
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ struct ocf_mpool *ocf_mpool_create(struct ocf_cache *cache,
|
|||||||
mpool->cache = cache;
|
mpool->cache = cache;
|
||||||
mpool->flags = flags;
|
mpool->flags = flags;
|
||||||
|
|
||||||
for (i = 0; i < min(ocf_mpool_max, mpool_max + 1); i++) {
|
for (i = 0; i < OCF_MIN(ocf_mpool_max, mpool_max + 1); i++) {
|
||||||
result = snprintf(name, sizeof(name), "%s_%u", name_perfix,
|
result = snprintf(name, sizeof(name), "%s_%u", name_perfix,
|
||||||
(1 << i));
|
(1 << i));
|
||||||
if (result < 0 || result >= sizeof(name))
|
if (result < 0 || result >= sizeof(name))
|
||||||
|
@ -60,7 +60,7 @@ static inline uint64_t ocf_bytes_2_lines(struct ocf_cache *cache,
|
|||||||
static inline uint64_t ocf_bytes_2_lines_round_up(
|
static inline uint64_t ocf_bytes_2_lines_round_up(
|
||||||
struct ocf_cache *cache, uint64_t bytes)
|
struct ocf_cache *cache, uint64_t bytes)
|
||||||
{
|
{
|
||||||
return DIV_ROUND_UP(bytes, ocf_line_size(cache));
|
return OCF_DIV_ROUND_UP(bytes, ocf_line_size(cache));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint64_t ocf_lines_2_bytes(struct ocf_cache *cache,
|
static inline uint64_t ocf_lines_2_bytes(struct ocf_cache *cache,
|
||||||
|
@ -92,7 +92,7 @@ int ocf_submit_obj_discard_wait(ocf_data_obj_t obj, uint64_t addr,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = min(length, max_length);
|
bytes = OCF_MIN(length, max_length);
|
||||||
|
|
||||||
env_atomic_inc(&cntx.req_remaining);
|
env_atomic_inc(&cntx.req_remaining);
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ int ocf_submit_write_zeroes_wait(ocf_data_obj_t obj, uint64_t addr,
|
|||||||
while (length) {
|
while (length) {
|
||||||
env_completion_init(&cntx.complete);
|
env_completion_init(&cntx.complete);
|
||||||
|
|
||||||
bytes = MIN(length, max_length);
|
bytes = OCF_MIN(length, max_length);
|
||||||
|
|
||||||
ocf_io_configure(io, addr, bytes, OCF_WRITE, 0, 0);
|
ocf_io_configure(io, addr, bytes, OCF_WRITE, 0, 0);
|
||||||
ocf_io_set_cmpl(io, &cntx, NULL,
|
ocf_io_set_cmpl(io, &cntx, NULL,
|
||||||
|
@ -253,7 +253,7 @@ struct ocf_request *ocf_req_new_discard(struct ocf_cache *cache,
|
|||||||
struct ocf_request *req;
|
struct ocf_request *req;
|
||||||
|
|
||||||
req = ocf_req_new_extended(cache, core_id, addr,
|
req = ocf_req_new_extended(cache, core_id, addr,
|
||||||
MIN(bytes, MAX_TRIM_RQ_SIZE),rw);
|
OCF_MIN(bytes, MAX_TRIM_RQ_SIZE),rw);
|
||||||
|
|
||||||
if (!req)
|
if (!req)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -56,8 +56,6 @@ typedef uint64_t sector_t;
|
|||||||
#define ENV_MEM_NOIO 1
|
#define ENV_MEM_NOIO 1
|
||||||
#define ENV_MEM_ATOMIC 2
|
#define ENV_MEM_ATOMIC 2
|
||||||
|
|
||||||
#define min(x, y) MIN(x, y)
|
|
||||||
|
|
||||||
#define ENV_WARN(cond, fmt, args...) ({})
|
#define ENV_WARN(cond, fmt, args...) ({})
|
||||||
|
|
||||||
#define ENV_WARN_ON(cond) ({ \
|
#define ENV_WARN_ON(cond) ({ \
|
||||||
|
Loading…
Reference in New Issue
Block a user