All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [RFC Patch Ust 2/5] Serialize the CTF global structures for ust-comm
@ 2014-05-02 13:40 Thibault, Daniel
  0 siblings, 0 replies; 7+ messages in thread
From: Thibault, Daniel @ 2014-05-02 13:40 UTC (permalink / raw)
  To: lttng-dev

----------------------------------------------------------------------
> Date: Fri, 2 May 2014 09:29:09 +0000 (UTC)
> From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> To: Geneviève Bastien <gbastien+lttng@versatic.net>

> Yes, all this is about not repeating global type descriptions over the Unix socket between applications and session daemon.
>
> The issue here is that with the current approach, we have to repeat possibly very long descriptions of structures, variants, and enums because they need to be bundled after every event description.
>
> Here is what I would envision instead:
>
> - We add a "global type" notifier to the UST notifiers (there is currently only "event" and "channel"). Those notifiers are sending the descriptions
>   of channels and events as seen from within the application to lttng-sessiond, so it can put it in its ust registry to later generate
>   the metadata.
> - Those notifiers can be used to send descriptions of enums, structs, and variants.
> - We'll probably want to have some way of verifying if the global type is exactly the same as global types with the same provider and
>   global type names registered previously, thus dealing with different provider .so versions, each containing different versions of the global
>   type. We'll have to find out what's the behaviour when this check does not succeed (failure or versioning of the global type within sessiond ?).
>   This verification will be needed once per global type, per application process. This verification needs to be done by sending the provider and
>   global type name, along with the global type details (to see if it matches).
> - Per global type, per application, we can keep a flag that knows whether the global type description has been successfully sent to the session
>   daemon for each session.

   I'd strongly advise to go the versioning way rather than the failure way (although failure is easier to implement initially).  The verification needs to be done more often than "once per global type, per application process": one use case is a process that dynamically loads (dlopen) an instrumented .so, generates events with it for a while, then unloads it (dlclose) and loads another .so that happens to include a provider with the same signature but different event payloads.  The process may or may not wholly unregister from and re-register with the session manager, depending on whether or not it has other providers loaded.

   See the closely related bugs #561, #698, #720.

   If the bandwidth used in sending lengthy type descriptions for mere verification is a concern, maybe the conversation between the app tracepoint provider and session manager could start by sending an MD5 or SHA hash of the type description.  Only when those mismatch would the full type description need to be sent.

   Also note that event type verification can be "lazy" (or "delayed") and occur only when the event type in question is actually enabled or emitted.  There isn't much point to updating the trace metadata with changing event types if the events in question are not enabled (at the channel or event level).  On the other hand, sending a filter specification to a provider pretty much requires event type verification, if only to warn the user that the filter he specified for the event won't be understood by the provider.

Daniel U. Thibault
Protection des systèmes et contremesures (PSC) | Systems Protection & Countermeasures (SPC)
Cyber sécurité pour les missions essentielles (CME) | Mission Critical Cyber Security (MCCS)
R & D pour la défense Canada - Valcartier (RDDC Valcartier) | Defence R&D Canada - Valcartier (DRDC Valcartier)
2459 route de la Bravoure
Québec QC  G3J 1X5
CANADA
Vox : (418) 844-4000 x4245
Fax : (418) 844-4538
NAC : 918V QSDJ <http://www.travelgis.com/map.asp?addr=918V%20QSDJ>
Gouvernement du Canada | Government of Canada
<http://www.valcartier.drdc-rddc.gc.ca/>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC Patch Ust 2/5] Serialize the CTF global structures for ust-comm
       [not found]         ` <53619DDF.5060909@versatic.net>
@ 2014-05-02  9:29           ` Mathieu Desnoyers
  0 siblings, 0 replies; 7+ messages in thread
From: Mathieu Desnoyers @ 2014-05-02  9:29 UTC (permalink / raw)
  To: Geneviève Bastien; +Cc: lttng-dev

----- Original Message -----
> From: "Geneviève Bastien" <gbastien+lttng@versatic.net>
> To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>
> Cc: lttng-dev@lists.lttng.org
> Sent: Wednesday, April 30, 2014 9:05:35 PM
> Subject: Re: [lttng-dev] [RFC Patch Ust 2/5] Serialize the CTF global structures for ust-comm
> 
> On 14-04-27 04:34 AM, Mathieu Desnoyers wrote:
> > ----- Original Message -----
> >> From: "Geneviève Bastien" <gbastien+lttng@versatic.net>
> >> To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>
> >> Cc: lttng-dev@lists.lttng.org
> >> Sent: Wednesday, April 9, 2014 7:33:06 PM
> >> Subject: Re: [lttng-dev] [RFC Patch Ust 2/5] Serialize the CTF global
> >> structures for ust-comm
> >>
> >> On 04/09/2014 11:42 AM, Mathieu Desnoyers wrote:
> >>> ----- Original Message -----
> >>>> From: "Geneviève Bastien" <gbastien+lttng@versatic.net>
> >>>> To: lttng-dev@lists.lttng.org
> >>>> Sent: Wednesday, March 26, 2014 10:47:09 AM
> >>>> Subject: [lttng-dev] [RFC Patch Ust 2/5] Serialize the CTF global
> >>>> structures	for ust-comm
> >>>>
> >>>> It flatten the global types so that global types used by other global
> >>>> types
> >>> flatten -> flattens
> >>>
> >>>> all belong to the event at serialization. This avoids recursive calls to
> >>>> the
> >>>> send and receive functions and simplifies error handling (no recursive
> >>>> frees).
> >>> Is the structure and enum part of the event, or declared outside of
> >>> the event scope ?
> >> They are named structures so declared outside the scope of the event.
> >> But they are sent only if one event needs them.
> >>> Is there a downside to this approach ? For instance, if the same
> >>> structure is used in many events, do we have to send the structure info
> >>> many times ?
> >> Sending each structure (and enum) once would be enough, we could keep a
> >> hash table of global types that were sent, like we do before dumping the
> >> metadata of those global types, and that would avoid sending them many
> >> times. But it is not what is being done right now. We just send all the
> >> global types, but they are added to the metadata only once.
> > Repeating the integers, strings, etc on the "wire" (unix socket) for
> > every field between UST and sessiond was not so bad, since they were
> > small enough descriptions.
> >
> > However, I figure that enumerations, structures and variant types will
> > grow to be much larger than their basic types counterparts.
> >
> > Therefore, sending the global type separately, and then sending a
> > reference to that type (a string) when encountering the event field
> > using this global type seems like a more scalable solution to me.
> Just to be clear. Your comment is about the number of times a global
> type is sent across the wire, not the way it is sent in the current
> implementation (an event is followed by the global types it uses)? So
> that event1 which uses struct1 will have 1 global type following it and
> later on, when event2 using also struct1 is sent, then it will have 0
> global types, right?

Yes, all this is about not repeating global type descriptions over the
unix socket between applications and session daemon.

The issue here is that with the current approach, we have to repeat
possibly very long descriptions of structures, variants, and enums
because they need to be bundled after every event description.

Here is what I would envision instead:

- We add a "global type" notifier to the UST notfiers (there is currently
  only "event" and "channel"). Those notifier are sending the descriptions
  of channels and events as seen from within the application to
  lttng-sessiond, so it can put it in its ust registry to later generate
  the metadata,
- Those notifiers can be used to send descriptions of enums, structs, and
  variants,
- We'll probably want to have some way of verifying if the global
  type is exactly the same as global types with the same provider and
  global type names registered previously, thus dealing with different
  provider .so versions, each containing different versions of the global
  type. We'll have to find out what's the behavior when this check does
  not succeed (failure or versioning of the global type within sessiond ?).
  This verification will be needed once per global type, per application
  process. This verification needs to be done by sending the provider and
  global type name, along with the global type details (to see if it
  matches).
- Per global type, per application, we can keep a flag that knows whether
  the global type description has been successfully sent to the session
  daemon for each session.

Thanks,

Mathieu

