From patchwork Fri Sep 30 02:53:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9357455 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 2ADFE6077A for ; Fri, 30 Sep 2016 02:56:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1426F29D3E for ; Fri, 30 Sep 2016 02:56:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 042CB29D43; Fri, 30 Sep 2016 02:56:08 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,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 4C03929D3E for ; Fri, 30 Sep 2016 02:56:06 +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 1bpnx4-0001nY-JL; Fri, 30 Sep 2016 02:53:30 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bpnx3-0001nM-8c for xen-devel@lists.xenproject.org; Fri, 30 Sep 2016 02:53:29 +0000 Received: from [85.158.137.68] by server-1.bemta-3.messagelabs.com id 78/E5-12967-8A3DDE75; Fri, 30 Sep 2016 02:53:28 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDIsWRWlGSWpSXmKPExsXiVRvkrLv88tt wg/N7TSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ow5a/4zFuwQrDh/eCVLA+Mb3i5GLg4hgRmM Eu+7TzGCOCwCa1glNryfzwriSAhcYpXYMXE/UIYDyImRWNlrDGGWSdw6AdTMCdSsInFz+yomi EG/GCVmLnnCBJIQFtCTOHL0BzuEnSJx694ZRhCbTcBA4s2OvawgtoiAksS9VZOZQGYyC+hLrP 7KAxJmEVCV2LXwFVgJr4C3xKsNT9hAbE4BX4lf216wQOz1kfi9fDlYXFRATmLl5RaoekGJkzO fsECM1JRYv0sfJMwsIC+x/e0c5gmMIrOQVM1CqJqFpGoBI/MqRo3i1KKy1CJdQ0u9pKLM9IyS 3MTMHF1DA2O93NTi4sT01JzEpGK95PzcTYzA0K9nYGDcwfj7uN8hRkkOJiVRXtmjb8OF+JLyU yozEosz4otKc1KLDzFqcHAITDg7dzqTFEtefl6qkgTv2ktAdYJFqempFWmZOcDohCmV4OBREu FdCZLmLS5IzC3OTIdInWLU5dgy9d5aJiGwGVLivE0gRQIgRRmleXAjYIniEqOslDAvIwMDgxB PQWpRbmYJqvwrRnEORiVh3k8gU3gy80rgNr0COoIJ6Ij8o29AjihJREhJNTAu2eks2bt6id86 6cuzl/yZaKdVayc/+V3cKbnZe5yj7vafDzPaEKzRsCJIf2nliXVLRLIfiKf+yJxvyGgz1Z71X W7wjFMZjVeiNvoHG586tPfm5K9hi3zP3NrEs1WFPdohmFl13pLMzW8L0478uRmy/8C99ilKPk /3bZzaFaL+ddWnst/yCdGVSizFGYmGWsxFxYkAYPrrnA8DAAA= X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-5.tower-31.messagelabs.com!1475204007!60399715!1 X-Originating-IP: [74.125.82.67] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 1739 invoked from network); 30 Sep 2016 02:53:27 -0000 Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by server-5.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 30 Sep 2016 02:53:27 -0000 Received: by mail-wm0-f67.google.com with SMTP id p138so1403632wmb.0 for ; Thu, 29 Sep 2016 19:53:27 -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=4l/vPxRmvxM/6OShVl4Eg2A42/DiqwhX4813symRo00=; b=MgTTLPxCg3+cyWIGhnWmUC80Vj2Wa+A+h+uegT01yrFMK+yfreeRanE+qU1hO1fZkz aFCgvPPmv8BWIONQujoyCyjM+6h0cbJ6qc4iH+dUCLx9S8y66r1ewwSTZj0h3N9NHuxD lE+SJ9DsK0HCGnvrbR5TNHYPxl4JLK2mcsrnQJU3uoVvHgxuHwCVhMW6ExuXPOnqjn2K /AUjW4WQ/JQVPZjpyZx0rHJAhofyCfVnVfe9RzvY7Iq4+i0Urym8sJX0CoFId+XOaito chaZSbWhanyc8JfvsTgf1vH28Y4Fs1JNDZZ5zGy+3w4LvPIMiPuKE1XjvZz9M7I1wsqR dxZw== 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=4l/vPxRmvxM/6OShVl4Eg2A42/DiqwhX4813symRo00=; b=eMw+dqFKEWxuPlKdNEmMwIR/+LEXdr/jvu7OO49BnmcK9HhegZqhUU8L3AVrY8/OZ1 9o+yuXmikFy0fiKm642UmYkfXFSrcb+LCypE4398TMOPKpljEb2FnOqk2g9T/71xt3ZE ShVvhbLAjFJtIhNo02AfaQWNJbNGVd/Ci96SPvDNg+DuoN+eY1CqJrVWuxTqlt6evZUl z7Va/ui0xMZGy80C+EQvmb78yGWtOwCB01FCq0X2o87ESMV17t5jdnIgcJLLxCUsGx8z Xa4sDDxfahL/M1/mBsdjo6yeu4cJkDQT113QMZQo2X3mR80zwWVwptJVd4AVYBRinkyl pJfA== X-Gm-Message-State: AA6/9Rn5rmbGBxodcpO8PbSpk9B6/9WOY0Up/K+rH3r2tU5TYKGxU6vGpJBlJQ35TCCZQg== X-Received: by 10.28.98.68 with SMTP id w65mr1630699wmb.4.1475204007412; Thu, 29 Sep 2016 19:53:27 -0700 (PDT) Received: from Solace.fritz.box ([80.66.223.126]) by smtp.gmail.com with ESMTPSA id t65sm1695331wmt.15.2016.09.29.19.53.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Sep 2016 19:53:26 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Fri, 30 Sep 2016 04:53:25 +0200 Message-ID: <147520400560.22544.6704334115981723287.stgit@Solace.fritz.box> In-Reply-To: <147520253247.22544.10673844222866363947.stgit@Solace.fritz.box> References: <147520253247.22544.10673844222866363947.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: George Dunlap Subject: [Xen-devel] [PATCH v2 01/10] xen: credit1: return the 'time remaining to the limit' as next timeslice. 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 If vcpu x has run for 200us, and sched_ratelimit_us is 1000us, continue running x _but_ return 1000us-200us as the next time slice. This way, next scheduling point will happen in 800us, i.e., exactly at the point when x crosses the threshold, and can be descheduled (if appropriate). Right now (without this patch), we're always returning sched_ratelimit_us (1000us, in the example above), which means we're (potentially) allowing x to run more than it should have been able to. Note that, however, in order to avoid setting timers to very short intervals, which is part of the purpose of rate limiting, we never use a time slice smaller than a well defined threshold. Such threshold (CSCHED_MIN_TIMER defined in this patch) is, in general independent from rate limiting, but it looks a good idea to set it to the minimum possible ratelimiting value. Signed-off-by: Dario Faggioli Reviewed-by: George Dunlap --- Cc: George Dunlap --- Changes from v1: * introduce CSCHED_MIN_TIMER, as agreed during review. --- xen/common/sched_credit.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index b63efac..4d84b5f 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -51,6 +51,8 @@ /* Default timeslice: 30ms */ #define CSCHED_DEFAULT_TSLICE_MS 30 #define CSCHED_CREDITS_PER_MSEC 10 +/* Never set a timer shorter than this value. */ +#define CSCHED_MIN_TIMER XEN_SYSCTL_SCHED_RATELIMIT_MIN /* @@ -1811,7 +1813,15 @@ csched_schedule( snext = scurr; snext->start_time += now; perfc_incr(delay_ms); - tslice = MICROSECS(prv->ratelimit_us); + /* + * Next timeslice must last just until we'll have executed for + * ratelimit_us. However, to avoid setting a really short timer, which + * will most likely be inaccurate and counterproductive, we never go + * below CSCHED_MIN_TIMER. + */ + tslice = MICROSECS(prv->ratelimit_us) - runtime; + if ( unlikely(runtime < CSCHED_MIN_TIMER) ) + tslice = CSCHED_MIN_TIMER; ret.migrated = 0; goto out; }