Changeset b4d65c7 for src/libcfa/concurrency/kernel.c
- Timestamp:
- Feb 6, 2017, 4:19:53 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 424931d, fe26fbf
- Parents:
- c0aa336 (diff), 6a5f0e7 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
rc0aa336 rb4d65c7 15 15 // 16 16 17 //Start and stop routine for the kernel, declared first to make sure they run first 18 void kernel_startup(void) __attribute__((constructor(101))); 19 void kernel_shutdown(void) __attribute__((destructor(101))); 20 17 21 //Header 18 22 #include "kernel" … … 39 43 }; 40 44 41 DECL_COROUTINE(processorCtx_t) 45 DECL_COROUTINE(processorCtx_t); 42 46 43 47 #define KERNEL_STORAGE(T,X) static char X##_storage[sizeof(T)] … … 52 56 processor * systemProcessor; 53 57 thread * mainThread; 54 55 void kernel_startup(void) __attribute__((constructor(101)));56 void kernel_shutdown(void) __attribute__((destructor(101)));57 58 58 59 //----------------------------------------------------------------------------- … … 184 185 void main(processorCtx_t * ctx); 185 186 thread * nextThread(cluster * this); 186 void runThread(processor * this, thread * dst);187 void scheduleInternal(processor * this, thread * dst); 187 188 void spin(processor * this, unsigned int * spin_count); 188 189 … … 197 198 198 199 if(readyThread) { 199 runThread(this, readyThread);200 scheduleInternal(this, readyThread); 200 201 spin_count = 0; 201 202 } else { … … 209 210 } 210 211 211 void runThread(processor * this, thread * dst) { 212 //Declarations for scheduleInternal 213 extern void ThreadCtxSwitch(coroutine * src, coroutine * dst); 214 215 // scheduleInternal runs a thread by context switching 216 // from the processor coroutine to the target thread 217 void scheduleInternal(processor * this, thread * dst) { 218 // coroutine * proc_ctx = get_coroutine(this->ctx); 219 // coroutine * thrd_ctx = get_coroutine(dst); 220 221 // //Update global state 222 // this->current_thread = dst; 223 224 // // Context Switch to the thread 225 // ThreadCtxSwitch(proc_ctx, thrd_ctx); 226 // // when ThreadCtxSwitch returns we are back in the processor coroutine 227 212 228 coroutine * proc_ctx = get_coroutine(this->ctx); 213 229 coroutine * thrd_ctx = get_coroutine(dst); 214 thrd_ctx->last = proc_ctx; 215 216 // context switch to specified coroutine 217 // Which is now the current_coroutine 218 // LIB_DEBUG_PRINTF("Kernel : switching to ctx %p (from %p, current %p)\n", thrd_ctx, proc_ctx, current_coroutine); 219 this->current_thread = dst; 220 this->current_coroutine = thrd_ctx; 221 CtxSwitch( proc_ctx->stack.context, thrd_ctx->stack.context ); 222 this->current_coroutine = proc_ctx; 223 // LIB_DEBUG_PRINTF("Kernel : returned from ctx %p (to %p, current %p)\n", thrd_ctx, proc_ctx, current_coroutine); 224 225 // when CtxSwitch returns we are back in the processor coroutine 226 } 227 230 thrd_ctx->last = proc_ctx; 231 232 // context switch to specified coroutine 233 // Which is now the current_coroutine 234 LIB_DEBUG_PRINTF("Kernel : switching to ctx %p (from %p, current %p)\n", thrd_ctx, proc_ctx, this->current_coroutine); 235 this->current_thread = dst; 236 this->current_coroutine = thrd_ctx; 237 CtxSwitch( proc_ctx->stack.context, thrd_ctx->stack.context ); 238 this->current_coroutine = proc_ctx; 239 LIB_DEBUG_PRINTF("Kernel : returned from ctx %p (to %p, current %p)\n", thrd_ctx, proc_ctx, this->current_coroutine); 240 241 // when CtxSwitch returns we are back in the processor coroutine 242 } 243 244 // Handles spinning logic 245 // TODO : find some strategy to put cores to sleep after some time 228 246 void spin(processor * this, unsigned int * spin_count) { 229 247 (*spin_count)++; 230 248 } 231 249 250 // Context invoker for processors 251 // This is the entry point for processors (kernel threads) 252 // It effectively constructs a coroutine by stealing the pthread stack 232 253 void * CtxInvokeProcessor(void * arg) { 233 254 processor * proc = (processor *) arg; … … 241 262 processorCtx_t proc_cor_storage = { proc, &info }; 242 263 264 //Set global state 243 265 proc->current_coroutine = &proc->ctx->c; 244 266 proc->current_thread = NULL; 245 267 268 //We now have a proper context from which to schedule threads 246 269 LIB_DEBUG_PRINTF("Kernel : core %p created (%p)\n", proc, proc->ctx); 247 248 // LIB_DEBUG_PRINTF("Kernel : core base : %p \n", info.base );249 // LIB_DEBUG_PRINTF("Kernel : core storage : %p \n", info.storage );250 // LIB_DEBUG_PRINTF("Kernel : core size : %x \n", info.size );251 // LIB_DEBUG_PRINTF("Kernel : core limit : %p \n", info.limit );252 // LIB_DEBUG_PRINTF("Kernel : core context : %p \n", info.context );253 // LIB_DEBUG_PRINTF("Kernel : core top : %p \n", info.top );254 255 //We now have a proper context from which to schedule threads256 270 257 271 // SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't … … 264 278 proc_cor_storage.c.notHalted = false; 265 279 280 // Main routine of the core returned, the core is now fully terminated 266 281 LIB_DEBUG_PRINTF("Kernel : core %p main ended (%p)\n", proc, proc->ctx); 267 282
Note: See TracChangeset
for help on using the changeset viewer.