Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13648821ybl; Sun, 29 Dec 2019 17:09:32 -0800 (PST) X-Google-Smtp-Source: APXvYqwLLmX0Q2Gtz+6iWpXXje/4uIbTc6IiZ/tGucWbtFuTAf4QJ97DLS+JvuGovQj3V52OEfyd X-Received: by 2002:a9d:5c1:: with SMTP id 59mr72486591otd.192.1577668172706; Sun, 29 Dec 2019 17:09:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577668172; cv=none; d=google.com; s=arc-20160816; b=aKRWwZY+Xjf8ErZ95gAjLA7/Uaa+ibVVCufvCzGeB8QlkIfgi4mIdnd9vEMKafS1Of Nph+yYk9Rhsx7RXXu6lsk4rMWRY01uFSWF1SckaNMXb3gyi6vpxhheanZdCDj0nONdgo ZhJoGZTRjvXWstdYk5pvayQ+C021GbZgI84PGXo3WZo1rvvVGlU75xtqiyiIxyz/ChuC OcEgsDCGQSsIb6wU+XfkGy1KfsItRnMGVLqMAdus2zJunGuADOnlJsCAhU2dgJQxam9R r9kmmFhNimczSULFbZ9OcCBO3lxWeqqwORUSzUGOgvJmMEE/E52Pk/KNNZL/1Xy5U5dq bzTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=bzOwmPivElsxLTt2tgWnOq2hHa+zO6L5P45OKVZv6J8=; b=jnZ7CZ//wwMbXgtEUgAhIrXFbuhgJHVIUc6dC8yKXPHyj6Ia8OgRqt9TwKyXsqQpME xazGI3g+ThdAa4Mbpq2K8Vzj+xp5DPRyMMlDzJa3659x9i0Xl343qHol9xANul1VoXUG m5wjkt81oHS9m7qleh/BnFGhfUo1+4vlmY1y4tbm8slNB/TDNGuD9CUm0XyYzgYD3H7A PGvcDw2UhxIG5XflCSavB4LHdSQNRkcOEIGMJdP5TxrNCIfZVnODxY1rsFA9s1xKUiVl 8v5EDe4OPq3cJVBbPj45BEWT9gbu1s1uWAb2zvMjz7yhKmw1tHg16uvuXBvrSg9hY4SP +uxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="LUHGkfy/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p22si22587666ota.43.2019.12.29.17.09.21; Sun, 29 Dec 2019 17:09:32 -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; dkim=pass header.i=@kernel.org header.s=default header.b="LUHGkfy/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726661AbfL3BIo (ORCPT + 99 others); Sun, 29 Dec 2019 20:08:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:53504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726543AbfL3BIn (ORCPT ); Sun, 29 Dec 2019 20:08:43 -0500 Received: from localhost (lfbn-ncy-1-150-155.w83-194.abo.wanadoo.fr [83.194.232.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A85B2207FD; Mon, 30 Dec 2019 01:08:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577668123; bh=p6eVjqX/8BJ4EZqmYWA7QlEUQWr7Nc8fEY/GzKskeTs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LUHGkfy/dSnejjScQOCNVj09R7nAcaFnzCnB30+aGUuCvpKxjPa4FxzP1IerLKFuj F39jAJ8S9LWgGUi3J69UESavcy4MvVicchaFU5cXdwLO+M77toTnpF22oTU/CRXt1E XOF2sNshOJVERQdcaJrmCEKGPE7SSDZQPmpd+LUk= Date: Mon, 30 Dec 2019 02:08:40 +0100 From: Frederic Weisbecker To: Chris Wilson Cc: Ingo Molnar , Peter Zijlstra , LKML , Jacek Anaszewski , Wanpeng Li , "Rafael J . Wysocki" , Benjamin Herrenschmidt , Rik van Riel , Thomas Gleixner , Yauheni Kaliuta , Viresh Kumar , Pavel Machek Subject: Re: [PATCH 2/6] sched/vtime: Bring up complete kcpustat accessor Message-ID: <20191230010839.GA8740@lenoir> References: <20191121024430.19938-1-frederic@kernel.org> <20191121024430.19938-3-frederic@kernel.org> <157756657962.14652.10349541055640858962@skylake-alporthouse-com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <157756657962.14652.10349541055640858962@skylake-alporthouse-com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Dec 28, 2019 at 08:56:19PM +0000, Chris Wilson wrote: > I'm randomly hitting this WARN on a non-virtualised system reading > /proc/stat. > > vtime->state is updated under the write_seqcount, so the access here is > deliberately racey, and the change in vtime->state would be picked up > the seqcount_retry. > > Quick suggestion would be something along the lines of > > static int vtime_state_check(struct vtime *vtime, int cpu) > { > + int state = READ_ONCE(vtime->state); > + > /* > * We raced against a context switch, fetch the > * kcpustat task again. > @@ -930,10 +932,10 @@ static int vtime_state_check(struct vtime *vtime, int cpu) > * > * Case 1) is ok but 2) is not. So wait for a safe VTIME state. > */ > - if (vtime->state == VTIME_INACTIVE) > + if (state == VTIME_INACTIVE) > return -EAGAIN; > > - return 0; > + return state; > } > > static u64 kcpustat_user_vtime(struct vtime *vtime) > @@ -1055,7 +1057,7 @@ static int kcpustat_cpu_fetch_vtime(struct kernel_cpustat *dst, > cpustat = dst->cpustat; > > /* Task is sleeping, dead or idle, nothing to add */ > - if (vtime->state < VTIME_SYS) > + if (err < VTIME_SYS) > continue; > > delta = vtime_delta(vtime); > @@ -1064,15 +1066,15 @@ static int kcpustat_cpu_fetch_vtime(struct kernel_cpustat *dst, > * Task runs either in user (including guest) or kernel space, > * add pending nohz time to the right place. > */ > - if (vtime->state == VTIME_SYS) { > + if (err == VTIME_SYS) { > cpustat[CPUTIME_SYSTEM] += vtime->stime + delta; > - } else if (vtime->state == VTIME_USER) { > + } else if (err == VTIME_USER) { > if (task_nice(tsk) > 0) > cpustat[CPUTIME_NICE] += vtime->utime + delta; > else > cpustat[CPUTIME_USER] += vtime->utime + delta; > } else { > - WARN_ON_ONCE(vtime->state != VTIME_GUEST); > + WARN_ON_ONCE(err != VTIME_GUEST); > if (task_nice(tsk) > 0) { > cpustat[CPUTIME_GUEST_NICE] += vtime->gtime + delta; > cpustat[CPUTIME_NICE] += vtime->gtime + delta; > > Or drop the warn. Good catch, can I use your Signed-off-by ? Thanks.