In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the Sinlinx A64 development board Linux kernel waiting queue poll what is blocking and non-blocking, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Development platform core Lingsi Sinlinx A64 memory: 1GB storage: 4GB development board detailed parameters https://m.tb.cn/h.3wMaSKm**
Blocking: blocking calls means that the current process is suspended (dormant) before the result of the call is returned. The function does not return until the result is obtained. By default, files are opened in this way. Non-blocking: this function does not block the current process but returns immediately until the result is not immediately available. The application can choose to open the device file in a blocking or non-blocking mode, and then the device reads and writes, which will be different if the read-write function of the driver supports blocking and non-blocking functions.
Blocking example: fd = open ("/ xxx/word", O_RDONLY); / / default blocking mode is enabled. If there is no data to read at this time, perform hibernation. If there is data to read, read the data immediately, do not sleep, and return immediately after reading the data. Non-blocking example: fd = open ("/ xxx/word", O_RDONLY | O_NONBLOCK); / / Open in non-blocking mode. If there is already data to read at this time, the data will be read and returned. If there is no data to read, return immediately, but return an error code.
1) how to get the way to open the user space application in the driver?
Open a device, the kernel will create a file structure, and the value of the open mode will be stored in the f_flags member of the file structure. The read,write interface of the driver can use the parameter file pointer to get the file opening mode. One member of the file structure is f_flags, and when created, the kernel stores the flag value of the last parameter of the open function in the f_flags variable.
Static ssize_t xxx_read (struct file * pfile, char user * buf, size_t count, loff_t * poff) {. / / determine whether there is a key action if (no key action) {/ / determine whether the pfile- > f_flags member sets O_NONBLOCK if (pfile- > f_flags & O_NONBLOCK) / / indicates that user space uses non-blocking to open {return-EAGAIN / / return an error code that tells the user space that you can try to read} / / open the blocking mode again, sleep if there is no data, do not immediately return to else {/ / hibernation, and wait for a key action to wake up the process. }}}
2) how do I know if there is a key press? If you press the key or release time, there will be an interrupt, so set a flag in the interrupt program. Define a global variable with an initial value of 0, indicating that no keystroke action has occurred. Set this variable to 1 in the interrupt program to indicate that a keystroke action has occurred.
3) how to put the process into hibernation? The simplest and most direct way to sleep: msleep function: once called, the calling process will sleep for a specified long time, and the kernel will wake up the process when the time is up. / / hibernate, waiting for a keystroke to wake up the process.
While (press = = 0) msleep (5); / / dormant 5ms about what is blocking and non-blocking in the Linux kernel waiting queue poll on the Sinlinx A64 development board. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.