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

Input_SRV: migration to event_loop #3968

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

Skorpionm
Copy link
Member

What's new

  • Input_SRV: migration to event_loop

Verification

  • Test GUI navigation using physical buttons on Flipper

Checklist (For Reviewer)

  • PR has description of feature/bug or link to Confluence/Jira task
  • Description contains actions to verify feature/bugfix
  • I've built this code, uploaded it to the device and verified feature/bugfix

Copy link

github-actions bot commented Oct 22, 2024

Compiled f7 firmware for commit a43990cb:

@Skorpionm Skorpionm marked this pull request as ready for review October 22, 2024 11:39
input_semaphore_callback,
instance);

instance->key_sequence = malloc(sizeof(InputSrvKeySequence) * input_pins_count);
Copy link
Contributor

@CookiePLMonster CookiePLMonster Oct 22, 2024

Choose a reason for hiding this comment

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

All those allocations could easily land on the stack, VLAs come in handy here (copying my remark from the previous PR).

Copy link
Member Author

Choose a reason for hiding this comment

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

no, if you put everything on the stack and turn on debugging, then the 1 KB stack allocated to the process is sometimes not enough and everything crashes with special effects

Copy link
Contributor

Choose a reason for hiding this comment

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

Those structures are tiny - so wouldn't this mean that even without them on the stack, 1KB is pushing the limit very close?

Copy link
Member Author

Choose a reason for hiding this comment

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

all structures on the stack will take about 220 bytes.

provided that there are only 6 buttons, when the number of buttons changes, the size of the structure will increase and if the structure is placed on the stack, the implementation ceases to be universal.

Copy link
Member Author

Choose a reason for hiding this comment

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

at the expense of 1kb on the stack it is enough even with debugging enabled, without it about 500 bytes are used per process

Copy link
Contributor

@CookiePLMonster CookiePLMonster Oct 22, 2024

Choose a reason for hiding this comment

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

In this case the keys could stay on the heap (although maybe put them on the service heap?) while instance goes to the stack? It does not have to be all or nothing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well then what's the point of chopping it into pieces?

Copy link
Contributor

Choose a reason for hiding this comment

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

Currently it's chopped into pieces already, and occupies 3 heap allocations - so by moving you save one allocation, which is better than nothing.

Copy link
Member

Choose a reason for hiding this comment

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

Keep in mind that services are allocated in special memory region and it's quite small. Increasing stack size may bring another set of problems

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, in this case the key arrays could stay on the user heap, but the inputsrv is so small there's no reason not to put it on the stack. Before this PR it was just a bunch of local variables.

furi_record_create(RECORD_INPUT_EVENTS, event_pubsub);
static void input_isr_key(void* context) {
InputSrv* instance = context;
furi_semaphore_release(instance->input_semaphore);
Copy link
Member

Choose a reason for hiding this comment

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

Interrupts may be missed in some edge cases

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.

4 participants