Changeset fc10e1b in mainline for kernel/test


Ignore:
Timestamp:
2018-09-07T16:34:11Z (7 years ago)
Author:
Jiří Zárevúcky <jiri.zarevucky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d2c91ab
Parents:
508b0df1 (diff), e90cfa6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'atomic'

Use more of <stdatomic.h> in kernel. Increment/decrement macros kept because
the are handy. atomic_t currently kept because I'm way too lazy to go through
all uses and think about the most appropriate replacement.

Location:
kernel/test
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • kernel/test/atomic/atomic1.c

    r508b0df1 rfc10e1b  
    3636        atomic_t a;
    3737
    38         atomic_set(&a, 10);
    39         if (atomic_get(&a) != 10)
    40                 return "Failed atomic_set()/atomic_get()";
     38        atomic_store(&a, 10);
     39        if (atomic_load(&a) != 10)
     40                return "Failed atomic_store()/atomic_load()";
    4141
    4242        if (atomic_postinc(&a) != 10)
    4343                return "Failed atomic_postinc()";
    44         if (atomic_get(&a) != 11)
    45                 return "Failed atomic_get() after atomic_postinc()";
     44        if (atomic_load(&a) != 11)
     45                return "Failed atomic_load() after atomic_postinc()";
    4646
    4747        if (atomic_postdec(&a) != 11)
    4848                return "Failed atomic_postdec()";
    49         if (atomic_get(&a) != 10)
    50                 return "Failed atomic_get() after atomic_postdec()";
     49        if (atomic_load(&a) != 10)
     50                return "Failed atomic_load() after atomic_postdec()";
    5151
    5252        if (atomic_preinc(&a) != 11)
    5353                return "Failed atomic_preinc()";
    54         if (atomic_get(&a) != 11)
    55                 return "Failed atomic_get() after atomic_preinc()";
     54        if (atomic_load(&a) != 11)
     55                return "Failed atomic_load() after atomic_preinc()";
    5656
    5757        if (atomic_predec(&a) != 10)
    5858                return "Failed atomic_predec()";
    59         if (atomic_get(&a) != 10)
    60                 return "Failed atomic_get() after atomic_predec()";
     59        if (atomic_load(&a) != 10)
     60                return "Failed atomic_load() after atomic_predec()";
    6161
    6262        return NULL;
  • kernel/test/mm/falloc2.c

    r508b0df1 rfc10e1b  
    117117const char *test_falloc2(void)
    118118{
    119         atomic_set(&thread_count, THREADS);
    120         atomic_set(&thread_fail, 0);
     119        atomic_store(&thread_count, THREADS);
     120        atomic_store(&thread_fail, 0);
    121121
    122122        for (unsigned int i = 0; i < THREADS; i++) {
     
    130130        }
    131131
    132         while (atomic_get(&thread_count) > 0) {
    133                 TPRINTF("Threads left: %" PRIua "\n",
    134                     atomic_get(&thread_count));
     132        while (atomic_load(&thread_count) > 0) {
     133                TPRINTF("Threads left: %zu\n",
     134                    atomic_load(&thread_count));
    135135                thread_sleep(1);
    136136        }
    137137
    138         if (atomic_get(&thread_fail) == 0)
     138        if (atomic_load(&thread_fail) == 0)
    139139                return NULL;
    140140
  • kernel/test/synch/rcu1.c

    r508b0df1 rfc10e1b  
    238238
    239239
    240 static atomic_t nop_callbacks_cnt = { 0 };
     240static atomic_t nop_callbacks_cnt = 0;
    241241/* Must be even. */
    242242static const int nop_updater_iters = 10000;
     
    268268static bool do_nop_callbacks(void)
    269269{
    270         atomic_set(&nop_callbacks_cnt, 0);
     270        atomic_store(&nop_callbacks_cnt, 0);
    271271
    272272        size_t exp_cnt = nop_updater_iters * get_thread_cnt();
     
    282282        size_t loop_cnt = 0, max_loops = 15;
    283283
    284         while (exp_cnt != atomic_get(&nop_callbacks_cnt) && loop_cnt < max_loops) {
     284        while (exp_cnt != atomic_load(&nop_callbacks_cnt) && loop_cnt < max_loops) {
    285285                ++loop_cnt;
    286286                TPRINTF(".");
     
    361361typedef struct {
    362362        rcu_item_t rcu;
    363         atomic_count_t start_time;
     363        size_t start_time;
    364364} seq_item_t;
    365365
     
    367367static errno_t seq_test_result = EOK;
    368368
    369 static atomic_t cur_time = { 1 };
    370 static atomic_count_t max_upd_done_time = { 0 };
     369static atomic_t cur_time = 1;
     370static size_t max_upd_done_time = { 0 };
    371371
    372372static void seq_cb(rcu_item_t *rcu_item)
     
    399399                for (size_t i = 0; i < work->read_cnt; ++i) {
    400400                        rcu_read_lock();
    401                         atomic_count_t start_time = atomic_postinc(&cur_time);
     401                        size_t start_time = atomic_postinc(&cur_time);
    402402
    403403                        for (volatile size_t d = 0; d < 10 * i; ++d) {
     
    448448        seq_test_result = EOK;
    449449        max_upd_done_time = 0;
    450         atomic_set(&cur_time, 1);
     450        atomic_store(&cur_time, 1);
    451451
    452452        const size_t iters = 100;
     
    821821{
    822822        barrier_t *b = member_to_inst(item, barrier_t, rcu_item);
    823         atomic_set(&b->done, 1);
     823        atomic_store(&b->done, 1);
    824824}
    825825
     
    835835        }
    836836
    837         atomic_set(&barrier->done, 0);
     837        atomic_store(&barrier->done, 0);
    838838
    839839        rcu_call(&barrier->rcu_item, barrier_callback);
    840840        rcu_barrier();
    841841
    842         if (1 == atomic_get(&barrier->done)) {
     842        if (1 == atomic_load(&barrier->done)) {
    843843                free(barrier);
    844844                return true;
  • kernel/test/synch/semaphore1.c

    r508b0df1 rfc10e1b  
    7373{
    7474        int i, j, k;
    75         atomic_count_t consumers;
    76         atomic_count_t producers;
     75        size_t consumers;
     76        size_t producers;
    7777
    7878        waitq_initialize(&can_start);
     
    8282                thread_t *thrd;
    8383
    84                 atomic_set(&items_produced, 0);
    85                 atomic_set(&items_consumed, 0);
     84                atomic_store(&items_produced, 0);
     85                atomic_store(&items_consumed, 0);
    8686
    8787                consumers = i * CONSUMERS;
    8888                producers = (4 - i) * PRODUCERS;
    8989
    90                 TPRINTF("Creating %" PRIua " consumers and %" PRIua " producers...",
     90                TPRINTF("Creating %zu consumers and %zu producers...",
    9191                    consumers, producers);
    9292
     
    115115                waitq_wakeup(&can_start, WAKEUP_ALL);
    116116
    117                 while ((items_consumed.count != consumers) || (items_produced.count != producers)) {
    118                         TPRINTF("%" PRIua " consumers remaining, %" PRIua " producers remaining\n",
    119                             consumers - items_consumed.count, producers - items_produced.count);
     117                while ((items_consumed != consumers) || (items_produced != producers)) {
     118                        TPRINTF("%zu consumers remaining, %zu producers remaining\n",
     119                            consumers - items_consumed, producers - items_produced);
    120120                        thread_sleep(1);
    121121                }
  • kernel/test/synch/workq-test-core.h

    r508b0df1 rfc10e1b  
    149149{
    150150        for (int i = 0; i < WAVES; ++i) {
    151                 atomic_set(&call_cnt[i], 0);
     151                atomic_store(&call_cnt[i], 0);
    152152        }
    153153
     
    179179
    180180        for (int i = 0; i < WAVES; ++i) {
    181                 while (atomic_get(&call_cnt[i]) < exp_call_cnt &&
     181                while (atomic_load(&call_cnt[i]) < exp_call_cnt &&
    182182                    sleep_cnt < max_sleep_cnt) {
    183183                        TPRINTF(".");
     
    190190
    191191        for (int i = 0; i < WAVES; ++i) {
    192                 if (atomic_get(&call_cnt[i]) == exp_call_cnt) {
    193                         TPRINTF("Ok: %" PRIua " calls in wave %d, as expected.\n",
    194                             atomic_get(&call_cnt[i]), i);
     192                if (atomic_load(&call_cnt[i]) == exp_call_cnt) {
     193                        TPRINTF("Ok: %zu calls in wave %d, as expected.\n",
     194                            atomic_load(&call_cnt[i]), i);
    195195                } else {
    196196                        success = false;
    197                         TPRINTF("Error: %" PRIua " calls in wave %d, but %zu expected.\n",
    198                             atomic_get(&call_cnt[i]), i, exp_call_cnt);
     197                        TPRINTF("Error: %zu calls in wave %d, but %zu expected.\n",
     198                            atomic_load(&call_cnt[i]), i, exp_call_cnt);
    199199                }
    200200        }
  • kernel/test/thread/thread1.c

    r508b0df1 rfc10e1b  
    4646        thread_detach(THREAD);
    4747
    48         while (atomic_get(&finish)) {
     48        while (atomic_load(&finish)) {
    4949                TPRINTF("%" PRIu64 " ", THREAD->tid);
    5050                thread_usleep(100000);
     
    5656{
    5757        unsigned int i;
    58         atomic_count_t total = 0;
     58        size_t total = 0;
    5959
    60         atomic_set(&finish, 1);
    61         atomic_set(&threads_finished, 0);
     60        atomic_store(&finish, 1);
     61        atomic_store(&threads_finished, 0);
    6262
    6363        for (i = 0; i < THREADS; i++) {
     
    7575        thread_sleep(10);
    7676
    77         atomic_set(&finish, 0);
    78         while (atomic_get(&threads_finished) < total) {
    79                 TPRINTF("Threads left: %" PRIua "\n", total - atomic_get(&threads_finished));
     77        atomic_store(&finish, 0);
     78        while (atomic_load(&threads_finished) < total) {
     79                TPRINTF("Threads left: %zu\n", total - atomic_load(&threads_finished));
    8080                thread_sleep(1);
    8181        }
Note: See TracChangeset for help on using the changeset viewer.