All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] sched_deadline/cyclicdeadline add tracelimit
@ 2022-06-17  6:40 Song Chen
  2022-06-29  6:58 ` Daniel Wagner
  0 siblings, 1 reply; 7+ messages in thread
From: Song Chen @ 2022-06-17  6:40 UTC (permalink / raw)
  To: linux-rt-users, jkacur; +Cc: williams, Song Chen

cyclictest has tracelimit to stop running when max latency
is higher than threshold but cyclicdeadline doesn't.

Therefore, tracelimit is introduced to cyclicdeadline in
this commit, once max latency is over, test stops and log
prints at the bottom of the ftrace file.

Signed-off-by: Song Chen <chensong_2000@189.cn>

---
v2:
1, disable ftrace when hitting thresold
---
 src/sched_deadline/cyclicdeadline.c | 48 ++++++++++++++++++++++++++---
 1 file changed, 44 insertions(+), 4 deletions(-)

diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
index d865fa3..f0f4008 100644
--- a/src/sched_deadline/cyclicdeadline.c
+++ b/src/sched_deadline/cyclicdeadline.c
@@ -80,7 +80,11 @@ struct sched_data {
 };
 
 static int shutdown;
-
+static int tracelimit = 0;
+static int trace_marker = 0;
+static pthread_mutex_t break_thread_id_lock = PTHREAD_MUTEX_INITIALIZER;
+static pid_t break_thread_id = 0;
+static uint64_t break_thread_value = 0;
 static pthread_barrier_t barrier;
 
 static int cpu_count;
@@ -667,6 +671,10 @@ static void teardown(void)
 
 	destroy_cpuset(CPUSET_ALL, 0);
 	destroy_cpuset(CPUSET_LOCAL, 1);
+
+	/* close any tracer file descriptors */
+	disable_trace_mark();
+
 }
 
 static void usage(int error)
@@ -689,6 +697,7 @@ static void usage(int error)
 	       "                           (default 500us).\n"
 	       "-t NUM   --threads         The number of threads to run as deadline (default 1).\n"
 	       "-q       --quiet           print a summary only on exit\n"
+	       "-b USEC  --breaktrace=USEC send break trace command when latency > USEC\n"
 	       );
 	exit(error);
 }
@@ -825,6 +834,18 @@ void *run_deadline(void *data)
 
 	while (!shutdown) {
 		period = do_runtime(tid, sd, period);
+		if (tracelimit && (stat->max > tracelimit)) {
+			shutdown++;
+			pthread_mutex_lock(&break_thread_id_lock);
+			if (break_thread_id == 0) {
+				break_thread_id = stat->tid;
+				break_thread_value = stat->max;
+				tracemark( "hit latency threshold (%lld > %d)",
+						 (unsigned long long) stat->max, tracelimit);
+			}
+			pthread_mutex_unlock(&break_thread_id_lock);
+			break;
+		}
 		sched_yield();
 	}
 	ret = sched_getattr(0, &attr, sizeof(attr), 0);
@@ -1063,9 +1084,10 @@ static void write_stats(FILE *f, void *data)
 	fprintf(f, "  }\n");
 }
 
-enum options_valud {
+enum options_values {
 	OPT_AFFINITY=1, OPT_DURATION, OPT_HELP, OPT_INTERVAL,
-	OPT_JSON, OPT_STEP, OPT_THREADS, OPT_QUIET
+	OPT_JSON, OPT_STEP, OPT_THREADS, OPT_QUIET,
+	OPT_BREAKTRACE, OPT_TRACEMARK,
 };
 
 int main(int argc, char **argv)
@@ -1104,9 +1126,11 @@ int main(int argc, char **argv)
 			{ "step",	required_argument,	NULL,	OPT_STEP },
 			{ "threads",	required_argument,	NULL,	OPT_THREADS },
 			{ "quiet",	no_argument,		NULL,	OPT_QUIET },
+			{ "breaktrace",       required_argument, NULL, OPT_BREAKTRACE },
+			{ "tracemark",	     no_argument,	NULL, OPT_TRACEMARK },
 			{ NULL,		0,			NULL,	0   },
 		};
-		c = getopt_long(argc, argv, "a::c:D:hi:s:t:q", options, NULL);
+		c = getopt_long(argc, argv, "a::c:D:hi:s:t:b:q", options, NULL);
 		if (c == -1)
 			break;
 		switch (c) {
@@ -1141,6 +1165,10 @@ int main(int argc, char **argv)
 		case 'D':
 			duration = parse_time_string(optarg);
 			break;
+		case 'b':
+		case OPT_BREAKTRACE:
+			tracelimit = atoi(optarg);
+			break;
 		case OPT_QUIET:
 		case 'q':
 			quiet = 1;
@@ -1149,6 +1177,9 @@ int main(int argc, char **argv)
 		case 'h':
 			usage(0);
 			break;
+		case OPT_TRACEMARK:
+			trace_marker = 1;
+			break;
 		default:
 			usage(1);
 		}
@@ -1186,6 +1217,8 @@ int main(int argc, char **argv)
 		warn("mlockall");
 
 	setup_ftrace_marker();
+	if (tracelimit && trace_marker)
+		enable_trace_mark();
 
 	thread = calloc(nr_threads, sizeof(*thread));
 	sched_data = calloc(nr_threads, sizeof(*sched_data));
@@ -1294,6 +1327,13 @@ int main(int argc, char **argv)
 
 	loop(sched_data, nr_threads);
 
+	if (tracelimit) {
+		if (break_thread_id) {
+			printf("# Break thread: %d\n", break_thread_id);
+			printf("# Break value: %llu\n", (unsigned long long)break_thread_value);
+		}
+	}
+
 	for (i = 0; i < nr_threads; i++) {
 
 		sd = &sched_data[i];
-- 
2.25.1


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

* Re: [PATCH v2] sched_deadline/cyclicdeadline add tracelimit
  2022-06-17  6:40 [PATCH v2] sched_deadline/cyclicdeadline add tracelimit Song Chen
@ 2022-06-29  6:58 ` Daniel Wagner
  2022-06-29 15:34   ` John Kacur
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Wagner @ 2022-06-29  6:58 UTC (permalink / raw)
  To: Song Chen; +Cc: linux-rt-users, jkacur, williams

Hi,

On Fri, Jun 17, 2022 at 02:40:52PM +0800, Song Chen wrote:
>  static void usage(int error)
> @@ -689,6 +697,7 @@ static void usage(int error)
>  	       "                           (default 500us).\n"
>  	       "-t NUM   --threads         The number of threads to run as deadline (default 1).\n"
>  	       "-q       --quiet           print a summary only on exit\n"
> +	       "-b USEC  --breaktrace=USEC send break trace command when latency > USEC\n"

Please also consider to update the man pages.

Daniel

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

* Re: [PATCH v2] sched_deadline/cyclicdeadline add tracelimit
  2022-06-29  6:58 ` Daniel Wagner
@ 2022-06-29 15:34   ` John Kacur
  2022-06-29 17:03     ` Daniel Wagner
  2022-06-30  1:03     ` Song Chen
  0 siblings, 2 replies; 7+ messages in thread
From: John Kacur @ 2022-06-29 15:34 UTC (permalink / raw)
  To: Daniel Wagner; +Cc: Song Chen, linux-rt-users, williams



On Wed, 29 Jun 2022, Daniel Wagner wrote:

> Hi,
> 
> On Fri, Jun 17, 2022 at 02:40:52PM +0800, Song Chen wrote:
> >  static void usage(int error)
> > @@ -689,6 +697,7 @@ static void usage(int error)
> >  	       "                           (default 500us).\n"
> >  	       "-t NUM   --threads         The number of threads to run as deadline (default 1).\n"
> >  	       "-q       --quiet           print a summary only on exit\n"
> > +	       "-b USEC  --breaktrace=USEC send break trace command when latency > USEC\n"
> 
> Please also consider to update the man pages.

@Song Chen, You can send that as an extra patch, but this is a good point, 
please update the man page as well.

@Danel Wagner, is that just a comment or would you like a Reviewed-by ?


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

* Re: [PATCH v2] sched_deadline/cyclicdeadline add tracelimit
  2022-06-29 15:34   ` John Kacur
@ 2022-06-29 17:03     ` Daniel Wagner
  2022-06-29 17:35       ` John Kacur
  2022-06-30  1:21       ` Song Chen
  2022-06-30  1:03     ` Song Chen
  1 sibling, 2 replies; 7+ messages in thread
From: Daniel Wagner @ 2022-06-29 17:03 UTC (permalink / raw)
  To: John Kacur; +Cc: Song Chen, linux-rt-users, williams

