Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp610103rwe; Thu, 25 Aug 2022 06:20:17 -0700 (PDT) X-Google-Smtp-Source: AA6agR4aXoiD7g2ZKaGfkG3yXp0mPRbAvevOTSE/jU90d0c3/c7U3otVm0Q5XCWEGlJLgRIo2TUX X-Received: by 2002:a17:90b:4a10:b0:1fb:2e77:a33 with SMTP id kk16-20020a17090b4a1000b001fb2e770a33mr13865686pjb.67.1661433617111; Thu, 25 Aug 2022 06:20:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661433617; cv=none; d=google.com; s=arc-20160816; b=fGn+x9p3ZzneLcA1AEYUj0tIhtL5ZDhdiXtjqdwIdrI9mFa07Cpkm+heln0DqQkBnG lX2eJT/9kpp2jmXSsAqRe0HQsDleFZGavo5sg6GHcbsjg2U1vL5KXfiDA5UdNmDnOyxw R4uWqLPzSiFwUhy3xN4yTEgXnqe/m/6AvvIm0YZGG5FDNxyuz4L/7aqWVpWyzXHUcEiW GxB+XtGw1w49dfLjPqJTC4ABrioSuQ8HRaeKNgigIwtQwEEWel/6lG8zsuZr2nd/T6st YEPyfx7+6NB9p9OhIq7gYuCE+Pv4MI6z1z2OXboxpHpAX9m4yE/OjFQwribboeZcRxJZ rsjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=o0E7YiHeVex1u0X6qaV95zV+IU6KmVTedW0VAfovtx8=; b=COz/yutlZ1t0dZAwh3LiDS/hB7vW4TtGdg1CJ22hRE+qSvfRnr1ZoGui9JlHsGhvJP bF2tU3zO4joKLsXWfK8F5xuMTxtpuX875la4vPwaQujkbuHS1R3W1Z3SdtAOmU8JBqeD VxzL/UB4treFjturpQLU8pcZdMOP4mQ58LYE2PvevdzNAk4ir0toe2zLScOE+icTMcLE Uv/FsS9IhEcib2CncYorcQTcdkzmCvqr5V2+Ded+K1xS2nTlvRyaglM5fvKJWBDwguJo D3pJJipGnwPsumuCHapPdxF70ZwJqDMo4wEFLCJMEEuLmaDLLIJ0MKUWf7AjgjlZ5KRL yIuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=TRE19aRm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q6-20020a63f946000000b004227ddf83f7si20053019pgk.559.2022.08.25.06.20.04; Thu, 25 Aug 2022 06:20:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=TRE19aRm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241439AbiHYM26 (ORCPT + 99 others); Thu, 25 Aug 2022 08:28:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238468AbiHYM2t (ORCPT ); Thu, 25 Aug 2022 08:28:49 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 623E5B2CD4 for ; Thu, 25 Aug 2022 05:28:48 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id p18so18381341plr.8 for ; Thu, 25 Aug 2022 05:28:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc; bh=o0E7YiHeVex1u0X6qaV95zV+IU6KmVTedW0VAfovtx8=; b=TRE19aRmzYeY60KDN1wOIIp3s3WQh2s1UiPVHSyC4h+toJTUn/oTh2+z/rhBhbwT6W NDeigQr3uEpitwebXfV935zr/yRXP0JDTsxyCSUw5JTINtlHZjKYcXG60i6fqttjH68I t/JoB4QAa0mGRFYYhWlznz5OiKOMTjBRy4TqgPJjFO3js0EKBC00oSRYeJ9dt11uCmeQ yhsE7wjOUDL3v6ZJEMykJvR8hjQvqCmRxoMTKurdisC/z/bcw3fE3F1j2ylZpsZaL9dH BBdloD+tLoAovOt6PQUfWLddZQetzIFhFIh3cfkO+ADUTA1v0pEvgxbuWN2v4QJxcGNj cjIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=o0E7YiHeVex1u0X6qaV95zV+IU6KmVTedW0VAfovtx8=; b=jiTw286tNNI7AGyQ0A5RS0d/KnzCWkscVwe0BTGtMAf3Lke5AjmhNcvbbTDjg75HDk TQFw1nlY63kBl7sJTQJ4kXZittwL7tFLbjllVHzSTpnWjn/zQeQWUqMM87mX0ZdQLMr9 dPvlaq8EBtHKNt094rlfzPefow647e0ceyKa4JoukqNTBUZG54S37+lQqeHCxo9J7wKg 1Y/6ThG1gKSwFtKS93YxfnrmH9QgpTRq4WVTta6gPxJ2DMsEZ+STjY3JD/Wj8nyo/E9s BwRVhakOWS4yYtWoMB4wJjkQtRPQob1+XbXDTA212CKqqm/XdPGZScKGLzpM4xOPbIs5 NiDA== X-Gm-Message-State: ACgBeo0CwZ49Ie9tL3QLtvKWSHkdArbMfyGewBHB5y6seGfC+X9lGcUw 9Md97EM7wQiCBHoilmNMcpObBg== X-Received: by 2002:a17:90a:2b0f:b0:1fa:d73f:ce92 with SMTP id x15-20020a17090a2b0f00b001fad73fce92mr13508804pjc.60.1661430527863; Thu, 25 Aug 2022 05:28:47 -0700 (PDT) Received: from [10.254.35.15] ([139.177.225.236]) by smtp.gmail.com with ESMTPSA id w16-20020a170902e89000b0016f196209c9sm10948960plg.123.2022.08.25.05.28.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Aug 2022 05:28:47 -0700 (PDT) Message-ID: <324b1d0f-42e5-8947-68cb-a3d20135f2c6@bytedance.com> Date: Thu, 25 Aug 2022 20:28:39 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.1.2 Subject: Re: [PATCH v3 10/10] sched/psi: per-cgroup PSI accounting disable/re-enable interface Content-Language: en-US To: Johannes Weiner Cc: tj@kernel.org, mkoutny@suse.com, surenb@google.com, gregkh@linuxfoundation.org, corbet@lwn.net, mingo@redhat.com, peterz@infradead.org, songmuchun@bytedance.com, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220824081829.33748-1-zhouchengming@bytedance.com> <20220824081829.33748-11-zhouchengming@bytedance.com> From: Chengming Zhou In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/8/24 17:59, Johannes Weiner wrote: > Hi Chengming, > > Thanks for incorporating all the feedback. I have a few nitpicks > below, but with those considered, please add: > > Acked-by: Johannes Weiner > > On Wed, Aug 24, 2022 at 04:18:29PM +0800, Chengming Zhou wrote: >> @@ -5171,12 +5220,19 @@ static struct cftype cgroup_base_files[] = { >> { >> .name = "irq.pressure", >> .flags = CFTYPE_PRESSURE, >> + .file_offset = offsetof(struct cgroup, psi_files[PSI_IRQ]), >> .seq_show = cgroup_irq_pressure_show, >> .write = cgroup_irq_pressure_write, >> .poll = cgroup_pressure_poll, >> .release = cgroup_pressure_release, >> }, >> #endif >> + { >> + .name = "cgroup.pressure", >> + .flags = CFTYPE_PRESSURE, >> + .seq_show = cgroup_psi_show, >> + .write = cgroup_psi_write, > > To match the naming convention, these should be called > cgroup_pressure_show() and cgroup_pressure_write(). I just find cgroup_pressure_write() already exists, so I change the names to cgroup_pressure_enable_show() and cgroup_pressure_enable_write(), since this file name is simplified from "cgroup.pressure.enable". Thanks. > >> @@ -745,6 +745,14 @@ static void psi_group_change(struct psi_group *group, int cpu, >> if (set & (1 << t)) >> groupc->tasks[t]++; >> >> + if (!group->enabled) { >> + if (groupc->state_mask & (1 << PSI_NONIDLE)) >> + record_times(groupc, now); > > Thanks for the explanation in the other thread, it made sense. But can > you please add a comment to document it? Something like: > > /* > * On the first group change after disabling PSI, conclude > * the current state and flush its time. This is unlikely > * to matter to the user, but aggregation (get_recent_times) > * may have already incorporated the live state into times_prev; > * avoid a delta sample underflow when PSI is later re-enabled. > */ > > An unlikely() would also make sense on that branch. > >> @@ -1081,6 +1092,40 @@ void cgroup_move_task(struct task_struct *task, struct css_set *to) >> >> task_rq_unlock(rq, task, &rf); >> } >> + >> +void psi_cgroup_enabled_sync(struct psi_group *group) >> +{ >> + int cpu; >> + >> + /* >> + * After we disable psi_group->enabled, we don't actually >> + * stop percpu tasks accounting in each psi_group_cpu, >> + * instead only stop test_state() loop, record_times() >> + * and averaging worker, see psi_group_change() for details. >> + * >> + * When disable cgroup PSI, this function has nothing to sync >> + * since cgroup pressure files are hidden and percpu psi_group_cpu >> + * would see !psi_group->enabled and only do task accounting. >> + * >> + * When re-enable cgroup PSI, this function use psi_group_change() >> + * to get correct state mask from test_state() loop on tasks[], >> + * and restart groupc->state_start from now, use .clear = .set = 0 >> + * here since no task status really changed. >> + */ >> + if (!group->enabled) >> + return; > > Thanks for adding the comment, that's helpful. > > I think the function would be a tad clearer and self-documenting if > you called it psi_cgroup_restart(), and only call it on enabling. > >> + for_each_possible_cpu(cpu) { >> + struct rq *rq = cpu_rq(cpu); >> + struct rq_flags rf; >> + u64 now; >> + >> + rq_lock_irq(rq, &rf); >> + now = cpu_clock(cpu); >> + psi_group_change(group, cpu, 0, 0, now, true); >> + rq_unlock_irq(rq, &rf); >> + } >> +} >> #endif /* CONFIG_CGROUPS */ > > Thanks, > Johannes