ARTICLE AD BOX
Environment: Android16 with kernel6.6
There is an Android service runs a thread like this:
void *poll_thread(void *data) { int fd, ret; struct pollfd fds = {0}; fd = open(PROCFS_PATH, O_RDONLY); if (fd < 0) return NULL; fds.fd = fd; fds.events = POLLIN; while (1) { ALOGI("polling...\n"); ret = poll(&fds, 1, -1); if (ret < 0) goto out; ALOGI("revents:0x%x\n", fds.revents); if (fds.revents & POLLIN) do_sth(); } out: close(fd); return NULL; }PROCFS_PATH is created by kernel driver.
At the beginning, it runs well. But it become weird after the system suspend. This is the kernel log shows:
[ 11.753542] [01-01 00:00:10.753] node open. //printed by kernel driver //... [ 35.249622] [01-18 15:27:42.249] PM: suspend entry (s2idle) [ 35.345921] [01-18 15:27:42.345] Freezing user space processes [ 35.349896] [01-18 15:27:42.349] node release. //<---This is printed by kernel driver, which means the node has been closed. [ 35.362634] [01-18 15:27:42.362] Freezing user space processes completed (elapsed 0.016 seconds) [ 35.362662] [01-18 15:27:42.362] OOM killer disabled. [ 35.362675] [01-18 15:27:42.362] Freezing remaining freezable tasks [ 35.373758] [01-18 15:27:42.373] Freezing remaining freezable tasks completed (elapsed 0.011 seconds) //... [ 35.730977] [01-18 15:27:42.730] OOM killer enabled. [ 35.730992] [01-18 15:27:42.730] Restarting tasks ... [ 35.752943] [01-18 15:27:42.752] kernel suspend 1886ms [ 37.630601] [01-18 15:27:44.630] PM: suspend exitAfter suspend, poll return the revents:0x20, which means POLLNVAL. This is the Android logcat:
01-01 00:00:11.744 1290 1296 I POLL_THREAD : polling... //runs well //... 01-18 15:27:45.831 1290 1296 I POLL_THREAD : revents:0x20 01-18 15:27:45.831 1290 1296 I POLL_THREAD : polling... 01-18 15:27:45.831 1290 1296 I POLL_THREAD : revents:0x20 01-18 15:27:45.831 1290 1296 I POLL_THREAD : polling... 01-18 15:27:45.831 1290 1296 I POLL_THREAD : revents:0x20 01-18 15:27:45.831 1290 1296 I POLL_THREAD : polling... 01-18 15:27:45.831 1290 1296 I POLL_THREAD : revents:0x20 01-18 15:27:45.831 1290 1296 I POLL_THREAD : polling... 01-18 15:27:45.831 1290 1296 I POLL_THREAD : revents:0x20 01-18 15:27:45.831 1290 1296 I POLL_THREAD : polling... 01-18 15:27:45.831 1290 1296 I POLL_THREAD : revents:0x20 01-18 15:27:45.831 1290 1296 I POLL_THREAD : polling... 01-18 15:27:45.831 1290 1296 I POLL_THREAD : revents:0x20 01-18 15:27:45.831 1290 1296 I POLL_THREAD : polling... 01-18 15:27:45.831 1290 1296 I POLL_THREAD : revents:0x20 01-18 15:27:45.831 1290 1296 I POLL_THREAD : polling... 01-18 15:27:45.831 1290 1296 I POLL_THREAD : revents:0x20I wonder why the fd is being closed here? This situation has a low probability of occurring. Can anyone give me some hints?
Add driver code here:
static int my_open(struct inode *inode, struct file *filp) { pr_info("node open.\n"); return 0; } static int my_release(struct inode *inode, struct file *filp) { pr_info("node release.\n"); return 0; } static unsigned int my_poll(struct file *filp, poll_table *wait) { unsigned int mask = 0; poll_wait(filp, wait_queue, wait); if (condition) mask = POLLIN | POLLRDNORM; return mask; }