Ignore:
File:
1 edited

Legend:

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

    raafed15 rf35749e  
    11/*
     2 * Copyright (c) 2025 Jiri Svoboda
    23 * Copyright (c) 2005 Jakub Jermar
    34 * All rights reserved.
     
    6061#include <arch/mm/tlb.h>
    6162#include <mm/frame.h>
     63#include <main/shutdown.h>
    6264#include <main/version.h>
    6365#include <mm/slab.h>
     
    227229        .argc = 2,
    228230        .argv = bench_argv
     231};
     232
     233/* Data and methods for 'printbench' command. */
     234static int cmd_printbench(cmd_arg_t *argv);
     235
     236static cmd_info_t printbench_info = {
     237        .name = "printbench",
     238        .description = "Run a printing benchmark.",
     239        .func = cmd_printbench,
     240        .argc = 0,
    229241};
    230242
     
    613625        &test_info,
    614626        &bench_info,
     627        &printbench_info,
    615628#endif
    616629#ifdef CONFIG_UDEBUG
     
    9931006                        printf("cpu%u: ", i);
    9941007                        thread_wire(thread, &cpus[i]);
    995                         thread_ready(thread);
     1008                        thread_start(thread);
    9961009                        thread_join(thread);
    997                         thread_detach(thread);
    9981010                } else
    9991011                        printf("Unable to create thread for cpu%u\n", i);
     
    15821594}
    15831595
     1596int cmd_printbench(cmd_arg_t *argv)
     1597{
     1598        int cnt = 20;
     1599
     1600        uint64_t *data = malloc(sizeof(uint64_t) * cnt);
     1601        if (data == NULL) {
     1602                printf("Error allocating memory for statistics\n");
     1603                return false;
     1604        }
     1605
     1606        for (int i = 0; i < cnt; i++) {
     1607                /*
     1608                 * Update and read thread accounting
     1609                 * for benchmarking
     1610                 */
     1611                irq_spinlock_lock(&TASK->lock, true);
     1612                uint64_t ucycles0, kcycles0;
     1613                task_get_accounting(TASK, &ucycles0, &kcycles0);
     1614                irq_spinlock_unlock(&TASK->lock, true);
     1615
     1616                /* Execute the test */
     1617                for (int j = 0; j < 20; j++) {
     1618                        printf("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ěščřžýáíéú!@#$%%^&*(){}+\n");
     1619                        printf("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ěščřžýáíéú!@#$%%^&*(){}+abcdefghijklmnopqrstuvwxyz\n");
     1620                        printf("0123456789ěščřžýáíéú!@#$%%^&*(){}+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\n");
     1621                }
     1622
     1623                /* Update and read thread accounting */
     1624                irq_spinlock_lock(&TASK->lock, true);
     1625                uint64_t ucycles1, kcycles1;
     1626                task_get_accounting(TASK, &ucycles1, &kcycles1);
     1627                irq_spinlock_unlock(&TASK->lock, true);
     1628
     1629                data[i] = ucycles1 - ucycles0 + kcycles1 - kcycles0;
     1630        }
     1631
     1632        printf("\n");
     1633
     1634        uint64_t cycles;
     1635        char suffix;
     1636        uint64_t sum = 0;
     1637
     1638        for (int i = 0; i < cnt; i++) {
     1639                sum += data[i];
     1640        }
     1641
     1642        order_suffix(sum / (uint64_t) cnt, &cycles, &suffix);
     1643        printf("Average\t\t%" PRIu64 "%c\n", cycles, suffix);
     1644
     1645        free(data);
     1646
     1647        return true;
     1648}
     1649
    15841650#endif
    15851651
Note: See TracChangeset for help on using the changeset viewer.