OVS stopwatches use names up to 31 bytes.  Long node and handler names
can exceed that limit and cannot then reliably be used to query samples.

Assign compact keys to stopwatch labels during graph initialization.
Store the allocated keys on nodes and handler inputs so sampling can
use them directly.  Matching labels share one timer.  Expose the keys
with their labels for appctl and update the northd and interconnection
performance tests to use them.

Assisted-by: GPT-6.2-Sol, Codex
Signed-off-by: Dumitru Ceara <[email protected]>
---
 NEWS                 |  2 ++
 lib/inc-proc-eng.c   | 63 +++++++++++++++++++++++++++++++++++++-------
 lib/inc-proc-eng.h   |  2 ++
 tests/ovn-northd.at  | 34 ++++++++++++++++--------
 tests/perf-northd.at | 34 ++++++++++++++++--------
 tests/perf-ovn-ic.at |  9 ++++---
 6 files changed, 109 insertions(+), 35 deletions(-)

diff --git a/NEWS b/NEWS
index 628d894a3f..aeba954afa 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,7 @@
 Post v26.09.0
 --------------
+   - Incremental processing stopwatches now use compact keys.
+     Use inc-engine/list-stopwatches to find the keys for show and reset.
    - ovn-nbctl lr-policy-del, when not passed a --chain value, can now delete
      matching policies with any chain value.
    - ovn-nbctl lr-policy-del will now return non-zero and emit an error
diff --git a/lib/inc-proc-eng.c b/lib/inc-proc-eng.c
index bcb0848c3b..11285b300d 100644
--- a/lib/inc-proc-eng.c
+++ b/lib/inc-proc-eng.c
@@ -18,6 +18,7 @@
 
 #include <errno.h>
 #include <getopt.h>
+#include <inttypes.h>
 #include <signal.h>
 #include <stdlib.h>
 #include <string.h>
@@ -26,6 +27,7 @@
 #include "openvswitch/dynamic-string.h"
 #include "openvswitch/hmap.h"
 #include "openvswitch/poll-loop.h"
+#include "openvswitch/shash.h"
 #include "openvswitch/vlog.h"
 #include "ovsdb-idl.h"
 #include "inc-proc-eng.h"
@@ -195,6 +197,15 @@ engine_set_log_timeout_cmd(struct unixctl_conn *conn, int 
argc OVS_UNUSED,
     unixctl_command_reply(conn, NULL);
 }
 
+#define ENGINE_STOPWATCH_MAX_NAME 31
+#define ENGINE_STOPWATCH_PREFIX "@ip:"
+
+BUILD_ASSERT_DECL(sizeof ENGINE_STOPWATCH_PREFIX "4294967295"
+                  <= ENGINE_STOPWATCH_MAX_NAME + 1);
+
+static struct shash engine_stopwatch_keys =
+    SHASH_INITIALIZER(&engine_stopwatch_keys);
+
 static void
 engine_list_stopwatch_cmd(struct unixctl_conn *conn, int argc OVS_UNUSED,
                           const char *argv[], void *arg OVS_UNUSED)
@@ -206,13 +217,15 @@ engine_list_stopwatch_cmd(struct unixctl_conn *conn, int 
argc OVS_UNUSED,
         if (node_name && strcmp(node->name, node_name)) {
             continue;
         }
-        ds_put_format(&output_str, "%s\n", node->name);
+        ds_put_format(&output_str, "%s -> %s\n", node->name,
+                      node->stopwatch_key);
         for (size_t i = 0; i < node->n_inputs; i++) {
             struct engine_node_input *input = &node->inputs[i];
             if (!input->change_handler) {
                 continue;
             }
-            ds_put_format(&output_str, "%s\n", input->change_handler_name);
+            ds_put_format(&output_str, "%s -> %s\n",
+                          input->change_handler_name, input->stopwatch_key);
         }
     }
 
@@ -260,6 +273,21 @@ engine_disable_stopwatches_cmd(struct unixctl_conn *conn, 
int argc,
     engine_set_stopwatch_cmd(conn, argc, argv, false);
 }
 
