Skip to content

Fix a period callback error and a tolerance error#31

Open
LiyouZhou wants to merge 1 commit intoARMmbed:masterfrom
LiyouZhou:fix_period_and_tolerance
Open

Fix a period callback error and a tolerance error#31
LiyouZhou wants to merge 1 commit intoARMmbed:masterfrom
LiyouZhou:fix_period_and_tolerance

Conversation

@LiyouZhou
Copy link
Copy Markdown
Contributor

  1. The first callback of a period callback now happens
    immediately after postcallback() instead of one period
    interval later.
  2. The tolerance is stored as double sided tolerance
    but used as single sided, with effect of have double
    the tolerance as user intended. This has been fixed.

Test result:

target platform_name test result elapsed_time (sec) copy_method
frdm-k64f-gcc K64F minar-tests-test-minar001_repeated_call_instance OK 2.32 shell
frdm-k64f-gcc K64F minar-tests-test-minar003_simple_callback OK 2.28 shell
frdm-k64f-gcc K64F minar-tests-test-minar004_simple_period_callback OK 2.3 shell
frdm-k64f-gcc K64F minar-tests-test-minar005_long_period_callback OK 3.2 shell
frdm-k64f-gcc K64F minar-tests-test-minar006_period_and_regular_callback OK 2.76 shell
frdm-k64f-gcc K64F minar-tests-test-minar007_no_overlap_period_callback OK 2.64 shell
frdm-k64f-gcc K64F minar-tests-test-minar008_overlapping_period_callback OK 2.49 shell
frdm-k64f-gcc K64F minar-tests-test-minar009_mixed_callbacks OK 2.43 shell
frdm-k64f-gcc K64F minar-tests-test-minar010_period_with_tolerence OK 2.49 shell
frdm-k64f-gcc K64F minar-tests-test-minar011_tolerance_and_delays OK 2.75 shell
frdm-k64f-gcc K64F minar-tests-test-minar012_three_period_callbacks OK 2.44 shell
frdm-k64f-gcc K64F minar-tests-test-minar013_three_regular_one_period OK 2.4 shell
frdm-k64f-gcc K64F minar-tests-test-minar014_four_periodic_callbacks OK 2.52 shell
frdm-k64f-gcc K64F minar-tests-test-minar015_three_regular_three_period OK 3.29 shell
frdm-k64f-gcc K64F minar-tests-test-minar016_remove_and_reschedule OK 2.37 shell
frdm-k64f-gcc K64F minar-tests-test-minar021_interrupt_safety OK 2.3 shell
frdm-k64f-gcc K64F minar-tests-test-minar023_period_less_than_tolerance OK 4.25 shell
frdm-k64f-gcc K64F minar-tests-test-minar024_cancel_inexistent_callback OK 2.3 shell
frdm-k64f-gcc K64F minar-tests-test-minar025_cancel_callback_twice OK 2.25 shell
frdm-k64f-gcc K64F minar-tests-test-minar027_call_start_while_running FAIL 2.35 shell
frdm-k64f-gcc K64F minar-tests-test-minar028_call_stop_while_not_running OK 2.31 shell
frdm-k64f-gcc K64F minar-tests-test-minar029_schedule_single_pool OK 2.32 shell
frdm-k64f-gcc K64F minar-tests-test-minar030_schedule_single_pool_plus_one OK 2.34 shell
frdm-k64f-gcc K64F minar-tests-test-minar031_full_and_additional_pool OK 2.37 shell
frdm-k64f-gcc K64F minar-tests-test-minar032_full_additional_pool_plus1 OK 2.38 shell
frdm-k64f-gcc K64F minar-tests-test-minar033_test_out_of_memory OK 1.96 shell
frdm-k64f-gcc K64F minar-tests-test-minar034_1000_callbacks_memcheck OK 2.54 shell
frdm-k64f-gcc K64F minar-tests-test-minar035_one_thousand_callbacks OK 3.6 shell
frdm-k64f-gcc K64F minar-tests-test-minar036_warn_duration_milliseconds FAIL 1.96 shell

Note that minar036 and 027 are expected to fail
@bogdanm @0xc0170 Please review

1. The first callback of a period callback now happens
immediately after postcallback() instead of one period
interval later.

2. The tolerance is stored as double sided tolerance
but used as single sided, with effect of have double
the tolerance as user intended. This has been fixed.
Comment thread source/minar.cpp
if(dispatch_tree.get_num_elements() > 0) {
CallbackNode *root = dispatch_tree.get_root();
now_plus_tolerance = wrapTime(now + root->tolerance);
now_plus_tolerance = wrapTime(now + root->tolerance/2);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a bit weird that initially we're doubling the tolerance, only to divide it by 2 later. Being consistent is probably a better idea.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I asked about the intention of double sided tolerance. When we store it we times it by 2 and every time we use it we divide. This is not intuitive unless there is a higher design purpose for this. This fix is the minimum amount of code change, but I can equally change all the other place to use single sided tolerance. What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the original purpose of the "double sided tolerance" was to allow an event's tolerance to be applied in each direction relative to the event's scheduled time: [scheduled_time - tolerance, scheduled_time + tolerance]. Since that's not implemented currently, I don't think that multiplying the initial tolerance by 2 gives us any advantage. The proper fix for this would be to actually apply and check the tolerance in both directions.
Cc @autopulated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current algorithm only consider one side of the tolerance: scheduled_time - tolerance. But if we consider both side, what can we do if (now > scheduled_time + tolerance)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bremoran, didn't you look at this a while ago?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did, however what I looked at was a scenario where, under heavy load, minar would stop scheduling periodic callbacks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I don't think that playing with the tolerance is a good idea for now. When we fix it, we'll fix it properly. Let's leave the code as it is for now.

@autopulated
Copy link
Copy Markdown
Contributor

  1. doesn't seem like the correct design decision here: I wouldn't expect a periodic callback to trigger immediately (it wouldn't be natural behaviour with boost asio timers, it isn't what Qt's QTimer would do, it isn't what setInterval does in JS, or what NSTimer would do in objective-c) what's the reason for the change?
  2. the original reason for doubling the tolerance was so that the "now" value would be the earliest possible execution value, so it was easy to sort by this. Possibly this reasoning has been lost, but hopefully that explains things.

@bogdanm
Copy link
Copy Markdown
Contributor

bogdanm commented Feb 23, 2016

I wouldn't expect a periodic callback to trigger immediately

I would expect a periodic callback to not trigger immediately only if it also had a delay, otherwise I don't see why it wouldn't just trigger after being scheduled. What if I want to schedule a callback with a period equal to one second, but I want it to run as soon as possible?

the original reason for doubling the tolerance was so that the "now" value would be the earliest possible execution value, so it was easy to sort by this.

Thanks. It looks like just using tolerance instead of 2 * tolerance should be safe then (however, I'll release a new major version of MINAR if we actually do this, just to be on the safe side).

@bremoran
Copy link
Copy Markdown
Contributor

While I appreciate the semantics you're looking for, @bogdanm, changing the behaviour of the API should require a major version bump. I would not recommend doing this right before a release.

@bogdanm
Copy link
Copy Markdown
Contributor

bogdanm commented Feb 23, 2016

I would not recommend doing this right before a release.

Completely agreed with the major version bump. Also, fair point. I'll postpone this.

@bogdanm bogdanm closed this Feb 23, 2016
@bogdanm
Copy link
Copy Markdown
Contributor

bogdanm commented Feb 23, 2016

While I closed this PR because of the upcoming release, feel free to continue disccusing these changes, as we'll revisit it after the release.

@bremoran
Copy link
Copy Markdown
Contributor

I wouldn't suggest closing this PR, rather just leave it open with a DO NOT MERGE label

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants