Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5881651ybi; Sun, 21 Jul 2019 04:35:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxCTEYewu3+ShlPkhmsdcD24/1hlLgg64v7YHLnoafjLBJS8jtXoAV8308ywqhkyRRgXwUt X-Received: by 2002:a63:f857:: with SMTP id v23mr41222340pgj.228.1563708939402; Sun, 21 Jul 2019 04:35:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563708939; cv=none; d=google.com; s=arc-20160816; b=vROt66OAr7SV2AWH6qWX3mATpTzdYETiMYiTs20aauY97sGsstKmwCPvynSIM+vjgg giySO4NX8d4HqVb2+C4/zBrKpnGTzv+Q5aXsCGENm23oeNaEIr1clFo6ST5LuozIJZfF W5AeSG3iPnh6GOwzajmVP/vbpR+pLRBxlvvJVcEu6WQwExJ+hP/Y0qsIsZBa2Ehplj6o ls1RI/zS6Palc8MDwMMtJM1vmLzpD7uXnFXmotjQPtt9jsF0YeArSRR5o4V2A8mv8wUE CH0Iip/gQRN7w++hzUntUQTbccc0Elhi0Kj8mi/LO0f57raFVh2RsKnb1yTBd9lpgbyJ Gevg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=DLc5GtezfkH1GUa/5pNEPLO84PVs2/7klETi8kUyBTg=; b=x0gpJha9Y5IYQ2oLAIWt6kXN0SU+MS4WRdwceuki30oR59czMUqaZr0mBc6tkwOHkJ T3ZXuB24pKpcKBZWls2W0qz+sAiNffyzBa16lp/VAedDG3QFc1agqca9pnpHecVWBPnE 6jp1Q76oYlxYQn8hzquHjQgsoH/d/uGz/g0QfCHk9UJ9v4qZ+jTkUvTXj0dUKpd+gFKL 4kI9f5ey9mEE8CdZrBI+CdZUUvpk1P76DS2VjKN50sx0L2jTwMi8vPhcp9gZT7G+o920 PwaY9n0fSLvEN1RcJQ0NcR0G51xL5pwZkYa8VcjKip9T/52ne0jl1vR0/2mZ/La/JGv1 CkhA== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r12si6645800pgm.473.2019.07.21.04.35.23; Sun, 21 Jul 2019 04:35:39 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727547AbfGULdF (ORCPT + 99 others); Sun, 21 Jul 2019 07:33:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38382 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726390AbfGULdE (ORCPT ); Sun, 21 Jul 2019 07:33:04 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2CC1A883BA; Sun, 21 Jul 2019 11:33:04 +0000 (UTC) Received: from krava.redhat.com (ovpn-204-23.brq.redhat.com [10.40.204.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F7F95D9D3; Sun, 21 Jul 2019 11:32:59 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Andi Kleen , Alexey Budankov , Michael Petlan Subject: [PATCH 77/79] libperf: Add perf_evlist__enable/disable test Date: Sun, 21 Jul 2019 13:25:04 +0200 Message-Id: <20190721112506.12306-78-jolsa@kernel.org> In-Reply-To: <20190721112506.12306-1-jolsa@kernel.org> References: <20190721112506.12306-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sun, 21 Jul 2019 11:33:04 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add simple perf_evlist enable/disable test together with evlist counter reading interface. Link: http://lkml.kernel.org/n/tip-6hfivpokxx49knjdtg1hcvcs@git.kernel.org Signed-off-by: Jiri Olsa --- tools/perf/lib/tests/test-evlist.c | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tools/perf/lib/tests/test-evlist.c b/tools/perf/lib/tests/test-evlist.c index f24c531afcb6..4e1407f20ffd 100644 --- a/tools/perf/lib/tests/test-evlist.c +++ b/tools/perf/lib/tests/test-evlist.c @@ -111,12 +111,75 @@ static int test_stat_thread(void) return 0; } +static int test_stat_thread_enable(void) +{ + struct perf_counts_values counts = { .val = 0 }; + struct perf_thread_map *threads; + struct perf_evlist *evlist; + struct perf_evsel *evsel; + struct perf_event_attr attr1 = { + .type = PERF_TYPE_SOFTWARE, + .config = PERF_COUNT_SW_CPU_CLOCK, + .disabled = 1, + }; + struct perf_event_attr attr2 = { + .type = PERF_TYPE_SOFTWARE, + .config = PERF_COUNT_SW_TASK_CLOCK, + .disabled = 1, + }; + int err; + + threads = perf_thread_map__new_dummy(); + __T("failed to create threads", threads); + + perf_thread_map__set_pid(threads, 0, 0); + + evlist = perf_evlist__new(); + __T("failed to create evlist", evlist); + + evsel = perf_evsel__new(&attr1); + __T("failed to create evsel1", evsel); + + perf_evlist__add(evlist, evsel); + + evsel = perf_evsel__new(&attr2); + __T("failed to create evsel2", evsel); + + perf_evlist__add(evlist, evsel); + + perf_evlist__set_maps(evlist, NULL, threads); + + err = perf_evlist__open(evlist); + __T("failed to open evsel", err == 0); + + perf_evlist__for_each_evsel(evlist, evsel) { + perf_evsel__read(evsel, 0, 0, &counts); + __T("failed to read value for evsel", counts.val == 0); + } + + perf_evlist__enable(evlist); + + perf_evlist__for_each_evsel(evlist, evsel) { + perf_evsel__read(evsel, 0, 0, &counts); + __T("failed to read value for evsel", counts.val != 0); + } + + perf_evlist__disable(evlist); + + perf_evlist__close(evlist); + perf_evlist__delete(evlist); + + perf_thread_map__put(threads); + return 0; +} + int main(int argc, char **argv) { __T_START; test_stat_cpu(); test_stat_thread(); + test_stat_thread_enable(); __T_OK; return 0; -- 2.21.0