blob: 0b1ee39c1ed24b6d8f7b004804860e7d4c71868b [file] [log] [blame]
Lucille Sylvester20ec38a2011-09-14 10:51:28 -06001#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
13/*
14 * All time, timer, and time interval values are in units of
15 * microseconds unless stated otherwise.
16 */
17#define MSM_IDLE_STATS_NR_MAX_INTERVALS 200
18
19struct msm_idle_pulse {
20 __s64 busy_start_time;
21 __u32 busy_interval;
22 __u32 wait_interval;
23};
24
25struct msm_idle_read_stats {
26 __u32 event;
27 __s64 return_timestamp;
28 __u32 busy_timer_remaining;
29 __u32 nr_collected;
30 struct msm_idle_pulse pulse_chain[MSM_IDLE_STATS_NR_MAX_INTERVALS];
31};
32
33struct msm_idle_write_stats {
34 __u32 busy_timer;
35 __u32 next_busy_timer;
36};
37
38#define MSM_IDLE_STATS_IOC_MAGIC 0xD8
39#define MSM_IDLE_STATS_IOC_READ_STATS \
40 _IOWR(MSM_IDLE_STATS_IOC_MAGIC, 1, struct msm_idle_read_stats)
41#define MSM_IDLE_STATS_IOC_WRITE_STATS \
42 _IOWR(MSM_IDLE_STATS_IOC_MAGIC, 2, struct msm_idle_write_stats)
43
44#ifdef __KERNEL__
45#include <linux/hrtimer.h>
46#include <linux/mutex.h>
47#include <linux/miscdevice.h>
48
49struct msm_idle_stats_device {
50 const char *name;
51 void (*get_sample)(struct msm_idle_stats_device *device,
52 struct msm_idle_pulse *pulse);
53
54 struct miscdevice miscdev;
55 spinlock_t lock;
56 wait_queue_head_t wait;
57 struct list_head list;
58 struct hrtimer busy_timer;
59 ktime_t busy_timer_interval;
60 ktime_t idle_start;
61 ktime_t remaining_time;
62
63 struct msm_idle_read_stats *stats;
64 struct msm_idle_read_stats stats_vector[2];
65};
66
67int msm_idle_stats_register_device(struct msm_idle_stats_device *device);
68int msm_idle_stats_deregister_device(struct msm_idle_stats_device *device);
69void msm_idle_stats_prepare_idle_start(struct msm_idle_stats_device *device);
70void msm_idle_stats_abort_idle_start(struct msm_idle_stats_device *device);
71void msm_idle_stats_idle_start(struct msm_idle_stats_device *device);
72void msm_idle_stats_idle_end(struct msm_idle_stats_device *device,
73 struct msm_idle_pulse *pulse);
74#endif
75
76#endif /* __ARCH_ARM_MACH_MSM_IDLE_STATS_DEVICE_H */
77