source: trunk/kernel/kern/kthread_create.c @ 41

Last change on this file since 41 was 1, checked in by alain, 8 years ago

First import

File size: 2.7 KB
RevLine 
[1]1/*
2 * kern/kthread_create.c - kernel-level threads creation
3 *
4 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
5 * Copyright (c) 2011,2012,2013,2014,2015 UPMC Sorbonne Universites
6 *
7 * This file is part of ALMOS-kernel.
8 *
9 * ALMOS-kernel is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2.0 of the License.
12 *
13 * ALMOS-kernel is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with ALMOS-kernel; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include <kmem.h>
24#include <cpu.h>
25#include <thread.h>
26#include <process.h>
27#include <list.h>
28#include <ppm.h>
29#include <pmm.h>
30#include <signal.h>
31#include <scheduler.h>
32#include <spinlock.h>
33#include <cluster.h>
34
35////////////////////////////////
36static void kthread_exit( void )
37{
38        thread_t * this = CURRENT_THREAD;
39       
40        thread_dmsg( 1, "Kernel Thread %x on CPU %d has finished\n",
41                     this, current_cpu->gid );
42       
43        sys_thread_exit(0); //sched_exit(this);
44       
45        PANIC ("Thread %x, CPU %d must never return", this, current_cpu->gid);
46}
47
48void thread_init(thread_t *thread);
49
50struct thread_s* kthread_create(struct process_s *process, kthread_t *kfunc, void *arg, uint_t cpu_lid)
51{
52        kmem_req_t req;
53        register struct page_s *page;
54        register thread_t *thread;
55 
56        req.type  = KMEM_PAGE;
57        req.size  = ARCH_THREAD_PAGE_ORDER;
58        req.flags = AF_KERNEL | AF_ZERO | AF_REMOTE;
59        //req.ptr   = clusters_tbl[cid].cluster; 
60        req.ptr   = current_cluster; 
61        page      = kmem_alloc(&req);
62 
63        if(page == NULL) return NULL;
64
65        thread = ppm_page2addr(page);
66
67        thread_init(thread);
68
69        //thread_set_current_cpu(thread, &clusters_tbl[cid].cluster->cpu_tbl[cpu_lid]);
70        thread_set_current_cpu(thread, &current_cluster->cpu_tbl[cpu_lid]);
71        thread->ecid            = current_cluster->id;
72        thread->egid            = current_cluster->cpu_tbl[cpu_lid].gid;
73        sched_setpolicy(thread, SCHED_RR);
74       
75        thread->process                 = process;
76        thread->type                 = KTHREAD;
77        thread->state                = S_KERNEL;
78        thread->info.sig_mask        = SIG_DEFAULT_MASK;
79        thread->info.attr.entry_func = (void*)kfunc;
80        thread->info.attr.exit_func  = (void*)kthread_exit;
81        thread->info.attr.arg1       = arg;
82        thread->info.attr.tid        = (uint_t) thread;
83        thread->info.attr.pid        = process->pid;
84        thread->info.page            = page;
85 
86        cpu_context_init(&thread->pws, thread);
87        return thread;
88}
Note: See TracBrowser for help on using the repository browser.