Motr  M0
st_misc.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #pragma once
24 
25 #ifndef __MOTR_ST_ST_MISC_H__
26 #define __MOTR_ST_ST_MISC_H__
27 
28 #ifdef __KERNEL__
29 
30 # include <linux/kernel.h>
31 # include <linux/ctype.h>
32 # include <linux/string.h>
33 # include <linux/types.h>
34 
35 #define str_dup(s) kstrdup((s), GFP_KERNEL)
36 
37 /*
38  * syslog(8) will trim leading spaces of each kernel log line, so we need to use
39  * a non-space character at the beginning of each line to preserve formatting
40  */
41 
42 #define LOG_PREFIX "."
43 
44 #else
45 
46 # include <ctype.h>
47 # include <stdio.h>
48 # include <stdint.h>
49 # include <stdlib.h>
50 # include <string.h>
51 
52 #define str_dup(s) strdup((s))
53 
54 #define LOG_PREFIX
55 
56 #endif /* __KERNEL__ */
57 
58 #define str_eq(a, b) (strcmp((a), (b)) == 0)
59 
60 enum {
61  TIME_ONE_SECOND = 1000000000ULL,
63 };
64 
68 pid_t get_tid(void);
69 void console_printf(const char *fmt, ...);
70 uint32_t generate_random(uint32_t max);
71 
72 uint64_t time_now(void);
73 uint64_t time_from_now(uint64_t secs, uint64_t ns);
74 uint64_t time_seconds(const uint64_t time);
75 uint64_t time_nanoseconds(const uint64_t time);
76 
77 void *mem_alloc(size_t size);
78 void mem_free(void *p);
79 
80 #define MEM_ALLOC_ARR(arr, nr) ((arr) = mem_alloc((nr) * sizeof ((arr)[0])))
81 #define MEM_ALLOC_PTR(arr) MEM_ALLOC_ARR(arr, 1)
82 
83 #endif /* __MOTR_ST_ST_MISC_H__ */
static struct m0_addb2_philter p
Definition: consumer.c:40
void mem_free(void *p)
Definition: st_misc.c:113
uint64_t time_seconds(const uint64_t time)
Definition: st_misc.c:79
uint64_t time_from_now(uint64_t secs, uint64_t ns)
Definition: st_misc.c:89
static long long max(long long a, long long b)
Definition: crate.c:196
char * fmt(const char *format,...) __attribute__((format(printf
void * mem_alloc(size_t size)
Definition: st_misc.c:99
void console_printf(const char *fmt,...)
Definition: st_misc.c:155
uint32_t generate_random(uint32_t max)
Definition: st_misc.c:164
pid_t get_tid(void)
Definition: st_misc.c:150
m0_bcount_t size
Definition: di.c:39
uint64_t time_nanoseconds(const uint64_t time)
Definition: st_misc.c:84
uint64_t time_now(void)
Definition: st_misc.c:69