From patchwork Fri Sep 29 12:39:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 9977959 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 543CF6034B for ; Fri, 29 Sep 2017 12:40:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4ACA32980D for ; Fri, 29 Sep 2017 12:40:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FA8E2985B; Fri, 29 Sep 2017 12:40:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BC1102980D for ; Fri, 29 Sep 2017 12:39:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 487E86EB59; Fri, 29 Sep 2017 12:39:59 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5CAC36EB01 for ; Fri, 29 Sep 2017 12:39:50 +0000 (UTC) Received: by mail-wr0-x241.google.com with SMTP id n64so1211247wrb.2 for ; Fri, 29 Sep 2017 05:39:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PJY/L4zh2IMyPmJPsCZvLGM4GvQ3NO5laaXa4lBtIFs=; b=YqCJOMsztcXi47GKn8RTa4PUOMdAZ6D+ya8EyX2r8yYxQ4Yu/QqweWsMwJyBd3ZocB CIs2QqpZBuCRQ0B/qnY6wYCImbvdR6CbEFIQKfT/xhxFYCTKAZ6QIXnnNFK6hQMub5C3 m6CELQbyb1kUzHy2Mg7Zs+TBTOEaEE5csLyJBapIq6ORxAchYDhOlQ7kzPUh8WhKHKIW KuK08HuseSO6CPlj6mOV61Z7+Ss21e2VyzpbsF2dHdnLQ0u2GioN4pfbGlT/egoOZE+0 C9FDTA538A4GYicG2bugC+JxgL7d4+viY0oihJE7ewsQnLY/Hl3enPwA7nMJQxCBbK0h BjMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PJY/L4zh2IMyPmJPsCZvLGM4GvQ3NO5laaXa4lBtIFs=; b=Ci66oi3ccAHxDw0/b9yYIySVBIQmmpRuzri6cccGFQzPEO2Ruo5I08c/yzAKY/4ZsI 9qVCTg+CfLetofugxiHhsgypFjFVN5puGn4wbVohZ0fiOD9qAX+TZkkGNfNrPAkI6uT9 nHUqo20M31W/f4nc3JajhX6HeN5NrNcin91Z590K6K5iwRqj2/4SWJ+O7tFNc8TmQRxp BrAHfQKSNPuekCoXiL5QNe4Y+BMWP0SoQSForaizIAMp5CTOYyyTFFAc+/Mg5DPpZff7 0kGgWE1c5S4z+3ggMDgzhiSassgcdXlE8QBB2iF85JJ8dWN0Z/4ldID5af9HiDCbRy4F K6Pw== X-Gm-Message-State: AHPjjUhxJ99FNYEns/o5B+vZF9IESoh0LBZujr6katkC8tCYUuFqjuuE pL1tgx7mzr+X7qBLQHe8rc3XFVJp X-Google-Smtp-Source: AOwi7QAAdbqVW1YFQb4tyx09AS7RS3/Pg6PJVNZG7cl49CQDYQ5nihG8SIzr88RxmOlO9rVOagd6eA== X-Received: by 10.223.162.152 with SMTP id s24mr6069398wra.207.1506688788573; Fri, 29 Sep 2017 05:39:48 -0700 (PDT) Received: from t460p.intel ([95.146.151.158]) by smtp.gmail.com with ESMTPSA id w5sm1959691wrg.65.2017.09.29.05.39.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Sep 2017 05:39:48 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Fri, 29 Sep 2017 13:39:34 +0100 Message-Id: <20170929123939.3312-3-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20170929123939.3312-1-tvrtko.ursulin@linux.intel.com> References: <20170929123939.3312-1-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [PATCH i-g-t 2/7] intel-gpu-overlay: Consolidate perf PMU access to library X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin Various tool modules implement their owm PMU open wrapper which can be replaced by calling the library one. v2: * Remove extra newline. (Chris Wilson) * Commit msg. Signed-off-by: Tvrtko Ursulin --- lib/igt_perf.c | 32 ++++++++++++++++++++++++++++++++ lib/igt_perf.h | 2 ++ overlay/gem-interrupts.c | 16 +--------------- overlay/gpu-freq.c | 22 ++-------------------- overlay/gpu-top.c | 32 ++++++++------------------------ overlay/power.c | 17 +---------------- overlay/rc6.c | 24 +++--------------------- 7 files changed, 49 insertions(+), 96 deletions(-) diff --git a/lib/igt_perf.c b/lib/igt_perf.c index 45cccff0ae53..961a858af9e3 100644 --- a/lib/igt_perf.c +++ b/lib/igt_perf.c @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include "igt_perf.h" @@ -24,3 +26,33 @@ uint64_t i915_type_id(void) return strtoull(buf, 0, 0); } +static int _perf_open(int config, int group, int format) +{ + struct perf_event_attr attr; + + memset(&attr, 0, sizeof (attr)); + + attr.type = i915_type_id(); + if (attr.type == 0) + return -ENOENT; + + attr.config = config; + + if (group >= 0) + format &= ~PERF_FORMAT_GROUP; + + attr.read_format = format; + + return perf_event_open(&attr, -1, 0, group, 0); +} + +int perf_i915_open(int config) +{ + return _perf_open(config, -1, PERF_FORMAT_TOTAL_TIME_ENABLED); +} + +int perf_i915_open_group(int config, int group) +{ + return _perf_open(config, group, + PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_GROUP); +} diff --git a/lib/igt_perf.h b/lib/igt_perf.h index a80b311cd1d1..8e674c3a3755 100644 --- a/lib/igt_perf.h +++ b/lib/igt_perf.h @@ -62,5 +62,7 @@ perf_event_open(struct perf_event_attr *attr, } uint64_t i915_type_id(void); +int perf_i915_open(int config); +int perf_i915_open_group(int config, int group); #endif /* I915_PERF_H */ diff --git a/overlay/gem-interrupts.c b/overlay/gem-interrupts.c index 7ba54fcd487d..a84aef0398a7 100644 --- a/overlay/gem-interrupts.c +++ b/overlay/gem-interrupts.c @@ -36,20 +36,6 @@ #include "gem-interrupts.h" #include "debugfs.h" -static int perf_open(void) -{ - struct perf_event_attr attr; - - memset(&attr, 0, sizeof (attr)); - - attr.type = i915_type_id(); - if (attr.type == 0) - return -ENOENT; - attr.config = I915_PERF_INTERRUPTS; - - return perf_event_open(&attr, -1, 0, -1, 0); -} - static long long debugfs_read(void) { char buf[8192], *b; @@ -127,7 +113,7 @@ int gem_interrupts_init(struct gem_interrupts *irqs) { memset(irqs, 0, sizeof(*irqs)); - irqs->fd = perf_open(); + irqs->fd = perf_i915_open(I915_PERF_INTERRUPTS); if (irqs->fd < 0 && interrupts_read() < 0) irqs->error = ENODEV; diff --git a/overlay/gpu-freq.c b/overlay/gpu-freq.c index 7f29b1aa986e..76c5ed9acfd1 100644 --- a/overlay/gpu-freq.c +++ b/overlay/gpu-freq.c @@ -33,30 +33,12 @@ #include "gpu-freq.h" #include "debugfs.h" -static int perf_i915_open(int config, int group) -{ - struct perf_event_attr attr; - - memset(&attr, 0, sizeof (attr)); - - attr.type = i915_type_id(); - if (attr.type == 0) - return -ENOENT; - attr.config = config; - - attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED; - if (group == -1) - attr.read_format |= PERF_FORMAT_GROUP; - - return perf_event_open(&attr, -1, 0, group, 0); -} - static int perf_open(void) { int fd; - fd = perf_i915_open(I915_PERF_ACTUAL_FREQUENCY, -1); - if (perf_i915_open(I915_PERF_REQUESTED_FREQUENCY, fd) < 0) { + fd = perf_i915_open_group(I915_PERF_ACTUAL_FREQUENCY, -1); + if (perf_i915_open_group(I915_PERF_REQUESTED_FREQUENCY, fd) < 0) { close(fd); fd = -1; } diff --git a/overlay/gpu-top.c b/overlay/gpu-top.c index 06f489dfdc83..812f47d5aced 100644 --- a/overlay/gpu-top.c +++ b/overlay/gpu-top.c @@ -48,24 +48,6 @@ #define I915_PERF_RING_WAIT(n) (__I915_PERF_RING(n) + 1) #define I915_PERF_RING_SEMA(n) (__I915_PERF_RING(n) + 2) -static int perf_i915_open(int config, int group) -{ - struct perf_event_attr attr; - - memset(&attr, 0, sizeof (attr)); - - attr.type = i915_type_id(); - if (attr.type == 0) - return -ENOENT; - attr.config = config; - - attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED; - if (group == -1) - attr.read_format |= PERF_FORMAT_GROUP; - - return perf_event_open(&attr, -1, 0, group, 0); -} - static int perf_init(struct gpu_top *gt) { const char *names[] = { @@ -77,27 +59,29 @@ static int perf_init(struct gpu_top *gt) }; int n; - gt->fd = perf_i915_open(I915_PERF_RING_BUSY(0), -1); + gt->fd = perf_i915_open_group(I915_PERF_RING_BUSY(0), -1); if (gt->fd < 0) return -1; - if (perf_i915_open(I915_PERF_RING_WAIT(0), gt->fd) >= 0) + if (perf_i915_open_group(I915_PERF_RING_WAIT(0), gt->fd) >= 0) gt->have_wait = 1; - if (perf_i915_open(I915_PERF_RING_SEMA(0), gt->fd) >= 0) + if (perf_i915_open_group(I915_PERF_RING_SEMA(0), gt->fd) >= 0) gt->have_sema = 1; gt->ring[0].name = names[0]; gt->num_rings = 1; for (n = 1; names[n]; n++) { - if (perf_i915_open(I915_PERF_RING_BUSY(n), gt->fd) >= 0) { + if (perf_i915_open_group(I915_PERF_RING_BUSY(n), gt->fd) >= 0) { if (gt->have_wait && - perf_i915_open(I915_PERF_RING_WAIT(n), gt->fd) < 0) + perf_i915_open_group(I915_PERF_RING_WAIT(n), + gt->fd) < 0) return -1; if (gt->have_sema && - perf_i915_open(I915_PERF_RING_SEMA(n), gt->fd) < 0) + perf_i915_open_group(I915_PERF_RING_SEMA(n), + gt->fd) < 0) return -1; gt->ring[gt->num_rings++].name = names[n]; diff --git a/overlay/power.c b/overlay/power.c index 84d860cae40c..dd4aec6bffd9 100644 --- a/overlay/power.c +++ b/overlay/power.c @@ -38,21 +38,6 @@ /* XXX Is this exposed through RAPL? */ -static int perf_open(void) -{ - struct perf_event_attr attr; - - memset(&attr, 0, sizeof (attr)); - - attr.type = i915_type_id(); - if (attr.type == 0) - return -1; - attr.config = I915_PERF_ENERGY; - - attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED; - return perf_event_open(&attr, -1, 0, -1, 0); -} - int power_init(struct power *power) { char buf[4096]; @@ -60,7 +45,7 @@ int power_init(struct power *power) memset(power, 0, sizeof(*power)); - power->fd = perf_open(); + power->fd = perf_i915_open(I915_PERF_ENERGY); if (power->fd != -1) return 0; diff --git a/overlay/rc6.c b/overlay/rc6.c index 3175bb22308f..46c975a557ff 100644 --- a/overlay/rc6.c +++ b/overlay/rc6.c @@ -35,24 +35,6 @@ #include "rc6.h" -static int perf_i915_open(int config, int group) -{ - struct perf_event_attr attr; - - memset(&attr, 0, sizeof (attr)); - - attr.type = i915_type_id(); - if (attr.type == 0) - return -ENOENT; - attr.config = config; - - attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED; - if (group == -1) - attr.read_format |= PERF_FORMAT_GROUP; - - return perf_event_open(&attr, -1, 0, group, 0); -} - #define RC6 (1<<0) #define RC6p (1<<1) #define RC6pp (1<<2) @@ -61,15 +43,15 @@ static int perf_open(unsigned *flags) { int fd; - fd = perf_i915_open(I915_PERF_RC6_RESIDENCY, -1); + fd = perf_i915_open_group(I915_PERF_RC6_RESIDENCY, -1); if (fd < 0) return -1; *flags |= RC6; - if (perf_i915_open(I915_PERF_RC6p_RESIDENCY, fd) >= 0) + if (perf_i915_open_group(I915_PERF_RC6p_RESIDENCY, fd) >= 0) *flags |= RC6p; - if (perf_i915_open(I915_PERF_RC6pp_RESIDENCY, fd) >= 0) + if (perf_i915_open_group(I915_PERF_RC6pp_RESIDENCY, fd) >= 0) *flags |= RC6pp; return fd;