Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[notifier] signal change to active/pending dataset + simplify 'Notifier::EventToString' #5657

Merged
merged 2 commits into from Oct 19, 2020

Conversation

abtink
Copy link
Member

@abtink abtink commented Oct 15, 2020

This PR contains two related commits:

[notifier] signal change to active or pending Operational Dataset

[notifier] simplify 'EventToString()'

This commit changes EventToString() to use an array instead of
switch. This helps with code size due to enumerator cases being
uint32_t bitmask values and therefore compliers may not be able to
optimize the switch statement as a table.

@size-report
Copy link

size-report bot commented Oct 15, 2020

Size Report of OpenThread

Merging #5657 into master(e48a1ff).

name branch text data bss total
ot-cli-ftd_1.1 master 388236 736 72700 461672
#5657 388060 736 72700 461496
+/- -176 0 0 -176
ot-cli-mtd_1.1 master 313788 736 64116 378640
#5657 313644 736 64116 378496
+/- -144 0 0 -144
ot-ncp-ftd_1.1 master 382204 736 71980 454920
#5657 382044 736 71980 454760
+/- -160 0 0 -160
ot-ncp-mtd_1.1 master 310764 736 63396 374896
#5657 310604 736 63396 374736
+/- -160 0 0 -160
ot-rcp_1.1 master 64136 636 7512 72284
#5657 64136 636 7512 72284
+/- 0 0 0 0
libopenthread-cli-ftd.a_1.1 master 38229 0 3108 41337
#5657 38229 0 3108 41337
+/- 0 0 0 0
libopenthread-cli-mtd.a_1.1 master 31048 0 3108 34156
#5657 31048 0 3108 34156
+/- 0 0 0 0
libopenthread-ftd.a_1.1 master 193713 4 54992 248709
#5657 193539 4 54992 248535
+/- -174 0 0 -174
libopenthread-mtd.a_1.1 master 132033 4 46408 178445
#5657 131875 4 46408 178287
+/- -158 0 0 -158
libopenthread-ncp-ftd.a_1.1 master 48147 0 2388 50535
#5657 48147 0 2388 50535
+/- 0 0 0 0
libopenthread-ncp-mtd.a_1.1 master 43343 0 2388 45731
#5657 43343 0 2388 45731
+/- 0 0 0 0
libopenthread-rcp.a_1.1 master 27198 0 1532 28730
#5657 27198 0 1532 28730
+/- 0 0 0 0
libopenthread-radio.a_1.1 master 13098 0 150 13248
#5657 13098 0 150 13248
+/- 0 0 0 0
ot-cli-ftd_1.2 master 409556 736 81668 491960
#5657 409380 736 81668 491784
+/- -176 0 0 -176
ot-cli-mtd_1.2 master 322788 736 64332 387856
#5657 322612 736 64332 387680
+/- -176 0 0 -176
ot-ncp-ftd_1.2 master 401316 736 80948 483000
#5657 401140 736 80948 482824
+/- -176 0 0 -176
ot-ncp-mtd_1.2 master 318900 736 63612 383248
#5657 318756 736 63612 383104
+/- -144 0 0 -144
ot-rcp_1.2 master 69120 636 16316 86072
#5657 69120 636 16316 86072
+/- 0 0 0 0
libopenthread-cli-ftd.a_1.2 master 39557 0 3108 42665
#5657 39557 0 3108 42665
+/- 0 0 0 0
libopenthread-cli-mtd.a_1.2 master 31492 0 3108 34600
#5657 31492 0 3108 34600
+/- 0 0 0 0
libopenthread-ftd.a_1.2 master 213477 4 63904 277385
#5657 213303 4 63904 277211
+/- -174 0 0 -174
libopenthread-mtd.a_1.2 master 140258 4 46568 186830
#5657 140100 4 46568 186672
+/- -158 0 0 -158
libopenthread-ncp-ftd.a_1.2 master 48147 0 2388 50535
#5657 48147 0 2388 50535
+/- 0 0 0 0
libopenthread-ncp-mtd.a_1.2 master 43343 0 2388 45731
#5657 43343 0 2388 45731
+/- 0 0 0 0
libopenthread-rcp.a_1.2 master 27198 0 1532 28730
#5657 27198 0 1532 28730
+/- 0 0 0 0
libopenthread-radio.a_1.2 master 13794 0 150 13944
#5657 13794 0 150 13944
+/- 0 0 0 0

@codecov
Copy link

codecov bot commented Oct 15, 2020

Codecov Report

Merging #5657 into master will decrease coverage by 3.09%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #5657      +/-   ##
==========================================
- Coverage   80.74%   77.64%   -3.10%     
==========================================
  Files         378      378              
  Lines       48331    48093     -238     
==========================================
- Hits        39024    37341    -1683     
- Misses       9307    10752    +1445     
Impacted Files Coverage Δ
src/core/common/notifier.hpp 100.00% <ø> (ø)
src/core/meshcop/dataset_manager.hpp 83.33% <ø> (ø)
src/core/common/notifier.cpp 86.66% <100.00%> (+4.79%) ⬆️
src/core/meshcop/dataset_manager.cpp 85.53% <100.00%> (-3.65%) ⬇️
src/core/utils/jam_detector.hpp 0.00% <0.00%> (-100.00%) ⬇️
src/core/utils/slaac_address.hpp 0.00% <0.00%> (-100.00%) ⬇️
src/core/api/jam_detection_api.cpp 0.00% <0.00%> (-52.95%) ⬇️
src/core/thread/discover_scanner.hpp 50.00% <0.00%> (-50.00%) ⬇️
examples/platforms/simulation/misc.c 30.43% <0.00%> (-43.48%) ⬇️
src/core/utils/channel_manager.cpp 45.56% <0.00%> (-41.10%) ⬇️
... and 95 more

