From mboxrd@z Thu Jan 1 00:00:00 1970 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 36C8B1DA4E for ; Tue, 24 Dec 2024 21:47:55 +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=1735076876; cv=none; b=tKfx5WoDPod9EEY7pbe+b6js10iPk2L2DeLHc1IE5ekj54LI+rj06ta5hmMJqjz079Hriv1aPlgcmo8s9XNLxefvsPgSpmKSgmkfchnVMyZZwwpBgRyX6LHysKi1j/S9rC1Wi031AaCbhxufl5E475dwp13sHsmRpNncb42wRyI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735076876; c=relaxed/simple; bh=sykxKwhrAXua/FQurwZXt3xP+oPw+nHI6ZpizCRcu3U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dtXvFbJzBlr9A3/Dpl1ss1RK+T94nRcCQh1MZTpbYPf4IdDJ0SrUUE66NmSzZ21Wh2Xee0HrtWryS1moDFVxLIiOk7QJF8+za3Kfo5kmrdYR92WRNdzdhNa6h7MC/jKhycfB5uXJT0mYm6yrIpyITlZPLJnDYKgLhhjBXlVMT/M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PZhSsGow; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PZhSsGow" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 682EFC4CED0; Tue, 24 Dec 2024 21:47:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735076875; bh=sykxKwhrAXua/FQurwZXt3xP+oPw+nHI6ZpizCRcu3U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PZhSsGowAHPfKFshLXYxyHPQt+ljYT1MZY2bgVyrtnyyNONXefSCn0BvGhU7Ux4z/ lolU6goSTofy7ymyargUaStkR1eaV3ePREyXO9D4C0KB1i78fQb+E7SPQszLOvGg7C 4PjaeexSuj1LlmAd/dHRlR2vTV9oDfLoUNxXltsmkh7yc0POBhCyb7Mrw6e8tw70T/ 7jVeEgHYU1mBThoLvadQw2B+KQeN3rWxOzFb+gIp02a+9bzTZ/saxIm0K1IeXDESzY PqK/7SHOi5+CtbItvxN1oWx5SyICS2lJDzr2sG8x2J3gXcvmhzQ8uwyHdN9wztJxgI xxa2AKOFBrT7w== Date: Tue, 24 Dec 2024 11:47:54 -1000 From: Tejun Heo To: Changwoo Min Cc: void@manifault.com, arighi@nvidia.com, mingo@redhat.com, peterz@infradead.org, changwoo@igalia.com, kernel-dev@igalia.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v6 2/6] sched_ext: Implement scx_bpf_now_ns() Message-ID: References: <20241220062025.27724-1-changwoo@igalia.com> <20241220062025.27724-3-changwoo@igalia.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=us-ascii Content-Disposition: inline In-Reply-To: <20241220062025.27724-3-changwoo@igalia.com> Hello, On Fri, Dec 20, 2024 at 03:20:21PM +0900, Changwoo Min wrote: ... > +__bpf_kfunc u64 scx_bpf_now_ns(void) Given that the default time unit is ns for the scheduler, the _ns suffix can probably go. > +{ > + struct rq *rq; > + u64 clock; > + > + preempt_disable(); > + > + /* > + * If the rq clock is valid, use the cached rq clock. > + * Otherwise, return a fresh rq glock. > + * > + * Note that scx_bpf_now_ns() is re-entrant between a process > + * context and an interrupt context (e.g., timer interrupt). > + * However, we don't need to consider the race between them > + * because such race is not observable from a caller. > + */ > + rq = this_rq(); > + clock = READ_ONCE(rq->scx.clock); > + > + if (!(READ_ONCE(rq->scx.flags) & SCX_RQ_CLK_VALID)) { > + clock = sched_clock_cpu(cpu_of(rq)); > + > + /* > + * The rq clock is updated outside of the rq lock. > + * In this case, keep the updated rq clock invalid so the next > + * kfunc call outside the rq lock gets a fresh rq clock. > + */ > + scx_rq_clock_update(rq, clock, false); Hmm... what does this update do? ... > +static inline void scx_rq_clock_update(struct rq *rq, u64 clock, bool valid) > +{ > + if (!scx_enabled()) > + return; > + WRITE_ONCE(rq->scx.clock, clock); > + if (valid) > + WRITE_ONCE(rq->scx.flags, rq->scx.flags | SCX_RQ_CLK_VALID); > +} Isn't rq->scx.clock used iff VALID is set? If so, why does !VALID read need to update rq->scx.clock? Thanks. -- tejun