From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (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 6ECDD26A1AF for ; Thu, 11 Dec 2025 08:11:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765440683; cv=none; b=oAMXC0Bf1aNksr57T9NYfCLMb/pDwfoZow3SN0l8XGqHZrLLDrmsU/K/xZ5OsgRi5an8MoPCcMpzE+muhiRB97Dwo/O3r2LcJSDN3dF+AeDJNwPLPrWdnBQjvcCmvfzmdt747ZRRe5YxV+oxm9O1Ko4tfnQnVZlx9ks3b7Njlzw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765440683; c=relaxed/simple; bh=nN5wirTN9tjMp6r6vFZJpPymE0yDhOeNAiBpNho6SPE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=BqeC5H5DP+s9z7CshRpxRY3fQbJid2AB6oK7hW2VUaqrkLn0davHigk2MuhgbVJzSStBHM/N1M+yznBxeVk1vYN3Ni0Lfmuapgspz7QQ7UIn2EwgN3zo3Ty0wK6tW4QyBZ6RfaIUGCCYNZaHORQtoZ1vRNjHpXoNInszqgJOXxQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=fRoSdc9N; arc=none smtp.client-ip=95.215.58.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="fRoSdc9N" Message-ID: <22446f7a-5c10-4569-87f6-552a036e8707@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1765440679; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rhcyAatNwAQ/AVLR9aKu+B+9ZToyBkixtQThIkEBfmU=; b=fRoSdc9N5IqnU1GA716GgxPXyBBH3uxxDt1wZ3iF58+k1/eB6MbIS1Ynzno7rH/JqD3nCQ lUnKT9AOuar0Gg1R9MwYySPoZzqIPskuQxogJBf+PTd/k3w5IdVjtDQz1AHPOomoB6xZGl AOzqj9wYsyDWKUDJH30Bf/eRmMLOkt0= Date: Thu, 11 Dec 2025 16:11:07 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH 2/2] sched: psi: use rq_clock() during task state changes To: Johannes Weiner , Peter Zijlstra , Suren Baghdasaryan , Ingo Molnar Cc: Dietmar Eggemann , John Stultz , linux-kernel@vger.kernel.org References: <20251210155805.752523-1-hannes@cmpxchg.org> <20251210155805.752523-2-hannes@cmpxchg.org> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou In-Reply-To: <20251210155805.752523-2-hannes@cmpxchg.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2025/12/10 23:58, Johannes Weiner wrote: > In the hottest psi paths, the scheduler already caches the cpu_clock() > call for the event in rq->clock. Now that the clocks between state > changes and pressure aggregation don't need to be synchronized inside > the seqcount section anymore, use the cheaper rq_clock(). > > Add update_rq_clock() calls to the few places where psi is entered > without the rq already locked. > > schbench -n 0 (no think ops): > > Before: average rps: 204408.50 > After: average rps: 204755.90 > > 2.67% -0.54% [kernel.kallsyms] [k] sched_clock_noinstr > > Signed-off-by: Johannes Weiner Reviewed-by: Chengming Zhou Thanks. > --- > kernel/sched/core.c | 3 ++- > kernel/sched/psi.c | 12 +++++++----- > kernel/sched/stats.h | 1 + > 3 files changed, 10 insertions(+), 6 deletions(-) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 41ba0be16911..cc66415b85a1 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -5519,9 +5519,10 @@ void sched_tick(void) > rq_lock(rq, &rf); > donor = rq->donor; > > + update_rq_clock(rq); > + > psi_account_irqtime(rq, donor, NULL); > > - update_rq_clock(rq); > hw_pressure = arch_scale_hw_pressure(cpu_of(rq)); > update_hw_load_avg(rq_clock_task(rq), rq, hw_pressure); > > diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c > index 4b7bf8eb46c2..4a0a83f1d1dc 100644 > --- a/kernel/sched/psi.c > +++ b/kernel/sched/psi.c > @@ -932,7 +932,7 @@ void psi_task_change(struct task_struct *task, int clear, int set) > return; > > cpu = task_cpu(task); > - now = cpu_clock(cpu); > + now = rq_clock(cpu_rq(cpu)); > > psi_flags_change(task, clear, set); > > @@ -947,7 +947,7 @@ void psi_task_switch(struct task_struct *prev, struct task_struct *next, > { > struct psi_group *common = NULL; > int cpu = task_cpu(prev); > - u64 now = cpu_clock(cpu); > + u64 now = rq_clock(cpu_rq(cpu)); > > psi_write_begin(cpu); > > @@ -1026,9 +1026,8 @@ void psi_account_irqtime(struct rq *rq, struct task_struct *curr, struct task_st > { > int cpu = task_cpu(curr); > struct psi_group_cpu *groupc; > + u64 irq, now; > s64 delta; > - u64 irq; > - u64 now; > > if (static_branch_likely(&psi_disabled) || !irqtime_enabled()) > return; > @@ -1046,7 +1045,7 @@ void psi_account_irqtime(struct rq *rq, struct task_struct *curr, struct task_st > return; > rq->psi_irq_time = irq; > > - now = cpu_clock(cpu); > + now = rq_clock(rq); > > psi_write_begin(cpu); > for_each_group(group, task_psi_group(curr)) { > @@ -1089,6 +1088,7 @@ void psi_memstall_enter(unsigned long *flags) > * race with CPU migration. > */ > rq = this_rq_lock_irq(&rf); > + update_rq_clock(rq); > > current->in_memstall = 1; > psi_task_change(current, 0, TSK_MEMSTALL | TSK_MEMSTALL_RUNNING); > @@ -1119,6 +1119,7 @@ void psi_memstall_leave(unsigned long *flags) > * race with CPU migration. > */ > rq = this_rq_lock_irq(&rf); > + update_rq_clock(rq); > > current->in_memstall = 0; > psi_task_change(current, TSK_MEMSTALL | TSK_MEMSTALL_RUNNING, 0); > @@ -1187,6 +1188,7 @@ void cgroup_move_task(struct task_struct *task, struct css_set *to) > } > > rq = task_rq_lock(task, &rf); > + update_rq_clock(rq); > > /* > * We may race with schedule() dropping the rq lock between > diff --git a/kernel/sched/stats.h b/kernel/sched/stats.h > index c903f1a42891..cb67a81e92b6 100644 > --- a/kernel/sched/stats.h > +++ b/kernel/sched/stats.h > @@ -210,6 +210,7 @@ static inline void psi_ttwu_dequeue(struct task_struct *p) > struct rq *rq; > > rq = __task_rq_lock(p, &rf); > + update_rq_clock(rq); > psi_task_change(p, p->psi_flags, 0); > __task_rq_unlock(rq, p, &rf); > }