Peter Zijlstra <pet...@infradead.org> wrote:

> > Please do not _undo_ the changes; just add the API you need.
> 
> add_return and sub_return are horrible interface for refcount, which is
> the problem.
> 
> If you meant: refcount_dec(), but want the old value for tracing, you
> want a different ordering than if you wanted to do
> refcount_dec_and_test(); dec_return can't know this.
> 
> David, would something like a __refcount_*() API work where there is a
> 3rd argument (int *), which, if !NULL, will be assigned the old value?

That would be fine, though the number needs to be something I can interpret
easily when looking through the traces.  It would also be okay if there was an
interpretation function that I could use in the trace point when setting the
variable.

Say:

        void rxrpc_get_call(struct rxrpc_call *call, enum rxrpc_call_trace op)
        {
                const void *here = __builtin_return_address(0);
                unsigned int n;

                refcount_inc_return(&call->usage, &n);

                trace_rxrpc_call(call->debug_id, op, n, here, NULL);
        }

then:

        TRACE_EVENT(rxrpc_call,
                    TP_PROTO(..., int usage, ...),

                    TP_ARGS(...),

                    TP_STRUCT__entry(
                            ...
                            __field(int, usage)
                            ...
                                     ),

                    TP_fast_assign(
                            ...
                            __entry->usage = refcount_interpret(usage);
                            ...
                                   ),

                    TP_printk("... u=%d ...",
                              ...
                              __entry->usage,
                              ...)
                    );

so that it looks like the refcount is 'complete' at 0.

David

Reply via email to