[IMPROVE] ARM: workaround for already running
[kernel/swap-modules.git] / energy / tm_stat.h
1 #ifndef _TM_STAT_H
2 #define _TM_STAT_H
3
4 /*
5  *  Dynamic Binary Instrumentation Module based on KProbes
6  *  energy/tm_stat.h
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  * Copyright (C) Samsung Electronics, 2013
23  *
24  * 2013         Vyacheslav Cherkashin <v.cherkashin@samsung.com>
25  *
26  */
27
28
29 #include <linux/types.h>
30 #include <linux/time.h>
31
32
33 struct tm_stat {
34         u64 timestamp;
35         u64 running;
36 };
37
38
39 #define DEFINE_TM_STAT(tm_name)         \
40         struct tm_stat tm_name = {      \
41                 .timestamp = 0,         \
42                 .running = 0            \
43         }
44
45
46 static inline u64 get_ntime(void)
47 {
48         struct timespec ts;
49         getnstimeofday(&ts);
50         return timespec_to_ns(&ts);
51 }
52
53 static inline void tm_stat_init(struct tm_stat *tm)
54 {
55         tm->timestamp = 0;
56         tm->running = 0;
57 }
58
59 static inline void tm_stat_set_timestamp(struct tm_stat *tm, u64 time)
60 {
61         tm->timestamp = time;
62 }
63
64 static inline u64 tm_stat_timestamp(struct tm_stat *tm)
65 {
66         return tm->timestamp;
67 }
68
69 static inline void tm_stat_update(struct tm_stat *tm, u64 time)
70 {
71         tm->running += time - tm->timestamp;
72 }
73
74 static inline u64 tm_stat_running(struct tm_stat *tm)
75 {
76         return tm->running;
77 }
78
79 static inline u64 tm_stat_current_running(struct tm_stat *tm, u64 now)
80 {
81         if (unlikely(now < tm->timestamp))
82                 printk("XXX %p WARNING now(%llu) < tmstmp(%llu)\n",
83                        tm, now, tm->timestamp);
84         return tm->timestamp ? tm->running + now - tm->timestamp: tm->running;
85 }
86
87 #endif /* _TM_STAT_H */