Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1362995lqd; Thu, 25 Apr 2024 13:12:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWK/2yWza/PSlwJEijLnoP3ymJV7mar2i7r41WrlqOvXyCY91tE9NsA8v3ejN0gFkHdnAt7gaRYxJx9Bz3HsDzGVp5lcF+fbpm4etrr2Q== X-Google-Smtp-Source: AGHT+IHv57b1MeHj2lXnpktpoBddcVmGmMjmgngHKw7zcWNIy+EVPuvFfibMWZzU79NyJW2kKt3o X-Received: by 2002:a05:620a:3632:b0:78e:bd2d:1689 with SMTP id da50-20020a05620a363200b0078ebd2d1689mr721561qkb.36.1714075968512; Thu, 25 Apr 2024 13:12:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714075968; cv=pass; d=google.com; s=arc-20160816; b=JDdpYFmLJcriUVVlTc1PUVCw//8adLUs2D7QdPiHJ+LN+FVhLQG9hmBjXBl/OfZrp8 YLX/2zB6olCg/YAqQhFL/uWqzhKm0fjuDJ8HV5CGjz+BSCgVP2vTSXsIwmZ96TFPnsXp /fCBM20Cu16GCVWC+Nw32RcKPb2HsPh9P4Po+zUMqewsJfwZ8zOF9FxQbseCQjg+Zpsv 2xe74DVMNGOBxDca87P97wF783WAOZfAbgsjGKwIcyd8Gb4y61+1+opH/hOyKZWGBaRL szXWgVzoWI/b1WiNtu+NcsMEFaGKnOhepZHE8OIVAOSHTRNyElv2XBYL+LS2YTXuQdEY +xBQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XQBoevb+USW2ffiD4QLRp2t0k75BnseUBr4iry6tC6k=; fh=snlKTMG/24fnOxMQRtb8Nh4y2MHN/r9lknK6HpqXf/8=; b=VlHZderBhVw1TZfT1wXXoQsQjfTghZf9N3G64z9Pa9EKtfrFZPxhqkQVpNtEiuZhCu Froa1E8o4aNtcid6m7zP6zlAC5PEko+IsEoDyAC9/9cpafMvEXdDOlOvyV0heeqtn2St NKC865v62UNKIJZzBqq9W2XUjiHM+v/jbF0lXytBr03lLDRIbnVtGrFPwp46KTEMFkdD +VqzpTe6i+RYldC5xnd9CWOTtsnZMIgBw605v6jNJunPuWL9MimlDzpiespm+/yXgdOy TQuISdS6bdiHJZcSNJlMf+jl3N2AkgrPHVTk7aENbh6Hq8/T9ADWZTUUBW/vwVj4KdYz JHkw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=gN+MnxIc; arc=pass (i=1 spf=pass spfdomain=canonical.com dkim=pass dkdomain=canonical.com dmarc=pass fromdomain=canonical.com); spf=pass (google.com: domain of linux-kernel+bounces-159104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159104-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id t2-20020a05620a0b0200b0078a35250c01si17935672qkg.387.2024.04.25.13.12.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 13:12:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-159104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=gN+MnxIc; arc=pass (i=1 spf=pass spfdomain=canonical.com dkim=pass dkdomain=canonical.com dmarc=pass fromdomain=canonical.com); spf=pass (google.com: domain of linux-kernel+bounces-159104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159104-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id EF6DF1C21686 for ; Thu, 25 Apr 2024 20:12:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7137E153510; Thu, 25 Apr 2024 20:12:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="gN+MnxIc" Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2C6D152E1A for ; Thu, 25 Apr 2024 20:12:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714075960; cv=none; b=kGrFmE+6HLcD0/SoRGWA6Av406eEVziB7IKDplkgW0yI7AEEb70i2IPvrgJYoBpnPzM3/wwgYs4LJxgFHBU/qL0S6+JOu0dH+27bBeic9/fCZxjyo3dSSqO3KVRXFHVbN4dm3ZVG5bUUoVjUnvPfYJziuKYR7ElaVkYJBUMtSbI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714075960; c=relaxed/simple; bh=LQMNL24CL+osLBg292NUUAZjCTTOPr7F9KBHA/bQFTQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ug6DWNGQCmCUW9E9oaZPZGHE8RMBqAwWNssL5offi1Z/h4S0HjA8vVNwxWZh/Nkp78Qv1WPt55S2KSs8w0gFaXt3/bt6UfX1DO43iOVVMOzfiddZybwbsrGiP7z6wB9dXUidlMJW1KNw0m5gVFm0hiVHALeEtE9vPlZS/bo5wlE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=gN+MnxIc; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id E161340590 for ; Thu, 25 Apr 2024 20:12:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1714075955; bh=XQBoevb+USW2ffiD4QLRp2t0k75BnseUBr4iry6tC6k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:In-Reply-To; b=gN+MnxIcO9AFxc9CjgwCawhegMga+470GSd0pbcvB/R+Q6tQ52RumnJSlFZnt4STu pPKDVfygAPbs5gvwxfhytfr1G7UCFQ3C3Dz/F+GYPPWxfjM2z/O81vLEYM9EW6jg2l J8/Ga9oZQGLHWJylqTUpDgERxAs/1ueMmE0e4w8GHSMlhzQRUYQ9Ohxs3G8janQbgo oL3FiYUdEyyACW6W06s96XdxRyg9qCwVfO93hHnEo9xnG37BSx766IAULiSlN1sP3m TUQRW09sLK769EXKqrZ1SGEz8Hn+oj5TJaZ9F2LN+fkzI8hFVicRyqVgAML5vg7otA FQifcOoA6y52Q== Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a55709e5254so76601766b.3 for ; Thu, 25 Apr 2024 13:12:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714075955; x=1714680755; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XQBoevb+USW2ffiD4QLRp2t0k75BnseUBr4iry6tC6k=; b=p+IOFFCmcclI/ZXTDqTB1GPS8nG2jawDZqRnNf3YsiN7eKP7rxWzordNCOwRlgxf5F YLXOR5C9er6ctTcuY96dBVfSTQKPk0CGwrQP6psZ0MeOp7jpbsqoocqTPwXxz2bjMRcr HIAjjdXQPA3suU7cOcBxBR4x5shP6Ob4hR3nGVL3FBylcN7D+O2NQzeaEVhAWTzVdyCd 8fTqQIo6Z6aVoPgolreTurdniuV22jftD8NdCk4uDJKgc4V/GoJt7J998f+4vUiV4ghc a3tiRjrZh8TsDAbG3kJOzE2vXRVcpwrELGDwUh0cPQSwyd0+p+rOR2ypJYEGZ1uHKtyr 9p9A== X-Forwarded-Encrypted: i=1; AJvYcCURHuVyFV5Ge6x2oaLpypdR3tMBkOIX4sIilAzjOncXtZTJ9IC5iHxayoB5fy5ELxlk0k7BEUCL3YvH8L8now1+sGmUTrWTsgL2ymXR X-Gm-Message-State: AOJu0YyzXfGgEteyuqiwL9XPnP+IJFJsifu5ImVvN1XI2qHhoe2Z3k9F uxPTfb6hPX1d/G5wIu8tYzWSkaf6cGNun536YWUqBxDXTvr17u6aZzHHgltGe0ZXyY/0gfQUIgW MjFaarrsvqrkMjgM4BbUfCoB9+suBSdYk5EcLzXFgeyHZBeG/zTdHwEUxG6CvT9qZ7ESDgwq1jl oqWw== X-Received: by 2002:a17:906:3391:b0:a58:aa82:778d with SMTP id v17-20020a170906339100b00a58aa82778dmr465583eja.63.1714075955343; Thu, 25 Apr 2024 13:12:35 -0700 (PDT) X-Received: by 2002:a17:906:3391:b0:a58:aa82:778d with SMTP id v17-20020a170906339100b00a58aa82778dmr465551eja.63.1714075954779; Thu, 25 Apr 2024 13:12:34 -0700 (PDT) Received: from localhost (host-82-49-69-7.retail.telecomitalia.it. [82.49.69.7]) by smtp.gmail.com with ESMTPSA id qu20-20020a170907111400b00a5242ec4573sm9813171ejb.29.2024.04.25.13.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 13:12:34 -0700 (PDT) Date: Thu, 25 Apr 2024 22:12:33 +0200 From: Andrea Righi To: Andrii Nakryiko Cc: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v3] selftests/bpf: Add ring_buffer__consume_n test. Message-ID: References: <20240425140627.112728-1-andrea.righi@canonical.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Apr 25, 2024 at 11:47:07AM -0700, Andrii Nakryiko wrote: > On Thu, Apr 25, 2024 at 7:06 AM Andrea Righi wrote: > > > > Add a testcase for the ring_buffer__consume_n() API. > > > > The test produces multiple samples in a ring buffer, using a > > sys_getpid() fentry prog, and consumes them from user-space in batches, > > rather than consuming all of them greedily, like ring_buffer__consume() > > does. > > > > Link: https://lore.kernel.org/lkml/CAEf4BzaR4zqUpDmj44KNLdpJ=Tpa97GrvzuzVNO5nM6b7oWd1w@mail.gmail.com > > Signed-off-by: Andrea Righi > > --- > > tools/testing/selftests/bpf/Makefile | 2 +- > > .../selftests/bpf/prog_tests/ringbuf.c | 64 +++++++++++++++++++ > > .../selftests/bpf/progs/test_ringbuf_n.c | 47 ++++++++++++++ > > 3 files changed, 112 insertions(+), 1 deletion(-) > > create mode 100644 tools/testing/selftests/bpf/progs/test_ringbuf_n.c > > > > ChangeLog v2 -> v3: > > - move skel_n inside ringbuf_n_subtest() > > > > ChangeLog v1 -> v2: > > - replace CHECK() with ASSERT_EQ() > > - fix skel -> skel_n > > - drop unused "seq" field from struct sample > > > > [...] > > > + /* Produce N_TOT_SAMPLES samples in the ring buffer by calling getpid() */ > > + skel_n->bss->value = SAMPLE_VALUE; > > + for (i = 0; i < N_TOT_SAMPLES; i++) > > + syscall(__NR_getpgid); > > + > > + /* Consume all samples from the ring buffer in batches of N_SAMPLES */ > > + for (i = 0; i < N_TOT_SAMPLES; i += err) { > > + err = ring_buffer__consume_n(ringbuf, N_SAMPLES); > > + ASSERT_EQ(err, N_SAMPLES, "rb_consume"); > > if something goes wrong and err is < 0, we might end up with a very > long loop. I changed this to: > > if (!ASSERT_EQ(...)) > goto cleanup_ringbuf; > > to avoid this problem Looks good, tested, just in case, and it works a expected. Thanks! -Andrea > > > + } > > + > > +cleanup_ringbuf: > > + ring_buffer__free(ringbuf); > > +cleanup: > > + test_ringbuf_n_lskel__destroy(skel_n); > > +} > > + > > [...]