diff options
Diffstat (limited to 'driver/gator_events_mmaped.c')
-rw-r--r-- | driver/gator_events_mmaped.c | 77 |
1 files changed, 55 insertions, 22 deletions
diff --git a/driver/gator_events_mmaped.c b/driver/gator_events_mmaped.c index cbb22b1..f81c402 100644 --- a/driver/gator_events_mmaped.c +++ b/driver/gator_events_mmaped.c | |||
@@ -14,11 +14,12 @@ | |||
14 | * <counter_set name="mmaped_cntX"> | 14 | * <counter_set name="mmaped_cntX"> |
15 | * <counter name="mmaped_cnt0"/> | 15 | * <counter name="mmaped_cnt0"/> |
16 | * <counter name="mmaped_cnt1"/> | 16 | * <counter name="mmaped_cnt1"/> |
17 | * <counter name="mmaped_cnt2"/> | ||
17 | * </counter_set> | 18 | * </counter_set> |
18 | * <category name="mmaped" counter_set="mmaped_cntX" per_cpu="no"> | 19 | * <category name="mmaped" counter_set="mmaped_cntX" per_cpu="no"> |
19 | * <event event="0x0" title="Simulated" name="Sine" description="Sort-of-sine"/> | 20 | * <event event="0x0" title="Simulated" name="Sine" display="maximum" average_selection="yes" description="Sort-of-sine"/> |
20 | * <event event="0x1" title="Simulated" name="Triangle" description="Triangular wave"/> | 21 | * <event event="0x1" title="Simulated" name="Triangle" display="maximum" average_selection="yes" description="Triangular wave"/> |
21 | * <event event="0x2" title="Simulated" name="PWM" description="PWM Signal"/> | 22 | * <event event="0x2" title="Simulated" name="PWM" display="maximum" average_selection="yes" description="PWM Signal"/> |
22 | * </category> | 23 | * </category> |
23 | */ | 24 | */ |
24 | 25 | ||
@@ -42,6 +43,10 @@ static int mmaped_buffer[MMAPED_COUNTERS_NUM * 2]; | |||
42 | static void __iomem *mmaped_base; | 43 | static void __iomem *mmaped_base; |
43 | #endif | 44 | #endif |
44 | 45 | ||
46 | #ifndef TODO | ||
47 | static s64 prev_time; | ||
48 | #endif | ||
49 | |||
45 | /* Adds mmaped_cntX directories and enabled, event, and key files to /dev/gator/events */ | 50 | /* Adds mmaped_cntX directories and enabled, event, and key files to /dev/gator/events */ |
46 | static int gator_events_mmaped_create_files(struct super_block *sb, | 51 | static int gator_events_mmaped_create_files(struct super_block *sb, |
47 | struct dentry *root) | 52 | struct dentry *root) |
@@ -77,6 +82,12 @@ static int gator_events_mmaped_start(void) | |||
77 | writel(ENABLED, COUNTERS_CONTROL_OFFSET); | 82 | writel(ENABLED, COUNTERS_CONTROL_OFFSET); |
78 | #endif | 83 | #endif |
79 | 84 | ||
85 | #ifndef TODO | ||
86 | struct timespec ts; | ||
87 | getnstimeofday(&ts); | ||
88 | prev_time = timespec_to_ns(&ts); | ||
89 | #endif | ||
90 | |||
80 | return 0; | 91 | return 0; |
81 | } | 92 | } |
82 | 93 | ||
@@ -90,50 +101,60 @@ static void gator_events_mmaped_stop(void) | |||
90 | #ifndef TODO | 101 | #ifndef TODO |
91 | /* This function "simulates" counters, generating values of fancy | 102 | /* This function "simulates" counters, generating values of fancy |
92 | * functions like sine or triangle... */ | 103 | * functions like sine or triangle... */ |
93 | static int mmaped_simulate(int counter) | 104 | static int mmaped_simulate(int counter, int delta_in_us) |
94 | { | 105 | { |
95 | int result = 0; | 106 | int result = 0; |
96 | 107 | ||
97 | switch (counter) { | 108 | switch (counter) { |
98 | case 0: /* sort-of-sine */ | 109 | case 0: /* sort-of-sine */ |
99 | { | 110 | { |
100 | static int t; | 111 | static int t = 0; |
101 | int x; | 112 | int x; |
102 | 113 | ||
103 | if (t % 1024 < 512) | 114 | t += delta_in_us; |
104 | x = 512 - (t % 512); | 115 | if (t > 2048000) |
116 | t = 0; | ||
117 | |||
118 | if (t % 1024000 < 512000) | ||
119 | x = 512000 - (t % 512000); | ||
105 | else | 120 | else |
106 | x = t % 512; | 121 | x = t % 512000; |
107 | 122 | ||
108 | result = 32 * x / 512; | 123 | result = 32 * x / 512000; |
109 | result = result * result; | 124 | result = result * result; |
110 | 125 | ||
111 | if (t < 1024) | 126 | if (t < 1024000) |
112 | result = 1922 - result; | 127 | result = 1922 - result; |
113 | |||
114 | t = (t + 1) % 2048; | ||
115 | } | 128 | } |
116 | break; | 129 | break; |
117 | case 1: /* triangle */ | 130 | case 1: /* triangle */ |
118 | { | 131 | { |
119 | static int v, d = 1; | 132 | static int v, d = 1; |
120 | 133 | ||
121 | v += d; | 134 | v = v + d * delta_in_us; |
122 | if (v % 2000 == 0) | 135 | if (v < 0) { |
123 | d = -d; | 136 | v = 0; |
137 | d = 1; | ||
138 | } else if (v > 1000000) { | ||
139 | v = 1000000; | ||
140 | d = -1; | ||
141 | } | ||
124 | 142 | ||
125 | result = v; | 143 | result = v; |
126 | } | 144 | } |
127 | break; | 145 | break; |
128 | case 2: /* PWM signal */ | 146 | case 2: /* PWM signal */ |
129 | { | 147 | { |
130 | static int t, dc; | 148 | static int t, dc, x; |
131 | 149 | ||
132 | t = (t + 1) % 2000; | 150 | t += delta_in_us; |
133 | if (t % 100) | 151 | if (t > 1000000) |
134 | dc = (dc + 200) % 2000; | 152 | t = 0; |
153 | if (x / 1000000 != (x + delta_in_us) / 1000000) | ||
154 | dc = (dc + 100000) % 1000000; | ||
155 | x += delta_in_us; | ||
135 | 156 | ||
136 | result = t < dc ? 0 : 2000; | 157 | result = t < dc ? 0 : 10; |
137 | } | 158 | } |
138 | break; | 159 | break; |
139 | } | 160 | } |
@@ -146,11 +167,23 @@ static int gator_events_mmaped_read(int **buffer) | |||
146 | { | 167 | { |
147 | int i; | 168 | int i; |
148 | int len = 0; | 169 | int len = 0; |
170 | #ifndef TODO | ||
171 | int delta_in_us; | ||
172 | struct timespec ts; | ||
173 | s64 time; | ||
174 | #endif | ||
149 | 175 | ||
150 | /* System wide counters - read from one core only */ | 176 | /* System wide counters - read from one core only */ |
151 | if (smp_processor_id()) | 177 | if (smp_processor_id()) |
152 | return 0; | 178 | return 0; |
153 | 179 | ||
180 | #ifndef TODO | ||
181 | getnstimeofday(&ts); | ||
182 | time = timespec_to_ns(&ts); | ||
183 | delta_in_us = (int)(time - prev_time) / 1000; | ||
184 | prev_time = time; | ||
185 | #endif | ||
186 | |||
154 | for (i = 0; i < MMAPED_COUNTERS_NUM; i++) { | 187 | for (i = 0; i < MMAPED_COUNTERS_NUM; i++) { |
155 | if (mmaped_counters[i].enabled) { | 188 | if (mmaped_counters[i].enabled) { |
156 | mmaped_buffer[len++] = mmaped_counters[i].key; | 189 | mmaped_buffer[len++] = mmaped_counters[i].key; |
@@ -159,7 +192,7 @@ static int gator_events_mmaped_read(int **buffer) | |||
159 | COUNTERS_VALUE_OFFSET[i]); | 192 | COUNTERS_VALUE_OFFSET[i]); |
160 | #else | 193 | #else |
161 | mmaped_buffer[len++] = mmaped_simulate( | 194 | mmaped_buffer[len++] = mmaped_simulate( |
162 | mmaped_counters[i].event); | 195 | mmaped_counters[i].event, delta_in_us); |
163 | #endif | 196 | #endif |
164 | } | 197 | } |
165 | } | 198 | } |