dpif: Optimize no-actions case in dpif_execute().
authorBen Pfaff <blp@nicira.com>
Wed, 8 Apr 2009 16:45:43 +0000 (09:45 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 8 Apr 2009 17:36:21 +0000 (10:36 -0700)
If there are no actions, then the packet will get dropped in the kernel,
so there's no point in making the system call at all.

lib/dpif.c

index 4da55332ade014a441e9d215153d54093dba35a6..119b40c3cb877b8b3989d558b1e4dd3fb898f21b 100644 (file)
@@ -558,16 +558,20 @@ dpif_execute(struct dpif *dpif, uint16_t in_port,
              const union odp_action actions[], size_t n_actions,
              const struct ofpbuf *buf)
 {
-    struct odp_execute execute;
     int error;
 
-    memset(&execute, 0, sizeof execute);
-    execute.in_port = in_port;
-    execute.actions = (union odp_action *) actions;
-    execute.n_actions = n_actions;
-    execute.data = buf->data;
-    execute.length = buf->size;
-    error = do_ioctl(dpif, ODP_EXECUTE, NULL, &execute);
+    if (n_actions > 0) {
+        struct odp_execute execute;
+        memset(&execute, 0, sizeof execute);
+        execute.in_port = in_port;
+        execute.actions = (union odp_action *) actions;
+        execute.n_actions = n_actions;
+        execute.data = buf->data;
+        execute.length = buf->size;
+        error = do_ioctl(dpif, ODP_EXECUTE, NULL, &execute);
+    } else {
+        error = 0;
+    }
 
     if (!(error ? VLOG_DROP_WARN(&error_rl) : VLOG_DROP_DBG(&dpmsg_rl))) {
         struct ds ds = DS_EMPTY_INITIALIZER;