+static const char *
+engine_register_stopwatch(const char *label)
+{
+    char *key = shash_find_data(&engine_stopwatch_keys, label);
+    if (!key) {
+        size_t n_keys = shash_count(&engine_stopwatch_keys);
+        ovs_assert(n_keys <= UINT32_MAX);
+
+        key = xasprintf(ENGINE_STOPWATCH_PREFIX"%"PRIuSIZE, n_keys);
+        stopwatch_create(key, SW_MS);
+        shash_add(&engine_stopwatch_keys, label, key);
+    }
+    return key;
+}
+
 static void
 engine_get_compute_failure_info(struct engine_node *node)
 {
@@ -283,7 +311,18 @@ engine_init(struct engine_node *node, struct engine_arg 
*arg)
             sorted_node->get_compute_failure_info =
                 engine_get_compute_failure_info;
         }
-        stopwatch_create(sorted_node->name, SW_MS);
+    }
+
+    VECTOR_FOR_EACH (&engine_nodes, sorted_node) {
+        sorted_node->stopwatch_key =
+            engine_register_stopwatch(sorted_node->name);
+        for (size_t i = 0; i < sorted_node->n_inputs; i++) {
+            struct engine_node_input *input = &sorted_node->inputs[i];
+            if (input->change_handler) {
+                input->stopwatch_key =
+                    engine_register_stopwatch(input->change_handler_name);
+            }
+        }
     }
 
     unixctl_command_register("inc-engine/show-stats", "", 0, 2,
@@ -315,7 +354,14 @@ engine_cleanup(void)
             node->cleanup(node->data);
         }
         free(node->data);
+        node->stopwatch_enabled = false;
+        node->stopwatch_key = NULL;
+        for (size_t i = 0; i < node->n_inputs; i++) {
+            node->inputs[i].stopwatch_key = NULL;
+        }
     }
+
+    shash_destroy_free_data(&engine_stopwatch_keys);
     vector_destroy(&engine_nodes);
 }
 
@@ -349,9 +395,6 @@ engine_add_input_impl(struct engine_node *node, struct 
engine_node *input,
     node->inputs[node->n_inputs].node = input;
     node->inputs[node->n_inputs].change_handler = change_handler;
     node->inputs[node->n_inputs].change_handler_name = change_handler_name;
-    if (change_handler) {
-        stopwatch_create(change_handler_name, SW_MS);
-    }
     node->n_inputs ++;
 }
 
@@ -500,11 +543,11 @@ run_recompute_callback(struct engine_node *node)
 {
     enum engine_node_state ret;
     if (node->stopwatch_enabled) {
-        stopwatch_start(node->name, time_msec());
+        stopwatch_start(node->stopwatch_key, time_msec());
     }
     ret = node->run(node, node->data);
     if (node->stopwatch_enabled) {
-        stopwatch_stop(node->name, time_msec());
+        stopwatch_stop(node->stopwatch_key, time_msec());
     }
     return ret;
 }
@@ -514,11 +557,11 @@ run_change_handler(struct engine_node *node, struct 
engine_node_input *input)
 {
     enum engine_input_handler_result ret;
     if (node->stopwatch_enabled) {
-        stopwatch_start(input->change_handler_name, time_msec());
+        stopwatch_start(input->stopwatch_key, time_msec());
     }
     ret = input->change_handler(node, node->data);
     if (node->stopwatch_enabled) {
-        stopwatch_stop(input->change_handler_name, time_msec());
+        stopwatch_stop(input->stopwatch_key, time_msec());
     }
     return ret;
 }
diff --git a/lib/inc-proc-eng.h b/lib/inc-proc-eng.h
index ece33e1beb..754002f847 100644
--- a/lib/inc-proc-eng.h
+++ b/lib/inc-proc-eng.h
@@ -214,6 +214,7 @@ struct engine_node_input {
      * and the pointers are NULL, the change handler MUST return EN_UNHANDLED.
      */
     const char *change_handler_name;
+    const char *stopwatch_key;
     enum engine_input_handler_result (*change_handler)
         (struct engine_node *node, void *data);
 };
