public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] seq_file: don't call bitmap_scnprintf_len()
@ 2008-10-12  9:29 Lai Jiangshan
  2008-10-13  6:38 ` Alexey Dobriyan
  0 siblings, 1 reply; 4+ messages in thread
From: Lai Jiangshan @ 2008-10-12  9:29 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Alexey Dobriyan, Paul Menage, Paul Jackson,
	Linux Kernel Mailing List


"m->count + len < m->size" is true commonly, so bitmap_scnprintf()
is commonly called. this fix saves a call to bitmap_scnprintf_len().

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/fs/seq_file.c b/fs/seq_file.c
index bd20f7f..11c85fe 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -452,17 +452,18 @@ int seq_dentry(struct seq_file *m, struct dentry *dentry, char *esc)
 
 int seq_bitmap(struct seq_file *m, unsigned long *bits, unsigned int nr_bits)
 {
-	size_t len = bitmap_scnprintf_len(nr_bits);
-
-	if (m->count + len < m->size) {
-		bitmap_scnprintf(m->buf + m->count, m->size - m->count,
-				 bits, nr_bits);
-		m->count += len;
-		return 0;
+	if (m->count < m->size) {
+		int len = bitmap_scnprintf(m->buf + m->count,
+				m->size - m->count, bits, nr_bits);
+		if (m->count + len < m->size) {
+			m->count += len;
+			return 0;
+		}
 	}
 	m->count = m->size;
 	return -1;
 }
+EXPORT_SYMBOL(seq_bitmap);
 
 static void *single_start(struct seq_file *p, loff_t *pos)
 {




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/4] seq_file: don't call bitmap_scnprintf_len()
  2008-10-12  9:29 [PATCH 1/4] seq_file: don't call bitmap_scnprintf_len() Lai Jiangshan
@ 2008-10-13  6:38 ` Alexey Dobriyan
  2008-10-13  7:17   ` Lai Jiangshan
  0 siblings, 1 reply; 4+ messages in thread
From: Alexey Dobriyan @ 2008-10-13  6:38 UTC (permalink / raw)
  To: Lai Jiangshan
  Cc: Andrew Morton, Paul Menage, Paul Jackson,
	Linux Kernel Mailing List

On Sun, Oct 12, 2008 at 05:29:17PM +0800, Lai Jiangshan wrote:
> "m->count + len < m->size" is true commonly, so bitmap_scnprintf()
> is commonly called. this fix saves a call to bitmap_scnprintf_len().

This saves a call if seq buffer is already full which is not a common
situation, so you're optimising for rare situations and adding branch
for common ones.

> --- a/fs/seq_file.c
> +++ b/fs/seq_file.c
> @@ -452,17 +452,18 @@ int seq_dentry(struct seq_file *m, struct dentry *dentry, char *esc)
>  
>  int seq_bitmap(struct seq_file *m, unsigned long *bits, unsigned int nr_bits)
>  {
> -	size_t len = bitmap_scnprintf_len(nr_bits);
> -
> -	if (m->count + len < m->size) {
> -		bitmap_scnprintf(m->buf + m->count, m->size - m->count,
> -				 bits, nr_bits);
> -		m->count += len;
> -		return 0;
> +	if (m->count < m->size) {
> +		int len = bitmap_scnprintf(m->buf + m->count,
> +				m->size - m->count, bits, nr_bits);
> +		if (m->count + len < m->size) {
> +			m->count += len;
> +			return 0;
> +		}
>  	}
>  	m->count = m->size;
>  	return -1;
>  }
> +EXPORT_SYMBOL(seq_bitmap);

Modular users, where are they?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/4] seq_file: don't call bitmap_scnprintf_len()
  2008-10-13  6:38 ` Alexey Dobriyan
@ 2008-10-13  7:17   ` Lai Jiangshan
  2008-10-15  1:35     ` Lai Jiangshan
  0 siblings, 1 reply; 4+ messages in thread
From: Lai Jiangshan @ 2008-10-13  7:17 UTC (permalink / raw)
  To: Alexey Dobriyan
  Cc: Andrew Morton, Paul Menage, Paul Jackson,
	Linux Kernel Mailing List

Alexey Dobriyan wrote:
> On Sun, Oct 12, 2008 at 05:29:17PM +0800, Lai Jiangshan wrote:
>> "m->count + len < m->size" is true commonly, so bitmap_scnprintf()
>> is commonly called. this fix saves a call to bitmap_scnprintf_len().
> 
> This saves a call if seq buffer is already full which is not a common
> situation, so you're optimising for rare situations and adding branch
> for common ones.

