From patchwork Sat Sep 2 18:17:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 4951 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.15.201 with SMTP id 70csp1693124jao; Sat, 2 Sep 2017 11:18:10 -0700 (PDT) X-Google-Smtp-Source: ADKCNb6pyGtaiORHzMBRP+SCSanSefYiF9BErVmkOQ7fVLWi1d2UDRBEFLYKkEHlW0tKaSrgM88m X-Received: by 10.28.217.139 with SMTP id q133mr271972wmg.116.1504376290657; Sat, 02 Sep 2017 11:18:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504376290; cv=none; d=google.com; s=arc-20160816; b=mTjr65yJh8em5n8vkx9nLqBslu+8niXM40u13dWSQSGv3NEc579kuiT+QUD/DIvxy1 uvS7wOOJbxenXISX1JS67+p0XM9P7mH2dTQCi3cvAaNx28PSszta5/G0GwuMXtqE7rPT RafB9FcPCqK2AWAzKruoCrs3yUyhxe4mKqXXqE1VTqjVUJZTXssLzQzm5kwQ7YSyCsjf sqE1XwryMEOTGUkCYpEgKmaECBRahWq4wbvdIxDZTNBY9V6EiH8Dmeo8wB8HJ1gdicn6 kohoXkA/7ORf3IW/41qiOkL9zIiL9UVkGeMnjVsJjFYnpKSuJHoD5D/xA1Z2xDTIIsfK vrow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:domainkey-signature:dkim-signature :delivered-to:arc-authentication-results; bh=oizk/S4YjPZIrkeVblE40KBdbsb6vfcuZ/H11fVJUqo=; b=iEkWU40tq+bcyYQJPRy3SQ4po7TVsKESOBLSOS+W2+uPQ7YKya4MJLP+7l6XyKPIYw 0NYaGm/wrXJdoBTdOpfL/tRNj82sJMiEkd12bnS7Bhy4rOMj+PFtzpU2rPRp5TYAefg2 Ma/H6Z7RR+7Api94IkUg94gklcp1lma+1ddNo+6T1psTVmWM/y8L68En7XxWCN0xq9je K65+DyhAHtQSBvKUkcXKLMDamXujD2nnSGBglw9xwnGywiyY9ObQYtPHnzFCU4rauDTk KI57Oq7zpnh6cOQWtymYx+x7uatiywLLcNEEp6afhcKZDwTyT0543I5R5xnVJvMxSkNz 3mVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=cbY2TAtf; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 2si1921919wrl.366.2017.09.02.11.18.10; Sat, 02 Sep 2017 11:18:10 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=cbY2TAtf; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E52A9689D6A; Sat, 2 Sep 2017 21:17:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from golem.pkh.me (LStLambert-657-1-117-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 56E31689D08 for ; Sat, 2 Sep 2017 21:17:47 +0300 (EEST) Received: from golem.pkh.me (localhost.localdomain [127.0.0.1]) by golem.pkh.me (OpenSMTPD) with ESMTP id 18829e00; Sat, 2 Sep 2017 18:17:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pkh.me; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; s=selector1; bh=QBO+w34 +ipdpJ1s74fVJ1pGdm3Y=; b=cbY2TAtfW0XXt4SvBosTo+QUlJnMZ2DihrGDCsd 2IRfo1h4fnws0NZNZLZEduABHLjPE7NXygG68M49BaXrXETA6NFzZz/wzc3SP9Ov RVb3iystSQd4n+mM/Lw4826vMyGN4cNozCUdeqlvtS9tapRHZwF/j7+wTzhMQR4p OvXpu0iNw1Jm/LhhFfnCivu1Unna9blu8arSxUC5EGHC+LmfNkp70kQyaGqZJUHz tQDZKgu6h76xiWme75QNiFqnZGTfgaBCpYSSp+E617uR2PvsNAFSp/9bNhZVghy3 mxYmP59MYTGBIbqPLjoXJI3HWV9lJGzoFewT4Qp+IFSGdWw== DomainKey-Signature: a=rsa-sha1; c=nofws; d=pkh.me; h=from:to:cc:subject :date:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; q=dns; s=selector1; b=V 3wGXvzt4kI+YK9Har2WEG+oTfBUUkEe2VJrLnMLrYw4RBbiW5o7bZB+Qe6ldoCI5 aVY+DVCOV+1bQE9UiKLMCb60MDVHREgwnUklAiE8zEQtOiaXttyfyslOISIFiicL gQ9kvtGpSGlqRLej7dVckVb8md/wRDOfmbm791Tx0oBMfsmXz+1AQDO1JGOuqp4T vrt8VRwqmUhlDUzUbRe+X3+Mds3Izap+Tga3IYSAbULEngSg0NnHCOp8qzFLHY3l ztVppUv7jKxjTzPRqb3PLxLtHkuZWrmSTYB79R74ih4rGZZr2uIvGV1wHazDrvtS MusPWHKqwPA1Ph3pzAHUg== Received: from localhost (golem.pkh.me [local]) by golem.pkh.me (OpenSMTPD) with ESMTPA id 5a2685c5; Sat, 2 Sep 2017 18:17:43 +0000 (UTC) From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= To: ffmpeg-devel@ffmpeg.org Date: Sat, 2 Sep 2017 20:17:40 +0200 Message-Id: <20170902181740.23104-3-u@pkh.me> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170902181740.23104-1-u@pkh.me> References: <20170902181740.23104-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] lavu/timer.h: add Linux Perf API support X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Clément Bœsch Refer to "checkasm: use perf API on Linux ARM*" commit for the rationale. The implementation is somehow duplicated with checkasm, but so is the current usage of AV_READ_TIME(). Until these implementations and heuristics are made consistent, I don't see a way of sharing that code. Note: when using libavutil/timer.h, it is now important to include before any other include due to the _GNU_SOURCE requirement. --- libavutil/timer.h | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/libavutil/timer.h b/libavutil/timer.h index da0761b607..f7ab455df2 100644 --- a/libavutil/timer.h +++ b/libavutil/timer.h @@ -26,12 +26,22 @@ #ifndef AVUTIL_TIMER_H #define AVUTIL_TIMER_H +#include "config.h" + +#if CONFIG_LINUX_PERF +# ifndef _GNU_SOURCE +# define _GNU_SOURCE +# endif +# include // read(3) +# include +# include +# include +#endif + #include #include #include -#include "config.h" - #if HAVE_MACH_MACH_TIME_H #include #endif @@ -85,7 +95,37 @@ } \ } -#ifdef AV_READ_TIME +#if CONFIG_LINUX_PERF + +#define START_TIMER \ + static int linux_perf_fd; \ + uint64_t tperf; \ + if (!linux_perf_fd) { \ + struct perf_event_attr attr = { \ + .type = PERF_TYPE_HARDWARE, \ + .size = sizeof(struct perf_event_attr), \ + .config = PERF_COUNT_HW_CPU_CYCLES, \ + .disabled = 1, \ + .exclude_kernel = 1, \ + .exclude_hv = 1, \ + }; \ + linux_perf_fd = syscall(__NR_perf_event_open, &attr, \ + 0, -1, -1, 0); \ + } \ + if (linux_perf_fd == -1) { \ + av_log(NULL, AV_LOG_ERROR, "perf_event_open failed: %s\n", \ + av_err2str(AVERROR(errno))); \ + } else { \ + ioctl(linux_perf_fd, PERF_EVENT_IOC_RESET, 0); \ + ioctl(linux_perf_fd, PERF_EVENT_IOC_ENABLE, 0); \ + } + +#define STOP_TIMER(id) \ + ioctl(linux_perf_fd, PERF_EVENT_IOC_DISABLE, 0); \ + read(linux_perf_fd, &tperf, sizeof(tperf)); \ + TIMER_REPORT(id, tperf) + +#elif defined(AV_READ_TIME) #define START_TIMER \ uint64_t tend; \ uint64_t tstart = AV_READ_TIME(); \