From patchwork Sat Oct 22 02:11:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meng Xu X-Patchwork-Id: 9390347 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 4207F608A7 for ; Sat, 22 Oct 2016 02:15:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3039229F8A for ; Sat, 22 Oct 2016 02:15:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2398E2A027; Sat, 22 Oct 2016 02:15:07 +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 95B192A022 for ; Sat, 22 Oct 2016 02:15:03 +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 1bxlne-0000ew-PY; Sat, 22 Oct 2016 02:12:42 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bxlnd-0000en-E9 for xen-devel@lists.xenproject.org; Sat, 22 Oct 2016 02:12:41 +0000 Received: from [193.109.254.147] by server-10.bemta-6.messagelabs.com id A2/70-21986-81BCA085; Sat, 22 Oct 2016 02:12:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFLMWRWlGSWpSXmKPExsUyr8m9Slf8NFe EwaZJNhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bigyeYCloEKw6cfMDcwNjD18XIySEk0Mgk cetcKYjNJqAicXzDI1YQW0RASeLeqslMXYxcHMwCLcwSe35+YwJJCAtYSpw9sY8NxGYRUJWYc O4mO4jNK+AscW7tOhYQW0JATuLkscmsEHaoxJrF55lg4o8fPmCcwMi1gJFhFaNGcWpRWWqRrp GBXlJRZnpGSW5iZo6uoYGZXm5qcXFiempOYlKxXnJ+7iZGoB8ZgGAH469lAYcYJTmYlER5F03 kjBDiS8pPqcxILM6ILyrNSS0+xCjDwaEkwTv9JFeEkGBRanpqRVpmDjCgYNISHDxKIrwWIGne 4oLE3OLMdIjUKUZFKXHeqSAJAZBERmkeXBssiC8xykoJ8zICHSLEU5BalJtZgir/ilGcg1FJm LcCZApPZl4J3PRXQIuZgBbXpHGALC5JREhJNTB67NyQvtCf//iy9KpLy74sn2qw719ZiHhZ46 o9PHvYAgLaTDx4eLmf3kk+wvgoZq7RyzQ1BXU+6+tax8qux+x4OGVDrtGUhYcZDDuFHqYfKi0 +fWgfh5dk9c3n7tL2aSlGL+t/9888sfF5SHVd+9xfz4vShGVypPjWn3rgYLEjdTZzk4/dwctK LMUZiYZazEXFiQDzarztXQIAAA== X-Env-Sender: mengxu@cis.upenn.edu X-Msg-Ref: server-2.tower-27.messagelabs.com!1477102327!14366182!1 X-Originating-IP: [158.130.71.122] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.0.13; banners=-,-,- X-VirusChecked: Checked Received: (qmail 21341 invoked from network); 22 Oct 2016 02:12:14 -0000 Received: from coyote.seas.upenn.edu (HELO hound.seas.upenn.edu) (158.130.71.122) by server-2.tower-27.messagelabs.com with SMTP; 22 Oct 2016 02:12:14 -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 u9M2Bmo8000359 (version=TLSv1/SSLv3 cipher=AES256-SHA256 bits=256 verify=NOT); Fri, 21 Oct 2016 22:11:49 -0400 From: Meng Xu To: xen-devel@lists.xenproject.org Date: Fri, 21 Oct 2016 22:11:16 -0400 Message-Id: <1477102276-4116-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 v2] 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: While a VCPU is running on a core, it may misses its deadline. Then repl_timer_handler() will update the VCPU period and deadline. The VCPU may have high priority with the new deadline and repl_timer_handler() decides to keep the VCPU running on the core, but with new period and deadline. However, the budget enforcement timer for the previous period is still armed. When rt_schedule() is called in the new period to enforce the budget for the previous period, 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. Signed-off-by: Meng Xu Reported-by: Dagaen Golomb --- 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 easire 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 --- xen/common/sched_rt.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c index d95f798..ff17bd2 100644 --- a/xen/common/sched_rt.c +++ b/xen/common/sched_rt.c @@ -407,6 +407,14 @@ 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 + */ + if ( svc->last_start < (svc->cur_deadline - svc->period) ) + svc->last_start = svc->cur_deadline - svc->period; + svc->cur_budget = svc->budget; /* TRACE */