Skip to content

Conversation

skeees
Copy link
Contributor

@skeees skeees commented May 16, 2018

As discussed in #13023 I've split this test out into a separate pr

This test (and documentation update) makes explicit the guarantee (previously undefined, but implied by the 'SingleThreaded' in SingleThreadedSchedulerClient()) - that callbacks pushed to the SingleThreadedSchedulerClient() obey the single threaded model for memory and execution - specifically, the callbacks are executed fully and in order, and even in cases where a subsequent callback is executed by a different thread, sequential consistency of memory for all threads executing these callbacks is maintained.

Maintaining memory consistency should make the api more developer friendly - especially for users of the validationinterface. To the extent that there are performance implications from this decision, these are not currently present in practice because all use of this scheduler happens on a single thread currently, furthermore the lock should guarantee consistency across callback executions even when callbacks are executed by multiple threads (as the test does).

@TheBlueMatt
Copy link
Contributor

Can you also note the memory model in validationinterface, since that's the "real" API here.

@skeees
Copy link
Contributor Author

skeees commented May 16, 2018

Updated

// the extra threads should effectively be doing nothing
// if they don't we'll get out of order behaviour
boost::thread_group threads;
for (int i = 0; i < 5; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: ++i is preferred according to the developer-notes.

threads.join_all();

BOOST_CHECK_EQUAL(counter1, 100);
BOOST_CHECK_EQUAL(counter2, 100);
Copy link
Contributor

Choose a reason for hiding this comment

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

Might want to label this a sanity check, to make it more clear that the 141/145 checks are the meat of the test.

* will receive callbacks in the same order. Furthermore, each ValidationInterface
* subscriber may assume that callbacks effectively run in a single thread with
* single-threaded memory consistency. That is, for a given ValidationInterface()
* instantiation, each callback will complete before
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: whitespace

/**
* Implement this to subscribe to validation events
*
* Events are totally ordered - that is - all CValidationInterface() subscribers
Copy link
Contributor

Choose a reason for hiding this comment

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

The wording here seems to imply order between different subscribers.

Ensures ordering of callbacks within a SingleThreadedSchedulerClient
with respect to each other
@skeees skeees force-pushed the scheduler-tests branch from 9c9e203 to 9b6848e Compare May 18, 2018 16:37
@fanquake fanquake added this to the 0.17.0 milestone Jul 18, 2018
@maflcko maflcko requested a review from TheBlueMatt July 22, 2018 01:25
@DrahtBot
Copy link
Contributor

The last travis run for this pull request was 65 days ago and is thus outdated. To trigger a fresh travis build, this pull request should be closed and re-opened.

@DrahtBot DrahtBot closed this Jul 22, 2018
@DrahtBot DrahtBot reopened this Jul 22, 2018
@maflcko maflcko removed this from the 0.17.0 milestone Jul 30, 2018
Copy link
Contributor

@jamesob jamesob left a comment

Choose a reason for hiding this comment

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

utACK 9b6848e

src/scheduler.h Outdated
* at the same time.
* which are required to be run serially. Jobs may not be run on the
* same thread, but no two jobs will be executed
* at the same time and memory will be sequentially consistent.
Copy link
Contributor

Choose a reason for hiding this comment

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

Sequentially consistent of release-acquire? I think release-acquire is all we should guarantee.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated, thanks

@skeees skeees force-pushed the scheduler-tests branch from 9b6848e to cbeaa91 Compare July 30, 2018 23:42
@skeees
Copy link
Contributor Author

skeees commented Jul 30, 2018

Updated to address @TheBlueMatt (diff is a comment change only)

@skeees
Copy link
Contributor Author

skeees commented Jul 31, 2018

Test failure was unrelated and now resolved

@jamesob
Copy link
Contributor

jamesob commented Jul 31, 2018

re-utACK cbeaa91

@maflcko maflcko merged commit cbeaa91 into bitcoin:master Aug 1, 2018
maflcko pushed a commit that referenced this pull request Aug 1, 2018
…nt the memory model

cbeaa91 Update ValidationInterface() documentation to explicitly specify threading and memory model (Jesse Cohen)
b296b42 Update documentation for SingleThreadedSchedulerClient() to specify the memory model (Jesse Cohen)
9994d01 Add Unit Test for SingleThreadedSchedulerClient (Jesse Cohen)

Pull request description:

  As discussed in #13023 I've split this test out into a separate pr

  This test (and documentation update) makes explicit the guarantee (previously undefined, but implied by the 'SingleThreaded' in `SingleThreadedSchedulerClient()`) - that callbacks pushed to the `SingleThreadedSchedulerClient()` obey the single threaded model for memory and execution - specifically, the callbacks are executed fully and in order, and even in cases where a subsequent callback is executed by a different thread, sequential consistency of memory for all threads executing these callbacks is maintained.

  Maintaining memory consistency should make the api more developer friendly - especially for users of the validationinterface. To the extent that there are performance implications from this decision, these are not currently present in practice because all use of this scheduler happens on a single thread currently, furthermore the lock should guarantee consistency across callback executions even when callbacks are executed by multiple threads (as the test does).

Tree-SHA512: 5d95a7682c402e5ad76b05bc9dfbca99ca64105f62ab9e78f6fc0f6ea8c5277aa399fbb94298e35cc677b0c2181ff17259584bb7ae230e38aa68b85ecbc22856
laanwj added a commit that referenced this pull request Aug 2, 2018
fe7180c [trivial,doc] Fix memory consistency model in comment (Jesse Cohen)

Pull request description:

  Updating a comment overlooked during review in #13247

Tree-SHA512: 0bd54ba1c265fdd77fd6e12ad0be46dd422348f7d926ce9abaca53fdb3a3c55c0d1cd90b4382321352076f4a81e2249c0014cd789f47a3637cb93bd983cb4657
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 17, 2020
… document the memory model

cbeaa91 Update ValidationInterface() documentation to explicitly specify threading and memory model (Jesse Cohen)
b296b42 Update documentation for SingleThreadedSchedulerClient() to specify the memory model (Jesse Cohen)
9994d01 Add Unit Test for SingleThreadedSchedulerClient (Jesse Cohen)

Pull request description:

  As discussed in bitcoin#13023 I've split this test out into a separate pr

  This test (and documentation update) makes explicit the guarantee (previously undefined, but implied by the 'SingleThreaded' in `SingleThreadedSchedulerClient()`) - that callbacks pushed to the `SingleThreadedSchedulerClient()` obey the single threaded model for memory and execution - specifically, the callbacks are executed fully and in order, and even in cases where a subsequent callback is executed by a different thread, sequential consistency of memory for all threads executing these callbacks is maintained.

  Maintaining memory consistency should make the api more developer friendly - especially for users of the validationinterface. To the extent that there are performance implications from this decision, these are not currently present in practice because all use of this scheduler happens on a single thread currently, furthermore the lock should guarantee consistency across callback executions even when callbacks are executed by multiple threads (as the test does).

Tree-SHA512: 5d95a7682c402e5ad76b05bc9dfbca99ca64105f62ab9e78f6fc0f6ea8c5277aa399fbb94298e35cc677b0c2181ff17259584bb7ae230e38aa68b85ecbc22856
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 17, 2020
…mment

fe7180c [trivial,doc] Fix memory consistency model in comment (Jesse Cohen)

Pull request description:

  Updating a comment overlooked during review in bitcoin#13247

Tree-SHA512: 0bd54ba1c265fdd77fd6e12ad0be46dd422348f7d926ce9abaca53fdb3a3c55c0d1cd90b4382321352076f4a81e2249c0014cd789f47a3637cb93bd983cb4657
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 17, 2020
… document the memory model

cbeaa91 Update ValidationInterface() documentation to explicitly specify threading and memory model (Jesse Cohen)
b296b42 Update documentation for SingleThreadedSchedulerClient() to specify the memory model (Jesse Cohen)
9994d01 Add Unit Test for SingleThreadedSchedulerClient (Jesse Cohen)

Pull request description:

  As discussed in bitcoin#13023 I've split this test out into a separate pr

  This test (and documentation update) makes explicit the guarantee (previously undefined, but implied by the 'SingleThreaded' in `SingleThreadedSchedulerClient()`) - that callbacks pushed to the `SingleThreadedSchedulerClient()` obey the single threaded model for memory and execution - specifically, the callbacks are executed fully and in order, and even in cases where a subsequent callback is executed by a different thread, sequential consistency of memory for all threads executing these callbacks is maintained.

  Maintaining memory consistency should make the api more developer friendly - especially for users of the validationinterface. To the extent that there are performance implications from this decision, these are not currently present in practice because all use of this scheduler happens on a single thread currently, furthermore the lock should guarantee consistency across callback executions even when callbacks are executed by multiple threads (as the test does).

Tree-SHA512: 5d95a7682c402e5ad76b05bc9dfbca99ca64105f62ab9e78f6fc0f6ea8c5277aa399fbb94298e35cc677b0c2181ff17259584bb7ae230e38aa68b85ecbc22856
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 17, 2020
…mment

fe7180c [trivial,doc] Fix memory consistency model in comment (Jesse Cohen)

Pull request description:

  Updating a comment overlooked during review in bitcoin#13247

Tree-SHA512: 0bd54ba1c265fdd77fd6e12ad0be46dd422348f7d926ce9abaca53fdb3a3c55c0d1cd90b4382321352076f4a81e2249c0014cd789f47a3637cb93bd983cb4657
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 17, 2020
… document the memory model

cbeaa91 Update ValidationInterface() documentation to explicitly specify threading and memory model (Jesse Cohen)
b296b42 Update documentation for SingleThreadedSchedulerClient() to specify the memory model (Jesse Cohen)
9994d01 Add Unit Test for SingleThreadedSchedulerClient (Jesse Cohen)

Pull request description:

  As discussed in bitcoin#13023 I've split this test out into a separate pr

  This test (and documentation update) makes explicit the guarantee (previously undefined, but implied by the 'SingleThreaded' in `SingleThreadedSchedulerClient()`) - that callbacks pushed to the `SingleThreadedSchedulerClient()` obey the single threaded model for memory and execution - specifically, the callbacks are executed fully and in order, and even in cases where a subsequent callback is executed by a different thread, sequential consistency of memory for all threads executing these callbacks is maintained.

  Maintaining memory consistency should make the api more developer friendly - especially for users of the validationinterface. To the extent that there are performance implications from this decision, these are not currently present in practice because all use of this scheduler happens on a single thread currently, furthermore the lock should guarantee consistency across callback executions even when callbacks are executed by multiple threads (as the test does).

Tree-SHA512: 5d95a7682c402e5ad76b05bc9dfbca99ca64105f62ab9e78f6fc0f6ea8c5277aa399fbb94298e35cc677b0c2181ff17259584bb7ae230e38aa68b85ecbc22856
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 17, 2020
…mment

fe7180c [trivial,doc] Fix memory consistency model in comment (Jesse Cohen)

Pull request description:

  Updating a comment overlooked during review in bitcoin#13247

Tree-SHA512: 0bd54ba1c265fdd77fd6e12ad0be46dd422348f7d926ce9abaca53fdb3a3c55c0d1cd90b4382321352076f4a81e2249c0014cd789f47a3637cb93bd983cb4657
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Apr 4, 2021
…tChain + optimization

50dbec5 Add unit tests for signals generated by ProcessNewBlock() (furszy)
f68251d Validation: rename one of the two instances using "bad-prevblk" to its correct description of "prevblk-not-found" (furszy)
a51a755 Fix concurrency-related bugs in ActivateBestChain (Jesse Cohen)
198f435 Do not unlock cs_main in ABC unless we've actually made progress. (Matt Corallo)
8d15cf5 Optimize ActivateBestChain for long chains (Pieter Wuille)
8640be1 Fix fast-shutdown crash if genesis block was not loaded (Matt Corallo)
ef24337 Hold cs_main while calling UpdatedBlockTip() and ui.NotifyBlockTip (Jesse Cohen)
f9d2ab3 Update ValidationInterface() documentation to explicitly specify threading and memory model (Jesse Cohen)
cb9bb25 Update documentation for SingleThreadedSchedulerClient() to specify the memory model (Jesse Cohen)
4ea2048 Add Unit Test for SingleThreadedSchedulerClient (Jesse Cohen)

Pull request description:

  Made some back ports and adaptations to validate further the work introduced in #2203 and #2209.
  Now that the scheduler thread is processing most of the chain events, the callbacks execution order must be verified to dispatch the events serially, ensuring a consistent memory state in each event processing invocation.
  There are some concurrency issues solved, as well a an optimization for larger chains for the ABC workflow. Each commit details them well.

  List:
  bitcoin#7917 (only fb8fad1)
  bitcoin#12988
  bitcoin#13023
  bitcoin#13247
  bitcoin#13835

  This is built on top of #2284 (and the reason that made me notice that problem). So, 2284 comes first, then this one.

ACKs for top commit:
  Fuzzbawls:
    ACK 50dbec5
  random-zebra:
    ACK 50dbec5 and merging...

Tree-SHA512: 573144cc96d2caa49ed2f0887dc8c53b5aca0efd54b6a25626063ccb780da426f56b3c6b7491648e7abefc1960c82b1354a4ff2c51425bfe99adaa4394562608
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants