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