Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp624976lqj; Sun, 2 Jun 2024 14:29:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW9YUx6c6Ldckb3YkPeD7pwrba3g3lnbFcKBydkUlkRdnaqxr2cSe9nFsxkxUivUjH8Knofu2jpICK701P8TlUsknjiRS6J1K/wYSs6/w== X-Google-Smtp-Source: AGHT+IGZEHZkHKrdL0bazipZ1lTOp2N6riR5KoS7bLpbCtBjy37iJAiAA4eVc2xw/I8JiViBPh97 X-Received: by 2002:a17:903:181:b0:1f6:7e5f:5a5a with SMTP id d9443c01a7336-1f67e5f617dmr7439745ad.16.1717363765457; Sun, 02 Jun 2024 14:29:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717363765; cv=pass; d=google.com; s=arc-20160816; b=I8W3nxZ8Fwnp83xXGDKrT8BbCT5oTX1JRQ5n5MKz79kaqUdabjTrq8QaxxokYtEuZ0 RBdrtQJPXMwhl5f3ThQb6UhSZXGDub3nAVzpps/voJgFPorgC6ZY69ewrDm+iG8kGrpl UPqKGFG8Xu5J4oAXl1L/HVhxls2eKHVbPZ7lNBx0hCVCDu6izyG9wempl1+ybFbQXY1i q16tpkGcI81Wt5fNcD+vOzj7Mp/hnn/u4pj0hNdm01U8t9R/xO4cpY5gKm6zMxBtdsc9 BgvfgDCtNtd+VOlRYKlZquTXz3bnROAZsd4Bnml/0kUBpwyNJYM4jLJJbfPnMtrNtXvz 5hJg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hRM5Up7nueppdyn8tDKX7ura3aeqAbEOv/BPahwmuTI=; fh=R5u18lFiCClNcqN5uYyUaev5nfkE683ziHRHr7rxFjQ=; b=MHRgjnHIRoI6WvbF1umfaFY/SQr+WdjRoXydy8ArkJLJntZ4RbI0ii1NPgt+H+fg0+ SwDd7hrvOjef8cH/j9V38ZIrpUR9BetV3wCk3xPVdKPy9Mj1GL1/7KobiItUCa1qr7xf 9SvJBVaXVlfVaMmnrjo66RpUBx+IAF6yXkG4mKxc99Lx0YoKToLgRoO8LSIimyGhfS4y 17NuDH/6Iyu0HaPNCH2RuTdeatEG5KwxQ8yNcpyow2TFPAsnt3o3e8VMiUKtOHCXQkpr u2JLyO2JS3AxCI2e5o9SHqhp82EoBCQFSw/4uaQInpP4gz6ebWjXRF8UfiYguVgr34gC 16kQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IYv9nFD8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-198446-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198446-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f6324173e2si54164815ad.583.2024.06.02.14.29.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jun 2024 14:29:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198446-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IYv9nFD8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-198446-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198446-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 18A7728131A for ; Sun, 2 Jun 2024 21:29:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CFEE178C80; Sun, 2 Jun 2024 21:29:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IYv9nFD8" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEB103C2D for ; Sun, 2 Jun 2024 21:29:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717363757; cv=none; b=lI9QpkqUs6A7tHY8XD5cesvNnQG2XFxhMGSBAcRkIGVFAQXAOlS0bpO1PyOVc6wJXxzUKLDKCiWSsFWXiUPZ69lFTZXDiGjn8VAUw2Z7KgMfUk3oEG1PtVv7mN1cZz3xRMyeeaW/JIDD10Wh7R578XRpLZ9JBfSdnQgPXNtlarU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717363757; c=relaxed/simple; bh=1vqt2V+7MDT26Ii7pi4e+LsYEkhNVLQJB5s6dJZNILI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uZNQmVcqeCeoBpqKHIRMydKUBzqseON+kAnLM8UBaZh4on4DtfDzI7ci0cSHuP5BBYIcv5xanVTKu/+EleYdHntNF++/E74+ltMCaKHpfxfyHGg/KO9wYa/uuaPDLGq9TbR9Zf1c+/HHkw31FN3o8XEwqzbNa5NKR5LLUcgb2+E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IYv9nFD8; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28049C2BBFC; Sun, 2 Jun 2024 21:29:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717363756; bh=1vqt2V+7MDT26Ii7pi4e+LsYEkhNVLQJB5s6dJZNILI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IYv9nFD8p4fT9gp89TK7L0Bv84peRZaqrCCRyejVOqxaawQykn6XeRgt9S62pAR+Q hEJVuUHW5LwlO1y+xn9Tr3tzv2pDQzE6TKu2ifIBV69Se425ypaBvnYTx45lfwPvw9 /BESNflkAZV8FYUNekEvA+tkiIPTtP/YsRpY++vQTej/A6jWFIYmOeATiYcTD/U5v5 JMlTPdTOpQQlDuhZCgUdfrtVcrkukOOlA1oSgZeMvbTr9vb7Ix5Hts6Ld6rPXe0xmQ Sk0cax5xc3ZMk8v9C9OGHUWc8ocObkEzM/nK2PbAXLntfgzlRXGqDHtra2WtGBkgn0 IBcvkIWyFiK3w== Date: Sun, 2 Jun 2024 23:29:08 +0200 From: Frederic Weisbecker To: Oleg Nesterov Cc: Ingo Molnar , Nicholas Piggin , Peter Zijlstra , Phil Auld , Thomas Gleixner , Chris von Recklinghausen , linux-kernel@vger.kernel.org Subject: Re: [PATCH] tick/nohz_full: don't abuse smp_call_function_single() in tick_setup_device() Message-ID: References: <20240522151742.GA10400@redhat.com> <20240528122019.GA28794@redhat.com> <20240601140321.GA3758@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240601140321.GA3758@redhat.com> Le Sat, Jun 01, 2024 at 04:03:22PM +0200, Oleg Nesterov a ?crit : > Hi Frederic, > > First of all, can we please make the additional changes you suggest on top of > this patch? I'd prefer to keep it as simple as possible, I will need to backport > it and I'd like to simplify the internal review. Sure! > > On 05/30, Frederic Weisbecker wrote: > > > > And after all, pushing a bit further your subsequent patch, can we get rid of > > tick_do_timer_boot_cpu and ifdefery altogether? Such as: > > Sure, I thought about this from the very beginning, see > https://lore.kernel.org/all/20240525135120.GA24152@redhat.com/ > and the changelog in > [PATCH] tick/nohz_full: turn tick_do_timer_boot_cpu into boot_cpu_is_nohz_full > https://lore.kernel.org/all/20240530124032.GA26833@redhat.com/ > on top of this patch. > > And yes, in this case it is better to check that tick_do_timer_cpu != _NONE to > ensure that tick_nohz_full_cpu(tick_cpu) can't crash. > > So I considered the change which is very close to yours, except > > > + } else if (timekeeper == TICK_DO_TIMER_NONE) { > > + if (WARN_ON_ONCE(tick_nohz_full_enabled())) > > + WRITE_ONCE(tick_do_timer_cpu, cpu); > > I don't think we need to change tick_do_timer_cpu in this case. > And I am not sure we need to check tick_nohz_full_enabled() here. > IOW, I was thinking about Hmm, in case of cpu-hotplug operations (that is after boot), we may be past nohz enablement and therefore it might be TICK_DO_TIMER_NONE. > > if (!td->evtdev) { > int tick_cpu = READ_ONCE(tick_do_timer_cpu); > /* > * If no cpu took the do_timer update, assign it to > * this cpu: > */ > if (tick_cpu == TICK_DO_TIMER_BOOT) { > WRITE_ONCE(tick_do_timer_cpu, cpu); > tick_next_period = ktime_get(); > /* > * The boot CPU may be nohz_full, in which case the > * first housekeeping secondary will take do_timer() > * from us. > */ > } else if (!WARN_ON_ONCE(tick_cpu == TICK_DO_TIMER_NONE)) && > tick_nohz_full_cpu(tick_cpu) && > !tick_nohz_full_cpu(cpu)) { > /* > * The boot CPU will stay in periodic (NOHZ disabled) > * mode until clocksource_done_booting() called after > * smp_init() selects a high resolution clocksource and > * timekeeping_notify() kicks the NOHZ stuff alive. > * > * So this WRITE_ONCE can only race with the READ_ONCE > * check in tick_periodic() but this race is harmless. > */ > WRITE_ONCE(tick_do_timer_cpu, cpu); > } > > But you know, somehow I like > [PATCH] tick/nohz_full: turn tick_do_timer_boot_cpu into boot_cpu_is_nohz_full > https://lore.kernel.org/all/20240530124032.GA26833@redhat.com/ > a bit more, to me the code looks more understandable this way. > > Note that this patch doesn't really need to keep #ifdef CONFIG_NO_HZ_FULL, > > if (!td->evtdev) { > static bool boot_cpu_is_nohz_full; > /* > * If no cpu took the do_timer update, assign it to > * this cpu: > */ > if (READ_ONCE(tick_do_timer_cpu) == TICK_DO_TIMER_BOOT) { > WRITE_ONCE(tick_do_timer_cpu, cpu); > tick_next_period = ktime_get(); > /* > * The boot CPU may be nohz_full, in which case the > * first housekeeping secondary will take do_timer() > * from us. > */ > boot_cpu_is_nohz_full = tick_nohz_full_cpu(cpu); > } else if (boot_cpu_is_nohz_full && !tick_nohz_full_cpu(cpu)) { > boot_cpu_is_nohz_full = false; > /* > * The boot CPU will stay in periodic (NOHZ disabled) > * mode until clocksource_done_booting() called after > * smp_init() selects a high resolution clocksource and > * timekeeping_notify() kicks the NOHZ stuff alive. > * > * So this WRITE_ONCE can only race with the READ_ONCE > * check in tick_periodic() but this race is harmless. > */ > WRITE_ONCE(tick_do_timer_cpu, cpu); > } > > should work without #ifdef. > > In this case I don't think we need the _NONE check, tick_sched_do_timer() will > complain. Right... > > But I won't argue. I will be happy to make V2 which follows your recommendations > but again, can I do this on top of this patch? I guess the static version above should work to remove the ifdef. And yes on top is fine. Thanks!