data race within ptr_ring code implementation












0














I am implementing single-producer,single-consumer ptr_ring buffers. Are there really data races within this linux driver code ?



I asked this because ThreadSanitizer gives me error and my system crashes after I started the ptr_ring code implementation.



inline int push_circ_queue(struct ptr_ring * buffer, unsigned int val1, unsigned int val2)
{
int push_status;

if (!ptr_ring_full_any(buffer)) // if (not full)
{
// assigns the two values in each item
item_push[buffer->producer].val1 = val1;
item_push[buffer->producer].val2 = val2;

DEBUG_MSG(KERN_INFO "buffer->producer = %u , item_push[buffer->producer].val1 = %u , item_push[buffer->producer].val2 = %un", buffer->producer, item_push[buffer->producer].val1, item_push[buffer->producer].val2);

/* insert one item into the buffer */
push_status = ptr_ring_produce_any(buffer, &item_push[buffer->producer]);

DEBUG_MSG(KERN_INFO "push_status = %un", push_status);

return 0;
}

else return 1; // full, not enough buffer space
}

inline int pop_circ_queue(struct ptr_ring * buffer, unsigned int * val1, unsigned int * val2)
{
unsigned int head;
unsigned int tail;

/* Read index before reading contents at that index. */
head = buffer->consumer_head;
tail = buffer->consumer_tail;

if (!ptr_ring_empty_any(buffer)) // if (not empty)
{
DEBUG_MSG(KERN_INFO "Before pop, head = %u , tail = %un", head, tail);

/* extract one item from the buffer */
item_pop[tail] = *((struct item *)ptr_ring_consume_any(buffer));

// reassigns the two values in each item
*val1 = item_pop[tail].val1;
*val2 = item_pop[tail].val2;

DEBUG_MSG(KERN_INFO "val1 = %u , val2 = %un", *val1, *val2);

DEBUG_MSG(KERN_INFO "After pop, head = %u , tail = %un", buffer->consumer_head, buffer->consumer_tail);

return 0;
}

else return 1; // empty, nothing to pop from the ring
}








