Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2268954imb; Mon, 4 Mar 2019 00:15:23 -0800 (PST) X-Google-Smtp-Source: APXvYqzi0BVIJHVOZ+pexMVpUfbHJvn/xCKHSJhIsAkjPjxSvScdwU38GyNGxD+MbuHKv8oqxP7i X-Received: by 2002:a63:112:: with SMTP id 18mr16749955pgb.139.1551687323834; Mon, 04 Mar 2019 00:15:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551687323; cv=none; d=google.com; s=arc-20160816; b=qSR3R/SQouxLBLE2ibQUkFVjvz/Po2bApNDEiim4hu+p0WS1j46hws+YlHlrMYIueD 37Q/KbfXX4Qu0LdHLm+xDz5BbQeSdwOv64+lseEKCxrn1ej8/X0mZkgi0x53RmBNx4wg nW6V6yxsU6vbyAQNBwRzAPb59xPhl4mDAZyIkdnMUVmfWXysRD9TA/O4Hy9tiuaw4isE njU8Uvs1BJ0c7VJ2aAvKC5JGCfnKGa8GO9GCz/2336b+5B/4tW4oPlVByygncWc7QJMg BEyALh7mgHuZRATKJYX7CRTeJmLpVn2HPllUiHDVeubjTaBS1J2IDqpPhRczeAbOG1VE ckaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject; bh=B6zuxHlO/z7zT9h85I/2ttom2MjKIL2Okd1mWF4imVU=; b=bvMIUMM+kMMit/5NnpTj6JRMXiJZHtstqvyGzBDn5q8jePvsj2X8uQ7S2Fo6z/hwzB I9EeNpXyThknLm4tCWqPg5K/NbI7df8ml1RB8Zf06li7shWGtG1tTpK1Uj3+e7Xqitte uC1+Aa54MFSJo57kLZ8f8jNu/r2YFx7AyPTPhQOQLMEscrMxMFJyfg8kC3zltLjoM/ns E7Kc6SrbVzFIAMY4idf2RT8D1GNF/uMH7lW7vBhiY3DMq1cXjEtrXv8e0/h6gii/rRup 2odcTu7XJa10dHE96+lh2gk4NqiOeiZpqPrxYWMDUCtP8bYlSfH8NrmctzmFR/vIL9/K Pbgg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u37si4629948pgn.480.2019.03.04.00.15.08; Mon, 04 Mar 2019 00:15:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726046AbfCDIOs (ORCPT + 99 others); Mon, 4 Mar 2019 03:14:48 -0500 Received: from mx2.suse.de ([195.135.220.15]:46680 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725974AbfCDIOs (ORCPT ); Mon, 4 Mar 2019 03:14:48 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 50B62AE5E; Mon, 4 Mar 2019 08:14:46 +0000 (UTC) Subject: Re: [BUG linux-4.9.x] xen hotplug cpu leads to 100% steal usage To: Dongli Zhang , xen-devel@lists.xenproject.org, stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: boris.ostrovsky@oracle.com, sstabellini@kernel.org, tglx@linutronix.de, joe.jin@oracle.com, Herbert Van Den Bergh , sboyd@kernel.org, john.stultz@linaro.org References: <841bb9a9-1cba-483f-a353-1209684f7c74@default> From: Juergen Gross Openpgp: preference=signencrypt Autocrypt: addr=jgross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bTdrnyDZaixT2T0f4tyF5Lfs+Ha8xVMhIyzNb1byDI5FKCb Message-ID: <5bd0923f-29f6-0ad0-a1e9-92019a515b11@suse.com> Date: Mon, 4 Mar 2019 09:14:45 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <841bb9a9-1cba-483f-a353-1209684f7c74@default> Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/03/2019 03:35, Dongli Zhang wrote: > This issue is only for stable 4.9.x (e.g., 4.9.160), while the root cause is > still in the lasted mainline kernel. > > This is obviated by new feature patch set ended with b672592f0221 > ("sched/cputime: Remove generic asm headers"). > > After xen guest is up for long time, once we hotplug new vcpu, the corresponding > steal usage might become 100% and the steal time from /proc/stat would increase > abnormally. > > As we cannot wait for long time to reproduce the issue, here is how I reproduce > it on purpose by accounting a large initial steal clock for new vcpu 2 and 3. > > 1. Apply the below patch to guest 4.9.160 to account large initial steal clock > for new vcpu 2 and 3: > > diff --git a/drivers/xen/time.c b/drivers/xen/time.c > index ac5f23f..3cf629e 100644 > --- a/drivers/xen/time.c > +++ b/drivers/xen/time.c > @@ -85,7 +85,14 @@ u64 xen_steal_clock(int cpu) > struct vcpu_runstate_info state; > > xen_get_runstate_snapshot_cpu(&state, cpu); > - return state.time[RUNSTATE_runnable] + state.time[RUNSTATE_offline]; > + > + if (cpu == 2 || cpu == 3) > + return state.time[RUNSTATE_runnable] > + + state.time[RUNSTATE_offline] > + + 0x00071e87e677aa12; > + else > + return state.time[RUNSTATE_runnable] > + + state.time[RUNSTATE_offline]; > } > > void xen_setup_runstate_info(int cpu) > > > 2. Boot hvm guest with "vcpus=2" and "maxvcpus=4". By default, VM boot with > vcpu 0 and 1. > > 3. Hotplug vcpu 2 and 3 via "xl vcpu-set 4" on dom0. > > In my env, the steal becomes 100% within 10s after the "xl vcpu-set" command on > dom0. > > I can reproduce on kvm with similar method. However, as the initial steal clock > on kvm guest is always 0, I do not think it is easy to hit this issue on kvm. > > -------------------------------------------------------- > > The root cause is that the return type of jiffies_to_usecs() is 'unsigned int', > but not 'unsigned long'. As a result, the leading 32 bits are discarded. > > jiffies_to_usecs() is indirectly triggered by cputime_to_nsecs() at line 264. > If guest is already up for long time, the initial steal time for new vcpu might > be large and the leading 32 bits of jiffies_to_usecs() would be discarded. > > As a result, the steal at line 259 is always large and the > this_rq()->prev_steal_time at line 264 is always small. The difference at line > 260 is always large during each time steal_account_process_time() is involved. > Finally, the steal time in /proc/stat would increase abnormally. > > 252 static __always_inline cputime_t steal_account_process_time(cputime_t maxtime) > 253 { > 254 #ifdef CONFIG_PARAVIRT > 255 if (static_key_false(¶virt_steal_enabled)) { > 256 cputime_t steal_cputime; > 257 u64 steal; > 258 > 259 steal = paravirt_steal_clock(smp_processor_id()); > 260 steal -= this_rq()->prev_steal_time; > 261 > 262 steal_cputime = min(nsecs_to_cputime(steal), maxtime); > 263 account_steal_time(steal_cputime); > 264 this_rq()->prev_steal_time += cputime_to_nsecs(steal_cputime); > 265 > 266 return steal_cputime; > 267 } > 268 #endif > 269 return 0; > 270 } > > -------------------------------------------------------- > > I have emailed the kernel mailing list about the return type of > jiffies_to_usecs() and jiffies_to_msecs(): > > https://lkml.org/lkml/2019/2/26/899 > > > So far, I have two solutions: > > 1. Change the return type from 'unsigned int' to 'unsigned long' as in above > link and I am afraid it would bring side effect. The return type in latest > mainline kernel is still 'unsigned int'. > > 2. Something like below based on stable 4.9.160: 3. use jiffies64_to_nsecs() instead of trying to open code it. Juergen