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

VxWorks support #45

Merged
merged 2 commits into from
Nov 7, 2024
Merged

VxWorks support #45

merged 2 commits into from
Nov 7, 2024

Conversation

biabbas
Copy link
Contributor

@biabbas biabbas commented Oct 7, 2024

Fixes #44

Copy link
Contributor

coderabbitai bot commented Oct 7, 2024

Walkthrough

The changes enhance support for the VxWorks operating system within the src/unix.rs and src/lib.rs modules. Modifications include the introduction of the SCHED_SPORADIC scheduling policy and updates to error handling functions specific to VxWorks. The RealtimeThreadSchedulePolicy enum is extended with a new Sporadic variant, and the set_thread_priority_and_policy function is adjusted for VxWorks compatibility. Additionally, the src/lib.rs file includes conditional compilation directives and updates to the ThreadPriorityValue struct to define a maximum thread priority specific to VxWorks.

Changes

File(s) Change Summary
src/unix.rs Added Sporadic variant to RealtimeThreadSchedulePolicy. Introduced errno() and set_errno() functions. Updated to_posix method to handle Sporadic. Modified set_thread_priority_and_policy to include VxWorks handling.
src/lib.rs Updated module declaration for unix to include target_os = "vxworks". Defined new MAX constant in ThreadPriorityValue struct for VxWorks. Updated error messages for ThreadPriorityValue to specify range for VxWorks.
tests/unix.rs Added support for VxWorks in multiple test functions. Duplicated get_and_set_priority_with_normal_policies for VxWorks. Maintained error handling logic for invalid priority values.

Poem

In the land of threads where bunnies play,
VxWorks hops in, brightening the day.
With policies new and errors in check,
Our library's strong, what the heck!
So let’s thread our way through the code,
With joy in our hearts, let the changes explode! 🐇✨


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@biabbas biabbas force-pushed the vxworks branch 2 times, most recently from bbd65de to 1dd8d9a Compare October 18, 2024 11:50
@biabbas biabbas marked this pull request as ready for review October 18, 2024 12:18
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

🧹 Outside diff range and nitpick comments (2)
src/lib.rs (1)

155-157: VxWorks support added successfully, consider future refinements

The changes successfully integrate VxWorks support into the library by treating it as a Unix-like system for thread priority management. This approach is logical and minimizes code duplication. However, as VxWorks is a real-time operating system, there might be specific considerations or optimizations that could be addressed in the future.

Consider the following for future improvements:

  1. Investigate if VxWorks requires any specific thread priority ranges or scheduling policies that differ from other Unix-like systems.
  2. Evaluate if any VxWorks-specific error handling or system calls need to be implemented.
  3. Test the library thoroughly on VxWorks to ensure full compatibility and optimal performance.

Also applies to: 171-173

src/unix.rs (1)

180-182: Add documentation for the Sporadic scheduling policy

Consider adding documentation to the Sporadic variant of RealtimeThreadSchedulePolicy to explain its behavior and usage on VxWorks.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1135f2e and 1dd8d9a.

