Skip to content

[Deepin-Kernel-SIG] [linux 6.6.y] [deepin] Input: evdev - Modify the process of closing the evdev device to use …#1636

Open
opsiff wants to merge 1 commit intodeepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-04-17-evdev
Open

[Deepin-Kernel-SIG] [linux 6.6.y] [deepin] Input: evdev - Modify the process of closing the evdev device to use …#1636
opsiff wants to merge 1 commit intodeepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-04-17-evdev

Conversation

@opsiff
Copy link
Copy Markdown
Member

@opsiff opsiff commented Apr 17, 2026

…the synchronize_rcu_expedited interface to speed up the shutdown process.

deepin inclusion
categroy: performace

As Documentations saied:
synchronize_rcu_expedited() instead
of synchronize_rcu(). This reduces latency,
but can increase CPU utilization, degrade
real-time latency, and degrade energy efficiency.
use it to optimize the shutdown process by
our system developer report where some input dev shutdown cost many XXms.
With the patched kernel, shutdown cost time from 5.96 to 5.11.

Tested-by: qiancheng qiancheng@uniontech.com

Summary by Sourcery

Enhancements:

  • Conditionally use synchronize_rcu_expedited() instead of synchronize_rcu() during evdev client cleanup when the system is halting, powering off, or restarting to reduce shutdown latency.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 17, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR adjusts the evdev client detach path to use synchronize_rcu_expedited() instead of synchronize_rcu() during system halt, power-off, or restart, in order to reduce shutdown latency while preserving the normal synchronize_rcu() behavior in all other runtime cases.

Sequence diagram for evdev_detach_client RCU synchronization on shutdown

sequenceDiagram
    participant Caller
    participant evdev as evdev_detach_client
    participant RCU as RCU_subsystem
    Caller->>evdev: evdev_detach_client(evdev, client)
    evdev->>evdev: spin_lock(evdev->client_lock)
    evdev->>evdev: list_del_rcu(client->node)
    evdev->>evdev: spin_unlock(evdev->client_lock)
    alt system_state is SYSTEM_HALT or SYSTEM_POWER_OFF or SYSTEM_RESTART
        evdev->>RCU: synchronize_rcu_expedited()
        RCU-->>evdev: expedited grace period complete
    else system_state is any other state
        evdev->>RCU: synchronize_rcu()
        RCU-->>evdev: normal grace period complete
    end
    evdev-->>Caller: detach complete
Loading

Flow diagram for conditional RCU synchronization in evdev_detach_client

flowchart TD
    A["Start evdev_detach_client"] --> B["Acquire client_lock spinlock"]
    B --> C["Remove client from list with list_del_rcu"]
    C --> D["Release client_lock spinlock"]
    D --> E{system_state}
    E -->|SYSTEM_HALT| F["Call synchronize_rcu_expedited"]
    E -->|SYSTEM_POWER_OFF| F
    E -->|SYSTEM_RESTART| F
    E -->|Any other state| G["Call synchronize_rcu"]
    F --> H["RCU grace period completed"]
    G --> H
    H --> I["Return from evdev_detach_client"]
Loading

File-Level Changes

Change Details Files
Optimize evdev client-detach RCU grace-period waiting during system shutdown sequences to reduce input device shutdown latency.
  • Replace the unconditional synchronize_rcu() call after removing an evdev client from the RCU list with a conditional that checks the global system_state.
  • Invoke synchronize_rcu_expedited() when system_state indicates SYSTEM_HALT, SYSTEM_POWER_OFF, or SYSTEM_RESTART to shorten the grace period during shutdown.
  • Fallback to the original synchronize_rcu() behavior when the system is in any other state to avoid the higher CPU/latency overhead of expedited RCU in normal operation.
drivers/input/evdev.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot deepin-ci-robot requested review from Wenlp and shy129 April 17, 2026 08:06
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from opsiff. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

…the synchronize_rcu_expedited interface to speed up the shutdown process.

deepin inclusion
categroy: performace

As Documentations saied:
	synchronize_rcu_expedited() instead
	of synchronize_rcu().  This reduces latency,
	but can increase CPU utilization, degrade
	real-time latency, and degrade energy efficiency.
use it to optimize the shutdown process by
our system developer report where some input dev shutdown
cost many XXms.
With the patched kernel, shutdown cost time from 5.96 to 5.11.

Tested-by: qiancheng <qiancheng@uniontech.com>
Signed-off-by: huangbibo <huangbibo@uniontech.com>
Signed-off-by: tuhaowen <tuhaowen@uniontech.com>
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
@opsiff opsiff force-pushed the linux-6.6.y-2026-04-17-evdev branch from a320522 to bfaaaf8 Compare April 17, 2026 08:08
Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The repeated system_state checks can be simplified by using an existing helper like in_shutdown() (if available in this kernel) or a small static inline helper, which will make the intent clearer and reduce duplication.
  • Given the higher cost of synchronize_rcu_expedited(), it would be worth briefly confirming that evdev_detach_client() is only called a small, bounded number of times during shutdown so this change doesn’t introduce unnecessary CPU spikes in that path.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The repeated `system_state` checks can be simplified by using an existing helper like `in_shutdown()` (if available in this kernel) or a small static inline helper, which will make the intent clearer and reduce duplication.
- Given the higher cost of `synchronize_rcu_expedited()`, it would be worth briefly confirming that `evdev_detach_client()` is only called a small, bounded number of times during shutdown so this change doesn’t introduce unnecessary CPU spikes in that path.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes evdev client teardown during system shutdown by switching from a normal RCU grace-period wait to an expedited one when the kernel is halting, powering off, or restarting, reducing shutdown latency in the input stack.

Changes:

  • Update evdev_detach_client() to call synchronize_rcu_expedited() when system_state is SYSTEM_HALT, SYSTEM_POWER_OFF, or SYSTEM_RESTART.
  • Preserve existing behavior (synchronize_rcu()) during normal runtime.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

3 participants