Home | History | Annotate | Download | only in linux
      1 #ifndef __ARCH_ARM_MACH_MSM_IDLE_STATS_DEVICE_H
      2 #define __ARCH_ARM_MACH_MSM_IDLE_STATS_DEVICE_H
      3 
      4 #include <linux/types.h>
      5 #include <linux/ioctl.h>
      6 
      7 #define MSM_IDLE_STATS_EVENT_NONE                     0
      8 #define MSM_IDLE_STATS_EVENT_BUSY_TIMER_EXPIRED       1
      9 #define MSM_IDLE_STATS_EVENT_BUSY_TIMER_EXPIRED_RESET 2
     10 #define MSM_IDLE_STATS_EVENT_COLLECTION_NEARLY_FULL   4
     11 #define MSM_IDLE_STATS_EVENT_COLLECTION_FULL          8
     12 #define MSM_IDLE_STATS_EVENT_IDLE_TIMER_EXPIRED      16
     13 
     14 /*
     15  * All time, timer, and time interval values are in units of
     16  * microseconds unless stated otherwise.
     17  */
     18 #define MSM_IDLE_STATS_NR_MAX_INTERVALS 200
     19 
     20 struct msm_idle_pulse {
     21 	__s64 busy_start_time;
     22 	__u32 busy_interval;
     23 	__u32 wait_interval;
     24 };
     25 
     26 struct msm_idle_read_stats {
     27 	__u32 event;
     28 	__s64 return_timestamp;
     29 	__u32 busy_timer_remaining;
     30 	__u32 nr_collected;
     31 	struct msm_idle_pulse pulse_chain[MSM_IDLE_STATS_NR_MAX_INTERVALS];
     32 };
     33 
     34 struct msm_idle_write_stats {
     35 	__u32 busy_timer;
     36 	__u32 next_busy_timer;
     37 	__u32 max_samples;
     38 };
     39 
     40 #define MSM_IDLE_STATS_IOC_MAGIC  0xD8
     41 #define MSM_IDLE_STATS_IOC_READ_STATS  \
     42 		_IOWR(MSM_IDLE_STATS_IOC_MAGIC, 1, struct msm_idle_read_stats)
     43 #define MSM_IDLE_STATS_IOC_WRITE_STATS  \
     44 		_IOWR(MSM_IDLE_STATS_IOC_MAGIC, 2, struct msm_idle_write_stats)
     45 
     46 #ifdef __KERNEL__
     47 #include <linux/hrtimer.h>
     48 #include <linux/mutex.h>
     49 #include <linux/miscdevice.h>
     50 
     51 struct msm_idle_stats_device {
     52 	const char *name;
     53 	void (*get_sample)(struct msm_idle_stats_device *device,
     54 		struct msm_idle_pulse *pulse);
     55 
     56 	struct miscdevice miscdev;
     57 	spinlock_t lock;
     58 	wait_queue_head_t wait;
     59 	struct list_head list;
     60 	struct hrtimer busy_timer;
     61 	ktime_t busy_timer_interval;
     62 	ktime_t idle_start;
     63 	ktime_t remaining_time;
     64 	__u32 max_samples;
     65 
     66 	struct msm_idle_read_stats *stats;
     67 	struct msm_idle_read_stats stats_vector[2];
     68 };
     69 
     70 int msm_idle_stats_register_device(struct msm_idle_stats_device *device);
     71 int msm_idle_stats_deregister_device(struct msm_idle_stats_device *device);
     72 void msm_idle_stats_prepare_idle_start(struct msm_idle_stats_device *device);
     73 void msm_idle_stats_abort_idle_start(struct msm_idle_stats_device *device);
     74 void msm_idle_stats_idle_start(struct msm_idle_stats_device *device);
     75 void msm_idle_stats_idle_end(struct msm_idle_stats_device *device,
     76 				struct msm_idle_pulse *pulse);
     77 void msm_idle_stats_update_event(struct msm_idle_stats_device *device,
     78 				__u32 event);
     79 #endif
     80 
     81 #endif  /* __ARCH_ARM_MACH_MSM_IDLE_STATS_DEVICE_H */
     82 
     83