Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support input device hot-plugging and removal via udev #68

Merged
merged 2 commits into from
Nov 11, 2024

Conversation

shengwen-tw
Copy link
Collaborator

@shengwen-tw shengwen-tw commented Oct 31, 2024

Overview

udev (userspace /dev) is a device manager for the Linux kernel. By monitoring add and remove events from udev, we can dynamically update the event device file descriptors table to enable device hot-plugging and removal.

Prerequisites

To test the modified code, compile mado with the Linux framebuffer backend.

Test procedure

  1. Switch to a new virtual terminal (VT) by pressing Ctrl+Alt+Fn (e.g., Ctrl+Alt+F3) and then execute:
$ sudo ./demo-fbdev
  1. Test the new feature by unplugging and reconnecting the mouse.
  2. Return to the desktop environment with Ctrl+Alt+F1.

backend/linux_input.c Outdated Show resolved Hide resolved
@@ -170,6 +260,12 @@ void *twin_linux_input_create(twin_screen_t *screen)
twin_set_file(dummy, tm->fd, TWIN_READ, tm);
#endif

/* Start event handling thread */
if (pthread_create(&tm->udev_thread, NULL, twin_linux_udev_thread, tm)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you create yet another thread for event handling? Can you deal with udev in the existing thread?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We indeed require only one thread, the udev and evdev are now handled by one pollfd array.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent. You have discovered how effective I/O multiplexing can be for optimizing the code.

Makefile Show resolved Hide resolved
backend/linux_input.c Outdated Show resolved Hide resolved
@shengwen-tw shengwen-tw marked this pull request as ready for review November 3, 2024 09:18
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase the latest main branch and mention the dependent package libuuid in the top-level documentation.

README.md Outdated Show resolved Hide resolved
@jserv
Copy link
Contributor

jserv commented Nov 10, 2024

Have you tested the proposed changes with more than one mouse device?

udev (userspace /dev) is a device manager for the Linux kernel. By monitoring
"add" and "remove" events from udev, we can dynamically update the event device
file descriptors table to enable device hot-plugging and removal.

Close sysprog21#61
README.md Outdated
@@ -88,6 +88,9 @@ For the VNC backend, please note that it has only been tested on GNU/Linux, and
$ tools/build-neatvnc.sh
```

For Linux framebuffer backend, install `libudev`, and `libuuid`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary , (comma). That is,

For Linux framebuffer backend, install libudev and libuuid:

@shengwen-tw
Copy link
Collaborator Author

shengwen-tw commented Nov 10, 2024

I adjusted the change to prevent the event device thread from reopening all file descriptors whenever udev detects add or remove events, as the previous approach caused substantial lag. I then tested it with 1, 2, and 3 mouse setups to ensure functionality is correct.

@jserv jserv merged commit 22a6dea into sysprog21:main Nov 11, 2024
3 checks passed
@jserv
Copy link
Contributor

jserv commented Nov 11, 2024

Thank @shengwen-tw for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants