comp.lang.ada
 help / color / mirror / Atom feed
* Watchdog-Timer Assignment
@ 2018-09-21 10:29 Alex
  2018-09-21 22:35 ` Shark8
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Alex @ 2018-09-21 10:29 UTC (permalink / raw)


Hello, I have a school assignment (I have heard that this is important to mention) which I need help with.

You can find my code here: https://ideone.com/LIWmJM

My assignment is this:

Modify F3 from Part 1 so that it occasionally takes more than 0.5 seconds to execute.

Augment the cyclic scheduler from Part 1 with a watchdog task to monitor F3's execution time. When F3 exceeds its deadline (0.5s), the watchdog task should immediately print a warning message. I.e., 0.5s after start of F3, either F3 has finished or the watchdog has printed a message. The watchdog should let F3 finish even if it misses its deadline.

The watchdog task should be started (released) at the same time as (or just before) F3 starts executing, and from that point measure the time that F3 uses.

When F3 misses its deadline the cyclic executive should re-synchronize so that F1 is started at whole seconds.

You should start with this skeleton code: part 2. Examine the code to understand how a task is declared inside an Ada program. Try to modify it in places indicated by the comments. You can also reuse your solution for part 1 as the initial code.

(P.S The skeleton code "part 2" is more or less an empty Watchdog task-body).

I have implemented a random delay for f3 so that it occasionally takes more than 0.5 seconds to execute. My biggest issue (I believe) is that (if f3 takes more than 0.5 seconds to execute) f1 is supposed to start over at the next whole second.

I dont know where I should put that delay for this to happen.

Thank you in advance!


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

* Re: Watchdog-Timer Assignment
  2018-09-21 10:29 Watchdog-Timer Assignment Alex
@ 2018-09-21 22:35 ` Shark8
  2018-09-21 23:13   ` Alex
  2018-09-22  2:34 ` Anh Vo
  2018-09-22  3:29 ` Shark8
  2 siblings, 1 reply; 11+ messages in thread
From: Shark8 @ 2018-09-21 22:35 UTC (permalink / raw)


On Friday, September 21, 2018 at 4:29:10 AM UTC-6, Alex wrote:
> Hello, I have a school assignment (I have heard that this is important to mention) which I need help with.
> 
> You can find my code here: https://ideone.com/LIWmJM
> 
> My assignment is this:
> 
> Modify F3 from Part 1 so that it occasionally takes more than 0.5 seconds to execute.
> 
> Augment the cyclic scheduler from Part 1 with a watchdog task to monitor F3's execution time. When F3 exceeds its deadline (0.5s), the watchdog task should immediately print a warning message. I.e., 0.5s after start of F3, either F3 has finished or the watchdog has printed a message. The watchdog should let F3 finish even if it misses its deadline.
> 
> The watchdog task should be started (released) at the same time as (or just before) F3 starts executing, and from that point measure the time that F3 uses.
> 
> When F3 misses its deadline the cyclic executive should re-synchronize so that F1 is started at whole seconds.
> 
> You should start with this skeleton code: part 2. Examine the code to understand how a task is declared inside an Ada program. Try to modify it in places indicated by the comments. You can also reuse your solution for part 1 as the initial code.
> 
> (P.S The skeleton code "part 2" is more or less an empty Watchdog task-body).
> 
> I have implemented a random delay for f3 so that it occasionally takes more than 0.5 seconds to execute. My biggest issue (I believe) is that (if f3 takes more than 0.5 seconds to execute) f1 is supposed to start over at the next whole second.
> 
> I dont know where I should put that delay for this to happen.
> 
> Thank you in advance!

Have you tried getting the current time, doing the math to find the next second, and then doing a delay there?

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

* Re: Watchdog-Timer Assignment
  2018-09-21 22:35 ` Shark8
@ 2018-09-21 23:13   ` Alex
  2018-09-22  7:04     ` Simon Wright
  0 siblings, 1 reply; 11+ messages in thread
From: Alex @ 2018-09-21 23:13 UTC (permalink / raw)


> Have you tried getting the current time, doing the math to find the next second, and then doing a delay there?

I did it that way as a beginning, but I can't use the "delay"-command because it is relative delay. I need to use "delay until" because the delay-command have something called "delay drift".

And for that to happen I have to have a variable with the Time-type and I have no idea how to get a Time-typed variable to round up to next second.


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

* Re: Watchdog-Timer Assignment
  2018-09-21 10:29 Watchdog-Timer Assignment Alex
  2018-09-21 22:35 ` Shark8
@ 2018-09-22  2:34 ` Anh Vo
  2018-09-22 11:54   ` Alex
  2018-09-22  3:29 ` Shark8
  2 siblings, 1 reply; 11+ messages in thread
From: Anh Vo @ 2018-09-22  2:34 UTC (permalink / raw)


On Friday, September 21, 2018 at 3:29:10 AM UTC-7, Alex wrote:
> Hello, I have a school assignment (I have heard that this is important to mention) which I need help with.
> 
> You can find my code here: https://ideone.com/LIWmJM
> 
> My assignment is this:
> 
> Modify F3 from Part 1 so that it occasionally takes more than 0.5 seconds to execute.
> 
> Augment the cyclic scheduler from Part 1 with a watchdog task to monitor F3's execution time. When F3 exceeds its deadline (0.5s), the watchdog task should immediately print a warning message. I.e., 0.5s after start of F3, either F3 has finished or the watchdog has printed a message. The watchdog should let F3 finish even if it misses its deadline.
> 
> The watchdog task should be started (released) at the same time as (or just before) F3 starts executing, and from that point measure the time that F3 uses.
> 
> When F3 misses its deadline the cyclic executive should re-synchronize so that F1 is started at whole seconds.
> 
> You should start with this skeleton code: part 2. Examine the code to understand how a task is declared inside an Ada program. Try to modify it in places indicated by the comments. You can also reuse your solution for part 1 as the initial code.
> 
> (P.S The skeleton code "part 2" is more or less an empty Watchdog task-body).
> 
> I have implemented a random delay for f3 so that it occasionally takes more than 0.5 seconds to execute. My biggest issue (I believe) is that (if f3 takes more than 0.5 seconds to execute) f1 is supposed to start over at the next whole second.
> 
> I dont know where I should put that delay for this to happen.
> 
> Thank you in advance!

I looked at your codes. I did not know exactly what you meant by "part 1" and "Part 2". 

Anh Vo


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

* Re: Watchdog-Timer Assignment
  2018-09-21 10:29 Watchdog-Timer Assignment Alex
  2018-09-21 22:35 ` Shark8
  2018-09-22  2:34 ` Anh Vo
@ 2018-09-22  3:29 ` Shark8
  2018-09-22 11:56   ` Alex
  2 siblings, 1 reply; 11+ messages in thread
From: Shark8 @ 2018-09-22  3:29 UTC (permalink / raw)


On Friday, September 21, 2018 at 4:29:10 AM UTC-6, Alex wrote:
> Hello, I have a school assignment (I have heard that this is important to mention) which I need help with.
> 
> You can find my code here: https://ideone.com/LIWmJM
> 
> My assignment is this:
> 
> Modify F3 from Part 1 so that it occasionally takes more than 0.5 seconds to execute.
> 
> Augment the cyclic scheduler from Part 1 with a watchdog task to monitor F3's execution time. When F3 exceeds its deadline (0.5s), the watchdog task should immediately print a warning message. I.e., 0.5s after start of F3, either F3 has finished or the watchdog has printed a message. The watchdog should let F3 finish even if it misses its deadline.
> 
> The watchdog task should be started (released) at the same time as (or just before) F3 starts executing, and from that point measure the time that F3 uses.
> 
> When F3 misses its deadline the cyclic executive should re-synchronize so that F1 is started at whole seconds.
> 
> You should start with this skeleton code: part 2. Examine the code to understand how a task is declared inside an Ada program. Try to modify it in places indicated by the comments. You can also reuse your solution for part 1 as the initial code.
> 
> (P.S The skeleton code "part 2" is more or less an empty Watchdog task-body).
> 
> I have implemented a random delay for f3 so that it occasionally takes more than 0.5 seconds to execute. My biggest issue (I believe) is that (if f3 takes more than 0.5 seconds to execute) f1 is supposed to start over at the next whole second.
> 
> I dont know where I should put that delay for this to happen.
> 
> Thank you in advance!

This?

    Function Next_Second return Ada.Calendar.Time is
	Use Ada.Calendar;
	Now       : Time renames Clock;
	Second    : Duration renames Seconds(Now);
	Trunc     : Constant Natural  := Natural(Second);
	Rounded   : Constant Duration := Duration(Trunc);
	Year      : Year_Number;
	Month     : Month_Number;
	Day       : Day_Number;
	S         : Duration;
    Begin
	Split(
          Date    => Now,
          Year    => Year,
          Month   => Month,
          Day     => Day,
          Seconds => S
         );
	return Time_Of(Year, Month, Day,
	  (if Rounded < Second
	   then Rounded + 1.0
	   else Rounded
	  ));
    End Next_Second;


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

* Re: Watchdog-Timer Assignment
  2018-09-21 23:13   ` Alex
@ 2018-09-22  7:04     ` Simon Wright
  2018-09-22 11:58       ` Alex
  0 siblings, 1 reply; 11+ messages in thread
From: Simon Wright @ 2018-09-22  7:04 UTC (permalink / raw)


Alex <henningssonalex@gmail.com> writes:

> I did it that way as a beginning, but I can't use the "delay"-command
> because it is relative delay. I need to use "delay until" because the
> delay-command have something called "delay drift".

Well, the program doesn't start out on a whole wall-clock second, so I
don't see why it need sync to the wall clock only if a procedure misses
its deadline! You may say "but it's a requirement"; but it's the sort of
requirement that needs to be properly justified, not handed down on
tablets of stone.

Would be just as reasonable to run in whole seconds from program
start-up (I've moved over to a Ravenscar mindset, at least as far as
time stuff is concerned, so used to not having relative delay
statements).

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

* Re: Watchdog-Timer Assignment
  2018-09-22  2:34 ` Anh Vo
@ 2018-09-22 11:54   ` Alex
  2018-09-22 13:18     ` Dennis Lee Bieber
  2018-09-25 17:05     ` Anh Vo
  0 siblings, 2 replies; 11+ messages in thread
From: Alex @ 2018-09-22 11:54 UTC (permalink / raw)


> I looked at your codes. I did not know exactly what you meant by "part 1" and "Part 2". 
> 
> Anh Vo

These are the instructions I have been given:

PART 1:

Write a cyclic scheduler which manages three procedures: F1, F2 and F3. We demand the following for the executions:

F1 should be executed every second.
F2 starts when F1 terminates.
F3 should execute every other (varannan) second, starting 0.5 seconds after F1's start.
The execution times for the functions are not known. However, it can be assumed that F1 and F2 together execute for less than 0.5 seconds, and that F3 does not take more than 0.5 seconds to execute.

Let the functions print an informative message when they execute, e.g.

F1 executing, time is now: 0.00001
F2 executing, time is now: 0.00004
F3 executing, time is now: 0.50008
F1 executing, time is now: 1.00008
F2 executing, time is now: 1.00010
F1 executing, time is now: 2.00007
F2 executing, time is now: 2.00008
F3 executing, time is now: 2.50007
...

Note: Some amount of jitter in start times for functions F1 and F3 cannot be avoided. However, the start times of the functions are not allowed to "drift" further and further away from the schedule.

PART 2: (The one I am stuck on).

Modify F3 from Part 1 so that it occasionally takes more than 0.5 seconds to execute.

Augment the cyclic scheduler from Part 1 with a watchdog task to monitor F3's execution time. When F3 exceeds its deadline (0.5s), the watchdog task should immediately print a warning message. I.e., 0.5s after start of F3, either F3 has finished or the watchdog has printed a message. The watchdog should let F3 finish even if it misses its deadline.

The watchdog task should be started (released) at the same time as (or just before) F3 starts executing, and from that point measure the time that F3 uses.

When F3 misses its deadline the cyclic executive should re-synchronize so that F1 is started at whole seconds.

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

* Re: Watchdog-Timer Assignment
  2018-09-22  3:29 ` Shark8
@ 2018-09-22 11:56   ` Alex
  0 siblings, 0 replies; 11+ messages in thread
From: Alex @ 2018-09-22 11:56 UTC (permalink / raw)


> This?
> 
>     Function Next_Second return Ada.Calendar.Time is
> 	Use Ada.Calendar;
> 	Now       : Time renames Clock;
> 	Second    : Duration renames Seconds(Now);
> 	Trunc     : Constant Natural  := Natural(Second);
> 	Rounded   : Constant Duration := Duration(Trunc);
> 	Year      : Year_Number;
> 	Month     : Month_Number;
> 	Day       : Day_Number;
> 	S         : Duration;
>     Begin
> 	Split(
>           Date    => Now,
>           Year    => Year,
>           Month   => Month,
>           Day     => Day,
>           Seconds => S
>          );
> 	return Time_Of(Year, Month, Day,
> 	  (if Rounded < Second
> 	   then Rounded + 1.0
> 	   else Rounded
> 	  ));
>     End Next_Second;

This I haven't seen! But that might work, I shall try. Even though I do not believe we had to do our own function, but that might work anyways. I will try. Thank you!

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

* Re: Watchdog-Timer Assignment
  2018-09-22  7:04     ` Simon Wright
@ 2018-09-22 11:58       ` Alex
  0 siblings, 0 replies; 11+ messages in thread
From: Alex @ 2018-09-22 11:58 UTC (permalink / raw)


> Well, the program doesn't start out on a whole wall-clock second, so I
> don't see why it need sync to the wall clock only if a procedure misses
> its deadline! You may say "but it's a requirement"; but it's the sort of
> requirement that needs to be properly justified, not handed down on
> tablets of stone.
> 
> Would be just as reasonable to run in whole seconds from program
> start-up (I've moved over to a Ravenscar mindset, at least as far as
> time stuff is concerned, so used to not having relative delay
> statements).

I wrote the exact instructions in an answer here. I think I need a delay in f3 that interrupts the program for the remaining time from Current Time to Next Whole Second. But I am not sure, that's why I am stuck.


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

* Re: Watchdog-Timer Assignment
  2018-09-22 11:54   ` Alex
@ 2018-09-22 13:18     ` Dennis Lee Bieber
  2018-09-25 17:05     ` Anh Vo
  1 sibling, 0 replies; 11+ messages in thread
From: Dennis Lee Bieber @ 2018-09-22 13:18 UTC (permalink / raw)


On Sat, 22 Sep 2018 04:54:57 -0700 (PDT), Alex <henningssonalex@gmail.com>
declaimed the following:


>F3 should execute every other (varannan) second, starting 0.5 seconds after F1's start.
>The execution times for the functions are not known. However, it can be assumed that F1 and F2 together execute for less than 0.5 seconds, and that F3 does not take more than 0.5 seconds to execute.
>
	So phase one means F1/F2/F3 together take just under 1 second, but F3
alternates... 

>
>Note: Some amount of jitter in start times for functions F1 and F3 cannot be avoided. However, the start times of the functions are not allowed to "drift" further and further away from the schedule.

	Which means using a DELAY UNTIL to set the start times for F1 and F3;
very crude pseudo-code.

	majorframe = 1; -- second
	minorframe = 0.5;
	epoch = now + majorframe;
	doF3 = true;
	loop
		delay until epoch;
		F1;
		F2;
		if doF3 then
			delay until epoch + minorframe;
		end if;
		doF3 = not doF3;
		epoch = epoch + majorframe;
	end loop/
		
>
>PART 2: (The one I am stuck on).
>
>Modify F3 from Part 1 so that it occasionally takes more than 0.5 seconds to execute.
>
>Augment the cyclic scheduler from Part 1 with a watchdog task to monitor F3's execution time. When F3 exceeds its deadline (0.5s), the watchdog task should immediately print a warning message. I.e., 0.5s after start of F3, either F3 has finished or the watchdog has printed a message. The watchdog should let F3 finish even if it misses its deadline.
>
>The watchdog task should be started (released) at the same time as (or just before) F3 starts executing, and from that point measure the time that F3 uses.
>
>When F3 misses its deadline the cyclic executive should re-synchronize so that F1 is started at whole seconds.

	It is possible to interpret that clause in a way that does NOT require
integral seconds for the start time, but only that F1 starts at a time
relative to its prior start which is an integral multiple of seconds...

	epoch + 1
	epoch + 2
	epoch + ...

so if F3 runs long, the watchdog needs to increment the epoch by a whole
major frame interval to resynchronize F1 to the NEXT normal period.
Assumption is that F3 does not run longer than 1.5 seconds (which would
result in it using up a whole major frame and into a second one).

	If you are going to interpret it to start on an integral second, then
the original scheduler itself should start on an integral second.


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/ 

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

* Re: Watchdog-Timer Assignment
  2018-09-22 11:54   ` Alex
  2018-09-22 13:18     ` Dennis Lee Bieber
@ 2018-09-25 17:05     ` Anh Vo
  1 sibling, 0 replies; 11+ messages in thread
From: Anh Vo @ 2018-09-25 17:05 UTC (permalink / raw)


On Saturday, September 22, 2018 at 4:54:59 AM UTC-7, Alex wrote:
> > I looked at your codes. I did not know exactly what you meant by "part 1" and "Part 2". 
> > 
> > Anh Vo
> 
> These are the instructions I have been given:
>  
> PART 2: (The one I am stuck on).
> 
> Modify F3 from Part 1 so that it occasionally takes more than 0.5 seconds to execute.
> 
> Augment the cyclic scheduler from Part 1 with a watchdog task to monitor F3's execution time. When F3 exceeds its deadline (0.5s), the watchdog task should immediately print a warning message. I.e., 0.5s after start of F3, either F3 has finished or the watchdog has printed a message. The watchdog should let F3 finish even if it misses its deadline.
> 
> The watchdog task should be started (released) at the same time as (or just before) F3 starts executing, and from that point measure the time that F3 uses.
> 
> When F3 misses its deadline the cyclic executive should re-synchronize so that F1 is started at whole seconds.

Could you post the original skeleton code given by your instructor. Then, we can work from there for Part 2.

Anh Vo


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

end of thread, other threads:[~2018-09-25 17:05 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-21 10:29 Watchdog-Timer Assignment Alex
2018-09-21 22:35 ` Shark8
2018-09-21 23:13   ` Alex
2018-09-22  7:04     ` Simon Wright
2018-09-22 11:58       ` Alex
2018-09-22  2:34 ` Anh Vo
2018-09-22 11:54   ` Alex
2018-09-22 13:18     ` Dennis Lee Bieber
2018-09-25 17:05     ` Anh Vo
2018-09-22  3:29 ` Shark8
2018-09-22 11:56   ` Alex

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox