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

fix Flowvar allocation #33

Merged
merged 4 commits into from
Jul 25, 2023
Merged

fix Flowvar allocation #33

merged 4 commits into from
Jul 25, 2023

Conversation

arnetheduck
Copy link
Member

  • flowvar was allocating the wrong size for the spsc channel
  • refactor channel to use an ordinary type for its buffer simplifying construction / allocation, remove 256-byte limitation
  • fix under-aligned allocation in channel test

* flowvar was allocating the wrong size for the spsc channel
* refactor channel to use an ordinary type for its buffer simplifying
construction / allocation, remove 256-byte limitation
* fix under-aligned allocation in channel test

createThread(threads[0], thread_func, ThreadArgs(ID: Receiver, chan: chan))
createThread(threads[1], thread_func, ThreadArgs(ID: Sender, chan: chan))

joinThread(threads[0])
joinThread(threads[1])

c_free(chan)
tp_freeAligned(chan)
Copy link

Choose a reason for hiding this comment

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

Example code tends to be copy/pasted, so it's better to use defer to schedule the calling of this function right after it's being allocated.

Copy link
Member Author

Choose a reason for hiding this comment

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

making this example safe would require some more significant refactoring, so I think it's beyond the scope of this PR (ie handling thread creation failure etc - there's just too much to fix)

chan[].initialize(itemSize = sizeof(int))
var chan = tp_allocAligned(
ChannelSPSCSingle[int], sizeof(ChannelSPSCSingle[int]), 64)
zeroMem(chan, sizeof(ChannelSPSCSingle[int]))
Copy link

Choose a reason for hiding this comment

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

This patterns seems to be repeated in few places. It would be nice to introduce a simpler helper called tp_alloc0Aligned?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about that too but it would significantly grow the scope of this PR since all of the library should ideally be updated

Copy link
Member Author

Choose a reason for hiding this comment

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

also, in some cases the library opts to not zero the full range of allocated bytes, so a "0" helper could not universally be applied, again pointing in the direction of a full review rather than a drive-by fix in this PR

arnetheduck added a commit to status-im/nim-blscurve that referenced this pull request Jul 7, 2023
The current version of `batchVerifyParallel` calls `syncAll` which syncs
on all executing tasks.

This PR changes this to syncing a Flowvar instead thus allowing
`batchVerifyParallel` to be called as a task itself.

Requires status-im/nim-taskpools#33
@zah zah merged commit ffba691 into stable Jul 25, 2023
@zah zah deleted the fix-channel branch July 25, 2023 15:58
zah added a commit to status-im/nim-blscurve that referenced this pull request Jul 25, 2023
* avoid blocking batchVerifyParallel

The current version of `batchVerifyParallel` calls `syncAll` which syncs
on all executing tasks.

This PR changes this to syncing a Flowvar instead thus allowing
`batchVerifyParallel` to be called as a task itself.

Requires status-im/nim-taskpools#33

* autoselect too

---------

Co-authored-by: zah <zahary@gmail.com>
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