Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3010420ybg; Mon, 28 Oct 2019 06:06:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwnG6pvXUW5STHVZQxHHfAouT45LbUid+3PiEjuVKIRN9h18Zy6sVMTwAl8pX0KOaM0yLdZ X-Received: by 2002:a05:6402:2d4:: with SMTP id b20mr17517527edx.103.1572267985223; Mon, 28 Oct 2019 06:06:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572267985; cv=none; d=google.com; s=arc-20160816; b=QhhI0NQkNapS3r+5exXPF+2DgRdcD8IohDEqPRQWF4Lrktz+cPvw4xRbnmGr7TlUV/ kFnKO01mL3J911iesuhJ7svTwrT1XkyJyjZv5EbxvO7NPxdrvP+ZMIaA9EGt1I37UHxI KfFDot3SJOFva1ijR563FjSS9+XvQubaWmg44XB8nfpC4inwkqYpRLRd00ct1usmk0qq 4d6exuZWASp65QJOaMR3XiZ0bI7d9vPnAmOcxR/ekBVoSQ8sx9FtNtcWWhWGKLgHcLsz ulMs5Tl19C9x6RGLTc7nIVLum7E//DdVjVpj1ncHEyQ6piwyAN/wqp9V0mpdVEGSa6nO cpZA== 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=qbvIV8NFzLW381kqWx7ZAJfNaoCQJF8H5l381KqTTVI=; b=GORhpHzozQeP4AjZCczPNUYFDeB0h/ftP0LpUemRDaGV75aUC/lb1E9J2Pxqm0aLah VQ5n4H64tcRBiss4khBgyxyWRNxXxh/1eIP1zmjQHroR9rppJY2xp0FGPGIzgUHgTLcw Lo/Mdt2fhZglk8BxQhRS9QifS9juszfkXoJ2apDaGZJAF2JIZU5ZoGdT8WsvdSeVmI+D SmWAHp8Vivpufg9uTXZF79NnR1xMX/3zeP7EMxvqcE43Zl3x9bokJrg3qt1T7DSbxRjV 6v7zFndxvcJ8INRS/1gnFBzLnjaiTTrCk4iUK/4B38PYmfi7p2WNqb+KmyfpksNKKelT FwlA== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c14si6301688ejm.48.2019.10.28.06.05.54; Mon, 28 Oct 2019 06:06:25 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729609AbfJ1C60 (ORCPT + 99 others); Sun, 27 Oct 2019 22:58:26 -0400 Received: from mga12.intel.com ([192.55.52.136]:35133 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728229AbfJ1C60 (ORCPT ); Sun, 27 Oct 2019 22:58:26 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Oct 2019 19:58:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,238,1569308400"; d="scan'208";a="229552470" Received: from sqa-gate.sh.intel.com (HELO clx-ap-likexu.tsp.org) ([10.239.48.212]) by fmsmga002.fm.intel.com with ESMTP; 27 Oct 2019 19:58:22 -0700 From: Like Xu To: Peter Zijlstra , Paolo Bonzini Cc: Sean Christopherson , Jim Mattson , Wanpeng Li , Alexander Shishkin , Arnaldo Carvalho de Melo , Borislav Petkov , Ingo Molnar , Jiri Olsa , Joerg Roedel , Namhyung Kim , Thomas Gleixner , Vitaly Kuznetsov , kan.liang@intel.com, wei.w.wang@intel.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH v4 1/6] perf/core: Provide a kernel-internal interface to recalibrate event period Date: Sun, 27 Oct 2019 18:52:38 +0800 Message-Id: <20191027105243.34339-2-like.xu@linux.intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191027105243.34339-1-like.xu@linux.intel.com> References: <20191027105243.34339-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, perf_event_period() is used by user tools via ioctl. Based on naming convention, exporting perf_event_period() for kernel users (such as KVM) who may recalibrate the event period for their assigned counter according to their requirements. The perf_event_period() is an external accessor, just like the perf_event_{en,dis}able() and should thus use perf_event_ctx_lock(). Suggested-by: Kan Liang Signed-off-by: Like Xu --- include/linux/perf_event.h | 5 +++++ kernel/events/core.c | 28 +++++++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 61448c19a132..d601df36e671 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1336,6 +1336,7 @@ extern void perf_event_disable_local(struct perf_event *event); extern void perf_event_disable_inatomic(struct perf_event *event); extern void perf_event_task_tick(void); extern int perf_event_account_interrupt(struct perf_event *event); +extern int perf_event_period(struct perf_event *event, u64 value); #else /* !CONFIG_PERF_EVENTS: */ static inline void * perf_aux_output_begin(struct perf_output_handle *handle, @@ -1415,6 +1416,10 @@ static inline void perf_event_disable(struct perf_event *event) { } static inline int __perf_event_disable(void *info) { return -1; } static inline void perf_event_task_tick(void) { } static inline int perf_event_release_kernel(struct perf_event *event) { return 0; } +static inline int perf_event_period(struct perf_event *event, u64 value) +{ + return -EINVAL; +} #endif #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL) diff --git a/kernel/events/core.c b/kernel/events/core.c index bb3748d29b04..2fbb485ae880 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -5106,16 +5106,11 @@ static int perf_event_check_period(struct perf_event *event, u64 value) return event->pmu->check_period(event, value); } -static int perf_event_period(struct perf_event *event, u64 __user *arg) +static int _perf_event_period(struct perf_event *event, u64 value) { - u64 value; - if (!is_sampling_event(event)) return -EINVAL; - if (copy_from_user(&value, arg, sizeof(value))) - return -EFAULT; - if (!value) return -EINVAL; @@ -5133,6 +5128,19 @@ static int perf_event_period(struct perf_event *event, u64 __user *arg) return 0; } +int perf_event_period(struct perf_event *event, u64 value) +{ + struct perf_event_context *ctx; + int ret; + + ctx = perf_event_ctx_lock(event); + ret = _perf_event_period(event, value); + perf_event_ctx_unlock(event, ctx); + + return ret; +} +EXPORT_SYMBOL_GPL(perf_event_period); + static const struct file_operations perf_fops; static inline int perf_fget_light(int fd, struct fd *p) @@ -5176,8 +5184,14 @@ static long _perf_ioctl(struct perf_event *event, unsigned int cmd, unsigned lon return _perf_event_refresh(event, arg); case PERF_EVENT_IOC_PERIOD: - return perf_event_period(event, (u64 __user *)arg); + { + u64 value; + + if (copy_from_user(&value, (u64 __user *)arg, sizeof(value))) + return -EFAULT; + return _perf_event_period(event, value); + } case PERF_EVENT_IOC_ID: { u64 id = primary_event_id(event); -- 2.21.0