All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libtraceevent: Add new xenomai plugin to print param_ex correctly
@ 2022-01-18  2:47 Hongzhan Chen
  2022-01-18  8:32 ` Bezdeka, Florian
  0 siblings, 1 reply; 4+ messages in thread
From: Hongzhan Chen @ 2022-01-18  2:47 UTC (permalink / raw)
  To: xenomai, jan.kiszka

For cobalt thread, there is special struct param_ex data stored in
data record, we need to parse and print its content out correctly
to hint user.

Signed-off-by: Hongzhan Chen <hongzhan.chen@intel.com>

diff --git a/plugins/Makefile b/plugins/Makefile
index 4c8cb17..dda584f 100644
--- a/plugins/Makefile
+++ b/plugins/Makefile
@@ -95,6 +95,7 @@ PLUGINS += plugin_sched_switch.so
 PLUGINS += plugin_function.so
 PLUGINS += plugin_futex.so
 PLUGINS += plugin_xen.so
+PLUGINS += plugin_xenomai_schedparams.so
 PLUGINS += plugin_scsi.so
 PLUGINS += plugin_cfg80211.so
 PLUGINS += plugin_tlb.so
diff --git a/plugins/plugin_xenomai_schedparams.c b/plugins/plugin_xenomai_schedparams.c
new file mode 100644
index 0000000..28d7583
--- /dev/null
+++ b/plugins/plugin_xenomai_schedparams.c
@@ -0,0 +1,201 @@
+// SPDX-License-Identifier: LGPL-2.1
+/*
+ * Copyright (C) 2021 Intel Inc, Hongzhan Chen <hongzhan.chen@intel.com>
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <linux/sched.h>
+
+#include "event-parse.h"
+#include "trace-seq.h"
+
+
+#define SCHED_SPORADIC		10
+#define SCHED_TP		11
+#define SCHED_QUOTA		12
+
+#define SCHED_COBALT		42
+#define SCHED_WEAK		43
+
+struct __sched_ss_param {
+	int __sched_low_priority;
+	struct timespec __sched_repl_period;
+	struct timespec __sched_init_budget;
+	int __sched_max_repl;
+};
+
+struct __sched_rr_param {
+	struct timespec __sched_rr_quantum;
+};
+
+struct __sched_tp_param {
+	int __sched_partition;
+};
+
+struct __sched_quota_param {
+	int __sched_group;
+};
+
+struct sched_param_ex {
+	int sched_priority;
+	union {
+		struct __sched_ss_param ss;
+		struct __sched_rr_param rr;
+		struct __sched_tp_param tp;
+		struct __sched_quota_param quota;
+	} sched_u;
+};
+
+#define sched_quota_group	sched_u.quota.__sched_group
+#define sched_tp_partition	sched_u.tp.__sched_partition
+#define sched_ss_low_priority	sched_u.ss.__sched_low_priority
+#define sched_ss_repl_period	sched_u.ss.__sched_repl_period
+#define sched_ss_init_budget	sched_u.ss.__sched_init_budget
+#define sched_ss_max_repl	sched_u.ss.__sched_max_repl
+
+static void write_policy(struct trace_seq *p, int policy)
+{
+	trace_seq_printf(p, "policy=");
+
+	switch (policy) {
+	case SCHED_QUOTA:
+		trace_seq_printf(p, "quota ");
+		break;
+	case SCHED_TP:
+		trace_seq_printf(p, "tp ");
+		break;
+	case SCHED_NORMAL:
+		trace_seq_printf(p, "normal ");
+		break;
+	case SCHED_SPORADIC:
+		trace_seq_printf(p, "sporadic ");
+		break;
+	case SCHED_RR:
+		trace_seq_printf(p, "rr ");
+		break;
+	case SCHED_FIFO:
+		trace_seq_printf(p, "fifo ");
+		break;
+	case SCHED_COBALT:
+		trace_seq_printf(p, "cobalt ");
+		break;
+	case SCHED_WEAK:
+		trace_seq_printf(p, "weak ");
+		break;
+	default:
+		trace_seq_printf(p, "unknown ");
+		break;
+	}
+}
+
+/* save param */
+static void write_param(struct tep_format_field *field,
+				struct tep_record *record,
+				struct trace_seq *p, int policy)
+{
+	int offset;
+	struct sched_param_ex *params;
+
+	offset = field->offset;
+
+	if (!strncmp(field->type, "__data_loc", 10)) {
+		unsigned long long v;
+
+		if (tep_read_number_field(field, record->data, &v)) {
+			trace_seq_printf(p, "invalid_data_loc");
+			return;
+		}
+		offset = v & 0xffff;
+
+	}
+
+	params = (struct sched_param_ex *)((char *)record->data + offset);
+
+	trace_seq_printf(p, "param: { ");
+
+	switch (policy) {
+	case SCHED_QUOTA:
+		trace_seq_printf(p, "priority=%d, group=%d",
+				 params->sched_priority,
+				 params->sched_quota_group);
+		break;
+	case SCHED_TP:
+		trace_seq_printf(p, "priority=%d, partition=%d",
+				 params->sched_priority,
+				 params->sched_tp_partition);
+		break;
+	case SCHED_NORMAL:
+		break;
+	case SCHED_SPORADIC:
+		trace_seq_printf(p, "priority=%d, low_priority=%d, ",
+				 params->sched_priority,
+				 params->sched_ss_low_priority);
+
+		trace_seq_printf(p, "budget=(%ld.%09ld), period=(%ld.%09ld), "
+				 params->sched_ss_init_budget.tv_sec,
+				 params->sched_ss_init_budget.tv_nsec);
+
+		trace_seq_printf(p, "maxrepl=%d",
+				 params->sched_ss_max_repl);
+		break;
+	case SCHED_RR:
+	case SCHED_FIFO:
+	case SCHED_COBALT:
+	case SCHED_WEAK:
+	default:
+		trace_seq_printf(p, "priority=%d", params->sched_priority);
+		break;
+	}
+	trace_seq_printf(p, " }");
+	trace_seq_putc(p, '\0');
+
+}
+
+static int cobalt_schedparam_handler(struct trace_seq *s,
+				struct tep_record *record,
+				struct tep_event *event, void *context)
+{
+	struct tep_format_field *field;
+	unsigned long long val;
+
+	if (tep_get_field_val(s, event, "pth", record, &val, 1))
+		return trace_seq_putc(s, '!');
+	trace_seq_puts(s, "pth: ");
+	trace_seq_printf(s, "0x%08llx ", val);
+
+	if (tep_get_field_val(s, event, "policy", record, &val, 1) == 0)
+		write_policy(s, val);
+
+	field = tep_find_field(event, "param_ex");
+	if (field)
+		write_param(field, record, s, val);
+
+	return 0;
+}
+
+int TEP_PLUGIN_LOADER(struct tep_handle *tep)
+{
+	tep_register_event_handler(tep, -1, "cobalt_posix", "cobalt_pthread_setschedparam",
+					cobalt_schedparam_handler, NULL);
+
+	tep_register_event_handler(tep, -1, "cobalt_posix", "cobalt_pthread_getschedparam",
+					cobalt_schedparam_handler, NULL);
+
+	tep_register_event_handler(tep, -1, "cobalt_posix", "cobalt_pthread_create",
+					cobalt_schedparam_handler, NULL);
+
+	return 0;
+}
+
+void TEP_PLUGIN_UNLOADER(struct tep_handle *tep)
+{
+	tep_unregister_event_handler(tep, -1, "cobalt_posix", "cobalt_pthread_setschedparam",
+					cobalt_schedparam_handler, NULL);
+
+	tep_unregister_event_handler(tep, -1, "cobalt_posix", "cobalt_pthread_getschedparam",
+					cobalt_schedparam_handler, NULL);
+
+	tep_unregister_event_handler(tep, -1, "cobalt_posix", "cobalt_pthread_create",
+					cobalt_schedparam_handler, NULL);
+}
-- 
2.17.1



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

* Re: [PATCH] libtraceevent: Add new xenomai plugin to print param_ex correctly
  2022-01-18  2:47 [PATCH] libtraceevent: Add new xenomai plugin to print param_ex correctly Hongzhan Chen
@ 2022-01-18  8:32 ` Bezdeka, Florian
  2022-01-19  1:25   ` Chen, Hongzhan
  0 siblings, 1 reply; 4+ messages in thread
From: Bezdeka, Florian @ 2022-01-18  8:32 UTC (permalink / raw)
  To: hongzhan.chen, xenomai, jan.kiszka

On Mon, 2022-01-17 at 21:47 -0500, Hongzhan Chen via Xenomai wrote:
> For cobalt thread, there is special struct param_ex data stored in
> data record, we need to parse and print its content out correctly
> to hint user.
> 
> Signed-off-by: Hongzhan Chen <hongzhan.chen@intel.com>
> 
> diff --git a/plugins/Makefile b/plugins/Makefile
> index 4c8cb17..dda584f 100644
> --- a/plugins/Makefile
> +++ b/plugins/Makefile
> @@ -95,6 +95,7 @@ PLUGINS += plugin_sched_switch.so
>  PLUGINS += plugin_function.so
>  PLUGINS += plugin_futex.so
>  PLUGINS += plugin_xen.so
> +PLUGINS += plugin_xenomai_schedparams.so
>  PLUGINS += plugin_scsi.so
>  PLUGINS += plugin_cfg80211.so
>  PLUGINS += plugin_tlb.so
> diff --git a/plugins/plugin_xenomai_schedparams.c b/plugins/plugin_xenomai_schedparams.c
> new file mode 100644
> index 0000000..28d7583
> --- /dev/null
> +++ b/plugins/plugin_xenomai_schedparams.c
> @@ -0,0 +1,201 @@
> +// SPDX-License-Identifier: LGPL-2.1
> +/*
> + * Copyright (C) 2021 Intel Inc, Hongzhan Chen <hongzhan.chen@intel.com>
> + */
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <linux/sched.h>
> +
> +#include "event-parse.h"
> +#include "trace-seq.h"
> +
> +
> +#define SCHED_SPORADIC		10
> +#define SCHED_TP		11
> +#define SCHED_QUOTA		12
> +
> +#define SCHED_COBALT		42
> +#define SCHED_WEAK		43
> +
> +struct __sched_ss_param {
> +	int __sched_low_priority;
> +	struct timespec __sched_repl_period;
> +	struct timespec __sched_init_budget;
> +	int __sched_max_repl;
> +};
> +
> +struct __sched_rr_param {
> +	struct timespec __sched_rr_quantum;
> +};
> +
> +struct __sched_tp_param {
> +	int __sched_partition;
> +};
> +
> +struct __sched_quota_param {
> +	int __sched_group;
> +};
> +
> +struct sched_param_ex {
> +	int sched_priority;
> +	union {
> +		struct __sched_ss_param ss;
> +		struct __sched_rr_param rr;
> +		struct __sched_tp_param tp;
> +		struct __sched_quota_param quota;
> +	} sched_u;
> +};

Looks like a code duplication. Everything around sched_param_ex is
still y2038 affected and might need to change within the Xenomai
codebase. Not sure if it is really a good idea to duplicate such
affected type definitions.

Btw: This patch is not targeting the xenomai code base, right?

> +
> +#define sched_quota_group	sched_u.quota.__sched_group
> +#define sched_tp_partition	sched_u.tp.__sched_partition
> +#define sched_ss_low_priority	sched_u.ss.__sched_low_priority
> +#define sched_ss_repl_period	sched_u.ss.__sched_repl_period
> +#define sched_ss_init_budget	sched_u.ss.__sched_init_budget
> +#define sched_ss_max_repl	sched_u.ss.__sched_max_repl
> +
> +static void write_policy(struct trace_seq *p, int policy)
> +{
> +	trace_seq_printf(p, "policy=");
> +
> +	switch (policy) {
> +	case SCHED_QUOTA:
> +		trace_seq_printf(p, "quota ");
> +		break;
> +	case SCHED_TP:
> +		trace_seq_printf(p, "tp ");
> +		break;
> +	case SCHED_NORMAL:
> +		trace_seq_printf(p, "normal ");
> +		break;
> +	case SCHED_SPORADIC:
> +		trace_seq_printf(p, "sporadic ");
> +		break;
> +	case SCHED_RR:
> +		trace_seq_printf(p, "rr ");
> +		break;
> +	case SCHED_FIFO:
> +		trace_seq_printf(p, "fifo ");
> +		break;
> +	case SCHED_COBALT:
> +		trace_seq_printf(p, "cobalt ");
> +		break;
> +	case SCHED_WEAK:
> +		trace_seq_printf(p, "weak ");
> +		break;
> +	default:
> +		trace_seq_printf(p, "unknown ");
> +		break;
> +	}
> +}
> +
> +/* save param */
> +static void write_param(struct tep_format_field *field,
> +				struct tep_record *record,
> +				struct trace_seq *p, int policy)
> +{
> +	int offset;
> +	struct sched_param_ex *params;
> +
> +	offset = field->offset;
> +
> +	if (!strncmp(field->type, "__data_loc", 10)) {
> +		unsigned long long v;
> +
> +		if (tep_read_number_field(field, record->data, &v)) {
> +			trace_seq_printf(p, "invalid_data_loc");
> +			return;
> +		}
> +		offset = v & 0xffff;
> +
> +	}
> +
> +	params = (struct sched_param_ex *)((char *)record->data + offset);
> +
> +	trace_seq_printf(p, "param: { ");
> +
> +	switch (policy) {
> +	case SCHED_QUOTA:
> +		trace_seq_printf(p, "priority=%d, group=%d",
> +				 params->sched_priority,
> +				 params->sched_quota_group);
> +		break;
> +	case SCHED_TP:
> +		trace_seq_printf(p, "priority=%d, partition=%d",
> +				 params->sched_priority,
> +				 params->sched_tp_partition);
> +		break;
> +	case SCHED_NORMAL:
> +		break;
> +	case SCHED_SPORADIC:
> +		trace_seq_printf(p, "priority=%d, low_priority=%d, ",
> +				 params->sched_priority,
> +				 params->sched_ss_low_priority);
> +
> +		trace_seq_printf(p, "budget=(%ld.%09ld), period=(%ld.%09ld), "
> +				 params->sched_ss_init_budget.tv_sec,
> +				 params->sched_ss_init_budget.tv_nsec);
> +
> +		trace_seq_printf(p, "maxrepl=%d",
> +				 params->sched_ss_max_repl);
> +		break;
> +	case SCHED_RR:
> +	case SCHED_FIFO:
> +	case SCHED_COBALT:
> +	case SCHED_WEAK:
> +	default:
> +		trace_seq_printf(p, "priority=%d", params->sched_priority);
> +		break;
> +	}
> +	trace_seq_printf(p, " }");
> +	trace_seq_putc(p, '\0');
> +
> +}
> +
> +static int cobalt_schedparam_handler(struct trace_seq *s,
> +				struct tep_record *record,
> +				struct tep_event *event, void *context)
> +{
> +	struct tep_format_field *field;
> +	unsigned long long val;
> +
> +	if (tep_get_field_val(s, event, "pth", record, &val, 1))
> +		return trace_seq_putc(s, '!');
> +	trace_seq_puts(s, "pth: ");
> +	trace_seq_printf(s, "0x%08llx ", val);
> +
> +	if (tep_get_field_val(s, event, "policy", record, &val, 1) == 0)
> +		write_policy(s, val);
> +
> +	field = tep_find_field(event, "param_ex");
> +	if (field)
> +		write_param(field, record, s, val);
> +
> +	return 0;
> +}
> +
> +int TEP_PLUGIN_LOADER(struct tep_handle *tep)
> +{
> +	tep_register_event_handler(tep, -1, "cobalt_posix", "cobalt_pthread_setschedparam",
> +					cobalt_schedparam_handler, NULL);
> +
> +	tep_register_event_handler(tep, -1, "cobalt_posix", "cobalt_pthread_getschedparam",
> +					cobalt_schedparam_handler, NULL);
> +
> +	tep_register_event_handler(tep, -1, "cobalt_posix", "cobalt_pthread_create",
> +					cobalt_schedparam_handler, NULL);
> +
> +	return 0;
> +}
> +
> +void TEP_PLUGIN_UNLOADER(struct tep_handle *tep)
> +{
> +	tep_unregister_event_handler(tep, -1, "cobalt_posix", "cobalt_pthread_setschedparam",
> +					cobalt_schedparam_handler, NULL);
> +
> +	tep_unregister_event_handler(tep, -1, "cobalt_posix", "cobalt_pthread_getschedparam",
> +					cobalt_schedparam_handler, NULL);
> +
> +	tep_unregister_event_handler(tep, -1, "cobalt_posix", "cobalt_pthread_create",
> +					cobalt_schedparam_handler, NULL);
> +}


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

* RE: [PATCH] libtraceevent: Add new xenomai plugin to print param_ex correctly
  2022-01-18  8:32 ` Bezdeka, Florian
@ 2022-01-19  1:25   ` Chen, Hongzhan
  2022-01-25 16:44     ` Jan Kiszka
  0 siblings, 1 reply; 4+ messages in thread
From: Chen, Hongzhan @ 2022-01-19  1:25 UTC (permalink / raw)
  To: Bezdeka, Florian, xenomai, Kiszka, Jan



>
>> +/*
>> + * Copyright (C) 2021 Intel Inc, Hongzhan Chen <hongzhan.chen@intel.com>
>> + */
>> +#include <stdio.h>
>> +#include <stdlib.h>
>> +#include <string.h>
>> +#include <linux/sched.h>
>> +
>> +#include "event-parse.h"
>> +#include "trace-seq.h"
>> +
>> +
>> +#define SCHED_SPORADIC		10
>> +#define SCHED_TP		11
>> +#define SCHED_QUOTA		12
>> +
>> +#define SCHED_COBALT		42
>> +#define SCHED_WEAK		43
>> +
>> +struct __sched_ss_param {
>> +	int __sched_low_priority;
>> +	struct timespec __sched_repl_period;
>> +	struct timespec __sched_init_budget;
>> +	int __sched_max_repl;
>> +};
>> +
>> +struct __sched_rr_param {
>> +	struct timespec __sched_rr_quantum;
>> +};
>> +
>> +struct __sched_tp_param {
>> +	int __sched_partition;
>> +};
>> +
>> +struct __sched_quota_param {
>> +	int __sched_group;
>> +};
>> +
>> +struct sched_param_ex {
>> +	int sched_priority;
>> +	union {
>> +		struct __sched_ss_param ss;
>> +		struct __sched_rr_param rr;
>> +		struct __sched_tp_param tp;
>> +		struct __sched_quota_param quota;
>> +	} sched_u;
>> +};
>
>Looks like a code duplication. Everything around sched_param_ex is
>still y2038 affected and might need to change within the Xenomai
>codebase. Not sure if it is really a good idea to duplicate such
>affected type definitions.
>
>Btw: This patch is not targeting the xenomai code base, right?  

