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

Usage of 'fixed-size' integer types in RTI code #453

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Conversation

Jakio815
Copy link
Collaborator

@Jakio815 Jakio815 commented Jun 24, 2024

This resolves issue #449.

  1. Clarified types of federate_id, which was defined as just int not int32_t, which could make problems on 16-bit systems.

  2. Also, change the runtime clock-synchronization after initial clock-sync, to send a 2 byte uint16_t federate_id not int32_t which is 4 bytes.

Summary by CodeRabbit

  • Bug Fixes

    • Improved consistency and data representation in clock synchronization by switching message size calculations and federate ID encoding from int to uint16_t.
    • Removed obsolete checks and error handling for federate ID limits in connection functions.
  • Refactor

    • Updated the type of _lf_my_fed_id and lf_fed_id from int to uint16_t for improved clarity and performance.

Copy link
Contributor

coderabbitai bot commented Jun 24, 2024

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

Commits

Files that changed from the base of the PR and between dc11c70 and e201df6.

Files selected for processing (5)
  • core/federated/RTI/rti_remote.c (3 hunks)
  • core/federated/clock-sync.c (1 hunks)
  • core/federated/federate.c (2 hunks)
  • core/utils/util.c (3 hunks)
  • include/core/utils/util.h (1 hunks)
________________________________________________
< Press W-A-S-D to move me around your codebase. >
------------------------------------------------
 \
  \   (\__/)
      (•ㅅ•)
      /   づ

Walkthrough

The changes standardize the data type used for a federate ID across multiple files, switching from int and int32_t to uint16_t. This improves consistency and prevents potential issues, particularly on 16-bit systems. Moreover, checks for the number of federates, which might exceed uint16_t limits, are removed to prevent unnecessary constraints.

Changes

File Path Change Summary
core/federated/RTI/rti_remote.c Updated message size calculation and type casting in clock synchronization thread function
core/federated/clock-sync.c Modified federate ID encoding from int to uint16_t for clock sync messages
core/federated/federate.c Removed checks for excess number of federates in connection functions
core/utils/util.c Changed _lf_my_fed_id type from int to uint16_t and updated associated logic
include/core/utils/util.h Updated _lf_my_fed_id and related functions to use uint16_t instead of int

Possibly related issues

  • lf-lang/reactor-c#449: This PR resolves the type inconsistency in federate ID, which is described in this issue as a potential bug due to mixed use of uint16_t, int, and int32_t.

Tip

CodeRabbit can generate a title for your PR based on the changes.

Add @coderabbitai placeholder anywhere in the title of your PR and CodeRabbit will replace it with a title based on the changes in the PR. You can change the placeholder by changing the reviews.auto_title_placeholder setting.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between eb48bae and 5cd75ab.

Files selected for processing (3)
  • core/federated/RTI/rti_remote.c (2 hunks)
  • core/federated/clock-sync.c (1 hunks)
  • core/utils/util.c (1 hunks)
Files skipped from review due to trivial changes (1)
  • core/utils/util.c
Additional comments not posted (1)
core/federated/RTI/rti_remote.c (1)

926-926: Updated message size calculation for clock sync

The change from int32_t to uint16_t for the federate ID in the clock synchronization logic is correctly reflected in the message_size calculation. This change should help reduce the network overhead and aligns with the PR's aim to improve efficiency on systems where uint16_t is the native size.

core/federated/RTI/rti_remote.c Outdated Show resolved Hide resolved
core/federated/clock-sync.c Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5cd75ab and 63ce483.

