diff options
author | Thomas Bertschinger <tahbertschinger@gmail.com> | 2024-01-15 23:41:02 -0700 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-01-16 01:47:05 -0500 |
commit | f5baaf48e3e82b1caf9f5cd1207d4d6feba3a2e5 (patch) | |
tree | 59f7b0e4667df7a9d3d5a45725f2aaab3e79b4c5 /c_src/include/linux/jiffies.h | |
parent | fb35dbfdc5a9446fbb856dae5542b23963e28b89 (diff) |
move Rust sources to top level, C sources into c_src
This moves the Rust sources out of rust_src/ and into the top level.
Running the bcachefs executable out of the development tree is now:
$ ./target/release/bcachefs command
or
$ cargo run --profile release -- command
instead of "./bcachefs command".
Building and installing is still:
$ make && make install
Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'c_src/include/linux/jiffies.h')
-rw-r--r-- | c_src/include/linux/jiffies.h | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/c_src/include/linux/jiffies.h b/c_src/include/linux/jiffies.h new file mode 100644 index 00000000..d16ea76f --- /dev/null +++ b/c_src/include/linux/jiffies.h @@ -0,0 +1,91 @@ +#ifndef _LINUX_JIFFIES_H +#define _LINUX_JIFFIES_H + +#include <time.h> +#include <linux/kernel.h> +#include <linux/time64.h> +#include <linux/typecheck.h> +#include <linux/types.h> + +#define time_after(a,b) \ + (typecheck(unsigned long, a) && \ + typecheck(unsigned long, b) && \ + ((long)((b) - (a)) < 0)) +#define time_before(a,b) time_after(b,a) + +#define time_after_eq(a,b) \ + (typecheck(unsigned long, a) && \ + typecheck(unsigned long, b) && \ + ((long)((a) - (b)) >= 0)) +#define time_before_eq(a,b) time_after_eq(b,a) + +#define time_in_range(a,b,c) \ + (time_after_eq(a,b) && \ + time_before_eq(a,c)) + +#define time_in_range_open(a,b,c) \ + (time_after_eq(a,b) && \ + time_before(a,c)) + +#define time_after64(a,b) \ + (typecheck(__u64, a) && \ + typecheck(__u64, b) && \ + ((__s64)((b) - (a)) < 0)) +#define time_before64(a,b) time_after64(b,a) + +#define time_after_eq64(a,b) \ + (typecheck(__u64, a) && \ + typecheck(__u64, b) && \ + ((__s64)((a) - (b)) >= 0)) +#define time_before_eq64(a,b) time_after_eq64(b,a) + +#define time_in_range64(a, b, c) \ + (time_after_eq64(a, b) && \ + time_before_eq64(a, c)) + +#define time_is_before_jiffies(a) time_after(jiffies, a) + +#define HZ 1000 + +static inline u64 jiffies_to_nsecs(const unsigned long j) +{ + return (u64)j * NSEC_PER_MSEC; +} + +static inline unsigned jiffies_to_msecs(const unsigned long j) +{ + return j; +} + +static inline unsigned long msecs_to_jiffies(const unsigned int m) +{ + return m; +} + +static inline unsigned long nsecs_to_jiffies(u64 n) +{ + return n / NSEC_PER_MSEC; +} + +static inline u64 sched_clock(void) +{ + struct timespec ts; + + clock_gettime(CLOCK_MONOTONIC_COARSE, &ts); + + return ((s64) ts.tv_sec * NSEC_PER_SEC) + ts.tv_nsec; +} + +static inline u64 local_clock(void) +{ + return sched_clock(); +} + +static inline u64 ktime_get_ns(void) +{ + return sched_clock(); +} + +#define jiffies nsecs_to_jiffies(sched_clock()) + +#endif |