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 0E132EB64DC for ; Wed, 19 Jul 2023 03:02:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229450AbjGSDC3 (ORCPT ); Tue, 18 Jul 2023 23:02:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230215AbjGSDCV (ORCPT ); Tue, 18 Jul 2023 23:02:21 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 066951BCA for ; Tue, 18 Jul 2023 20:01:54 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-666eef03ebdso4274812b3a.1 for ; Tue, 18 Jul 2023 20:01:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1689735713; x=1692327713; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=irp3EPa33LK85QAbTktFpig5JEBTIWbUT4zOa4f8pKI=; b=B76s3XuCZrrPV4rWry1FvWh5MrG3pQP4cQK0XiWE+UaqR5NoSB6OcVsURRvVhqwujr 4HcIOY1tuqZauHG+Z3H+EyGTqw5NfFK0nSMuIAYjNmwRMw4NoWEUHO88XEYAKGaXDKLR 4LeexLiowvf11fQ5xGQrSNVQKmsESazLiHQo4Y7J+OOa6kfjoFP+v5Hbgd4TF4kjxMQJ IV7lHdZbBMgWsdR5PimtHWmeuo+Sc5D4LhaFJrr/opbxUdHUvHQSHn2sZ8800PEf1HXn 17rUqRAm01DJV2Cm9PZG45JI+a+31nYWdkzv0qGsNYNS163N7PziWMMMeGBlNl/9gQTP uAhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689735713; x=1692327713; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=irp3EPa33LK85QAbTktFpig5JEBTIWbUT4zOa4f8pKI=; b=kcOnjjeFHYeeWTPehEsDPKWGl9f2MY2Krhk+fRMcriL1G48OaQa8VDmmxXuZFc5Xwq Mezn2Pe7q6kFRH7CWpVfFLoNPhxMZGBi3oTZ6wmire+k7YVFanDKQNGvPXEA0BYcEUB2 7bU16aA448rTvQAYINxCcC0zIifmiF9yDvb9XG3ULE/nlm/Kb0B83zR5umKMplOhNmW7 payZBmq8f8gqDEIkv2IlrSc8Xian6tbm7mniKp0HttRuO2sIufur9MOtBN+qTzBROKEV R3t0lW1JqJgSAiKSF5oTSgLgD2UPUJAsmlEeMxFosNainpOYrKPm54jOl6WZLYk5vyzr NQRQ== X-Gm-Message-State: ABy/qLalh4oVONbx6s1ViRz4gT35l1d7u+1RjL5wIazDVS/R1YSXa4bx CWYmseCHmvNwkx42LUEkpo7EgQ== X-Google-Smtp-Source: APBJJlFGenWZLBnBPUNEL75np9UL/1Ou3Xpj6s1x1kDq4GWQrcTml0C4VCalszw7CxTdgW84Wywo0Q== X-Received: by 2002:a05:6a20:7348:b0:133:6e6e:2b11 with SMTP id v8-20020a056a20734800b001336e6e2b11mr18317819pzc.2.1689735713474; Tue, 18 Jul 2023 20:01:53 -0700 (PDT) Received: from [10.85.115.102] ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id y10-20020aa7804a000000b0065dd1e7c2c1sm2170024pfm.63.2023.07.18.20.01.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Jul 2023 20:01:53 -0700 (PDT) Message-ID: Date: Wed, 19 Jul 2023 11:01:48 +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 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> From: Hao Jia In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Thanks, Hao