Changeset cc8bb9e3 in rtems


Ignore:
Timestamp:
Jun 7, 2016, 1:26:52 PM (3 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
4c19e59b
Parents:
6fc34e4
git-author:
Sebastian Huber <sebastian.huber@…> (06/07/16 13:26:52)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/07/16 13:28:57)
Message:

smptests/smpatomic01: Add seqlock test case

Location:
testsuites/smptests/smpatomic01
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • testsuites/smptests/smpatomic01/init.c

    r6fc34e4 rcc8bb9e3  
    572572      ts.tv_nsec,
    573573      ctx->rmw_count[i]
     574    );
     575  }
     576}
     577
     578/*
     579 * See also Hans-J. Boehm, HP Laboratories,
     580 * "Can Seqlocks Get Along With Programming Language Memory Models?",
     581 * http://www.hpl.hp.com/techreports/2012/HPL-2012-68.pdf
     582 */
     583
     584static rtems_interval test_seqlock_init(
     585  rtems_test_parallel_context *base,
     586  void *arg,
     587  size_t active_workers
     588)
     589{
     590  smpatomic01_context *ctx = (smpatomic01_context *) base;
     591
     592  ctx->normal_value = 0;
     593  ctx->second_value = 0;
     594  _Atomic_Store_ulong(&ctx->atomic_value, 0, ATOMIC_ORDER_RELEASE);
     595
     596  return test_duration();
     597}
     598
     599static unsigned long seqlock_read(smpatomic01_context *ctx)
     600{
     601  unsigned long counter = 0;
     602
     603  while (!rtems_test_parallel_stop_job(&ctx->base)) {
     604    unsigned long seq0;
     605    unsigned long seq1;
     606    unsigned long a;
     607    unsigned long b;
     608
     609    do {
     610      seq0 = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_ACQUIRE);
     611
     612      a = ctx->normal_value;
     613      b = ctx->second_value;
     614
     615      seq1 =
     616        _Atomic_Fetch_add_ulong(&ctx->atomic_value, 0, ATOMIC_ORDER_RELEASE);
     617    } while (seq0 != seq1 || seq0 % 2 != 0);
     618
     619    ++counter;
     620    rtems_test_assert(a == b);
     621  }
     622
     623  return counter;
     624}
     625
     626static void test_single_writer_seqlock_body(
     627  rtems_test_parallel_context *base,
     628  void *arg,
     629  size_t active_workers,
     630  size_t worker_index
     631)
     632{
     633  smpatomic01_context *ctx = (smpatomic01_context *) base;
     634  uint32_t cpu_self_index;
     635  unsigned long counter;
     636
     637  /*
     638   * Use the physical processor index, to observe timing differences introduced
     639   * by the system topology.
     640   */
     641  cpu_self_index = rtems_get_current_processor();
     642
     643  if (cpu_self_index == 0) {
     644    counter = 0;
     645
     646    while (!rtems_test_parallel_stop_job(&ctx->base)) {
     647      unsigned long seq;
     648
     649      seq = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
     650      _Atomic_Store_ulong(&ctx->atomic_value, seq + 1, ATOMIC_ORDER_RELAXED);
     651      _Atomic_Fence(ATOMIC_ORDER_ACQUIRE);
     652
     653      ++counter;
     654      ctx->normal_value = counter;
     655      ctx->second_value = counter;
     656
     657      _Atomic_Store_ulong(&ctx->atomic_value, seq + 2, ATOMIC_ORDER_RELEASE);
     658    }
     659  } else {
     660    counter = seqlock_read(ctx);
     661  }
     662
     663  ctx->per_worker_value[cpu_self_index] = counter;
     664}
     665
     666static void test_single_writer_seqlock_fini(
     667  rtems_test_parallel_context *base,
     668  void *arg,
     669  size_t active_workers
     670)
     671{
     672  smpatomic01_context *ctx = (smpatomic01_context *) base;
     673  size_t i;
     674
     675  printf("=== single writer seqlock test case ===\n");
     676
     677  for (i = 0; i < active_workers; ++i) {
     678    printf(
     679      "processor %zu count %lu\n",
     680      i,
     681      ctx->per_worker_value[i]
     682    );
     683  }
     684}
     685
     686static void test_multi_writer_seqlock_body(
     687  rtems_test_parallel_context *base,
     688  void *arg,
     689  size_t active_workers,
     690  size_t worker_index
     691)
     692{
     693  smpatomic01_context *ctx = (smpatomic01_context *) base;
     694  uint32_t cpu_self_index;
     695  unsigned long counter;
     696
     697  /*
     698   * Use the physical processor index, to observe timing differences introduced
     699   * by the system topology.
     700   */
     701  cpu_self_index = rtems_get_current_processor();
     702
     703  if (cpu_self_index % 2 == 0) {
     704    counter = 0;
     705
     706    while (!rtems_test_parallel_stop_job(&ctx->base)) {
     707      unsigned long seq;
     708
     709      do {
     710        seq = _Atomic_Load_ulong(&ctx->atomic_value, ATOMIC_ORDER_RELAXED);
     711      } while (
     712        seq % 2 != 0
     713          || !_Atomic_Compare_exchange_ulong(
     714              &ctx->atomic_value,
     715              &seq,
     716              seq + 1,
     717              ATOMIC_ORDER_ACQ_REL,
     718              ATOMIC_ORDER_RELAXED
     719            )
     720      );
     721
     722      ++counter;
     723      ctx->normal_value = counter;
     724      ctx->second_value = counter;
     725
     726      _Atomic_Store_ulong(&ctx->atomic_value, seq + 2, ATOMIC_ORDER_RELEASE);
     727    }
     728  } else {
     729    counter = seqlock_read(ctx);
     730  }
     731
     732  ctx->per_worker_value[cpu_self_index] = counter;
     733}
     734
     735static void test_multi_writer_seqlock_fini(
     736  rtems_test_parallel_context *base,
     737  void *arg,
     738  size_t active_workers
     739)
     740{
     741  smpatomic01_context *ctx = (smpatomic01_context *) base;
     742  size_t i;
     743
     744  printf("=== multi writer seqlock test case ===\n");
     745
     746  for (i = 0; i < active_workers; ++i) {
     747    printf(
     748      "processor %zu count %lu\n",
     749      i,
     750      ctx->per_worker_value[i]
    574751    );
    575752  }
     
    605782    .body = test_atomic_store_load_rmw_body,
    606783    .fini = test_atomic_store_load_rmw_fini
     784  }, {
     785    .init = test_seqlock_init,
     786    .body = test_single_writer_seqlock_body,
     787    .fini = test_single_writer_seqlock_fini
     788  }, {
     789    .init = test_seqlock_init,
     790    .body = test_multi_writer_seqlock_body,
     791    .fini = test_multi_writer_seqlock_fini
    607792  }
    608793};
  • testsuites/smptests/smpatomic01/smpatomic01.scn

    r6fc34e4 rcc8bb9e3  
    182182processor 22 delta 1361ns, read-modify-write count 0
    183183processor 23 delta 3200ns, read-modify-write count 0
     184=== single writer seqlock test case ===
     185processor 0 count 2451021
     186processor 1 count 1
     187processor 2 count 8
     188processor 3 count 31
     189processor 4 count 52
     190processor 5 count 23
     191processor 6 count 23
     192processor 7 count 49
     193processor 8 count 703
     194processor 9 count 750
     195processor 10 count 684
     196processor 11 count 770
     197processor 12 count 710
     198processor 13 count 691
     199processor 14 count 687
     200processor 15 count 695
     201processor 16 count 774
     202processor 17 count 828
     203processor 18 count 732
     204processor 19 count 719
     205processor 20 count 728
     206processor 21 count 761
     207processor 22 count 685
     208processor 23 count 764
     209=== multi writer seqlock test case ===
     210processor 0 count 124410
     211processor 1 count 7865
     212processor 2 count 123950
     213processor 3 count 7797
     214processor 4 count 124253
     215processor 5 count 7773
     216processor 6 count 124763
     217processor 7 count 7817
     218processor 8 count 124593
     219processor 9 count 7781
     220processor 10 count 124647
     221processor 11 count 7753
     222processor 12 count 124322
     223processor 13 count 7692
     224processor 14 count 124906
     225processor 15 count 7715
     226processor 16 count 124568
     227processor 17 count 7605
     228processor 18 count 125060
     229processor 19 count 7908
     230processor 20 count 124499
     231processor 21 count 7804
     232processor 22 count 124538
     233processor 23 count 7874
    184234*** END OF TEST SMPATOMIC 1 ***
Note: See TracChangeset for help on using the changeset viewer.