Skip to content

Add cbatch/crun/calloc add --exclusive #256

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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Conversation

1daidai1
Copy link
Collaborator

@1daidai1 1daidai1 commented Mar 24, 2025

Summary by CodeRabbit

  • New Features

    • Introduced an “--exclusive” option in command interfaces, allowing users to request exclusive node resource allocation.
    • Enhanced job and task reporting to clearly separate requested and allocated resources, showing detailed CPU, memory metrics, and exclusivity status.
    • Added new output format specifiers for requested CPUs, requested and allocated memory per node, and exclusivity status.
  • Refactor

    • Renamed resource-related fields for clearer distinction between requested and allocated resources.
    • Unified memory formatting and device map string generation for consistent display across components.

@1daidai1 1daidai1 force-pushed the dev/exclusivenew branch 7 times, most recently from 793126e to 7ccde9d Compare March 25, 2025 08:34
@1daidai1
Copy link
Collaborator Author

后端PKUHPC/CraneSched#458

@L-Xiafeng L-Xiafeng requested a review from Copilot March 29, 2025 04:42
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for an "--exclusive" flag across multiple components (cbatch, crun, calloc, etc.) to indicate exclusive node resource usage. The changes update proto messages, command-line argument parsing, and output formatting to include the new exclusive field.

  • Revised proto definitions and message fields to propagate exclusive attributes.
  • Updated command-line parsers and flag definitions for cbatch, crun, calloc, and related commands.
  • Adjusted output formatting in components such as cqueue, ceff, ccontrol, and cacct to display the exclusive status.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
protos/PublicDefs.proto Added new proto messages and renamed fields; introduced "exclusive".
internal/util/string.go Updated field reference from Resources to ReqResources.
internal/crun/crun.go Switched resource field references from Resources to ReqResources.
internal/crun/CmdArgParser.go Added --exclusive flag support in crun command parser.
internal/cqueue/cqueue.go Updated output processors and format specifiers to include exclusive.
internal/cqueue/CmdArgParser.go Updated help text to include --exclusive flag.
internal/ceff/ceff.go Adjusted calculations to use new aggregated resource fields.
internal/ccontrol/ccontrol.go Changed memory formatting function calls to util.FormatMemToMB.
internal/cbatch/cbatch.go Updated to use ReqResources and added exclusive flag processing.
internal/cbatch/CmdArgParser.go Added --exclusive flag support in cbatch command parser.
internal/calloc/calloc.go Updated resource references from Resources to ReqResources and added exclusive.
internal/calloc/CmdArgParser.go Included --exclusive flag support in calloc command parser.
internal/cacct/cacct.go Adjusted table output and field processors to include exclusive status.
internal/cacct/CmdArgParser.go Updated help text for new exclusive flag in cacct command parser.
Comments suppressed due to low confidence (1)

protos/PublicDefs.proto:299

  • [nitpick] Consider adding spaces around the '=' operator for consistency (e.g., 'string alloc_device_total = 42;').
  string alloc_device_total= 42;

Copy link

coderabbitai bot commented Mar 31, 2025

"""

Walkthrough

The changes update resource formatting and processing across multiple components to distinguish requested and allocated resources more clearly. New format specifiers and processing functions are introduced for CPU, memory, and exclusivity attributes. Command-line interfaces in several modules gain a new boolean --exclusive flag to specify exclusive node resource allocation. The resource field in task-related structures and protocol buffers is renamed from Resources to ReqResources, and a new Exclusive boolean field is added. Memory formatting is centralized via a new utility function. Error handling is enhanced to prevent division by zero in resource calculations.

Changes

File(s) Change Summary
internal/cacct/CmdArgParser.go
internal/cacct/cacct.go
Added new format specifiers (%C/%ReqCpus, %M/%ReqMemPerNode, %m/%AllocMemPerNode, %X/%Exclusive) and updated existing ones; introduced processing functions (ProcessReqCPUs, ProcessReqMemPerNode, ProcessAllocMemPerNode, ProcessExclusive); updated field mappings and format validation accordingly.
internal/calloc/CmdArgParser.go
internal/calloc/calloc.go
Added boolean flag FlagExclusive to CLI; renamed Resources to ReqResources in task struct; set task.Exclusive based on flag; updated resource field accesses accordingly.
internal/cbatch/CmdArgParser.go
internal/cbatch/cbatch.go
Introduced FlagExclusive CLI flag; renamed Resources to ReqResources in task processing; added task.Exclusive field and parsing logic for exclusivity flag.
internal/cqueue/CmdArgParser.go
internal/cqueue/cqueue.go
Expanded output format specifiers to include requested and allocated resource fields and exclusivity; renamed and added processing functions (ProcessReqCpuPerNode, ProcessReqMemPerNode, ProcessAllocMemPerNode, ProcessExclusive); updated field mappings and format validation.
internal/crun/CmdArgParser.go
internal/crun/crun.go
Added FlagExclusive CLI flag; renamed Resources to ReqResources in task struct; conditionally set task.Exclusive based on flag; updated resource field accesses.
internal/ccontrol/ccontrol.go Removed local formatMemToMB function; replaced calls with util.FormatMemToMB; removed unused variables; enhanced job resource output to include requested and allocated resources and exclusivity flag.
internal/ceff/ceff.go Added validation to prevent division by zero when NodeNum is zero; updated CPU and memory total calculations to use requested and allocated resource views consistently.
internal/util/string.go Modified CheckTaskArgs to check CPU core limit against ReqResources; added new utility function FormatMemToMB for memory size conversion.
protos/PublicDefs.proto Renamed resources to req_resources and res_view to req_res_view; added boolean exclusive fields to TaskToCtld and TaskInfo; added allocated_res_view field to TaskInfo.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLIParser
    participant TaskConfigurator
    participant Scheduler
    User->>CLIParser: Submit job with --exclusive flag
    CLIParser->>TaskConfigurator: Parse CLI flags (FlagExclusive)
    TaskConfigurator->>TaskConfigurator: Rename Resources to ReqResources
    TaskConfigurator->>TaskConfigurator: Set task.Exclusive = true (if FlagExclusive)
    TaskConfigurator->>Scheduler: Submit task with updated resource fields
    Scheduler-->>User: Acknowledge job with exclusive configuration
Loading

Suggested labels

enhancement

Suggested reviewers

  • RileyWen

Poem

A nimble rabbit hops with glee,
A flag for exclusivity now we see.
Resources renamed, details clear and bright,
CLI and tasks dance through code all night.
With bytes to MB and commands so true,
I cheer for each change—hip-hip, woo-hoo! 🐇✨
"""

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between e4d7efd and be15514.

