Changeset c621f4aa in mainline for kernel/generic/src/console/cmd.c


Ignore:
Timestamp:
2010-07-25T10:11:13Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
377cce8
Parents:
24a2517 (diff), a2da43c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with mainline.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/cmd.c

    r24a2517 rc621f4aa  
    4646#include <print.h>
    4747#include <panic.h>
    48 #include <arch/types.h>
     48#include <typedefs.h>
    4949#include <adt/list.h>
    5050#include <arch.h>
    5151#include <config.h>
    5252#include <func.h>
    53 #include <string.h>
     53#include <str.h>
    5454#include <macros.h>
    5555#include <debug.h>
     
    6666#include <ipc/irq.h>
    6767#include <ipc/event.h>
     68#include <sysinfo/sysinfo.h>
    6869#include <symtab.h>
    6970#include <errno.h>
     
    107108
    108109#ifdef CONFIG_TEST
    109 static int cmd_tests(cmd_arg_t *argv);
    110 static cmd_info_t tests_info = {
    111         .name = "tests",
    112         .description = "Print available kernel tests.",
    113         .func = cmd_tests,
    114         .argc = 0
    115 };
    116 
    117110static char test_buf[MAX_CMDLINE + 1];
    118111static int cmd_test(cmd_arg_t *argv);
    119112static cmd_arg_t test_argv[] = {
    120113        {
    121                 .type = ARG_TYPE_STRING,
     114                .type = ARG_TYPE_STRING_OPTIONAL,
    122115                .buffer = test_buf,
    123116                .len = sizeof(test_buf)
     
    126119static cmd_info_t test_info = {
    127120        .name = "test",
    128         .description = "Run kernel test.",
     121        .description = "Print list of kernel tests or run a test.",
    129122        .func = cmd_test,
    130123        .argc = 1,
     
    206199};
    207200
    208 /* Data and methods for 'call0' command. */
     201/* Data and methods for 'call0' and 'mcall0' command. */
    209202static char call0_buf[MAX_CMDLINE + 1];
    210203static char carg1_buf[MAX_CMDLINE + 1];
     
    354347};
    355348
     349static char flag_buf[MAX_CMDLINE + 1];
     350
    356351static int cmd_threads(cmd_arg_t *argv);
     352static cmd_arg_t threads_argv = {
     353        .type = ARG_TYPE_STRING_OPTIONAL,
     354        .buffer = flag_buf,
     355        .len = sizeof(flag_buf)
     356};
    357357static cmd_info_t threads_info = {
    358358        .name = "threads",
    359         .description = "List all threads.",
     359        .description = "List all threads (use -a for additional information).",
    360360        .func = cmd_threads,
    361         .argc = 0
     361        .argc = 1,
     362        .argv = &threads_argv
    362363};
    363364
    364365static int cmd_tasks(cmd_arg_t *argv);
     366static cmd_arg_t tasks_argv = {
     367        .type = ARG_TYPE_STRING_OPTIONAL,
     368        .buffer = flag_buf,
     369        .len = sizeof(flag_buf)
     370};
    365371static cmd_info_t tasks_info = {
    366372        .name = "tasks",
    367         .description = "List all tasks.",
     373        .description = "List all tasks (use -a for additional information).",
    368374        .func = cmd_tasks,
    369         .argc = 0
     375        .argc = 1,
     376        .argv = &tasks_argv
    370377};
    371378
     
    384391        .description = "List slab caches.",
    385392        .func = cmd_slabs,
     393        .argc = 0
     394};
     395
     396static int cmd_sysinfo(cmd_arg_t *argv);
     397static cmd_info_t sysinfo_info = {
     398        .name = "sysinfo",
     399        .description = "Dump sysinfo.",
     400        .func = cmd_sysinfo,
    386401        .argc = 0
    387402};
     
    475490        &set4_info,
    476491        &slabs_info,
     492        &sysinfo_info,
    477493        &symaddr_info,
    478494        &sched_info,
     
    485501        &zone_info,
    486502#ifdef CONFIG_TEST
    487         &tests_info,
    488503        &test_info,
    489504        &bench_info,
     
    500515void cmd_initialize(cmd_info_t *cmd)
    501516{
    502         spinlock_initialize(&cmd->lock, "cmd");
     517        spinlock_initialize(&cmd->lock, "cmd.lock");
    503518        link_initialize(&cmd->link);
    504519}
     
    648663                printf("Duplicate symbol, be more specific.\n");
    649664        } else if (rc == EOK) {
     665                ipl_t ipl;
     666
     667                ipl = interrupts_disable();
    650668                fnc = (unative_t (*)(void)) arch_construct_function(&fptr,
    651669                    (void *) symaddr, (void *) cmd_call0);
    652670                printf("Calling %s() (%p)\n", symbol, symaddr);
    653671                printf("Result: %#" PRIxn "\n", fnc());
     672                interrupts_restore(ipl);
    654673        } else {
    655674                printf("No symbol information available.\n");
     
    671690                        continue;
    672691               
    673                 thread_t *t;
    674                 if ((t = thread_create((void (*)(void *)) cmd_call0, (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) {
    675                         spinlock_lock(&t->lock);
    676                         t->cpu = &cpus[i];
    677                         spinlock_unlock(&t->lock);
    678                         printf("cpu%u: ", i);
    679                         thread_ready(t);
    680                         thread_join(t);
    681                         thread_detach(t);
     692                thread_t *thread;
     693                if ((thread = thread_create((void (*)(void *)) cmd_call0,
     694                    (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) {
     695                        irq_spinlock_lock(&thread->lock, true);
     696                        thread->cpu = &cpus[i];
     697                        irq_spinlock_unlock(&thread->lock, true);
     698                       
     699                        printf("cpu%" PRIs ": ", i);
     700                       
     701                        thread_ready(thread);
     702                        thread_join(thread);
     703                        thread_detach(thread);
    682704                } else
    683                         printf("Unable to create thread for cpu%u\n", i);
     705                        printf("Unable to create thread for cpu%" PRIs "\n", i);
    684706        }
    685707       
     
    706728                printf("Duplicate symbol, be more specific.\n");
    707729        } else if (rc == EOK) {
     730                ipl_t ipl;
     731
     732                ipl = interrupts_disable();
    708733                fnc = (unative_t (*)(unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call1);
    709734                printf("Calling f(%#" PRIxn "): %p: %s\n", arg1, symaddr, symbol);
    710735                printf("Result: %#" PRIxn "\n", fnc(arg1));
     736                interrupts_restore(ipl);
    711737        } else {
    712738                printf("No symbol information available.\n");
     
    736762                printf("Duplicate symbol, be more specific.\n");
    737763        } else if (rc == EOK) {
     764                ipl_t ipl;
     765
     766                ipl = interrupts_disable();
    738767                fnc = (unative_t (*)(unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call2);
    739768                printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n",
    740769                       arg1, arg2, symaddr, symbol);
    741770                printf("Result: %#" PRIxn "\n", fnc(arg1, arg2));
     771                interrupts_restore(ipl);
    742772        } else {
    743773                printf("No symbol information available.\n");
     
    767797                printf("Duplicate symbol, be more specific.\n");
    768798        } else if (rc == EOK) {
     799                ipl_t ipl;
     800
     801                ipl = interrupts_disable();
    769802                fnc = (unative_t (*)(unative_t, unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call3);
    770803                printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n",
    771804                       arg1, arg2, arg3, symaddr, symbol);
    772805                printf("Result: %#" PRIxn "\n", fnc(arg1, arg2, arg3));
     806                interrupts_restore(ipl);
    773807        } else {
    774808                printf("No symbol information available.\n");
     
    827861        bool pointer = false;
    828862        int rc;
    829 
    830         if (((char *)argv->buffer)[0] == '*') {
     863       
     864        if (((char *) argv->buffer)[0] == '*') {
    831865                rc = symtab_addr_lookup((char *) argv->buffer + 1, &addr);
    832866                pointer = true;
    833         } else if (((char *) argv->buffer)[0] >= '0' &&
    834                    ((char *)argv->buffer)[0] <= '9') {
    835                 rc = EOK;
    836                 addr = atoi((char *)argv->buffer);
    837         } else {
     867        } else if (((char *) argv->buffer)[0] >= '0' &&
     868                   ((char *) argv->buffer)[0] <= '9') {
     869                uint64_t value;
     870                rc = str_uint64((char *) argv->buffer, NULL, 0, true, &value);
     871                if (rc == EOK)
     872                        addr = (uintptr_t) value;
     873        } else
    838874                rc = symtab_addr_lookup((char *) argv->buffer, &addr);
    839         }
    840 
     875       
    841876        if (rc == ENOENT)
    842877                printf("Symbol %s not found.\n", argv->buffer);
     878        else if (rc == EINVAL)
     879                printf("Invalid address.\n");
    843880        else if (rc == EOVERFLOW) {
    844881                symtab_print_search((char *) argv->buffer);
    845                 printf("Duplicate symbol, be more specific.\n");
     882                printf("Duplicate symbol (be more specific) or address overflow.\n");
    846883        } else if (rc == EOK) {
    847884                if (pointer)
     
    849886                printf("Writing %#" PRIx64 " -> %p\n", arg1, addr);
    850887                *(uint32_t *) addr = arg1;
    851         } else {
     888        } else
    852889                printf("No symbol information available.\n");
    853         }
    854890       
    855891        return 1;
     
    868904}
    869905
     906/** Command for dumping sysinfo
     907 *
     908 * @param argv Ignores
     909 *
     910 * @return Always 1
     911 */
     912int cmd_sysinfo(cmd_arg_t * argv)
     913{
     914        sysinfo_dump(NULL);
     915        return 1;
     916}
     917
    870918
    871919/** Command for listings Thread information
    872920 *
     921 * @param argv Ignored
     922 *
     923 * @return Always 1
     924 */
     925int cmd_threads(cmd_arg_t *argv)
     926{
     927        if (str_cmp(flag_buf, "-a") == 0)
     928                thread_print_list(true);
     929        else if (str_cmp(flag_buf, "") == 0)
     930                thread_print_list(false);
     931        else
     932                printf("Unknown argument \"%s\".\n", flag_buf);
     933       
     934        return 1;
     935}
     936
     937/** Command for listings Task information
     938 *
     939 * @param argv Ignored
     940 *
     941 * @return Always 1
     942 */
     943int cmd_tasks(cmd_arg_t *argv)
     944{
     945        if (str_cmp(flag_buf, "-a") == 0)
     946                task_print_list(true);
     947        else if (str_cmp(flag_buf, "") == 0)
     948                task_print_list(false);
     949        else
     950                printf("Unknown argument \"%s\".\n", flag_buf);
     951       
     952        return 1;
     953}
     954
     955/** Command for listings Thread information
     956 *
    873957 * @param argv Ignores
    874958 *
    875959 * @return Always 1
    876960 */
    877 int cmd_threads(cmd_arg_t * argv)
    878 {
    879         thread_print_list();
    880         return 1;
    881 }
    882 
    883 /** Command for listings Task information
    884  *
    885  * @param argv Ignores
    886  *
    887  * @return Always 1
    888  */
    889 int cmd_tasks(cmd_arg_t * argv)
    890 {
    891         task_print_list();
    892         return 1;
    893 }
    894 
    895 /** Command for listings Thread information
    896  *
    897  * @param argv Ignores
    898  *
    899  * @return Always 1
    900  */
    901961int cmd_sched(cmd_arg_t * argv)
    902962{
     
    913973int cmd_zones(cmd_arg_t * argv)
    914974{
    915         zone_print_list();
     975        zones_print_list();
    916976        return 1;
    917977}
     
    9971057
    9981058#ifdef CONFIG_TEST
    999 /** Command for printing kernel tests list.
    1000  *
    1001  * @param argv Ignored.
    1002  *
    1003  * return Always 1.
    1004  */
    1005 int cmd_tests(cmd_arg_t *argv)
    1006 {
    1007         size_t len = 0;
    1008         test_t *test;
    1009         for (test = tests; test->name != NULL; test++) {
    1010                 if (str_length(test->name) > len)
    1011                         len = str_length(test->name);
    1012         }
    1013        
    1014         for (test = tests; test->name != NULL; test++)
    1015                 printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)"));
    1016        
    1017         printf("%-*s Run all safe tests\n", len, "*");
    1018         return 1;
    1019 }
    1020 
    10211059static bool run_test(const test_t *test)
    10221060{
     
    10251063        /* Update and read thread accounting
    10261064           for benchmarking */
    1027         ipl_t ipl = interrupts_disable();
    1028         spinlock_lock(&TASK->lock);
    1029         uint64_t t0 = task_get_accounting(TASK);
    1030         spinlock_unlock(&TASK->lock);
    1031         interrupts_restore(ipl);
     1065        irq_spinlock_lock(&TASK->lock, true);
     1066        uint64_t ucycles0, kcycles0;
     1067        task_get_accounting(TASK, &ucycles0, &kcycles0);
     1068        irq_spinlock_unlock(&TASK->lock, true);
    10321069       
    10331070        /* Execute the test */
    10341071        test_quiet = false;
    1035         char *ret = test->entry();
     1072        const char *ret = test->entry();
    10361073       
    10371074        /* Update and read thread accounting */
    1038         ipl = interrupts_disable();
    1039         spinlock_lock(&TASK->lock);
    1040         uint64_t dt = task_get_accounting(TASK) - t0;
    1041         spinlock_unlock(&TASK->lock);
    1042         interrupts_restore(ipl);
    1043        
    1044         uint64_t cycles;
    1045         char suffix;
    1046         order(dt, &cycles, &suffix);
    1047                
    1048         printf("Time: %" PRIu64 "%c cycles\n", cycles, suffix);
     1075        uint64_t ucycles1, kcycles1;
     1076        irq_spinlock_lock(&TASK->lock, true);
     1077        task_get_accounting(TASK, &ucycles1, &kcycles1);
     1078        irq_spinlock_unlock(&TASK->lock, true);
     1079       
     1080        uint64_t ucycles, kcycles;
     1081        char usuffix, ksuffix;
     1082        order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix);
     1083        order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix);
     1084       
     1085        printf("Time: %" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles\n",
     1086            ucycles, usuffix, kcycles, ksuffix);
    10491087       
    10501088        if (ret == NULL) {
     
    10521090                return true;
    10531091        }
    1054 
     1092       
    10551093        printf("%s\n", ret);
    10561094        return false;
     
    10611099        uint32_t i;
    10621100        bool ret = true;
    1063         uint64_t cycles;
    1064         char suffix;
     1101        uint64_t ucycles, kcycles;
     1102        char usuffix, ksuffix;
    10651103       
    10661104        if (cnt < 1)
     
    10781116                /* Update and read thread accounting
    10791117                   for benchmarking */
    1080                 ipl_t ipl = interrupts_disable();
    1081                 spinlock_lock(&TASK->lock);
    1082                 uint64_t t0 = task_get_accounting(TASK);
    1083                 spinlock_unlock(&TASK->lock);
    1084                 interrupts_restore(ipl);
     1118                irq_spinlock_lock(&TASK->lock, true);
     1119                uint64_t ucycles0, kcycles0;
     1120                task_get_accounting(TASK, &ucycles0, &kcycles0);
     1121                irq_spinlock_unlock(&TASK->lock, true);
    10851122               
    10861123                /* Execute the test */
    10871124                test_quiet = true;
    1088                 char * ret = test->entry();
     1125                const char *ret = test->entry();
    10891126               
    10901127                /* Update and read thread accounting */
    1091                 ipl = interrupts_disable();
    1092                 spinlock_lock(&TASK->lock);
    1093                 uint64_t dt = task_get_accounting(TASK) - t0;
    1094                 spinlock_unlock(&TASK->lock);
    1095                 interrupts_restore(ipl);
     1128                irq_spinlock_lock(&TASK->lock, true);
     1129                uint64_t ucycles1, kcycles1;
     1130                task_get_accounting(TASK, &ucycles1, &kcycles1);
     1131                irq_spinlock_unlock(&TASK->lock, true);
    10961132               
    10971133                if (ret != NULL) {
     
    11011137                }
    11021138               
    1103                 data[i] = dt;
    1104                 order(dt, &cycles, &suffix);
    1105                 printf("OK (%" PRIu64 "%c cycles)\n", cycles, suffix);
     1139                data[i] = ucycles1 - ucycles0 + kcycles1 - kcycles0;
     1140                order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix);
     1141                order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix);
     1142                printf("OK (%" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles)\n",
     1143                    ucycles, usuffix, kcycles, ksuffix);
    11061144        }
    11071145       
     
    11151153                }
    11161154               
    1117                 order(sum / (uint64_t) cnt, &cycles, &suffix);
    1118                 printf("Average\t\t%" PRIu64 "%c\n", cycles, suffix);
     1155                order_suffix(sum / (uint64_t) cnt, &ucycles, &usuffix);
     1156                printf("Average\t\t%" PRIu64 "%c\n", ucycles, usuffix);
    11191157        }
    11201158       
     
    11241162}
    11251163
    1126 /** Command for returning kernel tests
     1164static void list_tests(void)
     1165{
     1166        size_t len = 0;
     1167        test_t *test;
     1168       
     1169        for (test = tests; test->name != NULL; test++) {
     1170                if (str_length(test->name) > len)
     1171                        len = str_length(test->name);
     1172        }
     1173       
     1174        for (test = tests; test->name != NULL; test++)
     1175                printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)"));
     1176       
     1177        printf("%-*s Run all safe tests\n", len, "*");
     1178}
     1179
     1180/** Command for listing and running kernel tests
    11271181 *
    11281182 * @param argv Argument vector.
    11291183 *
    11301184 * return Always 1.
     1185 *
    11311186 */
    11321187int cmd_test(cmd_arg_t *argv)
     
    11421197                        }
    11431198                }
    1144         } else {
     1199        } else if (str_cmp((char *) argv->buffer, "") != 0) {
    11451200                bool fnd = false;
    11461201               
     
    11551210                if (!fnd)
    11561211                        printf("Unknown test\n");
    1157         }
     1212        } else
     1213                list_tests();
    11581214       
    11591215        return 1;
Note: See TracChangeset for help on using the changeset viewer.