Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752498AbbHEKcW (ORCPT ); Wed, 5 Aug 2015 06:32:22 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:23102 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752406AbbHEKcT (ORCPT ); Wed, 5 Aug 2015 06:32:19 -0400 Message-ID: <55C1E61B.1040808@huawei.com> Date: Wed, 5 Aug 2015 18:31:55 +0800 From: xiakaixu User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: Peter Zijlstra CC: , , , , , , , , , , , Subject: Re: [PATCH v6 3/4] bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter References: <1438678696-88289-1-git-send-email-xiakaixu@huawei.com> <1438678696-88289-4-git-send-email-xiakaixu@huawei.com> <20150805100425.GZ25159@twins.programming.kicks-ass.net> In-Reply-To: <20150805100425.GZ25159@twins.programming.kicks-ass.net> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.111.101.23] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1978 Lines: 71 于 2015/8/5 18:04, Peter Zijlstra 写道: > On Tue, Aug 04, 2015 at 08:58:15AM +0000, Kaixu Xia wrote: >> diff --git a/kernel/events/core.c b/kernel/events/core.c >> index 6251b53..726ca1b 100644 >> --- a/kernel/events/core.c >> +++ b/kernel/events/core.c >> @@ -8599,6 +8599,25 @@ struct perf_event_attr *perf_event_attrs(struct perf_event *event) >> return &event->attr; >> } >> >> +u64 perf_event_read_internal(struct perf_event *event) > > Maybe: perf_event_read_local(), as this is this function only works for > events active on the current CPU. > >> +{ >> + if (!event) >> + return -EINVAL; >> + >> + if (unlikely(event->state != PERF_EVENT_STATE_ACTIVE)) >> + return -EINVAL; > > You can return perf_event_count() in that case. > >> + >> + if (event->oncpu != raw_smp_processor_id() && > > That _must_ be smp_processor_id(). If that gives a warning (ie. > preemption is not disabled or we're not affine to this one cpu) then the > warning is valid. > >> + event->ctx->task != current) > > Write it like: > > if (event->ctx->task != current && > event->oncpu != smp_processor_id()) > > That way you'll not evaluate smp_processor_id() for current task events. > >> + return -EINVAL; >> + >> + if (unlikely(event->attr.inherit)) >> + return -EINVAL; > > This should be in your accept function, inherited events should never > get this far. > > You need IRQs disabled while calling __perf_event_read(), did you test > with lockdep enabled? Thanks for your review! I've not tested it, will do that from now on. > >> + __perf_event_read(event); >> + return perf_event_count(event); >> +} > > Also, you probably want a WARN_ON(in_nmi()) there, this function is > _NOT_ NMI safe. > > > > . > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/