public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH v4] libgfortran: Replace mutex with rwlock
@ 2023-05-09  2:32 Zhu, Lipeng
  2023-05-16  7:08 ` Zhu, Lipeng
  0 siblings, 1 reply; 16+ messages in thread
From: Zhu, Lipeng @ 2023-05-09  2:32 UTC (permalink / raw)
  To: Bernhard Reutner-Fischer
  Cc: fortran, gcc-patches, hongjiu.lu, tianyou.li, pan.deng, wangyang.guo



On 1/1/1970 8:00 AM, Bernhard Reutner-Fischer wrote:
> On Mon,  8 May 2023 17:44:43 +0800
> Lipeng Zhu <lipeng.zhu@intel.com> wrote:
> 
>> This patch try to introduce the rwlock and split the read/write to
>> unit_root tree and unit_cache with rwlock instead of the mutex to
>> increase CPU efficiency. In the get_gfc_unit function, the percentage
>> to step into the insert_unit function is around 30%, in most
>> instances, we can get the unit in the phase of reading the unit_cache
>> or unit_root tree. So split the read/write phase by rwlock would be an
>> approach to make it more parallel.
>>
>> BTW, the IPC metrics can gain around 9x in our test server with 220
>> cores. The benchmark we used is https://github.com/rwesson/NEAT
> 
> See commentary typos below.
> You did not state if you regression tested the patch?
I use valgrind --tool=helgrind or --tool=drd to test 'make 
check-fortran'. Is it necessary to add an additional unit test for this 
patch?

> Other than that it LGTM but i cannot approve it.
Thank you for your kind help for this patch, is there anything that I 
can do or can you help to push this patch forward?

> 
>> diff --git a/libgfortran/io/async.h b/libgfortran/io/async.h index
>> ad226c8e856..0033cc74252 100644
>> --- a/libgfortran/io/async.h
>> +++ b/libgfortran/io/async.h
>> @@ -210,6 +210,128 @@
>>       DEBUG_PRINTF ("%s" DEBUG_RED "ACQ:" DEBUG_NORM " %-30s %78p\n", aio_prefix, #mutex,
> mutex); \
Thanks, corrected in Patch v5.

>>     } while (0)
>>   
>> +#ifdef __GTHREAD_RWLOCK_INIT
>> +#define RWLOCK_DEBUG_ADD(rwlock) do {		\
>> +    aio_rwlock_debug *n;				\
>> +    n = xmalloc (sizeof(aio_rwlock_debug));	\
> 
> Missing space before the open brace: sizeof (
> 
Thanks, corrected in Patch v5.

>> diff --git a/libgfortran/io/unit.c b/libgfortran/io/unit.c index
>> 82664dc5f98..62f1db21d34 100644
>> --- a/libgfortran/io/unit.c
>> +++ b/libgfortran/io/unit.c
>> @@ -33,34 +33,36 @@ see the files COPYING3 and COPYING.RUNTIME
>> respectively.  If not, see
>>   
>>   
>>   /* IO locking rules:
>> -   UNIT_LOCK is a master lock, protecting UNIT_ROOT tree and UNIT_CACHE.
>> +   UNIT_RWLOCK is a master lock, protecting UNIT_ROOT tree and UNIT_CACHE.
>> +   And use the rwlock to spilt read and write phase to UNIT_ROOT tree
>> +   and UNIT_CACHE to increase CPU efficiency.
> 
> s/spilt/split. Maybe:
> 
> Using an rwlock improves efficiency by allowing us to separate readers and writers of both UNIT_ROOT
> and UNIT_CACHE.
> 
Thanks, corrected in Patch v5.

>> @@ -350,6 +356,17 @@ retry:
>>         if (c == 0)
>>   	break;
>>       }
>> +  /* We did not find a unit in the cache nor in the unit list, create a new
>> +    (locked) unit and insert into the unit list and cache.
>> +    Manipulating either or both the unit list and the unit cache requires to
>> +    hold a write-lock [for obvious reasons]:
>> +    1. By separating the read/write lock, it will greatly reduce the contention
>> +       at the read part, while write part is not always necessary or most
>> +       unlikely once the unit hit in cache.
> 
> +    By separating the read/write lock, we will greatly reduce the contention
> +    on the read part, while the write part is unlikely once the unit hits
> +    the cache.
> 
>> +    2. We try to balance the implementation complexity and the performance
>> +       gains that fit into current cases we observed by just using a
>> +       pthread_rwlock. */
> 
> Let's drop 2.

Got it, thanks!
> thanks,

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: [PATCH v4] libgfortran: Replace mutex with rwlock
@ 2023-05-25 12:40 Zhu, Lipeng
  0 siblings, 0 replies; 16+ messages in thread
From: Zhu, Lipeng @ 2023-05-25 12:40 UTC (permalink / raw)
  To: Thomas Koenig
  Cc: fortran, gcc-patches, rep.dot.nop, hongjiu.lu, tianyou.li,
	pan.deng, jakub, wangyang.guo



On 1/1/1970 8:00 AM, Thomas Koenig wrote:
> Hi Lipeng,
> 
>> May I know any comment or concern on this patch, thanks for your time :)
>>
> 
> Thanks for your patience in getting this reviewed.
> 
> A few remarks / questions.
> 
> Which strategy is used in this implementation, read-preferring or write-preferring?  And if read-
> preferring is used, is there a danger of deadlock if people do unreasonable things?
> Maybe you could explain that, also in a comment in the code >
> Can you add some sort of torture test case(s) which does a lot of opening/closing/reading/writing,
> possibly with asynchronous I/O and/or pthreads, to catch possible problems?  If there is a system
> dependency or some race condition, chances are that regression testers will catch this.

Hi Thomas,

Thanks for your time for the review.
Sure, I will add test case according to your suggestions and update the 
comment based on the implementation of "read-preferring" strategy.

Thanks,
Lipeng Zhu
> 
> With this, the libgfortran parts are OK, unless somebody else has more comments, so give this a couple
> of days.  I cannot approve the libgcc parts, that would be somebody else (Jakub?)
> 
> Best regards
> 
> 	Thomas
> 
> 

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

end of thread, other threads:[~2023-12-07  5:18 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20230424214534.77117b73 () nbbrfq>
2023-05-08  9:44 ` [PATCH v4] libgfortran: Replace mutex with rwlock Lipeng Zhu
2023-05-08 10:28   ` Bernhard Reutner-Fischer
2023-05-09  2:32 Zhu, Lipeng
2023-05-16  7:08 ` Zhu, Lipeng
2023-05-23  2:53   ` Zhu, Lipeng
2023-05-24 19:18     ` Thomas Koenig
2023-08-18  3:06       ` Zhu, Lipeng
2023-09-14  8:33         ` Zhu, Lipeng
2023-10-23  1:21           ` Zhu, Lipeng
2023-10-23  5:52             ` Thomas Koenig
2023-10-23 23:59               ` Zhu, Lipeng
2023-11-01 10:14                 ` Zhu, Lipeng
2023-11-02  9:58                   ` Bernhard Reutner-Fischer
2023-11-23  9:36                     ` Zhu, Lipeng
2023-12-07  5:18                       ` Zhu, Lipeng
2023-05-25 12:40 Zhu, Lipeng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).