From patchwork Wed Oct 26 19:06:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meng Xu X-Patchwork-Id: 9398031 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 B866160236 for ; Wed, 26 Oct 2016 19:08:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D8ED29D22 for ; Wed, 26 Oct 2016 19:08:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8219429D24; Wed, 26 Oct 2016 19:08:54 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 036C429D22 for ; Wed, 26 Oct 2016 19:08:52 +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 1bzTWw-0001T4-EB; Wed, 26 Oct 2016 19:06:30 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bzTWv-0001Sy-9j for xen-devel@lists.xenproject.org; Wed, 26 Oct 2016 19:06:29 +0000 Received: from [85.158.143.35] by server-6.bemta-6.messagelabs.com id 90/96-11175-4BEF0185; Wed, 26 Oct 2016 19:06:28 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFLMWRWlGSWpSXmKPExsUyr8m9SnfzP4E IgzVzTC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1owHPYvYC86JVvzc+o69gfGTYBcjJ4eQQCOT xJoNvCA2m4CKxPENj1hBbBEBJYl7qyYzdTFycTALtDBL7Pn5jQkkISxgJXGz9xqYzSKgKrHtf B8biM0r4CzReqeHEcSWEJCTOHlsMiuEHSqxZvF5Jpj444cPGCcwci1gZFjFqFGcWlSWWqRrbK SXVJSZnlGSm5iZo2toYKaXm1pcnJiempOYVKyXnJ+7iRHoRwYg2MF4el3gIUZJDiYlUd4HTwQ ihPiS8lMqMxKLM+KLSnNSiw8xynBwKEnwtv0FygkWpaanVqRl5gADCiYtwcGjJMK7FiTNW1yQ mFucmQ6ROsWoKCXOuxAkIQCSyCjNg2uDBfElRlkpYV5GoEOEeApSi3IzS1DlXzGKczAqCfO+B ZnCk5lXAjf9FdBiJqDF09PBFpckIqSkGhhXMl9f9yTLo5NjdrdXqsWhsgPb3bpqr/VKf53jV1 v8emnJei+mmGMdt0SWz81O1RY4v1frhvpHrg1Re3I/1O5JOxLx/Qdrvv8W315u/crj3OzH2/9 ksHTU3vG05mDi6rtY9+SEffr2xFhJ467LJh6xi0rrPn6VbRJduf309Bc/Zq68tTowgkOJpTgj 0VCLuag4EQA6Kqr/XQIAAA== X-Env-Sender: mengxu@cis.upenn.edu X-Msg-Ref: server-16.tower-21.messagelabs.com!1477508787!35683835!1 X-Originating-IP: [158.130.71.122] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.0.13; banners=-,-,- X-VirusChecked: Checked Received: (qmail 36962 invoked from network); 26 Oct 2016 19:06:27 -0000 Received: from coyote.seas.upenn.edu (HELO hound.seas.upenn.edu) (158.130.71.122) by server-16.tower-21.messagelabs.com with SMTP; 26 Oct 2016 19:06:27 -0000 Received: from panda-catbroadwell.cis.upenn.edu ([158.130.48.19]) (authenticated bits=0) by hound.seas.upenn.edu (8.14.9/8.14.5) with ESMTP id u9QJ6IOR039323 (version=TLSv1/SSLv3 cipher=AES256-SHA256 bits=256 verify=NOT); Wed, 26 Oct 2016 15:06:19 -0400 From: Meng Xu To: xen-devel@lists.xenproject.org Date: Wed, 26 Oct 2016 15:06:06 -0400 Message-Id: <1477508766-3781-1-git-send-email-mengxu@cis.upenn.edu> X-Mailer: git-send-email 1.9.1 X-Proofpoint-Virus-Version: vendor=nai engine=5600 definitions=5800 signatures=585085 X-Proofpoint-Spam-Reason: safe Cc: Wei Liu , Dagaen Golomb , George Dunlap , Haoran Li , Dario Faggioli , Linh Thi Xuan Phan , Meng Xu , Meng Xu , Tianyang Chen Subject: [Xen-devel] [PATCH v3] xen:rtds: Fix bug in budget accounting 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Bug scenario: repl_timer_handler() may be called before rt_schedule() for a VCPU. This situation may happen in two scenarios: (1) The VCPU misses deadline due to the system is oversubscribed. For example, the sum of VCPUs utilization on a core is larger than one. (2) The VCPU has budget = period, which causes the timers for rt_schedule() and repl_timer_handler() are fired at the same time. When the situation happens, it causes the following incorrect behavior: repl_timer_handler() will update the VCPU period and deadline. If the VCPU is still the highest priority one, even with the new deadline, it will continue to run, but with new period and deadline. Since the budget enforcement timer for the previous period is still armed, rt_schedule() will still be called in the new period and enforce the budget for the previous period. The current burn_budget() will deduct the time spent in previous period from the budget in current period, which is incorrect. Fix: We keeps last_start always within the current period for a VCPU, so that we only deduct the time spent in the current period from the VCPU budget. We always update last_start whenever we update cur_deadline for a VCPU. Signed-off-by: Meng Xu Reported-by: Dagaen Golomb Acked-by: Dario Faggioli --- Cc: Dario Faggioli Cc: George Dunlap Cc: Wei Liu Cc: Linh Thi Xuan Phan Cc: Haoran Li Cc: Meng Xu Cc: Dagaen Golomb Cc: Tianyang Chen --- Changes from v1: * Change commit message to make the bug scenario easier to understand; * The two bug scenarios described in v1 can be actually fixed by this patch; so we do not need to change the runq_tickle Changes from v2: * Change commit message to make the bug scenario clear * Always update last_start whenever cur_deadline is updated for a VCPU * Update last_start to now, instead of (cur_deadline - period) as suggested by Dario Faggioli --- xen/common/sched_rt.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index d95f798..4b4f232 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -407,6 +407,12 @@ rt_update_deadline(s_time_t now, struct rt_vcpu *svc) svc->cur_deadline += count * svc->period; } + /* + * svc may be scheduled to run immediately after it misses deadline + * Then rt_update_deadline is called before rt_schedule, which + * should only deduct the time spent in current period from the budget + */ + svc->last_start = now; svc->cur_budget = svc->budget; /* TRACE */