share



























    0














    I am implementing single-producer,single-consumer ptr_ring buffers. Are there really data races within this linux driver code ?



    I asked this because ThreadSanitizer gives me error and my system crashes after I started the ptr_ring code implementation.



    inline int push_circ_queue(struct ptr_ring * buffer, unsigned int val1, unsigned int val2)
    {
    int push_status;

    if (!ptr_ring_full_any(buffer)) // if (not full)
    {
    // assigns the two values in each item
    item_push[buffer->producer].val1 = val1;
    item_push[buffer->producer].val2 = val2;

    DEBUG_MSG(KERN_INFO "buffer->producer = %u , item_push[buffer->producer].val1 = %u , item_push[buffer->producer].val2 = %un", buffer->producer, item_push[buffer->producer].val1, item_push[buffer->producer].val2);

    /* insert one item into the buffer */
    push_status = ptr_ring_produce_any(buffer, &item_push[buffer->producer]);

    DEBUG_MSG(KERN_INFO "push_status = %un", push_status);

    return 0;
    }

    else return 1; // full, not enough buffer space
    }

    inline int pop_circ_queue(struct ptr_ring * buffer, unsigned int * val1, unsigned int * val2)
    {
    unsigned int head;
    unsigned int tail;

    /* Read index before reading contents at that index. */
    head = buffer->consumer_head;
    tail = buffer->consumer_tail;

    if (!ptr_ring_empty_any(buffer)) // if (not empty)
    {
    DEBUG_MSG(KERN_INFO "Before pop, head = %u , tail = %un", head, tail);

    /* extract one item from the buffer */
    item_pop[tail] = *((struct item *)ptr_ring_consume_any(buffer));

    // reassigns the two values in each item
    *val1 = item_pop[tail].val1;
    *val2 = item_pop[tail].val2;

    DEBUG_MSG(KERN_INFO "val1 = %u , val2 = %un", *val1, *val2);

    DEBUG_MSG(KERN_INFO "After pop, head = %u , tail = %un", buffer->consumer_head, buffer->consumer_tail);

    return 0;
    }

    else return 1; // empty, nothing to pop from the ring
    }








    share

























      0












      0








      0







      I am implementing single-producer,single-consumer ptr_ring buffers. Are there really data races within this linux driver code ?



      I asked this because ThreadSanitizer gives me error and my system crashes after I started the ptr_ring code implementation.



      inline int push_circ_queue(struct ptr_ring * buffer, unsigned int val1, unsigned int val2)
      {
      int push_status;

      if (!ptr_ring_full_any(buffer)) // if (not full)
      {
      // assigns the two values in each item
      item_push[buffer->producer].val1 = val1;
      item_push[buffer->producer].val2 = val2;

      DEBUG_MSG(KERN_INFO "buffer->producer = %u , item_push[buffer->producer].val1 = %u , item_push[buffer->producer].val2 = %un", buffer->producer, item_push[buffer->producer].val1, item_push[buffer->producer].val2);

      /* insert one item into the buffer */
      push_status = ptr_ring_produce_any(buffer, &item_push[buffer->producer]);

      DEBUG_MSG(KERN_INFO "push_status = %un", push_status);

      return 0;
      }

      else return 1; // full, not enough buffer space
      }

      inline int pop_circ_queue(struct ptr_ring * buffer, unsigned int * val1, unsigned int * val2)
      {
      unsigned int head;
      unsigned int tail;

      /* Read index before reading contents at that index. */
      head = buffer->consumer_head;
      tail = buffer->consumer_tail;

      if (!ptr_ring_empty_any(buffer)) // if (not empty)
      {
      DEBUG_MSG(KERN_INFO "Before pop, head = %u , tail = %un", head, tail);

      /* extract one item from the buffer */
      item_pop[tail] = *((struct item *)ptr_ring_consume_any(buffer));

      // reassigns the two values in each item
      *val1 = item_pop[tail].val1;
      *val2 = item_pop[tail].val2;

      DEBUG_MSG(KERN_INFO "val1 = %u , val2 = %un", *val1, *val2);

      DEBUG_MSG(KERN_INFO "After pop, head = %u , tail = %un", buffer->consumer_head, buffer->consumer_tail);

      return 0;
      }

      else return 1; // empty, nothing to pop from the ring
      }








      share













      I am implementing single-producer,single-consumer ptr_ring buffers. Are there really data races within this linux driver code ?



      I asked this because ThreadSanitizer gives me error and my system crashes after I started the ptr_ring code implementation.



      inline int push_circ_queue(struct ptr_ring * buffer, unsigned int val1, unsigned int val2)
      {
      int push_status;

      if (!ptr_ring_full_any(buffer)) // if (not full)
      {
      // assigns the two values in each item
      item_push[buffer->producer].val1 = val1;
      item_push[buffer->producer].val2 = val2;

      DEBUG_MSG(KERN_INFO "buffer->producer = %u , item_push[buffer->producer].val1 = %u , item_push[buffer->producer].val2 = %un", buffer->producer, item_push[buffer->producer].val1, item_push[buffer->producer].val2);

      /* insert one item into the buffer */
      push_status = ptr_ring_produce_any(buffer, &item_push[buffer->producer]);

      DEBUG_MSG(KERN_INFO "push_status = %un", push_status);

      return 0;
      }

      else return 1; // full, not enough buffer space
      }

      inline int pop_circ_queue(struct ptr_ring * buffer, unsigned int * val1, unsigned int * val2)
      {
      unsigned int head;
      unsigned int tail;

      /* Read index before reading contents at that index. */
      head = buffer->consumer_head;
      tail = buffer->consumer_tail;

      if (!ptr_ring_empty_any(buffer)) // if (not empty)
      {
      DEBUG_MSG(KERN_INFO "Before pop, head = %u , tail = %un", head, tail);

      /* extract one item from the buffer */
      item_pop[tail] = *((struct item *)ptr_ring_consume_any(buffer));

      // reassigns the two values in each item
      *val1 = item_pop[tail].val1;
      *val2 = item_pop[tail].val2;

      DEBUG_MSG(KERN_INFO "val1 = %u , val2 = %un", *val1, *val2);

      DEBUG_MSG(KERN_INFO "After pop, head = %u , tail = %un", buffer->consumer_head, buffer->consumer_tail);

      return 0;
      }

      else return 1; // empty, nothing to pop from the ring
      }






      drivers buffer multithreading





      share












      share










      share



      share










      asked 3 mins ago









      kevinkevin

      61




      61






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493142%2fdata-race-within-ptr-ring-code-implementation%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493142%2fdata-race-within-ptr-ring-code-implementation%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          濃尾地震

          How to rewrite equation of hyperbola in standard form

          No ethernet ip address in my vocore2