{"action":"created","issue":{"url":"https://api.github.com/repos/lkl/linux/issues/140","repository_url":"https://api.github.com/repos/lkl/linux","labels_url":"https://api.github.com/repos/lkl/linux/issues/140/labels{/name}","comments_url":"https://api.github.com/repos/lkl/linux/issues/140/comments","events_url":"https://api.github.com/repos/lkl/linux/issues/140/events","html_url":"https://github.com/lkl/linux/issues/140","id":144650928,"number":140,"title":"LKL uses 100% CPU after adding a network device","user":{"login":"tommie-lie","id":4471879,"avatar_url":"https://avatars.githubusercontent.com/u/4471879?v=3","gravatar_id":"","url":"https://api.github.com/users/tommie-lie","html_url":"https://github.com/tommie-lie","followers_url":"https://api.github.com/users/tommie-lie/followers","following_url":"https://api.github.com/users/tommie-lie/following{/other_user}","gists_url":"https://api.github.com/users/tommie-lie/gists{/gist_id}","starred_url":"https://api.github.com/users/tommie-lie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tommie-lie/subscriptions","organizations_url":"https://api.github.com/users/tommie-lie/orgs","repos_url":"https://api.github.com/users/tommie-lie/repos","events_url":"https://api.github.com/users/tommie-lie/events{/privacy}","received_events_url":"https://api.github.com/users/tommie-lie/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-03-30T16:51:38Z","updated_at":"2016-03-30T17:32:53Z","closed_at":null,"body":"I'm slightly puzzled by the fact that nobody else has already seen this issue which was introduced by 1f5a1affc6bd793f87a1bb13d41adaf7dd089eb9.\r\n\r\nThe semaphore `virtio_net_poll.sem` which served the purpose of blocking the poll thread while there really was nothing to do, was removed in the mentioned commit.\r\nAs a result, the poll thread that handles the tx queue issues a `poll()` call on the data stream descriptor (a tap device in case of virtio_net_tap) which immediately returns 99.9% of the time. If the tx queue is empty, `virtio_process_queue()` also returns immediately. As there is nothing else the loop does, it becomes a busy waiting loop and uses up one complete CPU core.\r\n\r\nSteps to reproduce:\r\nBuild current lkl master. Add `$(hijack_script} sleep 300` to `tools/lkl/tests/hijack-test.sh` in line 76 (after the LKL_HIJACK exports and the tap device initialization). Run `make test` and watch your htop for a sleep process.\r\n\r\nPartly reverting 1f5a1affc6bd793f87a1bb13d41adaf7dd089eb9 to restore the semaphore just caused another problem with the new eventfd closing mechanism: There is no way from `net_close()` in `virtio_net_tap.c` to access the poll queue data structure and increment the semaphore and `net_close()` is designed to be blocking until the threads joins.\r\n\r\nIf someone has a bright idea how to solve this elegantly, it'd be very welcome. I'll investigate further."},"comment":{"url":"https://api.github.com/repos/lkl/linux/issues/comments/203542622","html_url":"https://github.com/lkl/linux/issues/140#issuecomment-203542622","issue_url":"https://api.github.com/repos/lkl/linux/issues/140","id":203542622,"user":{"login":"tommie-lie","id":4471879,"avatar_url":"https://avatars.githubusercontent.com/u/4471879?v=3","gravatar_id":"","url":"https://api.github.com/users/tommie-lie","html_url":"https://github.com/tommie-lie","followers_url":"https://api.github.com/users/tommie-lie/followers","following_url":"https://api.github.com/users/tommie-lie/following{/other_user}","gists_url":"https://api.github.com/users/tommie-lie/gists{/gist_id}","starred_url":"https://api.github.com/users/tommie-lie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tommie-lie/subscriptions","organizations_url":"https://api.github.com/users/tommie-lie/orgs","repos_url":"https://api.github.com/users/tommie-lie/repos","events_url":"https://api.github.com/users/tommie-lie/events{/privacy}","received_events_url":"https://api.github.com/users/tommie-lie/received_events","type":"User","site_admin":false},"created_at":"2016-03-30T17:32:53Z","updated_at":"2016-03-30T17:32:53Z","body":"I'm sorry if I left the impression that your commit should be completely reverted, I'm sure it was necessary and the semaphore did behave strangely before.\r\n\r\nJust adding the semaphore to the tx poll thread definitely is enough, the rx thread behaves normally. There still the problem with the eventfd, though. I'm not convinced exposing `net_poll` to `lkl_netdev` is the nice thing to do. `net_poll` seems more like an implementation detail to me instead of an interface."}}