Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2041 → Rev 2042

/trunk/kernel/test/synch/rwlock2.c
66,7 → 66,7
rwlock_read_lock(&rwlock);
rwlock_read_lock(&rwlock);
thrd = thread_create(writer, NULL, TASK, 0, "writer");
thrd = thread_create(writer, NULL, TASK, 0, "writer", false);
if (thrd)
thread_ready(thrd);
else
/trunk/kernel/test/synch/rwlock3.c
64,7 → 64,7
rwlock_write_lock(&rwlock);
for (i = 0; i < 4; i++) {
thrd = thread_create(reader, NULL, TASK, 0, "reader");
thrd = thread_create(reader, NULL, TASK, 0, "reader", false);
if (thrd)
thread_ready(thrd);
else
/trunk/kernel/test/synch/semaphore1.c
90,7 → 90,7
for (j = 0; j < (CONSUMERS + PRODUCERS) / 2; j++) {
for (k = 0; k < i; k++) {
thrd = thread_create(consumer, NULL, TASK, 0, "consumer");
thrd = thread_create(consumer, NULL, TASK, 0, "consumer", false);
if (thrd)
thread_ready(thrd);
else
97,7 → 97,7
printf("could not create consumer %d\n", i);
}
for (k = 0; k < (4 - i); k++) {
thrd = thread_create(producer, NULL, TASK, 0, "producer");
thrd = thread_create(producer, NULL, TASK, 0, "producer", false);
if (thrd)
thread_ready(thrd);
else
/trunk/kernel/test/synch/rwlock4.c
130,7 → 130,7
k = random(7) + 1;
printf("Creating %d readers\n", k);
for (i = 0; i < k; i++) {
thrd = thread_create(reader, NULL, TASK, 0, "reader");
thrd = thread_create(reader, NULL, TASK, 0, "reader", false);
if (thrd)
thread_ready(thrd);
else
140,7 → 140,7
k = random(5) + 1;
printf("Creating %d writers\n", k);
for (i = 0; i < k; i++) {
thrd = thread_create(writer, NULL, TASK, 0, "writer");
thrd = thread_create(writer, NULL, TASK, 0, "writer", false);
if (thrd)
thread_ready(thrd);
else
/trunk/kernel/test/synch/semaphore2.c
93,7 → 93,7
k = random(7) + 1;
printf("Creating %d consumers\n", k);
for (i = 0; i < k; i++) {
thrd = thread_create(consumer, NULL, TASK, 0, "consumer");
thrd = thread_create(consumer, NULL, TASK, 0, "consumer", false);
if (thrd)
thread_ready(thrd);
else
/trunk/kernel/test/synch/rwlock5.c
87,7 → 87,7
for (j = 0; j < (READERS + WRITERS) / 2; j++) {
for (k = 0; k < i; k++) {
thrd = thread_create(reader, NULL, TASK, 0, "reader");
thrd = thread_create(reader, NULL, TASK, 0, "reader", false);
if (thrd)
thread_ready(thrd);
else
94,7 → 94,7
printf("Could not create reader %d\n", k);
}
for (k = 0; k < (4 - i); k++) {
thrd = thread_create(writer, NULL, TASK, 0, "writer");
thrd = thread_create(writer, NULL, TASK, 0, "writer", false);
if (thrd)
thread_ready(thrd);
else
/trunk/kernel/test/thread/thread1.c
61,7 → 61,7
 
for (i = 0; i < THREADS; i++) {
thread_t *t;
if (!(t = thread_create(threadtest, NULL, TASK, 0, "threadtest"))) {
if (!(t = thread_create(threadtest, NULL, TASK, 0, "threadtest", false))) {
printf("Could not create thread %d\n", i);
break;
}
/trunk/kernel/test/mm/falloc2.c
107,7 → 107,7
atomic_set(&thread_fail, 0);
for (i = 0; i < THREADS; i++) {
thread_t * thrd = thread_create(falloc, NULL, TASK, 0, "falloc");
thread_t * thrd = thread_create(falloc, NULL, TASK, 0, "falloc", false);
if (!thrd) {
printf("Could not create thread %d\n", i);
break;
/trunk/kernel/test/mm/slab1.c
138,7 → 138,7
SLAB_CACHE_NOMAGAZINE);
semaphore_initialize(&thr_sem, 0);
for (i = 0; i < THREADS; i++) {
if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest")))
if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest", false)))
printf("Could not create thread %d\n", i);
else
thread_ready(t);
/trunk/kernel/test/mm/slab2.c
190,7 → 190,7
0);
semaphore_initialize(&thr_sem,0);
for (i = 0; i < THREADS; i++) {
if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest")))
if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest", false)))
printf("Could not create thread %d\n", i);
else
thread_ready(t);
/trunk/kernel/test/fpu/mips2.c
122,7 → 122,7
for (i = 0; i < THREADS; i++) {
thread_t *t;
if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1"))) {
if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1", false))) {
printf("could not create thread %d\n", 2 * i);
break;
}
129,7 → 129,7
thread_ready(t);
total++;
if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2"))) {
if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2", false))) {
printf("could not create thread %d\n", 2 * i + 1);
break;
}
/trunk/kernel/test/fpu/fpu1.c
185,7 → 185,7
for (i = 0; i < THREADS; i++) {
thread_t *t;
if (!(t = thread_create(e, NULL, TASK, 0, "e"))) {
if (!(t = thread_create(e, NULL, TASK, 0, "e", false))) {
printf("could not create thread %d\n", 2 * i);
break;
}
192,7 → 192,7
thread_ready(t);
total++;
if (!(t = thread_create(pi, NULL, TASK, 0, "pi"))) {
if (!(t = thread_create(pi, NULL, TASK, 0, "pi", false))) {
printf("could not create thread %d\n", 2 * i + 1);
break;
}
/trunk/kernel/test/fpu/sse1.c
121,7 → 121,7
for (i = 0; i < THREADS; i++) {
thread_t *t;
if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1"))) {
if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1", false))) {
printf("could not create thread %d\n", 2 * i);
break;
}
128,7 → 128,7
thread_ready(t);
total++;
if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2"))) {
if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2", false))) {
printf("could not create thread %d\n", 2 * i + 1);
break;
}
/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;