pastebin - collaborative debugging tool
rovema.kpaste.net RSS


libigbavb debug code
Posted by Anonymous on Tue 25th Jun 2024 10:52
raw | new post
view followups (newest first): libigbavb debug code by Anonymous
modification of post by Anonymous (view diff)

  1. diff --git a/lib/Makefile b/lib/Makefile
  2. index 8a0c415..6aebf3b 100644
  3. --- a/lib/Makefile
  4. +++ b/lib/Makefile
  5. @@ -1,7 +1,7 @@
  6.  OBJS=igb
  7.  INCL=e1000_82575.h e1000_defines.h e1000_hw.h e1000_osdep.h e1000_regs.h igb.h
  8.  AVBLIB=libigb.a
  9. -#CFLAGS=-ggdb
  10. +CFLAGS=-ggdb -Wall
  11.  
  12.  CC?=gcc
  13.  RANLIB?=ranlib
  14. diff --git a/lib/igb.c b/lib/igb.c
  15. index 647234f..90f4062 100644
  16. --- a/lib/igb.c
  17. +++ b/lib/igb.c
  18. @@ -51,12 +51,43 @@
  19.  #include <semaphore.h>
  20.  #include <pthread.h>
  21.  
  22. +#define USE_DPRINTF 1
  23. +
  24. +#ifdef USE_DPRINTF
  25. +#include <stdarg.h>
  26. +#endif
  27. +
  28.  #include "e1000_hw.h"
  29.  #include "e1000_82575.h"
  30.  #include "igb_internal.h"
  31.  
  32.  #undef DEBUG
  33.  
  34. +#ifdef USE_DPRINTF
  35. +int g_debug_level = 2;
  36. +
  37. +#define DPRINTF_LEVEL_ENABLED(level) ((level) <= g_debug_level)
  38. +#define DPRINTF(level, args) \
  39. +       { \
  40. +               if (DPRINTF_LEVEL_ENABLED(level)) { \
  41. +                       int saved_errno = errno; \
  42. +                       dprintf_out args; \
  43. +                       errno = saved_errno; \
  44. +               } \
  45. +       }
  46. +
  47. +void dprintf_out(const char *fmt, ...)
  48. +{
  49. +       const char buffer[1024];
  50. +       va_list args;
  51. +       va_start(args, fmt);
  52. +       (void)vsnprintf(buffer, sizeof(buffer), fmt, args);
  53. +       syslog(LOG_DAEMON|LOG_ERR, buffer);
  54. +       va_end(args);
  55. +}
  56. +#endif /* USE_DPRINTF */
  57. +
  58. +
  59.  /*********************************************************************
  60.   *  PCI Device ID Table
  61.   *
  62. @@ -1008,8 +1039,10 @@ int igb_xmit(device_t *dev, unsigned int queue_index, struct igb_packet *packet)
  63.         if (packet == NULL)
  64.                 return -EINVAL;
  65.  
  66. -       if (igb_lock(dev) != 0)
  67. +       if (igb_lock(dev) != 0) {
  68. +               DPRINTF(1, ("igb_xmit: igb_lock() failed, errno=%d\n", errno));
  69.                 return errno;
  70. +       }
  71.  
  72.         packet->next = NULL; /* used for cleanup */
  73.  
  74. @@ -1100,8 +1133,10 @@ int igb_xmit(device_t *dev, unsigned int queue_index, struct igb_packet *packet)
  75.         ++txr->tx_packets;
  76.  
  77.  unlock:
  78. -       if (igb_unlock(dev) != 0)
  79. +       if (igb_unlock(dev) != 0) {
  80. +               DPRINTF(1, ("igb_xmit: igb_unlock() failed, errno=%d\n", errno));
  81.                 return errno;
  82. +       }
  83.  
  84.         return error;
  85.  }
  86. @@ -1179,11 +1214,15 @@ int igb_lock(device_t *dev)
  87.                 case 0:
  88.                         break;
  89.                 case EOWNERDEAD:
  90. +                       DPRINTF(0, ("igb_lock: trying to recover mutex %p\n", adapter->memlock));
  91.                         // some process terminated without unlocking the mutex
  92. -                       if (pthread_mutex_consistent(adapter->memlock) != 0)
  93. +                       if (pthread_mutex_consistent(adapter->memlock) != 0) {
  94. +                               DPRINTF(0, ("igb_lock: pthread_mutex_consistent() failed, errno=%d\n", errno));
  95.                                 return -errno;
  96. +                       }
  97.                         break;
  98.                 default:
  99. +                       DPRINTF(0, ("igb_lock: pthread_mutex_lock() failed, errno=%d\n", errno));
  100.                         return -errno;
  101.                         break;
  102.         }
  103. @@ -2486,6 +2525,8 @@ static int igb_create_lock(struct adapter *adapter)
  104.         bool attr_allocated = false;
  105.         pthread_mutexattr_t attr;
  106.  
  107. +       DPRINTF(2, ("--> igb_create_lock(adapter=%p)\n", adapter));
  108. +
  109.         if (!adapter) {
  110.                 errno = EINVAL;
  111.                 goto err;
  112. @@ -2541,13 +2582,17 @@ static int igb_create_lock(struct adapter *adapter)
  113.         fl.l_len = 1;
  114.         fl.l_pid = getpid();
  115.  
  116. -       if (fcntl(fd, F_SETLKW, &fl) != 0)
  117. +       if (fcntl(fd, F_SETLKW, &fl) != 0) {
  118. +               DPRINTF(1, ("igb_create_lock: F_SETLKW failed, errno=%d\n", errno));
  119.                 goto err;
  120. +       }
  121.  
  122.         locked = true;
  123.  
  124. -       if (fstat(fd, &stat) != 0)
  125. +       if (fstat(fd, &stat) != 0) {
  126. +               DPRINTF(1, ("igb_create_lock: fstat() failed, errno=%d\n", errno));
  127.                 goto err;
  128. +       }
  129.  
  130.         if (stat.st_size == 0) { // file is empty, do initialization
  131.                 /*
  132. @@ -2604,5 +2649,7 @@ err:
  133.                 (void) close(fd);
  134.         }
  135.  
  136. +       DPRINTF(2, ("<-- igb_create_lock, error=%d\n", (int)error));
  137. +
  138.         return error;
  139.  }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at