[ltt-dev] [UST PATCH] New naming convention for macro container_of
Mathieu Desnoyers
compudj at krystal.dyndns.org
Thu Sep 23 13:31:46 EDT 2010
* David Goulet (david.goulet at polymtl.ca) wrote:
>
>
> On 10-09-23 01:07 PM, Mathieu Desnoyers wrote:
>> * David Goulet (david.goulet at polymtl.ca) wrote:
>>> Following this.
>>>
>>> We are talking here about a major overhaul of naming convention. Just
>>> for trace_mark, basically, every symbols in marker.h and following
>>> headers have to be refactor with the __ust_ (or ust_) prefix :
>>>
>>> struct marker --> struct __ust_marker, and so on for types, macros and
>>> functions. This is quite a huge work in term of "syntax changes" and, as
>>> Mathieu pointed out, *long* name. I'm perfectly convince that this is
>>> necessary but if so now, should we than consider removing old LTTng
>>> comments, rename all ltt_* function to ust_*, etc... and so doing a
>>> complete cleanup once and for all ?
>>
>> Yes.
>>
>
> I'll try to put some time on that each file at a time. Good
>
>> Although for the code that is shared between the Linux kernel and UST,
>> (e.g. struct marker), I would be tempted to keep the name as is.
>>
>
> As a funny fact, few months ago, without knowing that much about UST, I
> had a redefinition error on exactly struct marker in one of my program
> that I wanted to trace with UST... It's kind of annoying when you have
> to refactor all your code because of the tracer...
>
> What's the main reason you are tempted to keep the name? (since UST come
> from LTTng, it's easier for porting new feature from ltt to ust...?)
Yep, exactly.
Mathieu
>
> Thanks
> David
>
>> Mathieu
>>
>>>
>>> Cheers
>>> David
>>>
>>> On 10-09-23 12:26 PM, David Goulet wrote:
>>>> This is the first patch introducing the new naming convention
>>>> for the UST tracer. To prevent namespace pollution, __ust_ prefix
>>>> is added to visible symbol in global header files.
>>>>
>>>> For this patch, only the container_of macro is renamed and the
>>>> redundant definition in kcompat/simple.h is removed.
>>>>
>>>> Signed-off-by: David Goulet<david.goulet at polymtl.ca>
>>>> ---
>>>> include/ust/core.h | 2 +-
>>>> include/ust/kcompat/simple.h | 12 ------------
>>>> libust/buffers.c | 6 +++---
>>>> libust/channels.c | 2 +-
>>>> libust/marker.c | 2 +-
>>>> libust/tracepoint.c | 4 ++--
>>>> libust/tracer.c | 2 +-
>>>> 7 files changed, 9 insertions(+), 21 deletions(-)
>>>>
>>>> diff --git a/include/ust/core.h b/include/ust/core.h
>>>> index 0172614..e23224a 100644
>>>> --- a/include/ust/core.h
>>>> +++ b/include/ust/core.h
>>>> @@ -141,7 +141,7 @@ static __inline__ int get_count_order(unsigned int count)
>>>> return order;
>>>> }
>>>>
>>>> -#define container_of(ptr, type, member) ({ \
>>>> +#define __ust_container_of(ptr, type, member) ({ \
>>>> const typeof( ((type *)0)->member ) *__mptr = (ptr); \
>>>> (type *)( (char *)__mptr - offsetof(type,member) );})
>>>>
>>>> diff --git a/include/ust/kcompat/simple.h b/include/ust/kcompat/simple.h
>>>> index 762d802..38a9be5 100644
>>>> --- a/include/ust/kcompat/simple.h
>>>> +++ b/include/ust/kcompat/simple.h
>>>> @@ -21,18 +21,6 @@
>>>> #ifndef KCOMPAT_SIMPLE_H
>>>> #define KCOMPAT_SIMPLE_H
>>>>
>>>> -/**
>>>> - * container_of - cast a member of a structure out to the containing structure
>>>> - * @ptr: the pointer to the member.
>>>> - * @type: the type of the container struct this is embedded in.
>>>> - * @member: the name of the member within the struct.
>>>> - *
>>>> - */
>>>> -#define container_of(ptr, type, member) ({ \
>>>> - const typeof( ((type *)0)->member ) *__mptr = (ptr); \
>>>> - (type *)( (char *)__mptr - offsetof(type,member) );})
>>>> -
>>>> -
>>>> /* libkcompat: from rcupdate.h */
>>>>
>>>> struct rcu_head {
>>>> diff --git a/libust/buffers.c b/libust/buffers.c
>>>> index 374ec61..8a2b90a 100644
>>>> --- a/libust/buffers.c
>>>> +++ b/libust/buffers.c
>>>> @@ -203,7 +203,7 @@ int ust_buffers_create_buf(struct ust_channel *channel, int cpu)
>>>>
>>>> static void ust_buffers_destroy_channel(struct kref *kref)
>>>> {
>>>> - struct ust_channel *chan = container_of(kref, struct ust_channel, kref);
>>>> + struct ust_channel *chan = __ust_container_of(kref, struct ust_channel, kref);
>>>> free(chan);
>>>> }
>>>>
>>>> @@ -225,7 +225,7 @@ static void ust_buffers_destroy_buf(struct ust_buffer *buf)
>>>> /* called from kref_put */
>>>> static void ust_buffers_remove_buf(struct kref *kref)
>>>> {
>>>> - struct ust_buffer *buf = container_of(kref, struct ust_buffer, kref);
>>>> + struct ust_buffer *buf = __ust_container_of(kref, struct ust_buffer, kref);
>>>> ust_buffers_destroy_buf(buf);
>>>> }
>>>>
>>>> @@ -592,7 +592,7 @@ static void ltt_relay_print_buffer_errors(struct ust_channel *channel, int cpu)
>>>>
>>>> static void ltt_relay_release_channel(struct kref *kref)
>>>> {
>>>> - struct ust_channel *ltt_chan = container_of(kref,
>>>> + struct ust_channel *ltt_chan = __ust_container_of(kref,
>>>> struct ust_channel, kref);
>>>> free(ltt_chan->buf);
>>>> }
>>>> diff --git a/libust/channels.c b/libust/channels.c
>>>> index df1a972..4de54a9 100644
>>>> --- a/libust/channels.c
>>>> +++ b/libust/channels.c
>>>> @@ -66,7 +66,7 @@ static struct ltt_channel_setting *lookup_channel(const char *name)
>>>> */
>>>> static void release_channel_setting(struct kref *kref)
>>>> {
>>>> - struct ltt_channel_setting *setting = container_of(kref,
>>>> + struct ltt_channel_setting *setting = __ust_container_of(kref,
>>>> struct ltt_channel_setting, kref);
>>>> struct ltt_channel_setting *iter;
>>>>
>>>> diff --git a/libust/marker.c b/libust/marker.c
>>>> index dbabf3e..761785a 100644
>>>> --- a/libust/marker.c
>>>> +++ b/libust/marker.c
>>>> @@ -235,7 +235,7 @@ static notrace void marker_probe_cb_noarg(const struct marker *mdata,
>>>>
>>>> static void free_old_closure(struct rcu_head *head)
>>>> {
>>>> - struct marker_entry *entry = container_of(head,
>>>> + struct marker_entry *entry = __ust_container_of(head,
>>>> struct marker_entry, rcu);
>>>> free(entry->oldptr);
>>>> /* Make sure we free the data before setting the pending flag to 0 */
>>>> diff --git a/libust/tracepoint.c b/libust/tracepoint.c
>>>> index 16b4819..63ae17d 100644
>>>> --- a/libust/tracepoint.c
>>>> +++ b/libust/tracepoint.c
>>>> @@ -87,7 +87,7 @@ static inline void *allocate_probes(int count)
>>>> static inline void release_probes(void *old)
>>>> {
>>>> if (old) {
>>>> - struct tp_probes *tp_probes = container_of(old,
>>>> + struct tp_probes *tp_probes = __ust_container_of(old,
>>>> struct tp_probes, probes[0]);
>>>> //ust// call_rcu_sched(&tp_probes->u.rcu, rcu_free_old_probes);
>>>> synchronize_rcu();
>>>> @@ -427,7 +427,7 @@ static void tracepoint_add_old_probes(void *old)
>>>> {
>>>> need_update = 1;
>>>> if (old) {
>>>> - struct tp_probes *tp_probes = container_of(old,
>>>> + struct tp_probes *tp_probes = __ust_container_of(old,
>>>> struct tp_probes, probes[0]);
>>>> list_add(&tp_probes->u.list,&old_probes);
>>>> }
>>>> diff --git a/libust/tracer.c b/libust/tracer.c
>>>> index 8c3f774..ed5e329 100644
>>>> --- a/libust/tracer.c
>>>> +++ b/libust/tracer.c
>>>> @@ -337,7 +337,7 @@ void ltt_release_transport(struct kref *kref)
>>>> */
>>>> void ltt_release_trace(struct kref *kref)
>>>> {
>>>> - struct ust_trace *trace = container_of(kref,
>>>> + struct ust_trace *trace = __ust_container_of(kref,
>>>> struct ust_trace, kref);
>>>> ltt_channels_trace_free(trace->channels);
>>>> free(trace);
>>>
>>> --
>>> David Goulet
>>> LTTng project, DORSAL Lab.
>>>
>>> PGP/GPG : 1024D/16BD8563
>>> BE3C 672B 9331 9796 291A 14C6 4AF7 C14B 16BD 8563
>>>
>>> _______________________________________________
>>> ltt-dev mailing list
>>> ltt-dev at lists.casi.polymtl.ca
>>> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
>>>
>>
>
> --
> David Goulet
> LTTng project, DORSAL Lab.
>
> PGP/GPG : 1024D/16BD8563
> BE3C 672B 9331 9796 291A 14C6 4AF7 C14B 16BD 8563
>
--
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
More information about the lttng-dev
mailing list