Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3693453ybv; Mon, 10 Feb 2020 04:50:12 -0800 (PST) X-Google-Smtp-Source: APXvYqzWNJ+ilf8ol4TteVJZzKT2hc48nZkoCifKNCXp9VSRY2hSHi96P1Npx3Eahhtueh/rjm1k X-Received: by 2002:a05:6808:64d:: with SMTP id z13mr735686oih.104.1581339012864; Mon, 10 Feb 2020 04:50:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581339012; cv=none; d=google.com; s=arc-20160816; b=QqSCU8Z9VT6mzJ4Wmb5c9spfH8jzg0j67fG/TE1eYvddaxI4HR85TpKq9OrE6yioZ8 EbJGB2O/8sYyHdfuFl3ZoYNSdTpUNlA+fK+JNMd7mT1rSXBJk1t9408LYiWZDF8uEKzv 163gn/VANSffT6ykAbJ4RoPhJcRnFSOOuiCMAQEEvnjUWiZbioHK6nc2XFMLJfsGrti4 8gC1fDCngDQ1zUfmEdHX8P8Ulz3G6opsbn2b967FbKwZuE8CS9SGn3HRmRHEOVhfaj8f 2BU5tu9QUI7hvkZYx2+0Vsf+q/q2b4UbCGU/c4G+ErQHvM9RUqAbIExR2m1sLDCIeWzp bCaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wapdjm9fpItUFQK830kayPTLA1FgMCsVpZLJyR8Pp7c=; b=CA2WFod4LSOVhA+9Wp8xeSk02YxFxwaDTMzJghjmqhdyfEANgPhNDEqJLDYLTJle8P 5WO8XNgmlmoRcyREeymKSvVYBJ0fKevAujh6iGyRKrJd2TuQ3E+NrZmDFmdE5GV5SV5Z p5q3iN0HHCR2lYnp7ACiCQ5ZH8WKwqC82vEYSc2HRegzU7hAa1mHX3GH1ZuBSEU01k20 96tLAViUMqydH2whhMFzZUX9ZMGU7rTd48iZU3Dy3BPMFAzyqpfjeuh7zAYYP9hx9oxn 83EwEJ5SMkSoxLoLsRy0soJGfaslSYZ+raIkllKI30UYX5APCsQG0mtQwZE+Y7tmf/Rg uBew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VFTPYCQo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t9si155384otp.57.2020.02.10.04.50.01; Mon, 10 Feb 2020 04:50:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VFTPYCQo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730710AbgBJMot (ORCPT + 99 others); Mon, 10 Feb 2020 07:44:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:41448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728095AbgBJMkq (ORCPT ); Mon, 10 Feb 2020 07:40:46 -0500 Received: from localhost (unknown [209.37.97.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 21E29208C4; Mon, 10 Feb 2020 12:40:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338446; bh=MIdrN4eNMf+qGiOgzxhA4qnCELEF867GZBySwRbQpQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VFTPYCQoXfU47cS3zm4/n5zCk3SVcTWafz/ENjbJk+Js/ZlhgIyLlj6h7r3YvEw0w Lkl3LoP8i+FXoLoBz1QeZGrNm/VblC9J4AQ0X8/P5TZErWUG9bSVC5iKkBISmfQBmB VAaSCiFmZ1ing7sUMPbOPzt1Z4rZRoU5qdv2MRqI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrii Nakryiko , Alexei Starovoitov Subject: [PATCH 5.5 161/367] selftests/bpf: Fix perf_buffer test on systems w/ offline CPUs Date: Mon, 10 Feb 2020 04:31:14 -0800 Message-Id: <20200210122439.685145454@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrii Nakryiko commit 91cbdf740a476cf2c744169bf407de2e3ac1f3cf upstream. Fix up perf_buffer.c selftest to take into account offline/missing CPUs. Fixes: ee5cf82ce04a ("selftests/bpf: test perf buffer API") Signed-off-by: Andrii Nakryiko Signed-off-by: Alexei Starovoitov Link: https://lore.kernel.org/bpf/20191212013621.1691858-1-andriin@fb.com Signed-off-by: Greg Kroah-Hartman --- tools/testing/selftests/bpf/prog_tests/perf_buffer.c | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) --- a/tools/testing/selftests/bpf/prog_tests/perf_buffer.c +++ b/tools/testing/selftests/bpf/prog_tests/perf_buffer.c @@ -4,6 +4,7 @@ #include #include #include +#include "libbpf_internal.h" static void on_sample(void *ctx, int cpu, void *data, __u32 size) { @@ -19,7 +20,7 @@ static void on_sample(void *ctx, int cpu void test_perf_buffer(void) { - int err, prog_fd, nr_cpus, i, duration = 0; + int err, prog_fd, on_len, nr_on_cpus = 0, nr_cpus, i, duration = 0; const char *prog_name = "kprobe/sys_nanosleep"; const char *file = "./test_perf_buffer.o"; struct perf_buffer_opts pb_opts = {}; @@ -29,15 +30,27 @@ void test_perf_buffer(void) struct bpf_object *obj; struct perf_buffer *pb; struct bpf_link *link; + bool *online; nr_cpus = libbpf_num_possible_cpus(); if (CHECK(nr_cpus < 0, "nr_cpus", "err %d\n", nr_cpus)) return; + err = parse_cpu_mask_file("/sys/devices/system/cpu/online", + &online, &on_len); + if (CHECK(err, "nr_on_cpus", "err %d\n", err)) + return; + + for (i = 0; i < on_len; i++) + if (online[i]) + nr_on_cpus++; + /* load program */ err = bpf_prog_load(file, BPF_PROG_TYPE_KPROBE, &obj, &prog_fd); - if (CHECK(err, "obj_load", "err %d errno %d\n", err, errno)) - return; + if (CHECK(err, "obj_load", "err %d errno %d\n", err, errno)) { + obj = NULL; + goto out_close; + } prog = bpf_object__find_program_by_title(obj, prog_name); if (CHECK(!prog, "find_probe", "prog '%s' not found\n", prog_name)) @@ -64,6 +77,11 @@ void test_perf_buffer(void) /* trigger kprobe on every CPU */ CPU_ZERO(&cpu_seen); for (i = 0; i < nr_cpus; i++) { + if (i >= on_len || !online[i]) { + printf("skipping offline CPU #%d\n", i); + continue; + } + CPU_ZERO(&cpu_set); CPU_SET(i, &cpu_set); @@ -81,8 +99,8 @@ void test_perf_buffer(void) if (CHECK(err < 0, "perf_buffer__poll", "err %d\n", err)) goto out_free_pb; - if (CHECK(CPU_COUNT(&cpu_seen) != nr_cpus, "seen_cpu_cnt", - "expect %d, seen %d\n", nr_cpus, CPU_COUNT(&cpu_seen))) + if (CHECK(CPU_COUNT(&cpu_seen) != nr_on_cpus, "seen_cpu_cnt", + "expect %d, seen %d\n", nr_on_cpus, CPU_COUNT(&cpu_seen))) goto out_free_pb; out_free_pb: @@ -91,4 +109,5 @@ out_detach: bpf_link__destroy(link); out_close: bpf_object__close(obj); + free(online); }