> 
> I'll see what I can do, probably something similar to what is done for
> the events.
> 
> Thanks,
> 
> Geneviève
> >
> > Thanks,
> >
> > Mathieu
> >
> >> Thanks,
> >> Geneviève
> >>> Thanks,
> >>>
> >>> Mathieu
> >>>
> >>>> Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
> >>>> ---
> >>>>    liblttng-ust-comm/lttng-ust-comm.c | 170
> >>>>    +++++++++++++++++++++++++++++++++----
> >>>>    liblttng-ust-ctl/ustctl.c          |  26 ++++++
> >>>>    2 files changed, 179 insertions(+), 17 deletions(-)
> >>>>
> >>>> diff --git a/liblttng-ust-comm/lttng-ust-comm.c
> >>>> b/liblttng-ust-comm/lttng-ust-comm.c
> >>>> index bc22130..90274c4 100644
> >>>> --- a/liblttng-ust-comm/lttng-ust-comm.c
> >>>> +++ b/liblttng-ust-comm/lttng-ust-comm.c
> >>>> @@ -742,6 +742,7 @@ int serialize_basic_type(enum ustctl_abstract_types
> >>>> *uatype,
> >>>>    	}
> >>>>    	case atype_array:
> >>>>    	case atype_sequence:
> >>>> +	case atype_structure:
> >>>>    	default:
> >>>>    		return -EINVAL;
> >>>>    	}
> >>>> @@ -800,6 +801,14 @@ int serialize_one_type(struct ustctl_type *ut,
> >>>> const
> >>>> struct lttng_type *lt)
> >>>>    		ut->atype = ustctl_atype_sequence;
> >>>>    		break;
> >>>>    	}
> >>>> +	case atype_structure:
> >>>> +	{
> >>>> +		strncpy(ut->u.structure.name, lt->u.structure.name,
> >>>> +						LTTNG_UST_SYM_NAME_LEN);
> >>>> +		ut->u.structure.name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
> >>>> +		ut->atype = ustctl_atype_structure;
> >>>> +		break;
> >>>> +	}
> >>>>    	default:
> >>>>    		return -EINVAL;
> >>>>    	}
> >>>> @@ -892,25 +901,82 @@ int serialize_enum(struct ustctl_enum *uenum,
> >>>>    }
> >>>>    
> >>>>    static
> >>>> -int serialize_global_type_decl(size_t *_nr_write_global_type_decl,
> >>>> -		struct ustctl_global_type_decl **ustctl_global_type,
> >>>> +int serialize_structure(struct ustctl_structure *ustruct,
> >>>> +		const struct lttng_structure *lstruct)
> >>>> +{
> >>>> +	int ret;
> >>>> +
> >>>> +	strncpy(ustruct->name, lstruct->name, LTTNG_UST_SYM_NAME_LEN);
> >>>> +	ustruct->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
> >>>> +
> >>>> +	/* Serialize the fields */
> >>>> +	if (lstruct->nr_fields > 0) {
> >>>> +		ret = serialize_fields(&ustruct->nr_fields, &ustruct->fields,
> >>>> +				lstruct->nr_fields,	lstruct->fields);
> >>>> +		if (ret) {
> >>>> +			return ret;
> >>>> +		}
> >>>> +	}
> >>>> +
> >>>> +	return 0;
> >>>> +}
> >>>> +
> >>>> +static size_t get_child_global_type_count(size_t nr_global_type_decl,
> >>>> +		const struct lttng_global_type_decl *lttng_global_type)
> >>>> +{
> >>>> +	size_t total_global_types = 0;
> >>>> +	int i;
> >>>> +	const struct lttng_global_type_decl *lg;
> >>>> +
> >>>> +	for (i = 0; i < nr_global_type_decl; i++) {
> >>>> +		lg = &lttng_global_type[i];
> >>>> +
> >>>> +		if (lg->nowrite)
> >>>> +			continue;
> >>>> +
> >>>> +		/* Count the global types in children as well */
> >>>> +		switch (lg->mtype) {
> >>>> +		case mtype_structure:
> >>>> +		{
> >>>> +			const struct lttng_structure *ls;
> >>>> +
> >>>> +			ls = lg->u.ctf_structure;
> >>>> +			/* Add the number of global types it contains and the count of its
> >>>> own
> >>>> children */
> >>>> +			if (ls->nr_global_type_decl > 0) {
> >>>> +				total_global_types += ls->nr_global_type_decl;
> >>>> +				total_global_types +=
> >>>> get_child_global_type_count(ls->nr_global_type_decl,
> >>>> +								ls->global_type_decl);
> >>>> +			}
> >>>> +			break;
> >>>> +		}
> >>>> +		case mtype_enum:
> >>>> +		default:
> >>>> +			break;
> >>>> +		}
> >>>> +	}
> >>>> +
> >>>> +	return total_global_types;
> >>>> +}
> >>>> +
> >>>> +/*
> >>>> + * When this method is called, index is the next index to write to and
> >>>> the
> >>>> + * ustctl_global_type structure is already initialized and will not
> >>>> overflow.
> >>>> + *
> >>>> + * The global type declarations are flattened at serialization to avoid
> >>>> + * needing to do recursive frees on error.
> >>>> + */
> >>>> +static int _serialize_global_type_decl(size_t *index,
> >>>> +		struct ustctl_global_type_decl *global_type_decl,
> >>>>    		size_t nr_global_type_decl,
> >>>>    		const struct lttng_global_type_decl *lttng_global_type)
> >>>>    {
> >>>> -	struct ustctl_global_type_decl *global_type_decl;
> >>>>    	int i, ret;
> >>>> -	size_t nr_write_global_type_decl = 0;
> >>>> -
> >>>> -	global_type_decl = zmalloc(nr_global_type_decl
> >>>> -					* sizeof(*global_type_decl));
> >>>> -	if (!global_type_decl)
> >>>> -		return -ENOMEM;
> >>>>    
> >>>>    	for (i = 0; i < nr_global_type_decl; i++) {
> >>>>    		struct ustctl_global_type_decl *f;
> >>>>    		const struct lttng_global_type_decl *lf;
> >>>>    
> >>>> -		f = &global_type_decl[nr_write_global_type_decl];
> >>>> +		f = &global_type_decl[*index];
> >>>>    		lf = &lttng_global_type[i];
> >>>>    
> >>>>    		/* skip 'nowrite' fields */
> >>>> @@ -928,18 +994,66 @@ int serialize_global_type_decl(size_t
> >>>> *_nr_write_global_type_decl,
> >>>>    			le = lf->u.ctf_enum;
> >>>>    			ret = serialize_enum(ue, le);
> >>>>    			if (ret)
> >>>> -				goto error;
> >>>> +				return ret;
> >>>>    
> >>>>    			f->mtype = ustctl_mtype_enum;
> >>>>    			break;
> >>>>    		}
> >>>> +		case mtype_structure:
> >>>> +		{
> >>>> +			struct ustctl_structure *us;
> >>>> +			const struct lttng_structure *ls;
> >>>> +
> >>>> +			/* Serialize children global types first */
> >>>> +			ls = lf->u.ctf_structure;
> >>>> +			ret = _serialize_global_type_decl(index,
> >>>> +					global_type_decl,
> >>>> +					ls->nr_global_type_decl,
> >>>> +					ls->global_type_decl);
> >>>> +			if (ret)
> >>>> +				return ret;
> >>>> +
> >>>> +			/* Reinitialize f since the index may have changed */
> >>>> +			f = &global_type_decl[*index];
> >>>> +			us = &f->u.ctf_structure;
> >>>> +
> >>>> +			ret = serialize_structure(us, ls);
> >>>> +			if (ret)
> >>>> +				return ret;
> >>>> +
> >>>> +			f->mtype = ustctl_mtype_structure;
> >>>> +			break;
> >>>> +		}
> >>>>    		default:
> >>>> -			ret = -EINVAL;
> >>>> -			goto error;
> >>>> +			return -EINVAL;
> >>>>    		}
> >>>>    
> >>>> -		nr_write_global_type_decl++;
> >>>> +		*index = *index + 1;
> >>>>    	}
> >>>> +	return 0;
> >>>> +}
> >>>> +
> >>>> +static
> >>>> +int serialize_global_type_decl(size_t *_nr_write_global_type_decl,
> >>>> +		struct ustctl_global_type_decl **ustctl_global_type,
> >>>> +		size_t nr_global_type_decl,
> >>>> +		const struct lttng_global_type_decl *lttng_global_type)
> >>>> +{
> >>>> +	struct ustctl_global_type_decl *global_type_decl;
> >>>> +	int i, ret;
> >>>> +	size_t nr_write_global_type_decl = 0;
> >>>> +	size_t nr_child_global_type_cnt =
> >>>> get_child_global_type_count(nr_global_type_decl,
> >>>> +							lttng_global_type);
> >>>> +
> >>>> +	global_type_decl = zmalloc((nr_global_type_decl +
> >>>> nr_child_global_type_cnt)
> >>>> +					* sizeof(*global_type_decl));
> >>>> +	if (!global_type_decl)
> >>>> +		return -ENOMEM;
> >>>> +
> >>>> +	ret = _serialize_global_type_decl(&nr_write_global_type_decl,
> >>>> global_type_decl,
> >>>> +			nr_global_type_decl, lttng_global_type);
> >>>> +	if (ret)
> >>>> +		goto error;
> >>>>    
> >>>>    	*_nr_write_global_type_decl = nr_write_global_type_decl;
> >>>>    	*ustctl_global_type = global_type_decl;
> >>>> @@ -954,6 +1068,9 @@ error:
> >>>>    		case ustctl_mtype_enum:
> >>>>    			free(m->u.ctf_enum.entries);
> >>>>    			break;
> >>>> +		case ustctl_mtype_structure:
> >>>> +			free(m->u.ctf_structure.fields);
> >>>> +			break;
> >>>>    		default:
> >>>>    			break;
> >>>>    		}
> >>>> @@ -1158,15 +1275,31 @@ int ustcomm_register_event(int sock,
> >>>>    				}
> >>>>    				break;
> >>>>    			}
> >>>> +			case ustctl_mtype_structure:
> >>>> +			{
> >>>> +				int field_len = one_global_type->u.ctf_structure.nr_fields *
> >>>> sizeof(*one_global_type->u.ctf_structure.fields);
> >>>> +
> >>>> +				/* Send the fields */
> >>>> +				DBG("Sending fields for global type structure %s.\n",
> >>>> +						one_global_type->u.ctf_structure.name);
> >>>> +				len = ustcomm_send_unix_sock(sock,
> >>>> one_global_type->u.ctf_structure.fields, field_len);
> >>>> +				free(one_global_type->u.ctf_structure.fields);
> >>>> +				one_global_type->u.ctf_structure.fields = NULL;
> >>>> +				if (len > 0 && len != field_len) {
> >>>> +					goto error_global_type;
> >>>> +				}
> >>>> +				if (len < 0) {
> >>>> +					goto error_global_type;
> >>>> +				}
> >>>> +				break;
> >>>> +			}
> >>>>    			default:
> >>>>    				break;
> >>>>    			}
> >>>>    		}
> >>>> -		free(global_type_decl);
> >>>>    
> >>>> -	} else {
> >>>> -		free(global_type_decl);
> >>>>    	}
> >>>> +	free(global_type_decl);
> >>>>    
> >>>>    	/* receive reply */
> >>>>    	len = ustcomm_recv_unix_sock(sock, &reply, sizeof(reply));
> >>>> @@ -1212,6 +1345,9 @@ error_global_type:
> >>>>    		case ustctl_mtype_enum:
> >>>>    			free(one_global_type->u.ctf_enum.entries);
> >>>>    			break;
> >>>> +		case ustctl_mtype_structure:
> >>>> +			free(one_global_type->u.ctf_structure.fields);
> >>>> +			break;
> >>>>    		default:
> >>>>    			break;
> >>>>    		}
> >>>> diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c
> >>>> index a181e62..3100f1b 100644
> >>>> --- a/liblttng-ust-ctl/ustctl.c
> >>>> +++ b/liblttng-ust-ctl/ustctl.c
> >>>> @@ -1896,6 +1896,32 @@ int ustctl_recv_register_event(int sock,
> >>>>    				}
> >>>>    				break;
> >>>>    			}
> >>>> +			case ustctl_mtype_structure:
> >>>> +			{
> >>>> +				int entry_len = one_global_type->u.ctf_structure.nr_fields *
> >>>> sizeof(*one_global_type->u.ctf_structure.fields);
> >>>> +				/* Receive the entries */
> >>>> +				one_global_type->u.ctf_structure.fields = zmalloc(entry_len);
> >>>> +				if (!one_global_type->u.ctf_structure.fields) {
> >>>> +					len = -ENOMEM;
> >>>> +					goto global_type_error;
> >>>> +				}
> >>>> +				len = ustcomm_recv_unix_sock(sock,
> >>>> +						one_global_type->u.ctf_structure.fields,
> >>>> +						entry_len);
> >>>> +				DBG("Received fields for struct %s.\n",
> >>>> one_global_type->u.ctf_structure.name);
> >>>> +				if (len > 0 && len != entry_len) {
> >>>> +					len = -EIO;
> >>>> +					goto global_type_error;
> >>>> +				}
> >>>> +				if (len == 0) {
> >>>> +					len = -EPIPE;
> >>>> +					goto global_type_error;
> >>>> +				}
> >>>> +				if (len < 0) {
> >>>> +					goto global_type_error;
> >>>> +				}
> >>>> +				break;
> >>>> +			}
> >>>>    			default:
> >>>>    				break;
> >>>>    			}
> >>>> --
> >>>> 1.9.1
> >>>>
> >>>>
> >>>> _______________________________________________
> >>>> lttng-dev mailing list
> >>>> lttng-dev@lists.lttng.org
> >>>> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
> >>>>
> >>
> 
> 

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC Patch Ust 2/5] Serialize the CTF global structures for ust-comm
       [not found]       ` <2087397408.8083.1398587642565.JavaMail.zimbra@efficios.com>
@ 2014-05-01  1:05         ` Geneviève Bastien
       [not found]         ` <53619DDF.5060909@versatic.net>
  1 sibling, 0 replies; 7+ messages in thread
From: Geneviève Bastien @ 2014-05-01  1:05 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: lttng-dev

On 14-04-27 04:34 AM, Mathieu Desnoyers wrote:
> ----- Original Message -----
>> From: "Geneviève Bastien" <gbastien+lttng@versatic.net>
>> To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>
>> Cc: lttng-dev@lists.lttng.org
>> Sent: Wednesday, April 9, 2014 7:33:06 PM
>> Subject: Re: [lttng-dev] [RFC Patch Ust 2/5] Serialize the CTF global structures for ust-comm
>>
>> On 04/09/2014 11:42 AM, Mathieu Desnoyers wrote:
>>> ----- Original Message -----
>>>> From: "Geneviève Bastien" <gbastien+lttng@versatic.net>
>>>> To: lttng-dev@lists.lttng.org
>>>> Sent: Wednesday, March 26, 2014 10:47:09 AM
>>>> Subject: [lttng-dev] [RFC Patch Ust 2/5] Serialize the CTF global
>>>> structures	for ust-comm
>>>>
>>>> It flatten the global types so that global types used by other global
>>>> types
>>> flatten -> flattens
>>>
>>>> all belong to the event at serialization. This avoids recursive calls to
>>>> the
>>>> send and receive functions and simplifies error handling (no recursive
>>>> frees).
>>> Is the structure and enum part of the event, or declared outside of
>>> the event scope ?
>> They are named structures so declared outside the scope of the event.
>> But they are sent only if one event needs them.
>>> Is there a downside to this approach ? For instance, if the same
>>> structure is used in many events, do we have to send the structure info
>>> many times ?
>> Sending each structure (and enum) once would be enough, we could keep a
>> hash table of global types that were sent, like we do before dumping the
>> metadata of those global types, and that would avoid sending them many
>> times. But it is not what is being done right now. We just send all the
>> global types, but they are added to the metadata only once.
> Repeating the integers, strings, etc on the "wire" (unix socket) for
> every field between UST and sessiond was not so bad, since they were
> small enough descriptions.
>
> However, I figure that enumerations, structures and variant types will
> grow to be much larger than their basic types counterparts.
>
> Therefore, sending the global type separately, and then sending a
> reference to that type (a string) when encountering the event field
> using this global type seems like a more scalable solution to me.
Just to be clear. Your comment is about the number of times a global 
type is sent across the wire, not the way it is sent in the current 
implementation (an event is followed by the global types it uses)? So 
that event1 which uses struct1 will have 1 global type following it and 
later on, when event2 using also struct1 is sent, then it will have 0 
global types, right?

I'll see what I can do, probably something similar to what is done for 
the events.

Thanks,

Geneviève
>
> Thanks,
>
> Mathieu
>
>> Thanks,
>> Geneviève
>>> Thanks,
>>>
>>> Mathieu
>>>
>>>> Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
>>>> ---
>>>>    liblttng-ust-comm/lttng-ust-comm.c | 170
>>>>    +++++++++++++++++++++++++++++++++----
>>>>    liblttng-ust-ctl/ustctl.c          |  26 ++++++
>>>>    2 files changed, 179 insertions(+), 17 deletions(-)
>>>>
>>>> diff --git a/liblttng-ust-comm/lttng-ust-comm.c
>>>> b/liblttng-ust-comm/lttng-ust-comm.c
>>>> index bc22130..90274c4 100644
>>>> --- a/liblttng-ust-comm/lttng-ust-comm.c
>>>> +++ b/liblttng-ust-comm/lttng-ust-comm.c
>>>> @@ -742,6 +742,7 @@ int serialize_basic_type(enum ustctl_abstract_types
>>>> *uatype,
>>>>    	}
>>>>    	case atype_array:
>>>>    	case atype_sequence:
>>>> +	case atype_structure:
>>>>    	default:
>>>>    		return -EINVAL;
>>>>    	}
>>>> @@ -800,6 +801,14 @@ int serialize_one_type(struct ustctl_type *ut, const
>>>> struct lttng_type *lt)
>>>>    		ut->atype = ustctl_atype_sequence;
>>>>    		break;
>>>>    	}
>>>> +	case atype_structure:
>>>> +	{
>>>> +		strncpy(ut->u.structure.name, lt->u.structure.name,
>>>> +						LTTNG_UST_SYM_NAME_LEN);
>>>> +		ut->u.structure.name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
>>>> +		ut->atype = ustctl_atype_structure;
>>>> +		break;
>>>> +	}
>>>>    	default:
>>>>    		return -EINVAL;
>>>>    	}
>>>> @@ -892,25 +901,82 @@ int serialize_enum(struct ustctl_enum *uenum,
>>>>    }
>>>>    
>>>>    static
>>>> -int serialize_global_type_decl(size_t *_nr_write_global_type_decl,
>>>> -		struct ustctl_global_type_decl **ustctl_global_type,
>>>> +int serialize_structure(struct ustctl_structure *ustruct,
>>>> +		const struct lttng_structure *lstruct)
>>>> +{
>>>> +	int ret;
>>>> +
>>>> +	strncpy(ustruct->name, lstruct->name, LTTNG_UST_SYM_NAME_LEN);
>>>> +	ustruct->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
>>>> +
>>>> +	/* Serialize the fields */
>>>> +	if (lstruct->nr_fields > 0) {
>>>> +		ret = serialize_fields(&ustruct->nr_fields, &ustruct->fields,
>>>> +				lstruct->nr_fields,	lstruct->fields);
>>>> +		if (ret) {
>>>> +			return ret;
>>>> +		}
>>>> +	}
>>>> +
>>>> +	return 0;
>>>> +}
>>>> +
>>>> +static size_t get_child_global_type_count(size_t nr_global_type_decl,
>>>> +		const struct lttng_global_type_decl *lttng_global_type)
>>>> +{
>>>> +	size_t total_global_types = 0;
>>>> +	int i;
>>>> +	const struct lttng_global_type_decl *lg;
>>>> +
>>>> +	for (i = 0; i < nr_global_type_decl; i++) {
>>>> +		lg = &lttng_global_type[i];
>>>> +
>>>> +		if (lg->nowrite)
>>>> +			continue;
>>>> +
>>>> +		/* Count the global types in children as well */
>>>> +		switch (lg->mtype) {
>>>> +		case mtype_structure:
>>>> +		{
>>>> +			const struct lttng_structure *ls;
>>>> +
>>>> +			ls = lg->u.ctf_structure;
>>>> +			/* Add the number of global types it contains and the count of its own
>>>> children */
>>>> +			if (ls->nr_global_type_decl > 0) {
>>>> +				total_global_types += ls->nr_global_type_decl;
>>>> +				total_global_types +=
>>>> get_child_global_type_count(ls->nr_global_type_decl,
>>>> +								ls->global_type_decl);
>>>> +			}
>>>> +			break;
>>>> +		}
>>>> +		case mtype_enum:
>>>> +		default:
>>>> +			break;
>>>> +		}
>>>> +	}
>>>> +
>>>> +	return total_global_types;
>>>> +}
>>>> +
>>>> +/*
>>>> + * When this method is called, index is the next index to write to and
>>>> the
>>>> + * ustctl_global_type structure is already initialized and will not
>>>> overflow.
>>>> + *
>>>> + * The global type declarations are flattened at serialization to avoid
>>>> + * needing to do recursive frees on error.
>>>> + */
>>>> +static int _serialize_global_type_decl(size_t *index,
>>>> +		struct ustctl_global_type_decl *global_type_decl,
>>>>    		size_t nr_global_type_decl,
>>>>    		const struct lttng_global_type_decl *lttng_global_type)
>>>>    {
>>>> -	struct ustctl_global_type_decl *global_type_decl;
>>>>    	int i, ret;
>>>> -	size_t nr_write_global_type_decl = 0;
>>>> -
>>>> -	global_type_decl = zmalloc(nr_global_type_decl
>>>> -					* sizeof(*global_type_decl));
>>>> -	if (!global_type_decl)
>>>> -		return -ENOMEM;
>>>>    
>>>>    	for (i = 0; i < nr_global_type_decl; i++) {
>>>>    		struct ustctl_global_type_decl *f;
>>>>    		const struct lttng_global_type_decl *lf;
>>>>    
>>>> -		f = &global_type_decl[nr_write_global_type_decl];
>>>> +		f = &global_type_decl[*index];
>>>>    		lf = &lttng_global_type[i];
>>>>    
>>>>    		/* skip 'nowrite' fields */
>>>> @@ -928,18 +994,66 @@ int serialize_global_type_decl(size_t
>>>> *_nr_write_global_type_decl,
>>>>    			le = lf->u.ctf_enum;
>>>>    			ret = serialize_enum(ue, le);
>>>>    			if (ret)
>>>> -				goto error;
>>>> +				return ret;
>>>>    
>>>>    			f->mtype = ustctl_mtype_enum;
>>>>    			break;
>>>>    		}
>>>> +		case mtype_structure:
>>>> +		{
>>>> +			struct ustctl_structure *us;
>>>> +			const struct lttng_structure *ls;
>>>> +
>>>> +			/* Serialize children global types first */
>>>> +			ls = lf->u.ctf_structure;
>>>> +			ret = _serialize_global_type_decl(index,
>>>> +					global_type_decl,
>>>> +					ls->nr_global_type_decl,
>>>> +					ls->global_type_decl);
>>>> +			if (ret)
>>>> +				return ret;
>>>> +
>>>> +			/* Reinitialize f since the index may have changed */
>>>> +			f = &global_type_decl[*index];
>>>> +			us = &f->u.ctf_structure;
>>>> +
>>>> +			ret = serialize_structure(us, ls);
>>>> +			if (ret)
>>>> +				return ret;
>>>> +
>>>> +			f->mtype = ustctl_mtype_structure;
>>>> +			break;
>>>> +		}
>>>>    		default:
>>>> -			ret = -EINVAL;
>>>> -			goto error;
>>>> +			return -EINVAL;
>>>>    		}
>>>>    
>>>> -		nr_write_global_type_decl++;
>>>> +		*index = *index + 1;
>>>>    	}
>>>> +	return 0;
>>>> +}
>>>> +
>>>> +static
>>>> +int serialize_global_type_decl(size_t *_nr_write_global_type_decl,
>>>> +		struct ustctl_global_type_decl **ustctl_global_type,
>>>> +		size_t nr_global_type_decl,
>>>> +		const struct lttng_global_type_decl *lttng_global_type)
>>>> +{
>>>> +	struct ustctl_global_type_decl *global_type_decl;
>>>> +	int i, ret;
>>>> +	size_t nr_write_global_type_decl = 0;
>>>> +	size_t nr_child_global_type_cnt =
>>>> get_child_global_type_count(nr_global_type_decl,
>>>> +							lttng_global_type);
>>>> +
>>>> +	global_type_decl = zmalloc((nr_global_type_decl +
>>>> nr_child_global_type_cnt)
>>>> +					* sizeof(*global_type_decl));
>>>> +	if (!global_type_decl)
>>>> +		return -ENOMEM;
>>>> +
>>>> +	ret = _serialize_global_type_decl(&nr_write_global_type_decl,
>>>> global_type_decl,
>>>> +			nr_global_type_decl, lttng_global_type);
>>>> +	if (ret)
>>>> +		goto error;
>>>>    
>>>>    	*_nr_write_global_type_decl = nr_write_global_type_decl;
>>>>    	*ustctl_global_type = global_type_decl;
>>>> @@ -954,6 +1068,9 @@ error:
>>>>    		case ustctl_mtype_enum:
>>>>    			free(m->u.ctf_enum.entries);
>>>>    			break;
>>>> +		case ustctl_mtype_structure:
>>>> +			free(m->u.ctf_structure.fields);
>>>> +			break;
>>>>    		default:
>>>>    			break;
>>>>    		}
>>>> @@ -1158,15 +1275,31 @@ int ustcomm_register_event(int sock,
>>>>    				}
>>>>    				break;
>>>>    			}
>>>> +			case ustctl_mtype_structure:
>>>> +			{
>>>> +				int field_len = one_global_type->u.ctf_structure.nr_fields *
>>>> sizeof(*one_global_type->u.ctf_structure.fields);
>>>> +
>>>> +				/* Send the fields */
>>>> +				DBG("Sending fields for global type structure %s.\n",
>>>> +						one_global_type->u.ctf_structure.name);
>>>> +				len = ustcomm_send_unix_sock(sock,
>>>> one_global_type->u.ctf_structure.fields, field_len);
>>>> +				free(one_global_type->u.ctf_structure.fields);
>>>> +				one_global_type->u.ctf_structure.fields = NULL;
>>>> +				if (len > 0 && len != field_len) {
>>>> +					goto error_global_type;
>>>> +				}
>>>> +				if (len < 0) {
>>>> +					goto error_global_type;
>>>> +				}
>>>> +				break;
>>>> +			}
>>>>    			default:
>>>>    				break;
>>>>    			}
>>>>    		}
>>>> -		free(global_type_decl);
>>>>    
>>>> -	} else {
>>>> -		free(global_type_decl);
>>>>    	}
>>>> +	free(global_type_decl);
>>>>    
>>>>    	/* receive reply */
>>>>    	len = ustcomm_recv_unix_sock(sock, &reply, sizeof(reply));
>>>> @@ -1212,6 +1345,9 @@ error_global_type:
>>>>    		case ustctl_mtype_enum:
>>>>    			free(one_global_type->u.ctf_enum.entries);
>>>>    			break;
>>>> +		case ustctl_mtype_structure:
>>>> +			free(one_global_type->u.ctf_structure.fields);
>>>> +			break;
>>>>    		default:
>>>>    			break;
>>>>    		}
>>>> diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c
>>>> index a181e62..3100f1b 100644
>>>> --- a/liblttng-ust-ctl/ustctl.c
>>>> +++ b/liblttng-ust-ctl/ustctl.c
>>>> @@ -1896,6 +1896,32 @@ int ustctl_recv_register_event(int sock,
>>>>    				}
>>>>    				break;
>>>>    			}
>>>> +			case ustctl_mtype_structure:
>>>> +			{
>>>> +				int entry_len = one_global_type->u.ctf_structure.nr_fields *
>>>> sizeof(*one_global_type->u.ctf_structure.fields);
>>>> +				/* Receive the entries */
>>>> +				one_global_type->u.ctf_structure.fields = zmalloc(entry_len);
>>>> +				if (!one_global_type->u.ctf_structure.fields) {
>>>> +					len = -ENOMEM;
>>>> +					goto global_type_error;
>>>> +				}
>>>> +				len = ustcomm_recv_unix_sock(sock,
>>>> +						one_global_type->u.ctf_structure.fields,
>>>> +						entry_len);
>>>> +				DBG("Received fields for struct %s.\n",
>>>> one_global_type->u.ctf_structure.name);
>>>> +				if (len > 0 && len != entry_len) {
>>>> +					len = -EIO;
>>>> +					goto global_type_error;
>>>> +				}
>>>> +				if (len == 0) {
>>>> +					len = -EPIPE;
>>>> +					goto global_type_error;
>>>> +				}
>>>> +				if (len < 0) {
>>>> +					goto global_type_error;
>>>> +				}
>>>> +				break;
>>>> +			}
>>>>    			default:
>>>>    				break;
>>>>    			}
>>>> --
>>>> 1.9.1
>>>>
>>>>
>>>> _______________________________________________
>>>> lttng-dev mailing list
>>>> lttng-dev@lists.lttng.org
>>>> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
>>>>
>>


_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC Patch Ust 2/5] Serialize the CTF global structures for ust-comm
       [not found]     ` <53458452.8030905@versatic.net>
@ 2014-04-27  8:34       ` Mathieu Desnoyers
       [not found]       ` <2087397408.8083.1398587642565.JavaMail.zimbra@efficios.com>
  1 sibling, 0 replies; 7+ messages in thread
From: Mathieu Desnoyers @ 2014-04-27  8:34 UTC (permalink / raw)
  To: Geneviève Bastien; +Cc: lttng-dev

----- Original Message -----
> From: "Geneviève Bastien" <gbastien+lttng@versatic.net>
> To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>
> Cc: lttng-dev@lists.lttng.org
> Sent: Wednesday, April 9, 2014 7:33:06 PM
> Subject: Re: [lttng-dev] [RFC Patch Ust 2/5] Serialize the CTF global structures for ust-comm
> 
> On 04/09/2014 11:42 AM, Mathieu Desnoyers wrote:
> > ----- Original Message -----
> >> From: "Geneviève Bastien" <gbastien+lttng@versatic.net>
> >> To: lttng-dev@lists.lttng.org
> >> Sent: Wednesday, March 26, 2014 10:47:09 AM
> >> Subject: [lttng-dev] [RFC Patch Ust 2/5] Serialize the CTF global
> >> structures	for ust-comm
> >>
> >> It flatten the global types so that global types used by other global
> >> types
> > flatten -> flattens
> >
> >> all belong to the event at serialization. This avoids recursive calls to
> >> the
> >> send and receive functions and simplifies error handling (no recursive
> >> frees).
> > Is the structure and enum part of the event, or declared outside of
> > the event scope ?
> They are named structures so declared outside the scope of the event.
> But they are sent only if one event needs them.
> >
> > Is there a downside to this approach ? For instance, if the same
> > structure is used in many events, do we have to send the structure info
> > many times ?
> Sending each structure (and enum) once would be enough, we could keep a
> hash table of global types that were sent, like we do before dumping the
> metadata of those global types, and that would avoid sending them many
> times. But it is not what is being done right now. We just send all the
> global types, but they are added to the metadata only once.

Repeating the integers, strings, etc on the "wire" (unix socket) for
every field between UST and sessiond was not so bad, since they were
small enough descriptions.

However, I figure that enumerations, structures and variant types will
grow to be much larger than their basic types counterparts.

Therefore, sending the global type separately, and then sending a
reference to that type (a string) when encountering the event field
using this global type seems like a more scalable solution to me.

Thanks,

Mathieu

> 
> Thanks,
> Geneviève
> >
> > Thanks,
> >
> > Mathieu
> >
> >> Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
> >> ---
> >>   liblttng-ust-comm/lttng-ust-comm.c | 170
> >>   +++++++++++++++++++++++++++++++++----
> >>   liblttng-ust-ctl/ustctl.c          |  26 ++++++
> >>   2 files changed, 179 insertions(+), 17 deletions(-)
> >>
> >> diff --git a/liblttng-ust-comm/lttng-ust-comm.c
> >> b/liblttng-ust-comm/lttng-ust-comm.c
> >> index bc22130..90274c4 100644
> >> --- a/liblttng-ust-comm/lttng-ust-comm.c
> >> +++ b/liblttng-ust-comm/lttng-ust-comm.c
> >> @@ -742,6 +742,7 @@ int serialize_basic_type(enum ustctl_abstract_types
> >> *uatype,
> >>   	}
> >>   	case atype_array:
> >>   	case atype_sequence:
> >> +	case atype_structure:
> >>   	default:
> >>   		return -EINVAL;
> >>   	}
> >> @@ -800,6 +801,14 @@ int serialize_one_type(struct ustctl_type *ut, const
> >> struct lttng_type *lt)
> >>   		ut->atype = ustctl_atype_sequence;
> >>   		break;
> >>   	}
> >> +	case atype_structure:
> >> +	{
> >> +		strncpy(ut->u.structure.name, lt->u.structure.name,
> >> +						LTTNG_UST_SYM_NAME_LEN);
> >> +		ut->u.structure.name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
> >> +		ut->atype = ustctl_atype_structure;
> >> +		break;
> >> +	}
> >>   	default:
> >>   		return -EINVAL;
> >>   	}
> >> @@ -892,25 +901,82 @@ int serialize_enum(struct ustctl_enum *uenum,
> >>   }
> >>   
> >>   static
> >> -int serialize_global_type_decl(size_t *_nr_write_global_type_decl,
> >> -		struct ustctl_global_type_decl **ustctl_global_type,
> >> +int serialize_structure(struct ustctl_structure *ustruct,
> >> +		const struct lttng_structure *lstruct)
> >> +{
> >> +	int ret;
> >> +
> >> +	strncpy(ustruct->name, lstruct->name, LTTNG_UST_SYM_NAME_LEN);
> >> +	ustruct->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
> >> +
> >> +	/* Serialize the fields */
> >> +	if (lstruct->nr_fields > 0) {
> >> +		ret = serialize_fields(&ustruct->nr_fields, &ustruct->fields,
> >> +				lstruct->nr_fields,	lstruct->fields);
> >> +		if (ret) {
> >> +			return ret;
> >> +		}
> >> +	}
> >> +
> >> +	return 0;
> >> +}
> >> +
> >> +static size_t get_child_global_type_count(size_t nr_global_type_decl,
> >> +		const struct lttng_global_type_decl *lttng_global_type)
> >> +{
> >> +	size_t total_global_types = 0;
> >> +	int i;
> >> +	const struct lttng_global_type_decl *lg;
> >> +
> >> +	for (i = 0; i < nr_global_type_decl; i++) {
> >> +		lg = &lttng_global_type[i];
> >> +
> >> +		if (lg->nowrite)
> >> +			continue;
> >> +
> >> +		/* Count the global types in children as well */
> >> +		switch (lg->mtype) {
> >> +		case mtype_structure:
> >> +		{
> >> +			const struct lttng_structure *ls;
> >> +
> >> +			ls = lg->u.ctf_structure;
> >> +			/* Add the number of global types it contains and the count of its own
> >> children */
> >> +			if (ls->nr_global_type_decl > 0) {
> >> +				total_global_types += ls->nr_global_type_decl;
> >> +				total_global_types +=
> >> get_child_global_type_count(ls->nr_global_type_decl,
> >> +								ls->global_type_decl);
> >> +			}
> >> +			break;
> >> +		}
> >> +		case mtype_enum:
> >> +		default:
> >> +			break;
> >> +		}
> >> +	}
> >> +
> >> +	return total_global_types;
> >> +}
> >> +
> >> +/*
> >> + * When this method is called, index is the next index to write to and
> >> the
> >> + * ustctl_global_type structure is already initialized and will not
> >> overflow.
> >> + *
> >> + * The global type declarations are flattened at serialization to avoid
> >> + * needing to do recursive frees on error.
> >> + */
> >> +static int _serialize_global_type_decl(size_t *index,
> >> +		struct ustctl_global_type_decl *global_type_decl,
> >>   		size_t nr_global_type_decl,
> >>   		const struct lttng_global_type_decl *lttng_global_type)
> >>   {
> >> -	struct ustctl_global_type_decl *global_type_decl;
> >>   	int i, ret;
> >> -	size_t nr_write_global_type_decl = 0;
> >> -
> >> -	global_type_decl = zmalloc(nr_global_type_decl
> >> -					* sizeof(*global_type_decl));
> >> -	if (!global_type_decl)
> >> -		return -ENOMEM;
> >>   
> >>   	for (i = 0; i < nr_global_type_decl; i++) {
> >>   		struct ustctl_global_type_decl *f;
> >>   		const struct lttng_global_type_decl *lf;
> >>   
> >> -		f = &global_type_decl[nr_write_global_type_decl];
> >> +		f = &global_type_decl[*index];
> >>   		lf = &lttng_global_type[i];
> >>   
> >>   		/* skip 'nowrite' fields */
> >> @@ -928,18 +994,66 @@ int serialize_global_type_decl(size_t
> >> *_nr_write_global_type_decl,
> >>   			le = lf->u.ctf_enum;
> >>   			ret = serialize_enum(ue, le);
> >>   			if (ret)
> >> -				goto error;
> >> +				return ret;
> >>   
> >>   			f->mtype = ustctl_mtype_enum;
> >>   			break;
> >>   		}
> >> +		case mtype_structure:
> >> +		{
> >> +			struct ustctl_structure *us;
> >> +			const struct lttng_structure *ls;
> >> +
> >> +			/* Serialize children global types first */
> >> +			ls = lf->u.ctf_structure;
> >> +			ret = _serialize_global_type_decl(index,
> >> +					global_type_decl,
> >> +					ls->nr_global_type_decl,
> >> +					ls->global_type_decl);
> >> +			if (ret)
> >> +				return ret;
> >> +
> >> +			/* Reinitialize f since the index may have changed */
> >> +			f = &global_type_decl[*index];
> >> +			us = &f->u.ctf_structure;
> >> +
> >> +			ret = serialize_structure(us, ls);
> >> +			if (ret)
> >> +				return ret;
> >> +
> >> +			f->mtype = ustctl_mtype_structure;
> >> +			break;
> >> +		}
> >>   		default:
> >> -			ret = -EINVAL;
> >> -			goto error;
> >> +			return -EINVAL;
> >>   		}
> >>   
> >> -		nr_write_global_type_decl++;
> >> +		*index = *index + 1;
> >>   	}
> >> +	return 0;
> >> +}
> >> +
> >> +static
> >> +int serialize_global_type_decl(size_t *_nr_write_global_type_decl,
> >> +		struct ustctl_global_type_decl **ustctl_global_type,
> >> +		size_t nr_global_type_decl,
> >> +		const struct lttng_global_type_decl *lttng_global_type)
> >> +{
> >> +	struct ustctl_global_type_decl *global_type_decl;
> >> +	int i, ret;
> >> +	size_t nr_write_global_type_decl = 0;
> >> +	size_t nr_child_global_type_cnt =
> >> get_child_global_type_count(nr_global_type_decl,
> >> +							lttng_global_type);
> >> +
> >> +	global_type_decl = zmalloc((nr_global_type_decl +
> >> nr_child_global_type_cnt)
> >> +					* sizeof(*global_type_decl));
> >> +	if (!global_type_decl)
> >> +		return -ENOMEM;
> >> +
> >> +	ret = _serialize_global_type_decl(&nr_write_global_type_decl,
> >> global_type_decl,
> >> +			nr_global_type_decl, lttng_global_type);
> >> +	if (ret)
> >> +		goto error;
> >>   
> >>   	*_nr_write_global_type_decl = nr_write_global_type_decl;
> >>   	*ustctl_global_type = global_type_decl;
> >> @@ -954,6 +1068,9 @@ error:
> >>   		case ustctl_mtype_enum:
> >>   			free(m->u.ctf_enum.entries);
> >>   			break;
> >> +		case ustctl_mtype_structure:
> >> +			free(m->u.ctf_structure.fields);
> >> +			break;
> >>   		default:
> >>   			break;
> >>   		}
> >> @@ -1158,15 +1275,31 @@ int ustcomm_register_event(int sock,
> >>   				}
> >>   				break;
> >>   			}
> >> +			case ustctl_mtype_structure:
> >> +			{
> >> +				int field_len = one_global_type->u.ctf_structure.nr_fields *
> >> sizeof(*one_global_type->u.ctf_structure.fields);
> >> +
> >> +				/* Send the fields */
> >> +				DBG("Sending fields for global type structure %s.\n",
> >> +						one_global_type->u.ctf_structure.name);
> >> +				len = ustcomm_send_unix_sock(sock,
> >> one_global_type->u.ctf_structure.fields, field_len);
> >> +				free(one_global_type->u.ctf_structure.fields);
> >> +				one_global_type->u.ctf_structure.fields = NULL;
> >> +				if (len > 0 && len != field_len) {
> >> +					goto error_global_type;
> >> +				}
> >> +				if (len < 0) {
> >> +					goto error_global_type;
> >> +				}
> >> +				break;
> >> +			}
> >>   			default:
> >>   				break;
> >>   			}
> >>   		}
> >> -		free(global_type_decl);
> >>   
> >> -	} else {
> >> -		free(global_type_decl);
> >>   	}
> >> +	free(global_type_decl);
> >>   
> >>   	/* receive reply */
> >>   	len = ustcomm_recv_unix_sock(sock, &reply, sizeof(reply));
> >> @@ -1212,6 +1345,9 @@ error_global_type:
> >>   		case ustctl_mtype_enum:
> >>   			free(one_global_type->u.ctf_enum.entries);
> >>   			break;
> >> +		case ustctl_mtype_structure:
> >> +			free(one_global_type->u.ctf_structure.fields);
> >> +			break;
> >>   		default:
> >>   			break;
> >>   		}
> >> diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c
> >> index a181e62..3100f1b 100644
> >> --- a/liblttng-ust-ctl/ustctl.c
> >> +++ b/liblttng-ust-ctl/ustctl.c
> >> @@ -1896,6 +1896,32 @@ int ustctl_recv_register_event(int sock,
> >>   				}
> >>   				break;
> >>   			}
> >> +			case ustctl_mtype_structure:
> >> +			{
> >> +				int entry_len = one_global_type->u.ctf_structure.nr_fields *
> >> sizeof(*one_global_type->u.ctf_structure.fields);
> >> +				/* Receive the entries */
> >> +				one_global_type->u.ctf_structure.fields = zmalloc(entry_len);
> >> +				if (!one_global_type->u.ctf_structure.fields) {
> >> +					len = -ENOMEM;
> >> +					goto global_type_error;
> >> +				}
> >> +				len = ustcomm_recv_unix_sock(sock,
> >> +						one_global_type->u.ctf_structure.fields,
> >> +						entry_len);
> >> +				DBG("Received fields for struct %s.\n",
> >> one_global_type->u.ctf_structure.name);
> >> +				if (len > 0 && len != entry_len) {
> >> +					len = -EIO;
> >> +					goto global_type_error;
> >> +				}
> >> +				if (len == 0) {
> >> +					len = -EPIPE;
> >> +					goto global_type_error;
> >> +				}
> >> +				if (len < 0) {
> >> +					goto global_type_error;
> >> +				}
> >> +				break;
> >> +			}
> >>   			default:
> >>   				break;
> >>   			}
> >> --
> >> 1.9.1
> >>
> >>
> >> _______________________________________________
> >> lttng-dev mailing list
> >> lttng-dev@lists.lttng.org
> >> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
> >>
> 
> 

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC Patch Ust 2/5] Serialize the CTF global structures for ust-comm
       [not found]   ` <224451157.1253.1397058138828.JavaMail.zimbra@efficios.com>
@ 2014-04-09 17:33     ` Geneviève Bastien
       [not found]     ` <53458452.8030905@versatic.net>
  1 sibling, 0 replies; 7+ messages in thread
From: Geneviève Bastien @ 2014-04-09 17:33 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: lttng-dev

On 04/09/2014 11:42 AM, Mathieu Desnoyers wrote:
> ----- Original Message -----
>> From: "Geneviève Bastien" <gbastien+lttng@versatic.net>
>> To: lttng-dev@lists.lttng.org
>> Sent: Wednesday, March 26, 2014 10:47:09 AM
>> Subject: [lttng-dev] [RFC Patch Ust 2/5] Serialize the CTF global structures	for ust-comm
>>
>> It flatten the global types so that global types used by other global types
> flatten -> flattens
>
>> all belong to the event at serialization. This avoids recursive calls to the
>> send and receive functions and simplifies error handling (no recursive
>> frees).
> Is the structure and enum part of the event, or declared outside of
> the event scope ?
They are named structures so declared outside the scope of the event. 
But they are sent only if one event needs them.
>
> Is there a downside to this approach ? For instance, if the same
> structure is used in many events, do we have to send the structure info
> many times ?
Sending each structure (and enum) once would be enough, we could keep a 
hash table of global types that were sent, like we do before dumping the 
metadata of those global types, and that would avoid sending them many 
times. But it is not what is being done right now. We just send all the 
global types, but they are added to the metadata only once.

Thanks,
Geneviève
>
> Thanks,
>
> Mathieu
>
>> Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
>> ---
>>   liblttng-ust-comm/lttng-ust-comm.c | 170
>>   +++++++++++++++++++++++++++++++++----
>>   liblttng-ust-ctl/ustctl.c          |  26 ++++++
>>   2 files changed, 179 insertions(+), 17 deletions(-)
>>
>> diff --git a/liblttng-ust-comm/lttng-ust-comm.c
>> b/liblttng-ust-comm/lttng-ust-comm.c
>> index bc22130..90274c4 100644
>> --- a/liblttng-ust-comm/lttng-ust-comm.c
>> +++ b/liblttng-ust-comm/lttng-ust-comm.c
>> @@ -742,6 +742,7 @@ int serialize_basic_type(enum ustctl_abstract_types
>> *uatype,
>>   	}
>>   	case atype_array:
>>   	case atype_sequence:
>> +	case atype_structure:
>>   	default:
>>   		return -EINVAL;
>>   	}
>> @@ -800,6 +801,14 @@ int serialize_one_type(struct ustctl_type *ut, const
>> struct lttng_type *lt)
>>   		ut->atype = ustctl_atype_sequence;
>>   		break;
>>   	}
>> +	case atype_structure:
>> +	{
>> +		strncpy(ut->u.structure.name, lt->u.structure.name,
>> +						LTTNG_UST_SYM_NAME_LEN);
>> +		ut->u.structure.name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
>> +		ut->atype = ustctl_atype_structure;
>> +		break;
>> +	}
>>   	default:
>>   		return -EINVAL;
>>   	}
>> @@ -892,25 +901,82 @@ int serialize_enum(struct ustctl_enum *uenum,
>>   }
>>   
>>   static
>> -int serialize_global_type_decl(size_t *_nr_write_global_type_decl,
>> -		struct ustctl_global_type_decl **ustctl_global_type,
>> +int serialize_structure(struct ustctl_structure *ustruct,
>> +		const struct lttng_structure *lstruct)
>> +{
>> +	int ret;
>> +
>> +	strncpy(ustruct->name, lstruct->name, LTTNG_UST_SYM_NAME_LEN);
>> +	ustruct->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
>> +
>> +	/* Serialize the fields */
>> +	if (lstruct->nr_fields > 0) {
>> +		ret = serialize_fields(&ustruct->nr_fields, &ustruct->fields,
>> +				lstruct->nr_fields,	lstruct->fields);
>> +		if (ret) {
>> +			return ret;
>> +		}
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>> +static size_t get_child_global_type_count(size_t nr_global_type_decl,
>> +		const struct lttng_global_type_decl *lttng_global_type)
>> +{
>> +	size_t total_global_types = 0;
>> +	int i;
>> +	const struct lttng_global_type_decl *lg;
>> +
>> +	for (i = 0; i < nr_global_type_decl; i++) {
>> +		lg = &lttng_global_type[i];
>> +
>> +		if (lg->nowrite)
>> +			continue;
>> +
>> +		/* Count the global types in children as well */
>> +		switch (lg->mtype) {
>> +		case mtype_structure:
>> +		{
>> +			const struct lttng_structure *ls;
>> +
>> +			ls = lg->u.ctf_structure;
>> +			/* Add the number of global types it contains and the count of its own
>> children */
>> +			if (ls->nr_global_type_decl > 0) {
>> +				total_global_types += ls->nr_global_type_decl;
>> +				total_global_types +=
>> get_child_global_type_count(ls->nr_global_type_decl,
>> +								ls->global_type_decl);
>> +			}
>> +			break;
>> +		}
>> +		case mtype_enum:
>> +		default:
>> +			break;
>> +		}
>> +	}
>> +
>> +	return total_global_types;
>> +}
>> +
>> +/*
>> + * When this method is called, index is the next index to write to and the
>> + * ustctl_global_type structure is already initialized and will not
>> overflow.
>> + *
>> + * The global type declarations are flattened at serialization to avoid
>> + * needing to do recursive frees on error.
>> + */
>> +static int _serialize_global_type_decl(size_t *index,
>> +		struct ustctl_global_type_decl *global_type_decl,
>>   		size_t nr_global_type_decl,
>>   		const struct lttng_global_type_decl *lttng_global_type)
>>   {
>> -	struct ustctl_global_type_decl *global_type_decl;
>>   	int i, ret;
>> -	size_t nr_write_global_type_decl = 0;
>> -
>> -	global_type_decl = zmalloc(nr_global_type_decl
>> -					* sizeof(*global_type_decl));
>> -	if (!global_type_decl)
>> -		return -ENOMEM;
>>   
>>   	for (i = 0; i < nr_global_type_decl; i++) {
>>   		struct ustctl_global_type_decl *f;
>>   		const struct lttng_global_type_decl *lf;
>>   
>> -		f = &global_type_decl[nr_write_global_type_decl];
>> +		f = &global_type_decl[*index];
>>   		lf = &lttng_global_type[i];
>>   
>>   		/* skip 'nowrite' fields */
>> @@ -928,18 +994,66 @@ int serialize_global_type_decl(size_t
>> *_nr_write_global_type_decl,
>>   			le = lf->u.ctf_enum;
>>   			ret = serialize_enum(ue, le);
>>   			if (ret)
>> -				goto error;
>> +				return ret;
>>   
>>   			f->mtype = ustctl_mtype_enum;
>>   			break;
>>   		}
>> +		case mtype_structure:
>> +		{
>> +			struct ustctl_structure *us;
>> +			const struct lttng_structure *ls;
>> +
>> +			/* Serialize children global types first */
>> +			ls = lf->u.ctf_structure;
>> +			ret = _serialize_global_type_decl(index,
>> +					global_type_decl,
>> +					ls->nr_global_type_decl,
>> +					ls->global_type_decl);
>> +			if (ret)
>> +				return ret;
>> +
>> +			/* Reinitialize f since the index may have changed */
>> +			f = &global_type_decl[*index];
>> +			us = &f->u.ctf_structure;
>> +
>> +			ret = serialize_structure(us, ls);
>> +			if (ret)
>> +				return ret;
>> +
>> +			f->mtype = ustctl_mtype_structure;
>> +			break;
>> +		}
>>   		default:
>> -			ret = -EINVAL;
>> -			goto error;
>> +			return -EINVAL;
>>   		}
>>   
>> -		nr_write_global_type_decl++;
>> +		*index = *index + 1;
>>   	}
>> +	return 0;
>> +}
>> +
>> +static
>> +int serialize_global_type_decl(size_t *_nr_write_global_type_decl,
>> +		struct ustctl_global_type_decl **ustctl_global_type,
>> +		size_t nr_global_type_decl,
>> +		const struct lttng_global_type_decl *lttng_global_type)
>> +{
>> +	struct ustctl_global_type_decl *global_type_decl;
>> +	int i, ret;
>> +	size_t nr_write_global_type_decl = 0;
>> +	size_t nr_child_global_type_cnt =
>> get_child_global_type_count(nr_global_type_decl,
>> +							lttng_global_type);
>> +
>> +	global_type_decl = zmalloc((nr_global_type_decl + nr_child_global_type_cnt)
>> +					* sizeof(*global_type_decl));
>> +	if (!global_type_decl)
>> +		return -ENOMEM;
>> +
>> +	ret = _serialize_global_type_decl(&nr_write_global_type_decl,
>> global_type_decl,
>> +			nr_global_type_decl, lttng_global_type);
>> +	if (ret)
>> +		goto error;
>>   
>>   	*_nr_write_global_type_decl = nr_write_global_type_decl;
>>   	*ustctl_global_type = global_type_decl;
>> @@ -954,6 +1068,9 @@ error:
>>   		case ustctl_mtype_enum:
>>   			free(m->u.ctf_enum.entries);
>>   			break;
>> +		case ustctl_mtype_structure:
>> +			free(m->u.ctf_structure.fields);
>> +			break;
>>   		default:
>>   			break;
>>   		}
>> @@ -1158,15 +1275,31 @@ int ustcomm_register_event(int sock,
>>   				}
>>   				break;
>>   			}
>> +			case ustctl_mtype_structure:
>> +			{
>> +				int field_len = one_global_type->u.ctf_structure.nr_fields *
>> sizeof(*one_global_type->u.ctf_structure.fields);
>> +
>> +				/* Send the fields */
>> +				DBG("Sending fields for global type structure %s.\n",
>> +						one_global_type->u.ctf_structure.name);
>> +				len = ustcomm_send_unix_sock(sock,
>> one_global_type->u.ctf_structure.fields, field_len);
>> +				free(one_global_type->u.ctf_structure.fields);
>> +				one_global_type->u.ctf_structure.fields = NULL;
>> +				if (len > 0 && len != field_len) {
>> +					goto error_global_type;
>> +				}
>> +				if (len < 0) {
>> +					goto error_global_type;
>> +				}
>> +				break;
>> +			}
>>   			default:
>>   				break;
>>   			}
>>   		}
>> -		free(global_type_decl);
>>   
>> -	} else {
>> -		free(global_type_decl);
>>   	}
>> +	free(global_type_decl);
>>   
>>   	/* receive reply */
>>   	len = ustcomm_recv_unix_sock(sock, &reply, sizeof(reply));
>> @@ -1212,6 +1345,9 @@ error_global_type:
>>   		case ustctl_mtype_enum:
>>   			free(one_global_type->u.ctf_enum.entries);
>>   			break;
>> +		case ustctl_mtype_structure:
>> +			free(one_global_type->u.ctf_structure.fields);
>> +			break;
>>   		default:
>>   			break;
>>   		}
>> diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c
>> index a181e62..3100f1b 100644
>> --- a/liblttng-ust-ctl/ustctl.c
>> +++ b/liblttng-ust-ctl/ustctl.c
>> @@ -1896,6 +1896,32 @@ int ustctl_recv_register_event(int sock,
>>   				}
>>   				break;
>>   			}
>> +			case ustctl_mtype_structure:
>> +			{
>> +				int entry_len = one_global_type->u.ctf_structure.nr_fields *
>> sizeof(*one_global_type->u.ctf_structure.fields);
>> +				/* Receive the entries */
>> +				one_global_type->u.ctf_structure.fields = zmalloc(entry_len);
>> +				if (!one_global_type->u.ctf_structure.fields) {
>> +					len = -ENOMEM;
>> +					goto global_type_error;
>> +				}
>> +				len = ustcomm_recv_unix_sock(sock,
>> +						one_global_type->u.ctf_structure.fields,
>> +						entry_len);
>> +				DBG("Received fields for struct %s.\n",
>> one_global_type->u.ctf_structure.name);
>> +				if (len > 0 && len != entry_len) {
>> +					len = -EIO;
>> +					goto global_type_error;
>> +				}
>> +				if (len == 0) {
>> +					len = -EPIPE;
>> +					goto global_type_error;
>> +				}
>> +				if (len < 0) {
>> +					goto global_type_error;
>> +				}
>> +				break;
>> +			}
>>   			default:
>>   				break;
>>   			}
>> --
>> 1.9.1
>>
>>
>> _______________________________________________
>> lttng-dev mailing list
>> lttng-dev@lists.lttng.org
>> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
>>


_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC Patch Ust 2/5] Serialize the CTF global structures for ust-comm
       [not found] ` <1395845232-17669-3-git-send-email-gbastien+lttng@versatic.net>
