I am working on an embedded Linux system with kernel-5.10.24, and I want to send events to system by writing to /dev/input/eventX.
With my testing of sendevent (sendevent.c), the event injecting is NOT as quick as from real hardware.
I think it might be because the overhead to write each event to /dev/intput/eventX from user space to kernel.
So I am wondering if there is a quick way for user space to send events as quick as possible?


1 Answer 1


The slowness comes from followings.

  1. fork process to run sendevent command;
  2. open /dev/input/eventX - in sendevent_main()
  3. write event data to above file - in sendevent_main();
  4. close the file - in sendevent_main().

I got it faster by changing the sendevent_main() as follows.

  1. open /dev/input/eventX;
  2. open the file with a list of events;
  3. create a loop and do followings
    3.1 read the event one by one from above file
    3.2 write the event one by one to `/dev/input/eventX'
  4. close files.

So in above changes, the event read and write is done in a loop without overhead ofopen and close for each event as before.

With this change, it is much faster to send event to /dev/input/eventX.
But it brings in another problem, some events' behavior is NOT correct as expected. Is it sending event too fast to be handled by application?

I am still checking and changing the code, such as add usleep(10000) between event sending. But it goes back to the original slowness.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .