{"action":"created","issue":{"url":"https://api.github.com/repos/joan2937/pigpio/issues/33","labels_url":"https://api.github.com/repos/joan2937/pigpio/issues/33/labels{/name}","comments_url":"https://api.github.com/repos/joan2937/pigpio/issues/33/comments","events_url":"https://api.github.com/repos/joan2937/pigpio/issues/33/events","html_url":"https://github.com/joan2937/pigpio/issues/33","id":117674536,"number":33,"title":"Notifications with incorrect sequence numbers","user":{"login":"fivdi","id":2605378,"avatar_url":"https://avatars.githubusercontent.com/u/2605378?v=3","gravatar_id":"","url":"https://api.github.com/users/fivdi","html_url":"https://github.com/fivdi","followers_url":"https://api.github.com/users/fivdi/followers","following_url":"https://api.github.com/users/fivdi/following{/other_user}","gists_url":"https://api.github.com/users/fivdi/gists{/gist_id}","starred_url":"https://api.github.com/users/fivdi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fivdi/subscriptions","organizations_url":"https://api.github.com/users/fivdi/orgs","repos_url":"https://api.github.com/users/fivdi/repos","events_url":"https://api.github.com/users/fivdi/events{/privacy}","received_events_url":"https://api.github.com/users/fivdi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-11-18T20:28:26Z","updated_at":"2015-11-21T11:20:35Z","closed_at":null,"body":"The effect seen here may be an edge case, or I may be doing something incorrectly, or I may be expecting too much.\r\n\r\nThe following program starts hardware PWM on GPIO18 at a frequency of 100KHz with a 50% duty cycle. It then activates notifications on GPIO18. This means about 200,000 notifications per second. Every 1,000,000 notifications the program prints the number of notifications so far. If the seqno for a notification is not the expected value an error message is printed.\r\n\r\n```c\r\n#include <fcntl.h>\r\n#include <stdio.h>\r\n#include <pigpio.h>\r\n\r\n#define LED 18\r\n\r\nint main() {\r\n  int version;\r\n  int handle;\r\n  char pipePath[32];\r\n  int fd;\r\n  int bytes;\r\n  int notificationCount = 0;\r\n  gpioReport_t r;\r\n  uint16_t lastSeqno = 0xffff;\r\n  uint32_t lastTick;\r\n\r\n  gpioCfgClock(1, 1, 1);\r\n\r\n  if ((version = gpioInitialise()) < 0) {\r\n    printf(\"gpioInitialise error\\n\");\r\n    return -1;\r\n  }\r\n\r\n  printf(\"version: %d\\n\", version);\r\n\r\n  if (gpioHardwarePWM(LED, 100000, 500000) < 0) {\r\n    printf(\"gpioHardwarePWM error\\n\");\r\n    return -1;\r\n  }\r\n\r\n  if ((handle = gpioNotifyOpen()) < 0) {\r\n    printf(\"gpioNotifyOpen error\\n\");\r\n    return -1;\r\n  }\r\n\r\n  if (gpioNotifyBegin(handle, (1 << LED)) < 0) {\r\n    printf(\"gpioNotifyBegin error\\n\");\r\n    return -1;\r\n  }\r\n\r\n  sprintf(pipePath, \"/dev/pigpio%d\", handle);\r\n\r\n  if ((fd = open(pipePath, O_RDONLY)) < 0) {\r\n    printf(\"open error\\n\");\r\n    return -1;\r\n  }\r\n\r\n  for (;;) {\r\n    bytes = read(fd, &r, 12);\r\n    if (bytes != 12) {\r\n      printf(\"read error\\n\");\r\n      return -1;\r\n    }\r\n\r\n    notificationCount++;\r\n    if (notificationCount % 1000000 == 0) {\r\n      printf(\"%d\\n\", notificationCount);\r\n    }\r\n\r\n    if (((uint16_t) (lastSeqno + 1)) != r.seqno) {\r\n      printf(\"  sequence error - lastSeqno: %d, seqno: %d\\n\", lastSeqno, r.seqno);\r\n      printf(\"    %d\\n\", notificationCount);\r\n    }\r\n\r\n    lastSeqno = r.seqno;\r\n    lastTick = r.tick;\r\n  }\r\n\r\n  gpioTerminate();\r\n\r\n  return 0;\r\n}\r\n```\r\n\r\nIf the program is run without any additional load everything looks fine and the output will be something like this:\r\n\r\n```\r\nversion: 40\r\n1000000\r\n2000000\r\n3000000\r\n4000000\r\n5000000\r\n6000000\r\n7000000\r\n8000000\r\n9000000\r\n10000000\r\n11000000\r\n12000000\r\n13000000\r\n14000000\r\n15000000\r\n16000000\r\n17000000\r\n18000000\r\n19000000\r\n20000000\r\n...\r\n```\r\n\r\nHowever, if there is additional load on the system, the output can look like this:\r\n\r\n```\r\nversion: 40\r\n1000000\r\n2000000\r\n  sequence error - lastSeqno: 28427, seqno: 28583\r\n    2780941\r\n  sequence error - lastSeqno: 31399, seqno: 32082\r\n    2783758\r\n  sequence error - lastSeqno: 32199, seqno: 33000\r\n    2783876\r\n  sequence error - lastSeqno: 33340, seqno: 33800\r\n    2784217\r\n  sequence error - lastSeqno: 34140, seqno: 34452\r\n    2784558\r\n  sequence error - lastSeqno: 34792, seqno: 35701\r\n    2784899\r\n  sequence error - lastSeqno: 38414, seqno: 39273\r\n    2787613\r\n  sequence error - lastSeqno: 39613, seqno: 40075\r\n    2787954\r\n  sequence error - lastSeqno: 40415, seqno: 40873\r\n    2788295\r\n  sequence error - lastSeqno: 41213, seqno: 42072\r\n    2788636\r\n  sequence error - lastSeqno: 42412, seqno: 42470\r\n    2788977\r\n  sequence error - lastSeqno: 42870, seqno: 43212\r\n    2789378\r\n  sequence error - lastSeqno: 44811, seqno: 44870\r\n    2790978\r\n  sequence error - lastSeqno: 45611, seqno: 46071\r\n    2791720\r\n  sequence error - lastSeqno: 46411, seqno: 46872\r\n    2792061\r\n  sequence error - lastSeqno: 47212, seqno: 47669\r\n    2792402\r\n  sequence error - lastSeqno: 48009, seqno: 48471\r\n    2792743\r\n  sequence error - lastSeqno: 48811, seqno: 49671\r\n    2793084\r\n  sequence error - lastSeqno: 50011, seqno: 50071\r\n    2793425\r\n  sequence error - lastSeqno: 50411, seqno: 50485\r\n    2793766\r\n  sequence error - lastSeqno: 51670, seqno: 52012\r\n    2794952\r\n  sequence error - lastSeqno: 52069, seqno: 52411\r\n    2795010\r\n  sequence error - lastSeqno: 52471, seqno: 52813\r\n    2795071\r\n  sequence error - lastSeqno: 52871, seqno: 53213\r\n    2795130\r\n  sequence error - lastSeqno: 53609, seqno: 54470\r\n    2795527\r\n  sequence error - lastSeqno: 55211, seqno: 55672\r\n    2796269\r\n  sequence error - lastSeqno: 56012, seqno: 56473\r\n    2796610\r\n  sequence error - lastSeqno: 56813, seqno: 56872\r\n    2796951\r\n  sequence error - lastSeqno: 57212, seqno: 57673\r\n    2797292\r\n  sequence error - lastSeqno: 58013, seqno: 58472\r\n    2797633\r\n  sequence error - lastSeqno: 58812, seqno: 58872\r\n    2797974\r\n  sequence error - lastSeqno: 59212, seqno: 59671\r\n    2798315\r\n  sequence error - lastSeqno: 60833, seqno: 61271\r\n    2799478\r\n  sequence error - lastSeqno: 61611, seqno: 62070\r\n    2799819\r\n  sequence error - lastSeqno: 62410, seqno: 62471\r\n    2800160\r\n  sequence error - lastSeqno: 63212, seqno: 63672\r\n    2800902\r\n  sequence error - lastSeqno: 64012, seqno: 64470\r\n    2801243\r\n  sequence error - lastSeqno: 64810, seqno: 64870\r\n    2801584\r\n  sequence error - lastSeqno: 65210, seqno: 134\r\n    2801925\r\n  sequence error - lastSeqno: 474, seqno: 602\r\n    2802266\r\n  sequence error - lastSeqno: 1274, seqno: 1735\r\n    2802939\r\n  sequence error - lastSeqno: 2875, seqno: 3337\r\n    2804080\r\n  sequence error - lastSeqno: 3677, seqno: 3773\r\n    2804421\r\n  sequence error - lastSeqno: 4113, seqno: 4536\r\n    2804762\r\n  sequence error - lastSeqno: 5290, seqno: 5735\r\n    2805517\r\n  sequence error - lastSeqno: 6075, seqno: 6135\r\n    2805858\r\n  sequence error - lastSeqno: 6475, seqno: 6934\r\n    2806199\r\n  sequence error - lastSeqno: 7274, seqno: 7336\r\n    2806540\r\n  sequence error - lastSeqno: 7676, seqno: 8135\r\n    2806881\r\n  sequence error - lastSeqno: 8475, seqno: 8536\r\n    2807222\r\n  sequence error - lastSeqno: 8876, seqno: 9336\r\n    2807563\r\n  sequence error - lastSeqno: 10875, seqno: 11381\r\n    2809103\r\n  sequence error - lastSeqno: 11721, seqno: 12136\r\n    2809444\r\n  sequence error - lastSeqno: 12902, seqno: 12935\r\n    2810211\r\n  sequence error - lastSeqno: 13275, seqno: 13737\r\n    2810552\r\n  sequence error - lastSeqno: 14077, seqno: 14133\r\n    2810893\r\n  sequence error - lastSeqno: 14473, seqno: 14936\r\n    2811234\r\n  sequence error - lastSeqno: 15276, seqno: 15737\r\n    2811575\r\n  sequence error - lastSeqno: 16077, seqno: 16136\r\n    2811916\r\n  sequence error - lastSeqno: 16476, seqno: 16934\r\n    2812257\r\n  sequence error - lastSeqno: 17676, seqno: 17733\r\n    2813000\r\n  sequence error - lastSeqno: 18073, seqno: 18136\r\n    2813341\r\n  sequence error - lastSeqno: 18476, seqno: 18536\r\n    2813682\r\n  sequence error - lastSeqno: 18876, seqno: 18935\r\n    2814023\r\n  sequence error - lastSeqno: 19275, seqno: 19736\r\n    2814364\r\n  sequence error - lastSeqno: 20519, seqno: 20937\r\n    2815148\r\n  sequence error - lastSeqno: 21377, seqno: 21719\r\n    2815589\r\n  sequence error - lastSeqno: 22074, seqno: 22556\r\n    2815945\r\n3000000\r\n4000000\r\n```\r\n\r\nThe sequence numbers are often off by a few hundred here. The additional load in this case was an `scp` command which copied a large file from another Linux machine to the Pi. \r\n\r\nSetting the PWM frequency to 200KHz will result in similar sequence number issues without any additional load on the system.\r\n\r\nIs this to be expected or am I doing something incorrectly?\r\n"},"comment":{"url":"https://api.github.com/repos/joan2937/pigpio/issues/comments/158628765","html_url":"https://github.com/joan2937/pigpio/issues/33#issuecomment-158628765","issue_url":"https://api.github.com/repos/joan2937/pigpio/issues/33","id":158628765,"user":{"login":"fivdi","id":2605378,"avatar_url":"https://avatars.githubusercontent.com/u/2605378?v=3","gravatar_id":"","url":"https://api.github.com/users/fivdi","html_url":"https://github.com/fivdi","followers_url":"https://api.github.com/users/fivdi/followers","following_url":"https://api.github.com/users/fivdi/following{/other_user}","gists_url":"https://api.github.com/users/fivdi/gists{/gist_id}","starred_url":"https://api.github.com/users/fivdi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fivdi/subscriptions","organizations_url":"https://api.github.com/users/fivdi/orgs","repos_url":"https://api.github.com/users/fivdi/repos","events_url":"https://api.github.com/users/fivdi/events{/privacy}","received_events_url":"https://api.github.com/users/fivdi/received_events","type":"User","site_admin":false},"created_at":"2015-11-21T11:20:35Z","updated_at":"2015-11-21T11:20:35Z","body":"Excellent, thank you very much. I'll add the modification to my installation and let you know how it goes."}}