@ 2014-04-09 15:42   ` Mathieu Desnoyers
       [not found]   ` <224451157.1253.1397058138828.JavaMail.zimbra@efficios.com>
  1 sibling, 0 replies; 7+ messages in thread
From: Mathieu Desnoyers @ 2014-04-09 15:42 UTC (permalink / raw)
  To: Geneviève Bastien; +Cc: lttng-dev

----- Original Message -----
> From: "Geneviève Bastien" <gbastien+lttng@versatic.net>
> To: lttng-dev@lists.lttng.org
> Sent: Wednesday, March 26, 2014 10:47:09 AM
> Subject: [lttng-dev] [RFC Patch Ust 2/5] Serialize the CTF global structures	for ust-comm
> 
> It flatten the global types so that global types used by other global types

flatten -> flattens

> all belong to the event at serialization. This avoids recursive calls to the
> send and receive functions and simplifies error handling (no recursive
> frees).

Is the structure and enum part of the event, or declared outside of
the event scope ?

Is there a downside to this approach ? For instance, if the same
structure is used in many events, do we have to send the structure info
many times ?

Thanks,

Mathieu

> 
> Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
> ---
>  liblttng-ust-comm/lttng-ust-comm.c | 170
>  +++++++++++++++++++++++++++++++++----
>  liblttng-ust-ctl/ustctl.c          |  26 ++++++
>  2 files changed, 179 insertions(+), 17 deletions(-)
> 
> diff --git a/liblttng-ust-comm/lttng-ust-comm.c
> b/liblttng-ust-comm/lttng-ust-comm.c
> index bc22130..90274c4 100644
> --- a/liblttng-ust-comm/lttng-ust-comm.c
> +++ b/liblttng-ust-comm/lttng-ust-comm.c
> @@ -742,6 +742,7 @@ int serialize_basic_type(enum ustctl_abstract_types
> *uatype,
>  	}
>  	case atype_array:
>  	case atype_sequence:
> +	case atype_structure:
>  	default:
>  		return -EINVAL;
>  	}
> @@ -800,6 +801,14 @@ int serialize_one_type(struct ustctl_type *ut, const
> struct lttng_type *lt)
>  		ut->atype = ustctl_atype_sequence;
>  		break;
>  	}
> +	case atype_structure:
> +	{
> +		strncpy(ut->u.structure.name, lt->u.structure.name,
> +						LTTNG_UST_SYM_NAME_LEN);
> +		ut->u.structure.name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
> +		ut->atype = ustctl_atype_structure;
> +		break;
> +	}
>  	default:
>  		return -EINVAL;
>  	}
> @@ -892,25 +901,82 @@ int serialize_enum(struct ustctl_enum *uenum,
>  }
>  
>  static
> -int serialize_global_type_decl(size_t *_nr_write_global_type_decl,
> -		struct ustctl_global_type_decl **ustctl_global_type,
> +int serialize_structure(struct ustctl_structure *ustruct,
> +		const struct lttng_structure *lstruct)
> +{
> +	int ret;
> +
> +	strncpy(ustruct->name, lstruct->name, LTTNG_UST_SYM_NAME_LEN);
> +	ustruct->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
> +
> +	/* Serialize the fields */
> +	if (lstruct->nr_fields > 0) {
> +		ret = serialize_fields(&ustruct->nr_fields, &ustruct->fields,
> +				lstruct->nr_fields,	lstruct->fields);
> +		if (ret) {
> +			return ret;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +static size_t get_child_global_type_count(size_t nr_global_type_decl,
> +		const struct lttng_global_type_decl *lttng_global_type)
> +{
> +	size_t total_global_types = 0;
> +	int i;
> +	const struct lttng_global_type_decl *lg;
> +
> +	for (i = 0; i < nr_global_type_decl; i++) {
> +		lg = &lttng_global_type[i];
> +
> +		if (lg->nowrite)
> +			continue;
> +
> +		/* Count the global types in children as well */
> +		switch (lg->mtype) {
> +		case mtype_structure:
> +		{
> +			const struct lttng_structure *ls;
> +
> +			ls = lg->u.ctf_structure;
> +			/* Add the number of global types it contains and the count of its own
> children */
> +			if (ls->nr_global_type_decl > 0) {
> +				total_global_types += ls->nr_global_type_decl;
> +				total_global_types +=
> get_child_global_type_count(ls->nr_global_type_decl,
> +								ls->global_type_decl);
> +			}
> +			break;
> +		}
> +		case mtype_enum:
> +		default:
> +			break;
> +		}
> +	}
> +
> +	return total_global_types;
> +}
> +
> +/*
> + * When this method is called, index is the next index to write to and the
> + * ustctl_global_type structure is already initialized and will not
> overflow.
> + *
> + * The global type declarations are flattened at serialization to avoid
> + * needing to do recursive frees on error.
> + */
> +static int _serialize_global_type_decl(size_t *index,
> +		struct ustctl_global_type_decl *global_type_decl,
>  		size_t nr_global_type_decl,
>  		const struct lttng_global_type_decl *lttng_global_type)
>  {
> -	struct ustctl_global_type_decl *global_type_decl;
>  	int i, ret;
> -	size_t nr_write_global_type_decl = 0;
> -
> -	global_type_decl = zmalloc(nr_global_type_decl
> -					* sizeof(*global_type_decl));
> -	if (!global_type_decl)
> -		return -ENOMEM;
>  
>  	for (i = 0; i < nr_global_type_decl; i++) {
>  		struct ustctl_global_type_decl *f;
>  		const struct lttng_global_type_decl *lf;
>  
> -		f = &global_type_decl[nr_write_global_type_decl];
> +		f = &global_type_decl[*index];
>  		lf = &lttng_global_type[i];
>  
>  		/* skip 'nowrite' fields */
> @@ -928,18 +994,66 @@ int serialize_global_type_decl(size_t
> *_nr_write_global_type_decl,
>  			le = lf->u.ctf_enum;
>  			ret = serialize_enum(ue, le);
>  			if (ret)
> -				goto error;
> +				return ret;
>  
>  			f->mtype = ustctl_mtype_enum;
>  			break;
>  		}
> +		case mtype_structure:
> +		{
> +			struct ustctl_structure *us;
> +			const struct lttng_structure *ls;
> +
> +			/* Serialize children global types first */
> +			ls = lf->u.ctf_structure;
> +			ret = _serialize_global_type_decl(index,
> +					global_type_decl,
> +					ls->nr_global_type_decl,
> +					ls->global_type_decl);
> +			if (ret)
> +				return ret;
> +
> +			/* Reinitialize f since the index may have changed */
> +			f = &global_type_decl[*index];
> +			us = &f->u.ctf_structure;
> +
> +			ret = serialize_structure(us, ls);
> +			if (ret)
> +				return ret;
> +
> +			f->mtype = ustctl_mtype_structure;
> +			break;
> +		}
>  		default:
> -			ret = -EINVAL;
> -			goto error;
> +			return -EINVAL;
>  		}
>  
> -		nr_write_global_type_decl++;
> +		*index = *index + 1;
>  	}
> +	return 0;
> +}
> +
> +static
> +int serialize_global_type_decl(size_t *_nr_write_global_type_decl,
> +		struct ustctl_global_type_decl **ustctl_global_type,
> +		size_t nr_global_type_decl,
> +		const struct lttng_global_type_decl *lttng_global_type)
> +{
> +	struct ustctl_global_type_decl *global_type_decl;
> +	int i, ret;
> +	size_t nr_write_global_type_decl = 0;
> +	size_t nr_child_global_type_cnt =
> get_child_global_type_count(nr_global_type_decl,
> +							lttng_global_type);
> +
> +	global_type_decl = zmalloc((nr_global_type_decl + nr_child_global_type_cnt)
> +					* sizeof(*global_type_decl));
> +	if (!global_type_decl)
> +		return -ENOMEM;
> +
> +	ret = _serialize_global_type_decl(&nr_write_global_type_decl,
> global_type_decl,
> +			nr_global_type_decl, lttng_global_type);
> +	if (ret)
> +		goto error;
>  
>  	*_nr_write_global_type_decl = nr_write_global_type_decl;
>  	*ustctl_global_type = global_type_decl;
> @@ -954,6 +1068,9 @@ error:
>  		case ustctl_mtype_enum:
>  			free(m->u.ctf_enum.entries);
>  			break;
> +		case ustctl_mtype_structure:
> +			free(m->u.ctf_structure.fields);
> +			break;
>  		default:
>  			break;
>  		}
> @@ -1158,15 +1275,31 @@ int ustcomm_register_event(int sock,
>  				}
>  				break;
>  			}
> +			case ustctl_mtype_structure:
> +			{
> +				int field_len = one_global_type->u.ctf_structure.nr_fields *
> sizeof(*one_global_type->u.ctf_structure.fields);
> +
> +				/* Send the fields */
> +				DBG("Sending fields for global type structure %s.\n",
> +						one_global_type->u.ctf_structure.name);
> +				len = ustcomm_send_unix_sock(sock,
> one_global_type->u.ctf_structure.fields, field_len);
> +				free(one_global_type->u.ctf_structure.fields);
> +				one_global_type->u.ctf_structure.fields = NULL;
> +				if (len > 0 && len != field_len) {
> +					goto error_global_type;
> +				}
> +				if (len < 0) {
> +					goto error_global_type;
> +				}
> +				break;
> +			}
>  			default:
>  				break;
>  			}
>  		}
> -		free(global_type_decl);
>  
> -	} else {
> -		free(global_type_decl);
>  	}
> +	free(global_type_decl);
>  
>  	/* receive reply */
>  	len = ustcomm_recv_unix_sock(sock, &reply, sizeof(reply));
> @@ -1212,6 +1345,9 @@ error_global_type:
>  		case ustctl_mtype_enum:
>  			free(one_global_type->u.ctf_enum.entries);
>  			break;
> +		case ustctl_mtype_structure:
> +			free(one_global_type->u.ctf_structure.fields);
> +			break;
>  		default:
>  			break;
>  		}
> diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c
> index a181e62..3100f1b 100644
> --- a/liblttng-ust-ctl/ustctl.c
> +++ b/liblttng-ust-ctl/ustctl.c
> @@ -1896,6 +1896,32 @@ int ustctl_recv_register_event(int sock,
>  				}
>  				break;
>  			}
> +			case ustctl_mtype_structure:
> +			{
> +				int entry_len = one_global_type->u.ctf_structure.nr_fields *
> sizeof(*one_global_type->u.ctf_structure.fields);
> +				/* Receive the entries */
> +				one_global_type->u.ctf_structure.fields = zmalloc(entry_len);
> +				if (!one_global_type->u.ctf_structure.fields) {
> +					len = -ENOMEM;
> +					goto global_type_error;
> +				}
> +				len = ustcomm_recv_unix_sock(sock,
> +						one_global_type->u.ctf_structure.fields,
> +						entry_len);
> +				DBG("Received fields for struct %s.\n",
> one_global_type->u.ctf_structure.name);
> +				if (len > 0 && len != entry_len) {
> +					len = -EIO;
> +					goto global_type_error;
> +				}
> +				if (len == 0) {
> +					len = -EPIPE;
> +					goto global_type_error;
> +				}
> +				if (len < 0) {
> +					goto global_type_error;
> +				}
> +				break;
> +			}
>  			default:
>  				break;
>  			}
> --
> 1.9.1
> 
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev@lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
> 

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFC Patch Ust 2/5] Serialize the CTF global structures for ust-comm
       [not found] <1395845232-17669-1-git-send-email-gbastien+lttng@versatic.net>
