Changes in / [f579760:875c629] in mainline


Ignore:
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • boot/Makefile.common

    rf579760 r875c629  
    139139        $(USPACE_PATH)/app/ping/ping \
    140140        $(USPACE_PATH)/app/stats/stats \
     141        $(USPACE_PATH)/app/tasks/tasks \
    141142        $(USPACE_PATH)/app/top/top \
    142143        $(USPACE_PATH)/app/sysinfo/sysinfo \
  • kernel/generic/include/ipc/ipc.h

    rf579760 r875c629  
    338338         * The caller box is different from sender->answerbox
    339339         * for synchronous calls.
     340         *
    340341         */
    341342        answerbox_t *callerbox;
     
    354355         * cases, we must keep it aside so that the answer is processed
    355356         * correctly.
     357         *
    356358         */
    357359        phone_t *caller_phone;
  • kernel/generic/src/ipc/ipc.c

    rf579760 r875c629  
    690690        irq_spinlock_exchange(&tasks_lock, &task->lock);
    691691       
    692         printf("[phone id] [calls] [state\n");
     692        /* Print opened phones & details */
     693        printf("PHONE:\n");
    693694       
    694695        size_t i;
    695696        for (i = 0; i < IPC_MAX_PHONES; i++) {
    696697                if (SYNCH_FAILED(mutex_trylock(&task->phones[i].lock))) {
    697                         printf("%-10zu (mutex busy)\n", i);
     698                        printf("%zu: mutex busy\n", i);
    698699                        continue;
    699700                }
    700701               
    701702                if (task->phones[i].state != IPC_PHONE_FREE) {
    702                         printf("%-10zu %7" PRIun " ", i,
    703                             atomic_get(&task->phones[i].active_calls));
     703                        printf("%zu: ", i);
    704704                       
    705705                        switch (task->phones[i].state) {
    706706                        case IPC_PHONE_CONNECTING:
    707                                 printf("connecting");
     707                                printf("connecting ");
    708708                                break;
    709709                        case IPC_PHONE_CONNECTED:
    710                                 printf("connected to %" PRIu64 " (%s)",
    711                                     task->phones[i].callee->task->taskid,
    712                                     task->phones[i].callee->task->name);
     710                                printf("connected to: %p (%" PRIu64 ") ",
     711                                    task->phones[i].callee,
     712                                    task->phones[i].callee->task->taskid);
    713713                                break;
    714714                        case IPC_PHONE_SLAMMED:
    715                                 printf("slammed by %p",
     715                                printf("slammed by: %p ",
    716716                                    task->phones[i].callee);
    717717                                break;
    718718                        case IPC_PHONE_HUNGUP:
    719                                 printf("hung up by %p",
     719                                printf("hung up - was: %p ",
    720720                                    task->phones[i].callee);
    721721                                break;
     
    724724                        }
    725725                       
    726                         printf("\n");
     726                        printf("active: %" PRIun "\n",
     727                            atomic_get(&task->phones[i].active_calls));
    727728                }
    728729               
     
    732733        irq_spinlock_lock(&task->answerbox.lock, false);
    733734       
    734 #ifdef __32_BITS__
    735         printf("[call id ] [method] [arg1] [arg2] [arg3] [arg4] [arg5]"
    736             " [flags] [sender\n");
    737 #endif
    738        
    739 #ifdef __64_BITS__
    740         printf("[call id         ] [method] [arg1] [arg2] [arg3] [arg4]"
    741             " [arg5] [flags] [sender\n");
    742 #endif
    743        
    744735        link_t *cur;
    745736       
    746         printf(" --- incomming calls ---\n");
     737        /* Print answerbox - calls */
     738        printf("ABOX - CALLS:\n");
    747739        for (cur = task->answerbox.calls.next; cur != &task->answerbox.calls;
    748740            cur = cur->next) {
    749741                call_t *call = list_get_instance(cur, call_t, link);
    750                
    751 #ifdef __32_BITS__
    752                 printf("%10p ", call);
    753 #endif
    754                
    755 #ifdef __64_BITS__
    756                 printf("%18p ", call);
    757 #endif
    758                
    759                 printf("%-8" PRIun " %-6" PRIun " %-6" PRIun " %-6" PRIun
    760                     " %-6" PRIun " %-6" PRIun " %-7x %" PRIu64 " (%s)\n",
     742                printf("Callid: %p Srctask:%" PRIu64 " M:%" PRIun
     743                    " A1:%" PRIun " A2:%" PRIun " A3:%" PRIun
     744                    " A4:%" PRIun " A5:%" PRIun " Flags:%x\n", call,
     745                    call->sender->taskid,
    761746                    IPC_GET_IMETHOD(call->data), IPC_GET_ARG1(call->data),
    762747                    IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data),
    763748                    IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data),
    764                     call->flags, call->sender->taskid, call->sender->name);
    765         }
    766        
    767         printf(" --- dispatched calls ---\n");
     749                    call->flags);
     750        }
     751       
     752        /* Print answerbox - dispatched calls */
     753        printf("ABOX - DISPATCHED CALLS:\n");
    768754        for (cur = task->answerbox.dispatched_calls.next;
    769755            cur != &task->answerbox.dispatched_calls;
    770756            cur = cur->next) {
    771757                call_t *call = list_get_instance(cur, call_t, link);
    772                
    773 #ifdef __32_BITS__
    774                 printf("%10p ", call);
    775 #endif
    776                
    777 #ifdef __64_BITS__
    778                 printf("%18p ", call);
    779 #endif
    780                
    781                 printf("%-8" PRIun " %-6" PRIun " %-6" PRIun " %-6" PRIun
    782                     " %-6" PRIun " %-6" PRIun " %-7x %" PRIu64 " (%s)\n",
     758                printf("Callid: %p Srctask:%" PRIu64 " M:%" PRIun
     759                    " A1:%" PRIun " A2:%" PRIun " A3:%" PRIun
     760                    " A4:%" PRIun " A5:%" PRIun " Flags:%x\n", call,
     761                    call->sender->taskid,
    783762                    IPC_GET_IMETHOD(call->data), IPC_GET_ARG1(call->data),
    784763                    IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data),
    785764                    IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data),
    786                     call->flags, call->sender->taskid, call->sender->name);
    787         }
    788        
    789         printf(" --- outgoing answers ---\n");
     765                    call->flags);
     766        }
     767       
     768        /* Print answerbox - answers */
     769        printf("ABOX - ANSWERS:\n");
    790770        for (cur = task->answerbox.answers.next;
    791771            cur != &task->answerbox.answers;
    792772            cur = cur->next) {
    793773                call_t *call = list_get_instance(cur, call_t, link);
    794                
    795 #ifdef __32_BITS__
    796                 printf("%10p ", call);
    797 #endif
    798                
    799 #ifdef __64_BITS__
    800                 printf("%18p ", call);
    801 #endif
    802                
    803                 printf("%-8" PRIun " %-6" PRIun " %-6" PRIun " %-6" PRIun
    804                     " %-6" PRIun " %-6" PRIun " %-7x %" PRIu64 " (%s)\n",
    805                     IPC_GET_IMETHOD(call->data), IPC_GET_ARG1(call->data),
     774                printf("Callid:%p M:%" PRIun " A1:%" PRIun " A2:%" PRIun
     775                    " A3:%" PRIun " A4:%" PRIun " A5:%" PRIun " Flags:%x\n",
     776                    call, IPC_GET_IMETHOD(call->data), IPC_GET_ARG1(call->data),
    806777                    IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data),
    807778                    IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data),
    808                     call->flags, call->sender->taskid, call->sender->name);
     779                    call->flags);
    809780        }
    810781       
  • kernel/generic/src/proc/task.c

    rf579760 r875c629  
    342342sysarg_t sys_task_set_name(const char *uspace_name, size_t name_len)
    343343{
     344        int rc;
    344345        char namebuf[TASK_NAME_BUFLEN];
    345346       
    346347        /* Cap length of name and copy it from userspace. */
     348       
    347349        if (name_len > TASK_NAME_BUFLEN - 1)
    348350                name_len = TASK_NAME_BUFLEN - 1;
    349351       
    350         int rc = copy_from_uspace(namebuf, uspace_name, name_len);
     352        rc = copy_from_uspace(namebuf, uspace_name, name_len);
    351353        if (rc != 0)
    352354                return (sysarg_t) rc;
    353355       
    354356        namebuf[name_len] = '\0';
    355        
    356         /*
    357          * As the task name is referenced also from the
    358          * threads, lock the threads' lock for the course
    359          * of the update.
    360          */
    361        
    362         irq_spinlock_lock(&tasks_lock, true);
    363         irq_spinlock_lock(&TASK->lock, false);
    364         irq_spinlock_lock(&threads_lock, false);
    365        
    366         /* Set task name */
    367357        str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf);
    368        
    369         irq_spinlock_unlock(&threads_lock, false);
    370         irq_spinlock_unlock(&TASK->lock, false);
    371         irq_spinlock_unlock(&tasks_lock, true);
    372358       
    373359        return EOK;
  • kernel/generic/src/proc/thread.c

    rf579760 r875c629  
    591591        order_suffix(thread->kcycles, &kcycles, &ksuffix);
    592592       
    593         char *name;
    594         if (str_cmp(thread->name, "uinit") == 0)
    595                 name = thread->task->name;
    596         else
    597                 name = thread->name;
    598        
    599593#ifdef __32_BITS__
    600594        if (*additional)
    601                 printf("%-8 %10p" PRIu64" %10p %9" PRIu64 "%c %9" PRIu64 "%c ",
    602                     thread->tid, thread->thread_code, thread->kstack,
    603                     ucycles, usuffix, kcycles, ksuffix);
     595                printf("%-8" PRIu64" %10p %9" PRIu64 "%c %9" PRIu64 "%c ",
     596                    thread->tid, thread->kstack, ucycles, usuffix,
     597                    kcycles, ksuffix);
    604598        else
    605                 printf("%-8" PRIu64" %-14s %10p %-8s %10p %-5" PRIu32 "\n",
    606                     thread->tid, name, thread, thread_states[thread->state],
     599                printf("%-8" PRIu64" %-14s %10p %-8s %10p %-5" PRIu32 " %10p\n",
     600                    thread->tid, thread->name, thread, thread_states[thread->state],
    607601                    thread->task, thread->task->context, thread->thread_code);
    608602#endif
     
    616610        else
    617611                printf("%-8" PRIu64" %-14s %18p %-8s %18p %-5" PRIu32 "\n",
    618                     thread->tid, name, thread, thread_states[thread->state],
     612                    thread->tid, thread->name, thread, thread_states[thread->state],
    619613                    thread->task, thread->task->context);
    620614#endif
     
    654648#ifdef __32_BITS__
    655649        if (additional)
    656                 printf("[id    ] [code    ] [stack   ] [ucycles ] [kcycles ]"
    657                     " [cpu] [waitqueue]\n");
     650                printf("[id    ] [stack   ] [ucycles ] [kcycles ] [cpu]"
     651                    " [waitqueue]\n");
    658652        else
    659653                printf("[id    ] [name        ] [address ] [state ] [task    ]"
    660                     " [ctx]\n");
     654                    " [ctx] [code    ]\n");
    661655#endif
    662656       
  • uspace/Makefile

    rf579760 r875c629  
    4646        app/stats \
    4747        app/taskdump \
     48        app/tasks \
    4849        app/tester \
    4950        app/tetris \
  • uspace/app/stats/stats.c

    rf579760 r875c629  
    11/*
    22 * Copyright (c) 2010 Stanislav Kozina
    3  * Copyright (c) 2010 Martin Decky
    43 * All rights reserved.
    54 *
     
    3736
    3837#include <stdio.h>
    39 #include <task.h>
    40 #include <thread.h>
    4138#include <stats.h>
    42 #include <errno.h>
    43 #include <stdlib.h>
     39#include <sys/time.h>
     40#include <inttypes.h>
    4441#include <malloc.h>
    45 #include <inttypes.h>
    46 #include <bool.h>
    47 #include <str.h>
    48 #include <arg_parse.h>
    4942
    50 #define NAME  "stats"
     43#define NAME  "sysstat"
    5144
    5245#define DAY     86400
     
    5447#define MINUTE  60
    5548
    56 static void list_tasks(void)
     49int main(int argc, char *argv[])
    5750{
    58         size_t count;
    59         stats_task_t *stats_tasks = stats_get_tasks(&count);
    60        
    61         if (stats_tasks == NULL) {
    62                 fprintf(stderr, "%s: Unable to get tasks\n", NAME);
    63                 return;
     51        struct timeval time;
     52        if (gettimeofday(&time, NULL) != 0) {
     53                fprintf(stderr, "%s: Cannot get time of day\n", NAME);
     54                return -1;
    6455        }
    6556       
    66         printf("[taskid] [thrds] [resident] [virtual] [ucycles]"
    67             " [kcycles] [name\n");
     57        uint64_t sec = time.tv_sec;
     58        printf("%02" PRIu64 ":%02" PRIu64 ":%02" PRIu64,
     59            (sec % DAY) / HOUR, (sec % HOUR) / MINUTE, sec % MINUTE);
    6860       
    69         size_t i;
    70         for (i = 0; i < count; i++) {
    71                 uint64_t resmem, virtmem, ucycles, kcycles;
    72                 char resmem_suffix, virtmem_suffix, usuffix, ksuffix;
    73                
    74                 order_suffix(stats_tasks[i].resmem, &resmem, &resmem_suffix);
    75                 order_suffix(stats_tasks[i].virtmem, &virtmem, &virtmem_suffix);
    76                 order_suffix(stats_tasks[i].ucycles, &ucycles, &usuffix);
    77                 order_suffix(stats_tasks[i].kcycles, &kcycles, &ksuffix);
    78                
    79                 printf("%-8" PRIu64 " %7zu %9" PRIu64 "%c %8" PRIu64 "%c"
    80                     " %8" PRIu64 "%c %8" PRIu64 "%c %s\n",
    81                     stats_tasks[i].task_id, stats_tasks[i].threads,
    82                     resmem, resmem_suffix, virtmem, virtmem_suffix,
    83                     ucycles, usuffix, kcycles, ksuffix, stats_tasks[i].name);
    84         }
     61        sysarg_t uptime = stats_get_uptime();
     62        printf(", up %" PRIun " days, %" PRIun " hours, "
     63            "%" PRIun " minutes, %" PRIun " seconds",
     64            uptime / DAY, (uptime % DAY) / HOUR,
     65            (uptime % HOUR) / MINUTE, uptime % MINUTE);
    8566       
    86         free(stats_tasks);
    87 }
    88 
    89 static void list_threads(task_id_t task_id, bool all)
    90 {
    91         size_t count;
    92         stats_thread_t *stats_threads = stats_get_threads(&count);
    93        
    94         if (stats_threads == NULL) {
    95                 fprintf(stderr, "%s: Unable to get threads\n", NAME);
    96                 return;
    97         }
    98        
    99         printf("[taskid] [threadid] [state ] [prio] [cpu ] [ucycles] [kcycles]\n");
    100        
    101         size_t i;
    102         for (i = 0; i < count; i++) {
    103                 if ((all) || (stats_threads[i].task_id == task_id)) {
    104                         uint64_t ucycles, kcycles;
    105                         char usuffix, ksuffix;
    106                        
    107                         order_suffix(stats_threads[i].ucycles, &ucycles, &usuffix);
    108                         order_suffix(stats_threads[i].kcycles, &kcycles, &ksuffix);
    109                        
    110                         printf("%-8" PRIu64 " %-10" PRIu64 " %-8s %6d ",
    111                             stats_threads[i].task_id, stats_threads[i].thread_id,
    112                             thread_get_state(stats_threads[i].state),
    113                             stats_threads[i].priority);
    114                        
    115                         if (stats_threads[i].on_cpu)
    116                                 printf("%6u ", stats_threads[i].cpu);
    117                         else
    118                                 printf("(none) ");
    119                        
    120                         printf("%8" PRIu64"%c %8" PRIu64"%c\n",
    121                             ucycles, usuffix, kcycles, ksuffix);
    122                 }
    123         }
    124        
    125         free(stats_threads);
    126 }
    127 
    128 static void list_cpus(void)
    129 {
    130         size_t count;
    131         stats_cpu_t *cpus = stats_get_cpus(&count);
    132        
    133         if (cpus == NULL) {
    134                 fprintf(stderr, "%s: Unable to get CPU statistics\n", NAME);
    135                 return;
    136         }
    137        
    138         printf("[id] [MHz     ] [busy cycles] [idle cycles]\n");
    139        
    140         size_t i;
    141         for (i = 0; i < count; i++) {
    142                 printf("%-4u ", cpus[i].id);
    143                 if (cpus[i].active) {
    144                         uint64_t bcycles, icycles;
    145                         char bsuffix, isuffix;
    146                        
    147                         order_suffix(cpus[i].busy_cycles, &bcycles, &bsuffix);
    148                         order_suffix(cpus[i].idle_cycles, &icycles, &isuffix);
    149                        
    150                         printf("%10" PRIu16 " %12" PRIu64 "%c %12" PRIu64 "%c\n",
    151                             cpus[i].frequency_mhz, bcycles, bsuffix,
    152                             icycles, isuffix);
    153                 } else
    154                         printf("inactive\n");
    155         }
    156        
    157         free(cpus);
    158 }
    159 
    160 static void print_load(void)
    161 {
    16267        size_t count;
    16368        load_t *load = stats_get_load(&count);
    164        
    165         if (load == NULL) {
    166                 fprintf(stderr, "%s: Unable to get load\n", NAME);
    167                 return;
    168         }
    169        
    170         printf("%s: Load average: ", NAME);
    171        
    172         size_t i;
    173         for (i = 0; i < count; i++) {
    174                 if (i > 0)
    175                         printf(" ");
     69        if (load != NULL) {
     70                printf(", load average: ");
    17671               
    177                 stats_print_load_fragment(load[i], 2);
     72                size_t i;
     73                for (i = 0; i < count; i++) {
     74                        if (i > 0)
     75                                printf(" ");
     76                       
     77                        stats_print_load_fragment(load[i], 2);
     78                }
     79               
     80                free(load);
    17881        }
    17982       
    18083        printf("\n");
    181        
    182         free(load);
    183 }
    184 
    185 static void print_uptime(void)
    186 {
    187         sysarg_t uptime = stats_get_uptime();
    188         printf("%s: Up %" PRIun " days, %" PRIun " hours, "
    189             "%" PRIun " minutes, %" PRIun " seconds\n", NAME,
    190             uptime / DAY, (uptime % DAY) / HOUR,
    191             (uptime % HOUR) / MINUTE, uptime % MINUTE);
    192 }
    193 
    194 static void usage(const char *name)
    195 {
    196         printf(
    197             "Usage: %s [-t task_id] [-a] [-c] [-l] [-u]\n" \
    198             "\n" \
    199             "Options:\n" \
    200             "\t-t task_id\n" \
    201             "\t--task=task_id\n" \
    202             "\t\tList threads of the given task\n" \
    203             "\n" \
    204             "\t-a\n" \
    205             "\t--all\n" \
    206             "\t\tList all threads\n" \
    207             "\n" \
    208             "\t-c\n" \
    209             "\t--cpus\n" \
    210             "\t\tList CPUs\n" \
    211             "\n" \
    212             "\t-l\n" \
    213             "\t--load\n" \
    214             "\t\tPrint system load\n" \
    215             "\n" \
    216             "\t-u\n" \
    217             "\t--uptime\n" \
    218             "\t\tPrint system uptime\n" \
    219             "\n" \
    220             "\t-h\n" \
    221             "\t--help\n" \
    222             "\t\tPrint this usage information\n"
    223             "\n" \
    224             "Without any options all tasks are listed\n",
    225             name
    226         );
    227 }
    228 
    229 int main(int argc, char *argv[])
    230 {
    231         bool toggle_tasks = true;
    232         bool toggle_threads = false;
    233         bool toggle_all = false;
    234         bool toggle_cpus = false;
    235         bool toggle_load = false;
    236         bool toggle_uptime = false;
    237        
    238         task_id_t task_id = 0;
    239        
    240         int i;
    241         for (i = 1; i < argc; i++) {
    242                 int off;
    243                
    244                 /* Usage */
    245                 if ((off = arg_parse_short_long(argv[i], "-h", "--help")) != -1) {
    246                         usage(argv[0]);
    247                         return 0;
    248                 }
    249                
    250                 /* All threads */
    251                 if ((off = arg_parse_short_long(argv[i], "-a", "--all")) != -1) {
    252                         toggle_tasks = false;
    253                         toggle_threads = true;
    254                         toggle_all = true;
    255                         continue;
    256                 }
    257                
    258                 /* CPUs */
    259                 if ((off = arg_parse_short_long(argv[i], "-c", "--cpus")) != -1) {
    260                         toggle_tasks = false;
    261                         toggle_cpus = true;
    262                         continue;
    263                 }
    264                
    265                 /* Threads */
    266                 if ((off = arg_parse_short_long(argv[i], "-t", "--task=")) != -1) {
    267                         // TODO: Support for 64b range
    268                         int tmp;
    269                         int ret = arg_parse_int(argc, argv, &i, &tmp, off);
    270                         if (ret != EOK) {
    271                                 printf("%s: Malformed task_id '%s'\n", NAME, argv[i]);
    272                                 return -1;
    273                         }
    274                        
    275                         task_id = tmp;
    276                        
    277                         toggle_tasks = false;
    278                         toggle_threads = true;
    279                         continue;
    280                 }
    281                
    282                 /* Load */
    283                 if ((off = arg_parse_short_long(argv[i], "-l", "--load")) != -1) {
    284                         toggle_tasks = false;
    285                         toggle_load = true;
    286                         continue;
    287                 }
    288                
    289                 /* Uptime */
    290                 if ((off = arg_parse_short_long(argv[i], "-u", "--uptime")) != -1) {
    291                         toggle_tasks = false;
    292                         toggle_uptime = true;
    293                         continue;
    294                 }
    295         }
    296        
    297         if (toggle_tasks)
    298                 list_tasks();
    299        
    300         if (toggle_threads)
    301                 list_threads(task_id, toggle_all);
    302        
    303         if (toggle_cpus)
    304                 list_cpus();
    305        
    306         if (toggle_load)
    307                 print_load();
    308        
    309         if (toggle_uptime)
    310                 print_uptime();
    311        
    31284        return 0;
    31385}
  • uspace/app/top/screen.c

    rf579760 r875c629  
    274274{
    275275        screen_style_inverted();
    276         printf("[taskid] [thrds] [resident] [%%resi] [virtual] [%%virt]"
     276        printf("[taskid] [threads] [resident] [%%resi] [virtual] [%%virt]"
    277277            " [%%user] [%%kern] [name");
    278278        screen_newline();
     
    303303                order_suffix(task->virtmem, &virtmem, &virtmem_suffix);
    304304               
    305                 printf("%-8" PRIu64 " %7zu %9" PRIu64 "%c ",
     305                printf("%-8" PRIu64 " %9zu %9" PRIu64 "%c ",
    306306                    task->task_id, task->threads, resmem, resmem_suffix);
    307307                print_percent(perc->resmem, 2);
Note: See TracChangeset for help on using the changeset viewer.