No,the patch is not for xenomai itself but for libtraceevent which is pure linux user
space lib used by kernel-shark or trace-cmd. But according to Jan, we need to maintain
them in xenomai tree. Basically , we will create new correspoding folder such
as libtraceevent or kernel-shark under xenomai tree and also related documents 
to tell user how to use them with libtraceevent or kernel-shark but it would not compile 
together with xenomai. 
It is to fix part of issue https://gitlab.com/Xenomai/xenomai-hacker-space/-/issues/33.

you are right that we had better not to duplicate them but I can not find a better way 
to share them between xenomai kernel and Linux userspace under current situation.

Regards

Hongzhan Chen
                                        



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

* Re: [PATCH] libtraceevent: Add new xenomai plugin to print param_ex correctly
  2022-01-19  1:25   ` Chen, Hongzhan
@ 2022-01-25 16:44     ` Jan Kiszka
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Kiszka @ 2022-01-25 16:44 UTC (permalink / raw)
  To: Chen, Hongzhan, Bezdeka, Florian, xenomai

On 19.01.22 02:25, Chen, Hongzhan wrote:
> 
> 
>>
>>> +/*
>>> + * Copyright (C) 2021 Intel Inc, Hongzhan Chen <hongzhan.chen@intel.com>
>>> + */
>>> +#include <stdio.h>
>>> +#include <stdlib.h>
>>> +#include <string.h>
>>> +#include <linux/sched.h>
>>> +
>>> +#include "event-parse.h"
>>> +#include "trace-seq.h"
>>> +
>>> +
>>> +#define SCHED_SPORADIC		10
>>> +#define SCHED_TP		11
>>> +#define SCHED_QUOTA		12
>>> +
>>> +#define SCHED_COBALT		42
>>> +#define SCHED_WEAK		43
>>> +
>>> +struct __sched_ss_param {
>>> +	int __sched_low_priority;
>>> +	struct timespec __sched_repl_period;
>>> +	struct timespec __sched_init_budget;
>>> +	int __sched_max_repl;
>>> +};
>>> +
>>> +struct __sched_rr_param {
>>> +	struct timespec __sched_rr_quantum;
>>> +};
>>> +
>>> +struct __sched_tp_param {
>>> +	int __sched_partition;
>>> +};
>>> +
>>> +struct __sched_quota_param {
>>> +	int __sched_group;
>>> +};
>>> +
>>> +struct sched_param_ex {
>>> +	int sched_priority;
>>> +	union {
>>> +		struct __sched_ss_param ss;
>>> +		struct __sched_rr_param rr;
>>> +		struct __sched_tp_param tp;
>>> +		struct __sched_quota_param quota;
>>> +	} sched_u;
>>> +};
>>
>> Looks like a code duplication. Everything around sched_param_ex is
>> still y2038 affected and might need to change within the Xenomai
>> codebase. Not sure if it is really a good idea to duplicate such
>> affected type definitions.
>>
>> Btw: This patch is not targeting the xenomai code base, right?
> 
> No,the patch is not for xenomai itself but for libtraceevent which is pure linux user
> space lib used by kernel-shark or trace-cmd. But according to Jan, we need to maintain
> them in xenomai tree. Basically , we will create new correspoding folder such
> as libtraceevent or kernel-shark under xenomai tree and also related documents
> to tell user how to use them with libtraceevent or kernel-shark but it would not compile
> together with xenomai.
> It is to fix part of issue https://gitlab.com/Xenomai/xenomai-hacker-space/-/issues/33.

OK, a README would be fine for the start, though I expect that we will 
eventually be able to plug the build into the Xenomai autoconf/automake 
as well. We do want this to be generated along the regular build, 
provided the user installed the required dependencies and/or enabled 
this feature. Would also ease packaging for debian, and building for 
xenomai-image (enlightened "trace-cmd report" could work even on the 
targets).

> 
> you are right that we had better not to duplicate them but I can not find a better way
> to share them between xenomai kernel and Linux userspace under current situation.

Once the plugin is integrated into the Xenomai code base, including 
existing headers should be even easier, specifically if they do not 
belong to our devel package.

Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux


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

end of thread, other threads:[~2022-01-25 16:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-18  2:47 [PATCH] libtraceevent: Add new xenomai plugin to print param_ex correctly Hongzhan Chen
2022-01-18  8:32 ` Bezdeka, Florian
2022-01-19  1:25   ` Chen, Hongzhan
2022-01-25 16:44     ` Jan Kiszka

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.