Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2487256pxu; Mon, 7 Dec 2020 07:51:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJyKmVrT/5ZrWQKEpD11N+GbnjLvvO9GgUTIg5FyqaXgGoNfzfK6o38czpMPcEpQvpAXM8uF X-Received: by 2002:a17:906:2358:: with SMTP id m24mr18977150eja.198.1607356306137; Mon, 07 Dec 2020 07:51:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607356306; cv=none; d=google.com; s=arc-20160816; b=f4QdDHnN041b/XPZLU3zKdQRsTwk0vAWbH3iesdMQ9u3bNJmFeYj1pkcYMRu4AeSDS yNeeVEuTcxD1tQ7/GneRqtrhzsYqgYJPMkzz6uaY68A3iu8dN1E+rKXdWOoI5NT4xHGZ enTWyUSplVitn0zi39xOmIxd8E8EH2NvpEMehl1eDHqkdktZXX7nf3ebqkvI9U/S+7Nf uFdLqJd8R6kQnYYUFZkt31nAHzxIPURW5IcwBujjYRS/NVuh02g5LaHhB2zVYLYcSB4j 2jEZ8eY9++z4RmiYPtVQkODAliv5ykgD6TNu7r6AUuuPFakcn3OHAI5FjkG8WlwiRrBg 2a5w== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=UP632KzV8q/pnPeSOlqUSkndcfY2+BT3fJ9Prk+u7ew=; b=bNEaxFYkVsT6egyja63N396GUNs8Xzlk2+60ZWgj05xbgo4yTDVvPIQzMyrffbbFRF JS3j4YPNgBg2SnjUBv1Q70uQCDOM3IkP06lBRSeYtvLyLVZ5MOVm8bXtNKltROAzQ4I0 g64eby78Ij46pIt9yN8fxDwhKHvKdDXkczA4uVx6VgHA3wPzdAioMCjd98ErWrswMMje VYPw1/p6UIAe5NgwEDe2eHbXoZPw4kbo7iBNUOkykq3FPlnfZCRl1gYG66ySgxD/EsMq 9PGzi3eqSldMhRgMsc4Qv+CECF5GrWD2/kBn8xdXzlGge0uHcHJnoozJS0KObHzPn+we nStA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ipdlcls9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g6si6712204ejw.417.2020.12.07.07.51.22; Mon, 07 Dec 2020 07:51:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ipdlcls9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726841AbgLGPtd (ORCPT + 99 others); Mon, 7 Dec 2020 10:49:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726778AbgLGPtd (ORCPT ); Mon, 7 Dec 2020 10:49:33 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8811C061749 for ; Mon, 7 Dec 2020 07:48:52 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id l9so4082050wrt.13 for ; Mon, 07 Dec 2020 07:48:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=UP632KzV8q/pnPeSOlqUSkndcfY2+BT3fJ9Prk+u7ew=; b=Ipdlcls9kyqNyX6Qhc86PRPdrdbMtj53DwOhc2UwWErC83fNYkK3wqSwToYUcLqURz FrxkyAJirl59tcHgt1ynxog5yRZwt3lmvNg+ZRncezSDmxQXyAnHHMm9Ck4AmaNrlmIV LGv54RwDzC7JtvDLU5h1XI9YmbxvPwG6fVbCKrSBL+Vf/sfODCaH45VFjwbWIFuH0xYc dFpsWt8pCiRqjAoLy7/dwyNw+wYr2JgLzaHbGI7a0Zx6uWmpgkk1sXrAphFc23LlVroi mVvCbFy1ASeeI5XM/Gikxy/SqxccYyPwBmvOSffpnSJw7MQpL5nl8g779EomKKGmQ/PU AD4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=UP632KzV8q/pnPeSOlqUSkndcfY2+BT3fJ9Prk+u7ew=; b=lb6teVM/yDPbljjmX0j+upbuNknJEjRVJY9MzPdhJ5Uwjbq6HyHRpe4h3bz5xHqxYX Z/L+94yw0QnrIjolXHmFWCLnOCuh0rB54mlJPpVmxJL2y7BxNe/RMCZMM0w2ZP0flLk6 4HHygrqD1iMR05q69DJzpxw/Hlf+CT5L0rPC3MP5UsVNVAEjVlWqA4D0osnh0wdfR4zB oXTSVn3spZltYzq7+Ey7k3skndu7uvGNEwJxqXBit0gHHDwA8ZE+SR+ol3uRi/0cxO9C ncgjgsI5AAKsLy30/X9sgtNCmLI6LxEYGo2MOPJ0qiYcnYx5T5TlkAPg2szbxAUrQfPp Lg2w== X-Gm-Message-State: AOAM531t/58C3GExhiMU93CuDykjbmGkSUJYHY3KYYLPGWpqVRSYnF1M 9PBkREvPMLvjvjxlsqQWgHeCQQ== X-Received: by 2002:adf:8285:: with SMTP id 5mr6622195wrc.289.1607356131397; Mon, 07 Dec 2020 07:48:51 -0800 (PST) Received: from google.com (203.75.199.104.bc.googleusercontent.com. [104.199.75.203]) by smtp.gmail.com with ESMTPSA id a13sm14937428wrm.39.2020.12.07.07.48.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 07:48:50 -0800 (PST) Date: Mon, 7 Dec 2020 15:48:46 +0000 From: Brendan Jackman To: Andrii Nakryiko Cc: Yonghong Song , bpf , Alexei Starovoitov , Daniel Borkmann , KP Singh , Florent Revest , open list , Jann Horn Subject: Re: [PATCH bpf-next v3 13/14] bpf: Add tests for new BPF atomic operations Message-ID: References: <20201203160245.1014867-1-jackmanb@google.com> <20201203160245.1014867-14-jackmanb@google.com> <6f008322-0b8f-223a-9148-ce9fee0810dc@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 04, 2020 at 11:49:22AM -0800, Andrii Nakryiko wrote: > On Fri, Dec 4, 2020 at 7:29 AM Yonghong Song wrote: > > > > > > > > On 12/4/20 1:45 AM, Brendan Jackman wrote: > > > On Thu, Dec 03, 2020 at 11:06:31PM -0800, Yonghong Song wrote: > > >> On 12/3/20 8:02 AM, Brendan Jackman wrote: > > > [...] > > >>> diff --git a/tools/testing/selftests/bpf/prog_tests/atomics_test.c b/tools/testing/selftests/bpf/prog_tests/atomics_test.c > > >>> new file mode 100644 > > >>> index 000000000000..66f0ccf4f4ec > > >>> --- /dev/null > > >>> +++ b/tools/testing/selftests/bpf/prog_tests/atomics_test.c > > >>> @@ -0,0 +1,262 @@ > > >>> +// SPDX-License-Identifier: GPL-2.0 > > >>> + > > >>> +#include > > >>> + > > >>> + > > >>> +#include "atomics_test.skel.h" > > >>> + > > >>> +static struct atomics_test *setup(void) > > >>> +{ > > >>> + struct atomics_test *atomics_skel; > > >>> + __u32 duration = 0, err; > > >>> + > > >>> + atomics_skel = atomics_test__open_and_load(); > > >>> + if (CHECK(!atomics_skel, "atomics_skel_load", "atomics skeleton failed\n")) > > >>> + return NULL; > > >>> + > > >>> + if (atomics_skel->data->skip_tests) { > > >>> + printf("%s:SKIP:no ENABLE_ATOMICS_TEST (missing Clang BPF atomics support)", > > >>> + __func__); > > >>> + test__skip(); > > >>> + goto err; > > >>> + } > > >>> + > > >>> + err = atomics_test__attach(atomics_skel); > > >>> + if (CHECK(err, "atomics_attach", "atomics attach failed: %d\n", err)) > > >>> + goto err; > > >>> + > > >>> + return atomics_skel; > > >>> + > > >>> +err: > > >>> + atomics_test__destroy(atomics_skel); > > >>> + return NULL; > > >>> +} > > >>> + > > >>> +static void test_add(void) > > >>> +{ > > >>> + struct atomics_test *atomics_skel; > > >>> + int err, prog_fd; > > >>> + __u32 duration = 0, retval; > > >>> + > > >>> + atomics_skel = setup(); > > >> > > >> When running the test, I observed a noticeable delay between skel load and > > >> skel attach. The reason is the bpf program object file contains > > >> multiple programs and the above setup() tries to do attachment > > >> for ALL programs but actually below only "add" program is tested. > > >> This will unnecessarily increase test_progs running time. > > >> > > >> The best is for setup() here only load and attach program "add". > > >> The libbpf API bpf_program__set_autoload() can set a particular > > >> program not autoload. You can call attach function explicitly > > >> for one specific program. This should be able to reduce test > > >> running time. > > > > > > Interesting, thanks a lot - I'll try this out next week. Maybe we can > > > actually load all the progs once at the beginning (i.e. in > > > > If you have subtest, people expects subtest can be individual runable. > > This will complicate your logic. > > > > > test_atomics_test) then attach/detch each prog individually as needed... > > > Sorry, I haven't got much of a grip on libbpf yet. > > > > One alternative is not to do subtests. There is nothing run to have > > just one bpf program instead of many. This way, you load all and attach > > once, then do all the test verification. > > I think subtests are good for debuggability, at least. But in this > case it's very easy to achieve everything you've discussed: > > 1. do open() right there in test_atomics_test() (btw, consider naming > the test just "atomics" or "atomic_insns" or something, no need for > test-test tautology) > 2. check if needs skipping, skip entire test > 3. if not skipping, load > 4. then pass the same instance of the skeleton to each subtest > 5. each subtest will > 5a. bpf_prog__attach(skel->prog.my_specific_subtest_prog); > 5b. trigger and do checks > 5c. bpf_link__destroy(); Thanks, this seems like the way forward to me.