On Wed, Jun 29, 2022 at 11:34:40AM -0400, John Kacur wrote:
> @Danel Wagner, is that just a comment or would you like a Reviewed-by ?

I just noticed that several option have been added to various tools an
no one cared to add them to the manual patches. Makes a bit sad after
spending time syncing all man pages up.

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

* Re: [PATCH v2] sched_deadline/cyclicdeadline add tracelimit
  2022-06-29 17:03     ` Daniel Wagner
@ 2022-06-29 17:35       ` John Kacur
  2022-06-30  1:21       ` Song Chen
  1 sibling, 0 replies; 7+ messages in thread
From: John Kacur @ 2022-06-29 17:35 UTC (permalink / raw)
  To: Daniel Wagner; +Cc: Song Chen, linux-rt-users, williams



On Wed, 29 Jun 2022, Daniel Wagner wrote:

> On Wed, Jun 29, 2022 at 11:34:40AM -0400, John Kacur wrote:
> > @Danel Wagner, is that just a comment or would you like a Reviewed-by ?
> 
> I just noticed that several option have been added to various tools an
> no one cared to add them to the manual patches. Makes a bit sad after
> spending time syncing all man pages up.
> 

Thanks Daniel
I should start requiring that before I pull in patches.

John


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

* Re: [PATCH v2] sched_deadline/cyclicdeadline add tracelimit
  2022-06-29 15:34   ` John Kacur
  2022-06-29 17:03     ` Daniel Wagner
@ 2022-06-30  1:03     ` Song Chen
  1 sibling, 0 replies; 7+ messages in thread
From: Song Chen @ 2022-06-30  1:03 UTC (permalink / raw)
  To: John Kacur, Daniel Wagner; +Cc: linux-rt-users, williams

Hi,

在 2022/6/29 23:34, John Kacur 写道:
> 
> 
> On Wed, 29 Jun 2022, Daniel Wagner wrote:
> 
>> Hi,
>>
>> On Fri, Jun 17, 2022 at 02:40:52PM +0800, Song Chen wrote:
>>>   static void usage(int error)
>>> @@ -689,6 +697,7 @@ static void usage(int error)
>>>   	       "                           (default 500us).\n"
>>>   	       "-t NUM   --threads         The number of threads to run as deadline (default 1).\n"
>>>   	       "-q       --quiet           print a summary only on exit\n"
>>> +	       "-b USEC  --breaktrace=USEC send break trace command when latency > USEC\n"
>>
>> Please also consider to update the man pages.
> 
> @Song Chen, You can send that as an extra patch, but this is a good point,
> please update the man page as well.
> 
> @Danel Wagner, is that just a comment or would you like a Reviewed-by ?

I will send v3 with man page update and "Reviewed-by" today, many thanks.

Song

> 
>   

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

* Re: [PATCH v2] sched_deadline/cyclicdeadline add tracelimit
  2022-06-29 17:03     ` Daniel Wagner
  2022-06-29 17:35       ` John Kacur
@ 2022-06-30  1:21       ` Song Chen
  1 sibling, 0 replies; 7+ messages in thread
From: Song Chen @ 2022-06-30  1:21 UTC (permalink / raw)
  To: Daniel Wagner, John Kacur; +Cc: linux-rt-users, williams

Hi,

在 2022/6/30 01:03, Daniel Wagner 写道:
> On Wed, Jun 29, 2022 at 11:34:40AM -0400, John Kacur wrote:
>> @Danel Wagner, is that just a comment or would you like a Reviewed-by ?
> 
> I just noticed that several option have been added to various tools an
> no one cared to add them to the manual patches. Makes a bit sad after
> spending time syncing all man pages up.

I totally agree with you in this point, in a lot of cases, document 
updates are behind the code implementation. people got confused if they
are not synced.

Thanks for pointing it out.

BR

Song

>   

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

end of thread, other threads:[~2022-06-30  1:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-17  6:40 [PATCH v2] sched_deadline/cyclicdeadline add tracelimit Song Chen
2022-06-29  6:58 ` Daniel Wagner
2022-06-29 15:34   ` John Kacur
2022-06-29 17:03     ` Daniel Wagner
2022-06-29 17:35       ` John Kacur
2022-06-30  1:21       ` Song Chen
2022-06-30  1:03     ` Song Chen

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.