Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1575161imu; Sat, 8 Dec 2018 02:53:55 -0800 (PST) X-Google-Smtp-Source: AFSGD/Websbm+kabSjvXfHZ8igCUAs563+POrGSD5aY6f6Z/pIZpdeZPA2aWkRzXORpcM0iRsqwh X-Received: by 2002:a17:902:584:: with SMTP id f4mr5523689plf.28.1544266435731; Sat, 08 Dec 2018 02:53:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544266435; cv=none; d=google.com; s=arc-20160816; b=ZAXw3At+TH9F6XBZaiLn1CyrpRwPAaIUX2cyCQRXaQG04xyJmREy/Q5uZzCRKruxry 6Je6y6bAP+zf6eyktEHnnJkeCWwNoCY2dpNTM3j7LpBmDD37PWEbEDF0CdH4/5OweWB3 A2hqXVG+7KKp4aYMDvny29b3AkwFUEqWvswdTWgSCJ4exp14U6zn2X1qQ9l/hENOX3B7 LVzETdohh/Sqas6C5Mz7yiT1D/SyJpNRNKSAXh72NvmwvvfanJ8CCzQUpk0xJOoN7WC5 7Ksqp1CGU5etvYPmz14A34OrKmOOM/lz49x4i6GVRKfCrtQp6jcNSuPhWjpbkAmAPQnj Cadg== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=NVvPx3iDHeHdNxEt/jMkPVpYf00zjygi86WbaLVtTko=; b=wYAd+3VZi2SWom/pXZIS2wRaQ/zYLdPW5la7Eflf4s56vpTVg03N7/86JpqjVowtbW w2FLNdpDVp190uRPUKEoOyxYHqi4OsOyvbELiQkksAgrvU+fisGqdphlW6TsyIHLDKJ+ Sg6JSEsi67XSUnEKZ+W7Q4h9j8xz4S/Ji5Pug3uS80vgquzAbSm0GrFGR8wT5AUeyOLz pYjl4ArHPAFqewgqjx5nPQniZtrEKMmF/ls4ohtMuSRVDwo+sdTMFMmrV4TyGlJmaTdx Y9MgRHwOJkXuYWCSmS1E1wvuomiwUjv/2UsqyWINKBr32kbVYqbLzBjE22u/HWsHPPz+ Fevw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=vkBRGpbf; 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 m15si4937291pgc.381.2018.12.08.02.53.40; Sat, 08 Dec 2018 02:53:55 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=vkBRGpbf; 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 S1726197AbeLHKwi (ORCPT + 99 others); Sat, 8 Dec 2018 05:52:38 -0500 Received: from merlin.infradead.org ([205.233.59.134]:45078 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726111AbeLHKwi (ORCPT ); Sat, 8 Dec 2018 05:52:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=NVvPx3iDHeHdNxEt/jMkPVpYf00zjygi86WbaLVtTko=; b=vkBRGpbf0hulaEwho0pic6HK8/ bTXTQ++/fTK+ayvldzDCrc8czDT+fXzid0puCjq2d/Vh3y6NC/LuEkyyFVf7ZYLw2sRbDBJzkj0Qp xijaOUoDcW01Xee42NBjugUy3DaaLysE2QwC1YJRk0huCPUXk278KXlLkYtnJguomd2Se15qU1p63 w5uRAg1Ss3tTXyEZ8uvTeK/S65mKr0DbTdLckPvPTQcZR+DteoBqWI1vHyuF05uabmurlf1uK1Cxe M2j/szHMRocCjx/hTDcrwngh3WBtCPA76y8/0cc/m5g7vxaB//IvkhL3jKTBleEgi32MYjOyW7+Em D702CVEg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gVaDg-0001yl-Eg; Sat, 08 Dec 2018 10:52:25 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 8A4D920725F5D; Sat, 8 Dec 2018 11:52:20 +0100 (CET) Date: Sat, 8 Dec 2018 11:52:20 +0100 From: Peter Zijlstra To: Nadav Amit Cc: Matthew Wilcox , Vlastimil Babka , Linux-MM , LKML , X86 ML , Ingo Molnar , Thomas Gleixner Subject: Re: Should this_cpu_read() be volatile? Message-ID: <20181208105220.GF5289@hirez.programming.kicks-ass.net> References: <20181203161352.GP10377@bombadil.infradead.org> <4F09425C-C9AB-452F-899C-3CF3D4B737E1@gmail.com> <20181203224920.GQ10377@bombadil.infradead.org> <20181206102559.GG13538@hirez.programming.kicks-ass.net> <55B665E1-3F64-4D87-B779-D1B4AFE719A9@gmail.com> <20181207084550.GA2237@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 07, 2018 at 04:40:52PM -0800, Nadav Amit wrote: > > I'm actually having difficulty finding the this_cpu_read() in any of the > > functions you mention, so I cannot make any concrete suggestions other > > than pointing at the alternative functions available. > > > So I got deeper into the code to understand a couple of differences. In the > case of select_idle_sibling(), the patch (Peter’s) increase the function > code size by 123 bytes (over the baseline of 986). The per-cpu variable is > called through the following call chain: > > select_idle_sibling() > => select_idle_cpu() > => local_clock() > => raw_smp_processor_id() > > And results in 2 more calls to sched_clock_cpu(), as the compiler assumes > the processor id changes in between (which obviously wouldn’t happen). That is the thing with raw_smp_processor_id(), it is allowed to be used in preemptible context, and there it _obviously_ can change between subsequent invocations. So again, this change is actually good. If we want to fix select_idle_cpu(), we should maybe not use local_clock() there but use sched_clock_cpu() with a stable argument, this code runs with IRQs disabled and therefore the CPU number is stable for us here. > There may be more changes around, which I didn’t fully analyze. But > the very least reading the processor id should not get “volatile”. > > As for finish_task_switch(), the impact is only few bytes, but still > unnecessary. It appears that with your patch preempt_count() causes multiple > reads of __preempt_count in this code: > > if (WARN_ONCE(preempt_count() != 2*PREEMPT_DISABLE_OFFSET, > "corrupted preempt_count: %s/%d/0x%x\n", > current->comm, current->pid, preempt_count())) > preempt_count_set(FORK_PREEMPT_COUNT); My patch proposed here: https://marc.info/?l=linux-mm&m=154409548410209 would actually fix that one I think, preempt_count() uses raw_cpu_read_4() which will loose the volatile with that patch.