From patchwork Wed Aug 17 17:19:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9286229 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5CEC560839 for ; Wed, 17 Aug 2016 17:21:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4969F294A2 for ; Wed, 17 Aug 2016 17:21:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A1B2294B8; Wed, 17 Aug 2016 17:21:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A0EAE294A2 for ; Wed, 17 Aug 2016 17:21:40 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ba4Uo-0000YA-1M; Wed, 17 Aug 2016 17:19:18 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ba4Ul-0000W6-Rz for xen-devel@lists.xenproject.org; Wed, 17 Aug 2016 17:19:15 +0000 Received: from [85.158.137.68] by server-5.bemta-3.messagelabs.com id 0E/94-03281-39C94B75; Wed, 17 Aug 2016 17:19:15 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrHIsWRWlGSWpSXmKPExsXiVRvkqDtpzpZ wg/49HBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8amK6vZC06aVay+u4ypgXGNZhcjF4eQwExG iQ1Lupm7GDk5WATWsEo8OigIkpAQuMQq0fp7GhNIQkIgRuL5jvesEHa5xLRX29lBbCEBFYmb2 1cxQUyawyTxb0o/C0hCWEBP4sjRH+wQdpBE27UuRhCbTcBA4s2OvWCDRASUJO6tmgy2gFmgQm LFyxtMEFeoSvzfshHsIl4Bb4kPr7aBzeEU8JG4tfo3C8Rib4nDk3vYQGxRATmJlZdbWCHqBSV OznwCVMMBNFNTYv0ufYjx8hLb385hnsAoMgtJ1SyEqllIqhYwMq9i1ChOLSpLLdI1MtNLKspM zyjJTczM0TU0MNbLTS0uTkxPzUlMKtZLzs/dxAgM/3oGBsYdjA17/Q4xSnIwKYny3qneEi7El 5SfUpmRWJwRX1Sak1p8iFGDg0Ngwtm505mkWPLy81KVJHh7ZgPVCRalpqdWpGXmACMUplSCg0 dJhLcWJM1bXJCYW5yZDpE6xajLsWXqvbVMQmAzpMR5U0CKBECKMkrz4EbAksUlRlkpYV5GBgY GIZ6C1KLczBJU+VeM4hyMSsK8y0Cm8GTmlcBtegV0BBPQEbz8YEeUJCKkpBoYBR90qs8+tbFd tHVN+ZyUM0+bT571El56WGb9122+ORGeqV2CXNO5a7lP31mReNL1y4XHjj8a/aXnXsorPVXt9 +3YEj8Vxx0fDsRt77tYenQGh2j3I7Z73W+zHZKXX6/7eH3qYX4fbyduI+Mvx1T0FwqxW/YIBK xy+toqv0+BrUn32k5evvu1SizFGYmGWsxFxYkAWAXxOREDAAA= X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-9.tower-31.messagelabs.com!1471454353!8624220!1 X-Originating-IP: [74.125.82.65] X-SpamReason: No, hits=0.2 required=7.0 tests=RCVD_ILLEGAL_IP X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 45944 invoked from network); 17 Aug 2016 17:19:14 -0000 Received: from mail-wm0-f65.google.com (HELO mail-wm0-f65.google.com) (74.125.82.65) by server-9.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 17 Aug 2016 17:19:14 -0000 Received: by mail-wm0-f65.google.com with SMTP id i138so26181917wmf.3 for ; Wed, 17 Aug 2016 10:19:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=P2IIgIRjtHehYlRT1ooZ+W2eN3RnL4Uyx9KLG8wapEo=; b=nWNlxbWxplY+Oh3t3hainasj4WTpojnex2dJbIiZfwsL3NwnddWXT+bqji9vQ1RZ/k IBEcuDrmc0WGkfxuCWKgQuH1hUL2J8jtgCIOqX14rZAUMriNneY3nv4r4DlULZcFhLtE MG3eK6CTDIHiFGEKPskpZBzFhumLxzS4E4T9Rq4zXuxxJWT2rjOdBmZOh8qbAW7KarkO +vSE4+aH0KRRn1JuF5cYZBI7h6QHNhJOSAWufxua6kmsfGmbGtKBUgXIBlPvus+tymhJ 9kefgbwARgWisdqKW7WkGPj2IqAwgosbh4GRcZzbItATTzDorn5/zS8GAjHiImS6VJDI YaZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:subject:from:to:cc:date:message-id :in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=P2IIgIRjtHehYlRT1ooZ+W2eN3RnL4Uyx9KLG8wapEo=; b=FjSvARz9vVZzXuGMuf1b8hOUaSGBVaVOmLtq+FG4OAaYpVzDTz0thaJkMHhnU1e6gp woHVwEOSTrTndwy5D3yRH0j45X8510ddAB/pNeDFX2FCXxKrycrqkEZxolpy1F3IcZ0v /k+zt6CTZ57UrJmUqUkWF+pse1Z1GVDU+bw3W/gpqcuN2H2p5gANBOuPoPgE9+ZUZY21 kcbuNsaCfFXm3aomL7ioaFKuvdhTT6fCXmQCZaWxbcUYw5IzwEso8zT/ICOQbE1i14T0 DyHFLVL0EqPSXGRHzh4cU/XTCnTqKP9YZean6GF9d22qDXPO2DJtGZ+ixb5FZ19+EpLf WVdQ== X-Gm-Message-State: AEkoousHtNcX4P+qyeULS48TvIFbD5p3OpWAY5bVsg74g3qel35BXvEFZc24Z0BbyqOcag== X-Received: by 10.28.24.73 with SMTP id 70mr17695091wmy.96.1471454353683; Wed, 17 Aug 2016 10:19:13 -0700 (PDT) Received: from Solace.fritz.box (net-2-32-14-104.cust.vodafonedsl.it. [2.32.14.104]) by smtp.gmail.com with ESMTPSA id n2sm32520357wjd.1.2016.08.17.10.19.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Aug 2016 10:19:13 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Wed, 17 Aug 2016 19:19:11 +0200 Message-ID: <147145435166.25877.2550918854619355050.stgit@Solace.fritz.box> In-Reply-To: <147145358844.25877.7490417583264534196.stgit@Solace.fritz.box> References: <147145358844.25877.7490417583264534196.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: George Dunlap , Wei Liu , Ian Jackson Subject: [Xen-devel] [PATCH 14/24] libxl: allow to set the ratelimit value online for Credit2 X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This is the remaining part of the plumbing (the libxl one) necessary to be able to change the value of the ratelimit_us parameter online, for Credit2 (like it is already for Credit1). Note that, so far, we were rejecting (for Credit1) a new value of zero, despite it is a pretty nice way to ask for the rate limiting to be disabled, and the hypervisor is already capable of dealing with it in that way. Therefore, we change things so that it is possible to do so, both for Credit1 and Credit2 While there, fix the error handling path (make it compliant with libxl's codying style) in Credit1 rate limiting related functions. Signed-off-by: Dario Faggioli Reviewed-by: George Dunlap --- Cc: Ian Jackson Cc: Wei Liu Cc: George Dunlap --- tools/libxl/libxl.c | 111 ++++++++++++++++++++++++++++++++++--------- tools/libxl/libxl.h | 4 ++ tools/libxl/libxl_types.idl | 4 ++ 3 files changed, 95 insertions(+), 24 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 6a50e49..d6a8d02 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -5229,69 +5229,132 @@ static int sched_credit_domain_set(libxl__gc *gc, uint32_t domid, return 0; } +static int sched_ratelimit_check(libxl__gc *gc, int ratelimit) +{ + if (ratelimit != 0 && + (ratelimit < XEN_SYSCTL_SCHED_RATELIMIT_MIN || + ratelimit > XEN_SYSCTL_SCHED_RATELIMIT_MAX)) { + LOG(ERROR, "Ratelimit out of range, valid range is from %d to %d", + XEN_SYSCTL_SCHED_RATELIMIT_MIN, XEN_SYSCTL_SCHED_RATELIMIT_MAX); + return ERROR_INVAL; + } + + return 0; +} + int libxl_sched_credit_params_get(libxl_ctx *ctx, uint32_t poolid, libxl_sched_credit_params *scinfo) { struct xen_sysctl_credit_schedule sparam; - int rc; + int r, rc; GC_INIT(ctx); - rc = xc_sched_credit_params_get(ctx->xch, poolid, &sparam); - if (rc != 0) { - LOGE(ERROR, "getting sched credit param"); - GC_FREE; - return ERROR_FAIL; + r = xc_sched_credit_params_get(ctx->xch, poolid, &sparam); + if (r < 0) { + LOGE(ERROR, "getting Credit scheduler parameters"); + rc = ERROR_FAIL; + goto out; } scinfo->tslice_ms = sparam.tslice_ms; scinfo->ratelimit_us = sparam.ratelimit_us; + rc = 0; + out: GC_FREE; - return 0; + return rc; } int libxl_sched_credit_params_set(libxl_ctx *ctx, uint32_t poolid, libxl_sched_credit_params *scinfo) { struct xen_sysctl_credit_schedule sparam; - int rc=0; + int r, rc; GC_INIT(ctx); if (scinfo->tslice_ms < XEN_SYSCTL_CSCHED_TSLICE_MIN || scinfo->tslice_ms > XEN_SYSCTL_CSCHED_TSLICE_MAX) { LOG(ERROR, "Time slice out of range, valid range is from %d to %d", XEN_SYSCTL_CSCHED_TSLICE_MIN, XEN_SYSCTL_CSCHED_TSLICE_MAX); - GC_FREE; - return ERROR_INVAL; + rc = ERROR_INVAL; + goto out; } - if (scinfo->ratelimit_us < XEN_SYSCTL_SCHED_RATELIMIT_MIN - || scinfo->ratelimit_us > XEN_SYSCTL_SCHED_RATELIMIT_MAX) { - LOG(ERROR, "Ratelimit out of range, valid range is from %d to %d", - XEN_SYSCTL_SCHED_RATELIMIT_MIN, XEN_SYSCTL_SCHED_RATELIMIT_MAX); - GC_FREE; - return ERROR_INVAL; + rc = sched_ratelimit_check(gc, scinfo->ratelimit_us); + if (rc) { + goto out; } if (scinfo->ratelimit_us > scinfo->tslice_ms*1000) { LOG(ERROR, "Ratelimit cannot be greater than timeslice"); - GC_FREE; - return ERROR_INVAL; + rc = ERROR_INVAL; + goto out; } sparam.tslice_ms = scinfo->tslice_ms; sparam.ratelimit_us = scinfo->ratelimit_us; - rc = xc_sched_credit_params_set(ctx->xch, poolid, &sparam); - if ( rc < 0 ) { - LOGE(ERROR, "setting sched credit param"); - GC_FREE; - return ERROR_FAIL; + r = xc_sched_credit_params_set(ctx->xch, poolid, &sparam); + if ( r < 0 ) { + LOGE(ERROR, "Setting Credit scheduler parameters"); + rc = ERROR_FAIL; + goto out; } scinfo->tslice_ms = sparam.tslice_ms; scinfo->ratelimit_us = sparam.ratelimit_us; + out: GC_FREE; - return 0; + return rc; +} + +int libxl_sched_credit2_params_get(libxl_ctx *ctx, uint32_t poolid, + libxl_sched_credit2_params *scinfo) +{ + struct xen_sysctl_credit2_schedule sparam; + int r, rc; + GC_INIT(ctx); + + r = xc_sched_credit2_params_get(ctx->xch, poolid, &sparam); + if (r < 0) { + LOGE(ERROR, "getting Credit2 scheduler parameters"); + rc = ERROR_FAIL; + goto out; + } + + scinfo->ratelimit_us = sparam.ratelimit_us; + + rc = 0; + out: + GC_FREE; + return rc; +} + +int libxl_sched_credit2_params_set(libxl_ctx *ctx, uint32_t poolid, + libxl_sched_credit2_params *scinfo) +{ + struct xen_sysctl_credit2_schedule sparam; + int r, rc; + GC_INIT(ctx); + + rc = sched_ratelimit_check(gc, scinfo->ratelimit_us); + if (rc) { + goto out; + } + + sparam.ratelimit_us = scinfo->ratelimit_us; + + r = xc_sched_credit2_params_set(ctx->xch, poolid, &sparam); + if ( r < 0 ) { + LOGE(ERROR, "Setting Credit2 scheduler parameters"); + rc = ERROR_FAIL; + goto out; + } + + scinfo->ratelimit_us = sparam.ratelimit_us; + + out: + GC_FREE; + return rc; } static int sched_credit2_domain_get(libxl__gc *gc, uint32_t domid, diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index ae21302..efc5912 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1978,6 +1978,10 @@ int libxl_sched_credit_params_get(libxl_ctx *ctx, uint32_t poolid, libxl_sched_credit_params *scinfo); int libxl_sched_credit_params_set(libxl_ctx *ctx, uint32_t poolid, libxl_sched_credit_params *scinfo); +int libxl_sched_credit2_params_get(libxl_ctx *ctx, uint32_t poolid, + libxl_sched_credit2_params *scinfo); +int libxl_sched_credit2_params_set(libxl_ctx *ctx, uint32_t poolid, + libxl_sched_credit2_params *scinfo); /* Scheduler Per-domain parameters */ diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index ef614be..38a4222 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -833,6 +833,10 @@ libxl_sched_credit_params = Struct("sched_credit_params", [ ("ratelimit_us", integer), ], dispose_fn=None) +libxl_sched2_credit_params = Struct("sched_credit2_params", [ + ("ratelimit_us", integer), + ], dispose_fn=None) + libxl_domain_remus_info = Struct("domain_remus_info",[ ("interval", integer), ("allow_unsafe", libxl_defbool),