Changeset 8b50a55 in rtems


Ignore:
Timestamp:
03/03/14 08:09:24 (10 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, 5, master
Children:
e0609ac
Parents:
a418b2f
git-author:
Sebastian Huber <sebastian.huber@…> (03/03/14 08:09:24)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/06/14 08:43:58)
Message:

score: Add _Atomic_Fence()

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/include/rtems/score/atomic.h

    ra418b2f r8b50a55  
    4444#define ATOMIC_INITIALIZER_FLAG CPU_ATOMIC_INITIALIZER_FLAG
    4545
     46static inline void _Atomic_Fence(
     47  Atomic_Order order
     48)
     49{
     50  _CPU_atomic_Fence( order );
     51}
     52
    4653/**
    4754 * @brief Initializes an atomic type value into a atomic object.
  • cpukit/score/include/rtems/score/cpustdatomic.h

    ra418b2f r8b50a55  
    8484#define CPU_ATOMIC_INITIALIZER_FLAG ATOMIC_FLAG_INIT
    8585
     86static inline void _CPU_atomic_Fence(
     87  Atomic_Order order
     88)
     89{
     90  atomic_thread_fence( (memory_order) order );
     91}
     92
    8693/**
    8794 * @brief Initializes an atomic type value into a atomic object.
  • testsuites/smptests/smpatomic01/init.c

    ra418b2f r8b50a55  
    2222#include <rtems/score/smpbarrier.h>
    2323#include <rtems.h>
     24#include <limits.h>
    2425#include <string.h>
    2526
     
    4142  unsigned long per_worker_value[CPU_COUNT];
    4243  unsigned long normal_value;
     44  char unused_space_for_cache_line_separation[128];
     45  unsigned long second_value;
    4346  Atomic_Flag global_flag;
    4447} test_context;
     
    7578  size_t worker_index;
    7679
    77   printf("=== atomic %s test case ==\n", test);
     80  printf("=== atomic %s test case ===\n", test);
    7881
    7982  for (worker_index = 0; worker_index < ctx->worker_count; ++worker_index) {
     
    254257{
    255258  test_fini(ctx, "or/and", true);
     259}
     260
     261static void test_atomic_fence_init(test_context *ctx)
     262{
     263  ctx->normal_value = 0;
     264  ctx->second_value = 0;
     265  _Atomic_Fence(ATOMIC_ORDER_RELEASE);
     266}
     267
     268static void test_atomic_fence_body(test_context *ctx, size_t worker_index)
     269{
     270  if (is_master_worker(worker_index)) {
     271    unsigned long counter = 0;
     272
     273    while (!stop(ctx)) {
     274      ++counter;
     275      ctx->normal_value = counter;
     276      _Atomic_Fence(ATOMIC_ORDER_RELEASE);
     277      ctx->second_value = counter;
     278    }
     279  } else {
     280    while (!stop(ctx)) {
     281      unsigned long n;
     282      unsigned long s;
     283
     284      s = ctx->second_value;
     285      _Atomic_Fence(ATOMIC_ORDER_ACQUIRE);
     286      n = ctx->normal_value;
     287
     288      rtems_test_assert(n - s < LONG_MAX);
     289    }
     290  }
     291}
     292
     293static void test_atomic_fence_fini(test_context *ctx)
     294{
     295  printf(
     296    "=== atomic fence test case ===\n"
     297    "normal value = %lu, second value = %lu\n",
     298    ctx->normal_value,
     299    ctx->second_value
     300  );
    256301}
    257302
     
    277322    test_atomic_or_and_body,
    278323    test_atomic_or_and_fini
     324  }, {
     325    test_atomic_fence_init,
     326    test_atomic_fence_body,
     327    test_atomic_fence_fini
    279328  },
    280329};
     
    433482  unsigned long c;
    434483
    435   puts("=== atomic simple add test case ==\n");
     484  puts("=== atomic simple add test case ===\n");
    436485
    437486  _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
     
    453502  unsigned long c;
    454503
    455   puts("=== atomic simple sub test case ==\n");
     504  puts("=== atomic simple sub test case ===\n");
    456505
    457506  _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
     
    473522  unsigned long c;
    474523
    475   puts("=== atomic simple or test case ==\n");
     524  puts("=== atomic simple or test case ===\n");
    476525
    477526  _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
     
    493542  unsigned long c;
    494543
    495   puts("=== atomic simple and test case ==\n");
     544  puts("=== atomic simple and test case ===\n");
    496545
    497546  _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
     
    513562  unsigned long c;
    514563
    515   puts("=== atomic simple exchange test case ==\n");
     564  puts("=== atomic simple exchange test case ===\n");
    516565
    517566  _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
     
    533582  unsigned long c;
    534583
    535   puts("=== atomic simple compare exchange test case ==\n");
     584  puts("=== atomic simple compare exchange test case ===\n");
    536585
    537586  _Atomic_Store_uint(&ctx->atomic_int_value, ia, ATOMIC_ORDER_RELAXED);
  • testsuites/smptests/smpatomic01/smpatomic01.scn

    ra418b2f r8b50a55  
    11*** TEST SMPATOMIC 1 ***
    2 === atomic simple add test case ==
    3 === atomic simple sub test case ==
    4 === atomic simple or test case ==
    5 === atomic simple and test case ==
    6 === atomic simple exchange test case ==
    7 === atomic simple compare exchange test case ==
    8 === static and dynamic initialization test case ===
    9 === atomic add test case ==
     2=== atomic simple add test case ===
     3=== atomic simple sub test case ===
     4=== atomic simple or test case ===
     5=== atomic simple and test case ===
     6=== atomic simple exchange test case ===
     7=== atomic simple compare exchange test case ===
     8=== static and dynamic initialization test case ====
     9=== atomic add test case ===
    1010worker 0 value: 16686
    1111worker 1 value: 36405
    1212atomic value: expected = 53091, actual = 53091
    13 === atomic flag test case ==
     13=== atomic flag test case ===
    1414worker 0 value: 5588
    1515worker 1 value: 16019
    1616atomic value: expected = 21607, actual = 21607
    17 === atomic sub test case ==
     17=== atomic sub test case ===
    1818worker 0 value: 4294950967
    1919worker 1 value: 4294930886
    2020atomic value: expected = 4294914557, actual = 4294914557
    21 === atomic compare exchange test case ==
     21=== atomic compare exchange test case ===
    2222worker 0 value: 2950
    2323worker 1 value: 22456
    2424atomic value: expected = 25406, actual = 25406
    25 === atomic or/and test case ==
     25=== atomic or/and test case ===
    2626worker 0 value: 1
    2727worker 1 value: 0
    2828atomic value: expected = 1, actual = 1
     29=== atomic fence test case ===
     30normal value = 10759507, second value = 10759507
    2931*** END OF TEST SMPATOMIC 1 ***
Note: See TracChangeset for help on using the changeset viewer.