Received: by 10.223.164.202 with SMTP id h10csp794561wrb; Fri, 10 Nov 2017 15:21:48 -0800 (PST) X-Google-Smtp-Source: AGs4zMZogE1A8Tb1SpbobNiZuJF77oyOYFve3Gk7DDr2PJEwFa+zFf8IAfiJfeSBKKDMsiXY67ix X-Received: by 10.98.106.5 with SMTP id f5mr1995584pfc.27.1510356108022; Fri, 10 Nov 2017 15:21:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510356107; cv=none; d=google.com; s=arc-20160816; b=Jg6z9W3w+PRf6a6p50RgTEm4mC9bObrX6/4FjnmKKMgHcSOywXDgBqESAJ1tKUIvR0 KVEoKjuxY2mah66ueCR1CI9Kbv0olma70Jn+/i/8hxHmiQUIse39SFob7whu/E7BeAGf GOOW+tGRHuMC6briAUj/Zvasn3JM3E/7L0ij+ye8OXRjCeRrIqNE66K3axjrn73k7mfI FlJUptw3yIGy01xtAz3Kbc2BPJH/MByTSp/7cWpevCWkVL364aZyjE3f0NckRf5/thbQ z52LE52VgKsQ+VWgj2Hjz1CzuBWBxuu3wsIkVn+f9rhxvJtZrDXUFUYUbGsMTbAdjtDI XYuw== 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:date:cc:to:from:subject:message-id :arc-authentication-results; bh=sWhv9tkuTn/m5Nr1ugqISdVaFYo4QbMAc+UnX9hr9pE=; b=zA7RzbKCG3zmzZ2JXK7KSLtNFYUkI7ZVrmHOywvQKhGGV+GjxZgR40JyCewckOir4R EIxGNgJdb6Cxspgu5Go9MpF7KRIySFHVIFdRDiwAj9MCLeBFP7dcvSZZmf0OCgk52EMm +Zpw3uLGTpr8Cuj70lnH0SUErSjNp6jT1LLlEu1exGVA/THEONIslPYv2uQCaze/Il3t hA1LO+1qV/xIQUVFu3aqfxEMhQpMfBoFwoyQu7VNPHa7ZBU6bde8OP6hJKh7bRoeqG7H xJesh37CsR675MzuTlSaUvqTOLTuPFV4UgEox6WLfEkOpl3X52A3+jdDORw7zAv5ZQJw oQxA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si5912527pgo.705.2017.11.10.15.21.34; Fri, 10 Nov 2017 15:21:47 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754185AbdKJXUx (ORCPT + 83 others); Fri, 10 Nov 2017 18:20:53 -0500 Received: from mga01.intel.com ([192.55.52.88]:48834 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751186AbdKJXUv (ORCPT ); Fri, 10 Nov 2017 18:20:51 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Nov 2017 15:20:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,376,1505804400"; d="scan'208";a="1037717" Received: from megha-z97x-ud7-th.sc.intel.com (HELO [143.183.85.162]) ([143.183.85.162]) by orsmga003.jf.intel.com with ESMTP; 10 Nov 2017 15:20:49 -0800 Message-ID: <1510356963.2515.5.camel@megha-Z97X-UD7-TH> Subject: Re: [PATCH V0 2/3] perf/x86/intel/bm.c: Add Intel Branch Monitoring support From: Megha Dey To: Alexander Shishkin Cc: x86@kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, andriy.shevchenko@linux.intel.com, kstewart@linuxfoundation.org, yu-cheng.yu@intel.com, len.brown@intel.com, gregkh@linuxfoundation.org, peterz@infradead.org, acme@kernel.org, jolsa@redhat.com, namhyung@kernel.org, vikas.shivappa@linux.intel.com, pombredanne@nexb.com, me@kylehuey.com, bp@suse.de, grzegorz.andrejczuk@intel.com, tony.luck@intel.com, corbet@lwn.net, ravi.v.shankar@intel.com Date: Fri, 10 Nov 2017 15:36:03 -0800 In-Reply-To: <20171106114943.mg6pwpqe6eqlx7w2@ukko.fi.intel.com> References: <1509732006-5917-1-git-send-email-megha.dey@linux.intel.com> <1509732006-5917-3-git-send-email-megha.dey@linux.intel.com> <20171106114943.mg6pwpqe6eqlx7w2@ukko.fi.intel.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2017-11-06 at 13:49 +0200, Alexander Shishkin wrote: > On Fri, Nov 03, 2017 at 11:00:05AM -0700, Megha Dey wrote: > > +static int intel_bm_event_init(struct perf_event *event) > > +{ > > ... > > > + /* > > + * Find a hardware counter for the target task > > + */ > > + for (i = 0; i < bm_num_counters; i++) { > > + if ((bm_counter_owner[i] == NULL) || > > + (bm_counter_owner[i]->state == PERF_EVENT_STATE_DEAD)) { > > + counter_to_use = i; > > + bm_counter_owner[i] = event; > > + break; > > How are two concurrent perf_event_open()s not going to race here? > Also, I'm not sure what's the value of looking at the ->state here. > Shouldn't the ->destroy() method clear the corresponding array slot? Yes you are right. I will add a locking mechanism here to prevent racing and remove the ->state in the next version. > > > + } > > + } > > ... > > > + wrmsrl(BR_DETECT_COUNTER_CONFIG_BASE + counter_to_use, > > + event->hw.bm_counter_conf); > > + wrmsrl(BR_DETECT_STATUS_MSR, 0); > > These wrmsrs will happen on whatever CPU perf_event_open() is called on, > as opposed to the CPU where the event will be scheduled. You probably want > to keep the MSR accesses in the start()/stop() callbacks. Agreed, don't think we need this code here. We are writing to the MSRs in start() anyways. > > Regards, > -- > Alex > From 1583142257068794376@xxx Sat Nov 04 13:28:29 +0000 2017 X-GM-THRID: 1583067906559816766 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread