Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp12461671ybl; Sat, 28 Dec 2019 12:58:08 -0800 (PST) X-Google-Smtp-Source: APXvYqzHU7J5mI3IHXJ8l5RZiec2Gdq39UOuYgni6/nNx4zqx/RThSpk97QBFU3ZqN7SKCjcCUYu X-Received: by 2002:a9d:6b12:: with SMTP id g18mr62503691otp.211.1577566688903; Sat, 28 Dec 2019 12:58:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577566688; cv=none; d=google.com; s=arc-20160816; b=YzLgTC3sDTL9lepkaZjgIugEhh7Nqm1YIuXOF2bMMP8RDE3n8nLCsd3mpm1ixxNrOw h8bMOEJzphDLgJtsHz25zvQaMxG5H3BOGUQklv8jKPBWkIpSo9xrV5kM96eIQIietVxi 6/QxdT0j5BrkIhrwVH2ZP0E9CMepr0/aBElS6FnNE2OxgNPx1LwAfr5EWE7HEDYZ8Zo6 FFjlXn5MtkoTEb3b0dk67MogMxFdC/m9HrinKIKU2OZfQJLodu+j/XhV5dgcUqVj5y8E Uq8Kxiel+9X8mxqPWsU5Ga4vmmcOFUNRze28wwhrQanM6BJ5sgCue6f6ZLnWp364JpsO nBLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:subject:user-agent:message-id :references:cc:in-reply-to:from:to:content-transfer-encoding :mime-version; bh=6UujQs3Q3CES6tGR+6edOeroKMzDIxvhmdZ9cIxtaNI=; b=oCp7SdIaMoyHIk/KfLvCN9D+hfonEK3APGUP9w2IEXFcNWe9TfkbBQ9kG8YhWjbTZ7 n0aWK2KCi4DLKwfv3/vQsC4Ljs6BxoLfDbsxFInOzD1McMeGqpO6Zs7dOL2hm1GmmGdh 3HN+zh20u1wUP8rz9b+u51B4tlX3qXtYI8sO6D7ES+sHbVsBRFuge6Mkgd1T0nHQ4iuM NKLgnrjhsQxHMDMU3E+1GQLiShHnRHP/7+q1J6u+t1XFXMd+8Toyyw9LTowg4UeckPI1 oNXDbUh158faA7dR+TYdd29v6MIfNdpE5va7hlOguU0/VH24WlvFG/rD5Ja0HI5z4QUB lDSA== 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 g26si21254142otn.180.2019.12.28.12.57.57; Sat, 28 Dec 2019 12:58:08 -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 S1726752AbfL1U5T convert rfc822-to-8bit (ORCPT + 99 others); Sat, 28 Dec 2019 15:57:19 -0500 Received: from mail.fireflyinternet.com ([109.228.58.192]:52509 "EHLO fireflyinternet.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726661AbfL1U5T (ORCPT ); Sat, 28 Dec 2019 15:57:19 -0500 X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from localhost (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP (TLS) id 19715024-1500050 for multiple; Sat, 28 Dec 2019 20:56:21 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT To: Frederic Weisbecker , Ingo Molnar , Peter Zijlstra From: Chris Wilson In-Reply-To: <20191121024430.19938-3-frederic@kernel.org> Cc: LKML , Frederic Weisbecker , Jacek Anaszewski , Wanpeng Li , "Rafael J . Wysocki" , Benjamin Herrenschmidt , Rik van Riel , Thomas Gleixner , Yauheni Kaliuta , Viresh Kumar , Pavel Machek References: <20191121024430.19938-1-frederic@kernel.org> <20191121024430.19938-3-frederic@kernel.org> Message-ID: <157756657962.14652.10349541055640858962@skylake-alporthouse-com> User-Agent: alot/0.6 Subject: Re: [PATCH 2/6] sched/vtime: Bring up complete kcpustat accessor Date: Sat, 28 Dec 2019 20:56:19 +0000 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Frederic Weisbecker (2019-11-21 02:44:26) > +static int kcpustat_cpu_fetch_vtime(struct kernel_cpustat *dst, > + const struct kernel_cpustat *src, > + struct task_struct *tsk, int cpu) > +{ > + struct vtime *vtime = &tsk->vtime; > + unsigned int seq; > + int err; > + > + do { > + u64 *cpustat; > + u64 delta; > + > + seq = read_seqcount_begin(&vtime->seqcount); > + > + err = vtime_state_check(vtime, cpu); > + if (err < 0) > + return err; > + > + *dst = *src; > + cpustat = dst->cpustat; > + > + /* Task is sleeping, dead or idle, nothing to add */ > + if (vtime->state < VTIME_SYS) > + continue; > + > + delta = vtime_delta(vtime); > + > + /* > + * Task runs either in user (including guest) or kernel space, > + * add pending nohz time to the right place. > + */ > + if (vtime->state == VTIME_SYS) { > + cpustat[CPUTIME_SYSTEM] += vtime->stime + delta; > + } else if (vtime->state == 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); 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. -Chris