Changeset e1b6742 in mainline for uspace/app/tasks/tasks.c


Ignore:
Timestamp:
2010-04-18T12:17:11Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e535eeb
Parents:
bbda5ab
Message:

export threads to user space
the "tasks" command can now print all threads or threads belonging to a task

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tasks/tasks.c

    rbbda5ab re1b6742  
    11/*
    22 * Copyright (c) 2010 Stanislav Kozina
     3 * Copyright (c) 2010 Martin Decky
    34 * All rights reserved.
    45 *
     
    4344#include <malloc.h>
    4445#include <inttypes.h>
     46#include <bool.h>
    4547#include <arg_parse.h>
    4648#include "func.h"
     
    5355#define PRINT_LOAD1(x)  ((x) >> 11)
    5456#define PRINT_LOAD2(x)  (((x) & 0x7ff) / 2)
    55 
    56 /** Thread states */
    57 //static const char *thread_states[] = {
    58 //      "Invalid",
    59 //      "Running",
    60 //      "Sleeping",
    61 //      "Ready",
    62 //      "Entering",
    63 //      "Exiting",
    64 //      "Lingering"
    65 //};
    6657
    6758static void list_tasks(void)
     
    9081                       
    9182                        printf("%8" PRIu64 "%8u %8" PRIu64"%c %12"
    92                             PRIu64"%c %12" PRIu64"%c %s\n", ids[i], stats_task->threads,
     83                            PRIu64 "%c %12" PRIu64 "%c %s\n", ids[i], stats_task->threads,
    9384                            virtmem, vmsuffix, ucycles, usuffix, kcycles, ksuffix,
    9485                            stats_task->name);
     
    10293}
    10394
    104 static void list_threads(task_id_t task_id)
    105 {
    106         /* TODO:
    107         size_t thread_count = THREAD_COUNT;
    108         thread_info_t *threads = malloc(thread_count * sizeof(thread_info_t));
    109         size_t result = get_task_threads(threads, sizeof(thread_info_t) * thread_count);
    110 
    111         while (result > thread_count) {
    112                 thread_count *= 2;
    113                 threads = realloc(threads, thread_count * sizeof(thread_info_t));
    114                 result = get_task_threads(threads, sizeof(thread_info_t) * thread_count);
    115         }
    116 
    117         if (result == 0) {
    118                 printf("No task with given pid!\n");
    119                 exit(1);
    120         }
    121 
    122         size_t i;
     95static void list_threads(task_id_t task_id, bool all)
     96{
     97        size_t count;
     98        thread_id_t *ids =
     99            (thread_id_t *) stats_get_threads(&count);
     100       
     101        if (ids == NULL) {
     102                fprintf(stderr, "%s: Unable to get threads\n", NAME);
     103                return;
     104        }
     105       
    123106        printf("    ID    State  CPU   Prio    [k]uCycles    [k]kcycles   Cycle fault\n");
    124         for (i = 0; i < result; ++i) {
    125                 if (threads[i].taskid != taskid) {
    126                         continue;
    127                 }
    128                 uint64_t ucycles, kcycles;
    129                 char usuffix, ksuffix;
    130                 order(threads[i].ucycles, &ucycles, &usuffix);
    131                 order(threads[i].kcycles, &kcycles, &ksuffix);
    132                 printf("%6llu %-8s %4u %6d %12llu%c %12llu%c\n", threads[i].tid,
    133                         thread_states[threads[i].state], threads[i].cpu,
    134                         threads[i].priority, ucycles, usuffix,
    135                         kcycles, ksuffix);
    136         }
    137 
    138         free(threads); */
     107        size_t i;
     108        for (i = 0; i < count; i++) {
     109                stats_thread_t *stats_thread = stats_get_thread(ids[i]);
     110                if (stats_thread != NULL) {
     111                        if ((all) || (stats_thread->task_id == task_id)) {
     112                                uint64_t ucycles, kcycles;
     113                                char usuffix, ksuffix;
     114                               
     115                                order(stats_thread->ucycles, &ucycles, &usuffix);
     116                                order(stats_thread->kcycles, &kcycles, &ksuffix);
     117                               
     118                                if (stats_thread->on_cpu) {
     119                                        printf("%8" PRIu64 " %-8s %4u %6d %12"
     120                                            PRIu64"%c %12" PRIu64"%c\n", ids[i],
     121                                            thread_get_state(stats_thread->state),
     122                                            stats_thread->cpu, stats_thread->priority,
     123                                            ucycles, usuffix, kcycles, ksuffix);
     124                                } else {
     125                                        printf("%8" PRIu64 " %-8s ---- %6d %12"
     126                                            PRIu64"%c %12" PRIu64"%c\n", ids[i],
     127                                            thread_get_state(stats_thread->state),
     128                                            stats_thread->priority,
     129                                            ucycles, usuffix, kcycles, ksuffix);
     130                                }
     131                        }
     132                       
     133                        free(stats_thread);
     134                } else if (all)
     135                        printf("%8" PRIu64 "\n", ids[i]);
     136        }
     137       
     138        free(ids);
    139139}
    140140
     
    190190{
    191191        printf(
    192             "Usage: tasks [-t task_id] [-l] [-c]\n" \
     192            "Usage: tasks [-t task_id] [-a] [-l] [-c]\n" \
    193193            "\n" \
    194194            "Options:\n" \
     
    197197            "\t\tList threads of the given task\n" \
    198198            "\n" \
     199            "\t-a\n" \
     200            "\t--all\n" \
     201            "\t\tList all threads\n" \
     202            "\n" \
    199203            "\t-l\n" \
    200204            "\t--load\n" \
     
    217221        bool toggle_tasks = true;
    218222        bool toggle_threads = false;
     223        bool toggle_all = false;
    219224        bool toggle_load = false;
    220225        bool toggle_cpus = false;
    221226       
    222         task_id_t task_id;
     227        task_id_t task_id = 0;
    223228       
    224229        int i;
     
    230235                        usage();
    231236                        return 0;
     237                }
     238               
     239                /* All threads */
     240                if ((off = arg_parse_short_long(argv[i], "-a", "--all")) != -1) {
     241                        toggle_tasks = false;
     242                        toggle_threads = true;
     243                        toggle_all = true;
     244                        continue;
    232245                }
    233246               
     
    268281       
    269282        if (toggle_threads)
    270                 list_threads(task_id);
     283                list_threads(task_id, toggle_all);
    271284       
    272285        if (toggle_load)
Note: See TracChangeset for help on using the changeset viewer.