Skip to contentSkip to conversation

net: Disable netmap backend when not supported

PATCH Superseded Vincenzo Maffione 3 participants 7 messages Feb 14, 2014 – Feb 21, 2014 Networking

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: Disable netmap backend when not supported

This patch fixes configure so that netmap is not compiled in if the host doesn't support an API version >= 11.

Moreover, some modifications have been done to net/netmap.c in order to reflect the current netmap API (11).

---
 configure    |  3 +++
 net/netmap.c | 57 ++++++++++++++-------------------------------------------
 2 files changed, 17 insertions(+), 43 deletions(-)
configure +3 -0
index 88133a1..61eb932 100755
@@ -2118,6 +2118,9 @@ if test "$netmap" != "no" ; then
 #include <net/if.h>
 #include <net/netmap.h>
 #include <net/netmap_user.h>
+#if (NETMAP_API < 11) || (NETMAP_API > 15)
+#error
+#endif
 int main(void) { return 0; }
 EOF
   if compile_prog "" "" ; then
net/netmap.c +14 -43

125 lines not on this page · raw message

Signature · 1 line
1.8.5.4
#1 lore raw
Quoted 17 lines · Vincenzo Maffione

This patch fixes configure so that netmap is not compiled in if the host doesn't support an API version >= 11.

Moreover, some modifications have been done to net/netmap.c in order to reflect the current netmap API (11).

---
 configure    |  3 +++
 net/netmap.c | 57 ++++++++++++++-------------------------------------------
 2 files changed, 17 insertions(+), 43 deletions(-)
configure +0 -0
index 88133a1..61eb932 100755

configure if test "$netmap" != "no" ; then · line 2123

Quoted 6 lines
configure +3 -0
@@ -2118,6 +2118,9 @@ if test "$netmap" != "no" ; then
 #include <net/if.h>
 #include <net/netmap.h>
 #include <net/netmap_user.h>
+#if (NETMAP_API < 11) || (NETMAP_API > 15)
+#error
+#endif

Why error when NETMAP_API > 15?

Quoted 22 lines
configure +0 -18
@@ -56,31 +58,6 @@ typedef struct NetmapState {
     struct iovec        iov[IOV_MAX];
 } NetmapState;
 
-#define D(format, ...)                                          \
-    do {                                                        \
-        struct timeval __xxts;                                  \
-        gettimeofday(&__xxts, NULL);                            \
-        printf("%03d.%06d %s [%d] " format "\n",                \
-                (int)__xxts.tv_sec % 1000, (int)__xxts.tv_usec, \
-                __func__, __LINE__, ##__VA_ARGS__);         \
-    } while (0)
-
-/* Rate limited version of "D", lps indicates how many per second */
-#define RD(lps, format, ...)                                    \
-    do {                                                        \
-        static int t0, __cnt;                                   \
-        struct timeval __xxts;                                  \
-        gettimeofday(&__xxts, NULL);                            \
-        if (t0 != __xxts.tv_sec) {                              \
-            t0 = __xxts.tv_sec;                                 \
-            __cnt = 0;                                          \

configure typedef struct NetmapState { · line 63

Quoted 10 lines
configure +0 -7
-        }                                                       \
-        if (__cnt++ < lps) {                                    \
-            D(format, ##__VA_ARGS__);                           \
-        }                                                       \
-    } while (0)
-
-
 #ifndef __FreeBSD__
 #define pkt_copy bcopy
 #else

Why are you deleting this?

Quoted 10 lines
configure +1 -1
@@ -237,7 +214,7 @@ static ssize_t netmap_receive(NetClientState *nc,
         return size;
     }
 
-    if (ring->avail == 0) {
+    if (nm_ring_empty(ring)) {
         /* No available slots in the netmap TX ring. */
         netmap_write_poll(s, true);
         return 0;

configure static ssize_t netmap_receive(NetClientState *nc, · line 233

Quoted 9 lines
configure +1 -2
@@ -250,8 +227,7 @@ static ssize_t netmap_receive(NetClientState *nc,
     ring->slot[i].len = size;
     ring->slot[i].flags = 0;
     pkt_copy(buf, dst, size);
-    ring->cur = NETMAP_RING_NEXT(ring, i);
-    ring->avail--;
+    ring->cur = ring->head = nm_ring_next(ring, i);
     ioctl(s->me.fd, NIOCTXSYNC, NULL);
 
     return size;

Are these changes related to the NETMAP_WITH_LIBS macro? Please do that in a separate patch so we keep the version checking change separate from the NETMAP_WITH_LIBS change.

#2 lore raw

2014-02-19 16:30 GMT+01:00 Stefan Hajnoczi <[email protected]>:

Quoted 14 lines · Vincenzo Maffione
Quoted 10 lines

This patch fixes configure so that netmap is not compiled in if the host doesn't support an API version >= 11.

Moreover, some modifications have been done to net/netmap.c in order to reflect the current netmap API (11).

---
 configure    |  3 +++
 net/netmap.c | 57

++++++++++++++-------------------------------------------

Quoted 2 lines
 2 files changed, 17 insertions(+), 43 deletions(-)
Quoted 14 lines

configure if test "$netmap" != "no" ; then · line 2123

Quoted 11 lines
configure +3 -0
index 88133a1..61eb932 100755
@@ -2118,6 +2118,9 @@ if test "$netmap" != "no" ; then
 #include <net/if.h>
 #include <net/netmap.h>
 #include <net/netmap_user.h>
+#if (NETMAP_API < 11) || (NETMAP_API > 15)
+#error
+#endif

Why error when NETMAP_API > 15?

Well, I believe Luigi can answer this question better than me, so I would wait for his answer.

Quoted 27 lines
Quoted 27 lines
configure +0 -22
@@ -56,31 +58,6 @@ typedef struct NetmapState {
     struct iovec        iov[IOV_MAX];
 } NetmapState;
 
-#define D(format, ...)                                          \
-    do {                                                        \
-        struct timeval __xxts;                                  \
-        gettimeofday(&__xxts, NULL);                            \
-        printf("%03d.%06d %s [%d] " format "\n",                \
-                (int)__xxts.tv_sec % 1000, (int)__xxts.tv_usec, \
-                __func__, __LINE__, ##__VA_ARGS__);         \
-    } while (0)
-
-/* Rate limited version of "D", lps indicates how many per second */
-#define RD(lps, format, ...)                                    \
-    do {                                                        \
-        static int t0, __cnt;                                   \
-        struct timeval __xxts;                                  \
-        gettimeofday(&__xxts, NULL);                            \
-        if (t0 != __xxts.tv_sec) {                              \
-            t0 = __xxts.tv_sec;                                 \
-            __cnt = 0;                                          \
-        }                                                       \
-        if (__cnt++ < lps) {                                    \
-            D(format, ##__VA_ARGS__);                           \
-        }                                                       \
Quoted 9 lines

configure typedef struct NetmapState { · line 63

Quoted 6 lines
configure +0 -3
-    } while (0)
-
-
 #ifndef __FreeBSD__
 #define pkt_copy bcopy
 #else

Why are you deleting this?

Because now equivalent code is contained by "netmap_user.h"

Quoted 19 lines
Quoted 19 lines
configure +2 -3
@@ -237,7 +214,7 @@ static ssize_t netmap_receive(NetClientState *nc,
         return size;
     }
 
-    if (ring->avail == 0) {
+    if (nm_ring_empty(ring)) {
         /* No available slots in the netmap TX ring. */
         netmap_write_poll(s, true);
         return 0;
@@ -250,8 +227,7 @@ static ssize_t netmap_receive(NetClientState *nc,
     ring->slot[i].len = size;
     ring->slot[i].flags = 0;
     pkt_copy(buf, dst, size);
-    ring->cur = NETMAP_RING_NEXT(ring, i);
-    ring->avail--;
+    ring->cur = ring->head = nm_ring_next(ring, i);
     ioctl(s->me.fd, NIOCTXSYNC, NULL);
 
Quoted 6 lines

configure static ssize_t netmap_receive(NetClientState *nc, · line 233

Quoted 1 line
configure +0 -0
     return size;

Are these changes related to the NETMAP_WITH_LIBS macro? Please do that in a separate patch so we keep the version checking change separate from the NETMAP_WITH_LIBS change.

Yes it is. The macro drives an #ifdef in netmap_user.h, so that we can use some new functions/macros.
Ok for the splitting. Is it necessary to prepare a patch series or can I send two different patches?

Thanks,
Vincenzo

Signature · 1 line
Vincenzo Maffione
#3 lore raw
Quoted 38 lines · Vincenzo Maffione

2014-02-19 16:30 GMT+01:00 Stefan Hajnoczi <[email protected]>:

Quoted 27 lines · Vincenzo Maffione
Quoted 26 lines
net/netmap.c +0 -22
@@ -56,31 +58,6 @@ typedef struct NetmapState {
     struct iovec        iov[IOV_MAX];
 } NetmapState;
 
-#define D(format, ...)                                          \
-    do {                                                        \
-        struct timeval __xxts;                                  \
-        gettimeofday(&__xxts, NULL);                            \
-        printf("%03d.%06d %s [%d] " format "\n",                \
-                (int)__xxts.tv_sec % 1000, (int)__xxts.tv_usec, \
-                __func__, __LINE__, ##__VA_ARGS__);         \
-    } while (0)
-
-/* Rate limited version of "D", lps indicates how many per second */
-#define RD(lps, format, ...)                                    \
-    do {                                                        \
-        static int t0, __cnt;                                   \
-        struct timeval __xxts;                                  \
-        gettimeofday(&__xxts, NULL);                            \
-        if (t0 != __xxts.tv_sec) {                              \
-            t0 = __xxts.tv_sec;                                 \
-            __cnt = 0;                                          \
-        }                                                       \
-        if (__cnt++ < lps) {                                    \
-            D(format, ##__VA_ARGS__);                           \
-        }                                                       \
Quoted 9 lines

net/netmap.c typedef struct NetmapState { · line 63

Quoted 6 lines
net/netmap.c +0 -3
-    } while (0)
-
-
 #ifndef __FreeBSD__
 #define pkt_copy bcopy
 #else

Why are you deleting this?

Quoted 1 line

Because now equivalent code is contained by "netmap_user.h"

Please mention that in the commit description.

(I guess it's too late to give them a NETMAP_* prefix since defining D() and RD() in a system header has a fair chance of causing namespace conflicts.)

Stefan

#4 lore raw
Quoted 1 line · Stefan Hajnoczi

On Wed, Feb 19, 2014 at 04:57:28PM +0100, Vincenzo Maffione wrote:

...

Quoted 5 lines

Please mention that in the commit description.

(I guess it's too late to give them a NETMAP_* prefix since defining D() and RD() in a system header has a fair chance of causing namespace conflicts.)

you are right that the naming is unfortunate and we will try to address that at a later time, removing the macros.

As partial mitigation of the problem, they are intended only for debugging (so they should only be used by lazy programmers; applications should prefer application-specific logging functions), and D(), RD() and ND() are only defined when 'NETMAP_WITH_LIBS' is defined and this should happen only in the single file that implements the netmap backend.

cheers
luigi

#5 lore raw
In reply to Stefan Hajnoczi
Quoted 14 lines · Stefan Hajnoczi
Quoted 10 lines · Vincenzo Maffione

This patch fixes configure so that netmap is not compiled in if the host doesn't support an API version >= 11.

Moreover, some modifications have been done to net/netmap.c in order to reflect the current netmap API (11).

---
 configure    |  3 +++
 net/netmap.c | 57

++++++++++++++-------------------------------------------

Quoted 2 lines
 2 files changed, 17 insertions(+), 43 deletions(-)
Quoted 14 lines

configure if test "$netmap" != "no" ; then · line 2123

Quoted 11 lines
configure +3 -0
index 88133a1..61eb932 100755
@@ -2118,6 +2118,9 @@ if test "$netmap" != "no" ; then
 #include <net/if.h>
 #include <net/netmap.h>
 #include <net/netmap_user.h>
+#if (NETMAP_API < 11) || (NETMAP_API > 15)
+#error
+#endif

Why error when NETMAP_API > 15?

this is meant to simulate a minor/major version number. We will mark minor new features with values up to 15, and if something happens that requires a change in the backend we will move above 15, at which point we will submit backend fixes and also the necessary update to ./configure

Quoted 11 lines

configure if test "$netmap" != "no" ; then

Quoted 6 lines
configure +1 -2
-    ring->cur = NETMAP_RING_NEXT(ring, i);
-    ring->avail--;
+    ring->cur = ring->head = nm_ring_next(ring, i);
     ioctl(s->me.fd, NIOCTXSYNC, NULL);
 
     return size;

Are these changes related to the NETMAP_WITH_LIBS macro? Please do that in a separate patch so we keep the version checking change separate from the NETMAP_WITH_LIBS change.

netmap version 11 and above has NETMAP_WITH_LIBS, while previous versions do not, so this ./configure change has to go together with the change in the backend.

The netmap 11 code has already been committed to the FreeBSD source repositories (for HEAD, 10 and 9) and to code.google.com/p/netmap/ (for those who want it on linux).

So there is really no point, in my opinion, to make one intermediate commit just to ./configure to disable netmap detection on FreeBSD (it is already off on linux), immediately followed by this one that uses the new feature.

Just to clarify: with one exception (fields in struct netmap_ring) the netmap changes that we have are not at the kernel/user boundary but in a library which avoids replicating long and boring code (interface name parsing, parameter setting) in applications.

Avoiding the single incompatible struct change would have been of course possible, but at the cost
extra complexity in the kernel and in userspace (to support two slightly different interfaces). Since netmap is (so far) relatively little used I thought it was more important to fix the API and keep it simple.

cheers
luigi

-----------------------------------------+-------------------------------

 Prof. Luigi RIZZO, [email protected]  . Dip. di Ing. dell'Informazione
 http://www.iet.unipi.it/~luigi/        . Universita` di Pisa
 TEL      +39-050-2211611               . via Diotisalvi 2
 Mobile   +39-338-6809875               . 56122 PISA (Italy)

-----------------------------------------+-------------------------------

#6 lore raw
Quoted 18 lines · Luigi Rizzo
Quoted 15 lines · Stefan Hajnoczi

configure if test "$netmap" != "no" ; then · line 2123

Quoted 11 lines · Vincenzo Maffione
configure +3 -0
index 88133a1..61eb932 100755
@@ -2118,6 +2118,9 @@ if test "$netmap" != "no" ; then
 #include <net/if.h>
 #include <net/netmap.h>
 #include <net/netmap_user.h>
+#if (NETMAP_API < 11) || (NETMAP_API > 15)
+#error
+#endif

Why error when NETMAP_API > 15?

Quoted 6 lines

this is meant to simulate a minor/major version number. We will mark minor new features with values up to 15, and if something happens that requires a change in the backend we will move above 15, at which point we will submit backend fixes and also the necessary update to ./configure

I see. A comment in the code would be nice to explain that.

Quoted 30 lines
Quoted 11 lines

configure if test "$netmap" != "no" ; then

Quoted 6 lines
configure +1 -2
-    ring->cur = NETMAP_RING_NEXT(ring, i);
-    ring->avail--;
+    ring->cur = ring->head = nm_ring_next(ring, i);
     ioctl(s->me.fd, NIOCTXSYNC, NULL);
 
     return size;

Are these changes related to the NETMAP_WITH_LIBS macro? Please do that in a separate patch so we keep the version checking change separate from the NETMAP_WITH_LIBS change.

netmap version 11 and above has NETMAP_WITH_LIBS, while previous versions do not, so this ./configure change has to go together with the change in the backend.

The netmap 11 code has already been committed to the FreeBSD source repositories (for HEAD, 10 and 9) and to code.google.com/p/netmap/ (for those who want it on linux).

So there is really no point, in my opinion, to make one intermediate commit just to ./configure to disable netmap detection on FreeBSD (it is already off on linux), immediately followed by this one that uses the new feature.

Just to clarify: with one exception (fields in struct netmap_ring) the netmap changes that we have are not at the kernel/user boundary but in a library which avoids replicating long and boring code (interface name parsing, parameter setting) in applications.

Quoted 6 lines

Avoiding the single incompatible struct change would have been of course possible, but at the cost
extra complexity in the kernel and in userspace (to support two slightly different interfaces). Since netmap is (so far) relatively little used I thought it was more important to fix the API and keep it simple.

Thanks for explaining. Please put justification for the NETMAP_WITH_LIBS changes in the commit description.

Stefan