[C++] 纯文本查看 复制代码
#define time_after(a,b) \
(typecheck(unsigned long, a) && \
typecheck(unsigned long, b) && \
((long)(b) - (long)(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) - (long)(b) >= 0))
#define time_before_eq(a,b) time_after_eq(b,a)
[C++] 纯文本查看 复制代码
#include <linux/config.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/time.h>
#include <linux/timer.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <linux/types.h>
#include <linux/spinlock.h>
#include <linux/interrupt.h>
#include <asm/hardirq.h>
int delay = HZ;
int jit_busy(char *buf, char **start, off_t offset, int len, int *eof, void *data)
{
unsigned long j0, j1;
j0 = jiffies;
j1 = j0 + delay;
while (time_before(jiffies, j1)) {
cpu_relax();
}
len = sprintf (buf, "%9li %9li\n", j0, j1);
*start = buf;
return len;
}
int __init jit_init(void)
{
create_proc_read_entry ("jitbusy", 0, NULL, jit_busy, NULL);
return 0;
}
void __exit jit_cleanup(void)
{
remove_proc_entry("currentime", NULL);
}
module_init (jit_init);
module_exit (jit_cleanup);