On Tue, 22 Sep 2020 12:09:19 +0800
Yafang Shao <[email protected]> wrote:
> > > Are there any methods to avoid un-inlining these wrappers ?
> > >
> > > For example,
> > > // include/linux/mmap_lock.h
> > >
> > > void mmap_lock_start_trace_wrapper();
> > > void mmap_lock_acquire_trace_wrapper();
> > >
> > > static inline void mmap_write_lock(struct mm_struct *mm)
> > > {
> > > mmap_lock_start_trace_wrapper();
> > > down_write(&mm->mmap_lock);
> > > mmap_lock_acquire_trace_wrapper();
> > > }
> > >
> > > // mm/mmap_lock.c
> > > void mmap_lock_start_trace_wrapper()
> > > {
> > > trace_mmap_lock_start();
> > > }
> > >
> > > void mmap_lock_start_trace_wrapper()
> > > {
> > > trace_mmap_lock_acquired();
> > > }
> >
> > We can do something like that, but I don't think it would end up being better.
> >
> > At the end of the day, because the trace stuff cannot be in the
> > header, we have to add an extra function call one way or the other.
> > This would just move the call one step further down the call stack.
> > So, I don't think it would affect performance in the
> > CONFIG_MMAP_LOCK_STATS + tracepoints not enabled at runtime case.
> >
>
> Right, it seems we have to add an extra function call.
>
> > Also the wrappers aren't quite so simple as this, they need some
> > parameters to work. (the struct mm_struct, whether it was a read or a
> > write lock, and whether or not the lock operation succeeded), so it
> > would mean adding more inlined code, which I think adds up to be a
> > nontrivial amount since these wrappers are called so often in the
> > kernel.
> >
> > If you feel strongly, let me know and I can send a version as you
> > describe and we can compare the two.
> >
>
> These tracepoints will be less useful if we have to turn on the config
> to enable it.
> I don't mind implementing it that way if we can't optimize it.
>
> Maybe Steven can give some suggestions, Steven ?
>
What you can do, and what we have done is the following:
(see include/linux/page_ref.h)
#ifdef CONFIG_TRACING
extern struct tracepoint __tracepoint_mmap_lock_start_locking;
extern struct tracepoint __tracepoint_mmap_lock_acquire_returned;
#define mmap_lock_tracepoint_active(t) static_key_false(&(__tracepoint_mmap_lock_##t).key)
#else
#define mmap_lock_tracepoint_active(t) false
#endif
static inline void mmap_write_lock(struct mm_struct *mm)
{
if (mmap_lock_tracepoint_active(start_locking))
mmap_lock_start_trace_wrapper();
down_write(&mm->mmap_lock);
if (mmap_lock_tracepoint_active(acquire_returned))
mmap_lock_acquire_trace_wrapper();
}
-- Steve
On Wed, Sep 23, 2020 at 12:51 AM Steven Rostedt <[email protected]> wrote:
>
> On Tue, 22 Sep 2020 12:09:19 +0800
> Yafang Shao <[email protected]> wrote:
>
> > > > Are there any methods to avoid un-inlining these wrappers ?
> > > >
> > > > For example,
> > > > // include/linux/mmap_lock.h
> > > >
> > > > void mmap_lock_start_trace_wrapper();
> > > > void mmap_lock_acquire_trace_wrapper();
> > > >
> > > > static inline void mmap_write_lock(struct mm_struct *mm)
> > > > {
> > > > mmap_lock_start_trace_wrapper();
> > > > down_write(&mm->mmap_lock);
> > > > mmap_lock_acquire_trace_wrapper();
> > > > }
> > > >
> > > > // mm/mmap_lock.c
> > > > void mmap_lock_start_trace_wrapper()
> > > > {
> > > > trace_mmap_lock_start();
> > > > }
> > > >
> > > > void mmap_lock_start_trace_wrapper()
> > > > {
> > > > trace_mmap_lock_acquired();
> > > > }
> > >
> > > We can do something like that, but I don't think it would end up being better.
> > >
> > > At the end of the day, because the trace stuff cannot be in the
> > > header, we have to add an extra function call one way or the other.
> > > This would just move the call one step further down the call stack.
> > > So, I don't think it would affect performance in the
> > > CONFIG_MMAP_LOCK_STATS + tracepoints not enabled at runtime case.
> > >
> >
> > Right, it seems we have to add an extra function call.
> >
> > > Also the wrappers aren't quite so simple as this, they need some
> > > parameters to work. (the struct mm_struct, whether it was a read or a
> > > write lock, and whether or not the lock operation succeeded), so it
> > > would mean adding more inlined code, which I think adds up to be a
> > > nontrivial amount since these wrappers are called so often in the
> > > kernel.
> > >
> > > If you feel strongly, let me know and I can send a version as you
> > > describe and we can compare the two.
> > >
> >
> > These tracepoints will be less useful if we have to turn on the config
> > to enable it.
> > I don't mind implementing it that way if we can't optimize it.
> >
> > Maybe Steven can give some suggestions, Steven ?
> >
>
>
> What you can do, and what we have done is the following:
>
> (see include/linux/page_ref.h)
>
>
> #ifdef CONFIG_TRACING
> extern struct tracepoint __tracepoint_mmap_lock_start_locking;
> extern struct tracepoint __tracepoint_mmap_lock_acquire_returned;
>
> #define mmap_lock_tracepoint_active(t) static_key_false(&(__tracepoint_mmap_lock_##t).key)
>
> #else
> #define mmap_lock_tracepoint_active(t) false
> #endif
>
> static inline void mmap_write_lock(struct mm_struct *mm)
> {
> if (mmap_lock_tracepoint_active(start_locking))
> mmap_lock_start_trace_wrapper();
> down_write(&mm->mmap_lock);
> if (mmap_lock_tracepoint_active(acquire_returned))
> mmap_lock_acquire_trace_wrapper();
> }
>
>
> -- Steve
Great!
Thanks Steve.
--
Thanks
Yafang
On Wed, 23 Sep 2020 18:04:17 +0800
Yafang Shao <[email protected]> wrote:
> > What you can do, and what we have done is the following:
> >
> > (see include/linux/page_ref.h)
> >
> >
> > #ifdef CONFIG_TRACING
> > extern struct tracepoint __tracepoint_mmap_lock_start_locking;
> > extern struct tracepoint __tracepoint_mmap_lock_acquire_returned;
> >
> > #define mmap_lock_tracepoint_active(t) static_key_false(&(__tracepoint_mmap_lock_##t).key)
> >
> > #else
> > #define mmap_lock_tracepoint_active(t) false
> > #endif
> >
> > static inline void mmap_write_lock(struct mm_struct *mm)
> > {
> > if (mmap_lock_tracepoint_active(start_locking))
> > mmap_lock_start_trace_wrapper();
> > down_write(&mm->mmap_lock);
> > if (mmap_lock_tracepoint_active(acquire_returned))
> > mmap_lock_acquire_trace_wrapper();
> > }
> >
> >
> > -- Steve
>
>
> Great!
>
> Thanks Steve.
If the above becomes useful, I may just add helper functions into a
header file that you can include. Perhaps call it: tracepoint_active()
and you need to pass in as an argument the name of the tracepoint.
-- Steve
On Wed, Sep 23, 2020 at 9:09 AM Steven Rostedt <[email protected]> wrote:
>
> On Wed, 23 Sep 2020 18:04:17 +0800
> Yafang Shao <[email protected]> wrote:
>
> > > What you can do, and what we have done is the following:
> > >
> > > (see include/linux/page_ref.h)
> > >
> > >
> > > #ifdef CONFIG_TRACING
> > > extern struct tracepoint __tracepoint_mmap_lock_start_locking;
> > > extern struct tracepoint __tracepoint_mmap_lock_acquire_returned;
> > >
> > > #define mmap_lock_tracepoint_active(t) static_key_false(&(__tracepoint_mmap_lock_##t).key)
> > >
> > > #else
> > > #define mmap_lock_tracepoint_active(t) false
> > > #endif
> > >
> > > static inline void mmap_write_lock(struct mm_struct *mm)
> > > {
> > > if (mmap_lock_tracepoint_active(start_locking))
> > > mmap_lock_start_trace_wrapper();
> > > down_write(&mm->mmap_lock);
> > > if (mmap_lock_tracepoint_active(acquire_returned))
> > > mmap_lock_acquire_trace_wrapper();
> > > }
> > >
> > >
> > > -- Steve
> >
> >
> > Great!
> >
> > Thanks Steve.
>
> If the above becomes useful, I may just add helper functions into a
> header file that you can include. Perhaps call it: tracepoint_active()
> and you need to pass in as an argument the name of the tracepoint.
Thanks for this suggestion Steven, it's working quite well.
I also have a very short patch to the tracing which allows plumbing
the string values through to "just work".
I plan to send out a v2 before the end of the week.
>
> -- Steve
On Thu, Sep 24, 2020 at 12:09 AM Steven Rostedt <[email protected]> wrote:
>
> On Wed, 23 Sep 2020 18:04:17 +0800
> Yafang Shao <[email protected]> wrote:
>
> > > What you can do, and what we have done is the following:
> > >
> > > (see include/linux/page_ref.h)
> > >
> > >
> > > #ifdef CONFIG_TRACING
> > > extern struct tracepoint __tracepoint_mmap_lock_start_locking;
> > > extern struct tracepoint __tracepoint_mmap_lock_acquire_returned;
> > >
> > > #define mmap_lock_tracepoint_active(t) static_key_false(&(__tracepoint_mmap_lock_##t).key)
> > >
> > > #else
> > > #define mmap_lock_tracepoint_active(t) false
> > > #endif
> > >
> > > static inline void mmap_write_lock(struct mm_struct *mm)
> > > {
> > > if (mmap_lock_tracepoint_active(start_locking))
> > > mmap_lock_start_trace_wrapper();
> > > down_write(&mm->mmap_lock);
> > > if (mmap_lock_tracepoint_active(acquire_returned))
> > > mmap_lock_acquire_trace_wrapper();
> > > }
> > >
> > >
> > > -- Steve
> >
> >
> > Great!
> >
> > Thanks Steve.
>
> If the above becomes useful, I may just add helper functions into a
> header file that you can include. Perhaps call it: tracepoint_active()
> and you need to pass in as an argument the name of the tracepoint.
>
Yes, please. The new helper would be useful.
--
Thanks
Yafang