@ 2014-03-26 14:47 ` Geneviève Bastien
       [not found] ` <1395845232-17669-3-git-send-email-gbastien+lttng@versatic.net>
  1 sibling, 0 replies; 7+ messages in thread
From: Geneviève Bastien @ 2014-03-26 14:47 UTC (permalink / raw)
  To: lttng-dev

It flatten the global types so that global types used by other global types
all belong to the event at serialization. This avoids recursive calls to the
send and receive functions and simplifies error handling (no recursive frees).

Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
---
 liblttng-ust-comm/lttng-ust-comm.c | 170 +++++++++++++++++++++++++++++++++----
 liblttng-ust-ctl/ustctl.c          |  26 ++++++
 2 files changed, 179 insertions(+), 17 deletions(-)

diff --git a/liblttng-ust-comm/lttng-ust-comm.c b/liblttng-ust-comm/lttng-ust-comm.c
index bc22130..90274c4 100644
--- a/liblttng-ust-comm/lttng-ust-comm.c
+++ b/liblttng-ust-comm/lttng-ust-comm.c
@@ -742,6 +742,7 @@ int serialize_basic_type(enum ustctl_abstract_types *uatype,
 	}
 	case atype_array:
 	case atype_sequence:
+	case atype_structure:
 	default:
 		return -EINVAL;
 	}
