{"id":10,"date":"2005-08-20T20:00:45","date_gmt":"2005-08-21T03:00:45","guid":{"rendered":"http:\/\/www.boxheap.net\/ddaniels\/blog\/?p=10"},"modified":"2009-02-07T10:42:07","modified_gmt":"2009-02-07T17:42:07","slug":"20050820","status":"publish","type":"post","link":"https:\/\/www.boxheap.net\/ddaniels\/blog\/2005\/08\/20050820\/","title":{"rendered":"20050820"},"content":{"rendered":"<pre>One of the things I've been thinking about writing about is interesting\r\nand common math problems. I'll start with some easy ones that I've had\r\nto do at work (no trade secrets, just common math in the trade).\r\n\r\nNotes:\r\n- I'll use the prefix \"0x\" to denote that the number is written in hex\r\nnotation. E.g.'s 0x10 is 16, 0x1F is 31.\r\n- There's 8 bits in a byte (I may not get to that until later problems\r\nthough).\r\n\r\nLargest packet aligned buffer:\r\nMPEG 2 transport streams have both 188 and 204 byte packets. In order to\r\ntransfer a high speed transport stream, large buffers are needed. Large\r\nbuffers reduce the number of interrupts per second, and make for\r\neffective DMA transfers. To effectively process an MPEG-II transport\r\nstream, buffers should be a multiple of the packet size. Splitting and\r\njoining buffers is not only \"a pain\" to program, but also requires\r\notherwise unnecessary processing power.\r\n\r\nWith a maximum buffer size of 0x20000 (131072) bytes, and a chosen\r\npacket size of 188, what is the largest packet aligned buffer size\r\nallowed?\r\n\r\nThe answer is simply 131072\/188*188 when the division is integer\r\ndivision (i.e. no decimal places). To do this with a calculator that\r\nonly does regular division, one simply needs to remember the integer\r\npart of the division. In this case 131072\/188=697..... So, then I just\r\nclear the calculator, and type 697*188 and get 131036 (0x1FFDC).\r\n\r\n...\r\n\r\nWith a maximum buffer size of 0x20000 (131072) bytes, and a chosen\r\npacket size of 204, what is the largest packet aligned buffer size\r\nallowed?\r\n\r\nThe answer is 131072\/204*204 where the division is integer division. The\r\nfinal number is then 130968 (0x1FF98).\r\n\r\nWhat is the minimum buffer size that is divisible by both 188 and 204?\r\n\r\nTo solve this, take out the common factors, and multiply the remaining\r\ntogether. The factors in 188 are: 2, 2, 47. The factors in 204 are: 2,\r\n2, 3, 17. So the answer is 2*2*47*3*17=9588 (0x2574), or\r\n188*204\/2\/2=9588 (0x2574).\r\n\r\nWith a maximum buffer size of 0x20000 (131072) bytes, and a packet size\r\nthat can only be 188 or 204, what is the largest packet aligned buffer\r\nallowed?\r\n\r\nUsing the knowledge from above that 9588 bytes is the smallest multiple\r\nof both 188 and 204, it's simply 131072\/9588*9588 (again where the\r\ndivision is integer division). So the answer is 124644 (0x1E6E4).\r\n\r\nOther numbers of interest:\r\n- 196=188+8(64 bits is 8 bytes) for a 188 byte packet with a 64 bit\r\ntimestamp.\r\n- 212=204+8 for a 204 byte packet with a 64 bit timestamp.\r\n- 512 bytes is a common write size divisor for hard drives.\r\n- 192=188+4(32 bits is 4 bytes) for the MPEG stride (MPEG 2 transport\r\nstride?) format (HDV).\r\n- 4 bytes (32 bits) seems to be a preferred DMA number (the PCI bus is\r\nalways at least 32 bits wide).\r\n- 8 bytes (64 bits) might be preferred for certain DMA.\r\n\r\nI'll probably write myself up a quick reference. When programming, you\r\ncan have the program calculate the right numbers given any buffer size,\r\npacket size or other factor.\r\nOriginally from: <a href=\"http:\/\/www.boxheap.net\/ddaniels\/notes\/20050820.txt\">http:\/\/www.boxheap.net\/ddaniels\/notes\/20050820.txt<\/a><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>One of the things I&#8217;ve been thinking about writing about is interesting and common math problems. I&#8217;ll start with some easy ones that I&#8217;ve had to do at work (no trade secrets, just common math in the trade). Notes: &#8211; I&#8217;ll use the prefix &#8220;0x&#8221; to denote that the number is written in hex notation. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.boxheap.net\/ddaniels\/blog\/wp-json\/wp\/v2\/posts\/10"}],"collection":[{"href":"https:\/\/www.boxheap.net\/ddaniels\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.boxheap.net\/ddaniels\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.boxheap.net\/ddaniels\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.boxheap.net\/ddaniels\/blog\/wp-json\/wp\/v2\/comments?post=10"}],"version-history":[{"count":1,"href":"https:\/\/www.boxheap.net\/ddaniels\/blog\/wp-json\/wp\/v2\/posts\/10\/revisions"}],"predecessor-version":[{"id":11,"href":"https:\/\/www.boxheap.net\/ddaniels\/blog\/wp-json\/wp\/v2\/posts\/10\/revisions\/11"}],"wp:attachment":[{"href":"https:\/\/www.boxheap.net\/ddaniels\/blog\/wp-json\/wp\/v2\/media?parent=10"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.boxheap.net\/ddaniels\/blog\/wp-json\/wp\/v2\/categories?post=10"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.boxheap.net\/ddaniels\/blog\/wp-json\/wp\/v2\/tags?post=10"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}