Re: [RFC PATCH v3 1/1] mmap_lock: add tracepoints around mmap_lock acquisition
From: Axel Rasmussen
Date: Thu Jun 25 2020 - 16:26:37 EST
Peter, one additional question for you.
Would you accept this patch if:
- The rwsem.{h,c} and lockdep.h changes were reverted
- It was split up into 2-3 commits
?
Thanks!
On Fri, Jun 19, 2020 at 9:28 AM Axel Rasmussen <axelrasmussen@xxxxxxxxxx> wrote:
>
> On Fri, Jun 19, 2020 at 1:30 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> >
> > On Thu, Jun 18, 2020 at 03:22:25PM -0700, Axel Rasmussen wrote:
> > > diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
> > > index f11b9bd3431d..6aabea1cbc5d 100644
> > > --- a/kernel/locking/rwsem.c
> > > +++ b/kernel/locking/rwsem.c
> > > @@ -1495,6 +1495,20 @@ void __sched down_read(struct rw_semaphore *sem)
> > > }
> > > EXPORT_SYMBOL(down_read);
> > >
> > > +/*
> > > + * lock for reading
> > > + */
> > > +void __sched down_read_contended_hook(struct rw_semaphore *sem,
> > > + void (*pre)(void *),
> > > + void (*post)(void *), void *arg)
> > > +{
> > > + might_sleep();
> > > + rwsem_acquire_read(&sem->dep_map, 0, 0, _RET_IP_);
> > > + LOCK_CONTENDED_HOOK(sem, __down_read_trylock, __down_read, pre, post,
> > > + arg);
> > > +}
> > > +EXPORT_SYMBOL(down_read_contended_hook);
> > > +
> > > int __sched down_read_killable(struct rw_semaphore *sem)
> > > {
> > > might_sleep();
> > > @@ -1509,6 +1523,24 @@ int __sched down_read_killable(struct rw_semaphore *sem)
> > > }
> > > EXPORT_SYMBOL(down_read_killable);
> > >
> > > +int __sched down_read_killable_contended_hook(struct rw_semaphore *sem,
> > > + void (*pre)(void *),
> > > + void (*post)(void *, int),
> > > + void *arg)
> > > +{
> > > + might_sleep();
> > > + rwsem_acquire_read(&sem->dep_map, 0, 0, _RET_IP_);
> > > +
> > > + if (LOCK_CONTENDED_HOOK_RETURN(sem, __down_read_trylock,
> > > + __down_read_killable, pre, post, arg)) {
> > > + rwsem_release(&sem->dep_map, _RET_IP_);
> > > + return -EINTR;
> > > + }
> > > +
> > > + return 0;
> > > +}
> > > +EXPORT_SYMBOL(down_read_killable_contended_hook);
> > > +
> > > /*
> > > * trylock for reading -- returns 1 if successful, 0 if contention
> > > */
> > > @@ -1533,6 +1565,20 @@ void __sched down_write(struct rw_semaphore *sem)
> > > }
> > > EXPORT_SYMBOL(down_write);
> > >
> > > +/*
> > > + * lock for writing
> > > + */
> > > +void __sched down_write_contended_hook(struct rw_semaphore *sem,
> > > + void (*pre)(void *),
> > > + void (*post)(void *), void *arg)
> > > +{
> > > + might_sleep();
> > > + rwsem_acquire(&sem->dep_map, 0, 0, _RET_IP_);
> > > + LOCK_CONTENDED_HOOK(sem, __down_write_trylock, __down_write, pre, post,
> > > + arg);
> > > +}
> > > +EXPORT_SYMBOL(down_write_contended_hook);
> > > +
> > > /*
> > > * lock for writing
> > > */
> > > @@ -1551,6 +1597,24 @@ int __sched down_write_killable(struct rw_semaphore *sem)
> > > }
> > > EXPORT_SYMBOL(down_write_killable);
> > >
> > > +int __sched down_write_killable_contended_hook(struct rw_semaphore *sem,
> > > + void (*pre)(void *),
> > > + void (*post)(void *, int),
> > > + void *arg)
> > > +{
> > > + might_sleep();
> > > + rwsem_acquire_read(&sem->dep_map, 0, 0, _RET_IP_);
> > > +
> > > + if (LOCK_CONTENDED_HOOK_RETURN(sem, __down_write_trylock,
> > > + __down_write_killable, pre, post, arg)) {
> > > + rwsem_release(&sem->dep_map, _RET_IP_);
> > > + return -EINTR;
> > > + }
> > > +
> > > + return 0;
> > > +}
> > > +EXPORT_SYMBOL(down_write_killable_contended_hook);
> > > +
> > > /*
> > > * trylock for writing -- returns 1 if successful, 0 if contention
> > > */
> >
> > NAK, absolutely not going to happen. This is an atrocious API to expose,
> > worse you're exporting.
>
> Ack about splitting this up.
>
> Thanks for taking a look. :)