@@ -800,6 +801,14 @@ int serialize_one_type(struct ustctl_type *ut, const struct lttng_type *lt)
 		ut->atype = ustctl_atype_sequence;
 		break;
 	}
+	case atype_structure:
+	{
+		strncpy(ut->u.structure.name, lt->u.structure.name,
+						LTTNG_UST_SYM_NAME_LEN);
+		ut->u.structure.name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
+		ut->atype = ustctl_atype_structure;
+		break;
+	}
 	default:
 		return -EINVAL;
 	}
@@ -892,25 +901,82 @@ int serialize_enum(struct ustctl_enum *uenum,
 }
 
 static
-int serialize_global_type_decl(size_t *_nr_write_global_type_decl,
-		struct ustctl_global_type_decl **ustctl_global_type,
+int serialize_structure(struct ustctl_structure *ustruct,
+		const struct lttng_structure *lstruct)
+{
+	int ret;
+
+	strncpy(ustruct->name, lstruct->name, LTTNG_UST_SYM_NAME_LEN);
+	ustruct->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
+
+	/* Serialize the fields */
+	if (lstruct->nr_fields > 0) {
+		ret = serialize_fields(&ustruct->nr_fields, &ustruct->fields,
+				lstruct->nr_fields,	lstruct->fields);
+		if (ret) {
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+static size_t get_child_global_type_count(size_t nr_global_type_decl,
+		const struct lttng_global_type_decl *lttng_global_type)
+{
+	size_t total_global_types = 0;
+	int i;
+	const struct lttng_global_type_decl *lg;
+
+	for (i = 0; i < nr_global_type_decl; i++) {
+		lg = &lttng_global_type[i];
+
+		if (lg->nowrite)
+			continue;
+
+		/* Count the global types in children as well */
+		switch (lg->mtype) {
+		case mtype_structure:
+		{
+			const struct lttng_structure *ls;
+
+			ls = lg->u.ctf_structure;
+			/* Add the number of global types it contains and the count of its own children */
+			if (ls->nr_global_type_decl > 0) {
+				total_global_types += ls->nr_global_type_decl;
+				total_global_types += get_child_global_type_count(ls->nr_global_type_decl,
+								ls->global_type_decl);
+			}
+			break;
+		}
+		case mtype_enum:
+		default:
+			break;
+		}
+	}
+
+	return total_global_types;
+}
+
+/*
+ * When this method is called, index is the next index to write to and the
+ * ustctl_global_type structure is already initialized and will not overflow.
+ *
+ * The global type declarations are flattened at serialization to avoid
+ * needing to do recursive frees on error.
+ */
+static int _serialize_global_type_decl(size_t *index,
+		struct ustctl_global_type_decl *global_type_decl,
 		size_t nr_global_type_decl,
 		const struct lttng_global_type_decl *lttng_global_type)
 {
-	struct ustctl_global_type_decl *global_type_decl;
 	int i, ret;
-	size_t nr_write_global_type_decl = 0;
-
-	global_type_decl = zmalloc(nr_global_type_decl
-					* sizeof(*global_type_decl));
-	if (!global_type_decl)
-		return -ENOMEM;
 
 	for (i = 0; i < nr_global_type_decl; i++) {
 		struct ustctl_global_type_decl *f;
 		const struct lttng_global_type_decl *lf;
 
-		f = &global_type_decl[nr_write_global_type_decl];
+		f = &global_type_decl[*index];
 		lf = &lttng_global_type[i];
 
 		/* skip 'nowrite' fields */
@@ -928,18 +994,66 @@ int serialize_global_type_decl(size_t *_nr_write_global_type_decl,
 			le = lf->u.ctf_enum;
 			ret = serialize_enum(ue, le);
 			if (ret)
-				goto error;
+				return ret;
 
 			f->mtype = ustctl_mtype_enum;
 			break;
 		}
+		case mtype_structure:
+		{
+			struct ustctl_structure *us;
+			const struct lttng_structure *ls;
+
+			/* Serialize children global types first */
+			ls = lf->u.ctf_structure;
+			ret = _serialize_global_type_decl(index,
+					global_type_decl,
+					ls->nr_global_type_decl,
+					ls->global_type_decl);
+			if (ret)
+				return ret;
+
+			/* Reinitialize f since the index may have changed */
+			f = &global_type_decl[*index];
+			us = &f->u.ctf_structure;
+
+			ret = serialize_structure(us, ls);
+			if (ret)
+				return ret;
+
+			f->mtype = ustctl_mtype_structure;
+			break;
+		}
 		default:
-			ret = -EINVAL;
-			goto error;
+			return -EINVAL;
 		}
 
-		nr_write_global_type_decl++;
+		*index = *index + 1;
 	}
+	return 0;
+}
+
+static
+int serialize_global_type_decl(size_t *_nr_write_global_type_decl,
+		struct ustctl_global_type_decl **ustctl_global_type,
+		size_t nr_global_type_decl,
+		const struct lttng_global_type_decl *lttng_global_type)
+{
+	struct ustctl_global_type_decl *global_type_decl;
+	int i, ret;
+	size_t nr_write_global_type_decl = 0;
+	size_t nr_child_global_type_cnt = get_child_global_type_count(nr_global_type_decl,
+							lttng_global_type);
+
+	global_type_decl = zmalloc((nr_global_type_decl + nr_child_global_type_cnt)
+					* sizeof(*global_type_decl));
+	if (!global_type_decl)
+		return -ENOMEM;
+
+	ret = _serialize_global_type_decl(&nr_write_global_type_decl, global_type_decl,
+			nr_global_type_decl, lttng_global_type);
+	if (ret)
+		goto error;
 
 	*_nr_write_global_type_decl = nr_write_global_type_decl;
 	*ustctl_global_type = global_type_decl;
@@ -954,6 +1068,9 @@ error:
 		case ustctl_mtype_enum:
 			free(m->u.ctf_enum.entries);
 			break;
+		case ustctl_mtype_structure:
+			free(m->u.ctf_structure.fields);
+			break;
 		default:
 			break;
 		}
@@ -1158,15 +1275,31 @@ int ustcomm_register_event(int sock,
 				}
 				break;
 			}
+			case ustctl_mtype_structure:
+			{
+				int field_len = one_global_type->u.ctf_structure.nr_fields * sizeof(*one_global_type->u.ctf_structure.fields);
+
+				/* Send the fields */
+				DBG("Sending fields for global type structure %s.\n",
+						one_global_type->u.ctf_structure.name);
+				len = ustcomm_send_unix_sock(sock, one_global_type->u.ctf_structure.fields, field_len);
+				free(one_global_type->u.ctf_structure.fields);
+				one_global_type->u.ctf_structure.fields = NULL;
+				if (len > 0 && len != field_len) {
+					goto error_global_type;
+				}
+				if (len < 0) {
+					goto error_global_type;
+				}
+				break;
+			}
 			default:
 				break;
 			}
 		}
