Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2041 → Rev 2042

/trunk/kernel/generic/include/proc/thread.h
148,6 → 148,7
uint64_t cycles; /**< Thread accounting. */
uint64_t last_cycle; /**< Last sampled cycle. */
bool uncounted; /**< Thread doesn't affect accumulated accounting. */
 
int priority; /**< Thread's priority. Implemented as index to CPU->rq */
uint32_t tid; /**< Thread ID. */
168,7 → 169,7
extern btree_t threads_btree; /**< B+tree containing all threads. */
 
extern void thread_init(void);
extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags, char *name);
extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags, char *name, bool uncounted);
extern void thread_ready(thread_t *t);
extern void thread_exit(void) __attribute__((noreturn));
 
/trunk/kernel/generic/src/main/kinit.c
98,7 → 98,7
* not mess together with kcpulb threads.
* Just a beautification.
*/
if ((t = thread_create(kmp, NULL, TASK, THREAD_FLAG_WIRED, "kmp"))) {
if ((t = thread_create(kmp, NULL, TASK, THREAD_FLAG_WIRED, "kmp", true))) {
spinlock_lock(&t->lock);
t->cpu = &cpus[0];
spinlock_unlock(&t->lock);
123,7 → 123,7
*/
for (i = 0; i < config.cpu_count; i++) {
 
if ((t = thread_create(kcpulb, NULL, TASK, THREAD_FLAG_WIRED, "kcpulb"))) {
if ((t = thread_create(kcpulb, NULL, TASK, THREAD_FLAG_WIRED, "kcpulb", true))) {
spinlock_lock(&t->lock);
t->cpu = &cpus[i];
spinlock_unlock(&t->lock);
143,7 → 143,7
/*
* Create kernel console.
*/
if ((t = thread_create(kconsole, "kconsole", TASK, 0, "kconsole")))
if ((t = thread_create(kconsole, "kconsole", TASK, 0, "kconsole", false)))
thread_ready(t);
else
panic("thread_create/kconsole\n");
/trunk/kernel/generic/src/main/main.c
266,7 → 266,7
/*
* Create the first thread.
*/
t = thread_create(kinit, NULL, k, 0, "kinit");
t = thread_create(kinit, NULL, k, 0, "kinit", true);
if (!t)
panic("can't create kinit thread\n");
thread_ready(t);
/trunk/kernel/generic/src/console/cmd.c
56,7 → 56,6
#include <cpu.h>
#include <mm/tlb.h>
#include <arch/mm/tlb.h>
#include <mm/as.h>
#include <mm/frame.h>
#include <main/version.h>
#include <mm/slab.h>
859,9 → 858,9
return 1;
}
 
static void test_wrapper(void *arg)
static bool run_test(const test_t *test)
{
test_t *test = (test_t *) arg;
printf("%s\t\t%s\n", test->name, test->desc);
/* Update and read thread accounting
for benchmarking */
885,41 → 884,13
if (ret == NULL) {
printf("Test passed\n");
// return true;
return;
return true;
}
 
printf("%s\n", ret);
// return false;
return false;
}
 
static bool run_test(const test_t *test)
{
printf("%s\t\t%s\n", test->name, test->desc);
/* Create separate task and thread
for the test */
task_t *ta = task_create(AS_KERNEL, "test");
if (ta == NULL) {
printf("Unable to create test task\n");
return false;
}
thread_t *t = thread_create(test_wrapper, (void *) test, ta, 0, "test_main");
if (t == NULL) {
printf("Unable to create test main thread\n");
task_destroy(ta);
return false;
}
/* Run the test */
thread_ready(t);
thread_join(t);
thread_detach(t);
return true;
}
 
/** Command for returning kernel tests
*
* @param argv Argument vector.
/trunk/kernel/generic/src/proc/task.c
220,13 → 220,13
/*
* Create the main thread.
*/
t1 = thread_create(uinit, kernel_uarg, task, THREAD_FLAG_USPACE, "uinit");
t1 = thread_create(uinit, kernel_uarg, task, THREAD_FLAG_USPACE, "uinit", false);
ASSERT(t1);
/*
* Create killer thread for the new task.
*/
t2 = thread_create(ktaskgc, t1, task, 0, "ktaskgc");
t2 = thread_create(ktaskgc, t1, task, 0, "ktaskgc", true);
ASSERT(t2);
thread_ready(t2);
 
285,11 → 285,12
thread_t *thr = list_get_instance(cur, thread_t, th_link);
spinlock_lock(&thr->lock);
if (thr == THREAD) /* Update accounting of current thread */
thread_update_accounting();
ret += thr->cycles;
/* Process only counted threads */
if (!thr->uncounted) {
if (thr == THREAD) /* Update accounting of current thread */
thread_update_accounting();
ret += thr->cycles;
}
spinlock_unlock(&thr->lock);
}
328,7 → 329,7
btree_remove(&tasks_btree, ta->taskid, NULL);
spinlock_unlock(&tasks_lock);
t = thread_create(ktaskclnp, NULL, ta, 0, "ktaskclnp");
t = thread_create(ktaskclnp, NULL, ta, 0, "ktaskclnp", true);
spinlock_lock(&ta->lock);
ta->accept_new_threads = false;
/trunk/kernel/generic/src/proc/thread.c
123,15 → 123,18
ipl_t ipl = interrupts_disable();
spinlock_lock(&THREAD->lock);
thread_update_accounting();
uint64_t cycles = THREAD->cycles;
THREAD->cycles = 0;
spinlock_unlock(&THREAD->lock);
if (!THREAD->uncounted) {
thread_update_accounting();
uint64_t cycles = THREAD->cycles;
THREAD->cycles = 0;
spinlock_unlock(&THREAD->lock);
spinlock_lock(&TASK->lock);
TASK->cycles += cycles;
spinlock_unlock(&TASK->lock);
} else
spinlock_unlock(&THREAD->lock);
spinlock_lock(&TASK->lock);
TASK->cycles += cycles;
spinlock_unlock(&TASK->lock);
interrupts_restore(ipl);
thread_exit();
302,16 → 305,17
*
* Create a new thread.
*
* @param func Thread's implementing function.
* @param arg Thread's implementing function argument.
* @param task Task to which the thread belongs.
* @param flags Thread flags.
* @param name Symbolic name.
* @param func Thread's implementing function.
* @param arg Thread's implementing function argument.
* @param task Task to which the thread belongs.
* @param flags Thread flags.
* @param name Symbolic name.
* @param uncounted Thread's accounting doesn't affect accumulated task accounting.
*
* @return New thread's structure on success, NULL on failure.
*
*/
thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags, char *name)
thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags, char *name, bool uncounted)
{
thread_t *t;
ipl_t ipl;
344,6 → 348,7
t->thread_arg = arg;
t->ticks = -1;
t->cycles = 0;
t->uncounted = uncounted;
t->priority = -1; /* start in rq[0] */
t->cpu = NULL;
t->flags = flags;
649,7 → 654,7
return (unative_t) rc;
}
 
if ((t = thread_create(uinit, kernel_uarg, TASK, THREAD_FLAG_USPACE, namebuf))) {
if ((t = thread_create(uinit, kernel_uarg, TASK, THREAD_FLAG_USPACE, namebuf, false))) {
tid = t->tid;
thread_ready(t);
return (unative_t) tid;