Motr  M0
misc.c File Reference
#include "lib/types.h"
#include "lib/assert.h"
#include "lib/arith.h"
#include "lib/string.h"
#include "lib/errno.h"
#include "lib/buf.h"
#include "lib/trace.h"
Include dependency graph for misc.c:

Go to the source code of this file.

Enumerations

enum  { M0_MOD_SAFE_LIMIT = UINT64_MAX/32 }
 

Functions

void __dummy_function (void)
 
 M0_BASSERT (sizeof(struct m0_uint128)==16)
 
M0_INTERNAL bool m0_uint128_eq (const struct m0_uint128 *u0, const struct m0_uint128 *u1)
 
M0_INTERNAL int m0_uint128_cmp (const struct m0_uint128 *u0, const struct m0_uint128 *u1)
 
M0_INTERNAL int m0_uint128_sscanf (const char *s, struct m0_uint128 *u128)
 
M0_INTERNAL void m0_uint128_add (struct m0_uint128 *res, const struct m0_uint128 *a, const struct m0_uint128 *b)
 
M0_INTERNAL void m0_uint128_mul64 (struct m0_uint128 *res, uint64_t a, uint64_t b)
 
uint64_t m0_rnd64 (uint64_t *prev)
 
uint64_t m0_rnd (uint64_t max, uint64_t *prev)
 
M0_INTERNAL uint64_t m0_gcd64 (uint64_t p, uint64_t q)
 
static uint64_t m0u64 (const unsigned char *s)
 
M0_INTERNAL void m0_uint128_init (struct m0_uint128 *u128, const char *magic)
 
static int64_t getdelta (uint64_t x0, uint64_t x1)
 
M0_INTERNAL bool m0_mod_gt (uint64_t x0, uint64_t x1)
 
M0_INTERNAL bool m0_mod_ge (uint64_t x0, uint64_t x1)
 
M0_INTERNAL uint64_t m0_round_up (uint64_t val, uint64_t size)
 
M0_INTERNAL uint64_t m0_round_down (uint64_t val, uint64_t size)
 
 M0_BASSERT (ergo(false, false)==true)
 
 M0_BASSERT (ergo(false, true)==true)
 
 M0_BASSERT (ergo(true, false)==false)
 
 M0_BASSERT (ergo(true, true)==true)
 
 M0_BASSERT (equi(false, false)==true)
 
 M0_BASSERT (equi(false, true)==false)
 
 M0_BASSERT (equi(true, false)==false)
 
 M0_BASSERT (equi(true, true)==true)
 
M0_INTERNAL const char * m0_bool_to_str (bool b)
 
M0_INTERNAL const char * m0_short_file_name (const char *fname)
 
M0_INTERNAL uint32_t m0_no_of_bits_set (uint64_t val)
 
M0_INTERNAL bool m0_elems_are_unique (const void *array, unsigned nr_elems, size_t elem_size)
 
M0_INTERNAL unsigned int m0_full_name_hash (const unsigned char *name, unsigned int len)
 
M0_INTERNAL uint64_t m0_ptr_wrap (const void *p)
 
M0_INTERNAL const void * m0_ptr_unwrap (uint64_t val)
 
M0_INTERNAL void m0_permute (uint64_t n, uint64_t *k, uint64_t *s, uint64_t *r)
 
M0_INTERNAL void m0_array_sort (uint64_t *arr, uint64_t arr_len)
 
M0_INTERNAL bool m0_bit_get (void *buffer, m0_bcount_t i)
 
M0_INTERNAL void m0_bit_set (void *buffer, m0_bcount_t i, bool val)
 
M0_INTERNAL bool m0_key_val_is_null (struct m0_key_val *kv)
 
M0_INTERNAL void m0_key_val_init (struct m0_key_val *kv, const struct m0_buf *key, const struct m0_buf *val)
 
M0_INTERNAL void m0_key_val_null_set (struct m0_key_val *kv)
 
M0_INTERNAL void * m0_vote_majority_get (struct m0_key_val *arr, uint32_t len, bool(*cmp)(const struct m0_buf *, const struct m0_buf *), uint32_t *vote_nr)
 
M0_INTERNAL uint64_t m0_dummy_id_generate (void)
 

Variables

M0_INTERNAL const char * m0_failed_condition
 
M0_INTERNAL const struct m0_key_val M0_KEY_VAL_NULL
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
M0_MOD_SAFE_LIMIT 

Definition at line 157 of file misc.c.

Function Documentation

◆ __dummy_function()

void __dummy_function ( void  )

Definition at line 32 of file misc.c.

◆ getdelta()

static int64_t getdelta ( uint64_t  x0,
uint64_t  x1 
)
static

Definition at line 161 of file misc.c.

Here is the caller graph for this function:

◆ m0_array_sort()

M0_INTERNAL void m0_array_sort ( uint64_t *  arr,
uint64_t  arr_len 
)

Sorts an array of integers in ascending order.

Definition at line 325 of file misc.c.

Here is the caller graph for this function:

◆ M0_BASSERT() [1/9]

M0_BASSERT ( sizeof(struct m0_uint128 = =16)

◆ M0_BASSERT() [2/9]

M0_BASSERT ( ergo(false, false)  = =true)

◆ M0_BASSERT() [3/9]

M0_BASSERT ( ergo(false, true)  = =true)

◆ M0_BASSERT() [4/9]

M0_BASSERT ( ergo(true, false)  = =false)

◆ M0_BASSERT() [5/9]

M0_BASSERT ( ergo(true, true)  = =true)

◆ M0_BASSERT() [6/9]

M0_BASSERT ( equi(false, false)  = =true)

◆ M0_BASSERT() [7/9]

M0_BASSERT ( equi(false, true)  = =false)

◆ M0_BASSERT() [8/9]

M0_BASSERT ( equi(true, false)  = =false)

◆ M0_BASSERT() [9/9]

M0_BASSERT ( equi(true, true)  = =true)

◆ m0_bit_get()

M0_INTERNAL bool m0_bit_get ( void *  buffer,
m0_bcount_t  i 
)

Get i-th bit value from the buffer.

Definition at line 340 of file misc.c.

Here is the caller graph for this function:

◆ m0_bit_set()

M0_INTERNAL void m0_bit_set ( void *  buffer,
m0_bcount_t  i,
bool  val 
)

Set i-th bit value in the buffer.

Definition at line 349 of file misc.c.

Here is the caller graph for this function:

◆ m0_bool_to_str()

M0_INTERNAL const char* m0_bool_to_str ( bool  b)

Definition at line 207 of file misc.c.

Here is the caller graph for this function:

◆ m0_dummy_id_generate()

M0_INTERNAL uint64_t m0_dummy_id_generate ( void  )

Generates process-uinque identifier. WARN: Atomic based.

Definition at line 425 of file misc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_elems_are_unique()

M0_INTERNAL bool m0_elems_are_unique ( const void *  array,
unsigned  nr_elems,
size_t  elem_size 
)

Definition at line 257 of file misc.c.

Here is the caller graph for this function:

◆ m0_full_name_hash()

M0_INTERNAL unsigned int m0_full_name_hash ( const unsigned char *  name,
unsigned int  len 
)

Definition at line 266 of file misc.c.

Here is the caller graph for this function:

◆ m0_key_val_init()

M0_INTERNAL void m0_key_val_init ( struct m0_key_val kv,
const struct m0_buf key,
const struct m0_buf val 
)

Initialises a key value pair.

Definition at line 369 of file misc.c.

Here is the caller graph for this function:

◆ m0_key_val_is_null()

M0_INTERNAL bool m0_key_val_is_null ( struct m0_key_val kv)

Returns true iff it's M0_KEY_VAL_NULL.

Definition at line 363 of file misc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_key_val_null_set()

M0_INTERNAL void m0_key_val_null_set ( struct m0_key_val kv)

Initialises a key to M0_KEY_VAL_NULL.

Definition at line 378 of file misc.c.

Here is the call graph for this function:

◆ m0_no_of_bits_set()

M0_INTERNAL uint32_t m0_no_of_bits_set ( uint64_t  val)

Definition at line 227 of file misc.c.

Here is the caller graph for this function:

◆ m0_permute()

M0_INTERNAL void m0_permute ( uint64_t  n,
uint64_t *  k,
uint64_t *  s,
uint64_t *  r 
)

Apply a permutation given by its Lehmer code in k[] to a set s[] of n elements and build inverse permutation in r[].

Parameters
n- number of elements in k[], s[] and r[]
k- Lehmer code of the permutation
s- an array to permute
r- an array to build inverse permutation in
Precondition
m0_forall(i, n, k[i] + i < n)
m0_forall(i, n, s[i] < n && ergo(s[i] == s[j], i == j))
Postcondition
m0_forall(i, n, s[i] < n && ergo(s[i] == s[j], i == j))
m0_forall(i, n, s[r[i]] == i && r[s[i]] == i)

Definition at line 288 of file misc.c.

Here is the caller graph for this function:

◆ m0_ptr_unwrap()

M0_INTERNAL const void* m0_ptr_unwrap ( uint64_t  val)

Definition at line 282 of file misc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_ptr_wrap()

M0_INTERNAL uint64_t m0_ptr_wrap ( const void *  p)

Converts Motr function pointer in a form that can be stored somewhere (e.g., in a trace log or addb2 record) and later decoded back into original pointer.

Such transformation is needed, because function pointers depend on the address at which Motr library is loaded.

Precondition
"p" must be a pointer to Motr executable code or NULL.

Definition at line 277 of file misc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_round_down()

M0_INTERNAL uint64_t m0_round_down ( uint64_t  val,
uint64_t  size 
)

Returns rounded down value of in chunks of .

Precondition
m0_is_po2(size)

Definition at line 187 of file misc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_round_up()

M0_INTERNAL uint64_t m0_round_up ( uint64_t  val,
uint64_t  size 
)

Returns rounded up value of in chunks of .

Precondition
m0_is_po2(size)

Definition at line 181 of file misc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_short_file_name()

M0_INTERNAL const char* m0_short_file_name ( const char *  fname)

Extracts the file name, relative to a motr sources directory, from a full-path file name. A motr source directory is detected by a name "motr/".

For example, given the following full-path file name:

/path/to/motr/lib/ut/finject.c

A short file name, relative to the "motr/" directory, is:

lib/ut/finject.c
Bug:
{ This function doesn't search for the rightmost occurrence of "motr/" in a file path, if "motr/" encounters several times in the path the first one will be picked up:
  /path/to/motr/fs/motr/lib/misc.h => fs/motr/lib/misc.h

}

Parameters
fnamefull path
Returns
short file name - a pointer inside fname string to the remaining file path, after motr source directory; if short file name cannot be found, then full fname is returned.

Definition at line 212 of file misc.c.

Here is the caller graph for this function:

◆ m0_uint128_add()

M0_INTERNAL void m0_uint128_add ( struct m0_uint128 res,
const struct m0_uint128 a,
const struct m0_uint128 b 
)

res = a + b;

Definition at line 62 of file misc.c.

Here is the caller graph for this function:

◆ m0_uint128_cmp()

M0_INTERNAL int m0_uint128_cmp ( const struct m0_uint128 u0,
const struct m0_uint128 u1 
)

Definition at line 45 of file misc.c.

Here is the caller graph for this function:

◆ m0_uint128_eq()

M0_INTERNAL bool m0_uint128_eq ( const struct m0_uint128 u0,
const struct m0_uint128 u1 
)

Definition at line 39 of file misc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_uint128_init()

M0_INTERNAL void m0_uint128_init ( struct m0_uint128 u128,
const char *  magic 
)

Definition at line 150 of file misc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_uint128_mul64()

M0_INTERNAL void m0_uint128_mul64 ( struct m0_uint128 res,
uint64_t  a,
uint64_t  b 
)

res = a * b;

Definition at line 76 of file misc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_uint128_sscanf()

M0_INTERNAL int m0_uint128_sscanf ( const char *  s,
struct m0_uint128 u128 
)

Scans uint128 in num:num format, where num can be in hex, octal or decimal format (depending on prefix).

Definition at line 51 of file misc.c.

◆ m0_vote_majority_get()

M0_INTERNAL void* m0_vote_majority_get ( struct m0_key_val arr,
uint32_t  len,
bool(*)(const struct m0_buf *, const struct m0_buf *)  cmp,
uint32_t *  vote_nr 
)

This API implements Boyer-Moore Voting Algorithm. Returns the majority element present in an input array. The majority element of an array, if present, is the element that occurs more than n/2 times in the array of length n. It has been assumed that members of the array can be compared for equality and method for the same needs to be provided by the user of the API. Returns null if there is no majority element.

Definition at line 383 of file misc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0u64()

static uint64_t m0u64 ( const unsigned char *  s)
static

Definition at line 140 of file misc.c.

Here is the caller graph for this function:

Variable Documentation

◆ m0_failed_condition

M0_INTERNAL const char* m0_failed_condition

Definition at line 224 of file misc.c.

◆ M0_KEY_VAL_NULL

M0_INTERNAL const struct m0_key_val M0_KEY_VAL_NULL
Initial value:
= {
.kv_key = M0_BUF_INIT0,
.kv_val = M0_BUF_INIT0,
}
#define M0_BUF_INIT0
Definition: buf.h:71

Definition at line 358 of file misc.c.