From patchwork Sat Oct 7 06:21:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yang X-Patchwork-Id: 149506 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp772016vqo; Fri, 6 Oct 2023 23:22:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpHSiZoM/sjry48hGHAFBKYOqXYUhwYQ4N7ppiDUSilKj6memGf4nFb+Ka2bul7/UdTTKy X-Received: by 2002:a54:4103:0:b0:3a7:d566:8b5e with SMTP id l3-20020a544103000000b003a7d5668b5emr9665075oic.44.1696659721978; Fri, 06 Oct 2023 23:22:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696659721; cv=none; d=google.com; s=arc-20160816; b=inmoKcqB2/a8yr/KT+J9ys46sMTiGxTUlIN7cR3mWbuHzwgLhmTrAvkC/amNkfSVec GzsQMbx72HvUG8oed7ZoRw2L+hKxGdxX/etqJ9yEiRosYEU6yUGQ2nlhb54rciWjXTr1 kBjlT5l566g8TIZTw9IqBZ484hhZelCQNnYvdgqgFxkej/i5cDcvtJiExyJ+vKsE1Vrk FdmyBCeECw96h818ddNnbNccwh/cFbByV1+wSotA6jxy+FjFS+a/LaxoPqU7yJDG0XEF zPubUoWL5TH50fjbADTs9T47iph+5+c5Nxi0RkHDsrL+IxPRDDGs8i7r9B2EtbaWE+Yi a0mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:mime-version:references :in-reply-to:message-id:date; bh=UW6BmZZhvQ+sr9X76O4kqtgd/jC/jR58FhDWCO1BROc=; fh=VMLNzHZtANsd/HsmVuFti9SxYDM/Oi4OY2rlrbFnr0s=; b=jDRf2tDv/wcnVmdL3DF8fIf1SD6+AGZ5htoUlyXgG8Nui7mqXFESGTk+5VcN5PHaNP OWGVwzN5LBD5fUXh9dW9IPc7/oUNaUIaZaIWolZ4ffZ575drDQ3TlJM9AD2tjGmccOhA TUMKMLieM/Z+1S4m+TBeDmEQOls6DHgKmEUDu7uvGm3kwbYgIwB1rNIJAnkPMT1P2/yW cHYACLaQcd7Jls1zrCt87vrr4hgxuFcSMIzaLAEEIpFptqyfDxSz3M3NRYm1EmybyEQb goGVpYNouOIfsAcGez9XLqHKCY09dkVGEYVDnJClJsetHtVx5MVOSnxf8pn8JfEBiJyc G9cA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id q7-20020a635047000000b0056a1ed17deasi3260608pgl.675.2023.10.06.23.22.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 23:22:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id D6E7D803E8E3; Fri, 6 Oct 2023 23:21:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343555AbjJGGVm (ORCPT + 18 others); Sat, 7 Oct 2023 02:21:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343532AbjJGGVl (ORCPT ); Sat, 7 Oct 2023 02:21:41 -0400 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FA22BB for ; Fri, 6 Oct 2023 23:21:39 -0700 (PDT) Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4S2Zv02gMGz4xPFw; Sat, 7 Oct 2023 14:21:32 +0800 (CST) Received: from szxlzmapp01.zte.com.cn ([10.5.231.85]) by mse-fl1.zte.com.cn with SMTP id 3976LSh2034032; Sat, 7 Oct 2023 14:21:28 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp02[null]) by mapi (Zmail) with MAPI id mid14; Sat, 7 Oct 2023 14:21:31 +0800 (CST) Date: Sat, 7 Oct 2023 14:21:31 +0800 (CST) X-Zmail-TransId: 2b046520f8eb657-18d47 X-Mailer: Zmail v1.0 Message-ID: <202310071421311735972@zte.com.cn> In-Reply-To: References: 202309141353492446199@zte.com.cn,202309141710195376952@zte.com.cn,CAJuCfpHV+Tf+-YqdWFwQNAeQJU5aqOM56R2GzbehFaFQcHuxAg@mail.gmail.com Mime-Version: 1.0 From: To: , , Cc: , , Subject: =?utf-8?q?=5BPATCH_linux-next_v2=5D_sched/psi=3A_Avoid_update_trigg?= =?utf-8?q?ers_and_rtpoll=5Ftotal_when_it_is_unnecessary?= X-MAIL: mse-fl1.zte.com.cn 3976LSh2034032 X-Fangmail-Gw-Spam-Type: 0 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6520F8EC.000/4S2Zv02gMGz4xPFw X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 06 Oct 2023 23:21:59 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778156291723326049 X-GMAIL-MSGID: 1779076664817019838 From: Yang Yang When psimon wakes up and there are no state changes for rtpoll_states, it's unnecessary to update triggers and rtpoll_total because the pressures being monitored by user have not changed. This will help to slightly reduce unnecessary computations of psi. There are also some minor related optimizations, please see below. The parameter update_total in update_triggers() is useless now. Since if changed_states & group->rtpoll_states is true, new_stall in update_triggers() will be true, then update_total should also be true. We have no need for update_total to help judgment whether to update rtpoll_total, so delete update_total. Update_triggers() always return now + group->rtpoll_min_period, and the return value is only used by psi_rtpoll_work(), so change update_triggers() to a void function, let group->rtpoll_next_update = now + group->rtpoll_min_period directly. Signed-off-by: Yang Yang Suggested-by: Suren Baghdasaryan --- kernel/sched/psi.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 1d0f634725a6..44a78774ae87 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -434,14 +434,13 @@ static u64 window_update(struct psi_window *win, u64 now, u64 value) return growth; } -static u64 update_triggers(struct psi_group *group, u64 now, bool *update_total, +static void update_triggers(struct psi_group *group, u64 now, enum psi_aggregators aggregator) { struct psi_trigger *t; u64 *total = group->total[aggregator]; struct list_head *triggers; u64 *aggregator_total; - *update_total = false; if (aggregator == PSI_AVGS) { triggers = &group->avg_triggers; @@ -471,14 +470,6 @@ static u64 update_triggers(struct psi_group *group, u64 now, bool *update_total, * events without dropping any). */ if (new_stall) { - /* - * Multiple triggers might be looking at the same state, - * remember to update group->polling_total[] once we've - * been through all of them. Also remember to extend the - * polling time if we see new stall activity. - */ - *update_total = true; - /* Calculate growth since last update */ growth = window_update(&t->win, now, total[t->state]); if (!t->pending_event) { @@ -503,8 +494,6 @@ static u64 update_triggers(struct psi_group *group, u64 now, bool *update_total, /* Reset threshold breach flag once event got generated */ t->pending_event = false; } - - return now + group->rtpoll_min_period; } static u64 update_averages(struct psi_group *group, u64 now) @@ -565,7 +554,6 @@ static void psi_avgs_work(struct work_struct *work) struct delayed_work *dwork; struct psi_group *group; u32 changed_states; - bool update_total; u64 now; dwork = to_delayed_work(work); @@ -584,7 +572,7 @@ static void psi_avgs_work(struct work_struct *work) * go - see calc_avgs() and missed_periods. */ if (now >= group->avg_next_update) { - update_triggers(group, now, &update_total, PSI_AVGS); + update_triggers(group, now, PSI_AVGS); group->avg_next_update = update_averages(group, now); } @@ -640,7 +628,6 @@ static void psi_rtpoll_work(struct psi_group *group) { bool force_reschedule = false; u32 changed_states; - bool update_total; u64 now; mutex_lock(&group->rtpoll_trigger_lock); @@ -706,10 +693,12 @@ static void psi_rtpoll_work(struct psi_group *group) } if (now >= group->rtpoll_next_update) { - group->rtpoll_next_update = update_triggers(group, now, &update_total, PSI_POLL); - if (update_total) + if (changed_states & group->rtpoll_states) { + update_triggers(group, now, PSI_POLL); memcpy(group->rtpoll_total, group->total[PSI_POLL], sizeof(group->rtpoll_total)); + } + group->rtpoll_next_update = now + group->rtpoll_min_period; } psi_schedule_rtpoll_work(group,