linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yordan Karadzhov <y.karadz@gmail.com>
To: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: Re: [PATCH v2 03/12] libtracefs: New kprobes APIs
Date: Tue, 2 Nov 2021 09:43:16 +0200	[thread overview]
Message-ID: <98a9177a-a255-8d35-a647-943c31c316cd@gmail.com> (raw)
In-Reply-To: <CAPpZLN4iJvmz-_EZV0TY6cGTSDDf=6V7DVPEEUAOaMjsGyaoUA@mail.gmail.com>



On 2.11.21 г. 6:58, Tzvetomir Stoyanov wrote:
> On Mon, Nov 1, 2021 at 7:22 PM Yordan Karadzhov <y.karadz@gmail.com> wrote:
>>
>>
> [ ... ]
>>> +/**
>>> + * tracefs_kprobe_create - Create a kprobe or kretprobe in the system
>>> + * @kprobe: Pointer to a kprobe context, describing the probe
>>> + *
>>> + * Return 0 on success, or -1 on error.
>>> + */
>>> +int tracefs_kprobe_create(struct tracefs_dynevent *kprobe)
>>> +{
>>> +     return dynevent_create(kprobe);
>>> +}
>>> +
>>
>> hmm, what will happen if if you have a code like this:
>>
>>
>> struct tracefs_dynevent *synth = tracefs_synth_alloc(...)
>>
>> int ret = tracefs_kprobe_create(synth);
>>
>>
>> Are you just giving several additional fake names to the same function ('dynevent_create()')?
>>
>>
> 
> Yes, that will work. All dynamic events - kprobes, uprobes, eprobes
> and synthetic events have almost the same configuration logic, which
> is handled by these dynevent_... internal APIs. That makes the code
> more consistent and reusable.
> I see three possible approaches to handle that:
>   1. Create structures like that:
>        struct tracefs_kprobe {
>           struct tracefs_dynevent dynevent;
>        };
>     and use only that type in krpobe specific APIs:
>       int tracefs_kprobe_create(struct tracefs_kprobe *kprobe)
>       {
>           return dynevent_create(&kprobe->dynevent);
>       }
> 
> 2. Expose the dynevent_... APIs directly:
>      struct tracefs_dynevent *synth =
> tracefs_dynevent_alloc(TRACE_DYNEVENT_SYNTH, ...);

I would prefer taking this approach. It is OK to also have several helper constructors like tracefs_kprobe_alloc(), 
tracefs_synth_alloc(), etc. that will call internally dynevent_alloc().

In principle having multiple constructors is OK.


>      struct tracefs_dynevent *kprobe =
> tracefs_dynevent_alloc(TRACE_DYNEVENT_KPROBE, ...);
> 
>      ret = tracefs_dynevent_create(synth);
>      ret = tracefs_dynevent_create(kprobe);
> 

Yes, this is OK as well.

We only have a single type (struct tracefs_dynevent) so there must be a single create. And what is even more important: 
there must be ONLY ONE destructor.

Think about the usecase of the APIs. You create an object using one of the constructors. Later at some point you want to 
use the objects and after this finally you want to destroy it. If we have multiple/specialized "create" and "destroy" 
versions for the same object type, the user must somehow keep its own record of which constructor had been used trough 
the entire live of the object in order to know which is the proper destructor to call at the end.

Thanks!
Yordan


>   The problem here is that there are some small differences between
> dynamic events - some parameters are mandatory for one event and
> optional for another. That can be handled in the
> tracefs_dynevent_alloc() API, but could be confusing for the library
> users.
> 
> 3. Mixed between 1) and 2), the current approach.
> 
> The first one adds a lot of overhead, a different set of APIs for each
> type of dynamic event - but maybe it is more clear for the library
> users. The second is straightforward for implementation, less APIs -
> but that could be confusing for the users.
> 
>>> +/**
>>> + * tracefs_kprobe_free - Free a kprobe context
>>> + * @kprobe: Pointer to a kprobe context
>>> + *
>>> + * The kprobe/kretprobe, described by this context, is not
>>> + * removed from the system by this API. It only frees the memory.
>>> + */
>>> +void tracefs_kprobe_free(struct tracefs_dynevent *kprobe)
>>> +{
>>> +     dynevent_free(kprobe);
>>> +}
>>> +
>>
>> The same argument applys here.
>>
>> Thanks!
>> Yordan
>>
> 
> Thanks for the review!
> 

  reply	other threads:[~2021-11-02  7:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-01  9:08 [PATCH v2 00/12] libtracefs dynamic events support Tzvetomir Stoyanov (VMware)
2021-11-01  9:08 ` [PATCH v2 01/12] libtracefs: Add new internal APIs for dynamic events Tzvetomir Stoyanov (VMware)
2021-11-01 17:06   ` Yordan Karadzhov
2021-11-02  4:33     ` Tzvetomir Stoyanov
2021-11-02 13:25       ` Steven Rostedt
2021-11-01  9:08 ` [PATCH v2 02/12] libtracefs: Rename tracefs_get_kprobes API Tzvetomir Stoyanov (VMware)
2021-11-01  9:08 ` [PATCH v2 03/12] libtracefs: New kprobes APIs Tzvetomir Stoyanov (VMware)
2021-11-01 17:22   ` Yordan Karadzhov
2021-11-02  4:58     ` Tzvetomir Stoyanov
2021-11-02  7:43       ` Yordan Karadzhov [this message]
2021-11-02 13:49         ` Steven Rostedt
2021-11-01  9:08 ` [PATCH v2 04/12] libtracefs: Remove redundant " Tzvetomir Stoyanov (VMware)
2021-11-01  9:08 ` [PATCH v2 05/12] libtracefs: Reimplement tracefs_kprobes_get API Tzvetomir Stoyanov (VMware)
2021-11-01  9:08 ` [PATCH v2 06/12] libtracefs: Change tracefs_kprobe_info API Tzvetomir Stoyanov (VMware)
2021-11-01  9:08 ` [PATCH v2 07/12] libtracefs: Reimplement kprobe raw APIs Tzvetomir Stoyanov (VMware)
2021-11-01  9:09 ` [PATCH v2 08/12] libtracefs: Extend kprobes unit test Tzvetomir Stoyanov (VMware)
2021-11-01  9:09 ` [PATCH v2 09/12] libtracefs: Update kprobes man pages Tzvetomir Stoyanov (VMware)
2021-11-01  9:09 ` [PATCH v2 10/12] libtracefs: Rename tracefs_synth_init API Tzvetomir Stoyanov (VMware)
2021-11-01  9:09 ` [PATCH v2 11/12] libtracefs: Use the internal dynamic events API when creating synthetic events Tzvetomir Stoyanov (VMware)
2021-11-01  9:09 ` [PATCH v2 12/12] libtracefs: Document tracefs_dynevent_list_free() API Tzvetomir Stoyanov (VMware)
2021-11-01 14:21 ` [PATCH v2 00/12] libtracefs dynamic events support Tzvetomir Stoyanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=98a9177a-a255-8d35-a647-943c31c316cd@gmail.com \
    --to=y.karadz@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tz.stoyanov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).