Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp191241rwb; Thu, 27 Jul 2023 11:11:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlEJRSyz6XX0LLY+tw/JU92rL2IgJQNwkk7L3DewV6AlzuWpH6adEE3DBji41sXkxxPg/pVt X-Received: by 2002:a17:90a:a2e:b0:268:4485:c868 with SMTP id o43-20020a17090a0a2e00b002684485c868mr36681pjo.49.1690481503491; Thu, 27 Jul 2023 11:11:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690481503; cv=none; d=google.com; s=arc-20160816; b=hkcyJPpYSQ2w0fRGF/f7hJI3dm1IbFE4LIIA/2yQidnomHw4pa8a4d1BTqrFBwjvmL uEgPdSOUd51QX5aRH0dt+Pfy8WcZS5rLW+ssqzrsHPkA5nb02vuddFinSiRcS6guzoUq aOd/XZDuU/MDTeLsXDwO845t312fOLEKHbV1YcJSeoDVcakvuxi2s1EM4WQbPS3YAB+T aeJQUMLu/jahw0x34adxOhmV3UrlLzI7voc0qQKvIDDS7dpTc1ETmmaDF08kc94iCX+D +DwU22dy9uoBRRY9seZpG5bvwQbFA+kD8ge6IFdjiddQL8XS22nTJRyXXzl5SH164s7o ASDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:sender:dkim-signature; bh=CMgWDc9HbFTZfCAa6CCrY6Sm3n2por+mG+JbQWL++uA=; fh=cpVGWf4RprNftWMU1V+toTwQfpUro6h05Qw1llkB12E=; b=I2gagNyTLCTLncGIKXrP8XI40ifH/K1FPBszgv01gL6RQ2KM1nOkIrzw6Hht2m3DIh Q/2ws+/hPSOPFJyq/VfXLYky7QAmkZtVyJ2GnfUHbbVYuTXpoPAPCPgTqdP2P4wqPFRo e2d0wbJKGi4h147djze8lrQw46kETFivbk1nUnl3qJb8e1n17jaQ5SaEBpoVbGy5dZGN +SQEsHAcikGOMosFcgcwCX09qkZkrbAIA4/Tv5lZ+zo5e73GemQa02morjjWDv0bVdk6 rC2/vX9dVji6LaK/utEvWGvPrQpOpNMbxY9M4TpuAC+UMh+rGKqqcfKWOgCvG8Zfl5t/ kvQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=RCcaFekW; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ms8-20020a17090b234800b002635d3815adsi3172943pjb.74.2023.07.27.11.11.30; Thu, 27 Jul 2023 11:11: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=@gmail.com header.s=20221208 header.b=RCcaFekW; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229939AbjG0Roc (ORCPT + 99 others); Thu, 27 Jul 2023 13:44:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbjG0Rob (ORCPT ); Thu, 27 Jul 2023 13:44:31 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0274730ED; Thu, 27 Jul 2023 10:44:31 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1b9c5e07c1bso9940345ad.2; Thu, 27 Jul 2023 10:44:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690479870; x=1691084670; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:sender :from:to:cc:subject:date:message-id:reply-to; bh=CMgWDc9HbFTZfCAa6CCrY6Sm3n2por+mG+JbQWL++uA=; b=RCcaFekWryy06wzg7UAG1HDH/IAEIm1lTcU2yxEyeXZqezvcy9ba1nwpBwUzwpGQgc lQ3sb9j9/E0Yaev3i/fzaujjnPQbX7LogkJXoL90KihlX1Zom10V1ZM0F3VdaIkxDOKf dFkC6yqPsAl14hIZglw5FB2XcyowxvSwcPHyuYwmG2oIZ7foSHXypHzsEIgE9jMl8FcR Sb8z/S59K2ojW/sYB4CYTjqALXlxjMX7Hcx7WUUnGJQ4izz77GRc1u4vcaT0OWD5+F00 r8vwmL5MFpeJ3guxnS7gaG6omeZ+Tu8E5AIyp2mAWjKMqDs4vCtnF3nlfvVOPCwN9xG0 LNbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690479870; x=1691084670; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:sender :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CMgWDc9HbFTZfCAa6CCrY6Sm3n2por+mG+JbQWL++uA=; b=M/oQShgim3oMboW8cDAQIuVaIJ3dxVA+ZdFZ1mih7ggQreVU6ALPjx4wWbYQfucf3k QnyEc4L3DFcZ6h+RSmI2bIpjBbWU7/Mn10sLCUZZB+PPtAGCHfU/i1qcuye/dX/deMFv aXqA3Zlf7fu7VrOKwS7bFveWsOQXgXAbeJT0v1aH3fWfD6Ca2YbM2+HbAvLXcRU5hGNM P5G1uwLR4zGNh8ERYdm3wwJ/FToowzC2v6NShEqEWRLs41T5mOoR02/onPGYCtuM90Fw /Hw6Nsg1/Zo/MuG4OObqESFCzDAcgi3JeHQz7b6tDfKjxfRcBRmcjk6OmOKkHYTABure yd1Q== X-Gm-Message-State: ABy/qLYRqlw/rtSzehwWu9AoNUrUOnHqV5rdPLOAJDRQFCjW1jLMDhSc xsmE/IypIp0sfH+0YjGFp/U= X-Received: by 2002:a17:902:ec8e:b0:1b3:d4d5:beb2 with SMTP id x14-20020a170902ec8e00b001b3d4d5beb2mr263plg.9.1690479870092; Thu, 27 Jul 2023 10:44:30 -0700 (PDT) Received: from localhost ([2620:10d:c090:400::5:18d]) by smtp.gmail.com with ESMTPSA id jk17-20020a170903331100b001bbce3d4774sm1935589plb.79.2023.07.27.10.44.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 10:44:29 -0700 (PDT) Sender: Tejun Heo Date: Thu, 27 Jul 2023 07:44:28 -1000 From: Tejun Heo To: Hao Jia Cc: lizefan.x@bytedance.com, hannes@cmpxchg.org, mkoutny@suse.com, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [External] Re: [PATCH] cgroup/rstat: record the cumulative per-cpu time of cgroup and its descendants Message-ID: References: <20230717093612.40846-1-jiahao.os@bytedance.com> <2655026d-6ae4-c14c-95b0-4177eefa434f@bytedance.com> <3d2b68bf-9f40-c779-dcfd-4cf9939edecc@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3d2b68bf-9f40-c779-dcfd-4cf9939edecc@bytedance.com> X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 Thu, Jul 27, 2023 at 08:05:44PM +0800, Hao Jia wrote: > > > 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? Oh yeah, I do. I'm just thinking whether we also want to expose that in the cgroupfs. We are currently not showing anything per-cpu and the output formatting gets nasty with a huge number of CPUs, so maybe that's not going to work out all that well. Anyways, I'll get back to you next week. Thanks. -- tejun