Changeset aaa3c457 in mainline


Ignore:
Timestamp:
2018-11-12T10:36:10Z (6 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a43dfcb
Parents:
3ce781f4 (diff), 6874bd2 (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.
git-author:
Jakub Jermář <jakub@…> (2018-11-12 10:36:10)
git-committer:
GitHub <noreply@…> (2018-11-12 10:36:10)
Message:

Merge pull request #56 from jermar/futexremoval

Remove kernel support for futexes in favor of waitq kobjects.

Files:
1 added
1 deleted
29 edited
1 moved

Legend:

Unmodified
Added
Removed
  • abi/include/abi/cap.h

    r3ce781f4 raaa3c457  
    5252} *cap_irq_handle_t;
    5353
     54typedef struct {
     55} *cap_waitq_handle_t;
     56
    5457#endif
    5558
  • abi/include/abi/syscall.h

    r3ce781f4 raaa3c457  
    5151        SYS_PROGRAM_SPAWN_LOADER,
    5252
    53         SYS_FUTEX_SLEEP,
    54         SYS_FUTEX_WAKEUP,
     53        SYS_WAITQ_CREATE,
     54        SYS_WAITQ_SLEEP,
     55        SYS_WAITQ_WAKEUP,
     56        SYS_WAITQ_DESTROY,
    5557        SYS_SMC_COHERENCE,
    5658
  • kernel/Makefile

    r3ce781f4 raaa3c457  
    227227        generic/src/synch/smc.c \
    228228        generic/src/synch/waitq.c \
    229         generic/src/synch/futex.c \
     229        generic/src/synch/syswaitq.c \
    230230        generic/src/smp/ipi.c \
    231231        generic/src/smp/smp.c \
  • kernel/generic/include/cap/cap.h

    r3ce781f4 raaa3c457  
    5555        KOBJECT_TYPE_IRQ,
    5656        KOBJECT_TYPE_PHONE,
     57        KOBJECT_TYPE_WAITQ,
    5758        KOBJECT_TYPE_MAX
    5859} kobject_type_t;
     
    6364struct irq;
    6465struct phone;
     66struct waitq;
    6567
    6668typedef struct kobject_ops {
     
    8890                struct irq *irq;
    8991                struct phone *phone;
     92                struct waitq *waitq;
    9093        };
    9194} kobject_t;
  • kernel/generic/include/proc/task.h

    r3ce781f4 raaa3c457  
    4242#include <synch/spinlock.h>
    4343#include <synch/mutex.h>
    44 #include <synch/futex.h>
    4544#include <adt/list.h>
    4645#include <adt/odict.h>
     
    128127        task_arch_t arch;
    129128
    130         /** Serializes access to futex_list.*/
    131         SPINLOCK_DECLARE(futex_list_lock);
    132         /** List of all futexes accesses by this task. */
    133         list_t futex_list;
    134 
    135129        /** Accumulated accounting. */
    136130        uint64_t ucycles;
  • kernel/generic/include/synch/syswaitq.h

    r3ce781f4 raaa3c457  
    11/*
    2  * Copyright (c) 2006 Jakub Jermar
     2 * Copyright (c) 2018 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    3333 */
    3434
    35 #ifndef KERN_FUTEX_H_
    36 #define KERN_FUTEX_H_
     35#ifndef KERN_SYS_WAITQ_H_
     36#define KERN_SYS_WAITQ_H_
    3737
    3838#include <typedefs.h>
    39 #include <synch/waitq.h>
    40 #include <adt/hash_table.h>
     39#include <abi/cap.h>
    4140
    42 /** Kernel-side futex structure. */
    43 typedef struct {
    44         /** Physical address of the status variable. */
    45         uintptr_t paddr;
    46         /** Wait queue for threads waiting for futex availability. */
    47         waitq_t wq;
    48         /** Futex hash table link. */
    49         ht_link_t ht_link;
    50         /** Number of tasks that reference this futex. */
    51         size_t refcount;
    52 } futex_t;
     41extern void sys_waitq_init(void);
    5342
    54 extern void futex_init(void);
    55 extern sys_errno_t sys_futex_sleep(uintptr_t, uintptr_t);
    56 extern sys_errno_t sys_futex_wakeup(uintptr_t);
     43extern void sys_waitq_task_cleanup(void);
    5744
    58 extern void futex_task_cleanup(void);
    59 extern void futex_task_init(struct task *);
     45extern sys_errno_t sys_waitq_create(cap_waitq_handle_t *);
     46extern sys_errno_t sys_waitq_sleep(cap_waitq_handle_t, uint32_t, unsigned int);
     47extern sys_errno_t sys_waitq_wakeup(cap_waitq_handle_t);
     48extern sys_errno_t sys_waitq_destroy(cap_waitq_handle_t);
    6049
    6150#endif
  • kernel/generic/include/synch/waitq.h

    r3ce781f4 raaa3c457  
    4949 *
    5050 */
    51 typedef struct {
     51typedef struct waitq {
    5252        /** Lock protecting wait queue structure.
    5353         *
  • kernel/generic/src/main/main.c

    r3ce781f4 raaa3c457  
    7777#include <mm/reserve.h>
    7878#include <synch/waitq.h>
    79 #include <synch/futex.h>
     79#include <synch/syswaitq.h>
    8080#include <arch/arch.h>
    8181#include <arch.h>
     
    278278        task_init();
    279279        thread_init();
    280         futex_init();
     280        sys_waitq_init();
    281281
    282282        sysinfo_set_item_data("boot_args", NULL, bargs, str_size(bargs) + 1);
  • kernel/generic/src/proc/task.c

    r3ce781f4 raaa3c457  
    4343#include <mm/slab.h>
    4444#include <atomic.h>
    45 #include <synch/futex.h>
    4645#include <synch/spinlock.h>
    4746#include <synch/waitq.h>
     
    251250        }
    252251
    253         futex_task_init(task);
    254 
    255252        irq_spinlock_lock(&tasks_lock, true);
    256253
  • kernel/generic/src/proc/thread.c

    r3ce781f4 raaa3c457  
    4848#include <synch/spinlock.h>
    4949#include <synch/waitq.h>
     50#include <synch/syswaitq.h>
    5051#include <cpu.h>
    5152#include <str.h>
     
    519520                         */
    520521                        ipc_cleanup();
    521                         futex_task_cleanup();
     522                        sys_waitq_task_cleanup();
    522523                        LOG("Cleanup of task %" PRIu64 " completed.", TASK->taskid);
    523524                }
  • kernel/generic/src/syscall/syscall.c

    r3ce781f4 raaa3c457  
    4646#include <interrupt.h>
    4747#include <ipc/sysipc.h>
    48 #include <synch/futex.h>
    4948#include <synch/smc.h>
     49#include <synch/syswaitq.h>
    5050#include <ddi/ddi.h>
    5151#include <ipc/event.h>
     
    136136
    137137        /* Synchronization related syscalls. */
    138         [SYS_FUTEX_SLEEP] = (syshandler_t) sys_futex_sleep,
    139         [SYS_FUTEX_WAKEUP] = (syshandler_t) sys_futex_wakeup,
     138        [SYS_WAITQ_CREATE] = (syshandler_t) sys_waitq_create,
     139        [SYS_WAITQ_SLEEP] = (syshandler_t) sys_waitq_sleep,
     140        [SYS_WAITQ_WAKEUP] = (syshandler_t) sys_waitq_wakeup,
     141        [SYS_WAITQ_DESTROY] = (syshandler_t) sys_waitq_destroy,
    140142        [SYS_SMC_COHERENCE] = (syshandler_t) sys_smc_coherence,
    141143
  • uspace/app/trace/syscalls.c

    r3ce781f4 raaa3c457  
    4646        [SYS_TASK_GET_ID] = { "task_get_id", 1, V_ERRNO },
    4747        [SYS_TASK_SET_NAME] = { "task_set_name", 2, V_ERRNO },
    48         [SYS_FUTEX_SLEEP] = { "futex_sleep_timeout", 3, V_ERRNO },
    49         [SYS_FUTEX_WAKEUP] = { "futex_wakeup", 1, V_ERRNO },
    5048
    5149        [SYS_AS_AREA_CREATE] = { "as_area_create", 5, V_ERRNO },
  • uspace/lib/c/generic/async/client.c

    r3ce781f4 raaa3c457  
    122122#include "../private/fibril.h"
    123123
    124 static FIBRIL_RMUTEX_INITIALIZE(message_mutex);
     124static fibril_rmutex_t message_mutex;
    125125
    126126/** Naming service session */
     
    173173void __async_client_init(void)
    174174{
     175        if (fibril_rmutex_initialize(&message_mutex) != EOK)
     176                abort();
     177
    175178        session_ns.iface = 0;
    176179        session_ns.mgmt = EXCHANGE_ATOMIC;
     
    186189        fibril_mutex_initialize(&session_ns.mutex);
    187190        session_ns.exchanges = 0;
     191}
     192
     193void __async_client_fini(void)
     194{
     195        fibril_rmutex_destroy(&message_mutex);
    188196}
    189197
  • uspace/lib/c/generic/async/ports.c

    r3ce781f4 raaa3c457  
    100100
    101101/** Futex guarding the interface hash table. */
    102 static FIBRIL_RMUTEX_INITIALIZE(interface_mutex);
     102static fibril_rmutex_t interface_mutex;
    103103static hash_table_t interface_hash_table;
    104104
     
    292292void __async_ports_init(void)
    293293{
     294        if (fibril_rmutex_initialize(&interface_mutex) != EOK)
     295                abort();
     296
    294297        if (!hash_table_create(&interface_hash_table, 0, 0,
    295298            &interface_hash_table_ops))
    296299                abort();
    297300}
     301
     302void __async_ports_fini(void)
     303{
     304        fibril_rmutex_destroy(&interface_mutex);
     305}
  • uspace/lib/c/generic/async/server.c

    r3ce781f4 raaa3c457  
    216216}
    217217
    218 static FIBRIL_RMUTEX_INITIALIZE(client_mutex);
     218static fibril_rmutex_t client_mutex;
    219219static hash_table_t client_hash_table;
    220220
    221221// TODO: lockfree notification_queue?
    222 static FIBRIL_RMUTEX_INITIALIZE(notification_mutex);
     222static fibril_rmutex_t notification_mutex;
    223223static hash_table_t notification_hash_table;
    224224static LIST_INITIALIZE(notification_queue);
     
    10131013void __async_server_init(void)
    10141014{
     1015        if (fibril_rmutex_initialize(&client_mutex) != EOK)
     1016                abort();
     1017        if (fibril_rmutex_initialize(&notification_mutex) != EOK)
     1018                abort();
     1019
    10151020        if (!hash_table_create(&client_hash_table, 0, 0, &client_hash_table_ops))
    10161021                abort();
     
    10211026
    10221027        async_create_manager();
     1028}
     1029
     1030void __async_server_fini(void)
     1031{
     1032        fibril_rmutex_destroy(&client_mutex);
     1033        fibril_rmutex_destroy(&notification_mutex);
    10231034}
    10241035
  • uspace/lib/c/generic/io/kio.c

    r3ce781f4 raaa3c457  
    3838#include <str.h>
    3939#include <stdint.h>
     40#include <stdlib.h>
    4041#include <errno.h>
    4142#include <abi/kio.h>
     
    5354        char data[KIO_BUFFER_SIZE];
    5455        size_t used;
    55 } kio_buffer = { .futex = FUTEX_INITIALIZER, };
     56} kio_buffer;
     57
     58void __kio_init(void)
     59{
     60        if (futex_initialize(&kio_buffer.futex, 1) != EOK)
     61                abort();
     62}
     63
     64void __kio_fini(void)
     65{
     66        futex_destroy(&kio_buffer.futex);
     67}
    5668
    5769errno_t kio_write(const void *buf, size_t size, size_t *nwritten)
  • uspace/lib/c/generic/libc.c

    r3ce781f4 raaa3c457  
    4040#include <tls.h>
    4141#include <fibril.h>
     42#include <fibril_synch.h>
    4243#include <task.h>
    4344#include <loader/pcb.h>
    4445#include <vfs/vfs.h>
    4546#include <vfs/inbox.h>
     47#include <io/kio.h>
    4648#include "private/libc.h"
    4749#include "private/async.h"
     
    6163void __libc_main(void *pcb_ptr)
    6264{
     65        __kio_init();
     66
    6367        assert(!__tcb_is_set());
    6468
     
    8185
    8286        __fibrils_init();
     87        __fibril_synch_init();
    8388
    8489        /* Initialize the fibril. */
     
    148153}
    149154
     155void __libc_fini(void)
     156{
     157        __async_client_fini();
     158        __async_server_fini();
     159        __async_ports_fini();
     160
     161        __fibril_synch_fini();
     162        __fibrils_fini();
     163
     164        __malloc_fini();
     165
     166        __kio_fini();
     167}
     168
    150169void __libc_exit(int status)
    151170{
  • uspace/lib/c/generic/malloc.c

    r3ce781f4 raaa3c457  
    195195
    196196/** Futex for thread-safe heap manipulation */
    197 static FIBRIL_RMUTEX_INITIALIZE(malloc_mutex);
     197static fibril_rmutex_t malloc_mutex;
    198198
    199199#define malloc_assert(expr) safe_assert(expr)
     
    484484void __malloc_init(void)
    485485{
     486        if (fibril_rmutex_initialize(&malloc_mutex) != EOK)
     487                abort();
     488
    486489        if (!area_create(PAGE_SIZE))
    487490                abort();
     491}
     492
     493void __malloc_fini(void)
     494{
     495        fibril_rmutex_destroy(&malloc_mutex);
    488496}
    489497
  • uspace/lib/c/generic/private/async.h

    r3ce781f4 raaa3c457  
    9595
    9696extern void __async_server_init(void);
     97extern void __async_server_fini(void);
    9798extern void __async_client_init(void);
     99extern void __async_client_fini(void);
    98100extern void __async_ports_init(void);
     101extern void __async_ports_fini(void);
    99102
    100103extern errno_t async_create_port_internal(iface_t, async_port_handler_t,
  • uspace/lib/c/generic/private/fibril.h

    r3ce781f4 raaa3c457  
    7979
    8080extern void __fibrils_init(void);
     81extern void __fibrils_fini(void);
    8182
    8283extern void fibril_wait_for(fibril_event_t *);
     
    120121} fibril_rmutex_t;
    121122
    122 #define FIBRIL_RMUTEX_INITIALIZER(name) \
    123         { .futex = FUTEX_INITIALIZE(1) }
    124 
    125 #define FIBRIL_RMUTEX_INITIALIZE(name) \
    126         fibril_rmutex_t name = FIBRIL_RMUTEX_INITIALIZER(name)
    127 
    128 extern void fibril_rmutex_initialize(fibril_rmutex_t *);
     123extern errno_t fibril_rmutex_initialize(fibril_rmutex_t *);
     124extern void fibril_rmutex_destroy(fibril_rmutex_t *);
    129125extern void fibril_rmutex_lock(fibril_rmutex_t *);
    130126extern bool fibril_rmutex_trylock(fibril_rmutex_t *);
  • uspace/lib/c/generic/private/futex.h

    r3ce781f4 raaa3c457  
    4242#include <time.h>
    4343#include <fibril.h>
     44#include <abi/cap.h>
     45#include <abi/synch.h>
    4446
    4547typedef struct futex {
    4648        volatile atomic_int val;
     49        volatile cap_waitq_handle_t whandle;
     50
    4751#ifdef CONFIG_DEBUG_FUTEX
    4852        _Atomic(fibril_t *) owner;
     
    5054} futex_t;
    5155
    52 extern void futex_initialize(futex_t *futex, int value);
     56extern errno_t futex_initialize(futex_t *futex, int value);
     57
     58static inline errno_t futex_destroy(futex_t *futex)
     59{
     60        if (futex->whandle) {
     61                errno_t rc;
     62                rc = __SYSCALL1(SYS_WAITQ_DESTROY, (sysarg_t) futex->whandle);
     63                futex->whandle = CAP_NIL;
     64                return rc;
     65        }
     66        return EOK;
     67}
    5368
    5469#ifdef CONFIG_DEBUG_FUTEX
    55 
    56 #define FUTEX_INITIALIZE(val) { (val) , NULL }
    57 #define FUTEX_INITIALIZER     FUTEX_INITIALIZE(1)
    5870
    5971void __futex_assert_is_locked(futex_t *, const char *);
     
    7486#else
    7587
    76 #define FUTEX_INITIALIZE(val) { (val) }
    77 #define FUTEX_INITIALIZER     FUTEX_INITIALIZE(1)
    78 
    7988#define futex_lock(fut)     (void) futex_down((fut))
    8089#define futex_trylock(fut)  futex_trydown((fut))
     
    8695
    8796#endif
     97
     98static inline errno_t futex_allocate_waitq(futex_t *futex)
     99{
     100        return __SYSCALL1(SYS_WAITQ_CREATE, (sysarg_t) &futex->whandle);
     101}
    88102
    89103/** Down the futex with timeout, composably.
     
    107121{
    108122        // TODO: Add tests for this.
     123
     124        assert(futex->whandle != CAP_NIL);
    109125
    110126        if (atomic_fetch_sub_explicit(&futex->val, 1, memory_order_acquire) > 0)
     
    132148        }
    133149
    134         return __SYSCALL2(SYS_FUTEX_SLEEP, (sysarg_t) futex, (sysarg_t) timeout);
     150        return __SYSCALL3(SYS_WAITQ_SLEEP, (sysarg_t) futex->whandle,
     151            (sysarg_t) timeout, (sysarg_t) SYNCH_FLAGS_FUTEX);
    135152}
    136153
     
    147164{
    148165        if (atomic_fetch_add_explicit(&futex->val, 1, memory_order_release) < 0)
    149                 return __SYSCALL1(SYS_FUTEX_WAKEUP, (sysarg_t) futex);
     166                return __SYSCALL1(SYS_WAITQ_WAKEUP, (sysarg_t) futex->whandle);
    150167
    151168        return EOK;
  • uspace/lib/c/generic/private/malloc.h

    r3ce781f4 raaa3c457  
    3737
    3838extern void __malloc_init(void);
     39extern void __malloc_fini(void);
    3940
    4041#endif
  • uspace/lib/c/generic/thread/fibril.c

    r3ce781f4 raaa3c457  
    8787
    8888/* This futex serializes access to global data. */
    89 static futex_t fibril_futex = FUTEX_INITIALIZER;
     89static futex_t fibril_futex;
    9090static futex_t ready_semaphore;
    9191static long ready_st_count;
     
    9595static LIST_INITIALIZE(timeout_list);
    9696
    97 static futex_t ipc_lists_futex = FUTEX_INITIALIZER;
     97static futex_t ipc_lists_futex;
    9898static LIST_INITIALIZE(ipc_waiter_list);
    9999static LIST_INITIALIZE(ipc_buffer_list);
     
    796796        if (!multithreaded) {
    797797                _ready_debug_check();
    798                 futex_initialize(&ready_semaphore, ready_st_count);
     798                if (futex_initialize(&ready_semaphore, ready_st_count) != EOK)
     799                        abort();
    799800                multithreaded = true;
    800801        }
     
    861862void __fibrils_init(void)
    862863{
     864        if (futex_initialize(&fibril_futex, 1) != EOK)
     865                abort();
     866        if (futex_initialize(&ipc_lists_futex, 1) != EOK)
     867                abort();
     868
    863869        /*
    864870         * We allow a fixed, small amount of parallelism for IPC reads, but
     
    876882}
    877883
     884void __fibrils_fini(void)
     885{
     886        futex_destroy(&fibril_futex);
     887        futex_destroy(&ipc_lists_futex);
     888}
     889
    878890void fibril_usleep(usec_t timeout)
    879891{
  • uspace/lib/c/generic/thread/fibril_synch.c

    r3ce781f4 raaa3c457  
    5151#include "../private/futex.h"
    5252
    53 void fibril_rmutex_initialize(fibril_rmutex_t *m)
    54 {
    55         futex_initialize(&m->futex, 1);
     53errno_t fibril_rmutex_initialize(fibril_rmutex_t *m)
     54{
     55        return futex_initialize(&m->futex, 1);
     56}
     57
     58void fibril_rmutex_destroy(fibril_rmutex_t *m)
     59{
     60        futex_destroy(&m->futex);
    5661}
    5762
     
    8590static fibril_local bool deadlocked = false;
    8691
    87 static futex_t fibril_synch_futex = FUTEX_INITIALIZER;
     92static futex_t fibril_synch_futex;
     93
     94void __fibril_synch_init(void)
     95{
     96        if (futex_initialize(&fibril_synch_futex, 1) != EOK)
     97                abort();
     98}
     99
     100void __fibril_synch_fini(void)
     101{
     102        futex_destroy(&fibril_synch_futex);
     103}
    88104
    89105typedef struct {
  • uspace/lib/c/generic/thread/futex.c

    r3ce781f4 raaa3c457  
    4949 * @param val   Initialization value.
    5050 *
     51 * @return      Error code.
    5152 */
    52 void futex_initialize(futex_t *futex, int val)
     53errno_t futex_initialize(futex_t *futex, int val)
    5354{
    5455        atomic_store_explicit(&futex->val, val, memory_order_relaxed);
     56        futex->whandle = CAP_NIL;
     57        return futex_allocate_waitq(futex);
    5558}
    5659
  • uspace/lib/c/generic/thread/mpsc.c

    r3ce781f4 raaa3c457  
    8080        }
    8181
     82        if (fibril_rmutex_initialize(&q->t_lock) != EOK) {
     83                free(q);
     84                free(n);
     85                free(c);
     86                return NULL;
     87        }
     88
    8289        q->elem_size = elem_size;
    83         fibril_rmutex_initialize(&q->t_lock);
    8490        q->head = q->tail = n;
    8591        q->close_node = c;
     
    97103        }
    98104
    99         // TODO: fibril_rmutex_destroy()
     105        fibril_rmutex_destroy(&q->t_lock);
    100106
    101107        free(q);
  • uspace/lib/c/include/fibril_synch.h

    r3ce781f4 raaa3c457  
    164164        fibril_semaphore_t name = FIBRIL_SEMAPHORE_INITIALIZER(name, cnt)
    165165
     166extern void __fibril_synch_init(void);
     167extern void __fibril_synch_fini(void);
     168
    166169extern void fibril_mutex_initialize(fibril_mutex_t *);
    167170extern void fibril_mutex_lock(fibril_mutex_t *);
  • uspace/lib/c/include/io/kio.h

    r3ce781f4 raaa3c457  
    4242#include <_bits/size_t.h>
    4343
     44extern void __kio_init(void);
     45extern void __kio_fini(void);
    4446extern errno_t kio_write(const void *, size_t, size_t *);
    4547extern void kio_update(void);
  • uspace/lib/c/include/libc.h

    r3ce781f4 raaa3c457  
    6262        __syscall6(p1, p2, p3, p4, p5, p6, id)
    6363
     64extern void __libc_fini(void);
     65
    6466#endif
    6567
  • uspace/srv/loader/main.c

    r3ce781f4 raaa3c457  
    5959#include <vfs/vfs.h>
    6060#include <vfs/inbox.h>
     61#include <libc.h>
    6162
    6263#ifdef CONFIG_RTLD
     
    357358        DPRINTF("Jump to entry point at %p\n", pcb.entry);
    358359
     360        __libc_fini();
    359361        __tcb_reset();
    360362        entry_point_jmp(prog_info.finfo.entry, &pcb);
Note: See TracChangeset for help on using the changeset viewer.