{"action":"created","comment":{"url":"https://api.github.com/repos/PX4/Firmware/pulls/comments/334010651","pull_request_review_id":300711543,"id":334010651,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDMzNDAxMDY1MQ==","diff_hunk":"@@ -100,62 +103,54 @@ void listener(listener_print_topic_cb cb, const orb_id_t &id, unsigned num_msgs,\n \t\tint sub = orb_subscribe_multi(id, topic_instance);\n \t\torb_set_interval(sub, topic_interval);\n \n-\t\tbool updated = false;\n \t\tunsigned i = 0;\n-\t\thrt_abstime start_time = hrt_absolute_time();\n \n \t\twhile (i < num_msgs) {\n \n-\t\t\t// check for user input to quit\n-\t\t\tint user_input_timeout = 1;\n-\n-\t\t\torb_check(sub, &updated);\n-\n-\t\t\tif (i == 0) {\n-\t\t\t\tupdated = true;\n-\t\t\t\tuser_input_timeout = 0;\t// don't wait\n-\t\t\t}\n-\n-\t\t\t// check for user input\n-\t\t\tstruct pollfd fds {};\n-\t\t\tfds.fd = 0; /* stdin */\n-\t\t\tfds.events = POLLIN;\n-\n-\t\t\tif (poll(&fds, 1, 0) > 0) {\n-\n-\t\t\t\tchar c = 0;\n-\t\t\t\tint ret = read(0, &c, user_input_timeout);\n-\n-\t\t\t\tif (ret) {\n-\t\t\t\t\treturn;\n-\t\t\t\t}\n-\n-\t\t\t\tswitch (c) {\n-\t\t\t\tcase 0x03: // ctrl-c\n-\t\t\t\tcase 0x1b: // esc\n-\t\t\t\tcase 'q':\n-\t\t\t\t\treturn;\n-\t\t\t\t\t/* not reached */\n+\t\t\tstruct pollfd fds[2] {};\n+\t\t\t// Poll for user input (for q or escape)\n+\t\t\tfds[0].fd = 0; /* stdin */\n+\t\t\tfds[0].events = POLLIN;\n+\t\t\t// Poll the UOrb subscription\n+\t\t\tfds[1].fd = sub;\n+\t\t\tfds[1].events = POLLIN;","path":"src/systemcmds/topic_listener/listener_main.cpp","position":56,"original_position":56,"commit_id":"f1563012a6ddf675df9f10dc72429f9f4de01c7a","original_commit_id":"f1563012a6ddf675df9f10dc72429f9f4de01c7a","user":{"login":"julianoes","id":1419688,"node_id":"MDQ6VXNlcjE0MTk2ODg=","avatar_url":"https://avatars3.githubusercontent.com/u/1419688?v=4","gravatar_id":"","url":"https://api.github.com/users/julianoes","html_url":"https://github.com/julianoes","followers_url":"https://api.github.com/users/julianoes/followers","following_url":"https://api.github.com/users/julianoes/following{/other_user}","gists_url":"https://api.github.com/users/julianoes/gists{/gist_id}","starred_url":"https://api.github.com/users/julianoes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/julianoes/subscriptions","organizations_url":"https://api.github.com/users/julianoes/orgs","repos_url":"https://api.github.com/users/julianoes/repos","events_url":"https://api.github.com/users/julianoes/events{/privacy}","received_events_url":"https://api.github.com/users/julianoes/received_events","type":"User","site_admin":false},"body":"It looks like setting up the pollfd structure is always the same in every loop. I'd therefore move it out of the while.","created_at":"2019-10-11T14:10:26Z","updated_at":"2019-10-11T14:11:47Z","html_url":"https://github.com/PX4/Firmware/pull/13157#discussion_r334010651","pull_request_url":"https://api.github.com/repos/PX4/Firmware/pulls/13157","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/PX4/Firmware/pulls/comments/334010651"},"html":{"href":"https://github.com/PX4/Firmware/pull/13157#discussion_r334010651"},"pull_request":{"href":"https://api.github.com/repos/PX4/Firmware/pulls/13157"}}},"pull_request":{"url":"https://api.github.com/repos/PX4/Firmware/pulls/13157","id":327132910,"node_id":"MDExOlB1bGxSZXF1ZXN0MzI3MTMyOTEw","html_url":"https://github.com/PX4/Firmware/pull/13157","diff_url":"https://github.com/PX4/Firmware/pull/13157.diff","patch_url":"https://github.com/PX4/Firmware/pull/13157.patch","issue_url":"https://api.github.com/repos/PX4/Firmware/issues/13157","number":13157,"state":"open","locked":false,"title":"Changed listener to not busy-wait","user":{"login":"ItsTimmy","id":725892,"node_id":"MDQ6VXNlcjcyNTg5Mg==","avatar_url":"https://avatars3.githubusercontent.com/u/725892?v=4","gravatar_id":"","url":"https://api.github.com/users/ItsTimmy","html_url":"https://github.com/ItsTimmy","followers_url":"https://api.github.com/users/ItsTimmy/followers","following_url":"https://api.github.com/users/ItsTimmy/following{/other_user}","gists_url":"https://api.github.com/users/ItsTimmy/gists{/gist_id}","starred_url":"https://api.github.com/users/ItsTimmy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ItsTimmy/subscriptions","organizations_url":"https://api.github.com/users/ItsTimmy/orgs","repos_url":"https://api.github.com/users/ItsTimmy/repos","events_url":"https://api.github.com/users/ItsTimmy/events{/privacy}","received_events_url":"https://api.github.com/users/ItsTimmy/received_events","type":"User","site_admin":false},"body":"**Describe problem solved by the proposed pull request**\r\nUnder certain circumstances, when running the `listener` command with the `-n` argument, it would incorrectly timeout. For example, by using `uorb top`, I can see that the `telemetry_status` message is being published once per second. However, when running `listener telemetry_status -n 100`, I receive two messages, then the message `Waited for 2 seconds without a message. Giving up.`\r\n\r\n**Test data / coverage**\r\nI ran a series of `listener` commands on different topics, with every possible combination of the `-i`, `-r`, and `-n` parameters.\r\n\r\n**Describe your preferred solution**\r\nI suspect that the issue had something to do with the `listener` performing a busy-wait between messages, therefore using up all available CPU. This can be demonstrated by running `listener cpuload -n 10` and observing that the load on every message except for the first is 100%. So, I changed the `listener` to poll on messages asynchronously. This fixed the issue with `telemetry_status`.\r\n\r\n**Additional context**\r\nSome work has been done recently on the listener, in #12799 and #13006 .\r\n","created_at":"2019-10-11T10:26:10Z","updated_at":"2019-10-11T14:11:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f7c5cb2bedeacdfff7184df0f4ec4b646d9d1f9d","assignee":null,"assignees":[],"requested_reviewers":[{"login":"dagar","id":84712,"node_id":"MDQ6VXNlcjg0NzEy","avatar_url":"https://avatars3.githubusercontent.com/u/84712?v=4","gravatar_id":"","url":"https://api.github.com/users/dagar","html_url":"https://github.com/dagar","followers_url":"https://api.github.com/users/dagar/followers","following_url":"https://api.github.com/users/dagar/following{/other_user}","gists_url":"https://api.github.com/users/dagar/gists{/gist_id}","starred_url":"https://api.github.com/users/dagar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dagar/subscriptions","organizations_url":"https://api.github.com/users/dagar/orgs","repos_url":"https://api.github.com/users/dagar/repos","events_url":"https://api.github.com/users/dagar/events{/privacy}","received_events_url":"https://api.github.com/users/dagar/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":10884838,"node_id":"MDU6TGFiZWwxMDg4NDgzOA==","url":"https://api.github.com/repos/PX4/Firmware/labels/bug","name":"bug","color":"fc2929","default":true}],"milestone":null,"commits_url":"https://api.github.com/repos/PX4/Firmware/pulls/13157/commits","review_comments_url":"https://api.github.com/repos/PX4/Firmware/pulls/13157/comments","review_comment_url":"https://api.github.com/repos/PX4/Firmware/pulls/comments{/number}","comments_url":"https://api.github.com/repos/PX4/Firmware/issues/13157/comments","statuses_url":"https://api.github.com/repos/PX4/Firmware/statuses/f1563012a6ddf675df9f10dc72429f9f4de01c7a","head":{"label":"ItsTimmy:pr-listener-fix","ref":"pr-listener-fix","sha":"f1563012a6ddf675df9f10dc72429f9f4de01c7a","user":{"login":"ItsTimmy","id":725892,"node_id":"MDQ6VXNlcjcyNTg5Mg==","avatar_url":"https://avatars3.githubusercontent.com/u/725892?v=4","gravatar_id":"","url":"https://api.github.com/users/ItsTimmy","html_url":"https://github.com/ItsTimmy","followers_url":"https://api.github.com/users/ItsTimmy/followers","following_url":"https://api.github.com/users/ItsTimmy/following{/other_user}","gists_url":"https://api.github.com/users/ItsTimmy/gists{/gist_id}","starred_url":"https://api.github.com/users/ItsTimmy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ItsTimmy/subscriptions","organizations_url":"https://api.github.com/users/ItsTimmy/orgs","repos_url":"https://api.github.com/users/ItsTimmy/repos","events_url":"https://api.github.com/users/ItsTimmy/events{/privacy}","received_events_url":"https://api.github.com/users/ItsTimmy/received_events","type":"User","site_admin":false},"repo":{"id":180767341,"node_id":"MDEwOlJlcG9zaXRvcnkxODA3NjczNDE=","name":"Firmware","full_name":"ItsTimmy/Firmware","private":false,"owner":{"login":"ItsTimmy","id":725892,"node_id":"MDQ6VXNlcjcyNTg5Mg==","avatar_url":"https://avatars3.githubusercontent.com/u/725892?v=4","gravatar_id":"","url":"https://api.github.com/users/ItsTimmy","html_url":"https://github.com/ItsTimmy","followers_url":"https://api.github.com/users/ItsTimmy/followers","following_url":"https://api.github.com/users/ItsTimmy/following{/other_user}","gists_url":"https://api.github.com/users/ItsTimmy/gists{/gist_id}","starred_url":"https://api.github.com/users/ItsTimmy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ItsTimmy/subscriptions","organizations_url":"https://api.github.com/users/ItsTimmy/orgs","repos_url":"https://api.github.com/users/ItsTimmy/repos","events_url":"https://api.github.com/users/ItsTimmy/events{/privacy}","received_events_url":"https://api.github.com/users/ItsTimmy/received_events","type":"User","site_admin":false},"html_url":"https://github.com/ItsTimmy/Firmware","description":"PX4 Autopilot Software","fork":true,"url":"https://api.github.com/repos/ItsTimmy/Firmware","forks_url":"https://api.github.com/repos/ItsTimmy/Firmware/forks","keys_url":"https://api.github.com/repos/ItsTimmy/Firmware/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ItsTimmy/Firmware/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ItsTimmy/Firmware/teams","hooks_url":"https://api.github.com/repos/ItsTimmy/Firmware/hooks","issue_events_url":"https://api.github.com/repos/ItsTimmy/Firmware/issues/events{/number}","events_url":"https://api.github.com/repos/ItsTimmy/Firmware/events","assignees_url":"https://api.github.com/repos/ItsTimmy/Firmware/assignees{/user}","branches_url":"https://api.github.com/repos/ItsTimmy/Firmware/branches{/branch}","tags_url":"https://api.github.com/repos/ItsTimmy/Firmware/tags","blobs_url":"https://api.github.com/repos/ItsTimmy/Firmware/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ItsTimmy/Firmware/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ItsTimmy/Firmware/git/refs{/sha}","trees_url":"https://api.github.com/repos/ItsTimmy/Firmware/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ItsTimmy/Firmware/statuses/{sha}","languages_url":"https://api.github.com/repos/ItsTimmy/Firmware/languages","stargazers_url":"https://api.github.com/repos/ItsTimmy/Firmware/stargazers","contributors_url":"https://api.github.com/repos/ItsTimmy/Firmware/contributors","subscribers_url":"https://api.github.com/repos/ItsTimmy/Firmware/subscribers","subscription_url":"https://api.github.com/repos/ItsTimmy/Firmware/subscription","commits_url":"https://api.github.com/repos/ItsTimmy/Firmware/commits{/sha}","git_commits_url":"https://api.github.com/repos/ItsTimmy/Firmware/git/commits{/sha}","comments_url":"https://api.github.com/repos/ItsTimmy/Firmware/comments{/number}","issue_comment_url":"https://api.github.com/repos/ItsTimmy/Firmware/issues/comments{/number}","contents_url":"https://api.github.com/repos/ItsTimmy/Firmware/contents/{+path}","compare_url":"https://api.github.com/repos/ItsTimmy/Firmware/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ItsTimmy/Firmware/merges","archive_url":"https://api.github.com/repos/ItsTimmy/Firmware/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ItsTimmy/Firmware/downloads","issues_url":"https://api.github.com/repos/ItsTimmy/Firmware/issues{/number}","pulls_url":"https://api.github.com/repos/ItsTimmy/Firmware/pulls{/number}","milestones_url":"https://api.github.com/repos/ItsTimmy/Firmware/milestones{/number}","notifications_url":"https://api.github.com/repos/ItsTimmy/Firmware/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ItsTimmy/Firmware/labels{/name}","releases_url":"https://api.github.com/repos/ItsTimmy/Firmware/releases{/id}","deployments_url":"https://api.github.com/repos/ItsTimmy/Firmware/deployments","created_at":"2019-04-11T10:16:40Z","updated_at":"2019-10-11T07:52:37Z","pushed_at":"2019-10-11T13:40:42Z","git_url":"git://github.com/ItsTimmy/Firmware.git","ssh_url":"git@github.com:ItsTimmy/Firmware.git","clone_url":"https://github.com/ItsTimmy/Firmware.git","svn_url":"https://github.com/ItsTimmy/Firmware","homepage":"https://px4.io","size":107608,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"PX4:master","ref":"master","sha":"803a71928f106ccefb453fc2bdf960fb22a63a89","user":{"login":"PX4","id":2096014,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIwOTYwMTQ=","avatar_url":"https://avatars3.githubusercontent.com/u/2096014?v=4","gravatar_id":"","url":"https://api.github.com/users/PX4","html_url":"https://github.com/PX4","followers_url":"https://api.github.com/users/PX4/followers","following_url":"https://api.github.com/users/PX4/following{/other_user}","gists_url":"https://api.github.com/users/PX4/gists{/gist_id}","starred_url":"https://api.github.com/users/PX4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PX4/subscriptions","organizations_url":"https://api.github.com/users/PX4/orgs","repos_url":"https://api.github.com/users/PX4/repos","events_url":"https://api.github.com/users/PX4/events{/privacy}","received_events_url":"https://api.github.com/users/PX4/received_events","type":"Organization","site_admin":false},"repo":{"id":5298790,"node_id":"MDEwOlJlcG9zaXRvcnk1Mjk4Nzkw","name":"Firmware","full_name":"PX4/Firmware","private":false,"owner":{"login":"PX4","id":2096014,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIwOTYwMTQ=","avatar_url":"https://avatars3.githubusercontent.com/u/2096014?v=4","gravatar_id":"","url":"https://api.github.com/users/PX4","html_url":"https://github.com/PX4","followers_url":"https://api.github.com/users/PX4/followers","following_url":"https://api.github.com/users/PX4/following{/other_user}","gists_url":"https://api.github.com/users/PX4/gists{/gist_id}","starred_url":"https://api.github.com/users/PX4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PX4/subscriptions","organizations_url":"https://api.github.com/users/PX4/orgs","repos_url":"https://api.github.com/users/PX4/repos","events_url":"https://api.github.com/users/PX4/events{/privacy}","received_events_url":"https://api.github.com/users/PX4/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/PX4/Firmware","description":"PX4 Autopilot Software","fork":false,"url":"https://api.github.com/repos/PX4/Firmware","forks_url":"https://api.github.com/repos/PX4/Firmware/forks","keys_url":"https://api.github.com/repos/PX4/Firmware/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PX4/Firmware/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PX4/Firmware/teams","hooks_url":"https://api.github.com/repos/PX4/Firmware/hooks","issue_events_url":"https://api.github.com/repos/PX4/Firmware/issues/events{/number}","events_url":"https://api.github.com/repos/PX4/Firmware/events","assignees_url":"https://api.github.com/repos/PX4/Firmware/assignees{/user}","branches_url":"https://api.github.com/repos/PX4/Firmware/branches{/branch}","tags_url":"https://api.github.com/repos/PX4/Firmware/tags","blobs_url":"https://api.github.com/repos/PX4/Firmware/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PX4/Firmware/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PX4/Firmware/git/refs{/sha}","trees_url":"https://api.github.com/repos/PX4/Firmware/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PX4/Firmware/statuses/{sha}","languages_url":"https://api.github.com/repos/PX4/Firmware/languages","stargazers_url":"https://api.github.com/repos/PX4/Firmware/stargazers","contributors_url":"https://api.github.com/repos/PX4/Firmware/contributors","subscribers_url":"https://api.github.com/repos/PX4/Firmware/subscribers","subscription_url":"https://api.github.com/repos/PX4/Firmware/subscription","commits_url":"https://api.github.com/repos/PX4/Firmware/commits{/sha}","git_commits_url":"https://api.github.com/repos/PX4/Firmware/git/commits{/sha}","comments_url":"https://api.github.com/repos/PX4/Firmware/comments{/number}","issue_comment_url":"https://api.github.com/repos/PX4/Firmware/issues/comments{/number}","contents_url":"https://api.github.com/repos/PX4/Firmware/contents/{+path}","compare_url":"https://api.github.com/repos/PX4/Firmware/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PX4/Firmware/merges","archive_url":"https://api.github.com/repos/PX4/Firmware/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PX4/Firmware/downloads","issues_url":"https://api.github.com/repos/PX4/Firmware/issues{/number}","pulls_url":"https://api.github.com/repos/PX4/Firmware/pulls{/number}","milestones_url":"https://api.github.com/repos/PX4/Firmware/milestones{/number}","notifications_url":"https://api.github.com/repos/PX4/Firmware/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PX4/Firmware/labels{/name}","releases_url":"https://api.github.com/repos/PX4/Firmware/releases{/id}","deployments_url":"https://api.github.com/repos/PX4/Firmware/deployments","created_at":"2012-08-04T21:19:36Z","updated_at":"2019-10-11T11:58:10Z","pushed_at":"2019-10-11T14:10:28Z","git_url":"git://github.com/PX4/Firmware.git","ssh_url":"git@github.com:PX4/Firmware.git","clone_url":"https://github.com/PX4/Firmware.git","svn_url":"https://github.com/PX4/Firmware","homepage":"https://px4.io","size":109321,"stargazers_count":2963,"watchers_count":2963,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":8442,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":560,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":8442,"open_issues":560,"watchers":2963,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/PX4/Firmware/pulls/13157"},"html":{"href":"https://github.com/PX4/Firmware/pull/13157"},"issue":{"href":"https://api.github.com/repos/PX4/Firmware/issues/13157"},"comments":{"href":"https://api.github.com/repos/PX4/Firmware/issues/13157/comments"},"review_comments":{"href":"https://api.github.com/repos/PX4/Firmware/pulls/13157/comments"},"review_comment":{"href":"https://api.github.com/repos/PX4/Firmware/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/PX4/Firmware/pulls/13157/commits"},"statuses":{"href":"https://api.github.com/repos/PX4/Firmware/statuses/f1563012a6ddf675df9f10dc72429f9f4de01c7a"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"julianoes"}}