Hi Alexey

I think this saves a call if seq buffer is _not_ full after called.

since calling bitmap_scnprintf() is the common situation. so we use
the return value of bitmap_scnprintf() instead of bitmap_scnprintf_len().

In old code bitmap_scnprintf_len() and bitmap_scnprintf() must be called
commonly.

Thanks Lai.

> 
>> --- a/fs/seq_file.c
>> +++ b/fs/seq_file.c
>> @@ -452,17 +452,18 @@ int seq_dentry(struct seq_file *m, struct dentry *dentry, char *esc)
>>  
>>  int seq_bitmap(struct seq_file *m, unsigned long *bits, unsigned int nr_bits)
>>  {
>> -	size_t len = bitmap_scnprintf_len(nr_bits);
>> -
>> -	if (m->count + len < m->size) {
>> -		bitmap_scnprintf(m->buf + m->count, m->size - m->count,
>> -				 bits, nr_bits);
>> -		m->count += len;
>> -		return 0;
>> +	if (m->count < m->size) {
>> +		int len = bitmap_scnprintf(m->buf + m->count,
>> +				m->size - m->count, bits, nr_bits);
>> +		if (m->count + len < m->size) {
>> +			m->count += len;
>> +			return 0;
>> +		}
>>  	}
>>  	m->count = m->size;
>>  	return -1;
>>  }
>> +EXPORT_SYMBOL(seq_bitmap);
> 
> Modular users, where are they?
> 
> 
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/4] seq_file: don't call bitmap_scnprintf_len()
  2008-10-13  7:17   ` Lai Jiangshan
@ 2008-10-15  1:35     ` Lai Jiangshan
  0 siblings, 0 replies; 4+ messages in thread
From: Lai Jiangshan @ 2008-10-15  1:35 UTC (permalink / raw)
  To: Alexey Dobriyan
  Cc: Andrew Morton, Paul Menage, Paul Jackson,
	Linux Kernel Mailing List

Lai Jiangshan wrote:
> Alexey Dobriyan wrote:
>> On Sun, Oct 12, 2008 at 05:29:17PM +0800, Lai Jiangshan wrote:
>>> "m->count + len < m->size" is true commonly, so bitmap_scnprintf()
>>> is commonly called. this fix saves a call to bitmap_scnprintf_len().
>> This saves a call if seq buffer is already full which is not a common
>> situation, so you're optimising for rare situations and adding branch
>> for common ones.
> 
> Hi Alexey
> 
> I think this saves a call if seq buffer is _not_ full after called.
> 
> since calling bitmap_scnprintf() is the common situation. so we use
> the return value of bitmap_scnprintf() instead of bitmap_scnprintf_len().
> 
> In old code bitmap_scnprintf_len() and bitmap_scnprintf() must be called
> commonly.
> 
> Thanks Lai.

Hi, Alexey,

Have noticed this comment? I hold my ground, ;-)
And seq_cpumask_list(), seq_nodemask_list() are needed for print mask
safely, Should I send independent patches for them if we can't
make an agreement about this fix.

Lai

> 
>>> --- a/fs/seq_file.c
>>> +++ b/fs/seq_file.c
>>> @@ -452,17 +452,18 @@ int seq_dentry(struct seq_file *m, struct dentry *dentry, char *esc)
>>>  
>>>  int seq_bitmap(struct seq_file *m, unsigned long *bits, unsigned int nr_bits)
>>>  {
>>> -	size_t len = bitmap_scnprintf_len(nr_bits);
>>> -
>>> -	if (m->count + len < m->size) {
>>> -		bitmap_scnprintf(m->buf + m->count, m->size - m->count,
>>> -				 bits, nr_bits);
>>> -		m->count += len;
>>> -		return 0;
>>> +	if (m->count < m->size) {
>>> +		int len = bitmap_scnprintf(m->buf + m->count,
>>> +				m->size - m->count, bits, nr_bits);
>>> +		if (m->count + len < m->size) {
>>> +			m->count += len;
>>> +			return 0;
>>> +		}
>>>  	}
>>>  	m->count = m->size;
>>>  	return -1;
>>>  }
>>> +EXPORT_SYMBOL(seq_bitmap);
>> Modular users, where are they?
>>
>>
>>
> 
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-10-15  1:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-12  9:29 [PATCH 1/4] seq_file: don't call bitmap_scnprintf_len() Lai Jiangshan
2008-10-13  6:38 ` Alexey Dobriyan
2008-10-13  7:17   ` Lai Jiangshan
2008-10-15  1:35     ` Lai Jiangshan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox