KMON - kmon core implementation ...
PATCH 2/4 KMON - kmon core implementation ...
This is the core implementation of the kmon interface.
Signed-off-by Davide Libenzi <[email protected]>
- Davide
include/linux/kmon.h new file +77 -0
@@ -0,0 +1,77 @@ +/* +* include/linux/kmon.h +* +* Copyright (C) 2007 Davide Libenzi <[email protected]> +* +*/ + +#ifndef _LINUX_KMON_H +#define _LINUX_KMON_H + +#define KMON_START _IO('K', 1) +#define KMON_STOP _IO('K', 2) +#define KMON_BUFFSIZE _IOR('K', 3, long) + + +#ifdef __KERNEL__ + +struct kmon_ring { +unsigned long head, tail; +unsigned long size; +void *data; +}; + +struct kmon_buffer { +void *data; +unsigned long size; +}; + +struct kmon_notifier { +struct list_head lnk; +void (*write)(struct kmon_notifier *,const struct kmon_buffer *,int ); +}; + +int kmon_ring_write (struct kmon_ring *rng,const struct kmon_buffer *kbuf,int n); +unsigned long kmon_ring_read (struct kmon_ring *rng,struct kmon_buffer *kbuf); +void kmon_ring_commit_read (struct kmon_ring *rng,unsigned long size); +int kmon_add_data (const void *data,unsigned long size); +void kmon_notify_add (struct kmon_notifier *knfy); +void kmon_notify_remove (struct kmon_notifier *knfy); +int kmon_setup (void ); +void kmon_cleanup (void ); + +unsigned long kmon_ring_avail (const struct kmon_ring *rng) +{ +return (rng->head - rng->tail) & (rng->size -1 ); +} + +static inline void kmon_put16 (unsigned char *buf,u16 v) +{ + *buf++ = (unsigned char ) v; + *buf = (unsigned char ) (v >>8 ); +} + +static inline void kmon_put32 (unsigned char *buf,u32 v) +{ + *buf++ = (unsigned char ) v; + *buf++ = (unsigned char ) (v >>8 ); + *buf++ = (unsigned char ) (v >>16 ); + *buf = (unsigned char ) (v >>24 ); +} + +static inline void kmon_put64 (unsigned char *buf,u64 v) +{ + *buf++ = (unsigned char ) v; + *buf++ = (unsigned char ) (v >>8 ); + *buf++ = (unsigned char ) (v >>16 ); + *buf++ = (unsigned char ) (v >>24 ); + *buf++ = (unsigned char ) (v >>32 ); + *buf++ = (unsigned char ) (v >>40 ); + *buf++ = (unsigned char ) (v >>48 ); + *buf = (unsigned char ) (v >>56 ); +} + +#endif /* __KERNEL__ */ + +#endif /* _LINUX_KMON_H */ +
drivers/char/kmon-dev.c new file +268 -0
268 lines not on this page · raw message
kernel/kmon.c new file +310 -0
310 lines not on this page · raw message
kernel/kmon-stats.c new file +62 -0
62 lines not on this page · raw message
include/linux/kmon-stats.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* include/linux/kmon-stats.h +* +* Copyright (C) 2007 Davide Libenzi <[email protected]> +* +*/ + +#ifndef _LINUX_KMON_STATS_H +#define _LINUX_KMON_STATS_H + +#define KMON_DT_TSKQUEUE 1 +#define KMON_DT_TSKDEQUEUE 2 +#define KMON_DT_TSKSWITCH 3 +#define KMON_DT_TSKWAKEUP 4 + +#ifdef __KERNEL__ + +#ifdef CONFIG_KMON + +void kmon_st_task_enqueue (struct task_struct *tsk); +void kmon_st_task_dequeue (struct task_struct *tsk); +void kmon_st_task_switch (struct task_struct *prev,struct task_struct *next); +void kmon_st_task_wakeup (struct task_struct *from,struct task_struct *to); + +#else /* CONFIG_KMON */ + +#define kmon_st_task_enqueue (p) do { } while (0) +#define kmon_st_task_dequeue (p) do { } while (0) +#define kmon_st_task_switch (p, n) do { } while (0) +#define kmon_st_task_wakeup (f, t) do { } while (0) + +#endif /* CONFIG_KMON */ + +#endif /* __KERNEL__ */ + +#endif /* _LINUX_KMON_STATS_H */ +