Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7643181rwp; Tue, 18 Jul 2023 20:10:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlFVLCn2KwYRsGJJRG7yi1O+ddNv4VXCA4r1ppbWvobUHK053Ag+dJN7WqdzqahjGwbAk5L+ X-Received: by 2002:aa7:c506:0:b0:521:790c:9505 with SMTP id o6-20020aa7c506000000b00521790c9505mr1141747edq.39.1689736223925; Tue, 18 Jul 2023 20:10:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689736223; cv=none; d=google.com; s=arc-20160816; b=wnBBVMHlR5o66/DTlJ6QuQsVqzuIUYJ1Sy3k4XPgbkwECObDphc4Og0ofhurrkAzlI wWB49M664Hy8WnX8HuHyL+1hMmtVzs0lVQdkG71CI0fEyO3WKEUHL06rMjHUicZFphYu BJQez4X8fXIuQh9vHsjK7aDhEdk/hw5Sesl6FXBDJncKpuZwQp93K11KUEpGREXXbx69 37Aq7dEy7xrzwlca1KN0kMSHsILfksnYmV5mAdgp3PLtbqQ4QYvdweVxnS6eFbuudQl8 4YCKPNarS1573GPZJ9YUo+w8YGg8mPrUvy4TNqGKnDeeI+ctYje+gxG+J+OzQrT56rHc VLBg== 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:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=irp3EPa33LK85QAbTktFpig5JEBTIWbUT4zOa4f8pKI=; fh=kEiBf8avgANjNmeF/x6h2Qr1e4f9pN2i30jE358RD2c=; b=0eikvErgzXKKcjKR+eQwiaQdt0pkU/GFj+ZRasnQmNm5UT18NbGSQGNDoB0zoS7ezP CEMrvjIot0NVTtMNM5OUWhj/YXRo21/LzPiH5LgZbRquYS3w3wIoa+D1aBV+KbzCwA0K WRQM7rthLQbpUhZfXZ6oK2tmPzcR1JsE+tC2w5RHqeZtzSgJbLtM3zumDolY/s7g9dFK /0PujgjebAlPMuLxslLZDV3/ulpW6nLKr0d9ZTYmlK7SL5qsVRS/DEuM9K6zUslLowuW A/pP+du7EC2jZ6fxYF+F8ezUTiwxA0eFgHCSQFw7ugoGTpK8GZWMwjTC29Q5zM7kicL4 8kIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=B76s3XuC; 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 k26-20020a17090627da00b0098882d02831si2089867ejc.710.2023.07.18.20.09.58; Tue, 18 Jul 2023 20:10:23 -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=B76s3XuC; 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 S230183AbjGSDC2 (ORCPT + 99 others); Tue, 18 Jul 2023 23:02:28 -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-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 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_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 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