Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1370409 > unrolled thread

Re: [PATCH 2/3] percpu_stats: Simple per-cpu statistics count helper functions

Started byNikolay Borisov <kernel@kyup.com>
First post2016-04-04 09:40 +0200
Last post2016-04-07 00:10 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH 2/3] percpu_stats: Simple per-cpu statistics count helper  functions Nikolay Borisov <kernel@kyup.com> - 2016-04-04 09:40 +0200
    Re: [PATCH 2/3] percpu_stats: Simple per-cpu statistics count helper  functions Waiman Long <waiman.long@hpe.com> - 2016-04-04 19:20 +0200
      Re: [PATCH 2/3] percpu_stats: Simple per-cpu statistics count helper  functions Christoph Lameter <cl@linux.com> - 2016-04-04 21:10 +0200
        Re: [PATCH 2/3] percpu_stats: Simple per-cpu statistics count helper  functions Waiman Long <waiman.long@hpe.com> - 2016-04-07 00:10 +0200

#1370409 — Re: [PATCH 2/3] percpu_stats: Simple per-cpu statistics count helper functions

FromNikolay Borisov <kernel@kyup.com>
Date2016-04-04 09:40 +0200
SubjectRe: [PATCH 2/3] percpu_stats: Simple per-cpu statistics count helper functions
Message-ID<rk7h8-8aW-7@gated-at.bofh.it>

On 04/02/2016 06:09 AM, Waiman Long wrote:
> This patch introduces a set of simple per-cpu statictics count helper
> functions that can be used by other kernel subsystems for keeping
> track of the number of events that happens. It is per-cpu based to
> reduce overhead and improve accuracy of the counter. Using per-cpu
> counter is usually overkill for such purpose.
> 
> The following APIs are provided:
> 
>  - int percpu_stats_init(struct percpu_stats *pcs, int num)
>    Initialize the per-cpu statictics counts structure which should have
>    the given number of statistics counts. Return -ENOMEM on error.
> 
>  - void percpu_stats_destroy(struct percpu_stats *pcs)
>    Free the percpu memory allocated.
> 
>  - void percpu_stats_inc(struct percpu_stats *pcs, int stat)
>    void percpu_stats_dec(struct percpu_stats *pcs, int stat)
>    Increment and decrement the given per-cpu statistics count.
> 
>  - unsigned long percpu_stats_sum(struct percpu_stats *pcs, int stat)
>    Return the current aggregated sum of the given statistics count.
> 
>  - void percpu_stats_reset(struct percpu_stats *pcs)
>    Clear all the statistics counts defined in the given percpu_stats
>    structure.
> 
> Signed-off-by: Waiman Long <Waiman.Long@hpe.com>
> ---
>  include/linux/percpu_stats.h |  103 ++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 103 insertions(+), 0 deletions(-)
>  create mode 100644 include/linux/percpu_stats.h

Just one minor nit below.
[..]
> +static inline void
> +__percpu_stats_add(struct percpu_stats *pcs, int stat, int cnt)
> +{
> +	unsigned long *pstat;
> +
> +	if ((unsigned int)stat >= pcs->nstats)
> +		return;
> +	preempt_disable();
> +	pstat = this_cpu_ptr(&pcs->stats[stat]);
> +	*pstat += cnt;
> +	preempt_enable();
> +}

pstat = get_cpu_ptr(&pcs->stats[stat]);
*pstat += cnt;
put_cpu_ptr(&pcs->stats[stat]);

It will generate identical code but this one uses APIs, making the
intention clearer. But as I said this is just a minor nit.

you can add my Reviewed-by: Nikolay Borisov <kernel@kyup.com> for this
particular patch.

[toc] | [next] | [standalone]


#1370787

