aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2012-09-15 09:23:35 -0400
committerHenrik Rydberg <rydberg@euromail.se>2012-09-19 13:50:18 -0400
commit4369c64c79a22b98d3b7eff9d089196cd878a10a (patch)
tree8194f7190e5beffdfea3826725b393a9c48e64cc
parent352ac4bd018005cfa6f844433a98aa0b724fa8db (diff)
Input: Send events one packet at a time
On heavy event loads, such as a multitouch driver, the irqsoff latency can be as high as 250 us. By accumulating a frame worth of data before passing it on, the latency can be dramatically reduced. As a side effect, the special EV_SYN handling can be removed, since the frame is now atomic. This patch adds the events() handler callback and uses it if it exists. The latency is improved by 50 us even without the callback. Cc: Daniel Kurtz <djkurtz@chromium.org> Tested-by: Benjamin Tissoires <benjamin.tissoires@enac.fr> Tested-by: Ping Cheng <pingc@wacom.com> Tested-by: Sedat Dilek <sedat.dilek@gmail.com> Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
-rw-r--r--drivers/input/input.c176
-rw-r--r--include/linux/input.h24
2 files changed, 144 insertions, 56 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c
index fbe522d0ead7..5244f3d05b12 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -47,6 +47,8 @@ static DEFINE_MUTEX(input_mutex);
47 47
48static struct input_handler *input_table[8]; 48static struct input_handler *input_table[8];
49 49
50static const struct input_value input_value_sync = { EV_SYN, SYN_REPORT, 1 };
51
50static inline int is_event_supported(unsigned int code, 52static inline int is_event_supported(unsigned int code,
51 unsigned long *bm, unsigned int max) 53 unsigned long *bm, unsigned int max)
52{ 54{
@@ -90,46 +92,81 @@ static void input_stop_autorepeat(struct input_dev *dev)
90 * filtered out, through all open handles. This function is called with 92 * filtered out, through all open handles. This function is called with
91 * dev->event_lock held and interrupts disabled. 93 * dev->event_lock held and interrupts disabled.
92 */ 94 */
93static void input_pass_event(struct input_dev *dev, 95static unsigned int input_to_handler(struct input_handle *handle,
94 unsigned int type, unsigned int code, int value) 96 struct input_value *vals, unsigned int count)
95{ 97{
96 struct input_handler *handler; 98 struct input_handler *handler = handle->handler;
97 struct input_handle *handle; 99 struct input_value *end = vals;
100 struct input_value *v;
98 101
99 rcu_read_lock(); 102 for (v = vals; v != vals + count; v++) {
103 if (handler->filter &&
104 handler->filter(handle, v->type, v->code, v->value))
105 continue;
106 if (end != v)
107 *end = *v;
108 end++;
109 }
100 110
101 handle = rcu_dereference(dev->grab); 111 count = end - vals;
102 if (handle) 112 if (!count)
103 handle->handler->event(handle, type, code, value); 113 return 0;
104 else {
105 bool filtered = false;
106 114
107 list_for_each_entry_rcu(handle, &dev->h_list, d_node) { 115 if (handler->events)
108 if (!handle->open) 116 handler->events(handle, vals, count);
109 continue; 117 else if (handler->event)
118 for (v = vals; v != end; v++)
119 handler->event(handle, v->type, v->code, v->value);
120
121 return count;
122}
123
124/*
125 * Pass values first through all filters and then, if event has not been
126 * filtered out, through all open handles. This function is called with
127 * dev->event_lock held and interrupts disabled.
128 */
129static void input_pass_values(struct input_dev *dev,
130 struct input_value *vals, unsigned int count)
131{
132 struct input_handle *handle;
133 struct input_value *v;
110 134
111 handler = handle->handler; 135 if (!count)
112 if (!handler->filter) { 136 return;
113 if (filtered)
114 break;
115 137
116 handler->event(handle, type, code, value); 138 rcu_read_lock();
117 139
118 } else if (handler->filter(handle, type, code, value)) 140 handle = rcu_dereference(dev->grab);
119 filtered = true; 141 if (handle) {
120 } 142 count = input_to_handler(handle, vals, count);
143 } else {
144 list_for_each_entry_rcu(handle, &dev->h_list, d_node)
145 if (handle->open)
146 count = input_to_handler(handle, vals, count);
121 } 147 }
122 148
123 rcu_read_unlock(); 149 rcu_read_unlock();
124 150
151 add_input_randomness(vals->type, vals->code, vals->value);
152
125 /* trigger auto repeat for key events */ 153 /* trigger auto repeat for key events */
126 if (type == EV_KEY && value != 2) { 154 for (v = vals; v != vals + count; v++) {
127 if (value) 155 if (v->type == EV_KEY && v->value != 2) {
128 input_start_autorepeat(dev, code); 156 if (v->value)
129 else 157 input_start_autorepeat(dev, v->code);
130 input_stop_autorepeat(dev); 158 else
159 input_stop_autorepeat(dev);
160 }
131 } 161 }
162}
132 163
164static void input_pass_event(struct input_dev *dev,
165 unsigned int type, unsigned int code, int value)
166{
167 struct input_value vals[] = { { type, code, value } };
168
169 input_pass_values(dev, vals, ARRAY_SIZE(vals));
133} 170}
134 171
135/* 172/*
@@ -146,18 +183,12 @@ static void input_repeat_key(unsigned long data)
146 183
147 if (test_bit(dev->repeat_key, dev->key) && 184 if (test_bit(dev->repeat_key, dev->key) &&
148 is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) { 185 is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) {
186 struct input_value vals[] = {
187 { EV_KEY, dev->repeat_key, 2 },
188 input_value_sync
189 };
149 190
150 input_pass_event(dev, EV_KEY, dev->repeat_key, 2); 191 input_pass_values(dev, vals, ARRAY_SIZE(vals));
151
152 if (dev->sync) {
153 /*
154 * Only send SYN_REPORT if we are not in a middle
155 * of driver parsing a new hardware packet.
156 * Otherwise assume that the driver will send
157 * SYN_REPORT once it's done.
158 */
159 input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
160 }
161 192
162 if (dev->rep[REP_PERIOD]) 193 if (dev->rep[REP_PERIOD])
163 mod_timer(&dev->timer, jiffies + 194 mod_timer(&dev->timer, jiffies +
@@ -170,6 +201,8 @@ static void input_repeat_key(unsigned long data)
170#define INPUT_IGNORE_EVENT 0 201#define INPUT_IGNORE_EVENT 0
171#define INPUT_PASS_TO_HANDLERS 1 202#define INPUT_PASS_TO_HANDLERS 1
172#define INPUT_PASS_TO_DEVICE 2 203#define INPUT_PASS_TO_DEVICE 2
204#define INPUT_SLOT 4
205#define INPUT_FLUSH 8
173#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE) 206#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE)
174 207
175static int input_handle_abs_event(struct input_dev *dev, 208static int input_handle_abs_event(struct input_dev *dev,
@@ -216,14 +249,14 @@ static int input_handle_abs_event(struct input_dev *dev,
216 /* Flush pending "slot" event */ 249 /* Flush pending "slot" event */
217 if (is_mt_event && mt && mt->slot != input_abs_get_val(dev, ABS_MT_SLOT)) { 250 if (is_mt_event && mt && mt->slot != input_abs_get_val(dev, ABS_MT_SLOT)) {
218 input_abs_set_val(dev, ABS_MT_SLOT, mt->slot); 251 input_abs_set_val(dev, ABS_MT_SLOT, mt->slot);
219 input_pass_event(dev, EV_ABS, ABS_MT_SLOT, mt->slot); 252 return INPUT_PASS_TO_HANDLERS | INPUT_SLOT;
220 } 253 }
221 254
222 return INPUT_PASS_TO_HANDLERS; 255 return INPUT_PASS_TO_HANDLERS;
223} 256}
224 257
225static void input_handle_event(struct input_dev *dev, 258static int input_get_disposition(struct input_dev *dev,
226 unsigned int type, unsigned int code, int value) 259 unsigned int type, unsigned int code, int value)
227{ 260{
228 int disposition = INPUT_IGNORE_EVENT; 261 int disposition = INPUT_IGNORE_EVENT;
229 262
@@ -236,13 +269,9 @@ static void input_handle_event(struct input_dev *dev,
236 break; 269 break;
237 270
238 case SYN_REPORT: 271 case SYN_REPORT:
239 if (!dev->sync) { 272 disposition = INPUT_PASS_TO_HANDLERS | INPUT_FLUSH;
240 dev->sync = true;
241 disposition = INPUT_PASS_TO_HANDLERS;
242 }
243 break; 273 break;
244 case SYN_MT_REPORT: 274 case SYN_MT_REPORT:
245 dev->sync = false;
246 disposition = INPUT_PASS_TO_HANDLERS; 275 disposition = INPUT_PASS_TO_HANDLERS;
247 break; 276 break;
248 } 277 }
@@ -327,14 +356,48 @@ static void input_handle_event(struct input_dev *dev,
327 break; 356 break;
328 } 357 }
329 358
330 if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN) 359 return disposition;
331 dev->sync = false; 360}
361
362static void input_handle_event(struct input_dev *dev,
363 unsigned int type, unsigned int code, int value)
364{
365 int disposition;
366
367 disposition = input_get_disposition(dev, type, code, value);
332 368
333 if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event) 369 if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event)
334 dev->event(dev, type, code, value); 370 dev->event(dev, type, code, value);
335 371
336 if (disposition & INPUT_PASS_TO_HANDLERS) 372 if (!dev->vals)
337 input_pass_event(dev, type, code, value); 373 return;
374
375 if (disposition & INPUT_PASS_TO_HANDLERS) {
376 struct input_value *v;
377
378 if (disposition & INPUT_SLOT) {
379 v = &dev->vals[dev->num_vals++];
380 v->type = EV_ABS;
381 v->code = ABS_MT_SLOT;
382 v->value = dev->mt->slot;
383 }
384
385 v = &dev->vals[dev->num_vals++];
386 v->type = type;
387 v->code = code;
388 v->value = value;
389 }
390
391 if (disposition & INPUT_FLUSH) {
392 if (dev->num_vals >= 2)
393 input_pass_values(dev, dev->vals, dev->num_vals);
394 dev->num_vals = 0;
395 } else if (dev->num_vals >= dev->max_vals - 2) {
396 dev->vals[dev->num_vals++] = input_value_sync;
397 input_pass_values(dev, dev->vals, dev->num_vals);
398 dev->num_vals = 0;
399 }
400
338} 401}
339 402
340/** 403/**
@@ -362,7 +425,6 @@ void input_event(struct input_dev *dev,
362 if (is_event_supported(type, dev->evbit, EV_MAX)) { 425 if (is_event_supported(type, dev->evbit, EV_MAX)) {
363 426
364 spin_lock_irqsave(&dev->event_lock, flags); 427 spin_lock_irqsave(&dev->event_lock, flags);
365 add_input_randomness(type, code, value);
366 input_handle_event(dev, type, code, value); 428 input_handle_event(dev, type, code, value);
367 spin_unlock_irqrestore(&dev->event_lock, flags); 429 spin_unlock_irqrestore(&dev->event_lock, flags);
368 } 430 }
@@ -841,10 +903,12 @@ int input_set_keycode(struct input_dev *dev,
841 if (test_bit(EV_KEY, dev->evbit) && 903 if (test_bit(EV_KEY, dev->evbit) &&
842 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) && 904 !is_event_supported(old_keycode, dev->keybit, KEY_MAX) &&
843 __test_and_clear_bit(old_keycode, dev->key)) { 905 __test_and_clear_bit(old_keycode, dev->key)) {
906 struct input_value vals[] = {
907 { EV_KEY, old_keycode, 0 },
908 input_value_sync
909 };
844 910
845 input_pass_event(dev, EV_KEY, old_keycode, 0); 911 input_pass_values(dev, vals, ARRAY_SIZE(vals));
846 if (dev->sync)
847 input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
848 } 912 }
849 913
850 out: 914 out:
@@ -1426,6 +1490,7 @@ static void input_dev_release(struct device *device)
1426 input_ff_destroy(dev); 1490 input_ff_destroy(dev);
1427 input_mt_destroy_slots(dev); 1491 input_mt_destroy_slots(dev);
1428 kfree(dev->absinfo); 1492 kfree(dev->absinfo);
1493 kfree(dev->vals);
1429 kfree(dev); 1494 kfree(dev);
1430 1495
1431 module_put(THIS_MODULE); 1496 module_put(THIS_MODULE);
@@ -1846,6 +1911,11 @@ int input_register_device(struct input_dev *dev)
1846 if (dev->hint_events_per_packet < packet_size) 1911 if (dev->hint_events_per_packet < packet_size)
1847 dev->hint_events_per_packet = packet_size; 1912 dev->hint_events_per_packet = packet_size;
1848 1913
1914 dev->max_vals = max(dev->hint_events_per_packet, packet_size) + 2;
1915 dev->vals = kcalloc(dev->max_vals, sizeof(*dev->vals), GFP_KERNEL);
1916 if (!dev->vals)
1917 return -ENOMEM;
1918
1849 /* 1919 /*
1850 * If delay and period are pre-set by the driver, then autorepeating 1920 * If delay and period are pre-set by the driver, then autorepeating
1851 * is handled by the driver itself and we don't do it in input.c. 1921 * is handled by the driver itself and we don't do it in input.c.
diff --git a/include/linux/input.h b/include/linux/input.h
index 9da4f5796fd6..ba4874302939 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -1169,6 +1169,18 @@ struct ff_effect {
1169#include <linux/mod_devicetable.h> 1169#include <linux/mod_devicetable.h>
1170 1170
1171/** 1171/**
1172 * struct input_value - input value representation
1173 * @type: type of value (EV_KEY, EV_ABS, etc)
1174 * @code: the value code
1175 * @value: the value
1176 */
1177struct input_value {
1178 __u16 type;
1179 __u16 code;
1180 __s32 value;
1181};
1182
1183/**
1172 * struct input_dev - represents an input device 1184 * struct input_dev - represents an input device
1173 * @name: name of the device 1185 * @name: name of the device
1174 * @phys: physical path to the device in the system hierarchy 1186 * @phys: physical path to the device in the system hierarchy
@@ -1240,7 +1252,6 @@ struct ff_effect {
1240 * last user closes the device 1252 * last user closes the device
1241 * @going_away: marks devices that are in a middle of unregistering and 1253 * @going_away: marks devices that are in a middle of unregistering and
1242 * causes input_open_device*() fail with -ENODEV. 1254 * causes input_open_device*() fail with -ENODEV.
1243 * @sync: set to %true when there were no new events since last EV_SYN
1244 * @dev: driver model's view of this device 1255 * @dev: driver model's view of this device
1245 * @h_list: list of input handles associated with the device. When 1256 * @h_list: list of input handles associated with the device. When
1246 * accessing the list dev->mutex must be held 1257 * accessing the list dev->mutex must be held
@@ -1305,12 +1316,14 @@ struct input_dev {
1305 unsigned int users; 1316 unsigned int users;
1306 bool going_away; 1317 bool going_away;
1307 1318
1308 bool sync;
1309
1310 struct device dev; 1319 struct device dev;
1311 1320
1312 struct list_head h_list; 1321 struct list_head h_list;
1313 struct list_head node; 1322 struct list_head node;
1323
1324 unsigned int num_vals;
1325 unsigned int max_vals;
1326 struct input_value *vals;
1314}; 1327};
1315#define to_input_dev(d) container_of(d, struct input_dev, dev) 1328#define to_input_dev(d) container_of(d, struct input_dev, dev)
1316 1329
@@ -1371,6 +1384,9 @@ struct input_handle;
1371 * @event: event handler. This method is being called by input core with 1384 * @event: event handler. This method is being called by input core with
1372 * interrupts disabled and dev->event_lock spinlock held and so 1385 * interrupts disabled and dev->event_lock spinlock held and so
1373 * it may not sleep 1386 * it may not sleep
1387 * @events: event sequence handler. This method is being called by
1388 * input core with interrupts disabled and dev->event_lock
1389 * spinlock held and so it may not sleep
1374 * @filter: similar to @event; separates normal event handlers from 1390 * @filter: similar to @event; separates normal event handlers from
1375 * "filters". 1391 * "filters".
1376 * @match: called after comparing device's id with handler's id_table 1392 * @match: called after comparing device's id with handler's id_table
@@ -1407,6 +1423,8 @@ struct input_handler {
1407 void *private; 1423 void *private;
1408 1424
1409 void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value); 1425 void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
1426 void (*events)(struct input_handle *handle,
1427 const struct input_value *vals, unsigned int count);
1410 bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value); 1428 bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
1411 bool (*match)(struct input_handler *handler, struct input_dev *dev); 1429 bool (*match)(struct input_handler *handler, struct input_dev *dev);
1412 int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id); 1430 int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);