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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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.

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
@@ -106,6 +106,7 @@ endif

ifeq ($(CONFIG_BACKEND_FBDEV), y)
BACKEND = fbdev
TARGET_LIBS += -ludev
Copy link
Contributor

Choose a reason for hiding this comment

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

Mention libudev-dev dependency in top-level document.

/* Open Linux udev (user space device manager) */
int udev_fd = twin_linux_udev_init(&udev, &mon);
if (udev_fd < 0) {
exit(2);
Copy link
Contributor

Choose a reason for hiding this comment

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

The exit call here seems too harsh. Even if the input event thread fails, other parts of Mado should continue running - this would allow programmers to see the error messages and diagnose what went wrong. Consider handling the failure more gracefully rather than terminating the entire program.

@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.

@jserv jserv requested a review from Bennctu November 6, 2024 17:56
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