Skip to content

Fix #506, update linux sysmon to use /proc/stat - #509

Merged
jphickey merged 2 commits into
nasa:devfrom
jphickey:fix-506-procstat
Oct 8, 2026
Merged

jphickey merged 2 commits into
nasa:devfrom
jphickey:fix-506-procstat

Conversation

@jphickey

@jphickey jphickey commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

name: FSW Code Change
about: Flight Software code changes
labels: fsw

Description of Change

Use data from /proc/stat instead of /proc/schedstat. The latter was more intended for debugging the kernel and is not widely available, as it depends on kernel options to enable it.

The /proc/stat data should be universally available on Linux, but the format and units are somewhat different. This also enables us to segregate the CPU usage into user and kernel mode. The data comes for free with the idle info, so this makes it available as well.

Linked Issue

Closes #506

Requirements Impact

  • Requirement ID(s):
  • Requirements updated as necessary
  • Existing requirements are still satisfied by this change

Testing Evidence

Execute CFS w/HS on Linux host. Verify that CPU load info is being correctly published by HS.
Note that without /proc/schedstat, the previous impl would fail to initialize.

Areas of Expertise Touched

  • ASTRO
  • CI/CD
  • COSMOS
  • Cybersecurity
  • Docker
  • EDS
  • Git
  • PSPs
  • SBN
  • SMP
  • Tables
  • TSN
  • Unit Tests
  • Other

Author Checklist

  • Linked GitHub issue is referenced above
  • Code has been formatted with .clang-format
  • Static analysis workflows ran and passed
  • Unit tests (UT Assert) updated/added to cover code changes
  • Unit test workflows ran and passed
  • COSMOS test suite was run; tests updated/added if relevant changes were made
  • Requirements have been reviewed; updated or confirmed still satisfied (see above)
  • Testing evidence is included above
  • Self-review of the diff completed

Reviewer Checklist

  • Code logic is correct and matches the stated intent
  • Code is readable, maintainable, and follows project conventions (ask your lead if you are unsure of where to find these conventions)
  • .clang-format has been applied
  • Static analysis results reviewed and acceptable
  • The change has been exercised by the unit tests (not just that tests pass — the new/changed code paths are actually covered)
  • COSMOS test suite was executed against this change and results reviewed (or confirmed N/A with justification)
  • Reviewer has independently verified the change behaves as described (e.g., by running the tests locally, reviewing CI output in detail, or performing additional ad-hoc testing as warranted)
  • Memory safety reviewed (allocation, bounds, lifetime, stack usage)
  • Requirements impact reviewed and appropriate
  • Error handling is appropriate
  • Appropriate Expert areas have been reviewed

Reviewer Testing Notes

@jphickey

Copy link
Copy Markdown
Contributor Author

NOTE: the other warnings in the generic-vxworks-rtp module are fixed in #510. Those warnings can be ignored here. This fixes the other 2 warnings that were in linux-sysmon.

Use data from /proc/stat instead of /proc/schedstat.  The latter was
more intended for debugging the kernel and is not widely available, as
it depends on kernel options to enable it.

The /proc/stat data should be universally available on Linux, but the
format and units are somewhat different.  This also enables us to
segregate the CPU usage into user and kernel mode.  The data comes for
free with the idle info, so this makes it available as well.
@jphickey

Copy link
Copy Markdown
Contributor Author

Rebased since the other static analysis warning was fixed. This should get a clean run.

@chillfig
chillfig self-requested a review October 5, 2026 13:59
chillfig
chillfig previously approved these changes Oct 6, 2026

@chillfig chillfig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Found a potential overbounds read if we have a large number of CPUs. Risk is low assuming number of CPUs are nominal.

Comment thread fsw/modules/linux_sysmon/linux_sysmon.c
Comment thread fsw/modules/linux_sysmon/linux_sysmon.c Outdated
chillfig
chillfig previously approved these changes Oct 8, 2026

@chillfig chillfig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could maybe use a clang-format (https://github.com/nasa/PSP/actions/runs/37805865884/job/113409851932?pr=509) but otherwise looks good to me!

Update the loop limit to take LINUX_SYSMON_MAX_CPUS into account as well
@jphickey
jphickey merged commit 73f01c6 into nasa:dev Oct 8, 2026
6 checks passed
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.

Change Linux Sysmon to use "/proc/stat" instead of "/proc/schedstat"

3 participants