3 Replies Latest reply on Feb 22, 2013 7:00 AM by Nil

    MPB reading gives incorrect result

    Nil

      Hi,

       

      I have some questions regarding MPB behaviour.

      In my test program I have allocated MPB memory using MPBalloc from config.c/h (provided with AccessFPGA program). Then I create local buffer to hold data and fill it up with user provided string or latter and using memcpy_put I write this buffer to MPB and it works as expected.

      Assuming I wrote “Hello ”  into my private buffer (size 32) then use memcpy_put to copy it into MPB then the content of MPB looks as follow (using sccDump)

       

      0000000000000000 | 68 65 6c 6c 6f 20 68 65  | hello he

      0000000000000008 | 6c 6c 6f 20 68 65 6c 6c  | llo hell

      0000000000000010 | 6f 20 68 65 6c 6c 6f 20   | o hello

      0000000000000018 | 68 65 6c 6c 6f 20 68 65  | hello he

      0000000000000020 | 00 00 00 00 00 00 00 00 | ........

      0000000000000028 | 00 00 00 00 00 00 00 00 | ........

       

      For reading the MPB I would do opposite where I use memcpy_get to copy content of MPB to private buffer but the results is

       

      hello hehello hehello hehello he

       

      whereas expected result is

       

      hello hello hello hello hello he

       

      Any ideas or suggestion about what is going wrong?

       

      I have attached the source code as well.

       

      Thanks,

      Nil

        • 1. Re: MPB reading gives incorrect result
          JanArneSobania

          Hi Nil,

           

          which version of sccLinux are you running your tests on? I think this phenomenon has already been observed before, but unfortunately I cannot find the older discussion at the moment. If I remember correctly, it was related to the caching type specified in the page tables when mapping the MPB. It seems the MPBs do not answer certain read requests correctly, but merely duplicate the first 8 bytes throughout one cacheline.

           

          I also read your test program, but in my opinion it is fine; there is nothing in there that could cause this error. However, I see some other problems:

           

          void readFromMpb(int core, int size){

            char *result = (char*) malloc (size);

            memcpy_get((void*)result, (void*)mpbs[core],size);

            result[size]=0;

           

          Apart from not checking the result of malloc for NULL, the last line writes to the first byte after the end of the buffer.

           

          void writeToMpb(int core, int size,char *str){

            char *buf = (char*) malloc (size);

            int len = strlen(str);

            printf("%d %s\n\n",len,str);

            if(len == 1){

              memset(buf,(char)*str, size);

            }else{

              int i;

              for(i=0; i <=size; i+=len){

                memcpy(buf+i,str,len);

              }

            }

           

            buf[size] = 0;

           

          Same problems as above, plus another buffer overflow (memcpy may write beyond the end of the buffer). Try allocating "size+len+1" bytes instead. And you may want to change "if(len == 1)" to "if(len <= 1)", just in case someone passes in a string of length zero.

           

          Regards,

          Jan-Arne

          • 2. Re: MPB reading gives incorrect result
            JanArneSobania

            Here is the discussion I was referring to: http://communities.intel.com/message/133047

             

            The problem is not related to the MPB per se, but rather to using MPBT+PCD in the page table.

             

            Regards,

            Jan-Arne

            • 3. Re: MPB reading gives incorrect result
              Nil

              Hi,

               

              I had a look at that discussion as well but i could not reach any conclusion as i was not setting any flags so i was not sure if it would be applicable to this case as well or not?

               

              i am using sccKit 1.4.2.2 and linux_3.1.4

               

              Same problems as above, plus another buffer overflow (memcpy may write beyond the end of the buffer). Try allocating "size+len+1" bytes instead.And you may want to change "if(len == 1)" to "if(len <= 1)", just in case someone passes in a string of length zero.

               

              Regards,

              Jan-Arne

              will change that