@@ -285,6 +286,7 @@ struct engine_node {
 
     /* Whether stopwatches are enabled for this node. */
     bool stopwatch_enabled;
+    const char *stopwatch_key;
 };
 
 /* Initialize the data for the engine nodes. It calls each node's
diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at
index b459b3a7b3..ac09908bdc 100644
--- a/tests/ovn-northd.at
+++ b/tests/ovn-northd.at
@@ -25472,12 +25472,27 @@ AT_SETUP([ovn-northd - engine stopwatches 
enable/disable])
 AT_KEYWORDS([ovn])
 ovn_start
 
+northd_sw=$(as northd ovn-appctl -t ovn-northd \
+              inc-engine/list-stopwatches northd | awk 'NR == 1 {print $NF}')
+lr_nat_sw=$(as northd ovn-appctl -t ovn-northd \
+              inc-engine/list-stopwatches lr_nat | awk 'NR == 1 {print $NF}')
+AT_CHECK([test -n "$northd_sw" && test -n "$lr_nat_sw"])
+dnl Long handler labels must still resolve to a valid OVS stopwatch.
+AT_CHECK([as northd ovn-appctl -t ovn-northd inc-engine/list-stopwatches |
+          awk 'length($1) > 31 && $2 == "->" && length($NF) <= 31 {
+              print $NF
+              exit
+          }' > long-key])
+AT_CHECK([test -s long-key])
+AT_CHECK([as northd ovn-appctl -t ovn-northd stopwatch/show "$(cat long-key)"],
+         [0], [ignore])
+
+
 dnl By default, engine stopwatches are disabled.  Trigger a recompute to
 dnl ensure the engine runs, then verify that no samples were collected.
 check as northd ovn-appctl -t ovn-northd inc-engine/recompute
 check ovn-nbctl --wait=sb sync
-AT_CHECK([as northd ovn-appctl -t ovn-northd stopwatch/show northd], [0], [dnl
-Statistics for 'northd'
+AT_CHECK([as northd ovn-appctl -t ovn-northd stopwatch/show "$northd_sw" | 
grep -v '@ip:'], [0], [dnl
   Total samples: 0
   Maximum: 0 msec
   Minimum: 0 msec
@@ -25493,13 +25508,12 @@ check ovn-nbctl --wait=sb sync
 
 dnl The "northd" stopwatch should have collected samples.
 OVS_WAIT_UNTIL([
-    stats=$(as northd ovn-appctl -t ovn-northd stopwatch/show northd)
+    stats=$(as northd ovn-appctl -t ovn-northd stopwatch/show "$northd_sw")
     echo "$stats" | grep -q 'Total samples: [[1-9]]'
 ])
 
 dnl The "lr_nat" stopwatch should still have no samples.
-AT_CHECK([as northd ovn-appctl -t ovn-northd stopwatch/show lr_nat], [0], [dnl
-Statistics for 'lr_nat'
+AT_CHECK([as northd ovn-appctl -t ovn-northd stopwatch/show "$lr_nat_sw" | 
grep -v '@ip:'], [0], [dnl
   Total samples: 0
   Maximum: 0 msec
   Minimum: 0 msec
@@ -25516,7 +25530,7 @@ check ovn-nbctl --wait=sb sync
 
 dnl Now "lr_nat" should also have collected samples.
 OVS_WAIT_UNTIL([
-    stats=$(as northd ovn-appctl -t ovn-northd stopwatch/show lr_nat)
+    stats=$(as northd ovn-appctl -t ovn-northd stopwatch/show "$lr_nat_sw")
     echo "$stats" | grep -q 'Total samples: [[1-9]]'
 ])
 
@@ -25527,8 +25541,7 @@ check as northd ovn-appctl -t ovn-northd 
inc-engine/recompute
 check ovn-nbctl --wait=sb sync
 
 dnl Verify "northd" has no new samples but "lr_nat" still collects.
-AT_CHECK([as northd ovn-appctl -t ovn-northd stopwatch/show northd], [0], [dnl
-Statistics for 'northd'
+AT_CHECK([as northd ovn-appctl -t ovn-northd stopwatch/show "$northd_sw" | 
grep -v '@ip:'], [0], [dnl
   Total samples: 0
   Maximum: 0 msec
   Minimum: 0 msec
@@ -25537,7 +25550,7 @@ Statistics for 'northd'
   Long term average: 0.000000 msec
 ])
 OVS_WAIT_UNTIL([
-    stats=$(as northd ovn-appctl -t ovn-northd stopwatch/show lr_nat)
+    stats=$(as northd ovn-appctl -t ovn-northd stopwatch/show "$lr_nat_sw")
     echo "$stats" | grep -q 'Total samples: [[1-9]]'
 ])
 
@@ -25546,8 +25559,7 @@ check as northd ovn-appctl -t ovn-northd 
inc-engine/disable-stopwatch
 check as northd ovn-appctl -t ovn-northd stopwatch/reset
 check as northd ovn-appctl -t ovn-northd inc-engine/recompute
 check ovn-nbctl --wait=sb sync
-AT_CHECK([as northd ovn-appctl -t ovn-northd stopwatch/show northd], [0], [dnl
-Statistics for 'northd'
+AT_CHECK([as northd ovn-appctl -t ovn-northd stopwatch/show "$northd_sw" | 
grep -v '@ip:'], [0], [dnl
   Total samples: 0
   Maximum: 0 msec
   Minimum: 0 msec
diff --git a/tests/perf-northd.at b/tests/perf-northd.at
index 0e9253b4b5..4f2fbf9cd8 100644
--- a/tests/perf-northd.at
+++ b/tests/perf-northd.at
@@ -77,7 +77,19 @@ m4_define([PARSE_STOPWATCH], [
 # to performance results.
 #
 m4_define([PERF_RECORD_STOPWATCH], [
-    PERF_RECORD_RESULT($3, [`ovn-appctl -t northd/ovn-northd stopwatch/show $1 
| PARSE_STOPWATCH($2)`])
+    PERF_RECORD_RESULT($3, [`ovn-appctl -t northd/ovn-northd stopwatch/show 
"$1" | PARSE_STOPWATCH($2)`])
+])
+
+# PERF_RECORD_ENGINE_STOPWATCH([NODE], [METRIC], [LABEL])
+#
+# The first row maps the node itself to its stopwatch key.  Subsequent
+# rows describe its change handlers.
+m4_define([PERF_RECORD_ENGINE_STOPWATCH], [
+    engine_stopwatch=$(ovn-appctl -t northd/ovn-northd \
+                         inc-engine/list-stopwatches "$1" | \
+                         awk 'NR == 1 {print $NF}')
+    check test -n "$engine_stopwatch"
+    PERF_RECORD_STOPWATCH([$engine_stopwatch], [$2], [$3])
 ])
 
 # PERF_RECORD()
@@ -85,18 +97,18 @@ m4_define([PERF_RECORD_STOPWATCH], [
 # Append a number of metrics to performance results
 #
 m4_define([PERF_RECORD_STOP], [
-    PERF_RECORD_STOPWATCH(northd, ["Maximum"], [Maximum (NB in msec)])
-    PERF_RECORD_STOPWATCH(northd, ["Short term average"], [Average (NB in 
msec)])
-    PERF_RECORD_STOPWATCH(sync_from_sb, ["Maximum"], [Maximum (SB in msec)])
-    PERF_RECORD_STOPWATCH(sync_from_sb, ["Short term average"], [Average (SB 
in msec)])
+    PERF_RECORD_ENGINE_STOPWATCH(northd, ["Maximum"], [Maximum (NB in msec)])
+    PERF_RECORD_ENGINE_STOPWATCH(northd, ["Short term average"], [Average (NB 
in msec)])
+    PERF_RECORD_ENGINE_STOPWATCH(sync_from_sb, ["Maximum"], [Maximum (SB in 
msec)])
+    PERF_RECORD_ENGINE_STOPWATCH(sync_from_sb, ["Short term average"], 
[Average (SB in msec)])
     PERF_RECORD_STOPWATCH(ovn-northd-loop, ["Maximum"], [Maximum (northd-loop 
in msec)])
     PERF_RECORD_STOPWATCH(ovn-northd-loop, ["Short term average"], [Average 
(northd-loop in msec)])
-    PERF_RECORD_STOPWATCH(lflow, ["Maximum"], [Maximum (lflows in msec)])
-    PERF_RECORD_STOPWATCH(lflow, ["Short term average"], [Average (lflows in 
msec)])
-    PERF_RECORD_STOPWATCH(port_group, ["Maximum"], [Maximum (port_group in 
msec)])
-    PERF_RECORD_STOPWATCH(port_group, ["Short term average"], [Average 
(port_group in msec)])
-    PERF_RECORD_STOPWATCH(sync_meters, ["Maximum"], [Maximum (sync_meters in 
msec)])
-    PERF_RECORD_STOPWATCH(sync_meters, ["Short term average"], [Average 
(sync_meters in msec)])
+    PERF_RECORD_ENGINE_STOPWATCH(lflow, ["Maximum"], [Maximum (lflows in 
msec)])
+    PERF_RECORD_ENGINE_STOPWATCH(lflow, ["Short term average"], [Average 
(lflows in msec)])
+    PERF_RECORD_ENGINE_STOPWATCH(port_group, ["Maximum"], [Maximum (port_group 
in msec)])
+    PERF_RECORD_ENGINE_STOPWATCH(port_group, ["Short term average"], [Average 
(port_group in msec)])
+    PERF_RECORD_ENGINE_STOPWATCH(sync_meters, ["Maximum"], [Maximum 
(sync_meters in msec)])
+    PERF_RECORD_ENGINE_STOPWATCH(sync_meters, ["Short term average"], [Average 
(sync_meters in msec)])
 
     ovn-appctl -t northd/ovn-northd stopwatch/reset
 ])
diff --git a/tests/perf-ovn-ic.at b/tests/perf-ovn-ic.at
index e39e4e3fc7..5731a80830 100644
--- a/tests/perf-ovn-ic.at
+++ b/tests/perf-ovn-ic.at
@@ -33,10 +33,13 @@ m4_define([IC_APPCTL], [ovn-appctl -t ic/ovn-ic])
 # that engine node) to the results file.  PARSE_STOPWATCH is defined in
 # perf-northd.at.
 m4_define([PERF_IC_NODE], [
+    engine_stopwatch=$(IC_APPCTL inc-engine/list-stopwatches "$1" | \
+                         awk 'NR == 1 {print $NF}')
+    check test -n "$engine_stopwatch"
     PERF_RECORD_RESULT([$2 Maximum (msec)],
-        [`IC_APPCTL stopwatch/show $1 | PARSE_STOPWATCH(["Maximum"])`])
+        [`IC_APPCTL stopwatch/show "$engine_stopwatch" | 
PARSE_STOPWATCH(["Maximum"])`])
     PERF_RECORD_RESULT([$2 Average (msec)],
-        [`IC_APPCTL stopwatch/show $1 | PARSE_STOPWATCH(["Short term 
average"])`])
+        [`IC_APPCTL stopwatch/show "$engine_stopwatch" | 
PARSE_STOPWATCH(["Short term average"])`])
 ])
 
 # PERF_IC_NODE_INCR([NODE], [LABEL])
@@ -155,7 +158,7 @@ ic_build_scale () {
 ic_node_incr () {
     local node=$1 metric=$2 max=0 h v
     for h in $(ovn-appctl -t ic/ovn-ic inc-engine/list-stopwatches "$node" \
-               2>/dev/null | tail -n +2); do
+               2>/dev/null | awk 'NR > 1 && NF {print $NF}'); do
         v=$(ovn-appctl -t ic/ovn-ic stopwatch/show "$h" 2>/dev/null \
             | grep "$metric" | awk '{print $(NF-1)}')
         test -n "$v" || v=0
-- 
2.56.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to