📒 Files selected for processing (14)
  • internal/cacct/CmdArgParser.go (1 hunks)
  • internal/cacct/cacct.go (10 hunks)
  • internal/calloc/CmdArgParser.go (2 hunks)
  • internal/calloc/calloc.go (5 hunks)
  • internal/cbatch/CmdArgParser.go (2 hunks)
  • internal/cbatch/cbatch.go (9 hunks)
  • internal/ccontrol/ccontrol.go (4 hunks)
  • internal/ceff/ceff.go (5 hunks)
  • internal/cqueue/CmdArgParser.go (1 hunks)
  • internal/cqueue/cqueue.go (11 hunks)
  • internal/crun/CmdArgParser.go (2 hunks)
  • internal/crun/crun.go (4 hunks)
  • internal/util/string.go (2 hunks)
  • protos/PublicDefs.proto (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • internal/cacct/CmdArgParser.go
🚧 Files skipped from review as they are similar to previous changes (12)
  • internal/calloc/CmdArgParser.go
  • internal/cbatch/CmdArgParser.go
  • internal/calloc/calloc.go
  • protos/PublicDefs.proto
  • internal/crun/CmdArgParser.go
  • internal/crun/crun.go
  • internal/util/string.go
  • internal/cqueue/CmdArgParser.go
  • internal/cbatch/cbatch.go
  • internal/ceff/ceff.go
  • internal/cacct/cacct.go
  • internal/cqueue/cqueue.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
internal/ccontrol/ccontrol.go (1)
internal/util/string.go (2)
  • FormatMemToMB (950-957)
  • HostNameListToStr (520-532)
🔇 Additional comments (6)
internal/ccontrol/ccontrol.go (6)

178-180: Great job centralizing memory formatting!

Replacing direct memory formatting with util.FormatMemToMB improves code maintainability and ensures consistent memory formatting across the codebase.


233-240: Good refactoring of memory formatting in partition display

Using the centralized utility function here ensures consistent formatting throughout the application. This is a solid improvement to code maintainability.


298-298: Good use of the FormatMemToMB utility function

This change maintains consistency with the other formatting changes in the file.


417-428: Well-structured resource display formatting

The job output format now clearly presents requested resources with node count, CPU, memory, and device maps. The per-node and total (multiplied by node count) presentation of CPU and memory resources provides better visibility into job resource requirements.


430-437: Good addition of allocated resources display for running jobs

Showing allocated resources only for running jobs improves the output clarity, as this information is only relevant for jobs that are actively using resources. This distinction between requested and allocated resources aligns well with the PR objectives.


439-443: Clear display of node lists and exclusive flag

The addition of the exclusive flag display is consistent with the PR changes that add this capability to command modules. The formatting is clean and follows the existing style patterns.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Copy link

@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

🧹 Nitpick comments (3)
internal/cacct/cacct.go (1)

324-327: Consider reducing code duplication across files.

The functions ProcessReqCPUs, ProcessReqMemPerNode, ProcessAllocMemPerNode, and ProcessExclusive have very similar implementations in both this file and cqueue.go. Consider moving these to a common utility package to avoid duplication and ensure consistency.

Also applies to: 408-411, 413-419, 500-503

internal/cqueue/cqueue.go (2)

181-184: Data processing functions updated for resource values.

The implementation correctly uses the new processing functions for resource data, but note that line 192 directly uses strconv.FormatBool(taskInfo.Exclusive) instead of calling ProcessExclusive(taskInfo) which is inconsistent with how other fields are processed.

Consider using the dedicated processing function for consistency:

-strconv.FormatBool(taskInfo.Exclusive),
+ProcessExclusive(taskInfo),

Also applies to: 192-192


385-388: Consider reducing code duplication across files.

The functions ProcessReqCPUs, ProcessReqMemPerNode, ProcessAllocMemPerNode, and ProcessExclusive have very similar implementations in both this file and cacct.go. Consider moving these to a common utility package to avoid duplication and ensure consistency.

Also applies to: 357-360, 350-355, 442-445

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 600c784 and 60d83c7.

📒 Files selected for processing (14)
  • internal/cacct/CmdArgParser.go (1 hunks)
  • internal/cacct/cacct.go (10 hunks)
  • internal/calloc/CmdArgParser.go (2 hunks)
  • internal/calloc/calloc.go (5 hunks)
  • internal/cbatch/CmdArgParser.go (2 hunks)
  • internal/cbatch/cbatch.go (8 hunks)
  • internal/ccontrol/ccontrol.go (4 hunks)
  • internal/ceff/ceff.go (5 hunks)
  • internal/cqueue/CmdArgParser.go (1 hunks)
  • internal/cqueue/cqueue.go (11 hunks)
  • internal/crun/CmdArgParser.go (2 hunks)
  • internal/crun/crun.go (4 hunks)
  • internal/util/string.go (2 hunks)
  • protos/PublicDefs.proto (5 hunks)
🧰 Additional context used
🧬 Code Definitions (5)
internal/cbatch/CmdArgParser.go (9)
internal/calloc/CmdArgParser.go (1)
  • RootCmd (54-67)
internal/crun/CmdArgParser.go (1)
  • RootCmd (58-70)
internal/cqueue/CmdArgParser.go (1)
  • RootCmd (47-72)
internal/cacctmgr/CmdArgParser.go (1)
  • RootCmd (69-82)
internal/cinfo/CmdArgParser.go (1)
  • RootCmd (42-62)
internal/cacct/CmdArgParser.go (1)
  • RootCmd (47-70)
internal/ccontrol/CmdArgParser.go (1)
  • RootCmd (46-57)
internal/ccancel/CmdArgParser.go (1)
  • RootCmd (41-84)
internal/cplugind/cplugind.go (1)
  • RootCmd (36-123)
internal/crun/CmdArgParser.go (9)
internal/calloc/CmdArgParser.go (1)
  • RootCmd (54-67)
internal/cbatch/CmdArgParser.go (1)
  • RootCmd (63-125)
internal/cqueue/CmdArgParser.go (1)
  • RootCmd (47-72)
internal/cacct/CmdArgParser.go (1)
  • RootCmd (47-70)
internal/cinfo/CmdArgParser.go (1)
  • RootCmd (42-62)
internal/cacctmgr/CmdArgParser.go (1)
  • RootCmd (69-82)
internal/ccontrol/CmdArgParser.go (1)
  • RootCmd (46-57)
internal/ccancel/CmdArgParser.go (1)
  • RootCmd (41-84)
internal/cplugind/cplugind.go (1)
  • RootCmd (36-123)
internal/cbatch/cbatch.go (4)
internal/util/string.go (1)
  • ParseGres (642-687)
internal/cbatch/CmdArgParser.go (2)
  • FlagGres (46-46)
  • FlagExclusive (51-51)
internal/calloc/CmdArgParser.go (2)
  • FlagGres (39-39)
  • FlagExclusive (44-44)
internal/crun/CmdArgParser.go (2)
  • FlagGres (43-43)
  • FlagExclusive (45-45)
internal/cqueue/cqueue.go (1)
internal/cacct/cacct.go (4)
  • ProcessReqCPUs (325-327)
  • ProcessReqMemPerNode (409-411)
  • ProcessAllocMemPerNode (414-419)
  • ProcessExclusive (501-503)
internal/cacct/cacct.go (1)
internal/cqueue/cqueue.go (4)
  • ProcessReqCPUs (386-388)
  • ProcessReqMemPerNode (358-360)
  • ProcessAllocMemPerNode (350-355)
  • ProcessExclusive (443-445)
🔇 Additional comments (47)
internal/crun/CmdArgParser.go (2)

45-45: Clean flag declaration added.

The FlagExclusive boolean flag is properly declared alongside other configuration flags, following the naming convention established in the file.


111-111: Flag properly initialized with cobra.

The FlagExclusive flag is correctly initialized with the Cobra library, including an appropriate default value (false) and a clear description ("Exclusive node resources").

internal/cbatch/CmdArgParser.go (2)

51-51: Flag declaration consistent with other commands.

The FlagExclusive boolean flag is properly declared, maintaining consistency with its implementation in the crun command.


162-162: Flag properly initialized with consistent parameters.

The FlagExclusive flag is correctly initialized with the same parameters as in the crun command, ensuring a uniform interface across different commands in the CraneSched-FrontEnd project.

internal/calloc/calloc.go (3)

373-379: Field renamed from Resources to ReqResources.

The task structure initialization now uses ReqResources instead of Resources, which more precisely indicates that these are requested resources rather than allocated ones. This renaming appears to be part of a larger refactoring across the codebase.


402-402: References to Resources consistently updated to ReqResources.

All references to the former Resources field have been systematically updated to use ReqResources, maintaining consistency throughout the file:

  • Device map assignment (line 402)
  • Memory limit settings (lines 418-419)
  • CPU core limit calculation (line 472)

Also applies to: 418-419, 472-472


461-463: Exclusive flag implementation properly integrated.

The implementation correctly sets the task.Exclusive field to true when the FlagExclusive flag is enabled. This placement is logical, coming after other flag processing and before the extra attributes are marshaled.

internal/crun/crun.go (3)

804-810: Field renamed consistently with other files.

The task structure initialization uses ReqResources instead of Resources, maintaining consistency with the same renaming in calloc.go and other files in the codebase.


847-849: References to Resources consistently updated throughout the file.

All references to the former Resources field have been systematically updated to use ReqResources:

  • Memory limit settings (lines 847-848)
  • Device map assignment (line 852)
  • CPU core limit calculation (line 905)

Also applies to: 852-852, 905-905


894-896: Exclusive flag handling consistent with other commands.

The implementation for setting the task.Exclusive field matches the approach used in calloc.go, ensuring uniform behavior across different commands when the --exclusive flag is used.

internal/calloc/CmdArgParser.go (2)

44-44: New flag added for exclusive resource allocation.

The FlagExclusive boolean variable has been added to support exclusive node resource allocation. This aligns with similar changes in other command-line utilities (cbatch, crun) in the codebase.


100-100: Flag registration for exclusive resource allocation.

The --exclusive flag is properly registered with a descriptive help message and a default value of false. This implementation enables users to request exclusive node resources when needed.

internal/util/string.go (1)

305-307: Field access updated to use ReqResources instead of Resources.

The code has been updated to access CPU core limits from task.ReqResources instead of task.Resources. This change is part of a broader refactoring across the codebase where the field has been renamed from Resources to ReqResources.

internal/ceff/ceff.go (4)

336-339: Added validation for node count and updated CPU calculation.

The code now checks if taskInfo.NodeNum is 0 before performing calculations that depend on it, which prevents potential division by zero errors. The CPU total calculation has also been updated to use taskInfo.AllocCpusTotal directly.


367-369: Updated memory efficiency calculation to use AllocMemTotal.

The calculation of memory allocation per node and total memory allocation now uses taskInfo.AllocMemTotal directly instead of computing it from other fields. This change maintains consistency with the CPU calculation update.


404-409: Added node count validation and updated CPU calculation in JSON output.

Similar to the changes in PrintTaskInfo, this code adds validation for taskInfo.NodeNum and updates the CPU calculation to use taskInfo.AllocCpusTotal directly in the JSON output function. This ensures consistent error handling and resource calculation between the two output methods.


440-444: Updated memory calculation in JSON output.

The memory allocation calculation in the JSON output function has been updated to use taskInfo.AllocMemTotal directly, matching the changes made in the PrintTaskInfo function. This ensures consistency between the two output methods.

internal/cbatch/cbatch.go (4)

45-51: Updated field name from Resources to ReqResources.

The field name has been changed from Resources to ReqResources to better reflect that it represents requested resources rather than allocated resources. This naming convention is clearer and more descriptive of the field's purpose.


84-84: Consistent field renaming throughout resource handling code.

All references to Resources have been updated to use ReqResources throughout the file, ensuring consistency with the field renaming. This includes device map access, memory limits, and CPU core limit calculations.

Also applies to: 105-106, 179-180, 196-198, 258-258


146-153: Added support for exclusive flag in batch script arguments.

Support for the --exclusive flag has been added to the argument processing loop, allowing users to specify exclusive node allocation in their batch scripts. The implementation correctly parses the boolean value and assigns it to task.Exclusive.


245-247: Added command-line override for exclusive flag.

This code allows the command-line --exclusive flag to override the script setting, maintaining consistency with how other flags are processed. Command-line arguments take precedence over script arguments, which is clearly documented in the code comments.

internal/ccontrol/ccontrol.go (4)

177-179: Improved code reuse by utilizing a centralized utility function.

The code now uses util.FormatMemToMB instead of a local function, which promotes better code organization and reuse across the codebase.


230-232: LGTM! Consistent use of memory formatting utility.

This change maintains consistency with the changes on lines 177-179 by using the same utility function.


345-348: Good handling of allocDeviceTotal display.

The code properly initializes allocDeviceTotal to "None" and conditionally updates it if actual data is available.


358-373: Enhanced job information display with clear requested vs. allocated resources.

The output format has been improved to clearly differentiate between requested resources (ReqRes) and allocated resources (AllocRes), making it easier for users to understand resource utilization. The addition of the exclusive flag display is also helpful.

internal/cqueue/CmdArgParser.go (1)

125-141: Well-documented new format specifiers for command-line output.

The new format specifiers clearly explain the additional information that can be displayed:

  • %M/%ReqMemPerNode - For requested memory per node
  • %m/%AllocMemPerNode - For allocated memory per node
  • %Q/%ReqCpus - For requested CPUs
  • %X/%Exclusive - For the exclusive status

These additions align with the resource request/allocation distinction being implemented throughout the codebase.

protos/PublicDefs.proto (5)

119-119: Clear field renaming for better semantics.

Renaming resources to req_resources in the TaskToCtld message clarifies that this field represents requested resources rather than allocated resources.


149-149: Added exclusive resource allocation support.

The new exclusive boolean field allows tasks to request exclusive access to resources, which is a valuable feature for workloads that require dedicated access to hardware.


176-178: Added fields to track allocated resources.

These new fields in RuntimeAttrOfTask provide a way to track the total CPU cores, memory, and devices allocated to a task, which is essential for resource monitoring and reporting.


269-269: Consistent field renaming for resource view.

Renaming res_view to req_res_view maintains consistency with the earlier change from resources to req_resources.


292-295: Complete implementation of resource tracking in TaskInfo.

These additions mirror the fields added to RuntimeAttrOfTask, ensuring that all necessary information about exclusive execution and allocated resources is available in the TaskInfo message.

internal/cacct/CmdArgParser.go (1)

119-148: Added consistent format specifiers across command-line tools.

The format specifiers added here match those added to cqueue/CmdArgParser.go, ensuring a consistent user experience across different tools in the suite. The documentation is clear and well-formatted.

internal/cacct/cacct.go (8)

164-165: Table header updated to reflect the distinction between requested and allocated resources.

The header now includes "ReqCPUs", "ReqMemPerNode", "AllocCPUs", "AllocMemPerNode", and "Exclusive", which aligns with the PR objective of adding exclusive resource allocation support.


213-217: Data processing functions updated for resource values.

The implementation now properly uses the new processing functions to format resource data, including ProcessReqCPUs, ProcessReqMemPerNode, ProcessAllocCPUs, ProcessAllocMemPerNode, and ProcessExclusive.

Also applies to: 223-223


324-327: New ProcessReqCPUs function implemented.

This function correctly calculates the total requested CPUs by multiplying the per-node CPU core limit by the number of nodes.


408-411: New ProcessReqMemPerNode function implemented.

The function properly calculates the requested memory per node in megabytes by converting from bytes.


413-419: New ProcessAllocMemPerNode function implemented with zero handling.

The function includes proper handling for the case where NodeNum is 0 to avoid division by zero errors.


500-503: Added ProcessExclusive function.

This function returns the exclusivity status as a boolean string, which is used for the new exclusive flag in the table output.


515-518: Updated field processor mappings for new resource fields.

The field processor map has been correctly updated to include mappings for the new resource processing functions.

Also applies to: 555-562, 615-618


676-678: Updated format specifier help text.

The help text now includes the new format specifiers, which is helpful for users.

internal/cqueue/cqueue.go (7)

135-136: Table header updated to reflect the distinction between requested and allocated resources.

The header now includes "ReqCPUs", "ReqMemPerNode", "AllocCPUs", "AllocMemPerNode", and "Exclusive", which aligns with the PR objective of adding exclusive resource allocation support.


301-304: Renamed ProcessCpuPerNode to ProcessReqCpuPerNode.

The function has been appropriately renamed to clarify that it processes requested (not allocated) CPU per node, and now uses ReqResView instead of ResView.


350-355: Renamed ProcessMemPerNode to ProcessAllocMemPerNode with zero handling.

The function has been renamed for clarity and includes proper handling for when NodeNum is 0 to avoid division by zero errors.


357-360: Added ProcessReqMemPerNode function.

The function properly calculates the requested memory per node in megabytes.


385-388: Added ProcessReqCPUs function.

This function correctly calculates the total requested CPUs across all nodes.


442-445: Added ProcessExclusive function.

This function returns the exclusivity status as a boolean string, matching the implementation in cacct.go.


597-599: Updated format specifier help text.

The help text now includes the new format specifiers, which is helpful for users. However, the mapping inconsistencies noted above should be addressed to ensure the help text is accurate.

Also applies to: 603-605

Copy link

@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
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 336de40 and ecae063.

📒 Files selected for processing (8)
  • internal/calloc/CmdArgParser.go (2 hunks)
  • internal/cbatch/CmdArgParser.go (2 hunks)
  • internal/cbatch/cbatch.go (8 hunks)
  • internal/cqueue/CmdArgParser.go (1 hunks)
  • internal/cqueue/cqueue.go (11 hunks)
  • internal/crun/CmdArgParser.go (2 hunks)
  • internal/util/string.go (2 hunks)
  • protos/PublicDefs.proto (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • internal/cbatch/CmdArgParser.go
  • internal/crun/CmdArgParser.go
  • internal/calloc/CmdArgParser.go
  • protos/PublicDefs.proto
  • internal/cqueue/cqueue.go
  • internal/cqueue/CmdArgParser.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
internal/cbatch/cbatch.go (4)
internal/util/string.go (1)
  • ParseGres (643-688)
internal/calloc/CmdArgParser.go (2)
  • FlagGres (39-39)
  • FlagExclusive (44-44)
internal/cbatch/CmdArgParser.go (2)
  • FlagGres (46-46)
  • FlagExclusive (51-51)
internal/crun/CmdArgParser.go (2)
  • FlagGres (43-43)
  • FlagExclusive (45-45)
🔇 Additional comments (9)
internal/util/string.go (2)

306-307: Field renamed from Resources to ReqResources.

The change modifies the CPU core limit check to validate against ReqResources instead of Resources, which aligns with the broader renaming pattern across the codebase.


883-890: New utility function for memory formatting.

This function converts memory sizes from bytes to MB for display. The function properly handles the edge case when data is 0 and correctly applies the B2MB conversion ratio.

internal/cbatch/cbatch.go (7)

46-52: Field renamed from Resources to ReqResources.

The resource initialization has been updated to use ReqResources instead of Resources, maintaining consistent naming across the codebase.


85-85: Field renamed from Resources to ReqResources.

The device map assignment now uses ReqResources for consistency.


106-107: Field renamed from Resources to ReqResources.

Memory limits are now assigned to ReqResources for consistency.


147-153: Added support for parsing the --exclusive flag from job scripts.

New option allows users to specify exclusive resource allocation in job scripts. The implementation correctly parses boolean values and handles error cases.


189-189: Field renamed from Resources to ReqResources.

Command-line gres argument processing now uses ReqResources for consistency.


206-207: Field renamed from Resources to ReqResources.

Memory limits from command-line arguments now use ReqResources for consistency.


277-277: Field renamed from Resources to ReqResources.

CPU core limit calculation now uses ReqResources for consistency.

Copy link

@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

♻️ Duplicate comments (2)
internal/cqueue/cqueue.go (2)

458-461: CPU field mapping reminder
Past reviews noted inconsistent CPU field mappings (“c” vs. “C”). This change sets "C" → ReqCpus and "c" → AllocCpus. Please confirm that the corresponding mappings in cacct.go are aligned.


504-508: 'Q' → 'ReqCpuPerNode'
Ensure the usage of 'Q' for “ReqCpuPerNode” is reflected consistently in other files (e.g., cacct.go) to avoid confusion in format specifiers.

🧹 Nitpick comments (2)
internal/cqueue/cqueue.go (2)

385-389: Minor doc mismatch for 'Q' group
The comment at line 385 merges “group” with “ProcessReqCpus” and may be missing a space. Also verify that mapping “Q” → total requested CPUs is clearly documented elsewhere for consistency.


597-599: Doc comment mapping mismatch
The doc comment here states 'c' → 'ReqCpuPerNode' and 'C' → 'AllocCpus', which contradicts the actual fieldMap (lines 458-461). Please update the reference documentation for accuracy.

Also applies to: 603-605

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ecae063 and adc5f7d.

📒 Files selected for processing (3)
  • internal/cbatch/cbatch.go (8 hunks)
  • internal/cqueue/CmdArgParser.go (1 hunks)
  • internal/cqueue/cqueue.go (11 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/cbatch/cbatch.go
  • internal/cqueue/CmdArgParser.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
internal/cqueue/cqueue.go (1)
internal/cacct/cacct.go (4)
  • ProcessReqCPUs (325-327)
  • ProcessReqMemPerNode (409-411)
  • ProcessAllocMemPerNode (414-419)
  • ProcessExclusive (501-503)
🔇 Additional comments (7)
internal/cqueue/cqueue.go (7)

135-136: Columns for resource info added
The newly introduced columns—“ReqCPUs”, “ReqMemPerNode”, “AllocCPUs”, “AllocMemPerNode”, and “Exclusive”—look correct. Ensure the naming remains consistent across the codebase (e.g., with cacct.go).


181-184: New resource processing function calls
Using ProcessReqCPUs, ProcessReqMemPerNode, ProcessAllocCpus, and ProcessAllocMemPerNode in these table columns appears correct and consistent with their definitions.


192-192: Exclusive column output
Converting the boolean taskInfo.Exclusive into a string is straightforward and likely suitable for display.


302-303: Confirm CPU-per-node logic
This function returns only task.ReqResView.AllocatableRes.CpuCoreLimit, without multiplying by task.NodeNum. If “per node” is truly the intention, then it’s correct. Otherwise, verify you aren’t missing a factor of task.NodeNum.


350-355: AllocMemPerNode calculation
Dividing the total allocated memory by the number of nodes, then converting to MB makes sense. Returning "0" if NodeNum == 0 is a safe fallback.


357-359: ReqMemPerNode calculation
This function’s logic—taking MemoryLimitBytes and converting to MB—matches the “per node” naming, assuming the limit is already per node data.


442-445: Exclusive function
Implementation is straightforward—just returns the string form of the Exclusive boolean.

@1daidai1 1daidai1 force-pushed the dev/exclusivenew branch 4 times, most recently from 9372506 to bd27a26 Compare April 9, 2025 08:28
Copy link

@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

🧹 Nitpick comments (1)
internal/cqueue/cqueue.go (1)

385-388: Incorrect comment for 'Q' group function.

The comment for the 'Q' group has "ProcessReqCpus" appended to it, which appears to be a typo or incomplete edit.

-// 'Q' groupProcessReqCpus
+// 'Q' group
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9372506 and bd27a26.

📒 Files selected for processing (4)
  • internal/cacct/CmdArgParser.go (1 hunks)
  • internal/cbatch/cbatch.go (9 hunks)
  • internal/cqueue/CmdArgParser.go (1 hunks)
  • internal/cqueue/cqueue.go (11 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/cbatch/cbatch.go
  • internal/cqueue/CmdArgParser.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
internal/cqueue/cqueue.go (1)
internal/cacct/cacct.go (4)
  • ProcessReqCPUs (325-327)
  • ProcessReqMemPerNode (409-411)
  • ProcessAllocMemPerNode (414-419)
  • ProcessExclusive (501-503)
🔇 Additional comments (11)
internal/cacct/CmdArgParser.go (2)

119-133: Improved output format documentation with new resource specifiers.

The added format specifiers clearly differentiate between requested and allocated resources, making it easier for users to understand resource utilization.

The changes properly follow the existing documentation pattern and provide sufficient explanations for each new specifier.


148-148: Added support for displaying job exclusivity.

The new %X/%Exclusive format specifier allows users to see if jobs are running in exclusive mode, which is important for resource accounting and scheduling optimization.

internal/cqueue/cqueue.go (9)

135-136: Enhanced table header with requested and allocated resource fields.

The table headers now properly distinguish between requested and allocated resources, and includes the new exclusive flag. This provides users with more comprehensive information about resource requests vs. actual allocations.


181-184: Updated table data to use new processor functions.

The implementation correctly uses the new processor functions to display requested and allocated resources.


192-192: Added support for displaying job exclusivity.

The exclusive flag is now properly included in the full output format, allowing users to see whether jobs are running in exclusive mode.


302-309: Renamed and updated CPU processing functions.

The functions are properly renamed to reflect the distinction between allocated and requested resources. The implementation of ProcessReqCpuPerNode now correctly uses ReqResView to get the requested CPU limit per node.


350-360: Added distinct memory processing functions.

The implementation now correctly handles both allocated and requested memory with separate functions. The null check in ProcessAllocMemPerNode is a good practice to prevent division by zero.


487-490: Memory format specifiers are properly mapped.

The memory format specifiers are consistently mapped with 'm' for allocated memory and 'M' for requested memory, which aligns with the documentation in CmdArgParser.go.


442-445: Added exclusive status processing and mapping.

The implementation correctly processes and maps the exclusive flag, using 'X' as the format specifier which is consistent with the documentation in CmdArgParser.go.

Also applies to: 537-538


598-601: Updated format specifier reference.

The reference list in the error message has been updated to include all the new format specifiers, which helps users understand the available options.


458-462:

❓ Verification inconclusive

Inconsistent mapping between CPU-related format specifiers.

There's an inconsistency in how CPU-related format specifiers are mapped:

  • 'C' maps to ProcessReqCPUs (total CPUs across all nodes)
  • 'Q' maps to ProcessReqCpuPerNode (CPUs per node)

This could be confusing for users, especially since the previous review noted a similar inconsistency with cacct.go.

Also applies to: 505-509


🏁 Script executed:

#!/bin/bash

# Check mapping in other files
echo "Checking CPU-related format specifiers in cacct.go:"
rg "ProcessReqCPUs|ProcessAllocCpus|ProcessReqCpuPerNode" internal/cacct/ -A 2 -B 2

echo -e "\nChecking format specifier documentation in other command parsers:"
rg "ReqCpus|AllocCpus|ReqCpuPerNode" internal/ --type go -A 1 -B 1

Length of output: 6306


Attention: Revisit CPU Format Specifier Mapping

The current implementation consistently maps the specifiers across the codebase:

  • In both internal/cqueue/cqueue.go and internal/cacct/cacct.go, the lowercase "c" (and "alloccpus") maps to "AllocCpus" via ProcessAllocCpus, while the uppercase "C" (and "reqcpus") maps to "ReqCpus" via ProcessReqCPUs—which calculates the total requested CPUs across all nodes.
  • Separately, the specifier "Q" (and "reqcpupernode") maps to "ReqCpuPerNode" via ProcessReqCpuPerNode.

While this pattern is consistent across modules, the divergence between using "C" for total requested CPUs and "Q" for per-node requested CPUs may still be nonintuitive for users. This mirrors the mapping noted earlier in cacct.go.

Points to Verify:

  • Confirm that the choice of specifiers (using "C" for total and "Q" for per-node) is an intentional design decision.
  • Consider whether renaming or adding clearer documentation for these specifiers might help avoid potential user confusion.

Copy link

@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

🧹 Nitpick comments (2)
internal/cacct/cacct.go (2)

408-420: Consider extracting memory conversion to a utility function.

The conversion from bytes to MB (dividing by 1024*1024) is duplicated in both memory-related processing functions. Consider extracting this to a utility function for better maintainability.

// In ProcessReqMemPerNode
-	return strconv.FormatUint(task.ReqResView.AllocatableRes.MemoryLimitBytes/(1024*1024), 10)
+	return strconv.FormatUint(util.BytesToMB(task.ReqResView.AllocatableRes.MemoryLimitBytes), 10)

// In ProcessAllocMemPerNode
-   return strconv.FormatUint(
-	task.AllocatedResView.AllocatableRes.MemoryLimitBytes /uint64(task.NodeNum) /(1024*1024), 10)
+   return strconv.FormatUint(
+	util.BytesToMB(task.AllocatedResView.AllocatableRes.MemoryLimitBytes /uint64(task.NodeNum)), 10)

This would require adding a utility function like:

// In util package
func BytesToMB(bytes uint64) uint64 {
    return bytes / (1024 * 1024)
}

324-332: Add nil checks to prevent potential panics.

The processing functions don't check if task.ReqResView or task.AllocatedResView is nil before accessing their fields. This could lead to panics if these fields are not set.

// In ProcessReqCPUs
 func ProcessReqCPUs(task *protos.TaskInfo) string {
+	if task.ReqResView == nil || task.ReqResView.AllocatableRes == nil {
+		return "0.00"
+	}
 	return strconv.FormatFloat(task.ReqResView.AllocatableRes.CpuCoreLimit*float64(task.NodeNum), 'f', 2, 64)
 }

// Similar changes for other processing functions

Also applies to: 408-420

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd27a26 and e7605a3.

📒 Files selected for processing (5)
  • internal/cacct/cacct.go (10 hunks)
  • internal/ccontrol/ccontrol.go (4 hunks)
  • internal/ceff/ceff.go (5 hunks)
  • internal/cqueue/cqueue.go (11 hunks)
  • protos/PublicDefs.proto (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • protos/PublicDefs.proto
  • internal/ccontrol/ccontrol.go
  • internal/ceff/ceff.go
  • internal/cqueue/cqueue.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
internal/cacct/cacct.go (1)
internal/cqueue/cqueue.go (4)
  • ProcessReqCPUs (387-389)
  • ProcessReqMemPerNode (359-361)
  • ProcessAllocMemPerNode (350-356)
  • ProcessExclusive (444-446)
🔇 Additional comments (13)
internal/cacct/cacct.go (13)

164-165: Added comprehensive resource fields to output header.

Nice enhancement to the job output header to now include both requested and allocated resource metrics, as well as the exclusive flag. This change provides users with a clearer understanding of both what was requested and what was actually allocated.


213-216: Updated table data output to use new resource metrics.

The implementation correctly updates the table output to include both requested and allocated resources, along with the exclusive flag.

Also applies to: 223-223


246-246: Updated CPU allocation display to use AllocatedResView.

Correct implementation to use the new AllocatedResView structure instead of the previous Resources field.


324-327: Added ProcessReqCPUs function to display requested CPU cores.

The function correctly calculates total requested CPU cores by multiplying per-node CPU limit by the number of nodes.


331-331: Updated ProcessAllocCPUs to use AllocatedResView.

This change appropriately updates the function to use the new resource view structure.


408-411: Added ProcessReqMemPerNode function.

The implementation correctly returns the requested memory per node in MB.


413-420: Added ProcessAllocMemPerNode with zero division protection.

Good implementation with proper error handling to prevent division by zero when node count is zero.


501-504: Added ProcessExclusive function.

The function correctly returns the exclusivity flag value.


516-518: Added ReqCpus field processor entries.

Correctly maps both the short form C and long form reqcpus to the ProcessReqCPUs function.


557-558: Added ReqMemPerNode field processor entries.

Correctly maps both the short form M and long form reqmempernode to the ProcessReqMemPerNode function.


561-562: Updated AllocMemPerNode field processor entries.

The mapping is correctly updated to use the new ProcessAllocMemPerNode function.


617-618: Added Exclusive field processor entries.

Correctly maps both the short form X and long form exclusive to the ProcessExclusive function.


677-679: Updated format specifier documentation.

The error message has been updated to include all the new format specifiers, making it easier for users to understand the available options.

Copy link

@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

♻️ Duplicate comments (1)
internal/cqueue/cqueue.go (1)

508-509: Inconsistent field mapping for CPU fields still present.

The field mapping for "Q" to ProcessReqCpuPerNode remains inconsistent with the mapping in cacct.go. In a previous review comment, it was suggested to use "C" for requested CPU fields to match across files.

#!/bin/bash
# Search for CPU-related field mappings in cacct.go to verify consistency
rg -A 2 "reqcpupernode|ReqCpuPerNode" internal/cacct
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64a7261 and 4c5dc70.

📒 Files selected for processing (14)
  • internal/cacct/CmdArgParser.go (1 hunks)
  • internal/cacct/cacct.go (10 hunks)
  • internal/calloc/CmdArgParser.go (2 hunks)
  • internal/calloc/calloc.go (5 hunks)
  • internal/cbatch/CmdArgParser.go (2 hunks)
  • internal/cbatch/cbatch.go (9 hunks)
  • internal/ccontrol/ccontrol.go (4 hunks)
  • internal/ceff/ceff.go (5 hunks)
  • internal/cqueue/CmdArgParser.go (1 hunks)
  • internal/cqueue/cqueue.go (11 hunks)
  • internal/crun/CmdArgParser.go (2 hunks)
  • internal/crun/crun.go (4 hunks)
  • internal/util/string.go (3 hunks)
  • protos/PublicDefs.proto (5 hunks)
✅ Files skipped from review due to trivial changes (3)
  • internal/cbatch/CmdArgParser.go
  • internal/cacct/CmdArgParser.go
  • internal/cqueue/CmdArgParser.go
🚧 Files skipped from review as they are similar to previous changes (10)
  • internal/calloc/CmdArgParser.go
  • internal/crun/CmdArgParser.go
  • internal/crun/crun.go
  • internal/calloc/calloc.go
  • internal/ccontrol/ccontrol.go
  • protos/PublicDefs.proto
  • internal/cbatch/cbatch.go
  • internal/util/string.go
  • internal/cacct/cacct.go
  • internal/ceff/ceff.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
internal/cqueue/cqueue.go (1)
internal/cacct/cacct.go (4)
  • ProcessReqCPUs (325-327)
  • ProcessReqMemPerNode (409-411)
  • ProcessAllocMemPerNode (414-420)
  • ProcessExclusive (502-504)
🔇 Additional comments (8)
internal/cqueue/cqueue.go (8)

135-136: New columns added to full output.

The addition of "ReqCPUs", "ReqMemPerNode", and "Exclusive" columns to the full output properly implements the requested feature for distinguishing between requested and allocated resources and adding support for exclusive node allocation.


302-304: LGTM: Process allocated CPUs per node.

The refactored function correctly processes allocated CPUs.


358-360: LGTM: ProcessReqMemPerNode implementation.

The function correctly returns the requested memory per node in MB.


386-389: LGTM: ProcessReqCPUs now correctly calculates total requested CPUs.

The function correctly multiplies per-node CPU limit by the number of nodes to get total requested CPUs.


443-446: LGTM: New ProcessExclusive function.

Properly formats the exclusive flag as a boolean string.


459-463: LGTM: Updated CPU field mappings.

The mapping has been updated to correctly associate lowercase 'c' with allocated CPUs and uppercase 'C' with requested CPUs, addressing a previous inconsistency between files.


538-539: LGTM: New exclusive field mapping.

Properly maps "X"/"exclusive" to the ProcessExclusive function.


599-607: LGTM: Updated format specifier help text.

The help text has been updated to include all the new field specifiers, providing clear guidance for users.

Copy link

@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

🧹 Nitpick comments (1)
internal/cqueue/cqueue.go (1)

458-463: Inconsistent naming conventions for CPU resource specifiers

There's an inconsistency in how CPU-related format specifiers are mapped. In this file, 'C' maps to total requested CPUs, while 'Q' maps to CPU per node. However, this naming might be confusing as it doesn't follow a clear pattern (e.g., capital letters for total resources and lowercase for per-node resources).

Consider adopting a more consistent naming convention, such as:

-	"C":             {"ReqCpus", ProcessReqCPUs},
-	"reqcpus":       {"ReqCpus", ProcessReqCPUs},
-	"Q":             {"ReqCpuPerNode", ProcessReqCpuPerNode},
-	"reqcpupernode": {"ReqCpuPerNode", ProcessReqCpuPerNode},
+	// Requested resources
+	"C":             {"ReqCpusTotal", ProcessReqCPUs}, 
+	"reqcpustotal":  {"ReqCpusTotal", ProcessReqCPUs},
+	"c":             {"ReqCpuPerNode", ProcessReqCpuPerNode},
+	"reqcpupernode": {"ReqCpuPerNode", ProcessReqCpuPerNode},
+	
+	// Allocated resources  
+	"A":             {"AllocCpusTotal", ProcessAllocCpus},
+	"alloccpustotal":{"AllocCpusTotal", ProcessAllocCpus},

Also applies to: 505-510

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 024c3c0 and 29f0c85.

📒 Files selected for processing (6)
  • internal/cacct/cacct.go (10 hunks)
  • internal/ccontrol/ccontrol.go (4 hunks)
  • internal/ceff/ceff.go (5 hunks)
  • internal/cqueue/cqueue.go (11 hunks)
  • internal/util/string.go (2 hunks)
  • protos/PublicDefs.proto (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • protos/PublicDefs.proto
  • internal/util/string.go
  • internal/ceff/ceff.go
🧰 Additional context used
🧠 Learnings (2)
internal/cqueue/cqueue.go (1)
Learnt from: NamelessOIer
PR: PKUHPC/CraneSched-FrontEnd#256
File: internal/cqueue/cqueue.go:350-356
Timestamp: 2025-04-24T16:05:47.127Z
Learning: In cqueue.go, the function ProcessAllocMemPerNode should use task.AllocatedResView.AllocatableRes.MemoryLimitBytes (allocated resources) rather than task.ReqResView.AllocatableRes.MemoryLimitBytes (requested resources) to correctly display allocated memory per node.
internal/cacct/cacct.go (1)
Learnt from: NamelessOIer
PR: PKUHPC/CraneSched-FrontEnd#256
File: internal/cqueue/cqueue.go:350-356
Timestamp: 2025-04-24T16:05:47.127Z
Learning: In cqueue.go, the function ProcessAllocMemPerNode should use task.AllocatedResView.AllocatableRes.MemoryLimitBytes (allocated resources) rather than task.ReqResView.AllocatableRes.MemoryLimitBytes (requested resources) to correctly display allocated memory per node.
🧬 Code Graph Analysis (2)
internal/cqueue/cqueue.go (1)
internal/cacct/cacct.go (4)
  • ProcessReqCPUs (325-327)
  • ProcessReqMemPerNode (409-411)
  • ProcessAllocMemPerNode (414-420)
  • ProcessExclusive (502-504)
internal/cacct/cacct.go (1)
internal/cqueue/cqueue.go (4)
  • ProcessReqCPUs (387-389)
  • ProcessReqMemPerNode (359-361)
  • ProcessAllocMemPerNode (350-356)
  • ProcessExclusive (444-446)
🪛 golangci-lint (1.64.8)
internal/cacct/cacct.go

246-246: undefined: task

(typecheck)

🔇 Additional comments (13)
internal/ccontrol/ccontrol.go (3)

178-180: Good improvement: Standardized memory formatting

The change to use util.FormatMemToMB instead of a local formatting function provides better consistency across the codebase for memory formatting.


417-419: Enhanced resource reporting with clear separation of requested vs allocated resources

The output now clearly distinguishes between requested resources (ReqRes) and allocated resources (AllocRes), making it easier for users to understand what they asked for versus what they actually got.


420-436: Added exclusive flag support in job display

The job display now includes the exclusive flag status, which aligns with the new --exclusive flag support added throughout the system.

internal/cacct/cacct.go (5)

164-165: Good enhancement: Expanded output header with resource distinction

The output header now clearly separates requested resources (ReqCPUs, ReqMemPerNode) from allocated resources (AllocCPUs, AllocMemPerNode) and adds the Exclusive flag, providing users with more detailed information.


213-216: Enhanced resource reporting with relevant processing functions

The implementation correctly uses the new processing functions to display requested and allocated resource information.


324-327: Good implementation: ProcessReqCPUs function

The function correctly calculates total requested CPUs as the product of CPU per node and node count.


414-420: Well-implemented allocation memory formatting with zero protection

The implementation correctly handles the edge case where node count is zero to avoid division by zero errors, and properly uses the allocated resources view.


501-504: Good implementation: ProcessExclusive function

Simple and correct implementation to display the exclusive flag as a boolean string.

internal/cqueue/cqueue.go (5)

135-136: Good enhancement: Updated output format with resource distinction

The output header has been updated to include requested and allocated resource columns along with the exclusive flag.


181-185: Enhanced resource reporting with separated resource views

The implementation correctly displays both requested and allocated resources.


302-304: Properly updated ProcessAllocCpus to use allocated resources

The function now correctly uses AllocatedResView instead of ReqResView to display actually allocated CPUs.


350-356: Correctly implemented memory per node with zero protection

The implementation handles the edge case where node count is zero to avoid division by zero errors, and properly uses allocated resources view as noted in your previous feedback.


599-602: Updated format specifier documentation

The documentation for format specifiers has been properly updated to include the new resource view specifiers and exclusive flag.

@1daidai1 1daidai1 force-pushed the dev/exclusivenew branch 4 times, most recently from f556a8a to 5cd246c Compare April 25, 2025 02:32
@1daidai1 1daidai1 force-pushed the dev/exclusivenew branch 2 times, most recently from 619c191 to 9c1b9fe Compare April 25, 2025 02:50
Copy link

@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

🧹 Nitpick comments (3)
internal/cqueue/cqueue.go (3)

596-598: Inconsistent capitalization in format specifier documentation.

There's inconsistent capitalization in the format specifier documentation:

  • Line 597: "AllocCPUs" vs "ReqCpus" (upper vs mixed case for "CPU")
  • Line 598: "ReqCpuPerNode" (mixed case)

This could be confusing to users. Consider standardizing to either all uppercase ("CPU") or all mixed case ("Cpu").

-		//a-Account, c-AllocCPUs, C-ReqCpus, e-ElapsedTime, h-Held, j-JobID, l-TimeLimit, L-NodeList, k-Comment,
-		//m-AllocMemPerNode, M-ReqMemPerNode, n-Name, N-NodeNum, p-Priority, P-Partition, q-Qos, Q-ReqCpuPerNode, r-ReqNodes,
+		//a-Account, c-AllocCpus, C-ReqCpus, e-ElapsedTime, h-Held, j-JobID, l-TimeLimit, L-NodeList, k-Comment,
+		//m-AllocMemPerNode, M-ReqMemPerNode, n-Name, N-NodeNum, p-Priority, P-Partition, q-Qos, Q-ReqCpuPerNode, r-ReqNodes,

456-457: Inconsistency between function name and field name capitalization.

The fieldMap maps "c" to {"AllocCpus", ProcessAllocCpus}, but the function is named ProcessAllocCpus (with mixed case "Cpus") while the field is named "AllocCpus" (with uppercase "C"). This inconsistency appears in several places throughout the code.

Consider standardizing the capitalization pattern across function names and field names.


601-604: Use hyphen for connecting format specifiers in error message comment.

Based on the previous review comment from NamelessOIer, the format for connecting format specifiers in the error message should use a hyphen ("-") rather than a slash ("/").

-				"a/Account, c/AllocCPUs, C/ReqCpus, e/ElapsedTime, h/Held, j/JobID, l/TimeLimit, L/NodeList, k/Comment,\n"+
-				"m/AllocMemPerNode, M/ReqMemPerNode, n/Name, N/NodeNum, p/Priority, P/Partition, q/Qos, Q/ReqCpuPerNode, r/ReqNodes,\n"+
-				"R/Reason, s/SubmitTime, S/StartTime, t/State, T/JobType, u/User, U/Uid, x/ExcludeNodes, X/Exclusive.", field)
+				"a-Account, c-AllocCpus, C-ReqCpus, e-ElapsedTime, h-Held, j-JobID, l-TimeLimit, L-NodeList, k-Comment,\n"+
+				"m-AllocMemPerNode, M-ReqMemPerNode, n-Name, N-NodeNum, p-Priority, P-Partition, q-Qos, Q-ReqCpuPerNode, r-ReqNodes,\n"+
+				"R-Reason, s-SubmitTime, S-StartTime, t-State, T-JobType, u-User, U-Uid, x-ExcludeNodes, X-Exclusive.", field)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e11df19 and 9c1b9fe.

📒 Files selected for processing (6)
  • internal/cacct/cacct.go (10 hunks)
  • internal/ccontrol/ccontrol.go (4 hunks)
  • internal/ceff/ceff.go (5 hunks)
  • internal/cqueue/cqueue.go (11 hunks)
  • internal/util/string.go (2 hunks)
  • protos/PublicDefs.proto (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • internal/ceff/ceff.go
  • protos/PublicDefs.proto
  • internal/ccontrol/ccontrol.go
  • internal/util/string.go
  • internal/cacct/cacct.go
🧰 Additional context used
🧠 Learnings (1)
internal/cqueue/cqueue.go (1)
Learnt from: NamelessOIer
PR: PKUHPC/CraneSched-FrontEnd#256
File: internal/cqueue/cqueue.go:350-356
Timestamp: 2025-04-24T16:05:47.127Z
Learning: In cqueue.go, the function ProcessAllocMemPerNode should use task.AllocatedResView.AllocatableRes.MemoryLimitBytes (allocated resources) rather than task.ReqResView.AllocatableRes.MemoryLimitBytes (requested resources) to correctly display allocated memory per node.
🔇 Additional comments (3)
internal/cqueue/cqueue.go (3)

350-353: Confirm memory calculation logic is correct.

I see that ProcessAllocMemPerNode now correctly uses AllocatedResView instead of ReqResView, which is consistent with the function's purpose. This addresses the issue identified in previous reviews.

However, unlike ProcessAllocCpus which multiplies by task.NodeNum, this function doesn't divide by task.NodeNum to get the memory per node. Please verify that this is indeed the expected behavior.


134-137: Changes look good - clear separation of requested vs allocated resources.

The header changes appropriately add columns for "ReqCPUs", "ReqMemPerNode", and "Exclusive" which aligns with the PR objectives of distinguishing requested and allocated resources more clearly and adding the exclusive flag.


440-443: Properly implemented exclusive flag handling.

The ProcessExclusive function correctly returns the string representation of the task's exclusive flag, which is consistent with the PR objective.

@1daidai1 1daidai1 closed this Apr 26, 2025
@1daidai1 1daidai1 reopened this Apr 26, 2025
@1daidai1 1daidai1 force-pushed the dev/exclusivenew branch 2 times, most recently from e13ee35 to cd6e89f Compare April 26, 2025 14:05
Copy link

@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

♻️ Duplicate comments (3)
internal/cqueue/cqueue.go (3)

459-463: Inconsistency in CPU field mappings.

There remains an inconsistency in the mapping of format specifiers between this file and cacct.go. In this file:

  • 'c' maps to ProcessAllocCpus (allocated CPUs)
  • 'C' maps to ProcessReqCPUs (total requested CPUs)
  • 'Q' maps to ProcessReqCpuPerNode (requested CPUs per node)

While in cacct.go, 'C' maps to ProcessReqCPUs and 'c' maps to ProcessAllocCPUs. This difference could confuse users when switching between commands.

Also applies to: 506-509


599-601: Missing hyphen in comment formatting.

The comments for format specifiers are missing a hyphen between character and description in some places, making the format inconsistent with the standard used elsewhere in the codebase.

-//a-Account, c-AllocCPUs, C-ReqCpus, e-ElapsedTime, h-Held, j-JobID, l-TimeLimit, L-NodeList, k-Comment,
-//m-AllocMemPerNode, M-ReqMemPerNode, n-Name, N-NodeNum, p-Priority, P-Partition, q-Qos, Q-ReqCpuPerNode, r-ReqNodes,
-//R-Reason, s-SubmitTime, S-StartTime, t-State, T-JobType, u-User, U-Uid, x-ExcludeNodes, X-Exclusive.
+//a-Account, c-AllocCPUs, C-ReqCpus, e-ElapsedTime, h-Held, j-JobID, l-TimeLimit, L-NodeList, k-Comment,
+//m-AllocMemPerNode, M-ReqMemPerNode, n-Name, N-NodeNum, p-Priority, P-Partition, q-Qos, Q-ReqCpuPerNode, r-ReqNodes,
+//R-Reason, s-SubmitTime, S-StartTime, t-State, T-JobType, u-User, U-Uid, x-ExcludeNodes, X-Exclusive.

606-607: Missing hyphen in help text.

Similar to the above comment, the help text in the error message is missing hyphens between format specifiers and their descriptions.

-				"a/Account, c/AllocCPUs, C/ReqCpus, e/ElapsedTime, h/Held, j/JobID, l/TimeLimit, L/NodeList, k/Comment,\n"+
-				"m/AllocMemPerNode, M/ReqMemPerNode, n/Name, N/NodeNum, p/Priority, P/Partition, q/Qos, Q/ReqCpuPerNode, r/ReqNodes,\n"+
-				"R/Reason, s/SubmitTime, S/StartTime, t/State, T/JobType, u/User, U/Uid, x/ExcludeNodes, X/Exclusive.", field)
+				"a-Account, c-AllocCPUs, C-ReqCpus, e-ElapsedTime, h-Held, j-JobID, l-TimeLimit, L-NodeList, k-Comment,\n"+
+				"m-AllocMemPerNode, M-ReqMemPerNode, n-Name, N-NodeNum, p-Priority, P-Partition, q-Qos, Q-ReqCpuPerNode, r-ReqNodes,\n"+
+				"R-Reason, s-SubmitTime, S-StartTime, t-State, T-JobType, u-User, U-Uid, x-ExcludeNodes, X-Exclusive.", field)
🧹 Nitpick comments (1)
internal/cqueue/cqueue.go (1)

302-309: Consider adding function comments.

The CPU processing functions lack descriptive comments explaining what they do. Adding comments would improve code readability and make it clearer that ProcessAllocCpus returns allocated CPU cores while ProcessReqCpuPerNode returns requested CPU cores per node.

// 'c' group
+// ProcessAllocCpus returns the allocated CPU cores for a task
func ProcessAllocCpus(task *protos.TaskInfo) string {
	return strconv.FormatFloat(task.AllocatedResView.AllocatableRes.CpuCoreLimit, 'f', 2, 64)
}

// 'C' group
+// ProcessReqCpuPerNode returns the requested CPU cores per node for a task
func ProcessReqCpuPerNode(task *protos.TaskInfo) string {
	return strconv.FormatFloat(task.ReqResView.AllocatableRes.CpuCoreLimit, 'f', 2, 64)
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9266d93 and cd6e89f.

📒 Files selected for processing (4)
  • internal/cacct/cacct.go (10 hunks)
  • internal/ccontrol/ccontrol.go (4 hunks)
  • internal/ceff/ceff.go (5 hunks)
  • internal/cqueue/cqueue.go (11 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • internal/ccontrol/ccontrol.go
  • internal/ceff/ceff.go
  • internal/cacct/cacct.go
🧰 Additional context used
🧠 Learnings (1)
internal/cqueue/cqueue.go (1)
Learnt from: NamelessOIer
PR: PKUHPC/CraneSched-FrontEnd#256
File: internal/cqueue/cqueue.go:350-356
Timestamp: 2025-04-24T16:05:47.127Z
Learning: In cqueue.go, the function ProcessAllocMemPerNode should use task.AllocatedResView.AllocatableRes.MemoryLimitBytes (allocated resources) rather than task.ReqResView.AllocatableRes.MemoryLimitBytes (requested resources) to correctly display allocated memory per node.
🧬 Code Graph Analysis (1)
internal/cqueue/cqueue.go (2)
internal/cacct/cacct.go (4)
  • ProcessReqCPUs (325-327)
  • ProcessReqMemPerNode (409-411)
  • ProcessAllocMemPerNode (414-420)
  • ProcessExclusive (502-504)
internal/util/string.go (1)
  • FormatMemToMB (940-947)
🔇 Additional comments (5)
internal/cqueue/cqueue.go (5)

350-356: Correct implementation of ProcessAllocMemPerNode.

Your change to use AllocatedResView.AllocatableRes.MemoryLimitBytes is correct, ensuring the function returns allocated rather than requested memory per node. This aligns with the function name and ensures accurate display of allocated resources.

I notice you're returning "0M" for the zero node case, which is good for avoiding division by zero.


358-360: Memory formatting implementation looks good.

The ProcessReqMemPerNode function correctly uses the utility function FormatMemToMB to format the requested memory per node, which ensures consistent memory formatting throughout the application.


386-389: Proper implementation of requested CPUs calculation.

The function correctly calculates total requested CPUs by multiplying the per-node CPU core limit by the number of nodes, which is essential for displaying the total CPU resources requested by a task.


443-446: Added exclusive flag processing.

The new ProcessExclusive function correctly formats the task's exclusive flag as a string, which is needed for displaying whether a task requests exclusive node access.


135-136: Correctly implemented new columns in table output.

The implementation correctly adds new columns for "ReqCPUs", "ReqMemPerNode", and "Exclusive" to distinguish between requested and allocated resources, and to display the new exclusive flag. The table data is also properly populated with the corresponding values.

Also applies to: 181-184, 192-192

@1daidai1 1daidai1 force-pushed the dev/exclusivenew branch from e4d7efd to be15514 Compare May 15, 2025 09:03
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.

2 participants