From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87F9BC001E0 for ; Thu, 27 Jul 2023 12:06:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233664AbjG0MGU (ORCPT ); Thu, 27 Jul 2023 08:06:20 -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-Google-Smtp-Source: APBJJlFjJHOftyjOvJAGevlCpI+03ZofFgqqbos+NnQhswgcV75ZqE3w1ltXd+wMTUeA0zFvSuVFeQ== 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 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