Skip to content

Commit 5e515ea

Browse files
committed
chore: doubled checked input_handler lag measurements
1 parent bc62542 commit 5e515ea

4 files changed

Lines changed: 1030 additions & 1042 deletions

File tree

TWO_IMPLEMENTATIONS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ that your mouse has.
1616
The new driver has general compatibility with the mice that linux already supports.
1717
In exchange it has 'more' lag than the old driver. Inconsequentially more. See the plot.
1818

19-
![Screenshot_2024-08-10_02-47-37](https://github.com/user-attachments/assets/def3a9d0-2bf3-401e-960c-b299592d1658)
19+
![Screenshot_2024-08-10_21-18-10](https://github.com/user-attachments/assets/2775d411-a3bb-40bc-a33d-b364debb3ed0)
2020

2121
We're talking microseconds here, so you have no reason to use the old driver.
2222
If, for some reason, you want to use the old driver and it supports your mouse. You can bind to it like so:

bench/Makefile

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
bench_driver: build
2-
bin/evdriverlag
2+
@bin/evdriverlag
33

44
bench_handler: build
5-
bin/evinputlag
5+
@bin/evinputlag
66

7-
build: evdriverlag.o evinputlag.o
8-
mkdir -p bin
9-
cc evdriverlag.o -o bin/evdriverlag
10-
cc evinputlag.o -o bin/evinputlag
11-
12-
evdriverlag.o: evdriverlag.c
13-
cc -c evdriverlag.c
14-
15-
evinputlag.o: evinputlag.c
16-
cc -c evinputlag.c
7+
build: evdriverlag.c evinputlag.c
8+
@mkdir -p bin
9+
@cc evdriverlag.c -o bin/evdriverlag
10+
@cc evinputlag.c -o bin/evinputlag
1711

1812
clean:
1913
rm *.o

bench/evinputlag.c

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
#include <sys/types.h>
55
#include <unistd.h>
66

7-
#define MOUSE_DEVICE "/dev/input/event2"
8-
9-
#define VIRTUAL_DEVICE "/dev/input/event9"
7+
#define VIRTUAL_DEVICE "/dev/input/event7"
108

119
static __suseconds_t to_us(struct timeval time) {
1210
return time.tv_sec * 1000000L + time.tv_usec;
@@ -16,21 +14,16 @@ static __suseconds_t to_us(struct timeval time) {
1614

1715
/**
1816
* NOTE: This benchmark depends on temporarily setting
19-
* maccel_filter from input_handler.h to return false
20-
* on EV_REL instead of true. So we can measure the original
21-
* event time from the physical device's event.
17+
* maccel_filter from input_handler.h to inject ktime_t diff (in us)
18+
* between when the original event was received and the modified event was
19+
* reported, as the value of the REL_Z REL_ABS event. So we can measure the
20+
* extra lag from the input_handler. Assuming REL_Z, REL_ABS are only produced
21+
* as carriers of the extra lag measurement.
2222
*
2323
*/
2424

2525
int main(void) {
26-
// Open the source device
27-
int fd_source = open(MOUSE_DEVICE, O_RDONLY);
28-
if (fd_source < 0) {
29-
perror("Failed to open source device");
30-
return 1;
31-
}
32-
33-
int vfd_source = open(VIRTUAL_DEVICE, O_RDONLY);
26+
int fd_source = open(VIRTUAL_DEVICE, O_RDONLY);
3427
if (fd_source < 0) {
3528
perror("Failed to open virtual device");
3629
return 1;
@@ -40,35 +33,36 @@ int main(void) {
4033
int tidx = 0;
4134

4235
// Main loop to read, modify, and write events
43-
struct input_event sev;
44-
struct input_event vev;
45-
while (tidx < EVENT_TIME_PAIR_CNT &&
46-
read(vfd_source, &vev, sizeof(vev)) > 0) {
36+
struct input_event ev;
37+
while (tidx < EVENT_TIME_PAIR_CNT && read(fd_source, &ev, sizeof(ev)) > 0) {
4738
struct timeval now;
4839
gettimeofday(&now, NULL);
4940

50-
if (read(fd_source, &sev, sizeof(sev)) <= 0) {
51-
break;
41+
if (ev.type == EV_REL && (ev.code == 2 || ev.code == 3)) {
42+
/* fprintf(stderr, "EVENT: type %d, code %d, value %d\n", ev.type,
43+
* ev.code, */
44+
/* ev.value); */
45+
times[tidx++] = to_us(ev.time);
46+
times[tidx++] = to_us(now);
47+
times[tidx++] = ev.value;
5248
}
53-
54-
times[tidx++] = to_us(sev.time);
55-
times[tidx++] = to_us(vev.time);
56-
times[tidx++] = to_us(now);
5749
}
5850

5951
// Cleanup
6052
close(fd_source);
6153

6254
tidx = 0;
6355

64-
printf("event_time,virtual_event_time,read_time,diff\n"); // eve'ry is in us
56+
printf("event_time,read_time,naive_diff,extra_lag,diff\n"); // eve'ry is in us
6557
while (tidx < EVENT_TIME_PAIR_CNT) {
6658
__suseconds_t event_time = times[tidx++];
67-
__suseconds_t virtual_event_time = times[tidx++];
6859
__suseconds_t read_time = times[tidx++];
60+
__suseconds_t extra_lag_measured_by_input_handler = times[tidx++];
6961

70-
printf("%lu,%lu,%lu,%lu\n", event_time, virtual_event_time, read_time,
71-
read_time - event_time);
62+
__suseconds_t diff = read_time - event_time;
63+
printf("%lu,%lu,%lu,%lu,%lu\n", event_time, read_time, diff,
64+
extra_lag_measured_by_input_handler,
65+
diff + extra_lag_measured_by_input_handler);
7266
}
7367

7468
return 0;

0 commit comments

Comments
 (0)