Files selected for processing (1)
  • core/federated/RTI/rti_remote.c (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • core/federated/RTI/rti_remote.c

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 63ce483 and 6b8e21d.

Files selected for processing (2)
  • core/utils/util.c (2 hunks)
  • include/core/utils/util.h (1 hunks)
Files skipped from review due to trivial changes (1)
  • include/core/utils/util.h
Files skipped from review as they are similar to previous changes (1)
  • core/utils/util.c

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6b8e21d and 01af69e.

Files selected for processing (2)
  • core/federated/RTI/rti_remote.c (3 hunks)
  • core/federated/clock-sync.c (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • core/federated/RTI/rti_remote.c
  • core/federated/clock-sync.c

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 01af69e and 7a33a70.

Files selected for processing (1)
  • core/federated/RTI/rti_remote.c (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • core/federated/RTI/rti_remote.c

@Jakio815 Jakio815 requested a review from edwardalee June 25, 2024 19:43
@lhstrh
Copy link
Member

lhstrh commented Jun 30, 2024

@edwardalee?

@lhstrh lhstrh requested a review from cmnrd July 1, 2024 07:33
core/federated/RTI/rti_remote.c Outdated Show resolved Hide resolved
core/federated/clock-sync.c Outdated Show resolved Hide resolved
include/core/utils/util.h Outdated Show resolved Hide resolved
include/core/utils/util.h Outdated Show resolved Hide resolved
core/utils/util.c Outdated Show resolved Hide resolved
core/utils/util.c Outdated Show resolved Hide resolved
Copy link
Contributor

@edwardalee edwardalee left a comment

Choose a reason for hiding this comment

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

This looks good to me, but I agree with @Jakio815 and @cmnrd that should go a step further and make it uint16_t throughout. I don't think the initialization to -1 is needed. I don't think it matters what it is initialized to because generated code will set it during initialization of the federate.

core/federated/clock-sync.c Outdated Show resolved Hide resolved
core/utils/util.c Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7a33a70 and a5128d4.

Files selected for processing (5)
  • core/federated/RTI/rti_remote.c (3 hunks)
  • core/federated/clock-sync.c (1 hunks)
  • core/federated/federate.c (2 hunks)
  • core/utils/util.c (2 hunks)
  • include/core/utils/util.h (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • core/federated/RTI/rti_remote.c
  • core/federated/clock-sync.c
  • core/utils/util.c
  • include/core/utils/util.h
Additional comments not posted (2)
core/federated/federate.c (2)

Line range hint 1189-1192: Verify the impact of removing the check for _lf_my_fed_id exceeding UINT16_MAX.

The removal of this check might lead to potential issues if _lf_my_fed_id exceeds the maximum value for a uint16_t. Ensure that this change does not introduce any vulnerabilities or unexpected behavior.


Line range hint 1442-1445: Verify the impact of removing the check for _lf_my_fed_id exceeding UINT16_MAX.

The removal of this check might lead to potential issues if _lf_my_fed_id exceeds the maximum value for a uint16_t. Ensure that this change does not introduce any vulnerabilities or unexpected behavior.

@@ -112,23 +112,29 @@ void _lf_message_print(const char* prefix, const char* format, va_list args,
// interleaved between threads.
// vprintf() is a version that takes an arg list rather than multiple args.
char* message;
if (_lf_my_fed_id < 0) {
Copy link
Collaborator Author

@Jakio815 Jakio815 Jul 1, 2024

Choose a reason for hiding this comment

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

This part gives compile time errors, since the uint16_t type will never be a negative integer.

However, if I remove the whole if and else, unit-tests fail, especially, general_utils_pqueue_test_c fails with a segfault.

It will not go through the removed if statement, and fail at line 129, because the name is a NULL pointer. Does anyone have ideas?

I'll leave the call stack below.
image

Copy link
Contributor

@cmnrd cmnrd Jul 2, 2024

Choose a reason for hiding this comment

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

I think it would be good to replace -1 with another id that indicates an uninitialized id or no id. Either 0x0000 or 0xffff. If we go with 0x0000 than of course, the first valid ID would be 0x0001 which is a potential breaking change. So 0xffff seems safer.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a5128d4 and a6bf793.

Files selected for processing (1)
  • core/utils/util.c (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • core/utils/util.c

@lhstrh lhstrh requested review from edwardalee and cmnrd July 4, 2024 07:10
@lhstrh lhstrh changed the title Clarify int types && Change clock-sync to send uint16_t types not int32_t types. Usage of 'fixed-size' integer types in RTI code Jul 4, 2024
Copy link
Contributor

@cmnrd cmnrd left a comment

Choose a reason for hiding this comment

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

Looks good. My only nitpick is that I would like to suggest using a name macro instead of the magic number 0xffff.

core/utils/util.c Outdated Show resolved Hide resolved
Copy link
Contributor

@edwardalee edwardalee left a comment

Choose a reason for hiding this comment

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

LGTM! I made some minor suggestions for paranoid coding.

Comment on lines -1795 to -1801
if (_lf_my_fed_id > UINT16_MAX) {
// This error is very unlikely to occur.
lf_print_error_and_exit("Too many federates! More than %d.", UINT16_MAX);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest:

      if (_lf_my_fed_id == UINT16_MAX) {
        lf_print_error_and_exit("Too many federates! More than %d.", UINT16_MAX - 1);
      }

Comment on lines -1918 to -1923
if (_lf_my_fed_id > UINT16_MAX) {
lf_print_error_and_exit("Too many federates! More than %d.", UINT16_MAX);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest:

      if (_lf_my_fed_id == UINT16_MAX) {
        lf_print_error_and_exit("Too many federates! More than %d.", UINT16_MAX - 1);
      }

core/utils/util.c Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a6bf793 and e231caa.

Files selected for processing (2)
  • core/federated/RTI/rti_remote.c (3 hunks)
  • core/federated/federate.c (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • core/federated/RTI/rti_remote.c
  • core/federated/federate.c

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e231caa and dc11c70.

Files selected for processing (1)
  • core/utils/util.c (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • core/utils/util.c

@Jakio815
Copy link
Collaborator Author

Jakio815 commented Jul 8, 2024

I'm still getting failures on this test, ./gradlew core:compileKotlin on Windows. Does anyone have ideas about this?

@cmnrd
Copy link
Contributor

cmnrd commented Jul 10, 2024

No, the error is really odd. It seems to be related to some caching mechanism. @lhstrh do you have any idea why this fails? Is there a way to reset the CI cache?

@lhstrh
Copy link
Member

lhstrh commented Jul 25, 2024

No, the error is really odd. It seems to be related to some caching mechanism. @lhstrh do you have any idea why this fails? Is there a way to reset the CI cache?

Nope. Not a Windows user... Remove the Gradle cache and try again? It looks like this PR was almost ready to merge but somehow got stuck. How do we move it forward?

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