{"action":"created","comment":{"url":"https://api.github.com/repos/p4lang/p4-spec/pulls/comments/127128536","pull_request_review_id":49678573,"id":127128536,"diff_hunk":"@@ -561,11 +598,67 @@ extern Counter<W, S> {\n }\n ```\n \n+See below for pseudocode of a reference implementation for the Counter\n+extern.\n+\n+```\n+Counter(N n_counters) {\n+    this.num_counters = n_counters;\n+    this.counter_vals = new array of size n_counters, each element with type W;\n+    this.max_counter_value = maximum value possible for type W;\n+}\n+\n+/// Add @add_value to a saturating counter whose current value is\n+/// @cur_value, and whose maximum possible value is @max_value.\n+///\n+/// Assume that type W is bit<X> and type V is bit<Y> where X >= Y.\n+/// There is very little, if any, reason to use signed count values.\n+\n+W next_counter_value(W cur_value, V add_value, W max_value) {\n+    bit<X+1> next_value = (bit<X+1>) cur_value + (bit<X+1>) add_value;\n+    if (next_value[X] == 1) {\n+        return max_value;\n+    }\n+    return (bit<X>) next_value;\n+}\n+\n+void count(in S index, in V add_value) {\n+    if (index < this.num_counters) {\n+        this.counter_vals[index] = next_counter_value(this.counter_vals[index],\n+                                           add_value, this.max_counter_value);\n+    } else {\n+        // No counter_vals updated if index is out of range.\n+        // See below for optional debug information to record.\n+    }\n+}\n+\n+void count(in S index) {\n+    count(index, 1);\n+}\n+```\n+\n+Rationale for saturating behavior: With saturating behavior, the\n+control plane can know that information was lost, if it reads the\n+maximum possible value from a counter.  In this case, it knows that","path":"p4-16/psa/PSA.mdk","position":135,"original_position":135,"commit_id":"8ccfa2b0d2367bd67fe5d42f16a5e5ee857344c5","original_commit_id":"8ccfa2b0d2367bd67fe5d42f16a5e5ee857344c5","user":{"login":"cc10512","id":3770874,"avatar_url":"https://avatars2.githubusercontent.com/u/3770874?v=3","gravatar_id":"","url":"https://api.github.com/users/cc10512","html_url":"https://github.com/cc10512","followers_url":"https://api.github.com/users/cc10512/followers","following_url":"https://api.github.com/users/cc10512/following{/other_user}","gists_url":"https://api.github.com/users/cc10512/gists{/gist_id}","starred_url":"https://api.github.com/users/cc10512/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cc10512/subscriptions","organizations_url":"https://api.github.com/users/cc10512/orgs","repos_url":"https://api.github.com/users/cc10512/repos","events_url":"https://api.github.com/users/cc10512/events{/privacy}","received_events_url":"https://api.github.com/users/cc10512/received_events","type":"User","site_admin":false},"body":"@vgurevich actually we can control the programmer's behavior to a certain extent by making it harder to code in a bad way. Giving them safe default behavior and the threads to build the rope to hang themselves will always push them toward the safe behavior because it's too much work to twist enough rope.","created_at":"2017-07-13T04:59:23Z","updated_at":"2017-07-13T04:59:37Z","html_url":"https://github.com/p4lang/p4-spec/pull/348#discussion_r127128536","pull_request_url":"https://api.github.com/repos/p4lang/p4-spec/pulls/348","_links":{"self":{"href":"https://api.github.com/repos/p4lang/p4-spec/pulls/comments/127128536"},"html":{"href":"https://github.com/p4lang/p4-spec/pull/348#discussion_r127128536"},"pull_request":{"href":"https://api.github.com/repos/p4lang/p4-spec/pulls/348"}}},"pull_request":{"url":"https://api.github.com/repos/p4lang/p4-spec/pulls/348","id":130053195,"html_url":"https://github.com/p4lang/p4-spec/pull/348","diff_url":"https://github.com/p4lang/p4-spec/pull/348.diff","patch_url":"https://github.com/p4lang/p4-spec/pull/348.patch","issue_url":"https://api.github.com/repos/p4lang/p4-spec/issues/348","number":348,"state":"open","locked":false,"title":"New PSA.mdk Counter section","user":{"login":"jafingerhut","id":109629,"avatar_url":"https://avatars1.githubusercontent.com/u/109629?v=3","gravatar_id":"","url":"https://api.github.com/users/jafingerhut","html_url":"https://github.com/jafingerhut","followers_url":"https://api.github.com/users/jafingerhut/followers","following_url":"https://api.github.com/users/jafingerhut/following{/other_user}","gists_url":"https://api.github.com/users/jafingerhut/gists{/gist_id}","starred_url":"https://api.github.com/users/jafingerhut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jafingerhut/subscriptions","organizations_url":"https://api.github.com/users/jafingerhut/orgs","repos_url":"https://api.github.com/users/jafingerhut/repos","events_url":"https://api.github.com/users/jafingerhut/events{/privacy}","received_events_url":"https://api.github.com/users/jafingerhut/received_events","type":"User","site_admin":false},"body":"There isn't any fleshing out of the counter control plane API with\r\nthese changes.\r\n\r\nThere is significant fleshing out of the Counter and DirectCounter\r\nextern definitions from the P4 program perspective, including a\r\nreference implementation defined as pseudocode, and an example P4\r\nprogram fragment demonstrating the use of both Counter and\r\nDirectCounter.\r\n\r\nPerhaps controversial changes:\r\n\r\nEliminate CounterType_t.  If you want a packet counter, just\r\ninstantiate a counter and only use the count() method that defaults to\r\nadding 1 to the counter.  If you want a byte counter, use the count()\r\nmethod that takes an 'add_value' parameter, and pass whatever you want\r\nas the number of bytes in the packet.  If you want both, instantiate 2\r\ncounter externs, and update them both.\r\n\r\nEnable more than one DirectCounter to be associated with a single\r\ntable.\r\n\r\nSpecify that the counter update operation should be saturating, not\r\nwrap-around, including the rationale for why.","created_at":"2017-07-12T04:27:54Z","updated_at":"2017-07-13T04:59:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"51be6f697dba828869b729fdb3783973580c0fcc","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/p4lang/p4-spec/pulls/348/commits","review_comments_url":"https://api.github.com/repos/p4lang/p4-spec/pulls/348/comments","review_comment_url":"https://api.github.com/repos/p4lang/p4-spec/pulls/comments{/number}","comments_url":"https://api.github.com/repos/p4lang/p4-spec/issues/348/comments","statuses_url":"https://api.github.com/repos/p4lang/p4-spec/statuses/8ccfa2b0d2367bd67fe5d42f16a5e5ee857344c5","head":{"label":"jafingerhut:psa-new-counter-section1","ref":"psa-new-counter-section1","sha":"8ccfa2b0d2367bd67fe5d42f16a5e5ee857344c5","user":{"login":"jafingerhut","id":109629,"avatar_url":"https://avatars1.githubusercontent.com/u/109629?v=3","gravatar_id":"","url":"https://api.github.com/users/jafingerhut","html_url":"https://github.com/jafingerhut","followers_url":"https://api.github.com/users/jafingerhut/followers","following_url":"https://api.github.com/users/jafingerhut/following{/other_user}","gists_url":"https://api.github.com/users/jafingerhut/gists{/gist_id}","starred_url":"https://api.github.com/users/jafingerhut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jafingerhut/subscriptions","organizations_url":"https://api.github.com/users/jafingerhut/orgs","repos_url":"https://api.github.com/users/jafingerhut/repos","events_url":"https://api.github.com/users/jafingerhut/events{/privacy}","received_events_url":"https://api.github.com/users/jafingerhut/received_events","type":"User","site_admin":false},"repo":{"id":90683714,"name":"p4-spec-1","full_name":"jafingerhut/p4-spec-1","owner":{"login":"jafingerhut","id":109629,"avatar_url":"https://avatars1.githubusercontent.com/u/109629?v=3","gravatar_id":"","url":"https://api.github.com/users/jafingerhut","html_url":"https://github.com/jafingerhut","followers_url":"https://api.github.com/users/jafingerhut/followers","following_url":"https://api.github.com/users/jafingerhut/following{/other_user}","gists_url":"https://api.github.com/users/jafingerhut/gists{/gist_id}","starred_url":"https://api.github.com/users/jafingerhut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jafingerhut/subscriptions","organizations_url":"https://api.github.com/users/jafingerhut/orgs","repos_url":"https://api.github.com/users/jafingerhut/repos","events_url":"https://api.github.com/users/jafingerhut/events{/privacy}","received_events_url":"https://api.github.com/users/jafingerhut/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jafingerhut/p4-spec-1","description":null,"fork":true,"url":"https://api.github.com/repos/jafingerhut/p4-spec-1","forks_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/forks","keys_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/teams","hooks_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/hooks","issue_events_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/issues/events{/number}","events_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/events","assignees_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/assignees{/user}","branches_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/branches{/branch}","tags_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/tags","blobs_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/git/refs{/sha}","trees_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/statuses/{sha}","languages_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/languages","stargazers_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/stargazers","contributors_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/contributors","subscribers_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/subscribers","subscription_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/subscription","commits_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/commits{/sha}","git_commits_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/git/commits{/sha}","comments_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/comments{/number}","issue_comment_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/issues/comments{/number}","contents_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/contents/{+path}","compare_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/merges","archive_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/downloads","issues_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/issues{/number}","pulls_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/pulls{/number}","milestones_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/milestones{/number}","notifications_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/labels{/name}","releases_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/releases{/id}","deployments_url":"https://api.github.com/repos/jafingerhut/p4-spec-1/deployments","created_at":"2017-05-09T00:10:36Z","updated_at":"2017-05-09T00:10:38Z","pushed_at":"2017-07-13T02:22:40Z","git_url":"git://github.com/jafingerhut/p4-spec-1.git","ssh_url":"git@github.com:jafingerhut/p4-spec-1.git","clone_url":"https://github.com/jafingerhut/p4-spec-1.git","svn_url":"https://github.com/jafingerhut/p4-spec-1","homepage":null,"size":22836,"stargazers_count":0,"watchers_count":0,"language":"TeX","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"p4lang:master","ref":"master","sha":"7aea51c2e2f5f9c34afc78f9ecf3276fe989bd26","user":{"login":"p4lang","id":10765181,"avatar_url":"https://avatars2.githubusercontent.com/u/10765181?v=3","gravatar_id":"","url":"https://api.github.com/users/p4lang","html_url":"https://github.com/p4lang","followers_url":"https://api.github.com/users/p4lang/followers","following_url":"https://api.github.com/users/p4lang/following{/other_user}","gists_url":"https://api.github.com/users/p4lang/gists{/gist_id}","starred_url":"https://api.github.com/users/p4lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/p4lang/subscriptions","organizations_url":"https://api.github.com/users/p4lang/orgs","repos_url":"https://api.github.com/users/p4lang/repos","events_url":"https://api.github.com/users/p4lang/events{/privacy}","received_events_url":"https://api.github.com/users/p4lang/received_events","type":"Organization","site_admin":false},"repo":{"id":40704988,"name":"p4-spec","full_name":"p4lang/p4-spec","owner":{"login":"p4lang","id":10765181,"avatar_url":"https://avatars2.githubusercontent.com/u/10765181?v=3","gravatar_id":"","url":"https://api.github.com/users/p4lang","html_url":"https://github.com/p4lang","followers_url":"https://api.github.com/users/p4lang/followers","following_url":"https://api.github.com/users/p4lang/following{/other_user}","gists_url":"https://api.github.com/users/p4lang/gists{/gist_id}","starred_url":"https://api.github.com/users/p4lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/p4lang/subscriptions","organizations_url":"https://api.github.com/users/p4lang/orgs","repos_url":"https://api.github.com/users/p4lang/repos","events_url":"https://api.github.com/users/p4lang/events{/privacy}","received_events_url":"https://api.github.com/users/p4lang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/p4lang/p4-spec","description":null,"fork":false,"url":"https://api.github.com/repos/p4lang/p4-spec","forks_url":"https://api.github.com/repos/p4lang/p4-spec/forks","keys_url":"https://api.github.com/repos/p4lang/p4-spec/keys{/key_id}","collaborators_url":"https://api.github.com/repos/p4lang/p4-spec/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/p4lang/p4-spec/teams","hooks_url":"https://api.github.com/repos/p4lang/p4-spec/hooks","issue_events_url":"https://api.github.com/repos/p4lang/p4-spec/issues/events{/number}","events_url":"https://api.github.com/repos/p4lang/p4-spec/events","assignees_url":"https://api.github.com/repos/p4lang/p4-spec/assignees{/user}","branches_url":"https://api.github.com/repos/p4lang/p4-spec/branches{/branch}","tags_url":"https://api.github.com/repos/p4lang/p4-spec/tags","blobs_url":"https://api.github.com/repos/p4lang/p4-spec/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/p4lang/p4-spec/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/p4lang/p4-spec/git/refs{/sha}","trees_url":"https://api.github.com/repos/p4lang/p4-spec/git/trees{/sha}","statuses_url":"https://api.github.com/repos/p4lang/p4-spec/statuses/{sha}","languages_url":"https://api.github.com/repos/p4lang/p4-spec/languages","stargazers_url":"https://api.github.com/repos/p4lang/p4-spec/stargazers","contributors_url":"https://api.github.com/repos/p4lang/p4-spec/contributors","subscribers_url":"https://api.github.com/repos/p4lang/p4-spec/subscribers","subscription_url":"https://api.github.com/repos/p4lang/p4-spec/subscription","commits_url":"https://api.github.com/repos/p4lang/p4-spec/commits{/sha}","git_commits_url":"https://api.github.com/repos/p4lang/p4-spec/git/commits{/sha}","comments_url":"https://api.github.com/repos/p4lang/p4-spec/comments{/number}","issue_comment_url":"https://api.github.com/repos/p4lang/p4-spec/issues/comments{/number}","contents_url":"https://api.github.com/repos/p4lang/p4-spec/contents/{+path}","compare_url":"https://api.github.com/repos/p4lang/p4-spec/compare/{base}...{head}","merges_url":"https://api.github.com/repos/p4lang/p4-spec/merges","archive_url":"https://api.github.com/repos/p4lang/p4-spec/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/p4lang/p4-spec/downloads","issues_url":"https://api.github.com/repos/p4lang/p4-spec/issues{/number}","pulls_url":"https://api.github.com/repos/p4lang/p4-spec/pulls{/number}","milestones_url":"https://api.github.com/repos/p4lang/p4-spec/milestones{/number}","notifications_url":"https://api.github.com/repos/p4lang/p4-spec/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/p4lang/p4-spec/labels{/name}","releases_url":"https://api.github.com/repos/p4lang/p4-spec/releases{/id}","deployments_url":"https://api.github.com/repos/p4lang/p4-spec/deployments","created_at":"2015-08-14T08:45:53Z","updated_at":"2017-06-20T16:46:19Z","pushed_at":"2017-07-13T02:23:06Z","git_url":"git://github.com/p4lang/p4-spec.git","ssh_url":"git@github.com:p4lang/p4-spec.git","clone_url":"https://github.com/p4lang/p4-spec.git","svn_url":"https://github.com/p4lang/p4-spec","homepage":null,"size":41550,"stargazers_count":15,"watchers_count":15,"language":"TeX","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":8,"mirror_url":null,"open_issues_count":55,"forks":8,"open_issues":55,"watchers":15,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/p4lang/p4-spec/pulls/348"},"html":{"href":"https://github.com/p4lang/p4-spec/pull/348"},"issue":{"href":"https://api.github.com/repos/p4lang/p4-spec/issues/348"},"comments":{"href":"https://api.github.com/repos/p4lang/p4-spec/issues/348/comments"},"review_comments":{"href":"https://api.github.com/repos/p4lang/p4-spec/pulls/348/comments"},"review_comment":{"href":"https://api.github.com/repos/p4lang/p4-spec/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/p4lang/p4-spec/pulls/348/commits"},"statuses":{"href":"https://api.github.com/repos/p4lang/p4-spec/statuses/8ccfa2b0d2367bd67fe5d42f16a5e5ee857344c5"}}}}
{"actor":{"display_login":"cc10512"}}