]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
devlink: Introduce new attribute 'tx_weight' to devlink-rate
authorMichal Wilczynski <michal.wilczynski@intel.com>
Thu, 1 Dec 2022 10:26:25 +0000 (11:26 +0100)
committerDavid Ahern <dsahern@kernel.org>
Sat, 3 Dec 2022 17:47:06 +0000 (10:47 -0700)
To fully utilize hierarchical QoS algorithm new attribute 'tx_weight'
needs to be introduced. Weight attribute allows for usage of Weighted
Fair Queuing arbitration scheme among siblings. This arbitration
scheme can be used simultaneously with the strict priority.

Introduce ability to configure tx_weight from devlink userspace
utility. Make the new attribute optional.

Example commands:
$ devlink port function rate add pci/0000:4b:00.0/node_custom \
  tx_weight 50 parent node_0

$ devlink port function rate set pci/0000:4b:00.0/2 tx_weight 20

Signed-off-by: Michal Wilczynski <michal.wilczynski@intel.com>
Reviewed-by: Wojciech Drewek <wojciech.drewek@intel.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
devlink/devlink.c

index 5d3fd96954bb922fcf2f1a26659042244b9d359c..4a5eee7a13e8840f0339f031b7332e2ff4123d75 100644 (file)
@@ -296,6 +296,7 @@ static void ifname_map_free(struct ifname_map *ifname_map)
 #define DL_OPT_LINECARD_TYPE   BIT(53)
 #define DL_OPT_SELFTESTS       BIT(54)
 #define DL_OPT_PORT_FN_RATE_TX_PRIORITY        BIT(55)
+#define DL_OPT_PORT_FN_RATE_TX_WEIGHT  BIT(56)
 
 struct dl_opts {
        uint64_t present; /* flags of present items */
@@ -355,6 +356,7 @@ struct dl_opts {
        uint64_t rate_tx_share;
        uint64_t rate_tx_max;
        uint32_t rate_tx_priority;
+       uint32_t rate_tx_weight;
        char *rate_node_name;
        const char *rate_parent_node;
        uint32_t linecard_index;
@@ -2076,6 +2078,13 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
                        if (err)
                                return err;
                        o_found |= DL_OPT_PORT_FN_RATE_TX_PRIORITY;
+               } else if (dl_argv_match(dl, "tx_weight") &&
+                          (o_all & DL_OPT_PORT_FN_RATE_TX_WEIGHT)) {
+                       dl_arg_inc(dl);
+                       err = dl_argv_uint32_t(dl, &opts->rate_tx_weight);
+                       if (err)
+                               return err;
+                       o_found |= DL_OPT_PORT_FN_RATE_TX_WEIGHT;
                } else if (dl_argv_match(dl, "parent") &&
                           (o_all & DL_OPT_PORT_FN_RATE_PARENT)) {
                        dl_arg_inc(dl);
@@ -2347,6 +2356,9 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
        if (opts->present & DL_OPT_PORT_FN_RATE_TX_PRIORITY)
                mnl_attr_put_u32(nlh, DEVLINK_ATTR_RATE_TX_PRIORITY,
                                 opts->rate_tx_priority);
+       if (opts->present & DL_OPT_PORT_FN_RATE_TX_WEIGHT)
+               mnl_attr_put_u32(nlh, DEVLINK_ATTR_RATE_TX_WEIGHT,
+                                opts->rate_tx_weight);
        if (opts->present & DL_OPT_PORT_FN_RATE_TX_MAX)
                mnl_attr_put_u64(nlh, DEVLINK_ATTR_RATE_TX_MAX,
                                 opts->rate_tx_max);
@@ -4974,6 +4986,13 @@ static void pr_out_port_fn_rate(struct dl *dl, struct nlattr **tb)
                        print_uint(PRINT_ANY, "tx_priority",
                                   " tx_priority %u", priority);
        }
+       if (tb[DEVLINK_ATTR_RATE_TX_WEIGHT]) {
+               uint32_t weight =
+                       mnl_attr_get_u32(tb[DEVLINK_ATTR_RATE_TX_WEIGHT]);
+               if (weight)
+                       print_uint(PRINT_ANY, "tx_weight",
+                                  " tx_weight %u", weight);
+       }
        if (tb[DEVLINK_ATTR_RATE_PARENT_NODE_NAME]) {
                const char *parent =
                        mnl_attr_get_str(tb[DEVLINK_ATTR_RATE_PARENT_NODE_NAME]);
@@ -5005,12 +5024,12 @@ static void cmd_port_fn_rate_help(void)
        pr_err("Usage: devlink port function rate help\n");
        pr_err("       devlink port function rate show [ DEV/{ PORT_INDEX | NODE_NAME } ]\n");
        pr_err("       devlink port function rate add DEV/NODE_NAME\n");
-       pr_err("               [ tx_share VAL ][ tx_max VAL ][ tx_priority N ][ { parent NODE_NAME | noparent } ]\n");
+       pr_err("               [ tx_share VAL ][ tx_max VAL ][ tx_priority N ][ tx_weight N ][ { parent NODE_NAME | noparent } ]\n");
        pr_err("       devlink port function rate del DEV/NODE_NAME\n");
        pr_err("       devlink port function rate set DEV/{ PORT_INDEX | NODE_NAME }\n");
-       pr_err("               [ tx_share VAL ][ tx_max VAL ][ tx_priority N ][ { parent NODE_NAME | noparent } ]\n\n");
+       pr_err("               [ tx_share VAL ][ tx_max VAL ][ tx_priority N ][ tx_weight N ][ { parent NODE_NAME | noparent } ]\n\n");
        pr_err("       VAL - float or integer value in units of bits or bytes per second (bit|bps)\n");
-       pr_err("       N - integer representing priority of the node among siblings\n");
+       pr_err("       N - integer representing priority/weight of the node among siblings\n");
        pr_err("       and SI (k-, m-, g-, t-) or IEC (ki-, mi-, gi-, ti-) case-insensitive prefix.\n");
        pr_err("       Bare number, means bits per second, is possible.\n\n");
        pr_err("       For details refer to devlink-rate(8) man page.\n");
@@ -5070,7 +5089,8 @@ static int cmd_port_fn_rate_add(struct dl *dl)
 
        err = dl_argv_parse(dl, DL_OPT_PORT_FN_RATE_NODE_NAME,
                            DL_OPT_PORT_FN_RATE_TX_SHARE | DL_OPT_PORT_FN_RATE_TX_MAX |
-                           DL_OPT_PORT_FN_RATE_TX_PRIORITY);
+                           DL_OPT_PORT_FN_RATE_TX_PRIORITY |
+                           DL_OPT_PORT_FN_RATE_TX_WEIGHT);
        if (err)
                return err;
 
@@ -5127,6 +5147,9 @@ static int port_fn_get_rates_cb(const struct nlmsghdr *nlh, void *data)
        if (tb[DEVLINK_ATTR_RATE_TX_PRIORITY])
                opts->rate_tx_priority =
                        mnl_attr_get_u32(tb[DEVLINK_ATTR_RATE_TX_PRIORITY]);
+       if (tb[DEVLINK_ATTR_RATE_TX_WEIGHT])
+               opts->rate_tx_weight =
+                       mnl_attr_get_u32(tb[DEVLINK_ATTR_RATE_TX_WEIGHT]);
        return MNL_CB_OK;
 }
 
@@ -5141,6 +5164,7 @@ static int cmd_port_fn_rate_set(struct dl *dl)
                                DL_OPT_PORT_FN_RATE_TX_SHARE |
                                DL_OPT_PORT_FN_RATE_TX_MAX |
                                DL_OPT_PORT_FN_RATE_TX_PRIORITY |
+                               DL_OPT_PORT_FN_RATE_TX_WEIGHT |
                                DL_OPT_PORT_FN_RATE_PARENT);
        if (err)
                return err;