FromWaiman Long <waiman.long@hpe.com>
Date2016-04-04 19:20 +0200
Message-ID<rkgkp-6rb-1@gated-at.bofh.it>
In reply to#1370409
On 04/04/2016 03:36 AM, Nikolay Borisov wrote:
>
> On 04/02/2016 06:09 AM, Waiman Long wrote:
>> This patch introduces a set of simple per-cpu statictics count helper
>> functions that can be used by other kernel subsystems for keeping
>> track of the number of events that happens. It is per-cpu based to
>> reduce overhead and improve accuracy of the counter. Using per-cpu
>> counter is usually overkill for such purpose.
>>
>> The following APIs are provided:
>>
>>   - int percpu_stats_init(struct percpu_stats *pcs, int num)
>>     Initialize the per-cpu statictics counts structure which should have
>>     the given number of statistics counts. Return -ENOMEM on error.
>>
>>   - void percpu_stats_destroy(struct percpu_stats *pcs)
>>     Free the percpu memory allocated.
>>
>>   - void percpu_stats_inc(struct percpu_stats *pcs, int stat)
>>     void percpu_stats_dec(struct percpu_stats *pcs, int stat)
>>     Increment and decrement the given per-cpu statistics count.
>>
>>   - unsigned long percpu_stats_sum(struct percpu_stats *pcs, int stat)
>>     Return the current aggregated sum of the given statistics count.
>>
>>   - void percpu_stats_reset(struct percpu_stats *pcs)
>>     Clear all the statistics counts defined in the given percpu_stats
>>     structure.
>>
>> Signed-off-by: Waiman Long<Waiman.Long@hpe.com>
>> ---
>>   include/linux/percpu_stats.h |  103 ++++++++++++++++++++++++++++++++++++++++++
>>   1 files changed, 103 insertions(+), 0 deletions(-)
>>   create mode 100644 include/linux/percpu_stats.h
> Just one minor nit below.
> [..]
>> +static inline void
>> +__percpu_stats_add(struct percpu_stats *pcs, int stat, int cnt)
>> +{
>> +	unsigned long *pstat;
>> +
>> +	if ((unsigned int)stat>= pcs->nstats)
>> +		return;
>> +	preempt_disable();
>> +	pstat = this_cpu_ptr(&pcs->stats[stat]);
>> +	*pstat += cnt;
>> +	preempt_enable();
>> +}
> pstat = get_cpu_ptr(&pcs->stats[stat]);
> *pstat += cnt;
> put_cpu_ptr(&pcs->stats[stat]);
>
> It will generate identical code but this one uses APIs, making the
> intention clearer. But as I said this is just a minor nit.
>
> you can add my Reviewed-by: Nikolay Borisov<kernel@kyup.com>  for this
> particular patch.

Yes, that will certainly make it look nicer. I will update the patch 
once I get feedback from my other ext4 patches.

Cheers,
Longman

[toc] | [prev] | [next] | [standalone]


#1370826

FromChristoph Lameter <cl@linux.com>
Date2016-04-04 21:10 +0200
Message-ID<rki2S-7T9-7@gated-at.bofh.it>
In reply to#1370787
On Mon, 4 Apr 2016, Waiman Long wrote:

> > > +	if ((unsigned int)stat>= pcs->nstats)
> > > +		return;
> > > +	preempt_disable();
> > > +	pstat = this_cpu_ptr(&pcs->stats[stat]);
> > > +	*pstat += cnt;
> > > +	preempt_enable();
> > > +}
> > pstat = get_cpu_ptr(&pcs->stats[stat]);
> > *pstat += cnt;
> > put_cpu_ptr(&pcs->stats[stat]);
> >
> > It will generate identical code but this one uses APIs, making the
> > intention clearer. But as I said this is just a minor nit.
> >
> > you can add my Reviewed-by: Nikolay Borisov<kernel@kyup.com>  for this
> > particular patch.
>
> Yes, that will certainly make it look nicer. I will update the patch once I
> get feedback from my other ext4 patches.

Why not

   this_cpu_add(pci->stats[stat], cnt)

This is a single instruction on x86.

[toc] | [prev] | [next] | [standalone]


#1372890

FromWaiman Long <waiman.long@hpe.com>
Date2016-04-07 00:10 +0200
Message-ID<rl3Ob-2aQ-17@gated-at.bofh.it>
In reply to#1370826
On 04/04/2016 03:09 PM, Christoph Lameter wrote:
> On Mon, 4 Apr 2016, Waiman Long wrote:
>
>>>> +	if ((unsigned int)stat>= pcs->nstats)
>>>> +		return;
>>>> +	preempt_disable();
>>>> +	pstat = this_cpu_ptr(&pcs->stats[stat]);
>>>> +	*pstat += cnt;
>>>> +	preempt_enable();
>>>> +}
>>> pstat = get_cpu_ptr(&pcs->stats[stat]);
>>> *pstat += cnt;
>>> put_cpu_ptr(&pcs->stats[stat]);
>>>
>>> It will generate identical code but this one uses APIs, making the
>>> intention clearer. But as I said this is just a minor nit.
>>>
>>> you can add my Reviewed-by: Nikolay Borisov<kernel@kyup.com>   for this
>>> particular patch.
>> Yes, that will certainly make it look nicer. I will update the patch once I
>> get feedback from my other ext4 patches.
> Why not
>
>     this_cpu_add(pci->stats[stat], cnt)
>
> This is a single instruction on x86.
>

Yes, using this_cpu_add() will be even simpler.

Cheers,
Longman

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web