diff mbox series

[ovs-dev,v4,1/2] netdev-dpdk: add dpdk support to the if-notifier API

Message ID 20191031121225.128149.83785.stgit@netdev64
State Superseded
Headers show
Series [ovs-dev,v4,1/2] netdev-dpdk: add dpdk support to the if-notifier API | expand

Commit Message

Eelco Chaudron Oct. 31, 2019, 12:12 p.m. UTC
This patch adds support for DPDK to notify link layer changes trough
the if_notifier_xxx() APIs.

Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
---
 lib/automake.mk        |    4 ++
 lib/if-notifier-dpdk.c |   82 ++++++++++++++++++++++++++++++++++++++++++++++++
 lib/if-notifier-dpdk.h |   46 +++++++++++++++++++++++++++
 lib/if-notifier.c      |   21 +++++++++++-
 4 files changed, 149 insertions(+), 4 deletions(-)
 create mode 100644 lib/if-notifier-dpdk.c
 create mode 100644 lib/if-notifier-dpdk.h

Comments

0-day Robot Oct. 31, 2019, 12:59 p.m. UTC | #1
Bleep bloop.  Greetings Eelco Chaudron, I am a robot and I have tried out your patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


checkpatch:
WARNING: Line is 80 characters long (recommended limit is 79)
#70 FILE: lib/if-notifier-dpdk.c:24:
static struct ovs_list dpdk_all_notifiers OVS_GUARDED_BY(dpdk_notifiers_mutex) \

Lines checked: 238, Warnings: 1, Errors: 0


Please check this out.  If you feel there has been an error, please email aconole@redhat.com

Thanks,
0-day Robot
Ilya Maximets Oct. 31, 2019, 2:21 p.m. UTC | #2
On 31.10.2019 13:12, Eelco Chaudron wrote:
> This patch adds support for DPDK to notify link layer changes trough
> the if_notifier_xxx() APIs.
> 
> Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
> ---
>   lib/automake.mk        |    4 ++
>   lib/if-notifier-dpdk.c |   82 ++++++++++++++++++++++++++++++++++++++++++++++++
>   lib/if-notifier-dpdk.h |   46 +++++++++++++++++++++++++++
>   lib/if-notifier.c      |   21 +++++++++++-
>   4 files changed, 149 insertions(+), 4 deletions(-)
>   create mode 100644 lib/if-notifier-dpdk.c
>   create mode 100644 lib/if-notifier-dpdk.h


Looking at all of this code I think that it might be too heavy
for just a single function to increment single sequence number.

Another approach:
Maybe we could just call rtnetlink_report_link() as a workaround.
netdev-dpdk is Linux dependent right now anyway.
What do you think?

Best regards, Ilya Maximets.
Eelco Chaudron Oct. 31, 2019, 2:26 p.m. UTC | #3
On 31 Oct 2019, at 15:21, Ilya Maximets wrote:

> On 31.10.2019 13:12, Eelco Chaudron wrote:
>> This patch adds support for DPDK to notify link layer changes trough
>> the if_notifier_xxx() APIs.
>>
>> Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
>> ---
>>   lib/automake.mk        |    4 ++
>>   lib/if-notifier-dpdk.c |   82 
>> ++++++++++++++++++++++++++++++++++++++++++++++++
>>   lib/if-notifier-dpdk.h |   46 +++++++++++++++++++++++++++
>>   lib/if-notifier.c      |   21 +++++++++++-
>>   4 files changed, 149 insertions(+), 4 deletions(-)
>>   create mode 100644 lib/if-notifier-dpdk.c
>>   create mode 100644 lib/if-notifier-dpdk.h
>
>
> Looking at all of this code I think that it might be too heavy
> for just a single function to increment single sequence number.
>
> Another approach:
> Maybe we could just call rtnetlink_report_link() as a workaround.
> netdev-dpdk is Linux dependent right now anyway.
> What do you think?

That would work, but it’s not really thread safe, as its will be 
called from the eal interrupt thread

//Eelco
diff mbox series

Patch

diff --git a/lib/automake.mk b/lib/automake.mk
index 17b36b4..add04e7 100644
--- a/lib/automake.mk
+++ b/lib/automake.mk
@@ -395,6 +395,7 @@  lib_libopenvswitch_la_SOURCES += \
 	lib/dpif-netlink-rtnl.h \
 	lib/if-notifier.c \
 	lib/if-notifier.h \
+	lib/if-notifier-dpdk.h \
 	lib/netdev-linux.c \
 	lib/netdev-linux.h \
 	lib/netdev-linux-private.h \
@@ -426,7 +427,8 @@  if DPDK_NETDEV
 lib_libopenvswitch_la_SOURCES += \
 	lib/dpdk.c \
 	lib/netdev-dpdk.c \
-	lib/netdev-offload-dpdk.c
+	lib/netdev-offload-dpdk.c \
+	lib/if-notifier-dpdk.c
 else
 lib_libopenvswitch_la_SOURCES += \
 	lib/dpdk-stub.c
