xl: add support for vif rate limiting
PATCH v2 1/1 xl: add support for vif rate limiting
Hi,
This patch series implements the required plumbering for vif rate limiting in libxl/xl.
The first patch fixes trivial indentation issues and introduces no functional changes.
The second patch implements dry-run for xl network-attach for debugging and testing purposes.
The third patch adds the required plumbering in libxl/xl to add vif rate limiting support. It uses the rate option syntax from xm/xend, ensuring full backward compatiblity.
The final patch adds the "check-xl-vif-parse" test script which tests various rate syntax.
Changes in v2:
- Don't default to unlimited in case of overflow/underflow or invalid syntax in rate
- Add error handling
- Remove use of matches in regex which weren't used anyway
- Add docs about the syntax
- Add note in docs explaining that limitations are netback implementation specific
- Modify test cases according to new behavior
Please comment on the overflow and error handling.
Sorry for the delay.
--
Mathieu
PATCH v2 1/1 xl: cleanup indentation
tools/libxl/xl_cmdimpl.c +4 -4
@@ -847,10 +847,10 @@ static void parse_config_data(const char nic->script =strdup (default_vifscript); } -if (default_bridge) { -free (nic->bridge); - nic->bridge =strdup (default_bridge); - } +if (default_bridge) { +free (nic->bridge); + nic->bridge =strdup (default_bridge); + } p =strtok (buf2,"," );if (!p)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v2 1/1 xl: xl network-attach -N (dry run) option
In reply to Mathieu GagnéAdd dryrun for testing and debugging purposes.
tools/libxl/xl_cmdimpl.c +10 -0
@@ -4916,6 +4916,16 @@ int main_networkattach(int argc, char **return 1 ; } } + +if (dryrun_only) { +char *json =libxl_device_nic_to_json (ctx, &nic); +printf ("vif: %s\n" , json); +free (json); +libxl_device_nic_dispose (&nic); +if (ferror (stdout) ||fflush (stdout)) {perror ("stdout" );exit (-1 ); } +return 0 ; + } +if (libxl_device_nic_add (ctx, domid, &nic)) {fprintf (stderr,"libxl_device_nic_add failed.\n" );return 1 ;
tools/libxl/xl_cmdtable.c +1 -1
@@ -288,7 +288,7 @@ struct cmd_spec cmd_table[] = {"" , }, { "network-attach", - &main_networkattach,0 , + &main_networkattach,1 ,"Create a new virtual network device" ,"<Domain> [type=<type>] [mac=<mac>] [bridge=<bridge>] " "[ip=<ip>] [script=<script>] [backend=<BackDomain>] [vifname=<name>] "
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v2 1/1 xl: add support for vif rate limiting
In reply to Mathieu GagnéThe rate keyword specifies the rate at which the outgoing traffic will be limited to. The default if this keyword is not specified is unlimited.
The rate keyword supports an optional replenishment interval parameter for specifying the granularity of credit replenishment. It determines the frequency at which the vif transmission credit is replenished. The default interval is 50ms.
For example:
'rate=10Mb/s'
'rate=250KB/s'
'rate=1MB/s@20ms'docs/misc/xl-network-configuration.markdown +29 -0
@@ -122,5 +122,34 @@ Specifies the backend domain which this defaults to domain 0. Specifying another domain requires setting up a driver domain which is outside the scope of this document. +### rate + +Specifies the rate at which the outgoing traffic will be limited to. +The default if this keyword is not specified is unlimited. + +The rate may be specified as "<RATE>/s" or optionally "<RATE>/s@<INTERVAL>". + + * `RATE` is in bytes and can accept suffixes: + * GB, MB, KB, B for bytes. + * Gb, Mb, Kb, b for bits. + * `INTERVAL` is in microseconds and can accept suffixes: ms, us, s. + It determines the frequency at which the vif transmission credit + is replenished. The default is 50ms. + +Vif rate limiting is credit-based. It means that for "1MB/s@20ms", the +available credit will be equivalent of the traffic you would have done +at "1MB/s" during 20ms. This will results in a credit of 20,000 bytes +replenished every 20,000 us. + +For example: + + 'rate=10Mb/s' -- meaning up to 10 megabits every second + 'rate=250KB/s' -- meaning up to 250 kilobytes every second + 'rate=1MB/s@20ms' -- meaning 20,000 bytes in every 20 millisecond period + +NOTE: The actual underlying limits of rate limiting are dependent +on the underlying netback implementation. + + [oui]: http://en.wikipedia.org/wiki/Organizationally_Unique_Identifier [net]: http://wiki.xen.org/wiki/HostConfiguration/Networking
tools/libxl/Makefile +1 -1
@@ -61,7 +61,7 @@ LIBXL_OBJS += _libxl_types.o libxl_flask AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h _libxl_list.h AUTOSRCS= libxlu_cfg_y.c libxlu_cfg_l.c LIBXLU_OBJS = libxlu_cfg_y.o libxlu_cfg_l.o libxlu_cfg.o \ - libxlu_disk_l.o libxlu_disk.o libxlu_pci.o + libxlu_disk_l.o libxlu_disk.o libxlu_vif.o libxlu_pci.o $(LIBXLU_OBJS): CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h CLIENTS = xl testidl
tools/libxl/libxl.c +7 -0
@@ -1854,6 +1854,13 @@ int libxl_device_nic_add(libxl_ctx *ctx,flexarray_append (back,libxl__strdup (gc, nic->ip)); } +if (nic->rate_interval_usecs >0 ) { +flexarray_append (back,"rate" ); +flexarray_append (back,libxl__sprintf (gc,"%llu,%lu" , + (unsigned long long ) nic->rate_bytes_per_interval, + (unsigned long ) nic->rate_interval_usecs)); + } +flexarray_append (back,"bridge" );flexarray_append (back,libxl__strdup (gc, nic->bridge));flexarray_append (back,"handle" );
tools/libxl/libxl_types.idl +2 -0
@@ -343,6 +343,8 @@ libxl_device_nic = Struct("device_nic", ("ifname", string), ("script", string), ("nictype", libxl_nic_type), + ("rate_bytes_per_interval", uint64), + ("rate_interval_usecs", uint32), ]) libxl_device_pci = Struct("device_pci", [
tools/libxl/libxlu_internal.h +2 -0
@@ -17,9 +17,11 @@#define LIBXLU_INTERNAL_H #include <stdio.h> +#include <stdlib.h> #include <errno.h> #include <string.h> #include <assert.h> +#include <regex.h> #define XLU_ConfigList XLU_ConfigSetting
tools/libxl/libxlu_vif.c new file +141 -0
141 lines not on this page · raw message
tools/libxl/libxlutil.h +7 -0
@@ -94,6 +94,13 @@ int xlu_disk_parse(XLU_Config *cfg, intint xlu_pci_parse_bdf (XLU_Config *cfg,libxl_device_pci *pcidev,const char *str); +/* +* Vif rate parsing. +*/ + +int xlu_vif_parse_rate (XLU_Config *cfg,const char *rate, +libxl_device_nic *nic); +#endif /* LIBXLUTIL_H */ /*
tools/libxl/xl_cmdimpl.c +21 -1
@@ -403,6 +403,24 @@ static void parse_disk_config(XLU_Configparse_disk_config_multistring (config,1 , &spec, disk); } +static void parse_vif_rate (XLU_Config **config,const char *rate, +libxl_device_nic *nic) +{ +int e; + +if (!*config) { + *config =xlu_cfg_init (stderr,"command line" ); +if (!*config) {perror ("xlu_cfg_init" );exit (-1 ); } + } + + e =xlu_vif_parse_rate (*config, rate, nic); +if (e ==EINVAL || e ==EOVERFLOW )exit (-1 ); +if (e) { +fprintf (stderr,"xlu_vif_parse_rate failed: %s\n" ,strerror (errno)); +exit (-1 ); + } +} +static void split_string_into_string_list (const char *str,const char *delim,libxl_string_list *psl)
@@ -906,7 +924,7 @@ 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" ); +parse_vif_rate (&config, (p2 +1 ), nic); }else if (!strcmp (p,"accel" )) {fprintf (stderr,"the accel parameter for vifs is currently not supported\n" ); }
@@ -4855,6 +4873,7 @@ int main_networkattach(int argc, char ** {int opt;libxl_device_nic nic; +XLU_Config *config =0 ;char *endptr, *oparg;const char *tok;int i;
@@ -4910,6 +4929,7 @@ int main_networkattach(int argc, char ** }else if (MATCH_OPTION ("model" , *argv, oparg)) {replace_string (&nic.model, oparg); }else if (MATCH_OPTION ("rate" , *argv, oparg)) { +parse_vif_rate (&config, oparg, &nic); }else if (MATCH_OPTION ("accel" , *argv, oparg)) { }else {fprintf (stderr,"unrecognized argument `%s'\n" , *argv);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v2 1/1 xl: add "check-xl-vif-parse" test script
In reply to Mathieu GagnéThis test script runs "xl -N network-attach 0 <foobar>" against various rate syntax and checks that the output is as expected.
tools/libxl/check-xl-vif-parse new file +209 -0
@@ -0,0 +1,209 @@ +#!/bin/bash + +set -e + +if [ -x ./xl ] ; then + export LD_LIBRARY_PATH=. + XL=./xl +else + XL=xl +fi + +fprefix=tmp.check-xl-vif-parse + +expected () { + cat >$fprefix.expected +} + +failures=0 + +one () { + expected_rc=$1; shift + printf "test case %s...\n" "$*" + set +e + ${XL} -N network-attach 0 "$@" </dev/null >$fprefix.actual 2>/dev/null + actual_rc=$? + diff -u $fprefix.expected $fprefix.actual + diff_rc=$? + set -e + if [ $actual_rc != $expected_rc ] || [ $diff_rc != 0 ]; then + echo >&2 "test case \`$*' failed ($actual_rc $diff_rc)" + failures=$(( $failures + 1 )) + fi +} + +complete () { + if [ "$failures" = 0 ]; then + echo all ok.; exit 0 + else + echo "$failures tests failed."; exit 1 + fi +} + +e=255 + + +#---------- test data ---------- + +# test invalid vif config +expected </dev/null +one 1 foo + +# test invalid rate units +expected </dev/null +one $e rate=foo +one $e rate=foo +one $e rate=10MB +one $e rate=10MB/m +one $e rate=10ZB +one $e rate=10ZB/s +one $e rate=10ZB/m + +# test b/s and B/s rate units +expected <<END +vif: { + "backend_domid": 0, + "devid": 0, + "mtu": 0, + "model": null, + "mac": "00:00:00:00:00:00", + "ip": null, + "bridge": null, + "ifname": null, + "script": null, + "nictype": null, + "rate_bytes_per_interval": 100000, + "rate_interval_usecs": 50000 +} + +END + +one 0 rate=16000000b/s +one 0 rate=16000000b/s@50ms +one 0 rate=2000000B/s +one 0 rate=2000000B/s@50ms + +# test Kb/s and KB/s rate units +expected <<END +vif: { + "backend_domid": 0, + "devid": 0, + "mtu": 0, + "model": null, + "mac": "00:00:00:00:00:00", + "ip": null, + "bridge": null, + "ifname": null, + "script": null, + "nictype": null, + "rate_bytes_per_interval": 100, + "rate_interval_usecs": 50000 +} + +END +one 0 rate=16Kb/s +one 0 rate=16Kb/s@50ms +one 0 rate=2KB/s +one 0 rate=2KB/s@50ms + +# test Mb/s and MB/s rate units +expected <<END +vif: { + "backend_domid": 0, + "devid": 0, + "mtu": 0, + "model": null, + "mac": "00:00:00:00:00:00", + "ip": null, + "bridge": null, + "ifname": null, + "script": null, + "nictype": null, + "rate_bytes_per_interval": 100000, + "rate_interval_usecs": 50000 +} + +END +one 0 rate=16Mb/s +one 0 rate=16Mb/s@50ms +one 0 rate=2MB/s +one 0 rate=2MB/s@50ms + +# test Gb/s and GB/s rate units +expected <<END +vif: { + "backend_domid": 0, + "devid": 0, + "mtu": 0, + "model": null, + "mac": "00:00:00:00:00:00", + "ip": null, + "bridge": null, + "ifname": null, + "script": null, + "nictype": null, + "rate_bytes_per_interval": 50000000, + "rate_interval_usecs": 50000 +} + +END +one 0 rate=8Gb/s +one 0 rate=8Gb/s@50ms +one 0 rate=1GB/s +one 0 rate=1GB/s@50ms + +# test rate overflow +expected </dev/null +one $e rate=4294967296b/s +one $e rate=4294967296Kb/s +one $e rate=4294967296Mb/s +one $e rate=4294967296Gb/s + +# test rate underflow +expected </dev/null +one $e rate=0B/s + +# test invalid replenishment interval +expected </dev/null +one $e rate=10Mb/s@foo +one $e rate=10Mb/s@10h +one $e rate=10MB/s@foo +one $e rate=10MB/s@10h + +# test replenishment interval in seconds +expected <<END +vif: { + "backend_domid": 0, + "devid": 0, + "mtu": 0, + "model": null, + "mac": "00:00:00:00:00:00", + "ip": null, + "bridge": null, + "ifname": null, + "script": null, + "nictype": null, + "rate_bytes_per_interval": 10000000, + "rate_interval_usecs": 1000000 +} + +END +one 0 rate=80Mb/s@1s +one 0 rate=10MB/s@1s + +# test replenishment interval overflow +expected </dev/null +one $e rate=1B/s@4294967296us +one $e rate=1B/s@4294968ms +one $e rate=1B/s@4295s + +# test replenishment interval underflow +expected </dev/null +one $e rate=1B/s@0us + +# test rate limiting resulting in overflow +expected </dev/null +one $e rate=4294967295GB/s@5us +one $e rate=4296MB/s@4294s + +complete
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 19 lines · Mathieu Gagné
The
ratekeyword specifies the rate at which the outgoing traffic will be limited to. The default if this keyword is not specified is unlimited.The
ratekeyword supports an optional replenishment interval parameter for specifying the granularity of credit replenishment. It determines the frequency at which the vif transmission credit is replenished. The default interval is 50ms.For example:
'rate=10Mb/s' 'rate=250KB/s' 'rate=1MB/s@20ms'Signed-off-by Mathieu Gagné <[email protected]>ddiff --git
a/tools/libxl/libxl.cb/tools/libxl/libxl.c
tools/libxl/libxl.c int libxl_device_nic_add(libxl_ctx *ctx, · line 1859
Quoted 6 lines
tools/libxl/libxl.c +3
-0@@ -1854,6 +1854,13 @@ int libxl_device_nic_add(libxl_ctx *ctx,flexarray_append (back,libxl__strdup (gc, nic->ip)); } +if (nic->rate_interval_usecs >0 ) { +flexarray_append (back,"rate" ); + flexarray_append(back, libxl__sprintf(gc, "%llu,%lu",
I think you want to use PRIu64 and PRIu32 here.
"%"PRIu64",%"PRIu32"
Quoted 17 lines
tools/libxl/libxl.c +5
-0+ (unsigned long long ) nic->rate_bytes_per_interval, + (unsigned long) nic->rate_interval_usecs)); + } +flexarray_append (back,"bridge" );flexarray_append (back,libxl__strdup (gc, nic->bridge));flexarray_append (back,"handle" );@@ -4855,6 +4873,7 @@ int main_networkattach(int argc, char ** {int opt;libxl_device_nic nic; +XLU_Config *config =0 ;char *endptr, *oparg;const char *tok;int i;
tools/libxl/libxl.c int main_networkattach(int argc, char ** · line 4935
Quoted 7 lines
tools/libxl/libxl.c +1
-0@@ -4910,6 +4929,7 @@ int main_networkattach(int argc, char ** }else if (MATCH_OPTION ("model" , *argv, oparg)) {replace_string (&nic.model, oparg); }else if (MATCH_OPTION ("rate" , *argv, oparg)) { +parse_vif_rate (&config, oparg, &nic); }else if (MATCH_OPTION ("accel" , *argv, oparg)) { }else {fprintf (stderr,"unrecognized argument `%s'\n" , *argv);
Both this and the existing main_blockattach and pci{attach,destach} appear to fail to call xlu_cfg_destroy and so are a bit leaky. I don't think this is critical right now (the process exits right away) -- but if you fancied fixing these up in a future patch it'd be much appreciated.
Given the use of PRIuXX as above:
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 4 of 4 v2] xl: add "check-xl-vif-parse" test script
In reply to Mathieu GagnéQuoted 4 lines · Mathieu Gagné
This test script runs "xl -N network-attach 0 <foobar>" against various rate syntax and checks that the output is as expected.
Signed-off-by Mathieu Gagné <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Mathieu Gagné writes ("[Xen-devel] [PATCH 0 of 4 v2] xl: add support for vif rate limiting"):
Quoted 1 line
This patch series implements the required plumbering for vif rate limiting in libxl/xl.
Thanks, I have applied the first two.
Whe you repost can you please make sure to wrap the commit messages to 70 columns or so ?
Thanks,
Ian.
Quoted 4 lines · Ian Jackson
Mathieu Gagné writes ("[Xen-devel] [PATCH 0 of 4 v2] xl: add support for vif rate limiting"):
Quoted 1 line
This patch series implements the required plumbering for vif rate limiting in libxl/xl.
Thanks, I have applied the first two.
Thanks.
Quoted 2 lines
Whe you repost can you please make sure to wrap the commit messages to 70 columns or so ?
Done. I forgot to synchronize the time of my virtual machine.
The v3 of this patch series is up there at "Mon, 16 Apr 2012 23:51:22 -0400".
Signature · 1 line
Mathieu