-		free(global_type_decl);
 
-	} else {
-		free(global_type_decl);
 	}
+	free(global_type_decl);
 
 	/* receive reply */
 	len = ustcomm_recv_unix_sock(sock, &reply, sizeof(reply));
@@ -1212,6 +1345,9 @@ error_global_type:
 		case ustctl_mtype_enum:
 			free(one_global_type->u.ctf_enum.entries);
 			break;
+		case ustctl_mtype_structure:
+			free(one_global_type->u.ctf_structure.fields);
+			break;
 		default:
 			break;
 		}
diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c
index a181e62..3100f1b 100644
--- a/liblttng-ust-ctl/ustctl.c
+++ b/liblttng-ust-ctl/ustctl.c
@@ -1896,6 +1896,32 @@ int ustctl_recv_register_event(int sock,
 				}
 				break;
 			}
+			case ustctl_mtype_structure:
+			{
+				int entry_len = one_global_type->u.ctf_structure.nr_fields * sizeof(*one_global_type->u.ctf_structure.fields);
+				/* Receive the entries */
+				one_global_type->u.ctf_structure.fields = zmalloc(entry_len);
+				if (!one_global_type->u.ctf_structure.fields) {
+					len = -ENOMEM;
+					goto global_type_error;
+				}
+				len = ustcomm_recv_unix_sock(sock,
+						one_global_type->u.ctf_structure.fields,
+						entry_len);
+				DBG("Received fields for struct %s.\n", one_global_type->u.ctf_structure.name);
+				if (len > 0 && len != entry_len) {
+					len = -EIO;
+					goto global_type_error;
+				}
+				if (len == 0) {
+					len = -EPIPE;
+					goto global_type_error;
+				}
+				if (len < 0) {
+					goto global_type_error;
+				}
+				break;
+			}
 			default:
 				break;
 			}
-- 
1.9.1


_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-05-02 13:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-02 13:40 [RFC Patch Ust 2/5] Serialize the CTF global structures for ust-comm Thibault, Daniel
     [not found] <1395845232-17669-1-git-send-email-gbastien+lttng@versatic.net>
2014-03-26 14:47 ` Geneviève Bastien
     [not found] ` <1395845232-17669-3-git-send-email-gbastien+lttng@versatic.net>
2014-04-09 15:42   ` Mathieu Desnoyers
     [not found]   ` <224451157.1253.1397058138828.JavaMail.zimbra@efficios.com>
2014-04-09 17:33     ` Geneviève Bastien
     [not found]     ` <53458452.8030905@versatic.net>
2014-04-27  8:34       ` Mathieu Desnoyers
     [not found]       ` <2087397408.8083.1398587642565.JavaMail.zimbra@efficios.com>
2014-05-01  1:05         ` Geneviève Bastien
     [not found]         ` <53619DDF.5060909@versatic.net>
2014-05-02  9:29           ` Mathieu Desnoyers

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.