⛔ Files ignored due to path filters (1)
  • Cargo.toml is excluded by !**/*.toml
📒 Files selected for processing (2)
  • src/lib.rs (2 hunks)
  • src/unix.rs (10 hunks)
🧰 Additional context used
🔇 Additional comments (11)
src/lib.rs (2)

155-157: LGTM: VxWorks support added to Unix-like systems

The addition of target_os = "vxworks" to the list of Unix-like target operating systems is appropriate. VxWorks, being a real-time operating system that follows POSIX standards, can likely use the same thread priority management implementation as other Unix-like systems. This change enhances the library's cross-platform support.


171-173: LGTM: Consistent VxWorks support in public exports

The addition of target_os = "vxworks" here is consistent with the previous change. This ensures that the Unix-like implementation is not only compiled for VxWorks targets but also publicly exported for use. This consistency is crucial for proper integration of VxWorks support in the library.

src/unix.rs (9)

15-16: LGTM: Adding VxWorks support for SCHED_SPORADIC

The import of SCHED_SPORADIC for VxWorks is appropriate and correctly conditionally compiled.


56-57: LGTM: VxWorks-specific errno retrieval

Using libc::errnoGet() to retrieve the errno on VxWorks is correct.


74-75: LGTM: VxWorks-specific errno setting

Using libc::errnoSet(number) to set the errno on VxWorks is appropriate.


198-199: Correct mapping of Sporadic policy to POSIX constant

Mapping RealtimeThreadSchedulePolicy::Sporadic to SCHED_SPORADIC is correct and ensures proper integration with VxWorks scheduling policies.


298-301: Proper handling of SCHED_SPORADIC in from_posix

The addition of SCHED_SPORADIC in the from_posix method allows for correct conversion from POSIX constants to ThreadSchedulePolicy on VxWorks.


364-365: Include VxWorks in OS conditions for priority specification

Adding VxWorks to the list of operating systems that allow specifying the priority using sched_param is appropriate.


Line range hint 444-450: Ensure consistent priority mapping for VxWorks

Including VxWorks in the conditional compilation ensures that thread priorities are correctly mapped and handled on VxWorks systems.


589-592: Extend priority-setting logic to include VxWorks

Including VxWorks in the condition for setting thread priority via pthread_setschedparam ensures that priorities are correctly set on VxWorks.


631-631: Appropriate exclusion of setpriority for VxWorks

Excluding the call to libc::setpriority for VxWorks is appropriate since VxWorks handles thread priorities differently, and setpriority may not be applicable.

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: 1

🧹 Outside diff range and nitpick comments (3)
src/unix.rs (1)

631-633: Clarify comments regarding setpriority on VxWorks

The addition of #[cfg(not(target_os = "vxworks"))] correctly excludes the call to libc::setpriority() on VxWorks since it is unavailable. The comments can be improved for clarity.

Consider updating the comments as follows:

- // VxWorks does not have setpriority function call. Control never
- // reaches this statement because of the cfg condition in if
+ // VxWorks does not have a `setpriority` function call.
+ // This call is excluded on VxWorks due to the `cfg` condition above.
src/vxworks.rs (2)

1-5: Update Module Documentation to Reflect VxWorks Support

The module documentation indicates that it defines Unix thread control, but this module is specifically for VxWorks. Please update the documentation to accurately reflect the purpose of this module.

Apply this diff to correct the documentation:

-//! This module defines the unix thread control.
+//! This module defines the VxWorks thread control.

147-151: Rename Variable _Sched_param to sched_param for Clarity

In the function from_posix, the parameter _Sched_param is used within the function. Prefixing variable names with an underscore in Rust typically indicates that the variable is unused. For clarity and to adhere to Rust naming conventions, consider renaming _Sched_param to sched_param.

Apply this diff to rename the variable:

-fn from_posix(_Sched_param: libc::_Sched_param) -> Self {
+fn from_posix(sched_param: libc::_Sched_param) -> Self {
    ScheduleParams {
-       sched_priority: _Sched_param.sched_priority,
+       sched_priority: sched_param.sched_priority,
    }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1dd8d9a and e967018.

📒 Files selected for processing (2)
  • src/unix.rs (10 hunks)
  • src/vxworks.rs (1 hunks)
🧰 Additional context used
🔇 Additional comments (10)
src/unix.rs (9)

15-16: Add SCHED_SPORADIC import for VxWorks

The conditional import of SCHED_SPORADIC under #[cfg(target_os = "vxworks")] correctly includes the necessary constant for VxWorks support.


56-57: Implement errno() function for VxWorks

Using libc::errnoGet() in the errno() function appropriately retrieves the error number on VxWorks systems.


74-75: Implement set_errno() function for VxWorks

Utilizing libc::errnoSet(number) in the set_errno() function correctly sets the error number on VxWorks.


180-182: Add Sporadic scheduling policy support

Introducing the Sporadic variant in RealtimeThreadSchedulePolicy adds support for the SCHED_SPORADIC policy on VxWorks systems.


198-199: Map Sporadic policy in to_posix()

Mapping RealtimeThreadSchedulePolicy::Sporadic to SCHED_SPORADIC in the to_posix() method ensures correct POSIX value translation for VxWorks.


298-301: Handle SCHED_SPORADIC in from_posix()

Adding SCHED_SPORADIC handling in the from_posix() function accurately translates the POSIX policy to RealtimeThreadSchedulePolicy::Sporadic for VxWorks.


364-365: Support priority specification on VxWorks

Including target_os = "vxworks" in the condition allows specifying thread priority using scheduling parameters on VxWorks, similar to macOS and iOS.


Line range hint 444-448: Extend priority mapping for VxWorks in to_posix()

Adding target_os = "vxworks" to the condition in to_posix() enables correct mapping of ThreadPriority values to POSIX priorities on VxWorks, consistent with macOS and iOS behavior.


589-592: Enable priority setting on VxWorks in set_thread_priority_and_policy()

Including VxWorks in the condition allows setting thread priority directly using pthread_setschedparam() on VxWorks, aligning with the implementation on macOS and iOS.

src/vxworks.rs (1)

18-21: 🛠️ Refactor suggestion

Prefer Using libc Definitions for Scheduling Constants

The constants SCHED_FIFO, SCHED_RR, SCHED_OTHER, and SCHED_SPORADIC are redefined with hardcoded values. To improve maintainability and ensure correctness, consider using the definitions from the libc crate if they are available for VxWorks.

Run the following script to verify if these constants are defined in libc for VxWorks:

If they are defined, you can replace the hardcoded constants with:

use libc::{SCHED_FIFO, SCHED_RR, SCHED_OTHER, SCHED_SPORADIC};

src/vxworks.rs Outdated Show resolved Hide resolved
src/unix.rs Outdated Show resolved Hide resolved
@biabbas
Copy link
Contributor Author

biabbas commented Oct 21, 2024

r? @iddm

Copy link
Owner

@iddm iddm left a comment

Choose a reason for hiding this comment

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

Thanks! Looks great, just some lint-things. Let's see if the tests pass.

src/unix.rs Outdated Show resolved Hide resolved
src/unix.rs Outdated Show resolved Hide resolved
src/unix.rs Outdated Show resolved Hide resolved
src/unix.rs Outdated Show resolved Hide resolved
src/unix.rs 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: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e967018 and ab7caa8.

📒 Files selected for processing (1)
  • src/unix.rs (10 hunks)
🧰 Additional context used

src/unix.rs Outdated Show resolved Hide resolved
src/unix.rs Outdated Show resolved Hide resolved
src/unix.rs 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

🧹 Outside diff range and nitpick comments (1)
src/unix.rs (1)

Line range hint 590-643: Simplify VxWorks-specific handling in set_thread_priority_and_policy

The addition of VxWorks to the list of operating systems that can set priority using pthread_setschedparam is correct. However, the new cfg_if block for VxWorks-specific handling of setpriority (lines 633-643) seems unnecessary and potentially problematic:

  1. It's inside a block that should only be executed for normal priority threads.
  2. The comment suggests this code is never reached for VxWorks.
  3. It returns an error instead of setting the priority.

Consider removing the VxWorks-specific cfg_if block and simplifying the code as follows:

 if matches!(policy, ThreadSchedulePolicy::Realtime(_))
-    || cfg!(any(target_os = "macos", target_os = "ios", target_os = "vxworks"))
+    || cfg!(any(target_os = "macos", target_os = "ios"))
 {
     // If the policy is a realtime one, the priority is set via
     // pthread_setschedparam.
     let params = ScheduleParams {
         sched_priority: fixed_priority,
     }
     .into_posix();

     let ret = unsafe {
         libc::pthread_setschedparam(
             native,
             policy.to_posix(),
             &params as *const libc::sched_param,
         )
     };

     match ret {
         0 => Ok(()),
         e => Err(Error::OS(e)),
     }
 } else {
     // Normal priority threads must be set with static priority 0.
     let params = ScheduleParams { sched_priority: 0 }.into_posix();

     let ret = unsafe {
         libc::pthread_setschedparam(
             native,
             policy.to_posix(),
             &params as *const libc::sched_param,
         )
     };

     if ret != 0 {
         return Err(Error::OS(ret));
     }

     // Normal priority threads adjust relative priority through niceness.
     set_errno(0);

-    // VxWorks does not have setpriority function call. Control never
-    // reaches this statement because of the cfg condition in if
-    cfg_if::cfg_if!{
-        if #[cfg(target_os = "vxworks")] {
-            return Err(Error::Priority("Could not set priority as set priority is not available on vxworks"));
-        } else {
-            let ret = unsafe { libc::setpriority(libc::PRIO_PROCESS, 0, fixed_priority) };
-            if ret != 0 {
-                return Err(Error::OS(errno()));
-            }
-        }
-    }
+    let ret = unsafe { libc::setpriority(libc::PRIO_PROCESS, 0, fixed_priority) };
+    if ret != 0 {
+        return Err(Error::OS(errno()));
+    }

     Ok(())
 }

This simplification removes the unnecessary VxWorks-specific handling and maintains the correct behavior for other operating systems.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ab7caa8 and 8160f6c.

📒 Files selected for processing (1)
  • src/unix.rs (10 hunks)
🧰 Additional context used
🔇 Additional comments (6)
src/unix.rs (6)

15-16: LGTM: Addition of SCHED_SPORADIC for VxWorks

The addition of SCHED_SPORADIC for VxWorks is correctly implemented and aligns with the PR objective of adding VxWorks support.


56-57: LGTM: VxWorks-specific error handling added

The addition of VxWorks-specific error handling using libc::errnoGet() is correctly implemented and consistent with error handling for other operating systems.


74-75: LGTM: VxWorks-specific error setting added

The addition of VxWorks-specific error setting using libc::errnoSet(number) is correctly implemented and consistent with error setting for other operating systems.


180-183: LGTM: Sporadic variant added to RealtimeThreadSchedulePolicy

The addition of the Sporadic variant to the RealtimeThreadSchedulePolicy enum is well-implemented and documented. It correctly supports VxWorks-specific functionality.


199-200: LGTM: Sporadic case added to to_posix method

The addition of the Sporadic case in the RealtimeThreadSchedulePolicy::to_posix method is correct and consistent with the earlier addition of the Sporadic variant.


445-445: LGTM: VxWorks added to normal thread scheduling cfg attribute

The addition of VxWorks to the cfg attribute for normal thread scheduling is correct and consistent with the overall goal of adding VxWorks support.

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

🧹 Outside diff range and nitpick comments (1)
src/unix.rs (1)

Line range hint 590-623: LGTM with suggestion: VxWorks support added to set_thread_priority_and_policy

The changes to include VxWorks in the priority setting logic are correct. However, there's a potential improvement for the VxWorks-specific setpriority function:

  1. The current implementation panics, which might not be the best approach for a library function.
  2. Consider returning an error instead of panicking.

Consider modifying the VxWorks-specific setpriority function to return an error instead of panicking:

#[cfg(target_os = "vxworks")]
unsafe fn setpriority(_which: u32, _who: u32, _priority: libc::c_int) -> libc::c_int {
    libc::ENOSYS  // Or another appropriate error code
}

This change would allow the caller to handle the unsupported function more gracefully.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8160f6c and f8a2195.

📒 Files selected for processing (1)
  • src/unix.rs (11 hunks)
🧰 Additional context used
📓 Learnings (1)
src/unix.rs (2)
Learnt from: biabbas
PR: iddm/thread-priority#45
File: src/unix.rs:445-445
Timestamp: 2024-10-22T09:16:09.579Z
Learning: Consistently including `target_os = "vxworks"` in `cfg` attributes is important to ensure full VxWorks support across the codebase.
Learnt from: biabbas
PR: iddm/thread-priority#45
File: src/unix.rs:445-445
Timestamp: 2024-10-22T03:27:30.771Z
Learning: VxWorks falls back to Unix code for most functionality, so missing `target_os = "vxworks"` in `cfg` attributes may not be an issue.
🔇 Additional comments (7)
src/unix.rs (7)

15-16: LGTM: VxWorks-specific scheduling policy added

The addition of SCHED_SPORADIC for VxWorks is correctly implemented with the appropriate conditional compilation directive.


56-57: LGTM: VxWorks-specific error handling added

The addition of VxWorks-specific error handling using libc::errnoGet() is correctly implemented with the appropriate conditional compilation directive.


74-75: LGTM: VxWorks-specific error setting added

The addition of VxWorks-specific error setting using libc::errnoSet(number) is correctly implemented with the appropriate conditional compilation directive.


180-183: LGTM: Sporadic scheduling policy added for VxWorks

The addition of the Sporadic variant to the RealtimeThreadSchedulePolicy enum is correctly implemented with the appropriate conditional compilation directive and clear documentation.


199-200: LGTM: Sporadic policy mapping added

The addition of the Sporadic case in the RealtimeThreadSchedulePolicy::to_posix method is correctly implemented with the appropriate conditional compilation directive.


299-302: LGTM: Sporadic policy parsing added

The addition of the Sporadic case in the ThreadSchedulePolicy::from_posix method is correctly implemented with the appropriate conditional compilation directive.


Line range hint 1-923: Summary: VxWorks support successfully implemented

The changes to add VxWorks support in src/unix.rs are well-implemented and consistent. Key points:

  1. Appropriate use of conditional compilation for VxWorks-specific code.
  2. Addition of the Sporadic scheduling policy for VxWorks.
  3. VxWorks-specific error handling and setting.
  4. Modifications to existing functions to accommodate VxWorks.

The only suggestion for improvement is to modify the VxWorks-specific setpriority function to return an error instead of panicking.

Overall, the implementation successfully adds VxWorks support to the thread priority management functionality.

@biabbas
Copy link
Contributor Author

biabbas commented Oct 22, 2024

Cargo test fails for VxWorks. The max value check in lib.rs for threadpriority seems to be the problem.

[vxWorks *]# ./unix-2dd6dee514656752.vxe

running 2 tests
test get_and_set_priority_with_realtime_policy_requires_capabilities::case_1_fifo ... FAILED
test get_and_set_priority_with_realtime_policy_requires_capabilities::case_2_roundrobin ... FAILED

failures:

---- get_and_set_priority_with_realtime_policy_requires_capabilities::case_1_fifo stdout ----
thread 'get_and_set_priority_with_realtime_policy_requires_capabilities::case_1_fifo' panicked at 'called `Result::unwrap()` on an `Err` value: "The value is not in the range of [0;99]"', tests/unix.rs:158:82
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- get_and_set_priority_with_realtime_policy_requires_capabilities::case_2_roundrobin stdout ----
thread 'get_and_set_priority_with_realtime_policy_requires_capabilities::case_2_roundrobin' panicked at 'called `Result::unwrap()` on an `Err` value: "The value is not in the range of [0;99]"', tests/unix.rs:158:82


failures:
    get_and_set_priority_with_realtime_policy_requires_capabilities::case_1_fifo
    get_and_set_priority_with_realtime_policy_requires_capabilities::case_2_roundrobin

test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.70s

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

🧹 Outside diff range and nitpick comments (2)
src/lib.rs (2)

155-155: Ensure Consistency in Conditional Compilation Statements

In both conditional compilation blocks, target_os = "vxworks" has been added. However, the entry for target_os = "netbsd" has been moved. Ensure that netbsd is included consistently in both blocks to maintain support across all intended Unix-like platforms.

Also applies to: 171-171


248-253: Update Documentation for ThreadPriorityValue::MAX

The documentation for ThreadPriorityValue::MAX should mention that the maximum value differs on VxWorks. This will help users understand the platform-specific behavior.

Consider adding a note to the documentation:

/// The maximum value for a thread priority.
/// 
/// - On VxWorks, the maximum value is `255`.
/// - On other platforms, the maximum value is `99`.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f8a2195 and 3db1c32.

📒 Files selected for processing (1)
  • src/lib.rs (3 hunks)
🧰 Additional context used
🔇 Additional comments (2)
src/lib.rs (2)

248-253: ⚠️ Potential issue

Update Error Message in try_from Implementation

The try_from method's error message still references the old priority range [0;99]. Since the maximum priority value is now 255 for VxWorks, the error message should be updated to reflect the new valid range.

Apply the following diff to correct the error message:

 fn try_from(value: u8) -> Result<Self, Self::Error> {
     if (Self::MIN..=Self::MAX).contains(&value) {
         Ok(Self(value))
     } else {
-        Err("The value is not in the range of [0;99]")
+        Err("The value is not in the valid priority range")
     }
 }

Likely invalid or redundant comment.


248-253: Verify Usage of ThreadPriorityValue::MAX in the Codebase

The change in MAX value for VxWorks may affect other parts of the code that rely on this constant. Verify that all usages of ThreadPriorityValue::MAX properly handle the new maximum value for VxWorks.

Run the following script to find all instances where ThreadPriorityValue::MAX is used:

✅ Verification successful

Usage of ThreadPriorityValue::MAX Verified

All usages of ThreadPriorityValue::MAX properly handle the new maximum value for VxWorks.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all usages of ThreadPriorityValue::MAX in the codebase

# Search for ThreadPriorityValue::MAX and display the surrounding 3 lines for context
rg -A 3 -B 3 'ThreadPriorityValue::MAX'

Length of output: 676

@biabbas biabbas force-pushed the vxworks branch 3 times, most recently from 6f599a6 to df5ff42 Compare October 22, 2024 12:04
@biabbas biabbas requested a review from iddm October 22, 2024 12:05
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

🧹 Outside diff range and nitpick comments (2)
src/unix.rs (2)

180-183: LGTM: VxWorks-specific Sporadic variant added correctly

The addition of the Sporadic variant to RealtimeThreadSchedulePolicy enum is correctly implemented with the appropriate cfg attribute for VxWorks. The comment provides a brief description of the variant.

Consider expanding the comment to provide more context about when and why this scheduling policy might be used in VxWorks systems.


Line range hint 590-623: VxWorks support added, but error handling could be improved

The changes correctly add VxWorks to the list of OSes where priority can be set using pthread_setschedparam. The VxWorks-specific handling of setpriority is also added.

However, the current implementation panics if setpriority is called on VxWorks. Consider returning an error instead of panicking for better error handling in production code. For example:

#[cfg(target_os = "vxworks")]
unsafe fn setpriority(_which: u32, _who: u32, _priority: libc::c_int) -> libc::c_int {
    -1 // Return an error code
}

// Then, in the calling code:
if cfg!(target_os = "vxworks") {
    return Err(Error::Priority("Set priority function not supported by VxWorks"));
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3db1c32 and df5ff42.

📒 Files selected for processing (3)
  • src/lib.rs (4 hunks)
  • src/unix.rs (11 hunks)
  • tests/unix.rs (2 hunks)
🧰 Additional context used
📓 Learnings (1)
src/unix.rs (2)
Learnt from: biabbas
PR: iddm/thread-priority#45
File: src/unix.rs:445-445
Timestamp: 2024-10-22T09:16:09.579Z
Learning: Consistently including `target_os = "vxworks"` in `cfg` attributes is important to ensure full VxWorks support across the codebase.
Learnt from: biabbas
PR: iddm/thread-priority#45
File: src/unix.rs:445-445
Timestamp: 2024-10-22T03:27:30.771Z
Learning: VxWorks falls back to Unix code for most functionality, so missing `target_os = "vxworks"` in `cfg` attributes may not be an issue.
🔇 Additional comments (8)
src/unix.rs (4)

15-16: LGTM: VxWorks-specific import added correctly

The addition of SCHED_SPORADIC import for VxWorks is correctly implemented with the appropriate cfg attribute. This change enhances VxWorks support in the codebase.


199-200: LGTM: VxWorks-specific Sporadic policy handling added correctly

The addition of the Sporadic case in the to_posix method is correctly implemented with the appropriate cfg attribute for VxWorks. This change ensures proper handling of the new scheduling policy for VxWorks systems.


365-366: LGTM: VxWorks support added to priority edge value calculation

The addition of VxWorks to the list of OSes in the ThreadPriority::get_edge_value_for_policy method is correct and consistent with the other VxWorks-related changes in the file.


Line range hint 1-853: Overall assessment: VxWorks support successfully implemented

The changes in this file successfully implement VxWorks support with appropriate use of conditional compilation and handling of VxWorks-specific behaviors. The modifications include:

  1. Adding VxWorks-specific imports
  2. Extending the RealtimeThreadSchedulePolicy enum with a Sporadic variant for VxWorks
  3. Updating the to_posix method to handle the new Sporadic policy
  4. Modifying the set_thread_priority_and_policy function to accommodate VxWorks
  5. Including VxWorks in priority edge value calculations

While the implementation is generally solid, consider improving the error handling for the setpriority function on VxWorks as suggested earlier.

tests/unix.rs (2)

Line range hint 49-54: Verify VxWorks compatibility in get_and_set_priority_with_normal_policies

The addition of target_os = "vxworks" allows this test to run on VxWorks. However, according to the PR objectives, tests are failing on VxWorks due to thread priority range issues. VxWorks may have different priority ranges for scheduling policies compared to other Unix-like systems. Please review and adjust the test cases to accommodate VxWorks-specific priority constraints to ensure they pass successfully.

Would you like assistance in modifying the test cases for VxWorks-specific behavior?


Line range hint 111-118: Ensure get_and_set_priority_with_normal_policy aligns with VxWorks behavior

By including target_os = "vxworks" in the conditional compilation, this test now runs on VxWorks. It's important to confirm that the assumptions in this test hold true for VxWorks, especially regarding the acceptance of non-zero priority values with the SCHED_OTHER policy. Since VxWorks may handle thread priorities differently, adjustments to the test or handling logic may be necessary.

Would you like assistance in adapting the test to VxWorks-specific scheduling policies?

src/lib.rs (2)

155-158: Approved: Added VxWorks to conditional compilation directives

The inclusion of target_os = "vxworks" in the conditional compilation directives correctly adds support for VxWorks. This ensures that the Unix module is compiled for VxWorks systems.


171-174: Approved: Exporting Unix module for VxWorks

The update to pub use unix::*; now includes VxWorks, allowing the Unix-specific implementations to be used on VxWorks platforms.

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@biabbas biabbas force-pushed the vxworks branch 2 times, most recently from d7a7769 to eb541fb Compare October 22, 2024 12:29
@biabbas
Copy link
Contributor Author

biabbas commented Oct 22, 2024

Test results for VxWorks

[vxWorks *]# ./tests/common-a84adfa34cf086c5.vxe

running 3 tests
test should_be_impossible_to_get_other_thread_native_id_via_threadext ... ok
test should_be_possible_to_get_current_thread_native_id_via_threadext ... ok
test should_be_possible_to_reset_the_same_priority ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.07s

[vxWorks *]# ./tests/unix-2dd6dee514656752.vxe

running 6 tests
test get_and_set_priority_with_normal_policies::policy_1_ThreadSchedulePolicy__Normal_NormalThreadSchedulePolicy__Other_::priority_1_ThreadPriority__Min ... ok
test get_and_set_priority_with_normal_policies::policy_1_ThreadSchedulePolicy__Normal_NormalThreadSchedulePolicy__Other_::priority_2_ThreadPriority__Max ... ok
test get_and_set_priority_with_normal_policies::policy_1_ThreadSchedulePolicy__Normal_NormalThreadSchedulePolicy__Other_::priority_3_ThreadPriority__Crossplatform_23u8_try_into___unwrap___ ... ok
test get_and_set_priority_with_normal_policy ... ok
test get_and_set_priority_with_realtime_policy_requires_capabilities::case_1_fifo ... ok
test get_and_set_priority_with_realtime_policy_requires_capabilities::case_2_roundrobin ... ok

test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.10s

[vxWorks *]# ./tests/thread_priority-16d21276c67c2411.vxe

running 2 tests
test unix::tests::change_between_realtime_and_normal_policies_requires_capabilities ... ok
test unix::tests::thread_schedule_policy_param_test ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.05s

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: 1

🧹 Outside diff range and nitpick comments (1)
src/unix.rs (1)

180-183: Enhance documentation for VxWorks Sporadic scheduling

While the basic documentation is present, it would be helpful to add more details about:

  • How Sporadic scheduling behaves in VxWorks
  • When to use this policy over Fifo or RoundRobin
  • Any VxWorks-specific limitations or considerations

Apply this diff to improve the documentation:

-    /// A sporadic scheduling policy specific to VxWorks.
+    /// A sporadic scheduling policy specific to VxWorks.
+    /// 
+    /// Sporadic threads are similar to FIFO threads but with additional
+    /// constraints on execution time and period. They are useful for
+    /// tasks that need precise control over CPU utilization while
+    /// maintaining real-time characteristics.

Also applies to: 199-200

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between df5ff42 and 45f18da.

📒 Files selected for processing (3)
  • src/lib.rs (4 hunks)
  • src/unix.rs (11 hunks)
  • tests/unix.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/unix.rs
🧰 Additional context used
📓 Learnings (1)
src/unix.rs (2)
Learnt from: biabbas
PR: iddm/thread-priority#45
File: src/unix.rs:445-445
Timestamp: 2024-10-22T09:16:09.579Z
Learning: Consistently including `target_os = "vxworks"` in `cfg` attributes is important to ensure full VxWorks support across the codebase.
Learnt from: biabbas
PR: iddm/thread-priority#45
File: src/unix.rs:445-445
Timestamp: 2024-10-22T03:27:30.771Z
Learning: VxWorks falls back to Unix code for most functionality, so missing `target_os = "vxworks"` in `cfg` attributes may not be an issue.
🔇 Additional comments (6)
src/lib.rs (4)

155-155: LGTM: VxWorks support added consistently

The VxWorks operating system has been correctly added to the conditional compilation directives for Unix-like systems.

Also applies to: 171-171


255-265: LGTM: Improved error handling with dynamic range values

The error handling has been enhanced to:

  1. Use String instead of &'static str for dynamic error messages
  2. Include the actual valid range in the error message, which is crucial for VxWorks support

Line range hint 817-829: LGTM: ThreadScopeExt implementation is correct

The implementation follows Rust's standard patterns for scoped threads and properly handles priority setting.


249-249: Verify the impact of the new MAX value

The MAX value has been updated to support VxWorks' wider priority range (0-255). Let's verify that this change doesn't affect existing code that might assume the previous maximum of 99.

✅ Verification successful

Let's examine the actual usage of these priority values and tests to make a proper assessment.


Let's check the actual implementation and tests to see how the priority values are validated and used.


Based on the comprehensive analysis of the code, I can now provide the final response:

The MAX value change is safely implemented with proper validation

The change to support VxWorks' priority range (0-255) is well-handled because:

  • The try_from implementation properly validates values against the new conditional MAX
  • Windows implementation explicitly handles the range 0-99 in its priority mapping
  • Unix implementation safely maps priorities using ratio calculations that work with both ranges
  • No hardcoded assumptions about the maximum value were found in tests or implementations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for direct usage of ThreadPriorityValue::MAX or hardcoded values
rg -l "ThreadPriorityValue::MAX|priority.*99|priority.*255"

# Search for potential test cases that might need updating
rg -l "test.*priority.*range|assert.*priority"

Length of output: 201


Script:

#!/bin/bash
# Check actual usage in unix.rs
rg -A 5 -B 5 "ThreadPriorityValue::MAX|priority.*99|priority.*255" src/unix.rs

# Check test assertions and priority range tests
rg -A 5 -B 5 "test.*priority.*range|assert.*priority" tests/unix.rs tests/windows.rs

# Check documentation mentions
rg -A 5 -B 5 "priority.*range|ThreadPriorityValue::MAX" README.md

Length of output: 1921


Script:

#!/bin/bash
# Check priority value validation and usage in lib.rs
rg -A 10 -B 10 "impl ThreadPriorityValue|impl ThreadPriority" src/lib.rs

# Check for any range checks or validations
ast-grep --pattern 'fn try_from($$$) -> Result<$$$> { $$$ }'

# Check for any priority conversion or mapping logic
rg -A 10 -B 10 "priority.*into|from.*priority" src/lib.rs src/unix.rs src/windows.rs

Length of output: 21107

src/unix.rs (2)

13-14: LGTM: VxWorks error handling implementation

The implementation correctly uses VxWorks-specific error handling functions errnoGet() and errnoSet().

Also applies to: 56-57, 74-75


445-452: Verify thread priority ranges for VxWorks

Based on the PR objectives mentioning test failures with priority range [0;99], we should verify that the priority ranges are correctly handled for VxWorks.

Also applies to: 590-597

✅ Verification successful

Priority range handling for VxWorks is correctly implemented

The verification shows that VxWorks priority ranges are properly handled:

  • VxWorks has a wider priority range [0..255] compared to other platforms [0..99], as defined in ThreadPriorityValue::MAX
  • Priority validation is handled through to_allowed_value_for_policy which uses get_min_priority and get_max_priority to enforce platform-specific ranges
  • VxWorks-specific scheduling policies (including SCHED_SPORADIC) are properly configured with appropriate cfg attributes
  • Priority setting is implemented via pthread_setschedparam for VxWorks, similar to macOS/iOS
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check priority range handling in tests and implementation

# Search for priority range checks
echo "Priority range checks:"
rg -A 5 "PriorityNotInRange|allowed_range|min_priority|max_priority" src/

# Search for VxWorks-specific test cases
echo -e "\nVxWorks test cases:"
rg -A 5 "target_os.*vxworks.*test" src/ tests/

Length of output: 2931


Script:

#!/bin/bash
# Let's check for VxWorks-specific priority handling and policy implementations

# Search for VxWorks-specific cfg attributes and their associated code
echo "VxWorks-specific priority handling:"
rg -B 2 -A 5 'target_os.*vxworks' src/

# Search for policy-to-priority value conversions
echo -e "\nPolicy to priority conversions:"
ast-grep --pattern 'fn to_allowed_value_for_policy($$$) { $$$ }'

# Check for any VxWorks-specific constants or priority ranges
echo -e "\nPriority range constants:"
rg -A 2 'const.*PRIORITY|PRIORITY_.*=' src/

Length of output: 8783

src/unix.rs 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: 2

🧹 Outside diff range and nitpick comments (2)
tests/unix.rs (1)

Line range hint 142-220: Fix test assumptions about priority ranges for VxWorks.

The test get_and_set_priority_with_realtime_policy_requires_capabilities is failing for VxWorks because it assumes a priority range of [0;99] which is incorrect for VxWorks (which uses [0;255]). This explains the test failures mentioned in the PR objectives for case_1_fifo and case_2_roundrobin.

The test should be updated to handle OS-specific priority ranges. Here's a suggested fix:

 #[rstest]
 #[case::fifo(ThreadSchedulePolicy::Realtime(RealtimeThreadSchedulePolicy::Fifo))]
 #[case::roundrobin(ThreadSchedulePolicy::Realtime(RealtimeThreadSchedulePolicy::RoundRobin))]
 fn get_and_set_priority_with_realtime_policy_requires_capabilities(
     #[case] realtime_policy: ThreadSchedulePolicy,
 ) {
     let thread_id = thread_native_id();
+    // Get the OS-specific max/min values instead of assuming [0;99]
     let max_value = ThreadPriority::max_value_for_policy(realtime_policy).unwrap();
     let min_value = ThreadPriority::min_value_for_policy(realtime_policy).unwrap();
 
     assert_eq!(
         set_thread_priority_and_policy(thread_id, ThreadPriority::Max, realtime_policy,),
         Ok(())
     );

This change will ensure the test uses the correct priority ranges for each OS, fixing the VxWorks test failures.

src/unix.rs (1)

180-183: Enhance documentation for Sporadic scheduling policy

While the implementation is correct, the documentation could be more detailed to help users understand:

  • When to use Sporadic scheduling over other policies
  • Any VxWorks-specific considerations or limitations

Consider expanding the documentation:

-    /// A sporadic scheduling policy specific to VxWorks.
+    /// A sporadic scheduling policy specific to VxWorks that allows threads to execute with
+    /// real-time priority for a specified amount of time within a given period.
+    /// This policy is useful for tasks that need to meet soft real-time constraints while
+    /// efficiently sharing CPU resources.

Also applies to: 199-200

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 45f18da and 5766c10.

📒 Files selected for processing (3)
  • src/lib.rs (4 hunks)
  • src/unix.rs (11 hunks)
  • tests/unix.rs (2 hunks)
🧰 Additional context used
📓 Learnings (1)
src/unix.rs (2)
Learnt from: biabbas
PR: iddm/thread-priority#45
File: src/unix.rs:445-445
Timestamp: 2024-10-22T09:16:09.579Z
Learning: Consistently including `target_os = "vxworks"` in `cfg` attributes is important to ensure full VxWorks support across the codebase.
Learnt from: biabbas
PR: iddm/thread-priority#45
File: src/unix.rs:445-445
Timestamp: 2024-10-22T03:27:30.771Z
Learning: VxWorks falls back to Unix code for most functionality, so missing `target_os = "vxworks"` in `cfg` attributes may not be an issue.
🔇 Additional comments (7)
src/lib.rs (3)

155-155: LGTM: VxWorks configuration is properly integrated

The addition of VxWorks to the Unix-like systems configuration is correct and consistent.

Also applies to: 171-171


249-249: LGTM: Thread priority range correctly adjusted for VxWorks

The MAX constant is properly configured to support VxWorks' wider priority range (0-255) while maintaining the existing range (0-99) for other platforms.


255-265: LGTM: Error handling improved with dynamic range values

The error handling has been enhanced to:

  1. Use String type for dynamic error messages
  2. Include actual MIN and MAX values in the error message
  3. Provide clearer feedback about valid priority ranges
src/unix.rs (4)

13-14: LGTM: VxWorks error handling implementation

The implementation correctly uses VxWorks-specific errnoGet and errnoSet functions for error handling, maintaining consistency with other OS implementations.

Also applies to: 56-57, 74-75


445-452: LGTM: VxWorks priority handling implementation

The implementation correctly handles VxWorks thread priorities:

  • Uses pthread_setschedparam for priority setting, similar to macOS/iOS
  • Properly handles priority conversion for VxWorks threads

Also applies to: 590-597


619-632: LGTM: VxWorks setpriority implementation

The implementation correctly handles the absence of setpriority in VxWorks:

  • Returns ENOSYS to indicate unsupported functionality
  • Sets errno correctly
  • Uses proper cfg attributes for conditional compilation

445-452: Verify thread priority ranges for VxWorks

Let's verify that the thread priority ranges are correctly handled for VxWorks.

✅ Verification successful

The search results show clear evidence of VxWorks-specific thread priority handling. In src/lib.rs, there's a dedicated constant MAX that's set to 255 for VxWorks (compared to 99 for other platforms):

pub const MAX: u8 = if cfg!(target_os = "vxworks") { 255 } else { 99 };

Let me verify the complete implementation by checking how these values are used in VxWorks-specific code paths.


Thread priority ranges for VxWorks are correctly implemented

The verification confirms proper handling of VxWorks thread priorities:

  • VxWorks-specific maximum priority is set to 255 (compared to 99 for other platforms)
  • VxWorks supports the SCHED_SPORADIC scheduling policy
  • Priority handling for VxWorks follows the same pattern as macOS/iOS for SCHED_OTHER policy
  • The implementation correctly maps priority values through to_allowed_value_for_policy
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check thread priority range handling for VxWorks

# Test: Search for VxWorks-specific priority range definitions
rg -A 5 'ThreadPriorityValue|MAX_PRIORITY' src/

Length of output: 4826


Script:

#!/bin/bash
# Search for VxWorks-specific scheduling code
rg -B 3 -A 3 'target_os = "vxworks"' src/

Length of output: 5881

tests/unix.rs Show resolved Hide resolved
src/lib.rs 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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5766c10 and fed2e16.

📒 Files selected for processing (1)
  • tests/unix.rs (3 hunks)
🧰 Additional context used
📓 Learnings (1)
tests/unix.rs (2)
Learnt from: biabbas
PR: iddm/thread-priority#45
File: src/unix.rs:445-445
Timestamp: 2024-10-22T09:16:09.579Z
Learning: Consistently including `target_os = "vxworks"` in `cfg` attributes is important to ensure full VxWorks support across the codebase.
Learnt from: biabbas
PR: iddm/thread-priority#45
File: src/unix.rs:445-445
Timestamp: 2024-10-22T03:27:30.771Z
Learning: VxWorks falls back to Unix code for most functionality, so missing `target_os = "vxworks"` in `cfg` attributes may not be an issue.
🔇 Additional comments (3)
tests/unix.rs (3)

49-49: LGTM! VxWorks correctly grouped with Unix-like systems.

The addition of VxWorks to the OS target list is appropriate as it shares similar thread priority behavior with other Unix-like systems.


74-81: LGTM! Comprehensive test coverage for VxWorks scheduling policies.

The test cases correctly:

  • Use VxWorks priority range [0..=255] consistently across all policies
  • Include all scheduling policies including the VxWorks-specific Sporadic policy

68-73: Verify priority range exclusions for VxWorks.

The exclusion of VxWorks from standard Unix priority ranges ([-20..=19] for Other and [0..=99] for Realtime) is correct, as VxWorks uses a different priority range.

Let's verify the priority ranges in the codebase:

✅ Verification successful

Let me gather more information about the priority ranges, particularly focusing on VxWorks specific code.


Based on the comprehensive search results, I can now verify the priority ranges for VxWorks and generate the final response:

Priority range exclusions for VxWorks are correctly configured

The code correctly handles VxWorks-specific priority ranges:

  • VxWorks uses [0..=255] range for all policies (Other, Fifo, RoundRobin, Sporadic)
  • Other Unix systems use:
    • [-20..=19] for Normal/Other policy
    • [0..=99] for Realtime policies (Fifo, RoundRobin)

This is verified by:

  • ThreadPriorityValue::MAX constant in src/lib.rs: if cfg!(target_os = "vxworks") { 255 } else { 99 }
  • Test cases in tests/unix.rs with correct ranges for each OS
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify priority range definitions for VxWorks
# Look for priority range definitions and validations

rg -B2 -A2 '0..=\d+' src/

Length of output: 270


Script:

#!/bin/bash
# Search for VxWorks specific priority handling
rg -B3 -A3 "vxworks|VxWorks" --type rust

# Search for priority range validations
rg -B3 -A3 "priority|Priority" --type rust

Length of output: 98789

tests/unix.rs Show resolved Hide resolved
Update src/unix.rs for vxWorks tests

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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

🧹 Outside diff range and nitpick comments (3)
src/unix.rs (3)

180-183: Enhance documentation for VxWorks SCHED_SPORADIC policy.

While the implementation is correct, consider adding more detailed documentation about:

  • How SCHED_SPORADIC differs from FIFO/RR in VxWorks
  • Any VxWorks-specific limitations or behaviors
  • When to use this policy over others

Apply this diff to improve documentation:

-    // Policy similar to Fifo
-    /// A sporadic scheduling policy specific to VxWorks.
+    /// A sporadic scheduling policy specific to VxWorks.
+    /// 
+    /// This policy is similar to FIFO but with additional constraints:
+    /// - Allows specification of replenishment period
+    /// - Provides execution time budget control
+    /// - Suitable for tasks that execute periodically with sporadic behavior

Also applies to: 199-200, 299-302


619-632: Improve setpriority implementation for VxWorks.

While the implementation is functionally correct, consider these improvements:

  1. Extract the setpriority implementation into a separate function
  2. Provide a more descriptive error message through errno

Apply this diff to improve the implementation:

+#[cfg(target_os = "vxworks")]
+unsafe fn setpriority_vxworks(
+    which: u32,
+    who: u32,
+    priority: libc::c_int,
+) -> libc::c_int {
+    // VxWorks does not support the setpriority syscall
+    set_errno(libc::ENOSYS);
+    -1
+}

-//VxWorks does not have set priority function
-#[cfg(target_os = "vxworks")]
-unsafe fn setpriority(
-    _which: u32,
-    _who: u32,
-    _priority: libc::c_int,
-) -> libc::c_int {
-    set_errno(libc::ENOSYS);
-    -1
-}
+#[cfg(target_os = "vxworks")]
+use setpriority_vxworks as setpriority;

Based on the verification results, I can now provide a final response about the VxWorks support:

VxWorks support is properly implemented but has a minor inconsistency in error handling

  • VxWorks has proper support for all required scheduling policies (SCHED_SPORADIC, SCHED_FIFO, SCHED_RR, SCHED_OTHER)
  • The setpriority function is correctly handled with a VxWorks-specific stub that sets ENOSYS
  • VxWorks is properly included in the OS-specific priority handling paths alongside macOS/iOS
  • However, there's an inconsistency in error handling where VxWorks uses errnoSet() but ignores its return value with let _, which could mask potential errors

Locations needing attention:

  • src/unix.rs: The set_errno function should properly handle the return value from errnoSet() for VxWorks
🔗 Analysis chain

Line range hint 1-932: Verify complete VxWorks support across the codebase.

Let's verify that VxWorks support is consistently implemented across all critical paths.


Let me generate additional scripts to better verify VxWorks support.


Let me generate one final verification script with corrected regex patterns.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify VxWorks support completeness

# Test 1: Check for any missing VxWorks cfg attributes in critical paths
echo "Checking for potential missing VxWorks cfg attributes..."
rg --type rust "cfg\(.*target_os.*\)" | grep -v "vxworks" | grep "macos\|ios"

# Test 2: Verify all required VxWorks-specific functions are implemented
echo "Verifying VxWorks-specific function implementations..."
rg --type rust "fn.*\(.*\).*\{" | grep -B 2 "cfg.*vxworks"

# Test 3: Check for potential inconsistencies in error handling
echo "Checking error handling consistency..."
rg --type rust "Error::" | grep -B 2 -A 2 "cfg.*vxworks"

Length of output: 746


Script:

#!/bin/bash
# Description: Comprehensive VxWorks support verification

# Check 1: Find all VxWorks-specific code paths
echo "=== VxWorks-specific code paths ==="
rg --type rust "#\[cfg\(target_os\s*=\s*\"vxworks\"\)\]" -B 2 -A 2

# Check 2: Find all VxWorks-specific types and constants
echo -e "\n=== VxWorks-specific types and constants ==="
rg --type rust "(?:#\[cfg\(target_os\s*=\s*\"vxworks\"\)\].*\n)?(pub\s+)?(type|const|static|struct|enum)" -A 1

# Check 3: Verify error handling paths that should include VxWorks
echo -e "\n=== Error handling paths ==="
rg --type rust "cfg_if! \{.*\n.*if.*target_os.*\n.*\}" -A 5

# Check 4: Find potential missing VxWorks cases in OS-specific code
echo -e "\n=== Potential missing VxWorks cases ==="
rg --type rust "target_os\s*=\s*\"(?!vxworks).*\".*\n.*\{" -A 3

# Check 5: Check scheduling policy implementations
echo -e "\n=== Scheduling policy implementations ==="
rg --type rust "(ThreadSchedulePolicy|RealtimeThreadSchedulePolicy|NormalThreadSchedulePolicy).*impl"

Length of output: 4335


Script:

#!/bin/bash

# Check 1: Find VxWorks-specific error handling with fixed regex
echo "=== VxWorks error handling ==="
rg --type rust -U "cfg_if!.*if.*vxworks.*\{" -A 5

# Check 2: Find potential missing VxWorks cases with fixed pattern
echo -e "\n=== OS-specific implementations ==="
rg --type rust "target_os.*=.*\"(linux|macos|ios|android|freebsd)\"" -A 2

# Check 3: Verify VxWorks scheduling policy support
echo -e "\n=== VxWorks scheduling policies ==="
rg --type rust "SCHED_(SPORADIC|FIFO|RR|OTHER)" -B 1

# Check 4: Find VxWorks-specific function implementations with fixed pattern
echo -e "\n=== VxWorks-specific functions ==="
rg --type rust "#\[cfg.*vxworks.*\](\n|\r\n).*fn.*\{" -A 2

# Check 5: Check ThreadExt implementation consistency
echo -e "\n=== ThreadExt implementation ==="
rg --type rust "impl.*ThreadExt.*\{" -A 10

Length of output: 14743

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b6d2073 and d4cec67.

📒 Files selected for processing (3)
  • src/lib.rs (4 hunks)
  • src/unix.rs (11 hunks)
  • tests/unix.rs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/unix.rs
🧰 Additional context used
📓 Learnings (1)
src/unix.rs (2)
Learnt from: biabbas
PR: iddm/thread-priority#45
File: src/unix.rs:445-445
Timestamp: 2024-10-22T09:16:09.579Z
Learning: Consistently including `target_os = "vxworks"` in `cfg` attributes is important to ensure full VxWorks support across the codebase.
Learnt from: biabbas
PR: iddm/thread-priority#45
File: src/unix.rs:445-445
Timestamp: 2024-10-22T03:27:30.771Z
Learning: VxWorks falls back to Unix code for most functionality, so missing `target_os = "vxworks"` in `cfg` attributes may not be an issue.
🔇 Additional comments (5)
src/lib.rs (3)

155-155: LGTM: VxWorks configuration is properly integrated

The addition of VxWorks to the Unix module configuration is consistent with its Unix-like nature and follows the existing pattern for OS-specific configurations.

Also applies to: 171-171


Line range hint 817-829: LGTM: ThreadScopeExt implementation is correct

The implementation follows Rust best practices and properly handles thread priority management within scopes.


249-249: Verify test coverage for VxWorks priority range

The implementation looks good, but we should ensure proper test coverage exists for the VxWorks-specific maximum priority value (255).

Also applies to: 255-265

src/unix.rs (2)

13-14: LGTM: VxWorks error handling implementation.

The implementation correctly uses VxWorks-specific errnoGet() and errnoSet() functions, maintaining consistency with other OS implementations.

Also applies to: 56-57, 74-75


445-454: LGTM: VxWorks priority handling implementation.

The implementation correctly includes VxWorks in the list of OSes that support priority changes for normal scheduling policies, maintaining consistency with other Unix-like systems.

@biabbas
Copy link
Contributor Author

biabbas commented Nov 5, 2024

review? @iddm

src/lib.rs Show resolved Hide resolved
@biabbas
Copy link
Contributor Author

biabbas commented Nov 7, 2024

@iddm How do we get these changes into a stable release?

@iddm iddm merged commit 4e0f070 into iddm:master Nov 7, 2024
10 checks passed
@iddm
Copy link
Owner

iddm commented Nov 7, 2024

Thank you! Available in https://crates.io/crates/thread-priority/1.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VxWorks target is not supported
2 participants