Skip to content

Support multi-threading in the Patmos Platform - #582

Open
EhsanKhodadad wants to merge 15 commits into
lf-lang:mainfrom
EhsanKhodadad:main
Open

Support multi-threading in the Patmos Platform#582
EhsanKhodadad wants to merge 15 commits into
lf-lang:mainfrom
EhsanKhodadad:main

Conversation

@EhsanKhodadad

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings April 29, 2026 12:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 aims to add multi-threaded runtime support for the Patmos platform by introducing Patmos implementations of the LF threading/synchronization abstractions when LF_SINGLE_THREADED is not defined.

Changes:

  • Added a Patmos “threaded” branch in lf_patmos_support.c with implementations for threads, mutexes, and condition variables.
  • Added Patmos platform typedefs for lf_thread_t, lf_mutex_t, and lf_cond_t under !LF_SINGLE_THREADED.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.

File Description
low_level_platform/impl/src/lf_patmos_support.c Adds Patmos-side threaded implementations (threads/mutex/cond) and related helpers under #else of LF_SINGLE_THREADED.
low_level_platform/api/platform/lf_patmos_support.h Introduces threaded Patmos typedefs and includes <pthread.h> when !LF_SINGLE_THREADED.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread low_level_platform/impl/src/lf_patmos_support.c Outdated
Comment thread low_level_platform/impl/src/lf_patmos_support.c Outdated
Comment thread low_level_platform/impl/src/lf_patmos_support.c
Comment thread low_level_platform/api/platform/lf_patmos_support.h Outdated
Comment thread low_level_platform/impl/src/lf_patmos_support.c Outdated
Comment thread low_level_platform/impl/src/lf_patmos_support.c
Comment thread low_level_platform/impl/src/lf_patmos_support.c
Comment thread low_level_platform/impl/src/lf_patmos_support.c Outdated
Comment thread low_level_platform/impl/src/lf_patmos_support.c
Co-authored-by: Copilot <copilot@github.com>

@edwardalee edwardalee left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks to me like the Copilot suggestions need to be addressed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

Comment thread low_level_platform/impl/src/lf_patmos_support.c Outdated
Comment thread low_level_platform/impl/src/lf_patmos_support.c
Comment thread low_level_platform/impl/src/lf_patmos_support.c Outdated
Comment thread low_level_platform/impl/src/lf_patmos_support.c Outdated
Comment thread low_level_platform/api/platform/lf_patmos_support.h
@edwardalee

Copy link
Copy Markdown
Contributor

As you address issues raised by Copilot, please record a brief comment on how the issue was addressed and mark the comment "Resolved".

@EhsanKhodadad
EhsanKhodadad requested a review from Copilot May 23, 2026 13:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

Comment thread low_level_platform/api/platform/lf_patmos_support.h
Comment thread low_level_platform/impl/src/lf_patmos_support.c Outdated
Comment thread low_level_platform/impl/src/lf_patmos_support.c
Comment thread low_level_platform/impl/src/lf_atomic_irq.c
Comment thread low_level_platform/api/platform/lf_patmos_support.h
Comment thread low_level_platform/impl/src/lf_patmos_support.c
@EhsanKhodadad

Copy link
Copy Markdown
Contributor Author

As you address issues raised by Copilot, please record a brief comment on how the issue was addressed and mark the comment "Resolved".

@edwardalee I addressed all Copilot's issues. I feel it is now ready for your review.

@edwardalee edwardalee added the enhancement Enhancement of existing feature label Jul 1, 2026
@edwardalee edwardalee changed the title multi-thread in the Patmos Platform Support multi-threading in the Patmos Platform Jul 1, 2026
@edwardalee
edwardalee requested a review from Copilot July 1, 2026 19:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread low_level_platform/impl/src/lf_patmos_support.c Outdated

@edwardalee edwardalee left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks OK to me, except it looks like the call to _lf_patmos_global_lock_acquire should be implemented in the Patmos-specific implementation of lf_disable_interrupts_nested rather than conditionally called in lf_atomic_irq.c‎.

Comment thread low_level_platform/impl/src/lf_atomic_irq.c Outdated
Comment thread low_level_platform/impl/src/lf_atomic_irq.c Outdated
Comment thread low_level_platform/impl/src/lf_atomic_irq.c Outdated
Comment thread low_level_platform/impl/src/lf_atomic_irq.c Outdated
Comment thread low_level_platform/impl/src/lf_atomic_irq.c Outdated
@EhsanKhodadad

EhsanKhodadad commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Looks OK to me, except it looks like the call to _lf_patmos_global_lock_acquire should be implemented in the Patmos-specific implementation of lf_disable_interrupts_nested rather than conditionally called in lf_atomic_irq.c‎.

Thank you for your review, @edwardalee, and sorry for my delayed answer.

I added _lf_patmos_global_lock_release function here because, as discussed in #582 (comment), lf_disable_interrupts_nested() only disables interrupts on the current core and does not provide mutual exclusion across cores.

Can we implement these functions in a separate file, named lf_atomic_patmos.c?

@edwardalee

Copy link
Copy Markdown
Contributor

Looks OK to me, except it looks like the call to _lf_patmos_global_lock_acquire should be implemented in the Patmos-specific implementation of lf_disable_interrupts_nested rather than conditionally called in lf_atomic_irq.c‎.

Thank you for your review, @edwardalee, and sorry for my delayed answer.

I added _lf_patmos_global_lock_release function here because, as discussed in #582 (comment), lf_disable_interrupts_nested() only disables interrupts on the current core and does not provide mutual exclusion across cores.

Can we implement these functions in a separate file, named lf_atomic_patmos.c?

Is lf_disable_interrupts_nested used anywhere else? If not, then with careful documentation, I think my suggestion could still make sense and it would avoid putting Patmos-specific code in the platform-independent file. Alternatively, maybe there is a better name for the function lf_disable_interrupts_nested that abstracts the functionality?

@EhsanKhodadad

Copy link
Copy Markdown
Contributor Author

Looks OK to me, except it looks like the call to _lf_patmos_global_lock_acquire should be implemented in the Patmos-specific implementation of lf_disable_interrupts_nested rather than conditionally called in lf_atomic_irq.c‎.

Thank you for your review, @edwardalee, and sorry for my delayed answer.
I added _lf_patmos_global_lock_release function here because, as discussed in #582 (comment), lf_disable_interrupts_nested() only disables interrupts on the current core and does not provide mutual exclusion across cores.
Can we implement these functions in a separate file, named lf_atomic_patmos.c?

Is lf_disable_interrupts_nested used anywhere else? If not, then with careful documentation, I think my suggestion could still make sense and it would avoid putting Patmos-specific code in the platform-independent file. Alternatively, maybe there is a better name for the function lf_disable_interrupts_nested that abstracts the functionality?

Thank you for your feedback, @edwardalee , I edited my PR in 6dc4221, so we have no changes in lf_atomic_irq.c in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement of existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants