Changeset aaa3c457 in mainline
- Timestamp:
- 2018-11-12T10:36:10Z (6 years ago)
- 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)
- Files:
-
- 1 added
- 1 deleted
- 29 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
abi/include/abi/cap.h
r3ce781f4 raaa3c457 52 52 } *cap_irq_handle_t; 53 53 54 typedef struct { 55 } *cap_waitq_handle_t; 56 54 57 #endif 55 58 -
abi/include/abi/syscall.h
r3ce781f4 raaa3c457 51 51 SYS_PROGRAM_SPAWN_LOADER, 52 52 53 SYS_FUTEX_SLEEP, 54 SYS_FUTEX_WAKEUP, 53 SYS_WAITQ_CREATE, 54 SYS_WAITQ_SLEEP, 55 SYS_WAITQ_WAKEUP, 56 SYS_WAITQ_DESTROY, 55 57 SYS_SMC_COHERENCE, 56 58 -
kernel/Makefile
r3ce781f4 raaa3c457 227 227 generic/src/synch/smc.c \ 228 228 generic/src/synch/waitq.c \ 229 generic/src/synch/ futex.c \229 generic/src/synch/syswaitq.c \ 230 230 generic/src/smp/ipi.c \ 231 231 generic/src/smp/smp.c \ -
kernel/generic/include/cap/cap.h
r3ce781f4 raaa3c457 55 55 KOBJECT_TYPE_IRQ, 56 56 KOBJECT_TYPE_PHONE, 57 KOBJECT_TYPE_WAITQ, 57 58 KOBJECT_TYPE_MAX 58 59 } kobject_type_t; … … 63 64 struct irq; 64 65 struct phone; 66 struct waitq; 65 67 66 68 typedef struct kobject_ops { … … 88 90 struct irq *irq; 89 91 struct phone *phone; 92 struct waitq *waitq; 90 93 }; 91 94 } kobject_t; -
kernel/generic/include/proc/task.h
r3ce781f4 raaa3c457 42 42 #include <synch/spinlock.h> 43 43 #include <synch/mutex.h> 44 #include <synch/futex.h>45 44 #include <adt/list.h> 46 45 #include <adt/odict.h> … … 128 127 task_arch_t arch; 129 128 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 135 129 /** Accumulated accounting. */ 136 130 uint64_t ucycles; -
kernel/generic/include/synch/syswaitq.h
r3ce781f4 raaa3c457 1 1 /* 2 * Copyright (c) 20 06Jakub Jermar2 * Copyright (c) 2018 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 33 33 */ 34 34 35 #ifndef KERN_ FUTEX_H_36 #define KERN_ FUTEX_H_35 #ifndef KERN_SYS_WAITQ_H_ 36 #define KERN_SYS_WAITQ_H_ 37 37 38 38 #include <typedefs.h> 39 #include <synch/waitq.h> 40 #include <adt/hash_table.h> 39 #include <abi/cap.h> 41 40 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; 41 extern void sys_waitq_init(void); 53 42 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); 43 extern void sys_waitq_task_cleanup(void); 57 44 58 extern void futex_task_cleanup(void); 59 extern void futex_task_init(struct task *); 45 extern sys_errno_t sys_waitq_create(cap_waitq_handle_t *); 46 extern sys_errno_t sys_waitq_sleep(cap_waitq_handle_t, uint32_t, unsigned int); 47 extern sys_errno_t sys_waitq_wakeup(cap_waitq_handle_t); 48 extern sys_errno_t sys_waitq_destroy(cap_waitq_handle_t); 60 49 61 50 #endif -
kernel/generic/include/synch/waitq.h
r3ce781f4 raaa3c457 49 49 * 50 50 */ 51 typedef struct {51 typedef struct waitq { 52 52 /** Lock protecting wait queue structure. 53 53 * -
kernel/generic/src/main/main.c
r3ce781f4 raaa3c457 77 77 #include <mm/reserve.h> 78 78 #include <synch/waitq.h> 79 #include <synch/ futex.h>79 #include <synch/syswaitq.h> 80 80 #include <arch/arch.h> 81 81 #include <arch.h> … … 278 278 task_init(); 279 279 thread_init(); 280 futex_init();280 sys_waitq_init(); 281 281 282 282 sysinfo_set_item_data("boot_args", NULL, bargs, str_size(bargs) + 1); -
kernel/generic/src/proc/task.c
r3ce781f4 raaa3c457 43 43 #include <mm/slab.h> 44 44 #include <atomic.h> 45 #include <synch/futex.h>46 45 #include <synch/spinlock.h> 47 46 #include <synch/waitq.h> … … 251 250 } 252 251 253 futex_task_init(task);254 255 252 irq_spinlock_lock(&tasks_lock, true); 256 253 -
kernel/generic/src/proc/thread.c
r3ce781f4 raaa3c457 48 48 #include <synch/spinlock.h> 49 49 #include <synch/waitq.h> 50 #include <synch/syswaitq.h> 50 51 #include <cpu.h> 51 52 #include <str.h> … … 519 520 */ 520 521 ipc_cleanup(); 521 futex_task_cleanup();522 sys_waitq_task_cleanup(); 522 523 LOG("Cleanup of task %" PRIu64 " completed.", TASK->taskid); 523 524 } -
kernel/generic/src/syscall/syscall.c
r3ce781f4 raaa3c457 46 46 #include <interrupt.h> 47 47 #include <ipc/sysipc.h> 48 #include <synch/futex.h>49 48 #include <synch/smc.h> 49 #include <synch/syswaitq.h> 50 50 #include <ddi/ddi.h> 51 51 #include <ipc/event.h> … … 136 136 137 137 /* 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, 140 142 [SYS_SMC_COHERENCE] = (syshandler_t) sys_smc_coherence, 141 143 -
uspace/app/trace/syscalls.c
r3ce781f4 raaa3c457 46 46 [SYS_TASK_GET_ID] = { "task_get_id", 1, V_ERRNO }, 47 47 [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 },50 48 51 49 [SYS_AS_AREA_CREATE] = { "as_area_create", 5, V_ERRNO }, -
uspace/lib/c/generic/async/client.c
r3ce781f4 raaa3c457 122 122 #include "../private/fibril.h" 123 123 124 static FIBRIL_RMUTEX_INITIALIZE(message_mutex);124 static fibril_rmutex_t message_mutex; 125 125 126 126 /** Naming service session */ … … 173 173 void __async_client_init(void) 174 174 { 175 if (fibril_rmutex_initialize(&message_mutex) != EOK) 176 abort(); 177 175 178 session_ns.iface = 0; 176 179 session_ns.mgmt = EXCHANGE_ATOMIC; … … 186 189 fibril_mutex_initialize(&session_ns.mutex); 187 190 session_ns.exchanges = 0; 191 } 192 193 void __async_client_fini(void) 194 { 195 fibril_rmutex_destroy(&message_mutex); 188 196 } 189 197 -
uspace/lib/c/generic/async/ports.c
r3ce781f4 raaa3c457 100 100 101 101 /** Futex guarding the interface hash table. */ 102 static FIBRIL_RMUTEX_INITIALIZE(interface_mutex);102 static fibril_rmutex_t interface_mutex; 103 103 static hash_table_t interface_hash_table; 104 104 … … 292 292 void __async_ports_init(void) 293 293 { 294 if (fibril_rmutex_initialize(&interface_mutex) != EOK) 295 abort(); 296 294 297 if (!hash_table_create(&interface_hash_table, 0, 0, 295 298 &interface_hash_table_ops)) 296 299 abort(); 297 300 } 301 302 void __async_ports_fini(void) 303 { 304 fibril_rmutex_destroy(&interface_mutex); 305 } -
uspace/lib/c/generic/async/server.c
r3ce781f4 raaa3c457 216 216 } 217 217 218 static FIBRIL_RMUTEX_INITIALIZE(client_mutex);218 static fibril_rmutex_t client_mutex; 219 219 static hash_table_t client_hash_table; 220 220 221 221 // TODO: lockfree notification_queue? 222 static FIBRIL_RMUTEX_INITIALIZE(notification_mutex);222 static fibril_rmutex_t notification_mutex; 223 223 static hash_table_t notification_hash_table; 224 224 static LIST_INITIALIZE(notification_queue); … … 1013 1013 void __async_server_init(void) 1014 1014 { 1015 if (fibril_rmutex_initialize(&client_mutex) != EOK) 1016 abort(); 1017 if (fibril_rmutex_initialize(¬ification_mutex) != EOK) 1018 abort(); 1019 1015 1020 if (!hash_table_create(&client_hash_table, 0, 0, &client_hash_table_ops)) 1016 1021 abort(); … … 1021 1026 1022 1027 async_create_manager(); 1028 } 1029 1030 void __async_server_fini(void) 1031 { 1032 fibril_rmutex_destroy(&client_mutex); 1033 fibril_rmutex_destroy(¬ification_mutex); 1023 1034 } 1024 1035 -
uspace/lib/c/generic/io/kio.c
r3ce781f4 raaa3c457 38 38 #include <str.h> 39 39 #include <stdint.h> 40 #include <stdlib.h> 40 41 #include <errno.h> 41 42 #include <abi/kio.h> … … 53 54 char data[KIO_BUFFER_SIZE]; 54 55 size_t used; 55 } kio_buffer = { .futex = FUTEX_INITIALIZER, }; 56 } kio_buffer; 57 58 void __kio_init(void) 59 { 60 if (futex_initialize(&kio_buffer.futex, 1) != EOK) 61 abort(); 62 } 63 64 void __kio_fini(void) 65 { 66 futex_destroy(&kio_buffer.futex); 67 } 56 68 57 69 errno_t kio_write(const void *buf, size_t size, size_t *nwritten) -
uspace/lib/c/generic/libc.c
r3ce781f4 raaa3c457 40 40 #include <tls.h> 41 41 #include <fibril.h> 42 #include <fibril_synch.h> 42 43 #include <task.h> 43 44 #include <loader/pcb.h> 44 45 #include <vfs/vfs.h> 45 46 #include <vfs/inbox.h> 47 #include <io/kio.h> 46 48 #include "private/libc.h" 47 49 #include "private/async.h" … … 61 63 void __libc_main(void *pcb_ptr) 62 64 { 65 __kio_init(); 66 63 67 assert(!__tcb_is_set()); 64 68 … … 81 85 82 86 __fibrils_init(); 87 __fibril_synch_init(); 83 88 84 89 /* Initialize the fibril. */ … … 148 153 } 149 154 155 void __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 150 169 void __libc_exit(int status) 151 170 { -
uspace/lib/c/generic/malloc.c
r3ce781f4 raaa3c457 195 195 196 196 /** Futex for thread-safe heap manipulation */ 197 static FIBRIL_RMUTEX_INITIALIZE(malloc_mutex);197 static fibril_rmutex_t malloc_mutex; 198 198 199 199 #define malloc_assert(expr) safe_assert(expr) … … 484 484 void __malloc_init(void) 485 485 { 486 if (fibril_rmutex_initialize(&malloc_mutex) != EOK) 487 abort(); 488 486 489 if (!area_create(PAGE_SIZE)) 487 490 abort(); 491 } 492 493 void __malloc_fini(void) 494 { 495 fibril_rmutex_destroy(&malloc_mutex); 488 496 } 489 497 -
uspace/lib/c/generic/private/async.h
r3ce781f4 raaa3c457 95 95 96 96 extern void __async_server_init(void); 97 extern void __async_server_fini(void); 97 98 extern void __async_client_init(void); 99 extern void __async_client_fini(void); 98 100 extern void __async_ports_init(void); 101 extern void __async_ports_fini(void); 99 102 100 103 extern errno_t async_create_port_internal(iface_t, async_port_handler_t, -
uspace/lib/c/generic/private/fibril.h
r3ce781f4 raaa3c457 79 79 80 80 extern void __fibrils_init(void); 81 extern void __fibrils_fini(void); 81 82 82 83 extern void fibril_wait_for(fibril_event_t *); … … 120 121 } fibril_rmutex_t; 121 122 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 *); 123 extern errno_t fibril_rmutex_initialize(fibril_rmutex_t *); 124 extern void fibril_rmutex_destroy(fibril_rmutex_t *); 129 125 extern void fibril_rmutex_lock(fibril_rmutex_t *); 130 126 extern bool fibril_rmutex_trylock(fibril_rmutex_t *); -
uspace/lib/c/generic/private/futex.h
r3ce781f4 raaa3c457 42 42 #include <time.h> 43 43 #include <fibril.h> 44 #include <abi/cap.h> 45 #include <abi/synch.h> 44 46 45 47 typedef struct futex { 46 48 volatile atomic_int val; 49 volatile cap_waitq_handle_t whandle; 50 47 51 #ifdef CONFIG_DEBUG_FUTEX 48 52 _Atomic(fibril_t *) owner; … … 50 54 } futex_t; 51 55 52 extern void futex_initialize(futex_t *futex, int value); 56 extern errno_t futex_initialize(futex_t *futex, int value); 57 58 static 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 } 53 68 54 69 #ifdef CONFIG_DEBUG_FUTEX 55 56 #define FUTEX_INITIALIZE(val) { (val) , NULL }57 #define FUTEX_INITIALIZER FUTEX_INITIALIZE(1)58 70 59 71 void __futex_assert_is_locked(futex_t *, const char *); … … 74 86 #else 75 87 76 #define FUTEX_INITIALIZE(val) { (val) }77 #define FUTEX_INITIALIZER FUTEX_INITIALIZE(1)78 79 88 #define futex_lock(fut) (void) futex_down((fut)) 80 89 #define futex_trylock(fut) futex_trydown((fut)) … … 86 95 87 96 #endif 97 98 static inline errno_t futex_allocate_waitq(futex_t *futex) 99 { 100 return __SYSCALL1(SYS_WAITQ_CREATE, (sysarg_t) &futex->whandle); 101 } 88 102 89 103 /** Down the futex with timeout, composably. … … 107 121 { 108 122 // TODO: Add tests for this. 123 124 assert(futex->whandle != CAP_NIL); 109 125 110 126 if (atomic_fetch_sub_explicit(&futex->val, 1, memory_order_acquire) > 0) … … 132 148 } 133 149 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); 135 152 } 136 153 … … 147 164 { 148 165 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); 150 167 151 168 return EOK; -
uspace/lib/c/generic/private/malloc.h
r3ce781f4 raaa3c457 37 37 38 38 extern void __malloc_init(void); 39 extern void __malloc_fini(void); 39 40 40 41 #endif -
uspace/lib/c/generic/thread/fibril.c
r3ce781f4 raaa3c457 87 87 88 88 /* This futex serializes access to global data. */ 89 static futex_t fibril_futex = FUTEX_INITIALIZER;89 static futex_t fibril_futex; 90 90 static futex_t ready_semaphore; 91 91 static long ready_st_count; … … 95 95 static LIST_INITIALIZE(timeout_list); 96 96 97 static futex_t ipc_lists_futex = FUTEX_INITIALIZER;97 static futex_t ipc_lists_futex; 98 98 static LIST_INITIALIZE(ipc_waiter_list); 99 99 static LIST_INITIALIZE(ipc_buffer_list); … … 796 796 if (!multithreaded) { 797 797 _ready_debug_check(); 798 futex_initialize(&ready_semaphore, ready_st_count); 798 if (futex_initialize(&ready_semaphore, ready_st_count) != EOK) 799 abort(); 799 800 multithreaded = true; 800 801 } … … 861 862 void __fibrils_init(void) 862 863 { 864 if (futex_initialize(&fibril_futex, 1) != EOK) 865 abort(); 866 if (futex_initialize(&ipc_lists_futex, 1) != EOK) 867 abort(); 868 863 869 /* 864 870 * We allow a fixed, small amount of parallelism for IPC reads, but … … 876 882 } 877 883 884 void __fibrils_fini(void) 885 { 886 futex_destroy(&fibril_futex); 887 futex_destroy(&ipc_lists_futex); 888 } 889 878 890 void fibril_usleep(usec_t timeout) 879 891 { -
uspace/lib/c/generic/thread/fibril_synch.c
r3ce781f4 raaa3c457 51 51 #include "../private/futex.h" 52 52 53 void fibril_rmutex_initialize(fibril_rmutex_t *m) 54 { 55 futex_initialize(&m->futex, 1); 53 errno_t fibril_rmutex_initialize(fibril_rmutex_t *m) 54 { 55 return futex_initialize(&m->futex, 1); 56 } 57 58 void fibril_rmutex_destroy(fibril_rmutex_t *m) 59 { 60 futex_destroy(&m->futex); 56 61 } 57 62 … … 85 90 static fibril_local bool deadlocked = false; 86 91 87 static futex_t fibril_synch_futex = FUTEX_INITIALIZER; 92 static futex_t fibril_synch_futex; 93 94 void __fibril_synch_init(void) 95 { 96 if (futex_initialize(&fibril_synch_futex, 1) != EOK) 97 abort(); 98 } 99 100 void __fibril_synch_fini(void) 101 { 102 futex_destroy(&fibril_synch_futex); 103 } 88 104 89 105 typedef struct { -
uspace/lib/c/generic/thread/futex.c
r3ce781f4 raaa3c457 49 49 * @param val Initialization value. 50 50 * 51 * @return Error code. 51 52 */ 52 voidfutex_initialize(futex_t *futex, int val)53 errno_t futex_initialize(futex_t *futex, int val) 53 54 { 54 55 atomic_store_explicit(&futex->val, val, memory_order_relaxed); 56 futex->whandle = CAP_NIL; 57 return futex_allocate_waitq(futex); 55 58 } 56 59 -
uspace/lib/c/generic/thread/mpsc.c
r3ce781f4 raaa3c457 80 80 } 81 81 82 if (fibril_rmutex_initialize(&q->t_lock) != EOK) { 83 free(q); 84 free(n); 85 free(c); 86 return NULL; 87 } 88 82 89 q->elem_size = elem_size; 83 fibril_rmutex_initialize(&q->t_lock);84 90 q->head = q->tail = n; 85 91 q->close_node = c; … … 97 103 } 98 104 99 // TODO: fibril_rmutex_destroy()105 fibril_rmutex_destroy(&q->t_lock); 100 106 101 107 free(q); -
uspace/lib/c/include/fibril_synch.h
r3ce781f4 raaa3c457 164 164 fibril_semaphore_t name = FIBRIL_SEMAPHORE_INITIALIZER(name, cnt) 165 165 166 extern void __fibril_synch_init(void); 167 extern void __fibril_synch_fini(void); 168 166 169 extern void fibril_mutex_initialize(fibril_mutex_t *); 167 170 extern void fibril_mutex_lock(fibril_mutex_t *); -
uspace/lib/c/include/io/kio.h
r3ce781f4 raaa3c457 42 42 #include <_bits/size_t.h> 43 43 44 extern void __kio_init(void); 45 extern void __kio_fini(void); 44 46 extern errno_t kio_write(const void *, size_t, size_t *); 45 47 extern void kio_update(void); -
uspace/lib/c/include/libc.h
r3ce781f4 raaa3c457 62 62 __syscall6(p1, p2, p3, p4, p5, p6, id) 63 63 64 extern void __libc_fini(void); 65 64 66 #endif 65 67 -
uspace/srv/loader/main.c
r3ce781f4 raaa3c457 59 59 #include <vfs/vfs.h> 60 60 #include <vfs/inbox.h> 61 #include <libc.h> 61 62 62 63 #ifdef CONFIG_RTLD … … 357 358 DPRINTF("Jump to entry point at %p\n", pcb.entry); 358 359 360 __libc_fini(); 359 361 __tcb_reset(); 360 362 entry_point_jmp(prog_info.finfo.entry, &pcb);
Note:
See TracChangeset
for help on using the changeset viewer.