All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lan Tianyu <tianyu.lan@intel.com>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: tj@kernel.org, jolsa@redhat.com, oleg@redhat.com,
	lenb@kernel.org, linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ACPI/Processor: Rework processor throttling with work_on_cpu()
Date: Wed, 26 Feb 2014 09:08:46 +0800	[thread overview]
Message-ID: <530D3E9E.7010206@intel.com> (raw)
In-Reply-To: <3890679.FyyHKXfXOb@vostro.rjw.lan>

On 2014年02月26日 09:23, Rafael J. Wysocki wrote:
> On Friday, February 21, 2014 01:35:45 PM Lan Tianyu wrote:
>> acpi_processor_set_throttling() uses set_cpus_allowed_ptr() to make
>> sure struct acpi_processor->acpi_processor_set_throttling() callback
>> run on associated cpu. But the function maybe called in a worker which
>> has been bound to a cpu. The patch is to replace set_cpus_allowed_ptr()
>> with work_on_cpu().
>>
>> Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
>> ---
>>  drivers/acpi/processor_throttling.c | 70 +++++++++++++++++--------------------
>>  1 file changed, 33 insertions(+), 37 deletions(-)
>>
>> diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
>> index 28baa05..2db105a 100644
>> --- a/drivers/acpi/processor_throttling.c
>> +++ b/drivers/acpi/processor_throttling.c
>> @@ -56,6 +56,12 @@ struct throttling_tstate {
>>  	int target_state;		/* target T-state */
>>  };
>>  
>> +struct acpi_processor_throttling_arg {
>> +	struct acpi_processor *pr;
>> +	int target_state;
>> +	bool force;
>> +};
>> +
>>  #define THROTTLING_PRECHANGE       (1)
>>  #define THROTTLING_POSTCHANGE      (2)
>>  
>> @@ -1060,16 +1066,25 @@ static int acpi_processor_set_throttling_ptc(struct acpi_processor *pr,
>>  	return 0;
>>  }
>>  
>> +static long acpi_processor_throttling_fn(void *data)
>> +{
>> +	struct acpi_processor_throttling_arg *arg = data;
>> +	struct acpi_processor *pr = arg->pr;
>> +	struct acpi_processor_throttling *p_throttling = &pr->throttling;
>> +
>> +	return p_throttling->acpi_processor_set_throttling(pr,
>> +			arg->target_state, arg->force);
> 
> What about doing
> 
> 	return pr->throttling.acpi_processor_set_throttling(...);
> 
> directly without using the extra p_throttling pointer?

This is better. I will update soon.

> 
>> +}
>> +
>>  int acpi_processor_set_throttling(struct acpi_processor *pr,
>>  						int state, bool force)
>>  {
>> -	cpumask_var_t saved_mask;
>>  	int ret = 0;
>>  	unsigned int i;
>>  	struct acpi_processor *match_pr;
>>  	struct acpi_processor_throttling *p_throttling;
>> +	struct acpi_processor_throttling_arg arg;
>>  	struct throttling_tstate t_state;
>> -	cpumask_var_t online_throttling_cpus;
>>  
>>  	if (!pr)
>>  		return -EINVAL;
>> @@ -1080,14 +1095,6 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
>>  	if ((state < 0) || (state > (pr->throttling.state_count - 1)))
>>  		return -EINVAL;
>>  
>> -	if (!alloc_cpumask_var(&saved_mask, GFP_KERNEL))
>> -		return -ENOMEM;
>> -
>> -	if (!alloc_cpumask_var(&online_throttling_cpus, GFP_KERNEL)) {
>> -		free_cpumask_var(saved_mask);
>> -		return -ENOMEM;
>> -	}
>> -
>>  	if (cpu_is_offline(pr->id)) {
>>  		/*
>>  		 * the cpu pointed by pr->id is offline. Unnecessary to change
>> @@ -1096,17 +1103,15 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
>>  		return -ENODEV;
>>  	}
>>  
>> -	cpumask_copy(saved_mask, &current->cpus_allowed);
>>  	t_state.target_state = state;
>>  	p_throttling = &(pr->throttling);
>> -	cpumask_and(online_throttling_cpus, cpu_online_mask,
>> -		    p_throttling->shared_cpu_map);
>> +
>>  	/*
>>  	 * The throttling notifier will be called for every
>>  	 * affected cpu in order to get one proper T-state.
>>  	 * The notifier event is THROTTLING_PRECHANGE.
>>  	 */
>> -	for_each_cpu(i, online_throttling_cpus) {
>> +	for_each_cpu_and(i, cpu_online_mask, p_throttling->shared_cpu_map) {
>>  		t_state.cpu = i;
>>  		acpi_processor_throttling_notifier(THROTTLING_PRECHANGE,
>>  							&t_state);
>> @@ -1118,21 +1123,18 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
>>  	 * it can be called only for the cpu pointed by pr.
>>  	 */
>>  	if (p_throttling->shared_type == DOMAIN_COORD_TYPE_SW_ANY) {
>> -		/* FIXME: use work_on_cpu() */
>> -		if (set_cpus_allowed_ptr(current, cpumask_of(pr->id))) {
>> -			/* Can't migrate to the pr->id CPU. Exit */
>> -			ret = -ENODEV;
>> -			goto exit;
>> -		}
>> -		ret = p_throttling->acpi_processor_set_throttling(pr,
>> -						t_state.target_state, force);
>> +		arg.pr = pr;
>> +		arg.target_state = state;
>> +		arg.force = force;
>> +		ret = work_on_cpu(pr->id, acpi_processor_throttling_fn, &arg);
>>  	} else {
>>  		/*
>>  		 * When the T-state coordination is SW_ALL or HW_ALL,
>>  		 * it is necessary to set T-state for every affected
>>  		 * cpus.
>>  		 */
>> -		for_each_cpu(i, online_throttling_cpus) {
>> +		for_each_cpu_and(i, cpu_online_mask,
>> +		    p_throttling->shared_cpu_map) {
>>  			match_pr = per_cpu(processors, i);
>>  			/*
>>  			 * If the pointer is invalid, we will report the
>> @@ -1153,13 +1155,12 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
>>  					"on CPU %d\n", i));
>>  				continue;
>>  			}
>> -			t_state.cpu = i;
>> -			/* FIXME: use work_on_cpu() */
>> -			if (set_cpus_allowed_ptr(current, cpumask_of(i)))
>> -				continue;
>> -			ret = match_pr->throttling.
>> -				acpi_processor_set_throttling(
>> -				match_pr, t_state.target_state, force);
>> +
>> +			arg.pr = match_pr;
>> +			arg.target_state = state;
>> +			arg.force = force;
>> +			ret = work_on_cpu(pr->id, acpi_processor_throttling_fn,
>> +				&arg);
>>  		}
>>  	}
>>  	/*
>> @@ -1168,17 +1169,12 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
>>  	 * affected cpu to update the T-states.
>>  	 * The notifier event is THROTTLING_POSTCHANGE
>>  	 */
>> -	for_each_cpu(i, online_throttling_cpus) {
>> +	for_each_cpu_and(i, cpu_online_mask, p_throttling->shared_cpu_map) {
>>  		t_state.cpu = i;
>>  		acpi_processor_throttling_notifier(THROTTLING_POSTCHANGE,
>>  							&t_state);
>>  	}
>> -	/* restore the previous state */
>> -	/* FIXME: use work_on_cpu() */
>> -	set_cpus_allowed_ptr(current, saved_mask);
>> -exit:
>> -	free_cpumask_var(online_throttling_cpus);
>> -	free_cpumask_var(saved_mask);
>> +
>>  	return ret;
>>  }
>>  
>>
> 


-- 
Best regards
Tianyu Lan
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: Lan Tianyu <tianyu.lan@intel.com>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: tj@kernel.org, jolsa@redhat.com, oleg@redhat.com,
	lenb@kernel.org, linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ACPI/Processor: Rework processor throttling with work_on_cpu()
Date: Wed, 26 Feb 2014 09:08:46 +0800	[thread overview]
Message-ID: <530D3E9E.7010206@intel.com> (raw)
In-Reply-To: <3890679.FyyHKXfXOb@vostro.rjw.lan>

On 2014年02月26日 09:23, Rafael J. Wysocki wrote:
> On Friday, February 21, 2014 01:35:45 PM Lan Tianyu wrote:
>> acpi_processor_set_throttling() uses set_cpus_allowed_ptr() to make
>> sure struct acpi_processor->acpi_processor_set_throttling() callback
>> run on associated cpu. But the function maybe called in a worker which
>> has been bound to a cpu. The patch is to replace set_cpus_allowed_ptr()
>> with work_on_cpu().
>>
>> Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
>> ---
>>  drivers/acpi/processor_throttling.c | 70 +++++++++++++++++--------------------
>>  1 file changed, 33 insertions(+), 37 deletions(-)
>>
>> diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
>> index 28baa05..2db105a 100644
>> --- a/drivers/acpi/processor_throttling.c
>> +++ b/drivers/acpi/processor_throttling.c
>> @@ -56,6 +56,12 @@ struct throttling_tstate {
>>  	int target_state;		/* target T-state */
>>  };
>>  
>> +struct acpi_processor_throttling_arg {
>> +	struct acpi_processor *pr;
>> +	int target_state;
>> +	bool force;
>> +};
>> +
>>  #define THROTTLING_PRECHANGE       (1)
>>  #define THROTTLING_POSTCHANGE      (2)
>>  
>> @@ -1060,16 +1066,25 @@ static int acpi_processor_set_throttling_ptc(struct acpi_processor *pr,
>>  	return 0;
>>  }
>>  
>> +static long acpi_processor_throttling_fn(void *data)
>> +{
>> +	struct acpi_processor_throttling_arg *arg = data;
>> +	struct acpi_processor *pr = arg->pr;
>> +	struct acpi_processor_throttling *p_throttling = &pr->throttling;
>> +
>> +	return p_throttling->acpi_processor_set_throttling(pr,
>> +			arg->target_state, arg->force);
> 
> What about doing
> 
> 	return pr->throttling.acpi_processor_set_throttling(...);
> 
> directly without using the extra p_throttling pointer?

This is better. I will update soon.

> 
>> +}
>> +
>>  int acpi_processor_set_throttling(struct acpi_processor *pr,
>>  						int state, bool force)
>>  {
>> -	cpumask_var_t saved_mask;
>>  	int ret = 0;
>>  	unsigned int i;
>>  	struct acpi_processor *match_pr;
>>  	struct acpi_processor_throttling *p_throttling;
>> +	struct acpi_processor_throttling_arg arg;
>>  	struct throttling_tstate t_state;
>> -	cpumask_var_t online_throttling_cpus;
>>  
>>  	if (!pr)
>>  		return -EINVAL;
>> @@ -1080,14 +1095,6 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
>>  	if ((state < 0) || (state > (pr->throttling.state_count - 1)))
>>  		return -EINVAL;
>>  
>> -	if (!alloc_cpumask_var(&saved_mask, GFP_KERNEL))
>> -		return -ENOMEM;
>> -
>> -	if (!alloc_cpumask_var(&online_throttling_cpus, GFP_KERNEL)) {
>> -		free_cpumask_var(saved_mask);
>> -		return -ENOMEM;
>> -	}
>> -
>>  	if (cpu_is_offline(pr->id)) {
>>  		/*
>>  		 * the cpu pointed by pr->id is offline. Unnecessary to change
>> @@ -1096,17 +1103,15 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
>>  		return -ENODEV;
>>  	}
>>  
>> -	cpumask_copy(saved_mask, &current->cpus_allowed);
>>  	t_state.target_state = state;
>>  	p_throttling = &(pr->throttling);
>> -	cpumask_and(online_throttling_cpus, cpu_online_mask,
>> -		    p_throttling->shared_cpu_map);
>> +
>>  	/*
>>  	 * The throttling notifier will be called for every
>>  	 * affected cpu in order to get one proper T-state.
>>  	 * The notifier event is THROTTLING_PRECHANGE.
>>  	 */
>> -	for_each_cpu(i, online_throttling_cpus) {
>> +	for_each_cpu_and(i, cpu_online_mask, p_throttling->shared_cpu_map) {
>>  		t_state.cpu = i;
>>  		acpi_processor_throttling_notifier(THROTTLING_PRECHANGE,
>>  							&t_state);
>> @@ -1118,21 +1123,18 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
>>  	 * it can be called only for the cpu pointed by pr.
>>  	 */
>>  	if (p_throttling->shared_type == DOMAIN_COORD_TYPE_SW_ANY) {
>> -		/* FIXME: use work_on_cpu() */
>> -		if (set_cpus_allowed_ptr(current, cpumask_of(pr->id))) {
>> -			/* Can't migrate to the pr->id CPU. Exit */
>> -			ret = -ENODEV;
>> -			goto exit;
>> -		}
>> -		ret = p_throttling->acpi_processor_set_throttling(pr,
>> -						t_state.target_state, force);
>> +		arg.pr = pr;
>> +		arg.target_state = state;
>> +		arg.force = force;
>> +		ret = work_on_cpu(pr->id, acpi_processor_throttling_fn, &arg);
>>  	} else {
>>  		/*
>>  		 * When the T-state coordination is SW_ALL or HW_ALL,
>>  		 * it is necessary to set T-state for every affected
>>  		 * cpus.
>>  		 */
>> -		for_each_cpu(i, online_throttling_cpus) {
>> +		for_each_cpu_and(i, cpu_online_mask,
>> +		    p_throttling->shared_cpu_map) {
>>  			match_pr = per_cpu(processors, i);
>>  			/*
>>  			 * If the pointer is invalid, we will report the
>> @@ -1153,13 +1155,12 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
>>  					"on CPU %d\n", i));
>>  				continue;
>>  			}
>> -			t_state.cpu = i;
>> -			/* FIXME: use work_on_cpu() */
>> -			if (set_cpus_allowed_ptr(current, cpumask_of(i)))
>> -				continue;
>> -			ret = match_pr->throttling.
>> -				acpi_processor_set_throttling(
>> -				match_pr, t_state.target_state, force);
>> +
>> +			arg.pr = match_pr;
>> +			arg.target_state = state;
>> +			arg.force = force;
>> +			ret = work_on_cpu(pr->id, acpi_processor_throttling_fn,
>> +				&arg);
>>  		}
>>  	}
>>  	/*
>> @@ -1168,17 +1169,12 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
>>  	 * affected cpu to update the T-states.
>>  	 * The notifier event is THROTTLING_POSTCHANGE
>>  	 */
>> -	for_each_cpu(i, online_throttling_cpus) {
>> +	for_each_cpu_and(i, cpu_online_mask, p_throttling->shared_cpu_map) {
>>  		t_state.cpu = i;
>>  		acpi_processor_throttling_notifier(THROTTLING_POSTCHANGE,
>>  							&t_state);
>>  	}
>> -	/* restore the previous state */
>> -	/* FIXME: use work_on_cpu() */
>> -	set_cpus_allowed_ptr(current, saved_mask);
>> -exit:
>> -	free_cpumask_var(online_throttling_cpus);
>> -	free_cpumask_var(saved_mask);
>> +
>>  	return ret;
>>  }
>>  
>>
> 


-- 
Best regards
Tianyu Lan

  reply	other threads:[~2014-02-26  1:14 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20140213124059.GA2908@krava.brq.redhat.com>
2014-02-17 17:19 ` WARNING at kernel/workqueue.c:829 wq_worker_waking_up+0x53/0x70() Oleg Nesterov
2014-02-18 22:49   ` Tejun Heo
2014-02-20 13:28     ` Lan Tianyu
2014-02-20 14:31       ` Jiri Olsa
2014-02-20 14:45         ` Lan Tianyu
2014-02-20 14:53           ` Jiri Olsa
2014-02-20 15:13           ` Oleg Nesterov
2014-02-20 15:17             ` Oleg Nesterov
2014-02-21  2:34               ` Lan Tianyu
2014-02-21  5:35               ` [PATCH] ACPI/Processor: Rework processor throttling with work_on_cpu() Lan Tianyu
2014-02-21 10:06                 ` Jiri Olsa
2014-02-21 17:07                   ` Jiri Olsa
2014-02-24  9:27                     ` Lan Tianyu
2014-02-24  9:27                       ` Lan Tianyu
2014-02-26  1:23                 ` Rafael J. Wysocki
2014-02-26  1:08                   ` Lan Tianyu [this message]
2014-02-26  1:08                     ` Lan Tianyu

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=530D3E9E.7010206@intel.com \
    --to=tianyu.lan@intel.com \
    --cc=jolsa@redhat.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=rjw@rjwysocki.net \
    --cc=tj@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.