Copy link
Contributor

@Irving-cl Irving-cl left a comment

Choose a reason for hiding this comment

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

LGTM👍

@@ -92,6 +92,8 @@ enum Event
kEventThreadBackboneRouterStateChanged = OT_CHANGED_THREAD_BACKBONE_ROUTER_STATE, ///< Backbone Router state changed
kEventThreadBackboneRouterLocalChanged = OT_CHANGED_THREAD_BACKBONE_ROUTER_LOCAL, ///< Local Backbone Router changed
kEventJoinerStateChanged = OT_CHANGED_JOINER_STATE, ///< Joiner state changed
kEventActiveDatasetChanged = OT_CHANGED_ACTIVE_DATASET, ///< Active Dataset changed
kEventPendingDatasetChanged = OT_CHANGED_PENDING_DATASET, ///< Pending Dataset changed
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a question: It seems that these events are always used alone when calling Signal instead of a bit mask way. So why not defining these values simply as 0-29? For uint32_t we can add at most 2 more events in the future.

Copy link
Member

Choose a reason for hiding this comment

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

The state changed callback provides multiple events via a bitmask.

void Notifier::Signal(Event aEvent)
{
mEventsToSignal.Add(aEvent);
mSignaledEvents.Add(aEvent);
mTask.Post();
}

Copy link
Member Author

Choose a reason for hiding this comment

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

We do use them as bitmask (which can contain multiple events) in the callbacks, e.g., in otStateChangedCallback() or in HandleNotifierEvents().

Signal() method uses a single event but multiple events can be collected and emitted together (Notifier
has its own Tasklet from which it would emit the collected events).


I agree we may face a limit due to use of uint32_t. We have been careful about adding events and only adding ones that would be useful. In the case here, I think knowing when Datasets get changed would be helpful (for different situations).

We have intentionally defined otChangedFlags type which is used as parameter type in otStateChangedCallback(). It is currentlly defined in instance.h (public header) as:

typedef uint32_t otChangedFlags;

typedef void (*otStateChangedCallback)(otChangedFlags aFlags, void *aContext);

This would allow us in future to change the otChangedFlags to uint64_t to get more possible OT_CHANGED events and hopefully minimize impact on users of the API.

Inside the core, we have Events type which acts as a set/list of events and provides helper methods to check whether it Contains(Event) and/or ContainsAny() or ContainsAll() of a collection of events.

This commit changes `EventToString()` to use an array instead of
`switch`. This helps with code size due to enumerator cases being
`uint32_t` bitmask values and therefore compliers may not be able to
optimize the `switch` statement as a table.
@jwhui jwhui merged commit 80d4cb0 into openthread:master Oct 19, 2020
simonlingoogle pushed a commit to simonlingoogle/openthread that referenced this pull request Nov 12, 2020
Bug: 171270296

* origin/github/master:
  [notifier] simplify 'EventToString()' (openthread#5657)
  [notifier] signal change to active or pending Operational Dataset (openthread#5657)
  [coap] add helper method 'Message::SetTokenFromMessage()' (openthread#5661)
  [dataset-manager] misc enhancements (openthread#5655)
  [simulation] add configuration MAX_NETWORK_SIZE (openthread#5565)
  [lib-url] update 'Makefile' to include 'src/core' in header path search (openthread#5659)
  [code-utils] enhance 'VerifyOrExit' to make action optional (openthread#5659)
  [autoconf] remove bashisms from configure.ac (openthread#5658)
  [otns] emit COAP send/receive events to OTNS (openthread#5656)
  [logging] update logging to use new helper macros (openthread#5650)
  [common] macros to get first/second/rest of variadic arguments (openthread#5650)
  [continuous-integration] kill ot-rcp and ot-cli in pty check (openthread#5654)
  [cli] add context for the user commands (openthread#5587)
  [thread-cert] turn off OTBR NAT64 in 1.2 Backbone tests (openthread#5652)
  [low-power] add an Enh-ACK frame link layer counter (openthread#5583)
  [thread-cert] refactor case 9.2.12 and 9.2.13 using pktverify (openthread#5442)
  [coap] allow max URI path length (openthread#5645)
  [harness-automation] update readme (openthread#5646)
  [common] use non-copyable for more instance-unique classes (openthread#5639)
  [linux] fix missing correct mtu (openthread#5642)
  [docs] update Doxygen menu (openthread#5641)
  [thread-cert] enhance case 5.6.7 for data version increment (openthread#5643)
  [cc1352,cc2652] add check before claiming transmit done (openthread#5640)
  [cli] add command to set/get external FEM's LNA gain (openthread#5563)
  [ip6] no anycast as source address (openthread#5632)
  [debug] prefer user provided assert to system assert (openthread#5624)
Change-Id: Ia7e971ebfef8a78dda9e818698e46831b41d1ec7
@abtink abtink deleted the notifier/dataset-changed branch February 23, 2022 21:44
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.

None yet

3 participants