[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 13 of 14] libxl: add NIC QoS parameters



# HG changeset patch
# User David Scott <dave.scott@xxxxxxxxxxxxx>
# Date 1301507668 -3600
# Node ID 2501899ab12fcc128ac62b0319b7a6f0b8982a42
# Parent  62443233adf0d2319da50210057041380d7bd07f
libxl: add NIC QoS parameters

The parameters are:
  qos_kb_per_sec:     maximum rate in KiB/sec
  qos_timeslice_usec: time period over which the average rate is enforced in
                      usec

One can now execute commands like
  xl network-attach ... rate=1024,50000
which should impose an average limit of 1MiB/sec, over intervals of 50ms

The "rate" key in the network backend is interpreted by netback. It wants:
  bytes_per_interval, interval_length

Signed-off-by: David Scott <dave.scott@xxxxxxxxxxxxx>

diff -r 62443233adf0 -r 2501899ab12f tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Wed Mar 30 18:54:28 2011 +0100
+++ b/tools/libxl/libxl.c       Wed Mar 30 18:54:28 2011 +0100
@@ -1194,6 +1194,8 @@ int libxl_device_nic_init(libxl_device_n
                libxl_xen_script_dir_path()) < 0 )
         return ERROR_FAIL;
     nic_info->nictype = NICTYPE_IOEMU;
+    nic_info->qos_kb_per_sec = 0;
+    nic_info->qos_timeslice_usec = 0;
     return 0;
 }
 
@@ -1205,6 +1207,7 @@ int libxl_device_nic_add(libxl_ctx *ctx,
     libxl__device device;
     char *dompath, **l;
     unsigned int nb, rc;
+    uint32_t bytes_per_interval; 
 
     front = flexarray_make(16, 1);
     if (!front) {
@@ -1263,6 +1266,14 @@ int libxl_device_nic_add(libxl_ctx *ctx,
     flexarray_append(back, libxl__strdup(&gc, nic->bridge));
     flexarray_append(back, "handle");
     flexarray_append(back, libxl__sprintf(&gc, "%d", nic->devid));
+    if (nic->qos_timeslice_usec > 0) {
+        bytes_per_interval = (uint32_t) 
+            (((uint64_t)nic->qos_kb_per_sec * 1024L * 
+              (uint64_t)nic->qos_timeslice_usec) / 1000000L);
+        flexarray_append(back, "rate");
+        flexarray_append(back, libxl__sprintf(&gc, "%u,%u", 
+            bytes_per_interval, nic->qos_timeslice_usec));
+    }
 
     flexarray_append(front, "backend-id");
     flexarray_append(front, libxl__sprintf(&gc, "%d", nic->backend_domid));
diff -r 62443233adf0 -r 2501899ab12f tools/libxl/libxl.idl
--- a/tools/libxl/libxl.idl     Wed Mar 30 18:54:28 2011 +0100
+++ b/tools/libxl/libxl.idl     Wed Mar 30 18:54:28 2011 +0100
@@ -225,6 +225,8 @@ libxl_device_nic = Struct("device_nic", 
     ("ifname", string),
     ("script", string),
     ("nictype", libxl_nic_type),
+    ("qos_kb_per_sec", uint32, False, "maximum rate in KiB/sec"),
+    ("qos_timeslice_usec", uint32, False, "time period over which the rate is 
enforced in usec"),
     ])
 
 libxl_device_net2 = Struct("device_net2", [
diff -r 62443233adf0 -r 2501899ab12f tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Wed Mar 30 18:54:28 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Wed Mar 30 18:54:28 2011 +0100
@@ -880,7 +880,10 @@ static void parse_config_data(const char
                         nic->backend_domid = 0;
                     }
                 } else if (!strcmp(p, "rate")) {
-                    fprintf(stderr, "the rate parameter for vifs is currently 
not supported\n");
+                    if (sscanf(p2 + 1, "%"PRIu32",%"PRIu32, 
&(nic->qos_kb_per_sec), &(nic->qos_timeslice_usec)) != 2) {
+                        fprintf(stderr, "Specified rate parameter needs to 
take the form: kb_per_sec,timeslice_usec\n");
+                        break;
+                    }
                 } else if (!strcmp(p, "accel")) {
                     fprintf(stderr, "the accel parameter for vifs is currently 
not supported\n");
                 }
@@ -4298,6 +4301,10 @@ int main_networkattach(int argc, char **
             free(nic.model);
             nic.model = strdup((*argv) + 6);
         } else if (!strncmp("rate=", *argv, 5)) {
+            if (sscanf((*argv) + 5, "%u,%u", &(nic.qos_kb_per_sec), 
&(nic.qos_timeslice_usec)) != 2) {
+                fprintf(stderr, "Specified rate parameter needs to take the 
form: kb_per_sec,timeslice_usec\n");
+                return 1;
+            }
         } else if (!strncmp("accel=", *argv, 6)) {
         } else {
             fprintf(stderr, "unrecognized argument `%s'\n", *argv);

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.