Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp360450iog; Wed, 29 Jun 2022 01:30:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uG8V03PDezyJUy+RCjnt2J1gFmDMTLjjSG0iTgMu9B7gfu/V0fRmzwR3LBpL+qwmCXPtcz X-Received: by 2002:a17:902:d4c4:b0:16a:2d0a:b609 with SMTP id o4-20020a170902d4c400b0016a2d0ab609mr9179184plg.5.1656491431009; Wed, 29 Jun 2022 01:30:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656491431; cv=none; d=google.com; s=arc-20160816; b=gCFW2tR8dshrstMxXF6U2nm+NFfJYHXVzyAo14i2QCu8Ia5WOZkEOq3STmPR7Emtio CTkqZxKDLgXrCDOoOdmkTM+HjkbyLLXVdU0TXq4KywmR4G/nUy6s/obffWHYIVKmBRZA G3lsmUiQ9IibuYpSV8mXQprr2U25yIGxE0hyUuK3D/8uwRcvwbHKl0PE/bZZGuXEXFQW VF+miEo9Q+MEbSnoHSb0Ao/uQZ3KsszFGhJR/F2V+mtWlV5ELtel+2pGVu8Gj6hk91Y5 mmZfJycP+RzqSBAkXjfhBKqrPb3VRMvd7XNXpSHCNvmah2ysML22mKVhhZ9chAcWTZgb vsAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=zRf5UwJSFwOKMWYCo+NYCtcvIlqTfbI8aBejevwXVI4=; b=CLyxW71GQlg3J/nT7c9vq+E5L6FC4KGk7D+pe5eFlVbCaxuv90y0TX/aBHIXcVPP7Z rHVRikSs5SJWbCyQN98fYXayRQXgSUgHTIFeihqKuZcigYE359/1XbreboiUErY591Hp JXBrNOy9pbsp3WAGAlJRVeHOLaYTDKeUfVdkpyWI963vrVj2nWppyKoy1DxRwlbZiHvY VPnT5xIaQPiB6b2hJGNly3SBuQI9QcE+LUHyI6RTudXFSKsEgLgVBeSx3T1WD6lSY2/s BJkeHNAmQbhdmoU8dqx2P9+5PLzOzZ6GphcsKThvnmJhk9ywYEybNWH2K9VY8gqE4ykE pu6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qGU014Np; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d12-20020a170902654c00b001637d6a52e8si24767481pln.19.2022.06.29.01.30.18; Wed, 29 Jun 2022 01:30:30 -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=@google.com header.s=20210112 header.b=qGU014Np; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231908AbiF2IEZ (ORCPT + 99 others); Wed, 29 Jun 2022 04:04:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231553AbiF2IEY (ORCPT ); Wed, 29 Jun 2022 04:04:24 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A58029C90 for ; Wed, 29 Jun 2022 01:04:22 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id o16so21186228wra.4 for ; Wed, 29 Jun 2022 01:04:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zRf5UwJSFwOKMWYCo+NYCtcvIlqTfbI8aBejevwXVI4=; b=qGU014NppgnQ4NbDPye4XEUlwmw0vOqpih0l20x5Lyk+Wz4aDJ8DVlo9on/rJ9KU2l h+7pRoY82L9tJXbAALnFHTmEmxkV1m6Av8BuOqJTndMfM/Gg/ZrvBJPPkY71wyB8CjL+ i+HmFQrI4WL7pXkhjMp0RPUB8BZChmeM/1Qf0X4yCN1QzeekMSLm15ybVmap+hDd/Qhb 7Y0uXcMiGGFjmgOpcGgeWuVsE9FFH7ALZIgsb97HLswmSLq4U9zn8iZkLmWEit9vhFcF CGmhi56oBjLbI+944WQa22TdRrGeF8Mf6IQWDNvBqWkEopbF+UCKcRWLIOFwUS0MQCJ7 IkFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zRf5UwJSFwOKMWYCo+NYCtcvIlqTfbI8aBejevwXVI4=; b=iq6gv6Y+mP7aoAKiQZQoak1QlqnvemeqoJyI0dbtXlnFfUZt1wS70joj7IP1XBcVaA AaeSgrFvqz9nN4VdPjwGNhWJTNDVtlzHWWP0t0Qk3+RcCHoO+rc0qAgXfJXGbTKmyvBr sft5WAzh+0b2TlgiDF7NZA3SVQJmw69vGlPkO5vO7GMCWgXdUKbxk7YJFGVfQfTNbycP PoJp7zVMWuQuPB4ituDzZhW1BB+IVzmXXK1bXIqeW6WCpLYY3qrgdKc1V7gkQ9lw0LzT 37GSAbKrKDTimu9FCvIboJjw4fMG0lJW+yc888W4gR6/t1hZl5KjL7kEgc/aFQffvA/n HFGg== X-Gm-Message-State: AJIora9xC0O9IwjOmvd4JQlq/EoT7ca4twhu1fal+D9zLcfVFC1IYfzN tjKvZrQDQ0wB+cH7Dfz2RE16PqwkZvp8i5spjrIYsw== X-Received: by 2002:adf:f146:0:b0:21b:8c7d:7294 with SMTP id y6-20020adff146000000b0021b8c7d7294mr1698559wro.582.1656489860013; Wed, 29 Jun 2022 01:04:20 -0700 (PDT) MIME-Version: 1.0 References: <20220610194435.2268290-1-yosryahmed@google.com> <20220610194435.2268290-9-yosryahmed@google.com> <00df1932-38fe-c6f8-49d0-3a44affb1268@fb.com> <59376285-21bc-ff12-3d64-3ea7257becb2@fb.com> In-Reply-To: <59376285-21bc-ff12-3d64-3ea7257becb2@fb.com> From: Yosry Ahmed Date: Wed, 29 Jun 2022 01:03:43 -0700 Message-ID: Subject: Re: [PATCH bpf-next v2 8/8] bpf: add a selftest for cgroup hierarchical stats collection To: Yonghong Song Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , Hao Luo , Tejun Heo , Zefan Li , Johannes Weiner , Shuah Khan , Michal Hocko , Roman Gushchin , David Rientjes , Stanislav Fomichev , Greg Thelen , Shakeel Butt , Linux Kernel Mailing List , Networking , bpf , Cgroups Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Tue, Jun 28, 2022 at 11:27 PM Yonghong Song wrote: > > > > On 6/28/22 12:43 AM, Yosry Ahmed wrote: > > On Mon, Jun 27, 2022 at 11:47 PM Yosry Ahmed wrote: > >> > >> On Mon, Jun 27, 2022 at 11:14 PM Yonghong Song wrote: > >>> > >>> > >>> > >>> On 6/10/22 12:44 PM, Yosry Ahmed wrote: > >>>> Add a selftest that tests the whole workflow for collecting, > >>>> aggregating (flushing), and displaying cgroup hierarchical stats. > >>>> > >>>> TL;DR: > >>>> - Whenever reclaim happens, vmscan_start and vmscan_end update > >>>> per-cgroup percpu readings, and tell rstat which (cgroup, cpu) pairs > >>>> have updates. > >>>> - When userspace tries to read the stats, vmscan_dump calls rstat to flush > >>>> the stats, and outputs the stats in text format to userspace (similar > >>>> to cgroupfs stats). > >>>> - rstat calls vmscan_flush once for every (cgroup, cpu) pair that has > >>>> updates, vmscan_flush aggregates cpu readings and propagates updates > >>>> to parents. > >>>> > >>>> Detailed explanation: > >>>> - The test loads tracing bpf programs, vmscan_start and vmscan_end, to > >>>> measure the latency of cgroup reclaim. Per-cgroup ratings are stored in > >>>> percpu maps for efficiency. When a cgroup reading is updated on a cpu, > >>>> cgroup_rstat_updated(cgroup, cpu) is called to add the cgroup to the > >>>> rstat updated tree on that cpu. > >>>> > >>>> - A cgroup_iter program, vmscan_dump, is loaded and pinned to a file, for > >>>> each cgroup. Reading this file invokes the program, which calls > >>>> cgroup_rstat_flush(cgroup) to ask rstat to propagate the updates for all > >>>> cpus and cgroups that have updates in this cgroup's subtree. Afterwards, > >>>> the stats are exposed to the user. vmscan_dump returns 1 to terminate > >>>> iteration early, so that we only expose stats for one cgroup per read. > >>>> > >>>> - An ftrace program, vmscan_flush, is also loaded and attached to > >>>> bpf_rstat_flush. When rstat flushing is ongoing, vmscan_flush is invoked > >>>> once for each (cgroup, cpu) pair that has updates. cgroups are popped > >>>> from the rstat tree in a bottom-up fashion, so calls will always be > >>>> made for cgroups that have updates before their parents. The program > >>>> aggregates percpu readings to a total per-cgroup reading, and also > >>>> propagates them to the parent cgroup. After rstat flushing is over, all > >>>> cgroups will have correct updated hierarchical readings (including all > >>>> cpus and all their descendants). > >>>> > >>>> Signed-off-by: Yosry Ahmed > >>> > >>> There are a selftest failure with test: > >>> > >>> get_cgroup_vmscan_delay:PASS:output format 0 nsec > >>> get_cgroup_vmscan_delay:PASS:cgroup_id 0 nsec > >>> get_cgroup_vmscan_delay:PASS:vmscan_reading 0 nsec > >>> get_cgroup_vmscan_delay:PASS:read cgroup_iter 0 nsec > >>> get_cgroup_vmscan_delay:PASS:output format 0 nsec > >>> get_cgroup_vmscan_delay:PASS:cgroup_id 0 nsec > >>> get_cgroup_vmscan_delay:FAIL:vmscan_reading unexpected vmscan_reading: > >>> actual 0 <= expected 0 > >>> check_vmscan_stats:FAIL:child1_vmscan unexpected child1_vmscan: actual > >>> 781874 != expected 382092 > >>> check_vmscan_stats:FAIL:child2_vmscan unexpected child2_vmscan: actual > >>> -1 != expected -2 > >>> check_vmscan_stats:FAIL:test_vmscan unexpected test_vmscan: actual > >>> 781874 != expected 781873 > >>> check_vmscan_stats:FAIL:root_vmscan unexpected root_vmscan: actual 0 < > >>> expected 781874 > >>> destroy_progs:PASS:remove cgroup_iter pin 0 nsec > >>> destroy_progs:PASS:remove cgroup_iter pin 0 nsec > >>> destroy_progs:PASS:remove cgroup_iter pin 0 nsec > >>> destroy_progs:PASS:remove cgroup_iter pin 0 nsec > >>> destroy_progs:PASS:remove cgroup_iter pin 0 nsec > >>> destroy_progs:PASS:remove cgroup_iter pin 0 nsec > >>> destroy_progs:PASS:remove cgroup_iter pin 0 nsec > >>> destroy_progs:PASS:remove cgroup_iter root pin 0 nsec > >>> cleanup_bpffs:PASS:rmdir /sys/fs/bpf/vmscan/ 0 nsec > >>> #33 cgroup_hierarchical_stats:FAIL > >>> > >> > >> The test is passing on my setup. I am trying to figure out if there is > >> something outside the setup done by the test that can cause the test > >> to fail. > >> > >>> > >>> Also an existing test also failed. > >>> > >>> btf_dump_data:PASS:find type id 0 nsec > >>> > >>> > >>> btf_dump_data:PASS:failed/unexpected type_sz 0 nsec > >>> > >>> > >>> btf_dump_data:FAIL:ensure expected/actual match unexpected ensure > >>> expected/actual match: actual '(union bpf_iter_link_info){.map = > >>> (struct){.map_fd = (__u32)1,},.cgroup ' > >>> test_btf_dump_struct_data:PASS:find struct sk_buff 0 nsec > >>> > >> > >> Yeah I see what happened there. bpf_iter_link_info was changed by the > >> patch that introduced cgroup_iter, and this specific union is used by > >> the test to test the "union with nested struct" btf dumping. I will > >> add a patch in the next version that updates the btf_dump_data test > >> accordingly. Thanks. > >> > > > > So I actually tried the attached diff to updated the expected dump of > > bpf_iter_link_info in this test, but the test still failed: > > > > btf_dump_data:FAIL:ensure expected/actual match unexpected ensure > > expected/actual match: actual '(union bpf_iter_link_info){.map = > > (struct){.map_fd = (__u32)1,},.cgroup = (struct){.cgroup_fd = > > (__u32)1,},}' != expected '(union bpf_iter_link_info){.map = > > (struct){.map_fd = (__u32)1,},.cgroup = (struct){.cgroup_fd = > > (__u32)1,.traversal_order = (__u32)1},}' > > > > It seems to me that the actual output in this case is not right, it is > > missing traversal_order. Did we accidentally find a bug in btf dumping > > of unions with nested structs, or am I missing something here? > > Probably there is an issue in btf_dump_data() function in > tools/lib/bpf/btf_dump.c. Could you take a look at it? I will try to take a look but after I figure out why the selftest added here is always passing for me and always failing for you :( > > > Thanks! > > > >>> > >>> test_btf_dump_struct_data:PASS:unexpected return value dumping sk_buff 0 > >>> nsec > >>> > >>> btf_dump_data:PASS:verify prefix match 0 nsec > >>> > >>> > >>> btf_dump_data:PASS:find type id 0 nsec > >>> > >>> > >>> btf_dump_data:PASS:failed to return -E2BIG 0 nsec > >>> > >>> > >>> btf_dump_data:PASS:ensure expected/actual match 0 nsec > >>> > >>> > >>> btf_dump_data:PASS:verify prefix match 0 nsec > >>> > >>> > >>> btf_dump_data:PASS:find type id 0 nsec > >>> > >>> > >>> btf_dump_data:PASS:failed to return -E2BIG 0 nsec > >>> > >>> > >>> btf_dump_data:PASS:ensure expected/actual match 0 nsec > >>> > >>> > >>> #21/14 btf_dump/btf_dump: struct_data:FAIL > >>> > >>> please take a look. > >>> > >>>> --- > >>>> .../prog_tests/cgroup_hierarchical_stats.c | 351 ++++++++++++++++++ > >>>> .../bpf/progs/cgroup_hierarchical_stats.c | 234 ++++++++++++ > >>>> 2 files changed, 585 insertions(+) > >>>> create mode 100644 tools/testing/selftests/bpf/prog_tests/cgroup_hierarchical_stats.c > >>>> create mode 100644 tools/testing/selftests/bpf/progs/cgroup_hierarchical_stats.c > >>>> > [...]