Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2131782pxb; Fri, 25 Mar 2022 11:38:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxq4otNbd1ythuBDOZh+uVNqwTmAgCb9SUvf0ZKmUjsZ1mz8IhZ1a+DdTveTn9mcRWyVOdc X-Received: by 2002:a17:902:d505:b0:154:76c2:f7bb with SMTP id b5-20020a170902d50500b0015476c2f7bbmr12944383plg.83.1648233523591; Fri, 25 Mar 2022 11:38:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648233523; cv=none; d=google.com; s=arc-20160816; b=pNVmYCrk2lWgthKaTOWbczUdVP6pgb9hhziL6Jik7rVqrjzVUOIUd7orDTzqqBBEQ5 RK7lVtaH4XAz6uX1PjP2rtOulM+O2InD3lKZokUJfemVIV7jeeO6H314FLz35wZzJtQK lH/QYAj4S/X5lLHrxyn8FvPqIJff08lPzA2aLmNPJC7sHznvP3N1zPOdwRjR4eykz4ee MUv1WGub7StZGtIKr9R3pmYxzv1Pv1BD3/LI3mx1My1OKDlMK2sV5gSl7VwANwNhquiW smkPux8/gsnYSlbaiVtumGBmiZk6C9QUKzc8ZNkY0uoEgev0OV4K8h3D4ksjDsCeXM0f bExA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=EnRjalLUnne4WiFDoA03n0RXMV+xf0Wg/PN4mQImy1k=; b=Jr/LRGO4IQZOp4lVUSS0hHKsOCbvs3ynsTupxghLUsQaNJMVvxGQAf3Cx6uVoL4PNV oIJY5xRVSk63oAfLIm+/3SacvlHTjpIKhkKCuh9ipcF0lF94OUFSD/6h2Uiriw9WS9Dq oHw6+gm8CQOuu3hkOxYSgDnd9jKBAhp5yG65OYR/yjx2dFdEyT6LCPnBEgcNiww3LLgT PDjTDYzZxUCThjyyXR7oxqApkALAuxQiVC4SKlF9H81t4x56nx37DLql7VgD6fEWKzil sJTjH8EYzFK8Rw/1j67T45LfR0PFpoiEQLBRK0NPiZana+WARQAh6DUHIA/ADstTVO7+ dAOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id p22-20020a056a000b5600b004fa3a8e0091si3503909pfo.328.2022.03.25.11.38.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 11:38:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E91B3F47E3; Fri, 25 Mar 2022 10:56:29 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344501AbiCYEpP (ORCPT + 99 others); Fri, 25 Mar 2022 00:45:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358282AbiCYEpJ (ORCPT ); Fri, 25 Mar 2022 00:45:09 -0400 Received: from esa11.hc1455-7.c3s2.iphmx.com (esa11.hc1455-7.c3s2.iphmx.com [207.54.90.137]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB21569CDA; Thu, 24 Mar 2022 21:43:25 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6200,9189,10296"; a="46962374" X-IronPort-AV: E=Sophos;i="5.90,209,1643641200"; d="scan'208";a="46962374" Received: from unknown (HELO yto-r4.gw.nic.fujitsu.com) ([218.44.52.220]) by esa11.hc1455-7.c3s2.iphmx.com with ESMTP; 25 Mar 2022 13:43:21 +0900 Received: from yto-m2.gw.nic.fujitsu.com (yto-nat-yto-m2.gw.nic.fujitsu.com [192.168.83.65]) by yto-r4.gw.nic.fujitsu.com (Postfix) with ESMTP id 4FC39CD6C3; Fri, 25 Mar 2022 13:43:22 +0900 (JST) Received: from oym-om3.fujitsu.com (oym-om3.o.css.fujitsu.com [10.85.58.163]) by yto-m2.gw.nic.fujitsu.com (Postfix) with ESMTP id 0639D169187; Fri, 25 Mar 2022 13:43:21 +0900 (JST) Received: from localhost.localdomain (bakeccha.fct.css.fujitsu.com [10.126.195.136]) by oym-om3.fujitsu.com (Postfix) with ESMTP id B7510403F02E4; Fri, 25 Mar 2022 13:43:20 +0900 (JST) From: Shunsuke Nakamura To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [RFC PATCH v2 7/7] libperf test: Add test_stat_overflow_event() Date: Fri, 25 Mar 2022 13:38:29 +0900 Message-Id: <20220325043829.224045-8-nakamura.shun@fujitsu.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220325043829.224045-1-nakamura.shun@fujitsu.com> References: <20220325043829.224045-1-nakamura.shun@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,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 Add a test to check overflowed events. Committer testing: $ sudo make tests -C ./tools/lib/perf V=1 make: Entering directory '/home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/lib/perf' make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=. obj=libperf make -C /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/lib/api/ O= libapi.a make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=./fd obj=libapi make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=./fs obj=libapi make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=. obj=tests make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=./tests obj=tests running static: - running tests/test-cpumap.c...OK - running tests/test-threadmap.c...OK - running tests/test-evlist.c... Event 0 -- overflow flag = 0x1, POLL_UP = 1, other signal event = 0 Event 1 -- overflow flag = 0x2, POLL_UP = 1, other signal event = 0 Event 2 -- overflow flag = 0x4, POLL_UP = 1, other signal event = 0 Event 3 -- overflow flag = 0x8, POLL_UP = 1, other signal event = 0 OK - running tests/test-evsel.c... OK running dynamic: - running tests/test-cpumap.c...OK - running tests/test-threadmap.c...OK - running tests/test-evlist.c... Event 0 -- overflow flag = 0x1, POLL_UP = 1, other signal event = 0 Event 1 -- overflow flag = 0x2, POLL_UP = 1, other signal event = 0 Event 2 -- overflow flag = 0x4, POLL_UP = 1, other signal event = 0 Event 3 -- overflow flag = 0x8, POLL_UP = 1, other signal event = 0 OK - running tests/test-evsel.c... OK make: Leaving directory '/home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/lib/perf' Signed-off-by: Shunsuke Nakamura --- tools/lib/perf/tests/test-evlist.c | 127 +++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/tools/lib/perf/tests/test-evlist.c b/tools/lib/perf/tests/test-evlist.c index ed616fc19b4f..ecfe35c64c40 100644 --- a/tools/lib/perf/tests/test-evlist.c +++ b/tools/lib/perf/tests/test-evlist.c @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include #include #include @@ -25,6 +27,13 @@ #define EVENT_NUM 15 #define WAIT_COUNT 100000000UL +static unsigned int overflow_flag; +static struct signal_counts { + int hup; + int others; +} sig_count = { 0, 0 }; +static struct perf_evlist *s_evlist; + static int libperf_print(enum libperf_print_level level, const char *fmt, va_list ap) { @@ -571,6 +580,123 @@ static int test_stat_multiplexing(void) return 0; } +static void sig_handler(int signo, siginfo_t *info, void *uc) +{ + struct perf_evsel *evsel; + int idx = 0; + bool overflow; + int err; + + switch (info->si_code) { + case POLL_HUP: + perf_evlist__for_each_evsel(s_evlist, evsel) { + err = perf_evsel__check_overflow(evsel, info->si_fd, &overflow); + if (err) + fprintf(stderr, "failed to check evsel overflow %d\n", err); + + if (overflow) { + overflow_flag = (1U << idx); + sig_count.hup++; + break; + } + idx++; + } + break; + default: + perf_evlist__for_each_evsel(s_evlist, evsel) { + err = perf_evsel__check_overflow(evsel, info->si_fd, &overflow); + if (err) + fprintf(stderr, "failed to check evsel overflow %d\n", err); + + if (overflow) { + overflow_flag = (1U << idx); + sig_count.others++; + break; + } + idx++; + } + } +} + +static int test_stat_overflow_event(void) +{ + static struct sigaction sig; + + struct perf_thread_map *threads; + struct perf_evsel *evsel; + struct perf_event_attr attr = { + .type = PERF_TYPE_SOFTWARE, + .config = PERF_COUNT_SW_CPU_CLOCK, + .sample_type = PERF_SAMPLE_PERIOD, + .sample_period = 100000, + .disabled = 1, + }; + int err, i, event_num = 4; + + LIBPERF_OPTS(perf_evsel_open_opts, opts, + .open_flags = PERF_FLAG_FD_CLOEXEC, + .flags = (O_RDWR | O_NONBLOCK | O_ASYNC), + .signal = SIGIO, + .owner_type = F_OWNER_PID, + .sig = &sig); + + /* setup signal handler */ + memset(&sig, 0, sizeof(struct sigaction)); + sig.sa_sigaction = (void *)sig_handler; + sig.sa_flags = SA_SIGINFO; + + threads = perf_thread_map__new_dummy(); + __T("failed to create threads", threads); + + perf_thread_map__set_pid(threads, 0, 0); + + s_evlist = perf_evlist__new(); + __T("failed to create evlist", s_evlist); + + for (i = 0; i < event_num; i++) { + evsel = perf_evsel__new(&attr); + __T("failed to create evsel", evsel); + + perf_evlist__add(s_evlist, evsel); + } + + perf_evlist__set_maps(s_evlist, NULL, threads); + + err = perf_evlist__open_opts(s_evlist, &opts); + __T("failed to open evlist", err == 0); + + i = 0; + perf_evlist__for_each_evsel(s_evlist, evsel) { + volatile unsigned int wait_count = WAIT_COUNT; + + err = perf_evsel__refresh(evsel, 1); + __T("failed to refresh evsel", err == 0); + + while (wait_count--) + ; + + __T_VERBOSE("Event %2d -- overflow flag = %#x, ", + i, overflow_flag); + __T_VERBOSE("POLL_UP = %d, other signal event = %d\n", + sig_count.hup, sig_count.others); + + __T("unexpected event overflow detected", overflow_flag && (1U << i)); + __T("unexpected signal event detected", + sig_count.hup == 1 && sig_count.others == 0); + + overflow_flag = 0; + sig_count.hup = 0; + sig_count.others = 0; + i++; + } + + perf_evlist__close(s_evlist); + perf_evlist__delete(s_evlist); + perf_thread_map__put(threads); + + return 0; +} + int test_evlist(int argc, char **argv) { __T_START; @@ -583,6 +709,7 @@ int test_evlist(int argc, char **argv) test_mmap_thread(); test_mmap_cpus(); test_stat_multiplexing(); + test_stat_overflow_event(); __T_END; return tests_failed == 0 ? 0 : -1; -- 2.25.1