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

Ability to have more than two additional core timer interrupts #452

Open
jpswensen opened this issue Apr 23, 2019 · 16 comments
Open

Ability to have more than two additional core timer interrupts #452

jpswensen opened this issue Apr 23, 2019 · 16 comments

Comments

@jpswensen
Copy link

We have run into an issue lately where we wanted to have more than two additional core timer interrupts. Now, I realize we could munge together multiple interrupts and makes sure they execute at integer multiples of each other, but it was just as easy to go into wiring.c on line 481 and add more entries into the gCoreTimerInfo[] array.

I looked through the way that the timer interrupts are handles and it seems that there would be little to no execution overhead to adding in 3-4 more slots in gCoreTimerInfo[], and only 8 bytes or so in terms of RAM (I'm not exactly sure the size of a function pointer on this architecture/compiler).

Option 1:
So, I guess my question is whether you would be averse to a pull request that adds 3 more slots in the gCoreTimerInfo[] array, allowing a total of 5 timer interrupts based on the Core Timer?

Options 2:
The other option I was thinking about was have a #define that a user could #undef that wrapped the gCoreTimerInfo[] declaration and let a user externally define their own array. Thoughts on this one?

Options 3:
I just live with it and go modify wiring.c on ever machine we use to build this chipkit code. This is our fallback, but there is no compile time or run time information that someone is trying to attach too many timer interrupts. It just fails to do it.

@majenkotech
Copy link
Member

Option 4:

Re-factor the code to use a linked list, so the only limit is the amount of free heap space.

@JacobChrist
Copy link
Member

JacobChrist commented Apr 23, 2019 via email

@majenkotech
Copy link
Member

Processing overhead, or memory overhead? There's little-to-no processing overhead for a linked list. Instead of incrementing a value and using it as an index to a table in memory you're just assigning a pointer to a variable. If anything it's faster.

for (int i = 0; i < 4; i++) {
    (do maths here to get the address that i should relate to, then do something with it)
}

for (struct foo *f = head; f; f = f->next) {
    (do something with f->...)
}

@JacobChrist
Copy link
Member

JacobChrist commented Apr 23, 2019 via email

@JacobChrist
Copy link
Member

JacobChrist commented Apr 23, 2019 via email

@jpswensen
Copy link
Author

jpswensen commented Apr 23, 2019 via email

@JacobChrist
Copy link
Member

JacobChrist commented Apr 23, 2019 via email

@majenkotech
Copy link
Member

Memory would be just 4 bytes per entry. However heap memory is at a premium thanks to Microchip's crippled memory handling - allocating a fixed amount to the heap memory, something which I have been campaigning for years and years to have lifted.

In general malloc/new etc are frowned upon in microcontrollers, mainly because they have traditionally had only very small amounts of memory. However we generally have lots and lots, and if it weren't for the limit (just 2k in most linker scripts IIRC) then using new/malloc etc would be far more common.

@majenkotech
Copy link
Member

Garbage collection is irrelevant. That's only for systems that don't require manual free/delete. The problem with heap is fragmentation, and that is only a problem when you have a tiny limit, like on an AVR.

If you are allocating at the start of your program and never freeing, as would probably be the case with these interrupts, then there is no fragmentation.

The biggest culprit is String, and that is generally down to people not knowing how to use it properly.

@JacobChrist
Copy link
Member

JacobChrist commented Apr 23, 2019 via email

@majenkotech
Copy link
Member

What about it?

@JacobChrist
Copy link
Member

JacobChrist commented Apr 23, 2019 via email

@majenkotech
Copy link
Member

Fragmentation in this scenario will probably not exist. Or if it does it will be so minor as to not even be noticeable. After all, how often will you add and remove core timer services?

@JacobChrist
Copy link
Member

JacobChrist commented Apr 23, 2019 via email

@majenkotech
Copy link
Member

majenkotech commented Apr 23, 2019

Well, I just tried re-implementing the CT service with a linked list, and it all crashed and burned. It'll be a longer term job this one, so I guess for now either we just increase the default size of the array, or do something fancy with #defines - though not sure what off hand.

@JacobChrist
Copy link
Member

JacobChrist commented Apr 24, 2019 via email

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

No branches or pull requests

4 participants
@JacobChrist @jpswensen @majenkotech and others