Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2325135rwb; Thu, 27 Jul 2023 05:47:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlGZ7z1cswD3jdVG1U4ny9q7nLAixyZP1lLbwyUhwLb8tiAsQh5S7WTU+Nb840NQhYqxwIKG X-Received: by 2002:a17:906:3199:b0:994:5577:aef1 with SMTP id 25-20020a170906319900b009945577aef1mr1967351ejy.7.1690462063909; Thu, 27 Jul 2023 05:47:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690462063; cv=none; d=google.com; s=arc-20160816; b=SpkiuGCMFzF4vgkDMiQopycReLoQFXa0AHnp+3IpT0mcEQ2nfhMlu+QZNRDzTXdO2P OPrTh2kGxZBgebauHqnH6Yh52ha/krqw/dWAdOwOSLtoFBsV+9cjsqYDmFn+9xpz85Ar 0fpdwiKBwry00RPoyh/475KS7IuLSxk46LTWy3HdHN4GcYywj+vkbXNM8eB/MpxooAsb DthRvmG2jjED4QQPt6LcBxhyAcEmzlqHWPCIue3ziB0/Q+2dAqgSz7k5FCB7nuXe0px7 Vfx6pyaTv72nOMcu9BYdVnV9xuGgzQtOP2QgdjufXmTaWy8OQFsDEM974NP7pXnu9rAD czsw== 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:references :cc:to:from:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=BwmFLONIOYK7ou7AxfGRdP9bRNPLFN3Vwa8VGbk/YHs=; fh=CTeGJ20A5qEyhcB8DoemTeosNHNRQxvZ/gRmyNPkdzA=; b=LeUHYDJy+hoXNlJDYG9apy2m+ge+LbvkMpMdXtpuYCiHDKvx5ZtjuETiEgYjxUevLM rij1VpBPZSRBfDD7To6Ij7gqqFbq0K8C1yRVjzliminZhdR6TXHLZ9d9IUb4XNgUYlsj TXCOBqAc/bsHwgCd7ZpRE7hbmzOF+XoEQvczeVyNvmRDo2c4LTFCHDe+llBsUIKXobrM /WozDry4NV/QeJbmYdsS5pKPYaJdVOZi7mYIhk4cLq1H2IDu2nbkbTFfxInvh0DGoMKx DUpyXOzH5VEgOF4G+8bnn/U9v2nFgiuJZ2K78/dYHzW0A5LxOTDGnftEpBGs+A6mAljA QIuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=RNxfAkB6; 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=pass (p=QUARANTINE sp=QUARANTINE 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 a17-20020a1709062b1100b0099bd554e682si841815ejg.337.2023.07.27.05.47.18; Thu, 27 Jul 2023 05:47:43 -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 header.s=google header.b=RNxfAkB6; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233445AbjG0MGT (ORCPT + 99 others); Thu, 27 Jul 2023 08:06:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231221AbjG0MGR (ORCPT ); Thu, 27 Jul 2023 08:06:17 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02C5726A6 for ; Thu, 27 Jul 2023 05:05:52 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1b9e9765f2cso5051615ad.3 for ; Thu, 27 Jul 2023 05:05:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690459551; x=1691064351; h=content-transfer-encoding:in-reply-to:references:cc:to:from:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=BwmFLONIOYK7ou7AxfGRdP9bRNPLFN3Vwa8VGbk/YHs=; b=RNxfAkB6CcRACh5rhHmxAkp5vnYxV0AIKYF3lzqbywIos8+89XoAyQG6m7j5hjiqcM CPyTO3A/iGiPxbvlAI4tI/As2dYzjeRzzrvZHIW7x8C5FrH5LJVdY/4E4JVWFGwmsqpa A2fifj2199zlUpSaS5tbjy5FkA0apVj36cYh0Dlf/r/W/69gQ5orqMxT6quUdZZmiYQm G93bbPe1CZwS72g+ua9mlFrnYY/b2XsGr4rhqJ2NgSlNjn7IcppvsbppQ+D4YEA8tIxx 8KzNLstuu1PHSSiky5j9/8sJnK+WDW84Tr46OyhI2Iz9NmKXbBAfE8PkV7e+kDdMjb2O 1F3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690459551; x=1691064351; h=content-transfer-encoding:in-reply-to:references:cc:to:from:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=BwmFLONIOYK7ou7AxfGRdP9bRNPLFN3Vwa8VGbk/YHs=; b=UaPHW0z/1UDF+jKSFc6FloQB+jwQadYqt2ZP45T8m//TvFoCHLnksbHaTF7orH5GJT 7lTWld2K9a+PboDckpnK1mbWSuAKp5XEba8WP1cqJAWJD0yBP+ydMBb7mW4Vxin3cNUP ETUp0EPNfC+0CNCEbUJQy6ZwljW482ge9p1utQ7EE6U1gdzs5vhx6n8njy9ittANjtDN jf6DH4UyDAmSHH8zB2KI2Gb8CpHD3/Hk3n/SNa1ZWaKzjYhUHYaUKLxujf4xJ58voZ8L z6XwqUDAfjisw878wf76oHtj2Ef0r5jUdKAQfJqBpvGDLRD8JJwb4ITV9wsquSdbu58Y Lp5g== X-Gm-Message-State: ABy/qLYvTfCgfKUurGO29iZEmTlWmQlBgj03H3iolE5UEweSXrSQL5iI GI0P/thiIZaShhPGvDNBtfqB3w== X-Received: by 2002:a17:902:9a0b:b0:1b8:9f6a:39de with SMTP id v11-20020a1709029a0b00b001b89f6a39demr3969803plp.65.1690459551262; Thu, 27 Jul 2023 05:05:51 -0700 (PDT) Received: from [10.85.115.102] ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id l15-20020a17090aec0f00b0025bdc3454c6sm2703969pjy.8.2023.07.27.05.05.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 Jul 2023 05:05:50 -0700 (PDT) Message-ID: <3d2b68bf-9f40-c779-dcfd-4cf9939edecc@bytedance.com> Date: Thu, 27 Jul 2023 20:05:44 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [External] Re: [PATCH] cgroup/rstat: record the cumulative per-cpu time of cgroup and its descendants From: Hao Jia To: Tejun Heo Cc: lizefan.x@bytedance.com, hannes@cmpxchg.org, mkoutny@suse.com, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org References: <20230717093612.40846-1-jiahao.os@bytedance.com> <2655026d-6ae4-c14c-95b0-4177eefa434f@bytedance.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,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 2023/7/19 Hao Jia wrote: > > > On 2023/7/19 Tejun Heo wrote: >> On Tue, Jul 18, 2023 at 06:08:50PM +0800, Hao Jia wrote: >>> https://github.com/jiaozhouxiaojia/cgv2-stat-percpu_test/tree/main >> >> So, we run `stress -c 1` for 1 second in the asdf/test0 cgroup and >> asdf/cpu.stat correctly reports the cumulative usage. After removing >> asdf/test0 cgroup, asdf's usage_usec is still there. What's missing here? > > Sorry, some of my expressions may have misled you. > > Yes, cpu.stat will display the cumulative **global** cpu time of the > cgroup and its descendants (the corresponding kernel variable is > "cgrp->bstat"), and it will not be lost when the child cgroup is removed. > > Similarly, we need a **per-cpu** variable to record the accumulated > per-cpu time of cgroup and its descendants. > The existing kernel variable "cgroup_rstat_cpu(cgrp, cpu)->bstat" is not > satisfied, it only records the per-cpu time of cgroup itself, > So I try to add "cgroup_rstat_cpu(cgrp, cpu)->cumul_bstat" to record > per-cpu time of cgroup and its descendants. > > In order to verify the correctness of my patch, I wrote a kernel module > to compare the results of calculating the per-cpu time of cgroup and its > descendants in two ways: >   Method 1. Traverse and add the per-cpu rstatc->bstat of cgroup and > each of its descendants. >   Method 2. Directly read "cgroup_rstat_cpu(cgrp, cpu)->cumul_bstat" in > the kernel. > > When the child cgroup is not removed, the results calculated by the two > methods should be equal. > >> What are you adding? > I want to add a **per-cpu variable** to record the cumulative per-cpu > time of cgroup and its descendants, which is similar to the variable > "cgrp->bstat", but it is a per-cpu variable. > It is very useful and convenient for calculating the usage of cgroup on > each cpu, and its behavior is similar to the "cpuacct.usage*" interface > of cgroup v1. > Hello Tejun, I don't know if I explained it clearly, and do you understand what I mean? Would you mind adding a variable like this to facilitate per-cpu usage calculations and migration from cgroup v1 to cgroup v2? Thanks, Hao