Skip to content

Commit 9609827

Browse files
bentissJiri Kosina
authored andcommitted
HID: multitouch: optimize the sticky fingers timer
Instead of unconditionally expiring the timer and calling a long mt_release_contacts(), we can check if some slots are used when the timer expires. We can also remove the timer if we happen to receive all the releases. The logic behind the MT_IO_FLAGS_PENDING_SLOTS could be implemented by counting how many slots are active, but using bits feels slightly more efficient. Signed-off-by: Benjamin Tissoires <[email protected]> Tested-by: Arek Burdach <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 4f4001b commit 9609827

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

drivers/hid/hid-multitouch.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ MODULE_LICENSE("GPL");
7979
#define MT_BUTTONTYPE_CLICKPAD 0
8080

8181
#define MT_IO_FLAGS_RUNNING 0
82+
#define MT_IO_FLAGS_ACTIVE_SLOTS 1
83+
#define MT_IO_FLAGS_PENDING_SLOTS 2
8284

8385
struct mt_slot {
8486
__s32 x, y, cx, cy, p, w, h;
@@ -705,6 +707,8 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
705707
input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
706708
input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
707709
input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
710+
711+
set_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
708712
}
709713
}
710714

@@ -720,6 +724,11 @@ static void mt_sync_frame(struct mt_device *td, struct input_dev *input)
720724
input_mt_sync_frame(input);
721725
input_sync(input);
722726
td->num_received = 0;
727+
if (test_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags))
728+
set_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
729+
else
730+
clear_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags);
731+
clear_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags);
723732
}
724733

725734
static int mt_touch_event(struct hid_device *hid, struct hid_field *field,
@@ -859,8 +868,13 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
859868
* only affect laggish machines and the ones that have a firmware
860869
* defect.
861870
*/
862-
if (td->mtclass.quirks & MT_QUIRK_STICKY_FINGERS)
863-
mod_timer(&td->release_timer, jiffies + msecs_to_jiffies(100));
871+
if (td->mtclass.quirks & MT_QUIRK_STICKY_FINGERS) {
872+
if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
873+
mod_timer(&td->release_timer,
874+
jiffies + msecs_to_jiffies(100));
875+
else
876+
del_timer(&td->release_timer);
877+
}
864878

865879
clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
866880
}
@@ -1210,7 +1224,8 @@ static void mt_expired_timeout(unsigned long arg)
12101224
*/
12111225
if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags))
12121226
return;
1213-
mt_release_contacts(hdev);
1227+
if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags))
1228+
mt_release_contacts(hdev);
12141229
clear_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
12151230
}
12161231

0 commit comments

Comments
 (0)