mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Weng Meiling <wengmeiling.weng@huawei.com>
To: Robert Richter <rric@kernel.org>
Cc: <oprofile-list@lists.sf.net>, <linux-kernel@vger.kernel.org>,
	Li Zefan <lizefan@huawei.com>, <wangnan0@huawei.com>,
	"zhangwei(Jovi)" <jovi.zhangwei@huawei.com>,
	Huang Qiang <h.huangqiang@huawei.com>
Subject: Re: [PATCH] oprofile: check whether oprofile perf enabled in op_overflow_handler()
Date: Thu, 16 Jan 2014 09:09:28 +0800	[thread overview]
Message-ID: <52D73148.4090408@huawei.com> (raw)
In-Reply-To: <20140115102445.GE20315@rric.localhost>


On 2014/1/15 18:24, Robert Richter wrote:
> On 15.01.14 10:02:44, Weng Meiling wrote:
>> On 2014/1/14 23:05, Robert Richter wrote:
>>> @@ -94,6 +98,11 @@ static int op_create_counter(int cpu, int event)
>>>  
>>>  	per_cpu(perf_events, cpu)[event] = pevent;
>>>  
>>> +	/* sync perf_events with overflow handler: */
>>> +	smp_wmb();
>>> +
>>> +	perf_event_enable(pevent);
>>> +
>>
>> Should this step go before the if check:pevent->state != PERF_EVENT_STATE_ACTIVE ?
>> Because the attr->disabled is true, So after the perf_event_create_kernel_counter
>> the pevent->state is not PERF_EVENT_STATE_ACTIVE.
> 
> Right, the check is a problem. We need to move it after the event was
> enabled. On error, we need to NULL the event, see below.
> 
> -Robert
> 
> ---
>  drivers/oprofile/oprofile_perf.c | 27 +++++++++++++++++++--------
>  1 file changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/oprofile/oprofile_perf.c b/drivers/oprofile/oprofile_perf.c
> index d5b2732..9dfb236 100644
> --- a/drivers/oprofile/oprofile_perf.c
> +++ b/drivers/oprofile/oprofile_perf.c
> @@ -38,6 +38,9 @@ static void op_overflow_handler(struct perf_event *event,
>  	int id;
>  	u32 cpu = smp_processor_id();
>  
> +	/* sync perf_events with op_create_counter(): */
> +	smp_rmb();
> +
>  	for (id = 0; id < num_counters; ++id)
>  		if (per_cpu(perf_events, cpu)[id] == event)
>  			break;
> @@ -68,6 +71,7 @@ static void op_perf_setup(void)
>  		attr->config		= counter_config[i].event;
>  		attr->sample_period	= counter_config[i].count;
>  		attr->pinned		= 1;
> +		attr->disabled		= 1;
>  	}
>  }
>  
> @@ -85,16 +89,23 @@ static int op_create_counter(int cpu, int event)
>  	if (IS_ERR(pevent))
>  		return PTR_ERR(pevent);
>  
> -	if (pevent->state != PERF_EVENT_STATE_ACTIVE) {
> -		perf_event_release_kernel(pevent);
> -		pr_warning("oprofile: failed to enable event %d "
> -				"on CPU %d\n", event, cpu);
> -		return -EBUSY;
> -	}
> -
>  	per_cpu(perf_events, cpu)[event] = pevent;
>  
> -	return 0;
> +	/* sync perf_events with overflow handler: */
> +	smp_wmb();
> +
> +	perf_event_enable(pevent);
> +
> +	if (pevent->state == PERF_EVENT_STATE_ACTIVE)
> +		return 0;
> +
> +	perf_event_release_kernel(pevent);
> +	per_cpu(perf_events, cpu)[event] = NULL;
> +
> +	pr_warning("oprofile: failed to enable event %d on CPU %d\n",
> +		event, cpu);
> +
> +	return -EBUSY;
>  }
>  
>  static void op_destroy_counter(int cpu, int event)
> 

OK, I'll test the patch, and send the result as soon as possible.


  reply	other threads:[~2014-01-16  1:10 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-20  7:49 Weng Meiling
2013-12-30  9:06 ` Weng Meiling
2014-01-13  8:45 ` Robert Richter
2014-01-14  1:52   ` Weng Meiling
2014-01-14 15:05     ` Robert Richter
2014-01-15  2:02       ` Weng Meiling
2014-01-15 10:24         ` Robert Richter
2014-01-16  1:09           ` Weng Meiling [this message]
2014-01-16  9:33             ` Weng Meiling
2014-01-16 11:52               ` Robert Richter
2014-01-16 19:36                 ` Will Deacon
2014-01-17  3:37                   ` Weng Meiling
2014-02-11  4:33                     ` Weng Meiling
2014-02-11 15:52                       ` Will Deacon
2014-02-11 18:05                         ` Will Deacon
2014-02-15  2:41                         ` Weng Meiling
2014-02-17 10:08                           ` Will Deacon
2014-02-17 11:39                             ` Weng Meiling

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52D73148.4090408@huawei.com \
    --to=wengmeiling.weng@huawei.com \
    --cc=h.huangqiang@huawei.com \
    --cc=jovi.zhangwei@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=oprofile-list@lists.sf.net \
    --cc=rric@kernel.org \
    --cc=wangnan0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome