public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Subhra Mazumdar <subhra.mazumdar@oracle.com>
To: Steven Sistare <steven.sistare@oracle.com>, linux-kernel@vger.kernel.org
Cc: peterz@infradead.org, dhaval.giani@oracle.com
Subject: Re: [RFC PATCH 1/2] pipe: introduce busy wait for pipe
Date: Tue, 4 Sep 2018 17:50:50 -0700	[thread overview]
Message-ID: <575e7d13-98e2-b5bf-e241-3f72a28b8c8a@oracle.com> (raw)
In-Reply-To: <db00b844-055e-2024-2334-8e4b0e0ac5c5@oracle.com>



On 08/31/2018 09:09 AM, Steven Sistare wrote:
> On 8/30/2018 4:24 PM, subhra mazumdar wrote:
>> Introduce pipe_ll_usec field for pipes that indicates the amount of micro
>> seconds a thread should spin if pipe is empty or full before sleeping. This
>> is similar to network sockets. Workloads like hackbench in pipe mode
>> benefits significantly from this by avoiding the sleep and wakeup overhead.
>> Other similar usecases can benefit. pipe_wait_flag is used to signal any
>> thread busy waiting. pipe_busy_loop_timeout checks if spin time is over.
>>
>> Signed-off-by: subhra mazumdar <subhra.mazumdar@oracle.com>
>> ---
>>   include/linux/pipe_fs_i.h | 19 +++++++++++++++++++
>>   1 file changed, 19 insertions(+)
>>
>> diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
>> index e7497c9..fdfd2a2 100644
>> --- a/include/linux/pipe_fs_i.h
>> +++ b/include/linux/pipe_fs_i.h
>> @@ -1,6 +1,8 @@
>>   #ifndef _LINUX_PIPE_FS_I_H
>>   #define _LINUX_PIPE_FS_I_H
>>   
>> +#include <linux/sched/clock.h>
>> +
>>   #define PIPE_DEF_BUFFERS	16
>>   
>>   #define PIPE_BUF_FLAG_LRU	0x01	/* page is on the LRU */
>> @@ -54,6 +56,8 @@ struct pipe_inode_info {
>>   	unsigned int waiting_writers;
>>   	unsigned int r_counter;
>>   	unsigned int w_counter;
>> +	unsigned int pipe_ll_usec;
>> +	unsigned long pipe_wait_flag;
>>   	struct page *tmp_page;
>>   	struct fasync_struct *fasync_readers;
>>   	struct fasync_struct *fasync_writers;
>> @@ -157,6 +161,21 @@ static inline int pipe_buf_steal(struct pipe_inode_info *pipe,
>>   	return buf->ops->steal(pipe, buf);
>>   }
>>   
>> +static inline unsigned long pipe_busy_loop_current_time(void)
>> +{
>> +	return (unsigned long)(local_clock() >> 10);
> Why ">> 10" ? local_lock() has nanosec units, and you compare to the tunable
> pipe_llc_sec which has microsec units.  Should be ">> 3".  Better yet, redefine
> the tunable to have nanosec units.  I suspect you will need very large values
> of the tunable to show similar results.
It's 2^10. I don't think using nanosec units is necessary. It is unlikely
data will be read or written in nano seconds. sk_busy_loop_timeout for
sockets uses micro seconds too.
>
> Also, since this type of optimization consumes CPU extra cycles that could
> be used by other tasks, show the overall CPU utilization before and after
> the optimization, such as by using "time hackbench ...".
OK.

Thanks,
Subhra
>
> - Steve
>
>> +}
>> +
>> +static inline bool pipe_busy_loop_timeout(struct pipe_inode_info *pipe,
>> +					  unsigned long start_time)
>> +{
>> +	unsigned long bp_usec = READ_ONCE(pipe->pipe_ll_usec);
>> +	unsigned long end_time = start_time + bp_usec;
>> +	unsigned long now = pipe_busy_loop_current_time();
>> +
>> +	return time_after(now, end_time);
>> +}
>> +
>>   /* Differs from PIPE_BUF in that PIPE_SIZE is the length of the actual
>>      memory allocation, whereas PIPE_BUF makes atomicity guarantees.  */
>>   #define PIPE_SIZE		PAGE_SIZE
>>


  reply	other threads:[~2018-09-05  0:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-30 20:24 [RFC PATCH 0/2] Pipe busy wait subhra mazumdar
2018-08-30 20:24 ` [RFC PATCH 1/2] pipe: introduce busy wait for pipe subhra mazumdar
2018-08-31 16:09   ` Steven Sistare
2018-09-05  0:50     ` Subhra Mazumdar [this message]
2018-09-05 13:45       ` Steven Sistare
2018-08-30 20:24 ` [RFC PATCH 2/2] pipe: use pipe busy wait subhra mazumdar
2018-09-04 21:54   ` Thomas Gleixner
2018-09-05  0:20     ` Subhra Mazumdar
2018-09-07 12:25   ` Peter Zijlstra
2018-09-17 21:05     ` Subhra Mazumdar
2018-09-17 22:43       ` Peter Zijlstra
2018-09-18  1:07         ` Subhra Mazumdar
2018-08-30 20:48 ` [RFC PATCH 0/2] Pipe " Subhra Mazumdar

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=575e7d13-98e2-b5bf-e241-3f72a28b8c8a@oracle.com \
    --to=subhra.mazumdar@oracle.com \
    --cc=dhaval.giani@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=steven.sistare@oracle.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