On 2023/12/12 1:45, H.J. Lu wrote:
> On Sat, Dec 9, 2023 at 7:25 PM Zhu, Lipeng <lipeng....@intel.com> wrote:
> >
> > On 2023/12/9 23:23, Jakub Jelinek wrote:
> > > On Sat, Dec 09, 2023 at 10:39:45AM -0500, Lipeng Zhu 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
> > > >
> > > > libgcc/ChangeLog:
> > > >
> > > >     * gthr-posix.h (__GTHREAD_RWLOCK_INIT): New macro.
> > > >     (__gthrw): New function.
> > > >     (__gthread_rwlock_rdlock): New function.
> > > >     (__gthread_rwlock_tryrdlock): New function.
> > > >     (__gthread_rwlock_wrlock): New function.
> > > >     (__gthread_rwlock_trywrlock): New function.
> > > >     (__gthread_rwlock_unlock): New function.
> > > >
> > > > libgfortran/ChangeLog:
> > > >
> > > >     * io/async.c (DEBUG_LINE): New macro.
> > > >     * io/async.h (RWLOCK_DEBUG_ADD): New macro.
> > > >     (CHECK_RDLOCK): New macro.
> > > >     (CHECK_WRLOCK): New macro.
> > > >     (TAIL_RWLOCK_DEBUG_QUEUE): New macro.
> > > >     (IN_RWLOCK_DEBUG_QUEUE): New macro.
> > > >     (RDLOCK): New macro.
> > > >     (WRLOCK): New macro.
> > > >     (RWUNLOCK): New macro.
> > > >     (RD_TO_WRLOCK): New macro.
> > > >     (INTERN_RDLOCK): New macro.
> > > >     (INTERN_WRLOCK): New macro.
> > > >     (INTERN_RWUNLOCK): New macro.
> > > >     * io/io.h (struct gfc_unit): Change UNIT_LOCK to UNIT_RWLOCK in
> > > >     a comment.
> > > >     (unit_lock): Remove including associated internal_proto.
> > > >     (unit_rwlock): New declarations including associated internal_proto.
> > > >     (dec_waiting_unlocked): Use WRLOCK and RWUNLOCK on
> unit_rwlock
> > > >     instead of __gthread_mutex_lock and __gthread_mutex_unlock on
> > > >     unit_lock.
> > > >     * io/transfer.c (st_read_done_worker): Use WRLOCK and
> RWUNLOCK
> > > on
> > > >     unit_rwlock instead of LOCK and UNLOCK on unit_lock.
> > > >     (st_write_done_worker): Likewise.
> > > >     * io/unit.c: Change UNIT_LOCK to UNIT_RWLOCK in 'IO locking rules'
> > > >     comment. Use unit_rwlock variable instead of unit_lock variable.
> > > >     (get_gfc_unit_from_unit_root): New function.
> > > >     (get_gfc_unit): Use RDLOCK, WRLOCK and RWUNLOCK on
> unit_rwlock
> > > >     instead of LOCK and UNLOCK on unit_lock.
> > > >     (close_unit_1): Use WRLOCK and RWUNLOCK on unit_rwlock instead
> > > of
> > > >     LOCK and UNLOCK on unit_lock.
> > > >     (close_units): Likewise.
> > > >     (newunit_alloc): Use RWUNLOCK on unit_rwlock instead of UNLOCK
> on
> > > >     unit_lock.
> > > >     * io/unix.c (find_file): Use RDLOCK and RWUNLOCK on unit_rwlock
> > > >     instead of LOCK and UNLOCK on unit_lock.
> > > >     (flush_all_units): Use WRLOCK and RWUNLOCK on unit_rwlock
> instead
> > > >     of LOCK and UNLOCK on unit_lock.
> > >
> > > Ok for trunk, thanks.
> > >
> > >       Jakub
> >
> > Thanks! Looking forward to landing to trunk.
> >
> > Lipeng Zhu
> 
> Pushed for you.
> 
> Thanks.
> 
> --
> H.J.

Thanks for everyone's patience and help, really appreciate that!

Lipeng Zhu

Reply via email to