Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2667336rdb; Mon, 5 Feb 2024 13:49:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCf92XNMpCW6mP/Mg8a1rmmKjiDrs9t4seZkRD6LeGDbj8mgXSfoeYFDelacSzKEzuFtvu X-Received: by 2002:a17:906:3587:b0:a36:f694:be6e with SMTP id o7-20020a170906358700b00a36f694be6emr200046ejb.12.1707169753132; Mon, 05 Feb 2024 13:49:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707169753; cv=pass; d=google.com; s=arc-20160816; b=U3OCMv49WtPPUIH4/+/NcWxBjFMP0tHvXjFXFjHlQKekZcSv2kSCuqIkQAttN/A6NY mQgfbNBI+1AS9w789M+BJZYTb2949PpJfil0fmJ6MI7b+TJ0K6EeosQYlNqbB4mFps3U eMUmC5A3tznf4HSlAS8izCWIJaS6d4v2pOJDMFSNNKGqB4i93gRd8wLTT5fQuWWgclqF bnc3BRatIi7GukvjvquIzNgq+m7nKxRqR+oUaSISOy+km7H7X162x/0pUw189X1m3Co7 eYkwzObOpOWgK8cQCNZ6hVbRuCT5pYY72MFzpUxXAAT7Z8QVOkU/MDLlgt1pqagVSRPE mfrg== 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=DkyL2wgQqWmaZFR8JOy9Mv82PeSnYI5eQmogKsTxoZs=; fh=TK+9QnUFT0ixmBV7O1Nf8gE0L6r7cbqFTEWmS+EIRII=; b=eSMVcdmy7TcuodVmMbiVwpoWGs0FMSuclz6JDOCF3y4GOp6UBbADxaUZzNL7KnqW2Q UljP1dy5smDYiy+yvnd0k38R7zr4tqlm1fzIu4bbaYPylsASaZ3af1p2Ha2KE7PI3MOx YlfUiAr8bylGBB8UiHUJFBAUnKW6rb+OZ0WnBg+drO7AlrQiiibOT8iN0Osx/0bdiRf3 XZNynBts28EWqisoWuElxRUYZWvW5gPDCJBss7tifSR3zbisvEskZ6LCubmAfHbHAzcc ObjPGPKIT76OwuGUNW96DnlxyEVKVfpurMNV+seoLUaYgOEvIlfnNpqS6zYFAf0bPO7e MLEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AoBZ6hj2; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-53916-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53916-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCWnjQee/iPm+65fWLRYQp1NEfWzEmgQ94NJxrdAhjIDy1zfeHY9Y/WVME4cG+kDaz7DCGpZq1wbGcPjnLcJ0NipNET7GUdR1sIUvgrHzQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id gu10-20020a170906f28a00b00a367f0b0b74si265172ejb.641.2024.02.05.13.49.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 13:49:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53916-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AoBZ6hj2; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-53916-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53916-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 am.mirrors.kernel.org (Postfix) with ESMTPS id DB2C91F2B8B2 for ; Mon, 5 Feb 2024 21:49:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 34D33134742; Mon, 5 Feb 2024 20:28:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AoBZ6hj2" 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 4605213472D for ; Mon, 5 Feb 2024 20:28:42 +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=1707164922; cv=none; b=QCdC5H4x3TeDYzWTpMMsIX75hPgvmcCFP8koViH4zD5RQx/Tdk+y+KQp810G8vb7fIk4l4AJMI6O6g1uPU535pD6R/cqMSQMW0yrI6A6DoZZCihib75+Gj1bow5aIYitGkP+sjDHJmcSob92OGEBhgZ54H0A9EO45494T0P6RLE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707164922; c=relaxed/simple; bh=XpivmY6ib69pXpZ7ii9oBxf6gCCiDNN1XjEi8/M3fCI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sOEfgGBW4Z/wxBNmJc1edWyet3gKWZAImhatyoM9arRXwG9aMcQsLZGkAQKBLI3op7spppQwLxyWHMo9WUoMs1WzbJrUAjRdaMwBkJ3uYGJWGtzgmIhEATsrnN0UlpF2g7DsXGVBNfl49AYZDtelBV1zG/VNUzAQKFTkDG69t54= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AoBZ6hj2; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B158AC433F1; Mon, 5 Feb 2024 20:28:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707164922; bh=XpivmY6ib69pXpZ7ii9oBxf6gCCiDNN1XjEi8/M3fCI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AoBZ6hj26Um+kCTmNQWGH6P1pNsPabqL1nGMXcFoLs4Vp4NSjpsF5o3pJK5EnCPVx hkWebOVgP3e2dR9l0Z9qv3CuEsg5oDOrvDNUcgcwT+12oM7+f0J6LmKnwlQDQsb2We qY4Crmui5HrC53UHgMlxCEDDgu02viILJoOMJXawuv4Ykz00D7LOzv0gvdhOL7khan bOk5g1CfXb7ANF8RmJhSNeTwyIuiXtt4eRoF9GWxcKDxRrUmWylSCbKCj8WLq9EseR EaF7vvU8W56ojuBl4ct7pX0sa/Tf2GNDdlJwfggWBHgKDALB+XQAMtmAvLvOZGPkHc l8M858HEw7vHg== Date: Mon, 5 Feb 2024 21:28:38 +0100 From: Frederic Weisbecker To: Anna-Maria Behnsen Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , John Stultz , Thomas Gleixner , Eric Dumazet , "Rafael J . Wysocki" , Arjan van de Ven , "Paul E . McKenney" , Rik van Riel , Steven Rostedt , Sebastian Siewior , Giovanni Gherdovich , Lukasz Luba , "Gautham R . Shenoy" , Srinivas Pandruvada , K Prateek Nayak Subject: Re: [PATCH v10 18/20] timers: Implement the hierarchical pull model Message-ID: References: <871q9qucjy.fsf@somnus> 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: <871q9qucjy.fsf@somnus> Le Mon, Feb 05, 2024 at 04:59:45PM +0100, Anna-Maria Behnsen a ?crit : > Frederic Weisbecker writes: > > > Le Mon, Jan 15, 2024 at 03:37:41PM +0100, Anna-Maria Behnsen a ?crit : > >> +static bool tmigr_handle_remote_up(struct tmigr_group *group, > >> + struct tmigr_group *child, > >> + void *ptr) > >> +{ > >> + struct tmigr_remote_data *data = ptr; > >> + u64 now, next = KTIME_MAX; > >> + struct tmigr_event *evt; > >> + unsigned long jif; > >> + u8 childmask; > >> + > >> + jif = data->basej; > >> + now = data->now; > >> + > >> + childmask = data->childmask; > >> + > >> +again: > >> + /* > >> + * Handle the group only if @childmask is the migrator or if the > >> + * group has no migrator. Otherwise the group is active and is > >> + * handled by its own migrator. > >> + */ > >> + if (!tmigr_check_migrator(group, childmask)) > >> + return true; > >> + > >> + raw_spin_lock_irq(&group->lock); > >> + > >> + evt = tmigr_next_expired_groupevt(group, now); > >> + > >> + if (evt) { > >> + unsigned int remote_cpu = evt->cpu; > >> + > >> + raw_spin_unlock_irq(&group->lock); > >> + > >> + next = tmigr_handle_remote_cpu(remote_cpu, now, jif); > >> + > >> + /* check if there is another event, that needs to be handled */ > >> + goto again; > >> + } else { > >> + raw_spin_unlock_irq(&group->lock); > >> + } > >> + > >> + /* > >> + * Update of childmask for the next level and keep track of the expiry > >> + * of the first event that needs to be handled > >> + */ > >> + data->childmask = group->childmask; > >> + data->firstexp = next; > > > > So assume we have: > > > > [GRP1:0] > > migrator = [GRP0:0] > > active = [GRP0:0] > > nextevt = TIMER3 > > / \ > > [GRP0:0] [GRP0:1] > > migrator = CPU0 migrator = NONE > > active = CPU0 active = NONE > > nextevt = KTIME_MAX nextevt = TIMER3 > > / \ / \ > > 0 1 2 3 > > idle idle idle idle (TIMER3) > > > > Then CPU 0 goes idle: > > > > [GRP1:0] > > migrator = NONE > > active = NONE > > nextevt = TIMER3 > > / \ > > [GRP0:0] [GRP0:1] > > migrator = NONE migrator = NONE > > active = NONE active = NONE > > nextevt = KTIME_MAX nextevt = TIMER3 > > / \ / \ > > 0 1 2 3 > > idle idle idle idle (TIMER3) > > > > CPU 0 is the idle migrator and its tmc->wakeup is TIMER3. > > But CPU 0 has a local timer that expires before TIMER3. > > > > When that timer interrupt fires, it raises the softirq, which > > executes on IRQ tail. So CPU0 eventually calls tmigr_handle_remote() > > before TIMER3 has expired. > > > > This leads to tmigr_next_expired_groupevt() to return NULL and then > > data->firstexp = KTIME_MAX and then tmc->wakeup = KTIME_MAX. > > > > Later on, tmigr_new_timer() is called with a KTIME_MAX global > > event and so tmc->wakeup stays with KTIME_MAX, ignoring TIMER3. > > > > It looks like you need to handle the tmigr_next_expired_groupevt() > > case returning NULL. > > Yes. You are right. group->next_expiry is updated via > tmigr_next_expired_groupevt(). So I should take this value to rely on > for the firstevt. > > But with this, we do not need the return value of > tmigr_handle_remote_cpu(). When the upperst level is inactive and there > is a timer (e.g. propagated there by tmigr_handle_remote_cpu()), the > return value of tmigr_handle_remote_cpu() is the next_expiry of the top > level group. But this value is also noticed by walking the hierarchy up > to the top level with tmigr_handle_remote_up(). Indeed that's a nice simplification! This also cure an issue with KTIME_MAX overwriting data->firstexp in tmigr_handle_remote_up() while walking upper level after an expiration on below level. Thanks.