Changeset 62b6d17 in mainline for kernel/generic


Ignore:
Timestamp:
2006-12-14T16:47:36Z (19 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
aeaebcc
Parents:
55cc9bc
Message:

introduce uncounted threads, whose accounting doesn't affect accumulated task accounting
run tests in kconsole thread again

Location:
kernel/generic
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/proc/thread.h

    r55cc9bc r62b6d17  
    149149        uint64_t cycles;                        /**< Thread accounting. */
    150150        uint64_t last_cycle;            /**< Last sampled cycle. */
     151        bool uncounted;                         /**< Thread doesn't affect accumulated accounting. */
    151152
    152153        int priority;                           /**< Thread's priority. Implemented as index to CPU->rq */
     
    169170
    170171extern void thread_init(void);
    171 extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags, char *name);
     172extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags, char *name, bool uncounted);
    172173extern void thread_ready(thread_t *t);
    173174extern void thread_exit(void) __attribute__((noreturn));
  • kernel/generic/src/console/cmd.c

    r55cc9bc r62b6d17  
    5757#include <mm/tlb.h>
    5858#include <arch/mm/tlb.h>
    59 #include <mm/as.h>
    6059#include <mm/frame.h>
    6160#include <main/version.h>
     
    860859}
    861860
    862 static void test_wrapper(void *arg)
    863 {
    864         test_t *test = (test_t *) arg;
     861static bool run_test(const test_t *test)
     862{
     863        printf("%s\t\t%s\n", test->name, test->desc);
    865864       
    866865        /* Update and read thread accounting
     
    886885        if (ret == NULL) {
    887886                printf("Test passed\n");
    888 //              return true;
    889                 return;
     887                return true;
    890888        }
    891889
    892890        printf("%s\n", ret);
    893 //      return false;
    894 }
    895 
    896 static bool run_test(const test_t *test)
    897 {
    898         printf("%s\t\t%s\n", test->name, test->desc);
    899        
    900         /* Create separate task and thread
    901            for the test */
    902         task_t *ta = task_create(AS_KERNEL, "test");
    903         if (ta == NULL) {
    904                 printf("Unable to create test task\n");
    905                 return false;
    906         }
    907        
    908         thread_t *t = thread_create(test_wrapper, (void *) test, ta, 0, "test_main");
    909         if (t == NULL) {
    910                 printf("Unable to create test main thread\n");
    911                 task_destroy(ta);
    912                 return false;
    913         }
    914        
    915         /* Run the test */
    916         thread_ready(t);
    917         thread_join(t);
    918         thread_detach(t);
    919        
    920         return true;
     891        return false;
    921892}
    922893
  • kernel/generic/src/main/kinit.c

    r55cc9bc r62b6d17  
    9999                 * Just a beautification.
    100100                 */
    101                 if ((t = thread_create(kmp, NULL, TASK, THREAD_FLAG_WIRED, "kmp"))) {
     101                if ((t = thread_create(kmp, NULL, TASK, THREAD_FLAG_WIRED, "kmp", true))) {
    102102                        spinlock_lock(&t->lock);
    103103                        t->cpu = &cpus[0];
     
    124124                for (i = 0; i < config.cpu_count; i++) {
    125125
    126                         if ((t = thread_create(kcpulb, NULL, TASK, THREAD_FLAG_WIRED, "kcpulb"))) {
     126                        if ((t = thread_create(kcpulb, NULL, TASK, THREAD_FLAG_WIRED, "kcpulb", true))) {
    127127                                spinlock_lock(&t->lock);                       
    128128                                t->cpu = &cpus[i];
     
    144144         * Create kernel console.
    145145         */
    146         if ((t = thread_create(kconsole, "kconsole", TASK, 0, "kconsole")))
     146        if ((t = thread_create(kconsole, "kconsole", TASK, 0, "kconsole", false)))
    147147                thread_ready(t);
    148148        else
  • kernel/generic/src/main/main.c

    r55cc9bc r62b6d17  
    267267         * Create the first thread.
    268268         */
    269         t = thread_create(kinit, NULL, k, 0, "kinit");
     269        t = thread_create(kinit, NULL, k, 0, "kinit", true);
    270270        if (!t)
    271271                panic("can't create kinit thread\n");
  • kernel/generic/src/proc/task.c

    r55cc9bc r62b6d17  
    221221         * Create the main thread.
    222222         */
    223         t1 = thread_create(uinit, kernel_uarg, task, THREAD_FLAG_USPACE, "uinit");
     223        t1 = thread_create(uinit, kernel_uarg, task, THREAD_FLAG_USPACE, "uinit", false);
    224224        ASSERT(t1);
    225225       
     
    227227         * Create killer thread for the new task.
    228228         */
    229         t2 = thread_create(ktaskgc, t1, task, 0, "ktaskgc");
     229        t2 = thread_create(ktaskgc, t1, task, 0, "ktaskgc", true);
    230230        ASSERT(t2);
    231231        thread_ready(t2);
     
    286286               
    287287                spinlock_lock(&thr->lock);
    288                
    289                 if (thr == THREAD) /* Update accounting of current thread */
    290                         thread_update_accounting();
    291                 ret += thr->cycles;
    292                
     288                /* Process only counted threads */
     289                if (!thr->uncounted) {
     290                        if (thr == THREAD) /* Update accounting of current thread */
     291                                thread_update_accounting();
     292                        ret += thr->cycles;
     293                }
    293294                spinlock_unlock(&thr->lock);
    294295        }
     
    329330        spinlock_unlock(&tasks_lock);
    330331       
    331         t = thread_create(ktaskclnp, NULL, ta, 0, "ktaskclnp");
     332        t = thread_create(ktaskclnp, NULL, ta, 0, "ktaskclnp", true);
    332333       
    333334        spinlock_lock(&ta->lock);
  • kernel/generic/src/proc/thread.c

    r55cc9bc r62b6d17  
    124124       
    125125        spinlock_lock(&THREAD->lock);
    126         thread_update_accounting();
    127         uint64_t cycles = THREAD->cycles;
    128         THREAD->cycles = 0;
    129         spinlock_unlock(&THREAD->lock);
    130        
    131         spinlock_lock(&TASK->lock);
    132         TASK->cycles += cycles;
    133         spinlock_unlock(&TASK->lock);
     126        if (!THREAD->uncounted) {
     127                thread_update_accounting();
     128                uint64_t cycles = THREAD->cycles;
     129                THREAD->cycles = 0;
     130                spinlock_unlock(&THREAD->lock);
     131               
     132                spinlock_lock(&TASK->lock);
     133                TASK->cycles += cycles;
     134                spinlock_unlock(&TASK->lock);
     135        } else
     136                spinlock_unlock(&THREAD->lock);
    134137       
    135138        interrupts_restore(ipl);
     
    303306 * Create a new thread.
    304307 *
    305  * @param func  Thread's implementing function.
    306  * @param arg   Thread's implementing function argument.
    307  * @param task  Task to which the thread belongs.
    308  * @param flags Thread flags.
    309  * @param name  Symbolic name.
     308 * @param func      Thread's implementing function.
     309 * @param arg       Thread's implementing function argument.
     310 * @param task      Task to which the thread belongs.
     311 * @param flags     Thread flags.
     312 * @param name      Symbolic name.
     313 * @param uncounted Thread's accounting doesn't affect accumulated task accounting.
    310314 *
    311315 * @return New thread's structure on success, NULL on failure.
    312316 *
    313317 */
    314 thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags, char *name)
     318thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags, char *name, bool uncounted)
    315319{
    316320        thread_t *t;
     
    345349        t->ticks = -1;
    346350        t->cycles = 0;
     351        t->uncounted = uncounted;
    347352        t->priority = -1;               /* start in rq[0] */
    348353        t->cpu = NULL;
     
    650655        }
    651656
    652         if ((t = thread_create(uinit, kernel_uarg, TASK, THREAD_FLAG_USPACE, namebuf))) {
     657        if ((t = thread_create(uinit, kernel_uarg, TASK, THREAD_FLAG_USPACE, namebuf, false))) {
    653658                tid = t->tid;
    654659                thread_ready(t);
Note: See TracChangeset for help on using the changeset viewer.