Multiple open operations on the input device

Source: Internet
Author: User

These two days in the study of Linux input-polldev.c, which is a new architecture provided by kernel, the architecture based on the original Linux input subsystem, added a layer of polling device encapsulation outside the input device. This architecture allows us to register a poll-Dev. We only need to provide this poll-dev with a polling interval and a polling callback function, then the system registers an input device for us and starts polling when we open the input device (when the polling time is greater than 0 ), after the round robin starts, the callback function we mentioned above will be called according to the set interval. When the input device is disabled, the call will be automatically terminated. In addition, this architecture also creates some sys-Fs nodes. One of the more useful ones is the poll node. We can cat this node to get the current polling frequency, you can also echo a value to update the polling frequency. In short, this is more convenient and direct than creating a polling system.

In researchCodeIt is also found that when the poll-Dev-based input device is opened, the open function of the polling device is also called (for the code, see the input_open_polled_device function. Of course, the premise is that you provide your own OPEN function when registering poll-Dev), because the mma8452q driver is currently in progress, so I think, in order to save power, I want the poll-Dev-based input device to provide 8452 power when it is turned on and 8452 power when it is turned off. Therefore, you can implement an open and close function by yourself, and assign the Open and Close pointers to the input_polled_dev object before registering poll-Dev.

This idea is good, but it is strange that I found that my open function was called only once after Android was started, and there was no indication that close was called. To confirm this problem. I wrote a test application myself.ProgramIn this test, I will open/dev/input/event2. twice in a row .. However, I still see that the open hanging in poll-Dev is called only once at the first open/dev/input/event2, similarly, when I call close/dev/input/event2 twice, I only saw that my corresponding close was called in the last call.

In this case, for the input device, its open function may be called only when the device is open for the first time. c. Check it. In the input_open_device () function, we can see that. Only the OPEN function of the input device corresponding to the first open input device is called. If an input device is opened multiple times later, the users of the input device can only be auto-incremented, instead of calling the OPEN function.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.