diff --git a/lib/if-notifier-dpdk.c b/lib/if-notifier-dpdk.c
new file mode 100644
index 0000000..145e0e4
--- /dev/null
+++ b/lib/if-notifier-dpdk.c
@@ -0,0 +1,82 @@ 
+/*
+ * Copyright (c) 2019 Red Hat, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <config.h>
+
+#include "if-notifier-dpdk.h"
+#include "ovs-thread.h"
+#include "openvswitch/list.h"
+
+static struct ovs_mutex dpdk_notifiers_mutex = OVS_MUTEX_INITIALIZER;
+static struct ovs_list dpdk_all_notifiers OVS_GUARDED_BY(dpdk_notifiers_mutex) \
+    = OVS_LIST_INITIALIZER(&dpdk_all_notifiers);
+
+struct dpdk_notifier {
+    struct ovs_list node;
+    dpdk_notify_func *cb;
+    void *aux;
+};
+
+struct dpdk_notifier *
+dpdk_notifier_create(dpdk_notify_func *cb, void *aux)
+{
+    struct dpdk_notifier *new = xmalloc(sizeof *new);
+
+    ovs_mutex_lock(&dpdk_notifiers_mutex);
+
+    new->cb = cb;
+    new->aux = aux;
+    ovs_list_push_back(&dpdk_all_notifiers, &new->node);
+
+    ovs_mutex_unlock(&dpdk_notifiers_mutex);
+
+    return new;
+}
+
+void
+dpdk_notifier_destroy(struct dpdk_notifier *notifier)
+{
+    if (!notifier) {
+        return;
+    }
+
+    ovs_mutex_lock(&dpdk_notifiers_mutex);
+
+    ovs_list_remove(&notifier->node);
+    free(notifier);
+
+    ovs_mutex_unlock(&dpdk_notifiers_mutex);
+}
+
+void
+dpdk_notifierr_report_link(void)
+{
+    struct dpdk_notifier *notifier;
+
+    ovs_mutex_lock(&dpdk_notifiers_mutex);
+
+    LIST_FOR_EACH (notifier, node, &dpdk_all_notifiers) {
+        if (!notifier->cb) {
+            continue;
+        }
+
+        notifier->cb(notifier->aux);
+    }
+
+    ovs_mutex_unlock(&dpdk_notifiers_mutex);
+}
+
+
diff --git a/lib/if-notifier-dpdk.h b/lib/if-notifier-dpdk.h
new file mode 100644
index 0000000..19cf36e
--- /dev/null
+++ b/lib/if-notifier-dpdk.h
@@ -0,0 +1,46 @@ 
+/*
+ * Copyright (c) 2019 Red Hat, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IF_NOTIFIER_DPDK_H
+#define IF_NOTIFIER_DPDK_H 1
+
+typedef void dpdk_notify_func(void *aux);
+
+struct dpdk_notifier;
+
+#ifdef DPDK_NETDEV
+
+struct dpdk_notifier *dpdk_notifier_create(dpdk_notify_func *cb, void *aux);
+void dpdk_notifier_destroy(struct dpdk_notifier *notifier);
+void dpdk_notifierr_report_link(void);
+
+#else
+
+static inline struct dpdk_notifier *dpdk_notifier_create(
+    dpdk_notify_func *cb OVS_UNUSED, void *aux OVS_UNUSED)
+{
+    return NULL;
+}
+
+static inline void dpdk_notifier_destroy(
+    struct dpdk_notifier *notifier OVS_UNUSED)
+{
+}
+
+#endif
+
+
+#endif /* if-notifier-dpdk.h */
diff --git a/lib/if-notifier.c b/lib/if-notifier.c
index 9a64f9b..4ecd559 100644
--- a/lib/if-notifier.c
+++ b/lib/if-notifier.c
@@ -18,9 +18,11 @@ 
 #include "if-notifier.h"
 #include "rtnetlink.h"
 #include "util.h"
+#include "if-notifier-dpdk.h"
 
 struct if_notifier {
-    struct nln_notifier *notifier;
+    struct nln_notifier *nl_notifier;
+    struct dpdk_notifier *dpdk_notifier;
     if_notify_func *cb;
     void *aux;
 };
@@ -33,6 +35,15 @@  if_notifier_cb(const struct rtnetlink_change *change OVS_UNUSED, void *aux)
     notifier->cb(notifier->aux);
 }
 
+static void
+dpdk_if_notifier_cb(void *aux)
+{
+    struct if_notifier *notifier;
+    notifier = aux;
+    notifier->cb(notifier->aux);
+}
+
+
 struct if_notifier *
 if_notifier_create(if_notify_func *cb, void *aux)
 {
@@ -40,7 +51,10 @@  if_notifier_create(if_notify_func *cb, void *aux)
     notifier = xmalloc(sizeof *notifier);
     notifier->cb = cb;
     notifier->aux = aux;
-    notifier->notifier = rtnetlink_notifier_create(if_notifier_cb, notifier);
+    notifier->nl_notifier = rtnetlink_notifier_create(if_notifier_cb,
+                                                      notifier);
+    notifier->dpdk_notifier = dpdk_notifier_create(dpdk_if_notifier_cb,
+                                                   notifier);
     return notifier;
 }
 
@@ -48,7 +62,8 @@  void
 if_notifier_destroy(struct if_notifier *notifier)
 {
     if (notifier) {
-        rtnetlink_notifier_destroy(notifier->notifier);
+        rtnetlink_notifier_destroy(notifier->nl_notifier);
+        dpdk_notifier_destroy(notifier->dpdk_notifier);
         free(notifier);
     }
 }