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
119static __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
2525int 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