Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1298822pxa; Sat, 15 Aug 2020 14:56:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/JZ0gcxUMjtT62LsmRgdbA/rYQD0yNeg7ITIZDK9G7by6+PODsyJgVt+QzImqHwgWPUJU X-Received: by 2002:a05:6402:a4c:: with SMTP id bt12mr8215641edb.360.1597528577447; Sat, 15 Aug 2020 14:56:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597528577; cv=none; d=google.com; s=arc-20160816; b=om8SBkf8F0D51eS8jHdLAysHIbPWqgwuSoAGMCLiiQ0XW1CDqOIpKFSFkSD7uBwn5E gMZoVDftw3q6FXVZo1O+c6pmi3B3n7i+rHLaqMBvZk1yYUWSNgYQldKzCo05Kk0KKl+2 2Ozp2NJ74/V2eLv3AUA8kAqLLQVafbIoCRvXzfgq4jsQQhCa4Swbnppsl9Q8behwGxhj iCWmEz8WU/u+bcjG+9zrK0SZonJSKYO71Q2kiroR3IDq41joGEHxFfn54ljtbxYdidly SQLB7rLcmpCe/clm2PSnmwYt7PLz3/EL15vR290+BPMSmhACYrkvdktm7/6Mja7+aJK4 H/GQ== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FwsOWE3cvymHDK4XxTdA3wF4GOr+2WPCQ6wnKRbw/jI=; b=m0Hnn4bUj4Gc0FVq9ZuPvhbiMijC9vVYV0dMAbEAfw5/9EVX7wx6Hg1tdXiFat0euD 9kD03UDOJmpV8s/R7cxcP8cKO+ZZ0ZBmRax1FKYJQ7CQZHWOLBFlKxTSSJ35FE6euuJY MamwgAcZHx0CmxrrtJdBM9lTFBqqBFZxD/27HDytv+qjp+rtStm+1Lx5BKikI2D0B3sh g7BvpMrin30bRDpe6rUWY+M2Fh4iDLXlZvJ8OctqjKJ8izcxIAV0w9lbaSCoB4By7tyi uvpYo5ZkZ8uVzFk76v/GuK17qMpLeusUdGjYiVlk8jhjqCaqodsoCSg8V/IT0KvzegkP wsCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=StWlDLaq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lk1si8241365ejb.504.2020.08.15.14.55.54; Sat, 15 Aug 2020 14:56:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=StWlDLaq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729295AbgHOVye (ORCPT + 99 others); Sat, 15 Aug 2020 17:54:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729112AbgHOVwg (ORCPT ); Sat, 15 Aug 2020 17:52:36 -0400 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 171EFC06137D for ; Fri, 14 Aug 2020 20:19:37 -0700 (PDT) Received: by mail-qk1-x744.google.com with SMTP id 77so10195377qkm.5 for ; Fri, 14 Aug 2020 20:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FwsOWE3cvymHDK4XxTdA3wF4GOr+2WPCQ6wnKRbw/jI=; b=StWlDLaq0MYdU1CWVuIg/J4GYVc+68Ndih7GA3RYvlHvpUIZIf7YgKHremE+6JTJUO xexuEqSkh+h37IgJdNAHSFAgEgU12rarmHYgKhMF2OPIcgpQ0OBxq9Tb+z80eovyzwwB QRRN5uoJO8eH3cecRwWPlUIGRwBTM9VQqnDQE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FwsOWE3cvymHDK4XxTdA3wF4GOr+2WPCQ6wnKRbw/jI=; b=dWLd9od2/rQ6WpiCzTKetr+gtHypOM2rCNeLJLs/dIZbJv6HxKydsasu51LccbdYpc Sed/YZIvqE5Ceu10ZChbo5rT+dtiCX+Fud7CCKd5NLt1Frq8daXWTJzXhUeqO9DeQJkm cEliPBiqigIO2pFISgrL3UinnzVGDdSDZ2lrYcskxl5pmV7UPp/4+iNpB+e7VYV9zsGg 4gOmcn3oyLjMy0ROk5zhBGyuDDFN9NjbgAirCKhFnIefOEazXZgVS8GL1SXegNkkAqk1 AZV8BMr7A6eGfBVszngwOtvvSXEAo4tKZ0r7TY57vQkLY/KMtxnAqtTyO99eVNtPR6IR FDtQ== X-Gm-Message-State: AOAM5303h16MSR6lnG1WX9HOzhEP2yd+38crig79kNPKk6aZgvsZHi3g EWuyQ/wQ5ugfBcctscsIgN/vvjMFAiXoEw== X-Received: by 2002:a05:620a:1009:: with SMTP id z9mr4628395qkj.107.1597461576169; Fri, 14 Aug 2020 20:19:36 -0700 (PDT) Received: from joelaf.cam.corp.google.com ([2620:15c:6:12:cad3:ffff:feb3:bd59]) by smtp.gmail.com with ESMTPSA id p12sm10055199qkk.118.2020.08.14.20.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 20:19:35 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: Vineeth Pillai , Joel Fernandes , Aaron Lu , Aubrey Li , Julien Desfossez , Kees Cook , "Paul E. McKenney" , Paul Turner , Peter Zijlstra , Steven Rostedt , Thomas Gleixner , Tim Chen , Tim Chen , Vincent Guittot , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), fweisbec@gmail.com, kerrnel@google.com, Phil Auld , Valentin Schneider , Paolo Bonzini , Chen Yu , Christian Brauner Subject: [PATCH RFC 12/12] sched/coresched: rq->core should be set only if not previously set Date: Fri, 14 Aug 2020 23:19:08 -0400 Message-Id: <20200815031908.1015049-13-joel@joelfernandes.org> X-Mailer: git-send-email 2.28.0.220.ged08abb693-goog In-Reply-To: <20200815031908.1015049-1-joel@joelfernandes.org> References: <20200815031908.1015049-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vineeth Pillai During hotplug events, smt_mask would not contain all the CPUs in a core and this can cause reassigning of rq->core, which breaks the core-wide counters that are needed for tracking kernel-mode entry/exits. This patch therefore makes sure that rq->core does not change once it is set. Signed-off-by: Vineeth Pillai Signed-off-by: Joel Fernandes (Google) --- kernel/sched/core.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 5da5b2317b21..464493f3a759 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -7519,21 +7519,25 @@ int sched_cpu_starting(unsigned int cpu) struct rq *rq, *core_rq = NULL; int i; - for_each_cpu(i, smt_mask) { - rq = cpu_rq(i); - if (rq->core && rq->core == rq) - core_rq = rq; - init_irq_work(&rq->core_irq_work, sched_core_irq_work); - } + core_rq = cpu_rq(cpu)->core; + + if (!core_rq) { + for_each_cpu(i, smt_mask) { + rq = cpu_rq(i); + if (rq->core && rq->core == rq) + core_rq = rq; + init_irq_work(&rq->core_irq_work, sched_core_irq_work); + } - if (!core_rq) - core_rq = cpu_rq(cpu); + if (!core_rq) + core_rq = cpu_rq(cpu); - for_each_cpu(i, smt_mask) { - rq = cpu_rq(i); + for_each_cpu(i, smt_mask) { + rq = cpu_rq(i); - WARN_ON_ONCE(rq->core && rq->core != core_rq); - rq->core = core_rq; + WARN_ON_ONCE(rq->core && rq->core != core_rq); + rq->core = core_rq; + } } printk("core: %d -> %d\n", cpu, cpu_of(core_rq)); -- 2.28.0.220.ged08abb693-goog